/* FordConnect fleet tracker — dashboard styles
   Palette roles follow the validated default: categorical slots 1–3 for vans
   (max three on screen at once), single-hue blue for the charts. */

:root {
  color-scheme: light;

  --surface-1:      #fcfcfb;
  --page:           #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --hairline:       rgba(11, 11, 11, 0.10);

  --series-1:       #2a78d6;   /* van 1 / chart default */
  --series-2:       #eb6834;   /* van 2 */
  --series-3:       #1baf7a;   /* van 3 */

  --good:           #0ca30c;
  --warning:        #fab219;
  --serious:        #ec835a;
  --critical:       #d03b3b;
  --success-text:   #006300;

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page:           #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --hairline:       rgba(255, 255, 255, 0.10);
    --series-1:       #3987e5;
    --series-2:       #d95926;
    --series-3:       #199e70;
    --success-text:   #0ca30c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --page:           #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --hairline:       rgba(255, 255, 255, 0.10);
  --series-1:       #3987e5;
  --series-2:       #d95926;
  --series-3:       #199e70;
  --success-text:   #0ca30c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--page);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--series-1); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.875em; }
pre.wrap { white-space: pre-wrap; word-break: break-all; background: var(--page); padding: 10px; border-radius: 8px; border: 1px solid var(--hairline); }

/* ── Simple pages (login, oauth) ───────────────────────────── */
.page-simple { display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; }
.card {
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 28px 32px;
  max-width: 720px;
  width: 100%;
}
.card-narrow { max-width: 380px; }
.card h1 { margin: 0 0 16px; font-size: 22px; }
.card h2 { margin: 24px 0 8px; font-size: 16px; }
.card h1.ok { color: var(--success-text); }
.card h1.bad { color: var(--critical); }

.muted { color: var(--text-muted); }
.steps { padding-left: 20px; color: var(--text-secondary); }
.steps li { margin-bottom: 6px; }

.notice { padding: 12px 14px; border-radius: 8px; margin: 16px 0; border: 1px solid; font-size: 14px; }
.notice-warn  { border-color: var(--warning);  background: color-mix(in srgb, var(--warning) 10%, transparent); }
.notice-error { border-color: var(--critical); background: color-mix(in srgb, var(--critical) 10%, transparent); }

.btn {
  display: inline-block; padding: 9px 18px; border-radius: 8px;
  border: 1px solid var(--hairline); background: var(--surface-1);
  color: var(--text-primary); text-decoration: none; cursor: pointer;
  font: inherit; font-weight: 500;
}
.btn-primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.btn:hover { filter: brightness(1.06); }

form label { display: block; margin-bottom: 6px; font-weight: 500; }
form input[type="password"], form input[type="text"], select, input[type="date"] {
  width: 100%; padding: 9px 12px; margin-bottom: 14px;
  border: 1px solid var(--baseline); border-radius: 8px;
  background: var(--surface-1); color: var(--text-primary); font: inherit;
}
select, input[type="date"] { width: auto; margin-bottom: 0; }

table.kv { width: 100%; border-collapse: collapse; margin: 12px 0; }
table.kv th, table.kv td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--hairline); vertical-align: top; font-weight: 400; }
table.kv th { color: var(--text-secondary); width: 34%; }

/* ── Dashboard shell ───────────────────────────────────────── */
.app { display: grid; grid-template-rows: auto 1fr; height: 100%; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--hairline);
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.topbar .filters label { margin: 0; font-size: 13px; color: var(--text-secondary); font-weight: 400; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.status-dot.ok { background: var(--good); }
.status-dot.warn { background: var(--warning); }
.status-dot.bad { background: var(--critical); }

.main { display: grid; grid-template-columns: 340px 1fr; min-height: 0; }
@media (max-width: 900px) { .main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; } }

.sidebar {
  background: var(--surface-1);
  border-right: 1px solid var(--hairline);
  overflow-y: auto;
  padding: 14px;
}
.map-pane { position: relative; min-height: 320px; }
#map { position: absolute; inset: 0; }
@media (max-width: 900px) { .map-pane { min-height: 60vh; } #map { position: relative; height: 60vh; } }

/* ── Van cards ─────────────────────────────────────────────── */
.van {
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--van-colour, var(--series-1));
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  cursor: pointer;
  background: var(--surface-1);
}
.van:hover { border-color: var(--baseline); }
.van.selected { box-shadow: 0 0 0 2px var(--van-colour, var(--series-1)) inset; }
.van-head { display: flex; align-items: baseline; gap: 8px; }
.van-name { font-weight: 600; }
.van-state { font-size: 12px; color: var(--text-secondary); margin-left: auto; }
.van-vehicle { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 17px; font-weight: 600; }
.stat-value .unit { font-size: 12px; font-weight: 400; color: var(--text-secondary); margin-left: 2px; }

.meter { height: 4px; border-radius: 2px; background: var(--gridline); margin-top: 5px; overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 2px; background: var(--series-1); }
.meter.low > span { background: var(--critical); }

.van-foot { margin-top: 10px; font-size: 12px; color: var(--text-muted); display: flex; gap: 10px; align-items: center; }

/* ── Panels ────────────────────────────────────────────────── */
.panel { background: var(--surface-1); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.panel h2 { font-size: 13px; margin: 0 0 2px; font-weight: 600; }
.panel .sub { font-size: 12px; color: var(--text-muted); margin: 0 0 12px; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-weight: 500; color: var(--text-secondary); padding: 6px 8px; border-bottom: 1px solid var(--baseline); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
table.data td { padding: 7px 8px; border-bottom: 1px solid var(--hairline); font-variant-numeric: tabular-nums; }
table.data tr:hover td { background: var(--page); }
table.data td.num { text-align: right; }
table.data .empty { color: var(--text-muted); text-align: center; padding: 24px 8px; }

/* ── Charts ────────────────────────────────────────────────── */
.chart { width: 100%; display: block; overflow: visible; }
.chart .grid line { stroke: var(--gridline); stroke-width: 1; }
.chart .axis line, .chart .axis path { stroke: var(--baseline); stroke-width: 1; }
.chart text { fill: var(--text-muted); font-size: 10px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .series-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-bar { fill: var(--series-1); }
.chart .crosshair { stroke: var(--baseline); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .marker { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }

.chart-tip {
  position: absolute; pointer-events: none; z-index: 500;
  background: var(--surface-1); border: 1px solid var(--hairline);
  border-radius: 8px; padding: 7px 10px; font-size: 12px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.14); white-space: nowrap;
}
.chart-tip .tip-label { color: var(--text-muted); }
.chart-tip .tip-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-wrap { position: relative; }

/* ── Map bits ──────────────────────────────────────────────── */
.van-marker {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,0.25);
}
.leaflet-popup-content { font-family: var(--font); font-size: 13px; }
.leaflet-container { background: var(--page); }

.banner {
  padding: 10px 14px; font-size: 13px;
  border-bottom: 1px solid var(--hairline);
  background: color-mix(in srgb, var(--warning) 14%, var(--surface-1));
  color: var(--text-primary);
}
.banner.error { background: color-mix(in srgb, var(--critical) 14%, var(--surface-1)); }
.banner a { font-weight: 600; }
