/* ─── JRA Control Panel v5 ─── */
/* Light theme, larger fonts, readability-first */
/* Reference: HK Racing Panel (light bg, dark sidebar, teal accent) */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@300;400;500;600;700&family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ─── Reset & Base ────────────────────────────────────────────────────────── */

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Light theme — inspired by HK Racing Panel */
  --bg-primary: #f5f4f0;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f0efeb;
  --bg-hover: #eae9e5;
  --bg-active: #e2e1dc;

  --border: #d4d1ca;
  --border-subtle: #e8e6e1;

  --text-primary: #1a1a1a;
  --text-secondary: #4a4a4a;
  --text-tertiary: #7a7974;
  --text-muted: #b0ada6;

  /* Teal accent — matching HK panel */
  --accent: #0f9b8e;
  --accent-hover: #0a7d72;
  --accent-muted: rgba(15, 155, 142, 0.12);
  --accent-dim: rgba(15, 155, 142, 0.06);

  --success: #22a355;
  --success-muted: rgba(34, 163, 85, 0.12);
  --warning: #d48806;
  --warning-muted: rgba(212, 136, 6, 0.12);
  --danger: #d9363e;
  --danger-muted: rgba(217, 54, 62, 0.12);
  --gold: #d48806;

  /* Dark sidebar */
  --sidebar-bg: #1a1f2e;
  --sidebar-hover: #262c3e;
  --sidebar-active: #2d3448;
  --sidebar-text: #b8bcc8;
  --sidebar-text-bright: #e8eaef;
  --sidebar-border: #2d3448;
  --sidebar-accent: #3dd9c6;

  --font-body: 'Inter', 'Noto Sans JP', 'Hiragino Sans', 'Hiragino Kaku Gothic Pro', sans-serif;
  --font-jp: 'Noto Sans JP', 'Hiragino Sans', 'Hiragino Kaku Gothic Pro', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-xl: 14px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.1);

  --transition-fast: 120ms ease;
  --transition-normal: 200ms ease;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.55;
  min-height: 100vh;
}

/* ─── Layout ──────────────────────────────────────────────────────────────── */

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  border-right: none;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform var(--transition-normal);
}

.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo svg { flex-shrink: 0; }

.sidebar-logo-text {
  display: flex;
  flex-direction: column;
}

.sidebar-logo-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--sidebar-text-bright);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.sidebar-logo-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--sidebar-text);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.6;
}

.sidebar-nav {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
}

.nav-section { margin-bottom: 6px; }

.nav-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--sidebar-text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 14px 10px 6px;
  opacity: 0.5;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--sidebar-text);
  cursor: pointer;
  font-size: 15px;
  font-weight: 450;
  transition: all var(--transition-fast);
  user-select: none;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-bright);
}

.nav-item.active {
  background: rgba(61, 217, 198, 0.12);
  color: var(--sidebar-accent);
  font-weight: 500;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.6;
}

.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--sidebar-border);
  font-size: 12px;
  color: var(--sidebar-text);
  opacity: 0.6;
}

.main {
  flex: 1;
  margin-left: 240px;
  min-width: 0;
}

.page-header {
  padding: 24px 32px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-tertiary);
  margin-top: 3px;
}

.page-content {
  padding: 28px 32px;
}

/* ─── Mobile hamburger ────────────────────────────────────────────────────── */

.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--sidebar-bg);
  border-bottom: none;
  z-index: 110;
  padding: 0 16px;
  align-items: center;
  gap: 12px;
}

.hamburger {
  background: none;
  border: none;
  color: var(--sidebar-text-bright);
  cursor: pointer;
  padding: 4px;
}

.mobile-logo-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--sidebar-text-bright);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
}

/* ─── Cards ───────────────────────────────────────────────────────────────── */

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.card-body {
  padding: 22px;
}

.card-body.flush {
  padding: 0;
}

/* ─── Stat Cards ──────────────────────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.stat-value.accent { color: var(--accent); }

.stat-sub {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 6px;
}

/* ─── Tables ──────────────────────────────────────────────────────────────── */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  vertical-align: top;
}

.data-table tr:hover td { background: var(--bg-hover); }

.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover td { color: var(--text-primary); }
.data-table .text-right { text-align: right; }
.data-table .text-center { text-align: center; }

.data-table .mono {
  font-family: var(--font-mono);
  font-size: 13px;
}

.data-table .jp { font-family: var(--font-jp); }

.data-table .en {
  font-size: 12px;
  color: var(--text-tertiary);
}

.data-table .highlight {
  color: var(--accent);
  font-weight: 600;
}

