:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --border: #e3e6eb;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --swim: #2563eb;
  --bike: #ea580c;
  --run: #16a34a;
  --transition: #8b8f99;
  --other: #9333ea;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --border: #2a2f38;
    --swim: #60a5fa;
    --bike: #fb923c;
    --run: #4ade80;
    --transition: #a1a6b0;
    --other: #c084fc;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.title { display: flex; align-items: center; gap: 10px; min-width: 0; }
h1 { font-size: 17px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
select {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px; max-width: 55vw;
}

.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--transition); flex: none; }
.dot.live { background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: pulse 2s infinite; }
.dot.stale { background: var(--warn); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); }
  70% { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  min-height: 0;
}
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--bg); }
.follow {
  position: absolute; z-index: 500; right: 12px; bottom: 24px;
  font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  box-shadow: 0 1px 4px rgb(0 0 0 / .2);
}
.follow.on { background: var(--text); color: var(--surface); }

.panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px 16px 24px;
}
.status { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; font-size: 13px; }
.pill { padding: 2px 9px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.pill.live { color: var(--ok); border-color: var(--ok); }
.pill.stale { color: var(--warn); border-color: var(--warn); }
.pill.old { color: var(--bad); border-color: var(--bad); }
.muted { color: var(--muted); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.stat {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 6px; min-width: 0;
}
.stat label { flex-basis: 100%; font-size: 12px; color: var(--muted); }
.stat b { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.stat.wide b { font-size: 26px; }
.stat:last-child:nth-child(odd) { grid-column: 1 / -1; }
#s-bat.low { color: var(--bad); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th { text-align: right; font-weight: 500; color: var(--muted); padding: 4px 6px; border-bottom: 1px solid var(--border); }
td { text-align: right; padding: 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
td .sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }
td .sw.gap { background: transparent; border: 2px dashed; }
tr.current td { font-weight: 600; }

.landing, .error { max-width: 560px; margin: 40px auto; padding: 0 16px; }
.landing ul { padding-left: 18px; }
.landing a { color: var(--swim); }
.error { color: var(--bad); }

.pos-marker {
  width: 16px; height: 16px; border-radius: 50%;
  border: 3px solid #fff; box-shadow: 0 0 0 1px rgb(0 0 0 / .35), 0 1px 4px rgb(0 0 0 / .4);
}

@media (max-width: 760px) {
  main { grid-template-columns: 1fr; grid-template-rows: 48vh auto; }
  body { height: auto; min-height: 100%; }
  .panel { border-left: 0; border-top: 1px solid var(--border); overflow: visible; }
  .map-wrap { min-height: 48vh; }
}
