/* Single-screen, no-scroll race strategy dashboard. Each .page fills the viewport
   below the header using CSS grid; canvases fill their grid cells. */
:root {
  --bg: #0a0e16;
  --panel: #121826;
  --panel2: #0e1420;
  --line: rgba(140,160,190,0.14);
  --text: #e6edf6;
  --muted: #8595ad;
  --accent: #39d4ff;
  --good: #52d39a;
  --warn: #f4c95d;
  --bad: #ff5a3c;
  --head-h: 54px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  background: radial-gradient(1200px 700px at 70% -10%, #16243a 0%, var(--bg) 55%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); font-size: 12px; }

/* ---------- header ---------- */
.topbar {
  height: var(--head-h);
  display: flex; align-items: center; gap: 20px;
  padding: 0 18px; border-bottom: 1px solid var(--line);
  background: rgba(10,14,22,0.85); backdrop-filter: blur(6px);
}
.brand { display: flex; flex-direction: column; line-height: 1; }
.eyebrow { color: var(--accent); font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; }
.brand h1 { font-size: 18px; margin: 2px 0 0; font-weight: 700; }
.tabs { display: flex; gap: 6px; }
.tab {
  background: transparent; color: var(--muted); border: 1px solid transparent;
  padding: 7px 14px; border-radius: 8px; font-size: 13px; cursor: pointer; font-weight: 600;
}
.tab:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.tab.active { color: var(--text); background: rgba(57,212,255,0.12); border-color: rgba(57,212,255,0.35); }
.head-right { margin-left: auto; display: flex; align-items: center; gap: 18px; }
.track-select { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.track-select select {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 5px 8px; font-size: 12px;
}
.status { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.status.mono { gap: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 8px var(--bad); }
.dot.live { background: var(--good); box-shadow: 0 0 8px var(--good); }

/* ---------- pages ---------- */
.page { display: none; height: calc(100vh - var(--head-h)); padding: 12px; gap: 12px; }
.page.active { display: grid; }
#page-strategy { grid-template-rows: auto auto minmax(0,1fr) minmax(0,33%); }
#page-coach { grid-template-rows: auto minmax(0,1fr) minmax(0,40%); }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(5,1fr); gap: 12px; }
.tile {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel2) 100%);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  display: flex; flex-direction: column; justify-content: center; min-height: 0;
}
.tile span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.tile strong { font-size: 30px; font-weight: 700; line-height: 1.05; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile small { color: var(--muted); font-size: 11px; }
.tile.accent { border-color: rgba(57,212,255,0.4); box-shadow: inset 0 0 24px rgba(57,212,255,0.07); }
.tile.accent strong { color: var(--accent); }
.bar { height: 5px; border-radius: 3px; background: rgba(255,255,255,0.08); margin-top: 7px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg,var(--bad),var(--warn),var(--good)); }

/* ---------- panels ---------- */
.panel {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; display: flex; flex-direction: column; min-height: 0; min-width: 0;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.panel-head h2 { font-size: 13px; margin: 0; font-weight: 600; letter-spacing: 0.02em; }
.chart-panel canvas { flex: 1; width: 100%; min-height: 0; }

/* strategy bottom */
.strategy-bottom { display: grid; grid-template-columns: 1fr 1.6fr; gap: 12px; min-height: 0; }
.balance { display: grid; grid-template-columns: repeat(5,1fr); gap: 8px; margin: auto 0; }
.balance > div { background: rgba(255,255,255,0.03); border-radius: 9px; padding: 8px; display: flex; flex-direction: column; }
.balance span { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.balance strong { font-size: 19px; font-variant-numeric: tabular-nums; }
.balance small { color: var(--muted); font-size: 10px; }
.lap-log .table-wrap { overflow: auto; flex: 1; min-height: 0; }
table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
th { text-align: right; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel2); padding: 3px 6px; font-size: 11px; }
th:first-child, td:first-child { text-align: left; }
td { text-align: right; padding: 3px 6px; border-top: 1px solid rgba(255,255,255,0.04); }

/* coach header: manual target-pace input */
.coach-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.coach-pace { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.coach-pace input { width: 64px; padding: 4px 6px; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12); border-radius: 6px; color: inherit; font: inherit; text-align: right; }

/* ---------- coach maps ---------- */
.maps { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; min-height: 0; }
.map {
  margin: 0; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px; display: flex; flex-direction: column; min-height: 0;
}
.map figcaption { font-size: 12px; font-weight: 600; margin-bottom: 4px; display: flex; justify-content: space-between; align-items: baseline; }
.map figcaption small { color: var(--muted); font-weight: 400; }
.map canvas { flex: 1; width: 100%; min-height: 0; }
.legend { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-left: 8px; }

/* coach bottom */
.coach-bottom { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; min-height: 0; }
.coach-bottom canvas { flex: 1; width: 100%; min-height: 0; }
.coach-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; min-height: 0; counter-reset: c; }
.coach-list li {
  padding: 8px 10px; margin-bottom: 6px; border-radius: 9px; font-size: 13px;
  background: rgba(255,90,60,0.08); border-left: 3px solid var(--bad);
  display: flex; justify-content: space-between; gap: 10px;
}
.coach-list li .lost { color: var(--bad); font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.coach-list li.push { background: rgba(82,211,154,0.10); border-left-color: var(--good); }
.coach-list li .gain { color: var(--good); font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.coach-list li.muted { background: transparent; border: 0; }
.coach-list li.wind { background: rgba(57,212,255,0.08); border-left-color: #39d4ff; }
.coach-list li.wind .gain { color: #39d4ff; }

/* ---------- inputs page ---------- */
#page-inputs.active { grid-template-rows: auto 1fr auto; align-content: start; }
.inputs-head { flex: none; }
.inputs-intro { margin: 6px 0 0; max-width: 70ch; line-height: 1.45; }
.inputs-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px; overflow: auto; min-height: 0; align-content: start;
}
.input-section { height: max-content; }
.input-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 0; border-bottom: 1px solid var(--line);
}
.input-section .input-row:last-child { border-bottom: none; }
.input-label { display: flex; flex-direction: column; font-size: 13px; gap: 1px; }
.input-label small { color: var(--muted); font-weight: 400; }
.input-hint { color: var(--muted); font-size: 11px; }
.input-row input {
  width: 96px; flex: none; background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px;
  font-size: 13px; text-align: right; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.input-row input:focus { outline: none; border-color: var(--accent); }
.inputs-actions { display: flex; align-items: center; gap: 12px; flex: none; }
.btn {
  border-radius: 8px; padding: 9px 16px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
.btn.primary { background: rgba(57,212,255,0.15); border-color: rgba(57,212,255,0.5); }
.btn.primary:hover { background: rgba(57,212,255,0.26); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: rgba(255,255,255,0.04); }

/* Weather page */
/* Taller than one viewport by design: block layout + its own scrollbar (the other
   pages are fixed grids). */
#page-weather.active { display: block; overflow-y: auto; }
.weather-top { display: grid; grid-template-columns: 3fr 2fr; gap: 12px; margin-bottom: 12px; }
.weather-bottom { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.map-panel canvas { width: 100%; height: 380px; }
.wx-map-wrap { position: relative; }
#wxMap { touch-action: none; cursor: grab; }        /* scroll-zoom & drag-pan without page scroll */
.wx-zoom { position: absolute; left: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 4px; z-index: 2; }
.wx-zoom .btn.mini { width: 30px; height: 30px; padding: 0; font-size: 15px; line-height: 1;
  background: rgba(13,19,32,0.78); border-color: #2a3550; }
.wx-zoom .btn.mini:hover { border-color: #39d4ff; color: var(--text); }
#wxWind { width: 100%; height: 300px; }
.wx-controls { display: inline-flex; align-items: center; gap: 8px; }
.wx-controls input[type="range"] { width: 140px; }
.btn.mini { padding: 2px 10px; font-size: 11px; }
.btn.mini.active { background: #39d4ff22; border-color: #39d4ff; }
.wx-eta { padding: 6px 12px; font-size: 13px; }
.wx-eta.warn { color: #ffb347; }
.wx-badges { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px; }
.wx-badges span { font: 11px ui-monospace, monospace; padding: 2px 8px; border: 1px solid #2a3550; border-radius: 10px; }
.rain-banner { padding: 8px 14px; margin-bottom: 10px; border: 1px solid #ffb347; border-radius: 8px; color: #ffb347; font-weight: 600; }
.rain-banner.hidden { display: none; }

/* Race schedule bar (Strategy page top strip) */
.top-strips { display: flex; flex-direction: column; gap: 8px; }
.sched-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; flex-wrap: wrap; }
.sched-status { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.sched-phase { font-weight: 700; letter-spacing: 0.02em; font-size: 13px; padding: 2px 10px; border-radius: 20px;
  background: rgba(120,140,170,0.14); color: var(--muted); white-space: nowrap; }
.sched-phase.pre { background: rgba(244,201,93,0.16); color: #f4c95d; }
.sched-phase.live { background: rgba(82,211,154,0.18); color: var(--good); }
.sched-detail-num { font-variant-numeric: tabular-nums; }
.sched-controls { display: inline-flex; align-items: center; gap: 8px; }
.sched-controls input[type="datetime-local"] { background: rgba(255,255,255,0.04); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; font: inherit; }
.btn.mini.primary { background: #39d4ff22; border-color: #39d4ff; color: var(--text); }
#wxGhiChart, #wxRainChart, #wxWindChart { width: 100%; height: 180px; }
/* .chart-panel's flex:1 (flex-basis 0) would collapse this canvas inside an
   auto-height panel — pin the basis to the intended height instead. */
#wxGhiChart { flex: 0 0 180px; }

/* Race-control follow/override indicator (Task 9) */
.rc-state { margin-left: .6rem; font-size: .8rem; color: var(--muted); }
.rc-state.override { color: #e0a53a; }
.follow { font-size: .8rem; color: var(--muted); display: inline-flex; gap: .3rem; align-items: center; }

/* Connection resilience banner (Task 10) */
.conn-banner {
  position: sticky; top: 0; z-index: 50;
  background: #7a2b2b; color: #fff; text-align: center;
  padding: .4rem .8rem; font-size: .85rem; letter-spacing: .02em;
}

/* Persistent safety-alert strip (ex-Vehicle-Health page alerts, now shown on every page). */
.alert-strip {
  position: sticky; top: 0; z-index: 49;
  color: #fff; text-align: center;
  padding: .35rem .8rem; font-size: .8rem; letter-spacing: .01em;
}
.alert-strip.warn { background: #7a5c1e; }
.alert-strip.bad { background: #7a2b2b; }

/* Hover tooltips for every canvas graph (see js/tooltip.js). A floating readout box
   beside the cursor + a thin vertical guide line on the plot. Both are DOM overlays
   (position:fixed) so they survive the charts' rAF redraw loop. */
canvas[data-tip] { cursor: crosshair; }
.chart-tip {
  position: fixed; z-index: 90; pointer-events: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.45);
  padding: 6px 9px; font: 11px ui-monospace, monospace; color: var(--text);
  min-width: 70px; max-width: 240px;
}
.chart-tip[hidden] { display: none; }
.chart-tip .tip-title { color: var(--muted); font-size: 10px; margin-bottom: 4px; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 6px; line-height: 1.5; }
.chart-tip .tip-row i { width: 8px; height: 8px; border-radius: 2px; flex: 0 0 auto; }
.chart-tip .tip-row span { color: var(--muted); }
.chart-tip .tip-row b { margin-left: auto; color: var(--text); font-weight: 600; }
.chart-guide {
  position: fixed; z-index: 89; width: 1px; pointer-events: none;
  background: rgba(255,255,255,0.28);
}
.chart-guide[hidden] { display: none; }

/* Telemetry staleness alarm (P2-17): connected-but-dead-feed, distinct from conn-banner above
   (socket loss). ".bad" = CAN telemetry stale (required); ".warn" = GPS-only stale (lower prio). */
.stale-warn {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 10px;
  white-space: nowrap; letter-spacing: .01em;
}
.stale-warn.warn { background: rgba(244,201,93,0.16); color: var(--warn); border: 1px solid rgba(244,201,93,0.4); }
.stale-warn.bad { background: rgba(255,90,60,0.16); color: var(--bad); border: 1px solid rgba(255,90,60,0.4); }