.data-table .position-1 { color: #b8860b; font-weight: 700; }
.data-table .position-2 { color: #808080; font-weight: 600; }
.data-table .position-3 { color: #a0522d; font-weight: 600; }

/* ─── Forms / Filters ─────────────────────────────────────────────────────── */

.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
  align-items: end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.filter-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input[type="text"],
input[type="search"],
input[type="date"],
select {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 9px 12px;
  outline: none;
  transition: border-color var(--transition-fast);
  min-width: 0;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-muted);
}

input::placeholder { color: var(--text-muted); }

select {
  cursor: pointer;
  padding-right: 32px;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a7974' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* ─── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-secondary);
  border-color: var(--border);
  color: var(--text-secondary);
}
.btn-secondary:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ─── Pagination ──────────────────────────────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  font-size: 13px;
  color: var(--text-tertiary);
}

.pagination-info { display: flex; align-items: center; gap: 4px; }

.pagination-buttons { display: flex; gap: 4px; }
.pagination-buttons .btn { min-width: 36px; justify-content: center; }

/* ─── Tags / Badges ───────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-accent { background: var(--accent-muted); color: var(--accent); }
.badge-success { background: var(--success-muted); color: var(--success); }
.badge-warning { background: var(--warning-muted); color: var(--warning); }
.badge-danger { background: var(--danger-muted); color: var(--danger); }
.badge-neutral { background: var(--bg-tertiary); color: var(--text-secondary); }

.grade-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.grade-g1 { background: rgba(180, 120, 0, 0.12); color: #9a6700; border: 1px solid rgba(180, 120, 0, 0.25); }
.grade-g2 { background: rgba(200, 80, 30, 0.12); color: #b85318; border: 1px solid rgba(200, 80, 30, 0.25); }
.grade-g3 { background: rgba(34, 163, 85, 0.12); color: #1a7a3a; border: 1px solid rgba(34, 163, 85, 0.25); }
.grade-listed { background: var(--bg-tertiary); color: var(--text-secondary); border: 1px solid var(--border); }

/* ─── Loading ─────────────────────────────────────────────────────────────── */

.spinner {
  display: inline-block;
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner-lg { width: 36px; height: 36px; border-width: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 56px 20px;
  color: var(--text-tertiary);
  font-size: 15px;
}

.empty-state {
  text-align: center;
  padding: 56px 20px;
  color: var(--text-tertiary);
  font-size: 15px;
}

/* ─── Links ───────────────────────────────────────────────────────────────── */

.link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  transition: color var(--transition-fast);
}

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

/* ─── Breadcrumb ──────────────────────────────────────────────────────────── */

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-tertiary);
  margin-bottom: 20px;
}

.breadcrumb .link { font-size: 13px; }
.breadcrumb-sep { color: var(--text-muted); }

/* ─── Profile Sections ────────────────────────────────────────────────────── */

.profile-header {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 28px;
}

.profile-info { flex: 1; }

.profile-name {
  font-size: 26px;
  font-weight: 700;
  font-family: var(--font-jp);
  letter-spacing: -0.01em;
}

.profile-name-en {
  font-size: 16px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.profile-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin-top: 14px;
  font-size: 14px;
}

.profile-meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}

.profile-meta-item .label {
  color: var(--text-tertiary);
  font-size: 12px;
  font-weight: 500;
}

/* ─── KV Grid ────────────────────────────────────────────────────────────── */

.kv-grid {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 8px 20px;
  font-size: 14px;
}

.kv-key {
  color: var(--text-tertiary);
  font-size: 13px;
  font-weight: 500;
}

.kv-value { color: var(--text-primary); }

/* ─── Section Grid ────────────────────────────────────────────────────────── */

.section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── Table Counts Grid ───────────────────────────────────────────────────── */

.table-counts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.table-count-group {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.table-count-group-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

.table-count-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 14px;
}

.table-count-item .name {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 13px;
}

.table-count-item .count {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 14px;
}

/* ─── Log Entries ─────────────────────────────────────────────────────────── */

.log-entry {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 13px;
  display: flex;
  gap: 14px;
  align-items: center;
}

.log-entry:last-child { border-bottom: none; }

.log-time {
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
}

.log-message {
  color: var(--text-secondary);
  flex: 1;
}

/* ─── Tabs ────────────────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  gap: 0;
}

.tab {
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-tertiary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-fast);
  user-select: none;
}

.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ─── Search Box ──────────────────────────────────────────────────────────── */

.search-box {
  position: relative;
  max-width: 420px;
  margin-bottom: 20px;
}

.search-box input { width: 100%; padding-left: 38px; }

.search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

/* ─── Table Wrapper ───────────────────────────────────────────────────────── */

.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ═══════════════════════════════════════════════════════════════════════════ */
/* ─── Race Day View Components ───────────────────────────────────────────── */
/* ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Date Picker Strip ──────────────────────────────────────────────────── */

.date-picker-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.date-picker-strip input[type="date"] {
  font-size: 14px;
  padding: 6px 10px;
  font-weight: 600;
}

.date-nav-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px 10px;
  font-size: 14px;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
}

.date-nav-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.recent-dates {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.recent-date-chip {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 3px 8px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.recent-date-chip:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.recent-date-chip.active {
  background: var(--accent-muted);
  border-color: var(--accent);
  color: var(--accent);
}

/* ─── Venue Tabs ─────────────────────────────────────────────────────────── */

.venue-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.venue-tab {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.venue-tab:hover {
  background: var(--bg-hover);
  border-color: var(--border);
}

.venue-tab.active {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.venue-tab-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-jp);
}

.venue-tab.active .venue-tab-name {
  color: var(--accent);
}

.venue-tab-meta {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 0;
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

/* Pipe separator before meta block */
.venue-tab-meta::before {
  content: '|';
  color: var(--border);
}

.venue-tab-progress {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.progress-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
}

.progress-dot.incomplete {
  background: var(--text-muted);
}

/* ─── Venue Info Strip ───────────────────────────────────────────────────── */

.venue-info-strip {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 6px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  flex-wrap: wrap;
  font-size: 13px;
}

.venue-info-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.venue-info-label {
  color: var(--text-tertiary);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.06em;
}

.venue-info-value {
  color: var(--text-primary);
  font-weight: 500;
}

/* ─── Race Number Pills ──────────────────────────────────────────────────── */

.race-pills {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
  flex-wrap: nowrap;
}

.race-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-width: 0;
  padding: 8px 4px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  line-height: 1.1;
  gap: 2px;
}

.race-pill:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.race-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.race-pill .pill-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

.race-pill .pill-rnum {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.1;
}

.race-pill .pill-grade {
  font-size: 11px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.05em;
  line-height: 1;
  min-height: 12px;
}

.race-pill.active .pill-grade {
  color: rgba(255,255,255,0.85);
}

/* ─── Race Detail Card ───────────────────────────────────────────────────── */

.race-header-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.race-header-top {
  padding: 10px 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.race-badge-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  background: var(--accent-muted);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 10px;
}

.race-name-block {
  flex: 1;
  min-width: 200px;
}

.race-name-jp {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-jp);
  line-height: 1.3;
}

.race-name-en {
  font-size: 14px;
  color: var(--text-tertiary);
  margin-top: 3px;
}

.race-header-meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  padding: 0 16px 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.race-meta-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
  color: var(--text-secondary);
}

