/* ═══════════════════════════════════════════════════════════════════════════════
   cOBD shared stylesheet
   ───────────────────────────────────────────────────────────────────────────────
   Extracted verbatim from public/index.html (the reference implementation) plus
   the handful of components that recur identically on fuel.html / analysis.html
   (.stats-grid family, .chart-caption, .pro-notice).

   Nothing here is a redesign. Values are the ones already shipping. Where two
   pages disagreed, index.html wins and the divergent page keeps its own override.

   Load order matters: this file must come AFTER the Leaflet stylesheet (so
   .leaflet-tile wins) and it is inserted after the <style> nav.js injects, which
   is the same cascade index.html had before extraction.
   ═══════════════════════════════════════════════════════════════════════════════ */

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

:root {
  /* Palette — fixed. Do not add colours here. */
  --bg:         #0f172a;
  --surface:    #1e293b;
  --surface2:   #283548;
  --border:     #334155;
  --text:       #f1f5f9;
  --muted:      #94a3b8;
  --accent:     #3b82f6;
  --accent-dim: #1d4ed8;
  --green:      #22c55e;
  --orange:     #f97316;
  --red:        #ef4444;

  /* Status colours that were already in use as bare hex literals across the
     pages, now named. These are the SAME values, not new ones. */
  --danger-text:  #fca5a5;   /* text on a red/destructive surface */
  --success-text: #86efac;   /* text on a green "all clear" surface */
  --info-text:    #93c5fd;   /* text on a blue informational surface */
  --warning-text: #fdba74;   /* text on an orange "worth a look" surface */
  --chart-amber:  #fbbf24;   /* the 30–60 km/h band; amber has no palette slot */
  --no-data:      #6b7280;   /* a plotted point whose value is unknown */
  --error-bg:     #450a0a;   /* error banner background */
  --map-bg:       #1a1d27;   /* map tile backdrop before tiles load */
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--text);
  min-height: 100vh; font-size: 14px;
}

/* ── Header ──────────────────────────────────────────────────────────────────── */
header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 24px; height: 56px; display: flex; align-items: center;
  justify-content: space-between; position: sticky; top: 0; z-index: 1100;
}
.logo { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 700; }
.logo svg { color: var(--accent); flex-shrink: 0; }
.header-right { display: flex; align-items: center; gap: 16px; color: var(--muted); font-size: 13px; }
#live-dot, .live-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted);
  display: inline-block; margin-right: 4px;
}
#live-dot.active, .live-dot.active { background: var(--green); box-shadow: 0 0 6px var(--green); }

main { max-width: 1400px; margin: 0 auto; padding: 24px; }

/* ── Controls: selects and buttons ───────────────────────────────────────────── */
/* 44px minimum on every interactive target — this is used on a phone in a car. */
select, button {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 11px 14px; font-size: 13px; cursor: pointer; outline: none;
  transition: border-color 0.15s; min-height: 44px;
}
select { min-width: 260px; max-width: 100%; }
select:focus, button:focus { border-color: var(--accent); }
select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button:hover  { border-color: var(--accent); background: var(--border); }
button.active { background: var(--accent-dim); border-color: var(--accent); color: #fff; }
.btn-sm { padding: 8px 12px; font-size: 12px; min-height: 38px; }

/* A plain horizontal control strip, for pages that do not need the full scope bar. */
.controls { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }

/* ── Scope bar: what am I looking at ─────────────────────────────────────────── */
.scope-bar {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 20px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.scope-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); font-weight: 600; }
.scope-spacer { flex: 1; }

/* Two ways to scope a page: one drive, or one period. Exactly one is live at a
   time, and the live one is spelled out in the state line below. */
.scope-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.scope-or { color: var(--muted); font-size: 12px; }
.scope-label.on { color: var(--accent); }
select.on { border-color: var(--accent); }
.range-chips { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.range-chip { padding: 11px 12px; font-size: 13px; min-height: 44px; white-space: nowrap; }
.scope-state {
  flex-basis: 100%; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  border-top: 1px solid var(--border); margin-top: 2px; padding-top: 12px;
}
.scope-mode {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--accent); color: var(--accent);
}
.scope-mode.drive { border-color: var(--green); color: var(--green); }
.scope-detail { font-size: 12px; color: var(--muted); }

