:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --hover-wash: rgba(11, 11, 11, 0.04);

  --sport-swim: #2a78d6;
  --sport-bike: #eb6834;
  --sport-run: #1baf7a;
  --sport-other: #b5b3ab;
  --sport-multi: #898781;
  --accent: #6250d6;
  --accent-2: #e87ba4;
  --muted-series: #a3a19a;
  --muted-wash: rgba(137, 135, 129, 0.10);

  --zone-1: #86b6ef;
  --zone-2: #5598e7;
  --zone-3: #2a78d6;
  --zone-4: #1c5cab;
  --zone-5: #104281;

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --delta-up: #006300;
  --delta-down: #52514e;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --hover-wash: rgba(255, 255, 255, 0.05);
    --sport-swim: #3987e5;
    --sport-bike: #d95926;
    --sport-run: #199e70;
    --sport-other: #5e5d58;
    --sport-multi: #898781;
    --accent: #9085e9;
    --accent-2: #d55181;
    --muted-series: #6f6d67;
    --muted-wash: rgba(137, 135, 129, 0.12);
    --zone-1: #9ec5f4;
    --zone-2: #6da7ec;
    --zone-3: #3987e5;
    --zone-4: #256abf;
    --zone-5: #184f95;
    --delta-up: #0ca30c;
    --delta-down: #c3c2b7;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: inherit; }

header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}
header .brand { font-weight: 600; }
header nav { display: flex; gap: 4px; flex-wrap: wrap; }
header nav a {
  padding: 6px 12px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-secondary);
}
header nav a:hover { background: var(--hover-wash); }
header nav a.active { color: var(--text-primary); font-weight: 600; background: var(--hover-wash); }
header .meta { margin-left: auto; display: flex; align-items: center; gap: 12px; color: var(--text-muted); font-size: 12px; }

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

h1 { font-size: 22px; margin: 0 0 4px; font-weight: 600; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
.subtitle { color: var(--text-secondary); margin: 0 0 20px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile, .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.tile { padding: 14px 16px; }
.tile .label { color: var(--text-secondary); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.tile .value { font-size: 26px; font-weight: 600; margin: 2px 0; }
.tile .sub { color: var(--text-muted); font-size: 12px; }
.tile .sub.up { color: var(--delta-up); }
.tile .sub.down { color: var(--delta-down); }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.status::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
.status-good::before { background: var(--good); }
.status-warning::before { background: var(--warning); }
.status-serious::before { background: var(--serious); }
.status-critical::before { background: var(--critical); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot-swim { background: var(--sport-swim); }
.dot-bike { background: var(--sport-bike); }
.dot-run { background: var(--sport-run); }
.dot-other { background: var(--sport-other); }
.dot-multi { background: var(--sport-multi); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; margin-bottom: 16px; }
.card { padding: 16px; margin-bottom: 16px; min-width: 0; }
.grid-2 .card { margin-bottom: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.card .note { color: var(--text-muted); font-size: 12px; margin: 0 0 8px; }

.chart { width: 100%; height: 300px; }
.chart.tall { height: 360px; }
.chart.short { height: 240px; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented a { padding: 4px 10px; font-size: 12px; text-decoration: none; color: var(--text-secondary); }
.segmented a + a { border-left: 1px solid var(--border); }
.segmented a.active { background: var(--hover-wash); color: var(--text-primary); font-weight: 600; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 500; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--hover-wash); }
td.name { white-space: normal; min-width: 180px; }
td.name a { text-decoration: none; font-weight: 500; }
td.name a:hover { text-decoration: underline; }
.table-wrap { overflow-x: auto; }
.muted { color: var(--text-muted); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
input, select, button {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
}
button { cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.link { border: none; background: none; padding: 0; color: var(--text-muted); text-decoration: underline; font-size: 12px; }

.pager { display: flex; gap: 12px; align-items: center; justify-content: flex-end; margin-top: 12px; color: var(--text-muted); }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 24px; }
.metrics div { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--grid); gap: 12px; }
.metrics dt { color: var(--text-secondary); }
.metrics dd { margin: 0; font-weight: 500; text-align: right; }

.login { max-width: 340px; margin: 12vh auto; padding: 28px; }
.login form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.error { color: var(--critical); font-size: 13px; }

@media (max-width: 640px) {
  header, main { padding-left: 16px; padding-right: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  header .meta { margin-left: 0; }
}