.race-meta-chip .meta-label {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ─── Race Detail Tabs ───────────────────────────────────────────────────── */

.race-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
}

.race-tab {
  padding: 12px 22px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-tertiary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-fast);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.race-tab:hover { color: var(--text-secondary); }

.race-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.race-tab-content {
  padding: 20px 0;
}

/* ═══════════════════════════════════════════════════════════════════════════ */
/* ─── Alerts ─────────────────────────────────────────────────────────────── */
/* ═══════════════════════════════════════════════════════════════════════════ */

.alert-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.alert-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.alert-item:hover {
  background: var(--bg-hover);
}

.alert-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.alert-icon.scratching {
  background: var(--danger-muted);
  color: var(--danger);
}

.alert-icon.time-change {
  background: var(--accent-muted);
  color: var(--accent);
}

.alert-icon.track-change {
  background: var(--warning-muted);
  color: var(--warning);
}

.alert-icon.jockey-change {
  background: rgba(140, 80, 200, 0.12);
  color: #7c3aed;
}

.alert-body {
  flex: 1;
  min-width: 0;
}

.alert-course {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 3px;
}

.alert-message {
  font-size: 15px;
  color: var(--text-primary);
  font-weight: 500;
}

.alert-detail {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 3px;
}

/* ═══════════════════════════════════════════════════════════════════════════ */
/* ─── Calendar ───────────────────────────────────────────────────────────── */
/* ═══════════════════════════════════════════════════════════════════════════ */

/* ── Calendar ────────────────────────────────────────────────────────────── */

.calendar-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.calendar-nav-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.calendar-month-label {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 220px;
  text-align: center;
  font-family: var(--font-body);
  letter-spacing: -0.02em;
}

.calendar-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-body);
  cursor: pointer;
}

.calendar-legend {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
  font-size: 12px;
  color: var(--text-tertiary);
}

.calendar-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.calendar-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.calendar-header-cell {
  padding: 10px 6px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-tertiary);
  line-height: 1.3;
}

.calendar-header-cell .header-sub {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 1px;
}

.calendar-header-cell.col-sat {
  color: #2070d0;
}

.calendar-header-cell.col-sun {
  color: #d9363e;
}

.calendar-cell {
  min-height: 110px;
  padding: 10px 10px 8px;
  background: var(--bg-secondary);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: default;
  transition: all var(--transition-fast);
  position: relative;
}

.calendar-cell.col-sat {
  background: rgba(32, 112, 208, 0.03);
}

.calendar-cell.col-sun {
  background: rgba(217, 54, 62, 0.03);
}

.calendar-cell.empty {
  background: transparent;
  border-color: transparent;
}

.calendar-cell.has-races {
  cursor: pointer;
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.calendar-cell.has-races.col-sat {
  background: rgba(32, 112, 208, 0.05);
  border-color: rgba(32, 112, 208, 0.25);
}

.calendar-cell.has-races.col-sun {
  background: rgba(217, 54, 62, 0.05);
  border-color: rgba(217, 54, 62, 0.25);
}

.calendar-cell.has-races:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 10px rgba(15, 155, 142, 0.15);
  transform: translateY(-1px);
}

.calendar-cell.today {
  border-color: var(--accent);
  border-width: 2px;
}

.calendar-day-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.calendar-day-num {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  line-height: 1;
}

.calendar-cell.has-races .calendar-day-num {
  color: var(--text-primary);
}

.calendar-cell.col-sat .calendar-day-num {
  color: #2070d0;
}

.calendar-cell.col-sun .calendar-day-num {
  color: #d9363e;
}

.calendar-cell.has-races.col-sat .calendar-day-num {
  color: #1a5eb0;
}

.calendar-cell.has-races.col-sun .calendar-day-num {
  color: #b82030;
}

.calendar-cell.today .calendar-day-num {
  color: var(--accent);
}

.calendar-race-count {
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-tertiary);
  background: var(--bg-tertiary);
  padding: 1px 6px;
  border-radius: 8px;
  line-height: 1.4;
}

.calendar-cell.has-races .calendar-race-count {
  color: var(--accent);
  background: var(--accent-muted);
}

.calendar-venues {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.calendar-venue-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  font-family: var(--font-jp);
  line-height: 1.3;
}

/* Venue color coding by region */
.calendar-venue-chip.venue-kanto {
  background: rgba(15, 155, 142, 0.08);
  color: #0a7d72;
}

.calendar-venue-chip.venue-kansai {
  background: rgba(212, 136, 6, 0.08);
  color: #96600a;
}

