/* Mobile first: everything is designed at phone width, then widens on larger screens.
   Light and dark follow the phone's own setting. */
:root {
  --bg: #f4f7f6;
  --card: #ffffff;
  --text: #102a27;
  --muted: #5b6f6c;
  --line: #dbe5e3;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --ok: #15803d;
  --watch: #b45309;
  --alert: #b91c1c;
  --info: #475569;
  --missing: #94a3b8;
  --radius: 14px;
  --tabs-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1514;
    --card: #12201e;
    --text: #e3efed;
    --muted: #93a8a5;
    --line: #23332f;
    --accent: #2dd4bf;
    --accent-ink: #062b27;
    --ok: #4ade80;
    --watch: #fbbf24;
    --alert: #f87171;
    --info: #a3b8c2;
    --missing: #64748b;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px);
}
main { padding: 12px 16px; max-width: 900px; margin: 0 auto; }
h1 { font-size: 1.4rem; margin: 6px 0 10px; }
h2 { font-size: 1.05rem; margin: 18px 0 8px; }
h3 { font-size: 0.95rem; margin: 14px 0 6px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.top {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: 0.2px; }
.top form { margin: 0; }
button.link { background: none; border: 0; color: var(--muted); font: inherit; padding: 6px; }

.banner { padding: 10px 16px; font-weight: 600; text-align: center; }
.banner.paused { background: var(--watch); color: #fff; }

.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; color: inherit; text-decoration: none; }
.card h2:first-child { margin-top: 0; }

/* Sign-in */
.login { max-width: 420px; margin: 8vh auto 0; }
.login label { display: block; margin: 14px 0 6px; font-weight: 600; }
input[type=password], input[type=date] {
  width: 100%; font: inherit; padding: 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
button, .button {
  display: inline-block; font: inherit; font-weight: 600; padding: 11px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); text-decoration: none; cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { background: var(--alert); color: #fff; border-color: var(--alert); }
button.wide, .login button { width: 100%; margin-top: 14px; }
.error { color: var(--alert); font-weight: 600; }
.flash { background: var(--card); border-left: 4px solid var(--accent); padding: 10px 12px; border-radius: 8px; }

/* Live */
.hero { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin: 4px 0 12px; }
.map { height: 46vh; min-height: 240px; width: 100%; background: var(--line); }
.map.tall { height: 52vh; border-radius: var(--radius); }
.hero-info { padding: 12px 14px; }
.vehicle-name { font-weight: 700; font-size: 1.1rem; }
.state { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 6px; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.85rem; font-weight: 600; background: var(--bg); border: 1px solid var(--line); }
.pill.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pill.off { color: var(--muted); }
.pill.stale { background: var(--watch); color: #fff; border-color: var(--watch); }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-height: 84px; }
.tile-label { font-size: 0.8rem; color: var(--muted); }
.tile-value { font-size: 1.25rem; font-weight: 700; margin-top: 2px; word-break: break-word; }
.tile-at { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }

/* Trips */
.trip-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.trip-when { font-weight: 600; }
.trip-stats { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; color: var(--muted); }
.trip-stats b { color: var(--text); }
.back { text-decoration: none; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 12px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat-label { font-size: 0.8rem; color: var(--muted); }
.stat-value { font-size: 1.15rem; font-weight: 700; }
.chart { color: var(--accent); overflow-x: auto; }
.chart svg { width: 100%; height: 60px; }

/* Diagnostics */
.summary { font-weight: 700; padding: 12px 14px; border-radius: 12px; color: #fff; }
.summary.ok { background: var(--ok); }
.summary.watch { background: var(--watch); }
.summary.alert { background: var(--alert); }
.diag ul { list-style: none; margin: 0; padding: 0; }
.diag-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.diag-item:first-child { border-top: 0; }
.dot { flex: 0 0 12px; height: 12px; border-radius: 50%; margin-top: 5px; background: var(--info); }
.diag-item.ok .dot { background: var(--ok); }
.diag-item.watch .dot { background: var(--watch); }
.diag-item.alert .dot { background: var(--alert); }
.diag-item.missing .dot { background: transparent; border: 2px solid var(--missing); }
.diag-main { flex: 1 1 auto; min-width: 0; }
.diag-label { font-weight: 600; }
.diag-note { font-size: 0.85rem; color: var(--muted); }
.diag-side { text-align: right; flex: 0 0 auto; max-width: 45%; }
.diag-value { font-weight: 700; word-break: break-word; }
.diag-item.missing .diag-value { font-weight: 400; color: var(--missing); }
.diag-status { font-size: 0.75rem; color: var(--muted); }
.spark { color: var(--accent); display: block; margin-left: auto; }

/* Log */
.filter { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.filter label { font-weight: 600; }
.filter input { width: auto; flex: 1 1 150px; }
.log-row { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin: 8px 0; }
.log-row summary { padding: 12px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; list-style: none; }
.log-row summary::-webkit-details-marker { display: none; }
.log-time { font-weight: 600; }
.log-head { font-size: 0.85rem; color: var(--muted); }
.kv { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 6px 12px; margin: 0; padding: 0 12px 12px; }
.card .kv { padding: 0; }
.kv dt { color: var(--muted); font-size: 0.9rem; }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }
.kv .raw { font-family: ui-monospace, Consolas, monospace; font-size: 0.8rem; font-weight: 400; }
.avl { color: var(--muted); font-size: 0.75rem; font-weight: 400; }

/* Tracker */
.status-on { color: var(--ok); font-weight: 700; }
.status-paused { color: var(--watch); font-weight: 700; }
.owner-unlock label { display: block; font-weight: 600; margin-bottom: 6px; }
.owner-unlock button { margin-top: 10px; width: 100%; }
.plain { padding-left: 18px; margin: 4px 0; }
.code { white-space: pre-wrap; word-break: break-all; font-size: 0.8rem; background: var(--bg); padding: 8px; border-radius: 8px; }

/* Bottom tab bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: 0.72rem; font-weight: 600; }
.tabs a[aria-current="page"] { color: var(--accent); }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Wider screens: more columns, same layout */
@media (min-width: 700px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .map { height: 52vh; }
}

/* Leaflet sits under the sticky header and tab bar */
.leaflet-container { z-index: 0; }
