:root {
  --bg: #0b1020;
  --panel: #121a2e;
  --panel-2: #172138;
  --line: #233052;
  --text: #e8ecf5;
  --muted: #8a96b3;
  --odd: #f2b62a;
  --pos: #34c77b;
  --neg: #f0525c;
  --win-bg: #12372b;
  --accent: #f2a516;
  --ok: #34c77b;
  --warn: #f2b62a;
  --off: #f0525c;
  --info: #3b82f6;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 28px; display: grid; gap: 14px; border-top: 4px solid var(--accent);
}
.auth-card h1 { margin: 0; font-size: 20px; }
.auth-card p { margin: 0; }
.auth-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-card input {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; font-size: 15px;
}
.auth-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.auth-card input.code { letter-spacing: 6px; font-size: 22px; text-align: center; }
.auth-card button {
  background: var(--accent); color: #1a1300; border: 0; border-radius: 8px; padding: 11px; font-weight: 700;
  font-size: 15px; cursor: pointer;
}
.alert { background: rgba(240, 82, 92, .12); border: 1px solid rgba(240, 82, 92, .5); color: #ffb3b8; padding: 10px 12px; border-radius: 8px; }
.center { padding: 40px 16px; text-align: center; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel);
  border-bottom: 3px solid var(--accent); position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 800; letter-spacing: .5px; }
.brand span { color: var(--muted); font-weight: 500; }
.refresh { margin-left: auto; color: var(--muted); font-size: 12px; }
.refresh.err { color: var(--neg); }
.who { display: flex; gap: 10px; align-items: center; }
.who form { margin: 0; }
button.link { background: none; border: 0; color: var(--text); text-decoration: underline; cursor: pointer; padding: 0; font: inherit; }

main#board { padding: 14px 16px 40px; }

/* ---------- Bookmaker strip ---------- */
.bk-strip { margin-bottom: 14px; }
.bk-summary { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; color: var(--muted); }
.bk-summary strong { color: var(--text); }
.bk-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.bk {
  display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; cursor: default;
}
.bk-code { font-weight: 700; }
.bk-meta { color: var(--muted); font-size: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.bk.st-ok .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(52, 199, 123, .18); }
.bk.st-warn .dot { background: var(--warn); }
.bk.st-offline .dot, .bk.st-error .dot { background: var(--off); }
.bk.st-offline, .bk.st-error { border-color: rgba(240, 82, 92, .45); }
.warn-mark {
  display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%;
  background: var(--warn); color: #1a1300; font-weight: 800; font-size: 11px; margin-left: 4px; cursor: help;
}

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--panel-2); color: var(--muted); }
.pill.st-ok { background: rgba(52, 199, 123, .15); color: var(--ok); }
.pill.st-warn { background: rgba(242, 182, 42, .15); color: var(--warn); }
.pill.st-offline, .pill.st-error { background: rgba(240, 82, 92, .15); color: var(--neg); }

/* ---------- Meeting + tabs ---------- */
.meeting-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.meeting-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.meeting-title h1 { margin: 0; font-size: 20px; }
.meeting-switch { display: flex; gap: 6px; flex-wrap: wrap; }
.meeting-switch a { padding: 4px 10px; border-radius: 6px; background: var(--panel); border: 1px solid var(--line); text-decoration: none; font-size: 12px; }
.meeting-switch a.active { border-color: var(--accent); color: var(--accent); }

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 0; scrollbar-width: thin; }
.tab {
  display: flex; align-items: center; gap: 6px; padding: 9px 14px; text-decoration: none; white-space: nowrap;
  border-radius: 8px 8px 0 0; color: var(--muted); font-weight: 600;
}
.tab:hover { color: var(--text); background: var(--panel); }
.tab.active { background: var(--panel); color: var(--text); box-shadow: inset 0 3px 0 var(--accent); }
.tab-time { font-weight: 400; font-size: 12px; }
.tab-dot { width: 7px; height: 7px; border-radius: 50%; }
.tab-dot.open { background: var(--ok); }
.tab-dot.closed { background: var(--neg); }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; max-height: calc(100vh - 230px); background: var(--panel); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 10px 10px; }
table.grid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
.grid th, .grid td { padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid th { background: #0e1528; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; font-weight: 600; position: sticky; z-index: 2; }
.grid thead tr:nth-child(1) th { top: 0; }
.grid thead tr:nth-child(2) th { top: 33px; }
.grid thead tr.totals td { position: sticky; top: 63px; z-index: 2; background: #0e1528; font-weight: 700; font-size: 15px; border-bottom: 2px solid var(--line); }
.grid .l { text-align: left; }
.grid td.no { color: var(--muted); width: 36px; }
.grid td.horse { font-weight: 700; text-transform: uppercase; min-width: 190px; }

/* Sticky first two columns */
.race th.no, .race td.no { position: sticky; left: 0; z-index: 3; background: var(--panel); }
.race th.horse, .race td.horse { position: sticky; left: 36px; z-index: 3; background: var(--panel); box-shadow: 1px 0 0 var(--line); }
.race thead th.no, .race thead th.horse { z-index: 5; background: #0e1528; }
.race thead tr.totals td:nth-child(-n+2) { left: 0; z-index: 5; }
.race thead tr.totals td:nth-child(2) { left: 36px; }
.overview th.l, .overview td.l { position: sticky; left: 0; z-index: 3; background: var(--panel); }
.overview thead th.l { z-index: 5; background: #0e1528; }

.bk-head { color: var(--text) !important; font-size: 13px !important; text-align: center !important; border-left: 2px solid var(--line); }
.grid .gs { border-left: 2px solid var(--line); }
.grid .gs.ga { border-left-color: rgba(242, 165, 22, .45); }
.bk-head.st-warn { box-shadow: inset 0 -2px 0 var(--warn); }
.bk-head.st-offline, .bk-head.st-error { box-shadow: inset 0 -2px 0 var(--off); opacity: .75; }
.all-head { color: var(--accent) !important; font-size: 13px !important; text-align: center !important; border-left: 2px solid var(--accent); }
td.all { background: rgba(242, 165, 22, .06); font-weight: 700; }

.grid tbody tr:hover td { background: var(--panel-2); }
.grid tbody tr:hover td.no, .grid tbody tr:hover td.horse { background: var(--panel-2); }
.odd { color: var(--odd); font-weight: 700; font-size: 15px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
td.na { color: #4a5678; text-align: center; }
td.scr { color: var(--muted); font-weight: 600; }
tr.scr-row td.horse { color: var(--muted); text-decoration: line-through; }
tr.winner td, tr.winner td.no, tr.winner td.horse { background: var(--win-bg); }

.badge { display: inline-block; font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 4px; letter-spacing: .4px; vertical-align: middle; background: var(--panel-2); color: var(--muted); }
.badge.open { background: #14532d; color: #6ee7a5; }
.badge.closed { background: #7f1d1d; color: #fecaca; }
.badge.sp { background: #1e3a8a; color: #bfdbfe; }
.badge.win { background: #166534; color: #bbf7d0; margin-left: 6px; }
.badge.sus { background: #713f12; color: #fde68a; }
.badge.ea { background: #3b0764; color: #e9d5ff; }

.legend { font-size: 12px; margin: 10px 2px 0; max-width: 900px; }
.empty-state { padding: 40px 0; text-align: center; }

@media (max-width: 640px) {
  .topbar { gap: 10px; }
  .refresh { display: none; }
  main#board { padding: 12px 8px 30px; }
  .table-wrap { max-height: none; }
  .grid td.horse { min-width: 140px; }
}
