/* 共通レイアウト / ブランド / カラー */
:root {
  --app-bg: #eef3f7;
  --app-max-width: 1360px;
  --app-side-pad: 16px;
  --app-scrollbar-w: 15px;
  --app-panel-bg: rgba(255, 255, 255, 0.95);
  --app-panel-border: #dbe4ec;
  --app-panel-shadow: 0 8px 22px rgba(17, 43, 66, 0.08);
  --app-radius: 10px;
  --app-panel-radius: var(--app-radius);
  --app-text: #1f3448;
  --app-subtle: #5f6f80;
  --app-accent: #0f7e4d;
}

body.with-app-fixed-title {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  padding-top: 0;
  color: var(--app-text);
  font-family: "Noto Sans JP", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    radial-gradient(1200px 360px at 94% -10%, rgba(26, 142, 89, 0.1), rgba(255, 255, 255, 0)),
    linear-gradient(180deg, #f4f7fa 0%, var(--app-bg) 100%);
}

/* ===== トップバー ===== */
.app-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1200;
  height: 66px;
  background: linear-gradient(90deg, #094d30 0%, #0f7e4d 60%, #13956b 100%);
  box-shadow: 0 2px 16px rgba(7, 54, 35, 0.32);
}

.app-topbar-inner {
  width: 100%;
  max-width: var(--app-max-width);
  margin: 0 auto;
  padding: 0 var(--app-side-pad);
  height: 100%;
  display: flex;
  align-items: center;
}

.app-page-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding-top: 66px;
  max-width: calc(var(--app-max-width) + 2 * var(--app-side-pad));
  margin: 0 auto;
  width: 100%;
}

.app-fixed-header {
  flex: 0 0 auto;
  padding: 10px calc(var(--app-side-pad) + var(--app-scrollbar-w)) 0 var(--app-side-pad);
  background: linear-gradient(
    180deg,
    rgba(243, 247, 251, 0.97) 0%,
    rgba(243, 247, 251, 0.9) 82%,
    rgba(243, 247, 251, 0) 100%
  );
  backdrop-filter: blur(6px);
  border-bottom: 1px solid rgba(31, 52, 72, 0.07);
}

.app-scroll-area {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  padding: 10px var(--app-side-pad) 14px;
}

.app-content-wrap {
  width: 100%;
}

.app-panel,
.page-title-card,
.race-header,
.detail-menu,
.section-card,
.stats-card,
.page-card {
  background: var(--app-panel-bg);
  border: 1px solid var(--app-panel-border);
  border-radius: var(--app-panel-radius);
  box-shadow: var(--app-panel-shadow);
}

.section-card,
.page-card {
  overflow: hidden;
}

.page-title-card {
  padding: 12px 14px;
  height: 80px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: nowrap;
  box-sizing: border-box;
  margin-bottom: 10px;
}

.page-title-heading {
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.01em;
  color: var(--app-text);
  margin: 0;
}

.page-title-sub {
  font-size: 0.78rem;
  color: var(--app-subtle);
  line-height: 1.4;
}

/* ===== パンくずリスト ===== */
.app-breadcrumb {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.95rem;
  color: var(--app-subtle);
  padding: 5px 2px 7px;
}

.app-breadcrumb-link {
  color: var(--app-subtle);
  text-decoration: none;
}

.app-breadcrumb-link:hover {
  color: var(--app-accent);
  text-decoration: underline;
}

.app-breadcrumb-sep {
  color: var(--app-border);
  user-select: none;
  font-size: 1.2rem;
  line-height: 1;
}

.app-breadcrumb-current {
  color: var(--app-text);
  font-weight: 500;
}

.stats-section {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.88),
    rgba(247, 250, 252, 0.9)
  );
  border: 1px solid var(--app-panel-border);
}

/* ===== ブランドロゴ（トップバー内） ===== */
.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  transition: opacity 0.15s ease;
}

.app-brand:hover {
  opacity: 0.82;
}

.app-brand-mark {
  display: block;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
}

.app-brand-text {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  line-height: 1;
}

.app-brand-text-main {
  color: #ffffff;
  font-weight: 800;
  font-size: 1.28rem;
  letter-spacing: 0.01em;
}

