:root {
  --cream: #1A2B3C;
  --dark: #C8DFF0;
  --brown: #8BAFD4;
  --gold: #E8B84B;
  --rust: #E05C5C;
  --sage: #4A9B7A;
  --sand: #7A9BB5;
  --paper: #243547;
  --green: #4A9B7A;
  /* Theme-aware variables */
  --thead-bg: #0D1B2A;
  --thead-color: #C8DFF0;
  --panel-bg: #0D1B2A;
  --text-primary: #C8DFF0;
  --bar-track-bg: #1a2a3a;
}

@keyframes db-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(74,155,122,0.6); }
  70%  { box-shadow: 0 0 0 7px rgba(74,155,122,0); }
  100% { box-shadow: 0 0 0 0 rgba(74,155,122,0); }
}

@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: #0D1B2A; color: #C8DFF0; font-family: 'Oxanium', Arial, sans-serif; min-height: 100vh; /* overflow-x:hidden removed — breaks position:fixed on mobile */ }
body::before { content: ''; position: fixed; inset: 0; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E"); pointer-events: none; z-index: 0; opacity: 0.4; }

header { background: #000000; padding: 0 32px 0 0; display: flex; align-items: center; border-bottom: 3px solid var(--sand); position: sticky; top: 0; z-index: 100; box-shadow: 0 4px 12px rgba(212, 175, 55, 0.15); }
.logo { font-family: 'Oxanium', Arial, sans-serif; font-size: 2.1rem; font-weight: 900; color: #E8E6E3; letter-spacing: 0.3em; padding: 16px 0; text-shadow: 0 2px 4px rgba(212, 175, 55, 0.3); }
.logo span { color: var(--gold); }
nav { display: flex; gap: 2px; flex-wrap: nowrap; }
nav button { background: none; border: none; color: var(--sand); font-family: 'Oxanium', Arial, sans-serif; font-size: 0.84rem; letter-spacing: 0.06em; text-transform: uppercase; padding: 18px 10px; cursor: pointer; transition: color 0.18s, border-color 0.18s; border-bottom: 3px solid transparent; margin-bottom: -3px; white-space: nowrap; }
nav button:hover { color: var(--sage); border-bottom-color: transparent; font-weight: 700; }
nav button.active { color: #ffffff; border-bottom-color: transparent; font-weight: 700; background: rgba(122,155,181,0.45); border-radius: 15px; margin-top:14px; margin-bottom:2px; padding: 3px 5px 2px 6px; border: 1px solid rgba(122,155,181,0.6); height:24px;}

main { max-width: 1440px; margin: 0 auto; padding: 36px 32px; position: relative; z-index: 1; }
.view { display: none; }
.view.active { display: block; }

.page-title { color: #C8DFF0; font-family: 'Oxanium', Arial, sans-serif; font-size: 2.8rem; font-weight: 900; line-height: 1.05; margin-bottom: 8px; letter-spacing: 0.02em; }
.page-subtitle { font-size: 0.8rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--sand); margin-bottom: 32px; }

.stats-row { display: flex; flex-wrap: nowrap; gap: 16px; margin-bottom: 40px; }
.stat-card { flex: 1 1 auto; min-width: 140px; background: #0D1B2A; color: #C8DFF0; padding: 18px 16px; border-radius: 3px; position: relative; overflow: hidden; border: 1px solid rgba(212,175,55,0.18); border-bottom: 3px solid rgba(255,255,255,0.35); box-shadow: 0 2px 12px rgba(0,0,0,0.35); transition: border-color 0.2s, box-shadow 0.2s; }
.stat-card:hover { border-color: rgba(232,184,75,0.4); border-bottom-color: rgba(255,255,255,0.35); box-shadow: 0 4px 20px rgba(0,0,0,0.5); outline: 1px solid #C8DFF0; }
.stat-value { font-family: 'Oxanium', Arial, sans-serif; font-size: 2.2rem; font-weight: 700; color: #C8DFF0; line-height: 1; letter-spacing: -0.01em; }
.stat-label { font-size: 0.9rem; font-weight: 700; letter-spacing: 0.15em; text-transform: uppercase; color: var(--sand); margin-top: 6px; }

.stat-card.stat-count { flex: 0 0 130px; min-width: 0; max-width: 130px; }
.stat-card.stat-table { flex: 1 1 200px; min-width: 180px; }
.table-wrap, .box { background: #1E2F42; border: 1px solid #7A9BB5; border-bottom: 3px solid rgba(255,255,255,0.35); border-radius: 2px; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.3); transition: border-color 0.2s ease, box-shadow 0.2s ease; }
.table-wrap::after, .box::after { display: none; }
.table-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid rgba(120,150,170,0.2); background: #0D1B2A; gap: 12px; flex-wrap: wrap; }
.search-box { display: flex; align-items: center; gap: 8px; background: var(--paper); border: 1px solid var(--sand); padding: 7px 12px; border-radius: 2px; min-width: 220px; }
.search-box input { border: none; outline: none; font-family: 'Oxanium', Arial, sans-serif; font-size: 0.96rem; background: transparent; width: 100%; color: #C8DFF0; }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; }
select, .filter-select { border: 1px solid var(--sand); background: #0D1B2A; font-family: 'Oxanium', Arial, sans-serif; font-size: 0.9rem; padding: 7px 10px; border-radius: 2px; color: #C8DFF0; cursor: pointer; outline: none; }

table { width: 100%; border-collapse: collapse; font-size: 0.96rem; }
thead tr { background: #0D1B2A; color: #C8DFF0; }
th { padding: 10px 13px; text-align: left; font-weight: 600; letter-spacing: 0.09em; text-transform: uppercase; font-size: 0.76rem; white-space: nowrap; color: #9db8cc; }
td { padding: 10px 13px; border-bottom: 1px solid rgba(180,160,130,0.15); vertical-align: middle; }
tbody tr { transition: background 0.15s; }
tbody tr:hover { background: rgba(212,175,55,0.1); }

.horse-name-cell { font-family: 'Oxanium', Arial, sans-serif; font-weight: 700; font-size: 1rem; color: #C8DFF0; }
#profile-race-table tbody tr { font-size: 0.94rem; }
#profile-race-table tbody tr:nth-child(even) { background: var(--paper); }
#profile-race-table tbody tr:hover { background: rgba(212,175,55,0.08); }
#profile-race-table tbody td { padding: 9px 12px; border-bottom: 1px solid rgba(180,160,130,0.2); }
#jp-race-table tbody tr { font-size: 0.94rem; }
#jp-race-table tbody tr:nth-child(even) { background: var(--paper); }
#jp-race-table tbody tr:hover { background: rgba(212,175,55,0.08); }
#jp-race-table tbody td { padding: 9px 12px; border-bottom: 1px solid rgba(180,160,130,0.2); }
.placement-badge { display: inline-block; min-width: 38px; height: 22px; border-radius: 3px; text-align: center; line-height: 22px; font-weight: 600; font-size: 0.8rem; padding: 0 7px; letter-spacing: 0.04em; }
.p1 { background: var(--gold); color: #000; font-weight: 700; }
.p2 { background: #999; color: white; }
.p3 { background: var(--brown); color: white; }
.pDNF { background: var(--rust); color: white; }
.pX { background: var(--paper); color: #C8DFF0; border: 1px solid var(--sand); }

.tag { display: inline-block; background: var(--sand); color: #C8DFF0; border-radius: 2px; padding: 1px 7px; font-size: 0.82rem; letter-spacing: 0.08em; text-transform: uppercase; margin: 1px; }
.tag-class {
  background: linear-gradient(135deg, rgba(212,175,55,0.2) 0%, rgba(212,175,55,0.3) 100%);
  color: #D4AF37;
  border: 1px solid rgba(212,175,55,0.4);
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
td .tag-class { padding: 3px 10px; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
.tag-class.solid { background: linear-gradient(135deg, #D4AF37 0%, #E8C86B 100%); color: #000; border: none; font-weight: 700; }
.tag-condition { background: #1C3A5E; color: #C8DFF0; }

.btn { font-family: 'Oxanium', Arial, sans-serif; font-size: 0.84rem; letter-spacing: 0.09em; text-transform: uppercase; padding: 8px 16px; border: none; border-radius: 3px; cursor: pointer; transition: all 0.18s; }
.btn-gold { background: linear-gradient(135deg, #D4AF37 0%, #E8C86B 100%); color: #000; font-weight: 600; box-shadow: 0 2px 8px rgba(212, 175, 55, 0.3); }
.btn-gold:hover { background: linear-gradient(135deg, #E8C86B 0%, #F4E5A8 100%); box-shadow: 0 4px 12px rgba(212, 175, 55, 0.5); }
.btn-outline { background: transparent; color: #C8DFF0; border: 1px solid #2C3E52; }
.btn-outline:hover { border-color: var(--gold); color: var(--gold); }
.btn-danger { background: transparent; color: var(--rust); border: 1px solid var(--rust); padding: 5px 10px; font-size: 0.84rem; }
.btn-danger:hover { background: var(--rust); color: white; }
.btn-suggest { background: var(--sage); color: white; }
.btn-suggest:hover { background: #5A8A6A; }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.75); display: none; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
#modal-track { z-index: 2000; }
.modal-overlay.open { display: flex; }
.modal { background: #1E2F42; color: #C8DFF0; border: 1px solid #2C3E52; border-top: 3px solid var(--sand); width: 680px; max-width: 96vw; max-height: 92vh; overflow-y: auto; border-radius: 3px; animation: slideUp 0.22s ease; box-shadow: 0 12px 48px rgba(0,0,0,0.6), 0 0 0 1px rgba(232,184,75,0.08); }
.modal-wide { width: 1100px !important; max-width: 96vw !important; }
.modal-header { padding: 22px 26px 0; display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-family: 'Oxanium', Arial, sans-serif; font-size: 1.5rem; font-weight: 700; color: #C8DFF0; letter-spacing: 0.02em; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 1.6rem; color: #C8DFF0; line-height: 1; }
.modal-body { padding: 18px 26px 26px; background: #1E2F42; color: #C8DFF0; }
.modal-label { display: block; font-size: 0.8rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: #7A9BB5; margin-bottom: 5px; }
.modal-input { width: 100%; box-sizing: border-box; background: #0D1B2A; border: 1px solid #2E4A66; border-radius: 4px; color: #C8DFF0; font-size: 0.9rem; padding: 9px 12px; outline: none; transition: border-color 0.15s; font-family: inherit; }
.modal-input:focus { border-color: #E8B84B; }
.modal-input option { background: #0D1B2A; color: #C8DFF0; }
.modal-input[type="file"] { padding: 0; cursor: pointer; }
.modal-input[type="file"]::file-selector-button { background: #2E4A66; border: none; border-right: 1px solid #3A5C80; color: #C8DFF0; font-family: 'Oxanium', sans-serif; font-size: 0.82rem; letter-spacing: 0.06em; padding: 9px 14px; cursor: pointer; transition: background 0.15s; }
.modal-input[type="file"]::file-selector-button:hover { background: #3A5C80; }

.sg-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.sg-table thead tr { background: #0D1B2A; color: #C8DFF0; }
.sg-table thead th { padding: 10px 12px; text-align: left; font-size: 0.75rem; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 600; color: #C8DFF0; white-space: nowrap; }
.sg-table thead th.center { text-align: center; }
.sg-table thead th.right  { text-align: right;  }
.sg-table tbody tr { border-bottom: 1px solid rgba(180,160,130,0.2); }
.sg-table tbody tr:hover { background: rgba(212,175,55,0.06); }
.sg-table tbody td { padding: 9px 12px; color: #C8DFF0; vertical-align: middle; }
.sg-table tbody td.center { text-align: center; }
.sg-table tbody td.right  { text-align: right;  }
.sg-table tbody td.muted  { color: #8BAFD4; font-size: 0.82rem; }
.sg-table tbody td.gold   { color: #C8DFF0; font-weight: 700; }
.sg-table tbody td.rank   { color: var(--sand); font-size: 0.78rem; }

.sg-section-label { font-size: 0.72rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--sand); margin-bottom: 10px; margin-top: 20px; border-bottom: 1px solid rgba(120,150,170,0.15); padding-bottom: 5px; }
.sg-panel-header { background: #0D1B2A; padding: 12px 18px; font-size: 0.78rem; letter-spacing: 0.14em; text-transform: uppercase; color: #C8DFF0; font-weight: 700; }
.sg-stat-card { background: #0D1B2A; border-radius: 2px; padding: 14px 12px; text-align: center; }
.sg-stat-value { font-size: 1.1rem; font-weight: 700; color: #C8DFF0; line-height: 1; }
.sg-stat-label { font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase; color: #8BAFD4; margin-top: 4px; }
.sg-table-scroll { overflow-x: auto; border: 1px solid var(--sand); border-radius: 2px; background: #1E2F42; }
select.sg-select { border: 1px solid var(--sand); background: #0D1B2A; color: #C8DFF0; font-family: 'Oxanium', Arial, sans-serif; font-size: 0.9rem; padding: 7px 10px; border-radius: 2px; outline: none; cursor: pointer; }
select.sg-select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(212,175,55,0.2); }

.form-section-label { font-size: 0.82rem; letter-spacing: 0.2em; text-transform: uppercase; color: #C8DFF0; border-bottom: 1px solid var(--sand); padding-bottom: 6px; margin: 18px 0 14px; grid-column: 1/-1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 0.84rem; letter-spacing: 0.13em; text-transform: uppercase; color: #C8DFF0; }
input[type="text"], input[type="date"], input[type="number"], textarea, select.form-select { border: 1px solid #2C3E52; background: #0D1B2A; color: #C8DFF0; font-family: 'Oxanium', Arial, sans-serif; font-size: 0.96rem; padding: 9px 11px; border-radius: 3px; outline: none; transition: border-color 0.18s, box-shadow 0.18s; width: 100%; }
input:focus, textarea:focus, select.form-select:focus { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(232,184,75,0.18); }
textarea { resize: vertical; min-height: 70px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--sand); }

.compare-select-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 20px; align-items: center; margin-bottom: 28px; }
.lineup-dd-item:hover { background: rgba(232,184,75,0.1); color: var(--gold); }
.vs-badge { font-family: 'Oxanium', Arial, sans-serif; font-size: 1.8rem; font-weight: 900; color: #C8DFF0; text-align: center; }
.compare-card { background: #1E2F42; border: 1px solid #7A9BB5; border-bottom: 3px solid rgba(255,255,255,0.35); border-radius: 2px; padding: 22px; box-shadow: 0 4px 12px rgba(0,0,0,0.3); position: relative; overflow: hidden; }
.compare-horse-name { font-family: 'Oxanium', Arial, sans-serif; font-size: 1.8rem; font-weight: 700; margin-bottom: 14px; }
.compare-stat { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid rgba(180,160,130,0.3); font-size: 0.96rem; }
.compare-stat-label { color: #8BAFD4; }
.winner-badge { display: inline-block; background: var(--gold); color: #000; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; padding: 2px 8px; border-radius: 2px; margin-left: 6px; vertical-align: middle; }
.ai-rec-box { background: #0D1B2A; color: var(--cream); border-left: 4px solid var(--gold); padding: 18px 22px; border-radius: 0 2px 2px 0; margin-top: 20px; font-size: 1.02rem; line-height: 1.8; }
.ai-rec-box strong { font-family: 'Oxanium', Arial, sans-serif; font-size: 1.3rem; color: #C8DFF0; display: block; margin-bottom: 6px; }

.suggest-form { background: #1E2F42; border: 1px solid #7A9BB5; border-radius: 2px; padding: 28px; margin-bottom: 28px; box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
.suggest-form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 20px; }
.suggest-result { background: #0D1B2A; color: var(--cream); border-radius: 2px; padding: 28px; }
.suggest-result h3 { font-family: 'Oxanium', Arial, sans-serif; font-size: 1.7rem; color: #C8DFF0; margin-bottom: 16px; }
.suggest-horse-row { display: flex; align-items: flex-start; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid rgba(255,255,255,0.08); gap: 14px; }
.suggest-horse-name { font-family: 'Oxanium', Arial, sans-serif; font-size: 1.3rem; }
.suggest-score-bar { flex: 1; margin: 0 14px; height: 8px; background: rgba(255,255,255,0.1); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.suggest-score-fill { height: 100%; background: var(--gold); border-radius: 4px; }
.suggest-score-val { font-size: 0.96rem; color: var(--sand); width: 50px; text-align: right; padding-top: 4px; }
.suggest-reason { font-size: 0.9rem; color: var(--sand); margin-top: 4px; line-height: 1.6; }
.suggest-rank-1 .suggest-horse-name { color: #C8DFF0; }

.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.chart-card { background: #1E2F42; border: 1px solid #7A9BB5; border-bottom: 3px solid rgba(255,255,255,0.35); border-radius: 2px; padding: 22px; box-shadow: 0 4px 12px rgba(0,0,0,0.3); transition: border-color 0.2s ease, box-shadow 0.2s ease; position: relative; overflow: hidden; }
.chart-card:hover, .box:hover, .table-wrap:hover { border-bottom-color: rgba(255,255,255,0.35); box-shadow: 0 8px 24px rgba(0,0,0,0.4); outline: none; }
.chart-title { font-size: 0.84rem; letter-spacing: 0.18em; text-transform: uppercase; color: #8BAFD4; margin-bottom: 18px; }
.bar-chart { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 200px 1fr 44px; align-items: center; gap: 10px; font-size: 0.94rem; }
.bar-label { color: #C8DFF0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 700; }
.bar-track { background: rgba(180,160,130,0.3); border-radius: 2px; height: 11px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 2px; width: 0; transition: width 3s ease-out; }
.bar-val { text-align: right; color: #8BAFD4; font-size: 0.85rem; }

.empty-state { text-align: center; padding: 50px 20px; color: #8BAFD4; }
.empty-state .ei { font-size: 3.1rem; margin-bottom: 10px; }
.empty-state p { font-size: 1.02rem; margin-bottom: 18px; }
.empty-compare { text-align: center; padding: 36px; color: #8BAFD4; font-size: 1.02rem; background: var(--paper); border: 1px dashed var(--sand); border-radius: 2px; }

#backup-banner { display:none; background:#7a3010; color:#fff; padding:10px 24px; font-size:0.85rem; display:flex; align-items:center; justify-content:space-between; gap:12px; }
#backup-banner.hidden { display:none !important; }
#backup-banner button { background:rgba(255,255,255,0.2); border:1px solid rgba(255,255,255,0.4); color:#fff; padding:4px 12px; border-radius:2px; cursor:pointer; font-size:0.8rem; }

.timeline-wrap { overflow-x:auto; padding:12px 0; }
.timeline-track { display:flex; align-items:center; gap:0; min-width:100%; position:relative; padding:20px 16px 8px; }
.timeline-dot { width:14px; height:14px; border-radius:50%; flex-shrink:0; cursor:pointer; position:relative; transition:transform 0.15s; z-index:2; }
.timeline-dot:hover { transform:scale(1.4); }
.timeline-line { flex:1; height:2px; background:rgba(180,160,130,0.3); min-width:12px; }
.timeline-label { font-size:0.62rem; color:#8BAFD4; text-align:center; margin-top:4px; white-space:nowrap; }

.heatmap-table { border-collapse:collapse; width:100%; font-size:0.78rem; }
.heatmap-table th { background:#0D1B2A; color:var(--sand); padding:6px 10px; text-align:center; font-weight:500; letter-spacing:0.08em; font-size:0.72rem; }
.heatmap-table td { padding:7px 10px; text-align:center; border:1px solid rgba(180,160,130,0.2); font-weight:600; font-size:0.82rem; }

.star-btn { background:none; border:none; cursor:pointer; font-size:1.1rem; padding:2px 6px; line-height:1; color:#8BAFD4; transition:color 0.15s,transform 0.15s; }
.star-btn:hover { transform:scale(1.25); }
.star-btn.starred { color:var(--gold); }

.fav-dropdown { display:none; position:absolute; top:calc(100% + 4px); left:0; background:#1E2F42; border:1px solid rgba(232,184,75,0.3); border-top:4px solid var(--gold); border-radius:3px; min-width:220px; z-index:9999; box-shadow:0 8px 32px rgba(212,175,55,0.3); padding:6px 0; }
.fav-dropdown.open { display:block; }
.fav-item { display:flex; align-items:center; justify-content:space-between; padding:9px 16px; cursor:pointer; font-size:0.9rem; color:#C8DFF0; transition:background 0.15s; }
.fav-item:hover { background:rgba(232,184,75,0.1); }
.fav-item-name { font-weight:700; color:#C8DFF0; }
.fav-empty { padding:14px 16px; color:#8BAFD4; font-size:0.85rem; text-align:center; }

@media print {
  body > *:not(#print-area) { display:none !important; }
  #print-area { display:block !important; }
}

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(120,150,170,0.4); border-radius: 4px; }

.data-menu-item {
  display: block; width: 100%; text-align: left;
  background: transparent; border: none; color: #C8DFF0;
  padding: 9px 20px; font-size: 0.9rem; cursor: pointer;
  font-family: inherit; letter-spacing: 0.04em; text-transform: none;
}
.data-menu-item:hover { background: rgba(212,175,55,0.15); color: var(--gold); }

/* ─── FOOTER ─────────────────────────────────────────────────────────────── */
#site-footer {
  background: #000000;
  border-top: 3px solid var(--sand);
  margin-top: 60px;
  position: relative;
  z-index: 1;
}
.footer-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 48px 32px 36px;
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr 1fr 1fr;
  gap: 40px;
}
.footer-brand .footer-logo {
  font-family: 'Oxanium', Arial, sans-serif;
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--gold);
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}
.footer-brand .footer-tagline {
  font-size: 0.84rem;
  color: var(--sand);
  letter-spacing: 0.1em;
  margin-bottom: 10px;
  line-height: 1.6;
}
.footer-brand .footer-version {
  font-size: 0.72rem;
  color: rgba(120,155,181,0.5);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.footer-col-title {
  font-family: 'Oxanium', Arial, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(232,184,75,0.2);
}
.footer-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.footer-links a {
  color: var(--sand);
  text-decoration: none;
  font-size: 0.88rem;
  letter-spacing: 0.04em;
  transition: color 0.18s;
}
.footer-links a:hover {
  color: var(--gold);
}
.footer-bottom {
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px 32px;
  border-top: 1px solid rgba(120,155,181,0.15);
  font-size: 0.76rem;
  color: rgba(120,155,181,0.5);
  letter-spacing: 0.1em;
  text-align: center;
}

/* ─── LIGHT THEME ────────────────────────────────────────────────────────── */
/* Bold & sporty — crisp white + deep navy accent. Dark mode inverted.        */
/* Navy accent:  #1A3A5C  (primary)  #2A5A8C  (hover/lighter)                 */
/* Backgrounds:  #FFFFFF  (surface)  #F2F5F8  (panel)  #E8EDF2  (subtle)      */
/* Text:         #0D1B2A  (primary)  #3A5570  (secondary/muted)                */

/* ── Base variables & page ─────────────────────────────────────────────── */
body[data-theme="light"] {
  background: #F2F5F8 !important;
  background-image: none !important;
  color: #0D1B2A;
  --gold:        #1A3A5C;   /* Navy — replaces gold everywhere              */
  --gold-hover:  #2A5A8C;   /* Lighter navy for hover states                */
  --brown:       #2A5A8C;   /* Mid-navy (was --brown / muted accent)        */
  --sand:        #3A5570;   /* Dark navy-grey (secondary text, borders)     */
  --dark:        #0D1B2A;   /* Near-black primary text                      */
  --cream:       #FFFFFF;   /* Card/surface white (was dark panel in dark)  */
  --paper:       #F2F5F8;   /* Page background (was deep navy paper)        */
  --thead-bg:    #E8EDF2;
  --thead-color: #0D1B2A;
  --panel-bg:    #E8EDF2;
  --text-primary:#0D1B2A;
  --bar-track-bg:#D4DAE1;
}
body[data-theme="light"]::before { opacity: 0 !important; }

/* ── Header ────────────────────────────────────────────────────────────── */
body[data-theme="light"] header {
  background: #FFFFFF;
  border-bottom-color: #1A3A5C;
  box-shadow: 0 4px 16px rgba(26,58,92,0.12);
}
body[data-theme="light"] .logo { color: #0D1B2A; text-shadow: none; }
body[data-theme="light"] .logo span { color: #1A3A5C; }
body[data-theme="light"] nav button { color: #3A5570; }
body[data-theme="light"] nav button:hover,
body[data-theme="light"] nav button.active { color: #1A3A5C; border-bottom-color: #1A3A5C; }

/* ── Page headings ──────────────────────────────────────────────────────── */
body[data-theme="light"] .page-title { color: #1A3A5C; }
body[data-theme="light"] .page-subtitle { color: #3A5570; }

/* ── Stat cards ─────────────────────────────────────────────────────────── */
body[data-theme="light"] .stat-card {
  background: #FFFFFF;
  color: #0D1B2A;
  border-color: rgba(26,58,92,0.15);
  box-shadow: 0 2px 8px rgba(26,58,92,0.08);
}
body[data-theme="light"] .stat-card::after {
  background: linear-gradient(90deg, #1A3A5C 0%, #2A5A8C 50%, #1A3A5C 100%);
  box-shadow: none;
}
body[data-theme="light"] .stat-card:hover { border-color: rgba(26,58,92,0.35); box-shadow: 0 4px 16px rgba(26,58,92,0.15); }
body[data-theme="light"] .stat-value { color: #0D1B2A; }
body[data-theme="light"] .stat-label { color: #3A5570; }

/* ── Tables ─────────────────────────────────────────────────────────────── */
body[data-theme="light"] .table-wrap, body[data-theme="light"] .box { background: #FFFFFF; border-color: #C8D4DE; box-shadow: 0 2px 8px rgba(26,58,92,0.08); }
body[data-theme="light"] .table-toolbar { background: #E8EDF2; border-color: #C8D4DE; }
body[data-theme="light"] .search-box { background: #FFFFFF; border-color: #A8B8C8; }
body[data-theme="light"] .search-box input { color: #0D1B2A; }
body[data-theme="light"] select,
body[data-theme="light"] .filter-select { background: #FFFFFF; color: #0D1B2A; border-color: #A8B8C8; }

body[data-theme="light"] thead tr { background: #E8EDF2; }
body[data-theme="light"] th { color: #1A3A5C; background: #E8EDF2; font-weight: 700; }
body[data-theme="light"] td { color: #0D1B2A; border-bottom-color: #D4DAE1; }
body[data-theme="light"] tbody tr:hover { background: rgba(26,58,92,0.05); }

body[data-theme="light"] .horse-name-cell { color: #0D1B2A; }
body[data-theme="light"] #profile-race-table tbody tr:nth-child(even),
body[data-theme="light"] #jp-race-table tbody tr:nth-child(even) { background: #F2F5F8; }

/* ── Placement badges ───────────────────────────────────────────────────── */
body[data-theme="light"] .p1 { background: #1A3A5C; color: #fff; }
body[data-theme="light"] .p3 { background: #2A5A8C; color: #fff; }
body[data-theme="light"] .pX { background: #E8EDF2; color: #0D1B2A; border-color: #A8B8C8; }

/* ── Tags ───────────────────────────────────────────────────────────────── */
body[data-theme="light"] .tag { background: #C8D4DE; color: #0D1B2A; }
body[data-theme="light"] .tag-condition { background: #D0E4F5; color: #1A3A5C; }
body[data-theme="light"] .tag-class { color: #1A3A5C; border-color: rgba(26,58,92,0.4); background: rgba(26,58,92,0.08); }

/* ── Buttons ────────────────────────────────────────────────────────────── */
body[data-theme="light"] .btn-gold { background: linear-gradient(135deg, #1A3A5C 0%, #2A5A8C 100%); color: #fff; box-shadow: 0 2px 8px rgba(26,58,92,0.25); }
body[data-theme="light"] .btn-gold:hover { background: linear-gradient(135deg, #2A5A8C 0%, #3A6A9C 100%); box-shadow: 0 4px 12px rgba(26,58,92,0.35); }
body[data-theme="light"] .btn-outline { color: #0D1B2A; border-color: #A8B8C8; }
body[data-theme="light"] .btn-outline:hover { border-color: #1A3A5C; color: #1A3A5C; }

/* ── Modals ─────────────────────────────────────────────────────────────── */
body[data-theme="light"] .modal-overlay { background: rgba(13,27,42,0.5); }
body[data-theme="light"] .modal { background: #FFFFFF; color: #0D1B2A; border-color: #C8D4DE; border-top-color: #1A3A5C; box-shadow: 0 12px 48px rgba(26,58,92,0.2); }
body[data-theme="light"] .modal-title { color: #0D1B2A; }
body[data-theme="light"] .modal-close { color: #3A5570; }
body[data-theme="light"] .modal-body { background: #FFFFFF; color: #0D1B2A; }
body[data-theme="light"] .modal-label { color: #3A5570; }
body[data-theme="light"] .modal-input { background: #F0F4F8; border-color: #B0C4D8; color: #0D1B2A; }
body[data-theme="light"] .modal-input:focus { border-color: #C8962A; }
body[data-theme="light"] .modal-input option { background: #F0F4F8; color: #0D1B2A; }
body[data-theme="light"] .modal-input[type="file"]::file-selector-button { background: #C8D4DE; border-right-color: #B0C4D8; color: #0D1B2A; }
body[data-theme="light"] .modal-input[type="file"]::file-selector-button:hover { background: #B0C4D8; }

/* ── SG (stats grid) tables ─────────────────────────────────────────────── */
body[data-theme="light"] .sg-table thead tr { background: #E8EDF2; }
body[data-theme="light"] .sg-table thead th { color: #1A3A5C; }
body[data-theme="light"] .sg-table tbody td { color: #0D1B2A; }
body[data-theme="light"] .sg-table tbody td.muted { color: #3A5570; }
body[data-theme="light"] .sg-table tbody tr { border-bottom-color: #D4DAE1; }
body[data-theme="light"] .sg-section-label { color: #3A5570; border-bottom-color: #D4DAE1; }
body[data-theme="light"] .sg-panel-header { background: #E8EDF2; color: #1A3A5C; }
body[data-theme="light"] .sg-stat-card { background: #E8EDF2; }
body[data-theme="light"] .sg-stat-value { color: #1A3A5C; }
body[data-theme="light"] .sg-stat-label { color: #3A5570; }
body[data-theme="light"] .sg-table-scroll { background: #FFFFFF; border-color: #C8D4DE; }
body[data-theme="light"] select.sg-select { background: #FFFFFF; color: #0D1B2A; border-color: #A8B8C8; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
body[data-theme="light"] label { color: #0D1B2A; }
body[data-theme="light"] .form-section-label { color: #0D1B2A; border-color: #A8B8C8; }
body[data-theme="light"] input[type="text"],
body[data-theme="light"] input[type="date"],
body[data-theme="light"] input[type="number"],
body[data-theme="light"] textarea,
body[data-theme="light"] select.form-select { background: #FFFFFF; color: #0D1B2A; border-color: #A8B8C8; }
body[data-theme="light"] input:focus,
body[data-theme="light"] textarea:focus,
body[data-theme="light"] select.form-select:focus { border-color: #1A3A5C; box-shadow: 0 0 0 2px rgba(26,58,92,0.15); }
body[data-theme="light"] .form-actions { border-color: #C8D4DE; }

/* ── Compare / suggest / charts ─────────────────────────────────────────── */
body[data-theme="light"] .compare-card { background: #FFFFFF; border-color: #C8D4DE; }
body[data-theme="light"] .compare-stat { border-bottom-color: #D4DAE1; }
body[data-theme="light"] .compare-stat-label { color: #3A5570; }
body[data-theme="light"] .compare-horse-name { color: #0D1B2A; }
body[data-theme="light"] .ai-rec-box { background: #E8EDF2; color: #0D1B2A; border-left-color: #1A3A5C; }
body[data-theme="light"] .ai-rec-box strong { color: #1A3A5C; }
body[data-theme="light"] .empty-compare { background: #F2F5F8; border-color: #C8D4DE; color: #3A5570; }

body[data-theme="light"] .suggest-form { background: #FFFFFF; border-color: #C8D4DE; }
body[data-theme="light"] .suggest-result { background: #E8EDF2; color: #0D1B2A; }
body[data-theme="light"] .suggest-result h3 { color: #1A3A5C; }
body[data-theme="light"] .suggest-horse-row { border-bottom-color: rgba(26,58,92,0.12); }
body[data-theme="light"] .suggest-score-bar { background: rgba(26,58,92,0.12); }
body[data-theme="light"] .suggest-score-fill { background: #1A3A5C; }
body[data-theme="light"] .suggest-score-val { color: #3A5570; }
body[data-theme="light"] .suggest-reason { color: #3A5570; }
body[data-theme="light"] .suggest-rank-1 .suggest-horse-name { color: #1A3A5C; }

body[data-theme="light"] .chart-card { background: #FFFFFF; border-color: #C8D4DE; }
body[data-theme="light"] .chart-title { color: #1A3A5C; }
body[data-theme="light"] .bar-label { color: #0D1B2A; }
body[data-theme="light"] .bar-track { background: #D4DAE1; }
body[data-theme="light"] .bar-val { color: #3A5570; }
body[data-theme="light"] .bar-fill { background: #1A3A5C; }
body[data-theme="light"] .empty-state { color: #3A5570; }

/* ── Misc widgets ───────────────────────────────────────────────────────── */
body[data-theme="light"] .vs-badge { color: #1A3A5C; }
body[data-theme="light"] .winner-badge { background: #1A3A5C; color: #fff; }

body[data-theme="light"] .timeline-line { background: rgba(26,58,92,0.2); }
body[data-theme="light"] .timeline-label { color: #3A5570; }

body[data-theme="light"] .heatmap-table th { background: #E8EDF2; color: #1A3A5C; }
body[data-theme="light"] .heatmap-table td { border-color: #D4DAE1; }

body[data-theme="light"] .star-btn { color: #A8B8C8; }
body[data-theme="light"] .star-btn.starred { color: #1A3A5C; }

body[data-theme="light"] .fav-dropdown { background: #FFFFFF; border-color: rgba(26,58,92,0.2); border-top-color: #1A3A5C; box-shadow: 0 8px 32px rgba(26,58,92,0.15); }
body[data-theme="light"] .fav-item { color: #0D1B2A; }
body[data-theme="light"] .fav-item:hover { background: rgba(26,58,92,0.06); }
body[data-theme="light"] .fav-item-name { color: #1A3A5C; }
body[data-theme="light"] .fav-empty { color: #3A5570; }

body[data-theme="light"] .data-menu-item { color: #0D1B2A; }
body[data-theme="light"] .data-menu-item:hover { background: rgba(26,58,92,0.08); color: #1A3A5C; }
body[data-theme="light"] #data-menu,
body[data-theme="light"] #horses-nav-menu { background: #FFFFFF; border-color: rgba(26,58,92,0.2); }

body[data-theme="light"] #backup-banner { background: #c0622a; }

/* ── DB count badge ─────────────────────────────────────────────────────── */
body[data-theme="light"] #db-count-badge { background: #E8EDF2 !important; border-color: #C8D4DE !important; color: #1A3A5C !important; }

/* ── Theme toggle ───────────────────────────────────────────────────────── */
#theme-toggle {
  background: none; border: none; cursor: pointer;
  font-size: 1.25rem; padding: 8px 10px;
  color: var(--sand); transition: color 0.18s, transform 0.2s; line-height: 1;
}
#theme-toggle:hover { color: var(--gold); transform: scale(1.15); }
body[data-theme="light"] #theme-toggle { color: #3A5570; }
body[data-theme="light"] #theme-toggle:hover { color: #1A3A5C; }

/* ── Footer ─────────────────────────────────────────────────────────────── */
body[data-theme="light"] #site-footer { background: #1A3A5C; border-top-color: var(--gold); }
body[data-theme="light"] .footer-brand .footer-logo { color: #FFFFFF; }
body[data-theme="light"] .footer-brand .footer-tagline { color: rgba(255,255,255,0.65); }
body[data-theme="light"] .footer-brand .footer-version { color: rgba(255,255,255,0.35); }
body[data-theme="light"] .footer-col-title { color: var(--gold); border-color: rgba(232,184,75,0.3); }
body[data-theme="light"] .footer-links a { color: rgba(255,255,255,0.65); }
body[data-theme="light"] .footer-links a:hover { color: var(--gold); }
body[data-theme="light"] .footer-bottom { color: rgba(255,255,255,0.35); border-color: rgba(255,255,255,0.1); }

/* ── Hardcoded inline-style overrides (JS-rendered content) ─────────────── */
/* Dark panels → white surface */
body[data-theme="light"] [style*="background:#1E2F42"] { background: #FFFFFF !important; }
body[data-theme="light"] [style*="background:#0D1B2A"] { background: #E8EDF2 !important; }
body[data-theme="light"] [style*="background:#1a2736"] { background: #E8EDF2 !important; }
body[data-theme="light"] [style*="background:#1A2B3C"] { background: #E8EDF2 !important; }
body[data-theme="light"] [style*="background:#243547"] { background: #FFFFFF !important; }
/* Light text → dark text */
body[data-theme="light"] [style*="color:#C8DFF0"]:not(#site-footer *) { color: #0D1B2A !important; }
body[data-theme="light"] [style*="color:#8BAFD4"]:not(#site-footer *) { color: #3A5570 !important; }
body[data-theme="light"] [style*="color:#7A9BB5"]:not(#site-footer *) { color: #3A5570 !important; }
body[data-theme="light"] [style*="color:#9db8cc"]:not(#site-footer *) { color: #3A5570 !important; }
/* Gold → navy */
body[data-theme="light"] [style*="color:var(--gold)"],
body[data-theme="light"] [style*="color: var(--gold)"] { color: #1A3A5C !important; }

/* ── Speed records ──────────────────────────────────────────────────────── */
body[data-theme="light"] #speed-records-body [style*="background:var(--paper)"],
body[data-theme="light"] #speed-records-body [style*="background: var(--paper)"] { background: #FFFFFF !important; border-color: #C8D4DE !important; }
body[data-theme="light"] #speed-records-body [style*="background:#0D1B2A"] { background: #E8EDF2 !important; }
body[data-theme="light"] #speed-records-body [style*="color:#C8DFF0"] { color: #0D1B2A !important; }
body[data-theme="light"] #speed-records-body [style*="color:#8BAFD4"] { color: #3A5570 !important; }
body[data-theme="light"] #speed-records-body [style*="color:#fff"] { color: #0D1B2A !important; }
body[data-theme="light"] #speed-records-body td { border-bottom-color: #D4DAE1; }
body[data-theme="light"] #speed-records-body thead tr { background: #E8EDF2 !important; }
body[data-theme="light"] #speed-records-body th { color: #1A3A5C !important; }
body[data-theme="light"] #speed-records-body tbody tr:hover { background: rgba(26,58,92,0.05); }

/* ── Pagination & modal footers ─────────────────────────────────────────── */
body[data-theme="light"] #horses-pagination,
body[data-theme="light"] #jockeys-pagination,
body[data-theme="light"] #trainers-pagination,
body[data-theme="light"] #tracks-pagination,
body[data-theme="light"] #races-pagination,
body[data-theme="light"] #race-list-page-info,
body[data-theme="light"] [style*="background:var(--cream)"],
body[data-theme="light"] [style*="background: var(--cream)"] {
  background: #E8EDF2 !important;
  border-top-color: #C8D4DE !important;
  color: #0D1B2A !important;
}
body[data-theme="light"] #horses-pagination span,
body[data-theme="light"] #jockeys-pagination span,
body[data-theme="light"] #trainers-pagination span,
body[data-theme="light"] #tracks-pagination span,
body[data-theme="light"] #races-pagination span { color: #1A3A5C !important; }

/* ── Dashboard boxes without border class ───────────────────────────────── */
body[data-theme="light"] #recent-races-table,
body[data-theme="light"] #hot-horses-list { border: 1px solid #C8D4DE; border-radius: 2px; color: #0D1B2A; }

/* ── Suppress gold stripe on scrollable recent-races box (it floats mid-content) */
#recent-races-table::after { display: none; }

/* ── THICK BOTTOM BORDER ON ALL BOXES (dark + light) ───────────────────── */
.table-wrap,
.box,
.chart-card,
.compare-card,
.suggest-form,
.sg-table-scroll,
.modal {
  position: relative;
}
.table-wrap::after,
.box::after,
.chart-card::after,
.compare-card::after,
.suggest-form::after,
.sg-table-scroll::after,
.modal::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, #D4AF37 0%, #F4E5A8 50%, #D4AF37 100%);
  box-shadow: 0 0 6px rgba(212,175,55,0.5);
  pointer-events: none;
  z-index: 1;
}
/* Light mode — navy stripe instead of gold */
body[data-theme="light"] .table-wrap::after,
body[data-theme="light"] .box::after,
body[data-theme="light"] .chart-card::after,
body[data-theme="light"] .compare-card::after,
body[data-theme="light"] .suggest-form::after,
body[data-theme="light"] .sg-table-scroll::after,
body[data-theme="light"] .modal::after {
  background: linear-gradient(90deg, #1A3A5C 0%, #2A5A8C 50%, #1A3A5C 100%);
  box-shadow: none;
}
.nav-locked { opacity: 0.55; cursor: pointer; }

/* ── Privacy Policy Modal ─────────────────────────────────────── */
.privacy-meta {
  color: rgba(255,255,255,0.4);
  font-size: 0.78rem;
  margin-bottom: 20px;
}
.privacy-section-label {
  color: var(--gold);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 20px 0 6px;
}
body[data-theme="light"] .privacy-meta {
  color: rgba(13,27,42,0.45);
}
body[data-theme="light"] #modal-privacy .modal-body p,
body[data-theme="light"] #modal-privacy .modal-body strong {
  color: #0D1B2A;
}
body[data-theme="light"] #modal-privacy .modal-body strong {
  color: #0D1B2A;
}

/* ── Footer ───────────────────────────────────────────────────── */

/* ── Ticker (light theme) ─────────────────────────────────────── */
body[data-theme="light"] #track-ticker-wrap { background: #E8EDF2; border-radius: 3px; }
body[data-theme="light"] #track-ticker-inner * { color: #0D1B2A !important; }
body[data-theme="light"] #track-ticker-inner [style*="color:#C8DFF0"] { color: #0D1B2A !important; }
body[data-theme="light"] #track-ticker-inner [style*="color:#ffffff"],
body[data-theme="light"] #track-ticker-inner [style*="color: #ffffff"],
body[data-theme="light"] #track-ticker-inner [style*="color:white"],
body[data-theme="light"] #track-ticker-inner [style*="color:#fff"] { color: #0D1B2A !important; }
body[data-theme="light"] #track-ticker-inner [style*="background:#1E2F42"] { background: #ffffff !important; }
body[data-theme="light"] #track-ticker-inner [style*="background:#0D1B2A"] { background: #D4DCE5 !important; }
body[data-theme="light"] #track-ticker-inner [style*="background:rgba(0,0,0"] { background: rgba(26,58,92,0.08) !important; }

/* ── Post Position Heatmap (light theme) ─────────────────────── */
body[data-theme="light"] #pp-heatmap { background: #ffffff; }
body[data-theme="light"] #pp-heatmap th { color: #3A5570 !important; }
body[data-theme="light"] #pp-heatmap td { color: #0D1B2A !important; }

/* ── Matrix Page ───────────────────────────────────────────────── */
.matrix-card {
  background: var(--paper, #111E2D);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 4px;
  padding: 10px 12px;
  min-width: 0;
}
.matrix-card-header {
  position: sticky;
  top: 0;
  background: var(--paper, #111E2D);
  z-index: 1;
}
.matrix-card-scroll {
  max-height: 200px;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.12) transparent;
}
.matrix-card-scroll::-webkit-scrollbar { width: 2px; }
.matrix-card-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 2px; }
.matrix-card-scroll::-webkit-scrollbar-track { background: transparent; }

/* ================================================================
   RESPONSIVE — MOBILE & TABLET
   These rules live here (after all base styles) so they win the
   cascade over everything above, including nav/header rules.
   ================================================================ */

/* ── PHONE ≤ 768px ─────────────────────────────────────────────── */
@media (max-width: 768px) {

  header {
    padding: 0 8px 0 0 !important;
    flex-wrap: wrap;
  }
  .nav-logo-link { margin-left: 12px !important; }
  .nav-logo-link img { height: 50px !important; }

  /* Hide desktop nav, show hamburger */
  nav#main-nav, header > nav { display: none !important; }
  #nav-hamburger { display: block !important; }

  .nav-right { padding-right: 8px !important; gap: 6px !important; }
  #user-nav-wrap > button { font-size: 0.75rem !important; padding: 5px 8px !important; }
  #user-nav-menu { min-width: 200px !important; }

  #mobile-nav-drawer { position: absolute; top: 100%; left: 0; width: 100%; }

  /* Main */
  main { padding: 12px 10px !important; max-width: 100vw !important; }
  .page-title    { font-size: 1.3rem !important; }
  .page-subtitle { font-size: 0.8rem !important; margin-bottom: 16px !important; }

  /* Stats row — inline style has flex-wrap:nowrap */
  .stats-row { flex-wrap: wrap !important; gap: 10px !important; margin-bottom: 16px !important; }
  .stat-card, .stat-card.stat-table, .stat-card.stat-count {
    flex: 1 1 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  /* DB badge */
  #db-count-badge { flex-wrap: wrap !important; gap: 8px !important; font-size: 0.78rem !important; padding: 8px 12px !important; }
  #db-data-range-hint { margin-left: 0 !important; }

  /* Dashboard grid (inline: grid-template-columns:270px 1fr) */
  div[style*="grid-template-columns:270px"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 18px !important;
    width: 100% !important;
  }
  div[style*="grid-template-columns:270px"] > div { min-width: 0 !important; width: 100% !important; }

  #recent-races-track-filter { width: 100% !important; margin-top: 6px !important; }

  /* Tables */
  .table-wrap { overflow-x: auto !important; }
  .search-box  { min-width: 0 !important; width: 100% !important; }
  .filter-row  { flex-wrap: wrap !important; gap: 6px !important; }
  .filter-row select { flex: 1 1 calc(50% - 6px) !important; min-width: 120px !important; }

  /* Charts */
  .chart-grid { grid-template-columns: 1fr !important; }
  .bar-row    { grid-template-columns: 100px 1fr 40px !important; font-size: 0.82rem !important; }

  /* Compare / forms */
  .compare-select-row  { grid-template-columns: 1fr !important; }
  .suggest-form-grid   { grid-template-columns: 1fr !important; }
  .form-grid           { grid-template-columns: 1fr !important; }

  /* Modals */
  .modal { width: 97vw !important; min-width: 0 !important; max-width: 97vw !important; max-height: 92vh !important; }

  /* Banners */
  #trial-banner    { flex-direction: column !important; align-items: flex-start !important; gap: 8px !important; }
  #data-tip-banner { flex-direction: column !important; align-items: flex-start !important; padding: 10px 12px !important; }

  /* Heatmap — 1000px wide inline, hide on phone */
  div[style*="width:1000px"] { display: none !important; }
}

/* ── TABLET 769px–1024px ───────────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {

  main { padding: 20px 18px !important; }
  nav#main-nav, header > nav { flex-wrap: wrap !important; }

  .stats-row { flex-wrap: wrap !important; }
  .stat-card.stat-table { flex: 1 1 calc(50% - 16px) !important; min-width: 0 !important; }

  div[style*="grid-template-columns:270px"] { grid-template-columns: 200px 1fr !important; gap: 16px !important; }

  div[style*="width:1000px"] { width: 100% !important; overflow-x: auto !important; }

  .modal { width: 88vw !important; min-width: 0 !important; }
}

/* ── Force loader to be fullscreen centered ── */
#tp-loader {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  z-index: 99999 !important;
}
#tp-loader img {
  max-width: 80vw !important;
  max-height: 40vh !important;
  width: auto !important;
  height: auto !important;
}
#tp-loader-bar-wrap {
  width: min(260px, 80vw) !important;
}

/* ── Force all modal overlays to be truly fullscreen centered ── */
.modal-overlay {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  display: none;
  align-items: center !important;
  justify-content: center !important;
}
.modal-overlay.open {
  display: flex !important;
}

/* ── Mobile/tablet footer safety fixes ──────────────────────────────── */
@media (max-width: 768px) {
  #site-footer {
    overflow: hidden;
  }

  #site-footer .footer-inner {
    width: 100%;
    max-width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 22px 16px;
    padding: 30px 16px 24px;
  }

  #site-footer .footer-brand {
    grid-column: 1 / -1;
    min-width: 0;
    text-align: center;
  }

  #site-footer .footer-col {
    min-width: 0;
  }

  #site-footer .footer-brand .footer-logo img {
    height: 104px !important;
    max-width: 100%;
    width: auto;
  }

  #site-footer .footer-col-title {
    font-size: 0.68rem;
    letter-spacing: 0.14em;
    margin-bottom: 12px;
  }

  #site-footer .footer-links {
    gap: 8px;
  }

  #site-footer .footer-links a {
    display: inline-block;
    max-width: 100%;
    font-size: 0.82rem;
    line-height: 1.35;
  }

  #site-footer .footer-links a,
  #site-footer .footer-tagline,
  #site-footer .footer-bottom {
    overflow-wrap: anywhere;
    word-break: normal;
  }

  #site-footer .footer-bottom {
    width: 100%;
    max-width: 100%;
    padding: 14px 16px;
    line-height: 1.5;
  }

  #modal-contact div[style*="grid-template-columns:1fr 1fr"],
  #modal-feedback div[style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  #modal-contact .modal-body,
  #modal-feedback .modal-body {
    padding: 16px 18px 22px !important;
  }
}

@media (max-width: 360px) {
  #site-footer .footer-inner {
    gap: 20px 12px;
    padding-left: 14px;
    padding-right: 14px;
  }

  #site-footer .footer-links a {
    font-size: 0.78rem;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  #site-footer .footer-inner {
    width: 100%;
    max-width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 30px;
    padding: 42px 24px 30px;
  }

  #site-footer .footer-brand {
    grid-column: 1 / -1;
    min-width: 0;
  }

  #site-footer .footer-col {
    min-width: 0;
  }

  #site-footer .footer-brand .footer-logo img {
    height: 130px !important;
    max-width: 100%;
    width: auto;
  }

  #site-footer .footer-bottom {
    max-width: 100%;
    padding-left: 24px;
    padding-right: 24px;
  }
}


/* ── Phone overflow/header safety patch ─────────────────────────────────── */
@media (max-width: 768px) {
  html {
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    max-width: 100%;
    overflow-x: clip;
  }

  header.main-header {
    width: 100%;
    max-width: 100vw;
    min-height: 62px;
    padding: 0 8px 0 0 !important;
    flex-wrap: nowrap !important;
  }

  header.main-header .main-nav {
    display: none !important;
  }

  header.main-header .login-link,
  header.main-header .free-trial-link {
    display: none !important;
  }

  header.main-header .nav-right {
    flex: 0 1 auto !important;
    margin-left: auto !important;
    min-width: 0 !important;
    max-width: calc(100vw - 88px) !important;
  }

  header.main-header .user-btn {
    max-width: calc(100vw - 170px) !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }

  header.main-header .badge-role {
    display: none !important;
  }

  header.main-header #mobile-nav-drawer {
    width: 100vw !important;
    max-width: 100vw !important;
    max-height: calc(100vh - 62px) !important;
    overflow-y: auto !important;
  }
}