.calendar-venue-chip.venue-local {
  background: rgba(120, 120, 160, 0.08);
  color: #5a5a7a;
}

.calendar-venue-chip .venue-name {
  font-weight: 600;
}

.calendar-venue-chip .venue-count {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  opacity: 0.7;
}

.calendar-venue-chip .venue-progress {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-left: auto;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.calendar-venue-chip .venue-progress .done {
  color: var(--success);
}

/* ── Scheduled dates (from JRA website) ── */
.calendar-cell.scheduled {
  border-style: dashed;
  border-color: rgba(100, 180, 255, 0.4);
  background: rgba(100, 180, 255, 0.03);
}
.calendar-cell.scheduled.col-sat {
  background: rgba(60, 140, 240, 0.04);
  border-color: rgba(60, 140, 240, 0.35);
}
.calendar-cell.scheduled.col-sun {
  background: rgba(200, 70, 80, 0.04);
  border-color: rgba(200, 70, 80, 0.35);
}
.calendar-cell.scheduled:hover {
  border-color: rgba(100, 180, 255, 0.7);
  box-shadow: 0 2px 10px rgba(100, 180, 255, 0.12);
}

.scheduled-badge {
  color: #5aa0e0 !important;
  background: rgba(90, 160, 224, 0.12) !important;
  font-size: 10px !important;
  letter-spacing: 0.02em;
}

.calendar-venue-chip.venue-scheduled {
  border: 1px dashed rgba(100, 180, 255, 0.3);
}

.calendar-venue-chip .venue-graded {
  color: #e8a735;
  font-size: 12px;
  margin-left: 2px;
  flex-shrink: 0;
}

.calendar-featured {
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.3;
  padding: 1px 8px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  font-family: var(--font-jp);
}

/* ─── Pedigree Tree ───────────────────────────────────────────────────────── */

.pedigree-panel {
  padding: 12px 16px 16px;
}

.pedigree-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  font-family: var(--font-jp);
}

.ped-grid {
  display: flex;
  align-items: stretch;
  gap: 2px;
  overflow-x: auto;
}

.ped-col {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}

.ped-cell {
  background: var(--bg-tertiary);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  font-family: var(--font-jp);
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  flex: 1;
}

.ped-cell .ped-en {
  font-size: 11px;
  color: var(--text-tertiary);
  font-family: var(--font-sans);
}

/* Gen 3 — great-grandparents: 4 cells each side */
.ped-col.ped-gen3 { min-width: 120px; }
.ped-cell.ped-g3 { font-size: 12px; padding: 4px 8px; }

/* Gen 2 — grandparents: 2 cells each side */
.ped-col.ped-gen2 { min-width: 130px; }
.ped-cell.ped-g2 { font-size: 13px; padding: 6px 10px; }

/* Gen 1 — parents */
.ped-col.ped-gen1 { min-width: 140px; }
.ped-cell.ped-g1 { font-size: 14px; font-weight: 500; padding: 8px 10px; }
.ped-cell.ped-sire { border-left: 3px solid var(--accent); }
.ped-cell.ped-dam  { border-left: 3px solid #e84393; }

/* Center — the horse itself */
.ped-col.ped-center { min-width: 120px; }
.ped-cell.ped-self {
  font-size: 14px;
  font-weight: 600;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  justify-content: center;
  text-align: center;
}

.ped-sireline {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-tertiary);
}
.ped-sireline-label {
  font-weight: 600;
  color: var(--text-secondary);
}

.pedigree-name-en {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .mobile-header { display: flex; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }

  .main {
    margin-left: 0;
    padding-top: 56px;
  }

  .page-header { padding: 16px 18px 14px; }
  .page-content { padding: 18px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .table-counts-grid { grid-template-columns: 1fr; }
  .section-grid { grid-template-columns: 1fr; }
  .filters-bar { flex-direction: column; }

  .filter-group { width: 100%; }
  .filter-group input, .filter-group select { width: 100%; }

  .profile-header { flex-direction: column; }

  .kv-grid { grid-template-columns: 1fr; gap: 2px 0; }
  .kv-key { margin-top: 10px; }

  .ped-grid { flex-wrap: wrap; }
  .ped-col { min-width: 100px; }
  .pagination { flex-direction: column; gap: 10px; }

  .venue-tabs { flex-direction: row; }
  .venue-tab { min-width: unset; }

  .calendar-grid { gap: 3px; }
  .calendar-cell { min-height: 80px; padding: 6px; }
  .calendar-day-num { font-size: 14px; }
  .calendar-venue-chip { font-size: 10px; padding: 3px 5px; }
  .calendar-legend { display: none; }
  .calendar-month-label { font-size: 18px; min-width: 160px; }
}

/* ═══════════════════════════════════════════════════════════════════════════ */
/* ─── v4: SSE Connection Indicator ───────────────────────────────────────── */
/* ═══════════════════════════════════════════════════════════════════════════ */

.sse-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--sidebar-text);
  letter-spacing: 0.03em;
}

.sse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s ease;
}

.sse-dot.connected {
  background: #22c55e;
  box-shadow: 0 0 4px #22c55e;
}

.sse-dot.connecting {
  background: var(--warning);
  animation: sse-pulse 1.5s ease infinite;
}

.sse-dot.error {
  background: var(--danger);
}

@keyframes sse-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ─── v4: Race Status Indicators on Race Pills ────────────────────────── */