.app-brand-text-sub {
  color: rgba(255, 255, 255, 0.75);
  font-weight: 700;
  font-size: 1.08rem;
  letter-spacing: 0.02em;
}

/* ===== ページナビゲーション（タイトル下・全画面共通） ===== */
.app-page-nav {
  display: flex;
  align-items: stretch;
  gap: 6px;
  margin-top: 10px;
  margin-bottom: 10px;
  padding: 0;
  background: none;
  border-radius: 0;
  width: auto;
}

.app-page-nav-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  padding: 0.5rem 1rem;
  border-radius: var(--app-radius);
  font-weight: 700;
  font-size: 0.95rem;
  color: #495057;
  background: #ffffff;
  border: 1px solid #dee2e6;
  text-decoration: none;
  letter-spacing: 0.01em;
  white-space: nowrap;
  line-height: 1.2;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.app-page-nav-item:hover {
  background: #f0f4f8;
  color: var(--app-text);
  border-color: #b8c8d8;
}

.app-page-nav-item.active {
  color: #ffffff;
  background: #198754;
  border-color: #198754;
  box-shadow: 0 2px 6px rgba(25, 135, 84, 0.3);
}

.app-page-nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.7;
}

.app-page-nav-item.active .app-page-nav-icon {
  opacity: 1;
}

/* ===== グレードバッジ ===== */
.grade-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3.25rem;
  padding: 0.24rem 0.58rem;
  margin-right: 0.35rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1;
  color: #fff;
}

.grade-G1,
.grade-GI,
.grade-JG1 {
  background: #1161c7;
}

.grade-G2,
.grade-GII,
.grade-JG2 {
  background: #cc2f42;
}

.grade-G3,
.grade-GIII,
.grade-JG3 {
  background: #14915a;
}

.grade-L,
.grade-Listed,
.grade-OP,
.grade-OPEN {
  background: #5f6f80;
}

/* ===== レース番号・発走時刻チップ（全ページ共通） ===== */
.race-meta-chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #1a3e5c;
  background: rgba(31, 52, 72, 0.08);
  border: 1px solid rgba(31, 52, 72, 0.15);
  white-space: nowrap;
  letter-spacing: 0.02em;
}

/* ===== 共通テーブル ===== */
.table-results {
  table-layout: auto;
  width: max-content;
  min-width: 100%;
}

/* table-responsive が overflow-x:auto で暗黙的に overflow-y:auto になるのを防ぐ
   → sticky が app-scroll-area 基準で効くようにする */
.section-card .table-responsive {
  overflow-y: clip;
}

/* ===== page-table-fill: テーブルページ専用フルハイトレイアウト =====
   table-responsive 自身をスクロールコンテナにすることで thead sticky を確実に機能させる
   （重賞カレンダー・データ取得ページで使用） */
body.page-table-fill .app-scroll-area {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  scrollbar-gutter: auto;
}

body.page-table-fill .app-scroll-area > .app-content-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

body.page-table-fill .section-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.page-table-fill .section-card .table-responsive {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.table-results th {
  background: #ededed;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
  word-break: keep-all;
  position: sticky;
  top: 0;
  z-index: 3;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.08);
}

.table-results th,
.table-results td {
  text-align: center;
  vertical-align: middle;
  font-size: 0.88rem;
  padding: 0.4rem 0.5rem;
  line-height: 1.25;
  white-space: nowrap;
  word-break: keep-all;
}

.btn.btn-secondary {
  border-radius: 999px;
  border-color: #607080;
  background: #607080;
  font-weight: 700;
}

.btn.btn-secondary:hover {
  border-color: #4d5b69;
  background: #4d5b69;
}