/* ── Hero: the headline facts about the current scope ────────────────────────── */
.hero {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; margin-bottom: 20px;
}
.hero-top { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.hero-title { font-size: 22px; font-weight: 700; }
.hero-sub { color: var(--muted); font-size: 13px; }
.hero-badge {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted);
}
.hero-badge.trip { color: var(--green); border-color: var(--green); }
.hero-badge.idle { color: var(--orange); border-color: var(--orange); }
.hero-badge.all  { color: var(--accent); border-color: var(--accent); }

/* ── Metric tiles (dense, six across) ────────────────────────────────────────── */
.metrics { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
.metric { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 14px; min-width: 0; }
.metric-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin-bottom: 6px; }
.metric-value { font-size: 22px; font-weight: 700; line-height: 1.1; overflow-wrap: anywhere; }
.metric-unit  { font-size: 12px; color: var(--muted); margin-left: 3px; font-weight: 400; }
.metric-note  { font-size: 11px; color: var(--muted); margin-top: 5px; }

/* ── Stat cards (sparse, four across) — from fuel.html / analysis.html ───────── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-unit  { font-size: 13px; color: var(--muted); margin-left: 3px; font-weight: 400; }

/* ── Section headers ─────────────────────────────────────────────────────────── */
.section-header {
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted); margin-bottom: 12px; margin-top: 28px; display: flex; align-items: center; gap: 8px;
}
.section-header::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.section-hint { font-size: 12px; color: var(--muted); margin: -4px 0 12px; text-transform: none; letter-spacing: 0; }

/* ── Charts ──────────────────────────────────────────────────────────────────── */
.charts-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 8px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; min-width: 0; }
.chart-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 4px; }
/* avg / min / max line printed under the title by cobd.makeChart(...).readout */
.chart-readout { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
/* Height is a variable so a page can say --chart-h: 220px without forking the
   rule. The default is index.html's value. */
.chart-canvas-wrap { position: relative; height: var(--chart-h, 180px); }
/* Every chart states the window it covers and how many readings are in it, so a
   number is never shown without the period it belongs to. */
.chart-caption { margin-top: 10px; font-size: 12px; color: var(--muted); line-height: 1.45; }

/* ── Health breakdown ────────────────────────────────────────────────────────── */
.health-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; }
.health-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.health-score { font-size: 34px; font-weight: 700; line-height: 1; }
.health-verdict { font-size: 13px; }
.health-parts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.part-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; gap: 6px; }
.bar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }

/* ── Explore links, scoped to the current selection ──────────────────────────── */
.explore { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.explore-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; text-decoration: none; color: var(--text);
  transition: border-color 0.15s, background 0.15s; min-height: 44px;
}
.explore-card:hover { border-color: var(--accent); background: var(--surface2); }
.explore-title { font-size: 13px; font-weight: 600; }
.explore-desc  { font-size: 11px; color: var(--muted); margin-top: 3px; }

/* ── Map ─────────────────────────────────────────────────────────────────────── */
.map-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
#map, .map-canvas { height: 420px; background: var(--map-bg); }
.leaflet-tile { filter: brightness(0.85) saturate(0.9); }
.map-footer {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted);
}
.legend { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 24px; height: 4px; border-radius: 2px; }
#map-info, .map-info { margin-left: auto; }

/* ── Diagnostics disclosure ──────────────────────────────────────────────────── */
details.diag { margin-top: 28px; }
details.diag > summary {
  cursor: pointer; list-style: none; padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  font-size: 13px; font-weight: 600; color: var(--muted);
  display: flex; align-items: center; gap: 8px; min-height: 44px;
}
details.diag > summary::-webkit-details-marker { display: none; }
details.diag > summary:hover { border-color: var(--accent); color: var(--text); }
details.diag > summary::before { content: '▸'; transition: transform 0.15s; }
details.diag[open] > summary::before { transform: rotate(90deg); }
details.diag[open] > summary { border-radius: 10px 10px 0 0; }
.diag-body { border: 1px solid var(--border); border-top: none; border-radius: 0 0 10px 10px; padding: 16px; }