.race-pill .status-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  transition: background 0.3s ease;
}

.race-pill .status-bar.status-scheduled { background: var(--text-muted); }
.race-pill .status-bar.status-entries   { background: var(--text-tertiary); }
.race-pill .status-bar.status-odds      { background: var(--accent); opacity: 0.5; }
.race-pill .status-bar.status-weighed   { background: var(--accent); }
.race-pill .status-bar.status-result    { background: var(--warning); }
.race-pill .status-bar.status-final     { background: var(--success); }

/* Status tooltip on hover */
.race-pill[data-status]::after {
  content: attr(data-status-label);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 10;
  box-shadow: var(--shadow-md);
}

.race-pill[data-status]:hover::after { opacity: 1; }

/* ─── v4: Race Status Badge in Race Header ────────────────────────────── */

.badge-final   { background: var(--success-muted); color: var(--success); }
.badge-result  { background: var(--warning-muted); color: var(--warning); }
.badge-weighed { background: var(--accent-muted); color: var(--accent); }
.badge-odds    { background: rgba(140, 80, 200, 0.12); color: #7c3aed; }
.badge-entries { background: var(--bg-tertiary); color: var(--text-secondary); }
.badge-scheduled { background: var(--bg-tertiary); color: var(--text-muted); }

/* ─── v4: Last Update Banner ─────────────────────────────────────────── */

.last-update-banner {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 11px;
  color: var(--text-tertiary);
  margin-bottom: 0;
  margin-left: auto;
  white-space: nowrap;
}

.last-update-banner .sse-dot { flex-shrink: 0; }

.last-update-banner .update-time {
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.flash-update {
  animation: flash-green 0.6s ease;
}

@keyframes flash-green {
  0% { box-shadow: 0 0 0 0 rgba(34, 163, 85, 0.3); }
  50% { box-shadow: 0 0 8px 2px rgba(34, 163, 85, 0.15); }
  100% { box-shadow: var(--shadow-sm); }
}

/* ─── Utility ─────────────────────────────────────────────────────────────── */

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.ml-auto { margin-left: auto; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-muted { color: var(--text-tertiary); }
.text-accent { color: var(--accent); }
.font-mono { font-family: var(--font-mono); }
.font-jp { font-family: var(--font-jp); }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* ═══════════════════════════════════════════════════════════════════════════ */
/* ─── Waku (Bracket) Colors — JRA 8-bracket system ───────────────────────── */
/* ═══════════════════════════════════════════════════════════════════════════ */

.waku-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  font-family: var(--font-mono);
  line-height: 1;
}

/* ─── Payoffs Grid ────────────────────────────────────────────────────────── */

.payoffs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.payoff-card {
  margin: 0;
}

.payoff-card .data-table td {
  padding: 10px 14px;
}

.payoff-card .data-table .highlight {
  color: var(--accent);
  font-weight: 600;
  font-size: 15px;
}

.waku-1 { background: #ffffff; color: #1a1a1a; border: 1px solid #d0d0d0; }
.waku-2 { background: #1a1a1a; color: #ffffff; }
.waku-3 { background: #e03030; color: #ffffff; }
.waku-4 { background: #2070d0; color: #ffffff; }
.waku-5 { background: #e8c820; color: #1a1a1a; }
.waku-6 { background: #18a050; color: #ffffff; }
.waku-7 { background: #e87020; color: #ffffff; }
.waku-8 { background: #e860a0; color: #ffffff; }

/* ═══════════════════════════════════════════════════════════════════════════ */
/* ─── Odds Pool Tabs (HK Panel-style sub-tabs) ──────────────────────────── */
/* ═══════════════════════════════════════════════════════════════════════════ */

.odds-tab-container {
  padding: 0;
}

.odds-pool-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 0 20px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 16px;
}

.odds-pool-tab {
  padding: 8px 18px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.odds-pool-tab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border);
}

.odds-pool-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.odds-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  margin-bottom: 12px;
}

/* Responsive: stack pool tabs on narrow screens */
@media (max-width: 768px) {
  .odds-pool-tabs {
    gap: 6px;
  }
  .odds-pool-tab {
    padding: 7px 12px;
    font-size: 12px;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════ */
/* ─── JRA-style Odds Matrix Grid ─────────────────────────────────────────── */
/* ═══════════════════════════════════════════════════════════════════════════ */

/* --- Win/Place Odds Table ------------------------------------------------ */

.wp-table-wrap {
  overflow-x: auto;
}

.wp-table {
  width: auto;
  border-collapse: collapse;
  font-size: 14px;
}

.wp-table thead th {
  padding: 10px 12px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.wp-table tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light, var(--border));
  vertical-align: middle;
}

.wp-table .wp-row:hover td {
  background: var(--bg-hover);
}

.wp-row.wp-bracket-last td {
  border-bottom: 2px solid var(--border);
}

.wp-col-waku  { width: 44px; text-align: center; }
.wp-col-num   { width: 50px; text-align: center; }
.wp-col-name  { width: 220px; }
.wp-col-win   { width: 90px; text-align: right; }
.wp-col-place { width: 120px; text-align: right; }

.wp-cell-waku { text-align: center; vertical-align: middle; }
.wp-cell-num  { text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.wp-cell-name { font-family: var(--font-jp); }

.wp-cell-odds {
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono, monospace);
}

.wp-cell-place {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono, monospace);
}

.wp-place-val { font-weight: 500; }
.wp-place-sep { color: var(--text-muted); margin: 0 2px; }

.wp-name-en {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  font-family: var(--font-sans);
}

.wp-name-jp {
  font-size: 12px;
  color: var(--text-tertiary);
  font-family: var(--font-jp);
}

.wp-cell-odds.odds-hot,
.wp-cell-place.odds-hot {
  background: rgba(0, 184, 148, 0.12);
  color: var(--accent);
}

/* --- JRA-style Odds Matrix Grid ------------------------------------------ */

/* Wrapper: horizontal scroll for wide matrices */
.odds-matrix-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 0 12px;
}

/* Columns container: flex row of "column strips" */
.odds-matrix-cols {
  display: flex;
  gap: 3px;
  min-width: min-content;
}

/* Each column strip (one base number) */
.odds-matrix-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 80px;
  flex-shrink: 0;
}

/* Column header (horse/bracket number) */
.odds-matrix-col-hdr {
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 4px;
  position: sticky;
  top: 0;
  z-index: 5;
}

/* 2-row header for trifecta (1着 X / 2着 Y) */
.odds-matrix-col-hdr-2row {
  text-align: center;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 4px;
  line-height: 1.4;
  position: sticky;
  top: 0;
  z-index: 5;
}

.odds-matrix-col-hdr-2row b {
  font-weight: 700;
  font-size: 14px;
}

/* Each cell: row-number + odds value */
.odds-matrix-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  min-height: 32px;
  transition: background var(--transition-fast);
}

.odds-matrix-cell:hover {
  background: var(--bg-hover);
}

/* The row number label (counterpart horse/bracket) */
.odds-matrix-row-num {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  min-width: 20px;
  text-align: center;
  flex-shrink: 0;
}

/* The odds value */
.odds-matrix-val {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  text-align: right;
  flex: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums lining-nums;
}

/* Highlight: low odds (favorites) — JRA uses red */
.odds-fav .odds-matrix-val {
  color: var(--danger);
  font-weight: 700;
}

.odds-fav {
  background: var(--danger-muted);
  border-color: rgba(217, 54, 62, 0.2);
}

/* Self-pair cell (e.g. horse 3 × horse 3 in exacta) — greyed out */
.odds-matrix-self {
  background: var(--bg-tertiary);
  border-color: var(--border-subtle);
  opacity: 0.5;
}

.odds-matrix-self .odds-matrix-val {
  color: var(--text-muted);
}

/* ─── Trio / Trifecta Sections ───────────────────────────────────────────── */
/* Each "first horse" gets its own collapsible section */

.odds-trio-section {
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow-sm);
}

.odds-trio-section-hdr {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 4;
}

.odds-trio-section-hdr::before {
  content: '軸 ';
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--font-body);
}

.odds-trio-section > .odds-matrix-cols {
  padding: 10px 12px 14px;
  min-width: min-content;
}

/* ─── Bilingual sub-name styling (like HK panel) ───────────────────── */

.bi-sub {
  font-size: 12px;
  color: var(--text-tertiary);
  font-family: var(--font-body);
  line-height: 1.3;
}

/* ─── Language toggle button ──────────────────────────────────── */

.lang-toggle-btn {
  display: block;
  width: 100%;
  padding: 8px 12px;
  background: var(--sidebar-hover);
  color: var(--sidebar-text-bright);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-body);
  transition: background 0.2s;
  text-align: center;
  letter-spacing: 0.02em;
}

.lang-toggle-btn:hover {
  background: var(--sidebar-active);
}

/* ─── Matrix responsive: compact on narrow screens ───────────────────────── */

@media (max-width: 768px) {
  .odds-matrix-col {
    min-width: 70px;
  }
  .odds-matrix-cell {
    padding: 4px 6px;
    gap: 4px;
  }
  .odds-matrix-row-num {
    font-size: 11px;
    min-width: 16px;
  }
  .odds-matrix-val {
    font-size: 12px;
  }
  .odds-matrix-col-hdr {
    font-size: 13px;
    padding: 6px 3px;
  }
  .odds-trio-section-hdr {
    font-size: 14px;
    padding: 10px 14px;
  }
}
/* ============================================================
   COMPACT HEADER OVERRIDE — reduces top navigation from ~70% to ~35%
   Add this at the END of style.css (appends, does not replace)
   ============================================================ */

/* --- Page header: tighter padding --- */
.page-header {
    padding: 8px 20px !important;
    margin-bottom: 4px !important;
}
.page-header h1 {
    font-size: 18px !important;
    margin: 0 !important;
}
.page-header .subtitle,
.page-header p {
    font-size: 12px !important;
    margin: 0 !important;
}

/* --- Date picker row: single compact line --- */
.date-nav,
.date-picker-row,
.date-strip {
    padding: 4px 0 !important;
    margin: 0 !important;
    gap: 4px !important;
    align-items: center !important;
}
.date-nav input[type="date"],
.date-picker-row input[type="date"] {
    height: 28px !important;
    font-size: 13px !important;
    padding: 2px 6px !important;
}
.date-nav button,
.date-picker-row button,
.date-chip {
    height: 26px !important;
    padding: 2px 8px !important;
    font-size: 12px !important;
    line-height: 22px !important;
}
.live-indicator,
.live-badge {
    font-size: 11px !important;
    padding: 2px 8px !important;
}

/* --- Course tabs: compact single row --- */
.course-tabs,
.venue-tabs {
    padding: 2px 0 !important;
    margin: 0 !important;
    gap: 6px !important;
}
.course-tab,
.venue-tab {
    padding: 4px 12px !important;
    font-size: 13px !important;
    min-height: unset !important;
}
.course-tab .venue-name,
.venue-tab .venue-name {
    font-size: 13px !important;
}
.course-tab .venue-info,
.venue-tab .venue-info {
    font-size: 10px !important;
}

/* --- Course info bar: merge into one tight line --- */
.course-info,
.course-info-bar,
.venue-info-bar {
    padding: 3px 12px !important;
    margin: 0 !important;
    font-size: 12px !important;
    gap: 8px !important;
}

/* --- Race tabs (R01–R12): smaller pills --- */
.race-tabs,
.race-pills {
    padding: 2px 0 !important;
    margin: 0 !important;
    gap: 3px !important;
}
.race-tab,
.race-pill {
    padding: 4px 2px !important;
    font-size: 13px !important;
    min-height: unset !important;
    height: auto !important;
}
.race-tab .race-num,
.race-pill .race-num {
    font-size: 13px !important;
    line-height: 1.2 !important;
}
.race-tab .grade-label,
.race-pill .grade-label {
    font-size: 9px !important;
    line-height: 1.1 !important;
}

/* --- Race header (RACE 01 + Final confirmed): compact --- */
.race-header,
.race-title-bar {
    padding: 4px 12px !important;
    margin: 2px 0 !important;
}
.race-header h2,
.race-header h3,
.race-title {
    font-size: 15px !important;
    margin: 0 !important;
}
.race-status-badge {
    font-size: 11px !important;
    padding: 2px 8px !important;
}

/* --- Race meta line (POST, TRACK, DIST, etc.): one compact line --- */
.race-meta,
.race-details,
.race-info-line {
    padding: 2px 12px !important;
    margin: 0 !important;
    font-size: 12px !important;
    gap: 10px !important;
}

/* --- Data tabs (STARTERS, ODDS, etc.): compact --- */
.data-tabs,
.tab-bar,
.content-tabs {
    padding: 0 !important;
    margin: 2px 0 !important;
    gap: 0 !important;
}
.data-tab,
.tab-btn,
.content-tab {
    padding: 5px 14px !important;
    font-size: 13px !important;
}

/* --- Reduce all section gaps --- */
.race-day-content > *,
.main-content > *,
#main-content > * {
    margin-bottom: 2px !important;
}
/* ============================================================
   COMPACT HEADER v2 — merge RACE 01 + meta into one slim line
   Append to end of style.css
   ============================================================ */