/* 枠色 / 上がり / 人気カラー */
.waku-1 {
  --bs-table-bg: #ffffff;
  background-color: #ffffff !important;
  color: #111 !important;
}
.waku-2 {
  --bs-table-bg: #222222;
  background-color: #222222 !important;
  color: #fff !important;
}
.waku-3 {
  --bs-table-bg: #d32f2f;
  background-color: #d32f2f !important;
  color: #fff !important;
}
.waku-4 {
  --bs-table-bg: #1976d2;
  background-color: #1976d2 !important;
  color: #fff !important;
}
.waku-5 {
  --bs-table-bg: #ffd600;
  background-color: #ffd600 !important;
  color: #111 !important;
}
.waku-6 {
  --bs-table-bg: #2e7d32;
  background-color: #2e7d32 !important;
  color: #fff !important;
}
.waku-7 {
  --bs-table-bg: #f57c00;
  background-color: #f57c00 !important;
  color: #fff !important;
}
.waku-8 {
  --bs-table-bg: #f8bbd0;
  background-color: #f8bbd0 !important;
  color: #111 !important;
}

.agari-rank-1 {
  --bs-table-bg: #fff2a8;
  background-color: #fff2a8 !important;
  color: #5c4800 !important;
  font-weight: 700;
}
.agari-rank-2 {
  --bs-table-bg: #bfe1ff;
  background-color: #bfe1ff !important;
  color: #003b73 !important;
  font-weight: 700;
}
.agari-rank-3 {
  --bs-table-bg: #ffd6ad;
  background-color: #ffd6ad !important;
  color: #7a3b00 !important;
  font-weight: 700;
}
.agari-rank-other {
  --bs-table-bg: #f7f7f7;
  background-color: #f7f7f7 !important;
  color: #444 !important;
}

.ninki-1 {
  --bs-table-bg: #fff2a8;
  background-color: #fff2a8 !important;
  color: #5c4800 !important;
  font-weight: 700;
}
.ninki-2 {
  --bs-table-bg: #bfe1ff;
  background-color: #bfe1ff !important;
  color: #003b73 !important;
  font-weight: 700;
}
.ninki-3 {
  --bs-table-bg: #ffd6ad;
  background-color: #ffd6ad !important;
  color: #7a3b00 !important;
  font-weight: 700;
}
.ninki-other {
  --bs-table-bg: #f6f6f6;
  background-color: #f6f6f6 !important;
  color: #555 !important;
}

@media (max-width: 768px) {
  :root {
    --app-side-pad: 10px;
  }

  .app-topbar {
    height: 50px;
  }

  .app-page-shell {
    padding-top: 50px;
  }

  .app-brand-mark {
    width: 30px;
    height: 30px;
  }

  .app-brand-text-main {
    font-size: 0.95rem;
  }

  .app-brand-text-sub {
    font-size: 0.82rem;
  }

  .app-page-nav {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
  }

  .app-page-nav::-webkit-scrollbar {
    display: none;
  }

  .app-page-nav-item {
    flex-shrink: 0;
  }

  .page-title-card {
    height: auto;
    min-height: 70px;
    flex-wrap: wrap;
  }

  .app-page-nav-item {
    padding: 0.45rem 0.75rem;
    font-size: 0.875rem;
    gap: 4px;
  }

  .app-page-nav-icon {
    width: 14px;
    height: 14px;
  }
}

/* ===== 年切り替えプルダウン（共通） ===== */
.year-selector-dropdown {
  padding: 5px 12px;
  border: 1px solid var(--app-panel-border);
  border-radius: var(--app-radius);
  background: var(--app-panel-bg);
  color: var(--app-subtle);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}

.year-selector-dropdown:hover,
.year-selector-dropdown:focus {
  border-color: var(--app-accent);
  color: var(--app-accent);
}

/* ===== レスポンシブ列表示制御（グローバル） ===== */
@media (max-width: 992px) {
  .hide-lg { display: none !important; }
}
@media (max-width: 768px) {
  .hide-md { display: none !important; }
}

/* ===== フッター ===== */
.app-footer {
  text-align: center;
  padding: 18px 16px 24px;
  font-size: 0.78rem;
  color: var(--app-subtle);
  border-top: 1px solid var(--app-panel-border);
  margin-top: 8px;
}

.app-footer-link {
  color: var(--app-subtle);
  text-decoration: none;
}

.app-footer-link:hover {
  color: var(--app-accent);
  text-decoration: underline;
}

.app-footer-sep {
  margin: 0 8px;
  color: var(--app-panel-border);
}

.app-footer-copy {
  color: var(--app-subtle);
}
