:root {
  --bg: #f4f5f7; --card: #fff; --text: #15181d; --muted: #5d6573; --border: #dde1e7; --accent: #2563eb;
  --good: #16a34a; --fair: #eab308; --poor: #ea580c; --bad: #dc2626; --none: #9ca3af;
  --chart-p50: #2563eb; --chart-p95: #7c3aed; --chart-loss: rgba(220, 38, 38, .35);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418; --card: #1b1f25; --text: #e8eaed; --muted: #9aa3b0; --border: #2c323b; --accent: #60a5fa;
    --none: #6b7280; --chart-p50: #60a5fa; --chart-p95: #c084fc; --chart-loss: rgba(248, 113, 113, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111418; --card: #1b1f25; --text: #e8eaed; --muted: #9aa3b0; --border: #2c323b; --accent: #60a5fa;
  --none: #6b7280; --chart-p50: #60a5fa; --chart-p95: #c084fc; --chart-loss: rgba(248, 113, 113, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 24px 0 6px; }
.sub { color: var(--muted); margin: 0 0 16px; }
a { color: var(--accent); }
.error { color: var(--bad); }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; }

/* Run list */
.wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
th.l, td.l { text-align: left; }
tr:last-child td { border-bottom: 0; }
td small { color: var(--muted); }
tr.click { cursor: pointer; }
tr.click:hover td { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.good { color: var(--good); } .warn { color: var(--poor); } .bad { color: var(--bad); }

/* Run view */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 1px; background: var(--border); overflow: hidden; margin-bottom: 12px; }
.stats div { background: var(--card); padding: 10px 12px; }
.stats b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats span { font-size: 12px; color: var(--muted); }
.stats .wide { grid-column: span 2; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; margin: 0 0 8px; font-size: 13px; }
.toolbar select { font: inherit; padding: 4px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--card); color: var(--text); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); }
.legend i { display: inline-block; width: 18px; height: 6px; border-radius: 3px; vertical-align: middle; margin-right: 4px; }
#map { height: min(60vh, 600px); min-height: 320px; overflow: hidden; }
#chart { margin-top: 12px; }
#chart, .chart { padding: 8px 4px 4px; overflow: hidden; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin: 0 6px 0 0; vertical-align: baseline; }
.pop td:not(:first-child) { color: inherit; }
.leaflet-popup-content { font: 13px/1.45 system-ui, sans-serif; margin: 10px 12px; }
.pop b { font-size: 14px; }
.pop table { margin-top: 4px; }
.pop td { padding: 1px 0 1px 12px; border: 0; }
.pop td:first-child { padding-left: 0; text-align: left; color: #5d6573; }
.pin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.4);
  font: 700 10px/14px system-ui, sans-serif; color: #fff; text-align: center; }
.u-legend { font-size: 12px; }
.btn { font: inherit; font-weight: 600; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--text); cursor: pointer; }
.btn:disabled { opacity: .5; cursor: default; }