/* --- Merge RACE 01 badge + race meta into a single flex row --- */
.race-header,
.race-title-bar {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 2px 8px !important;
    margin: 0 !important;
    gap: 8px !important;
    min-height: unset !important;
    flex-wrap: nowrap !important;
}

/* Race number badge — inline, small */
.race-header h2,
.race-header h3,
.race-title,
.race-label {
    font-size: 13px !important;
    margin: 0 !important;
    padding: 1px 8px !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
}

/* Status badge (Final confirmed) — small inline */
.race-status-badge,
.race-status {
    font-size: 10px !important;
    padding: 1px 6px !important;
    margin: 0 !important;
    flex-shrink: 0 !important;
}

/* --- Race meta line: inline with smaller text --- */
.race-meta,
.race-details,
.race-info-line {
    padding: 0 !important;
    margin: 0 !important;
    font-size: 11px !important;
    gap: 6px !important;
    line-height: 1.3 !important;
    display: flex !important;
    align-items: center !important;
    flex-wrap: wrap !important;
}
.race-meta span,
.race-details span,
.race-info-line span {
    font-size: 11px !important;
}

/* --- Course info bar: even tighter --- */
.course-info,
.course-info-bar,
.venue-info-bar {
    padding: 2px 8px !important;
    font-size: 11px !important;
    line-height: 1.3 !important;
}
/* ============================================================
   COMPACT HEADER v3 — targets actual class names from app.js
   Append to end of style.css
   ============================================================ */