/* ── Tables ──────────────────────────────────────────────────────────────────── */
.table-wrap { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; overflow-x: auto; margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: var(--surface2); padding: 10px 14px; text-align: left;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 9px 14px; color: var(--text); vertical-align: middle; }

/* ── Pills, tags and text helpers ────────────────────────────────────────────── */
.mono { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; }
.dim  { color: var(--muted); }
.tag  {
  display: inline-block; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 6px; font-size: 11px; font-family: monospace;
  max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle;
}
.kind-pill {
  display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px;
  padding: 2px 7px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); font-weight: 600;
}
.kind-pill.trip  { color: var(--green);  border-color: var(--green); }
.kind-pill.idle  { color: var(--orange); border-color: var(--orange); }
.kind-pill.noise { color: var(--muted);  border-color: var(--border); }

/* ── Row-level expand control and raw-parameter dump ─────────────────────────── */
.expand-btn { background: none; border: 1px solid var(--border); color: var(--muted); padding: 4px 10px; font-size: 11px; border-radius: 4px; min-height: 32px; }
.expand-btn:hover { color: var(--text); border-color: var(--accent); background: none; }
.raw-row { display: none; }
.raw-row td { padding: 0; }
.raw-content {
  background: var(--bg); border-top: 1px solid var(--border); padding: 12px 14px;
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 11px; color: var(--muted);
  line-height: 1.8; max-height: 240px; overflow-y: auto; display: flex; flex-wrap: wrap; gap: 4px 20px;
}
.raw-pair { white-space: nowrap; }
.raw-key  { color: var(--accent); }
.raw-name { color: var(--muted); font-size: 10px; margin-left: 2px; }

/* ── Pagination ──────────────────────────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); flex-wrap: wrap;
}
.pagination-btns { display: flex; gap: 8px; }
.pagination-btns button { padding: 8px 14px; font-size: 12px; min-height: 38px; }
.pagination-btns button:disabled { opacity: 0.35; cursor: default; }

/* ── Empty and error states ──────────────────────────────────────────────────── */
.empty { padding: 40px; text-align: center; color: var(--muted); }
.empty-inline { padding: 24px; text-align: center; color: var(--muted); font-size: 13px; }

#error-banner, .error-banner {
  display: none; background: var(--error-bg); border: 1px solid var(--red); color: var(--danger-text);
  padding: 10px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 13px;
}

/* Shown instead of the page body when the API answers 403 for a plan that cannot
   read this data. See cobd.apiFetch — the error it throws carries .forbidden. */
.pro-notice {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 20px; max-width: 640px; margin-top: 8px;
}
.pro-notice h2 { font-size: 15px; font-weight: 700; margin-bottom: 10px; }
.pro-notice p  { font-size: 13px; color: var(--muted); line-height: 1.6; margin-bottom: 10px; }
.pro-notice p:last-child { margin-bottom: 0; }

/* Inline verdict block: green all-clear, orange worth-a-look, red outside range. */
.diag-card { border-radius: 8px; padding: 14px 16px; font-size: 13px; line-height: 1.6; margin-top: 12px; }
.diag-card.ok     { background: rgba(34,197,94,0.1);  border: 1px solid rgba(34,197,94,0.3);  color: var(--success-text); }
.diag-card.warn   { background: rgba(249,115,22,0.1); border: 1px solid rgba(249,115,22,0.3); color: var(--warning-text); }
.diag-card.severe { background: rgba(239,68,68,0.1);  border: 1px solid rgba(239,68,68,0.3);  color: var(--danger-text); }

/* Informational aside — identical in setup.html and how-it-works.html today. */
.tip-box {
  background: rgba(59,130,246,0.08); border: 1px solid rgba(59,130,246,0.2);
  border-radius: 8px; padding: 12px 16px; font-size: 13px; color: var(--info-text);
  line-height: 1.6; margin-bottom: 16px;
}
.tip-box strong { color: var(--accent); }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 1100px) { .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
  .explore     { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-grid  { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  .health-parts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #map, .map-canvas { height: 300px; }
}
@media (max-width: 560px) { .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