/* --- Race header card: slim single-row layout --- */
.race-header-card {
    padding: 2px 8px !important;
    margin: 0 !important;
    gap: 0 !important;
}

/* --- Top row (RACE 01 + Final confirmed): compact inline --- */
.race-header-top {
    padding: 1px 0 !important;
    margin: 0 !important;
    min-height: unset !important;
    line-height: 1.2 !important;
}

/* --- Meta chips row (POST, TRACK, DIST, etc.): tight inline --- */
.race-header-meta {
    padding: 0 !important;
    margin: 0 !important;
    gap: 4px !important;
    line-height: 1.2 !important;
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
}

.race-meta-chip {
    font-size: 11px !important;
    padding: 0px 4px !important;
    margin: 0 !important;
    line-height: 1.3 !important;
}

.race-meta-chip .meta-label {
    font-size: 10px !important;
}

/* COMPACT HEADER v5 */
.race-header-card { margin-bottom: 2px !important; padding: 0 !important; border-radius: 4px !important; box-shadow: none !important; }
.race-header-top { padding: 4px 10px 2px !important; gap: 4px !important; align-items: center !important; min-height: unset !important; flex-wrap: nowrap !important; }
.race-badge-label { font-size: 13px !important; padding: 2px 8px !important; margin: 0 !important; margin-bottom: 0 !important; gap: 4px !important; }
.race-name-block { gap: 0 !important; margin: 0 !important; padding: 0 !important; min-width: unset !important; }
.race-name-jp { font-size: 14px !important; line-height: 1.2 !important; margin: 0 !important; padding: 0 !important; }
.race-name-en { font-size: 10px !important; line-height: 1.1 !important; margin: 0 !important; }
.grade-badge { font-size: 10px !important; padding: 0px 4px !important; }
.race-status, .status-badge { font-size: 10px !important; padding: 1px 6px !important; }
.race-header-meta { padding: 2px 10px 3px !important; margin: 0 !important; gap: 6px !important; border-bottom: none !important; }
.race-meta-chip { font-size: 12px !important; padding: 0 2px !important; gap: 3px !important; line-height: 1.2 !important; }
.race-meta-chip .meta-label { font-size: 9px !important; }

/* ─── DATA ENRICHMENT STYLES ─────────────────────────────── */
.blinker-badge { display:inline-block; background:#e8a735; color:#000; font-size:9px; font-weight:700; padding:0 3px; border-radius:2px; vertical-align:middle; margin-left:3px; line-height:1.4; }
.jockey-change-badge { display:inline-block; color:var(--danger,#ef4444); font-size:10px; margin-left:2px; cursor:help; }
.apprentice-badge { display:inline-block; color:var(--accent,#00bfa5); font-size:11px; margin-left:2px; }
.race-pace-bar { display:flex; flex-wrap:wrap; gap:8px; padding:4px 10px 6px; background:var(--bg-tertiary,rgba(255,255,255,0.03)); border-bottom:1px solid var(--border-subtle,rgba(255,255,255,0.06)); align-items:center; }
.pace-chip { display:inline-flex; align-items:center; gap:4px; font-size:12px; color:var(--text-secondary); }
.pace-chip .pace-label { font-size:9px; color:var(--text-muted); text-transform:uppercase; letter-spacing:0.05em; }
.pace-laps { font-size:11px; font-family:var(--font-mono,monospace); }
.pace-corners { font-size:11px; max-width:400px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.slope-training-panel { margin-top:8px; padding:8px 12px; background:var(--bg-tertiary,rgba(255,255,255,0.02)); border-radius:6px; border:1px solid var(--border-subtle,rgba(255,255,255,0.06)); }
.slope-title { font-size:12px; font-weight:600; color:var(--text-secondary); margin-bottom:4px; }
.slope-table { width:100%; font-size:12px; border-collapse:collapse; }
.slope-table th { font-size:10px; color:var(--text-muted); text-transform:uppercase; text-align:right; padding:2px 6px; border-bottom:1px solid var(--border-subtle,rgba(255,255,255,0.06)); }
.slope-table th:first-child, .slope-table td:first-child { text-align:left; }
.slope-table td { padding:2px 6px; text-align:right; color:var(--text-primary); }

/* ─── Training Tab ───────────────────────────────────────── */
.training-horse-block { margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border-subtle, rgba(255,255,255,0.06)); }
.training-horse-block:last-child { border-bottom: none; margin-bottom: 0; }
.training-horse-header { font-size: 14px; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }

/* ─── Race Summary (JRA-style タイム + コーナー) ─────────── */
.race-summary-section { padding: 12px 16px; border-top: 1px solid var(--border-subtle, rgba(255,255,255,0.06)); }
.race-summary-block { margin-bottom: 12px; }
.race-summary-block:last-child { margin-bottom: 0; }
.race-summary-title { font-size: 13px; font-weight: 700; color: var(--text-primary); margin-bottom: 6px; }
.race-summary-table { width: 100%; border-collapse: collapse; }
.race-summary-table td { padding: 4px 8px; font-size: 13px; border-bottom: 1px solid var(--border-subtle, rgba(255,255,255,0.04)); }
.race-summary-table .summary-label { width: 120px; color: var(--text-muted); font-size: 12px; white-space: nowrap; }

/* ─── FORM Tab Styles ──────────────────────────────────────────────────── */
.form-stats-table th, .form-stats-table td { white-space: nowrap; padding: 6px 8px; font-size: 0.82rem; }
.form-stats-table .form-horse-name { max-width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rs-counts { display: block; font-size: 0.7rem; color: var(--text-muted); font-family: var(--font-mono); margin-top: 1px; }
.form-detail-horse { border-bottom: 1px solid var(--border); cursor: pointer; }
.form-detail-horse:last-child { border-bottom: none; }
.form-detail-header { padding: 10px 16px; display: flex; align-items: center; gap: 8px; font-size: 0.9rem; font-weight: 500; user-select: none; }
.form-expand-icon { margin-left: auto; color: var(--text-muted); font-size: 0.75rem; transition: transform 0.2s; }
.form-detail-horse.expanded .form-expand-icon { transform: rotate(90deg); }
.form-detail-body { display: none; padding: 0 16px 12px; }
.form-detail-horse.expanded .form-detail-body { display: block; }
.form-breakdown-table { font-size: 0.8rem; }
.form-breakdown-table th, .form-breakdown-table td { padding: 4px 10px; }
.form-indent td:first-child { padding-left: 24px; color: var(--text-muted); font-size: 0.78rem; }
.form-history-horse { border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.form-history-horse:last-child { border-bottom: none; }
.form-history-header { padding: 10px 16px 6px; font-size: 0.9rem; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.form-history-count { margin-left: auto; font-size: 0.75rem; color: var(--text-muted); font-weight: 400; }
.form-history-table th, .form-history-table td { white-space: nowrap; padding: 4px 6px; font-size: 0.78rem; }
.form-field-count { color: var(--text-muted); font-size: 0.7rem; }
