:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --good: #006300;
  --bad: #d03b3b;
  /* Categorical slots, assigned to years in a fixed order. */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --good: #0ca30c;
    --bad: #e66767;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --good: #0ca30c;
  --bad: #e66767;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 24px clamp(16px, 3vw, 40px) 48px;
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1 { font-size: 22px; margin: 0 0 2px; font-weight: 650; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--text-secondary); }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}

button, select {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
}
button { cursor: pointer; }
.header-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.header-actions form { display: contents; }
button.ghost:hover { background: var(--grid); }

input[type="text"], input[type="password"] {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.login-page { min-height: 100vh; display: grid; place-items: center; }
.login-card {
  width: min(360px, 100%);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}
.login-form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.login-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-secondary); }
.login-form label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; }
.login-form button { padding: 8px 10px; font-weight: 600; }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 20px;
  padding: 12px 16px;
  margin-bottom: 20px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  position: sticky;
  top: 8px;
  z-index: 10;
}
.filters label, .inline-controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}
.filters fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.filters legend { font-size: 12px; color: var(--text-secondary); padding: 0; margin-bottom: 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.chip .swatch { width: 10px; height: 10px; border-radius: 50%; opacity: 0.35; }
.chip[aria-pressed="true"] { color: var(--text-primary); border-color: var(--text-muted); }
.chip[aria-pressed="true"] .swatch { opacity: 1; }
.chip:disabled { opacity: 0.45; cursor: not-allowed; text-decoration: line-through; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.tile-year { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); font-weight: 600; }
.tile-year .swatch { width: 10px; height: 10px; border-radius: 50%; }
.tile-value { font-size: 28px; font-weight: 650; margin: 2px 0; }
.tile-meta { font-size: 12px; color: var(--text-secondary); }
.delta-up { color: var(--good); }
.delta-down { color: var(--bad); }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
  min-width: 0;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 8px;
}
.inline-controls { display: flex; gap: 12px; }

.grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 0 20px;
  align-items: start;
}
@media (max-width: 1000px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
}

.chart-box { position: relative; height: 320px; margin-top: 8px; }
.chart-box.tall { height: 420px; }

details { margin-top: 12px; }
summary { cursor: pointer; color: var(--text-secondary); font-size: 13px; }
.table-wrap { overflow: auto; max-height: 420px; margin-top: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 4px 8px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { position: sticky; top: 0; background: var(--surface-1); color: var(--text-secondary); font-weight: 600; }

.notes { font-size: 12px; }
.error { color: var(--bad); }
.loading main { opacity: 0.5; transition: opacity 0.2s; }

@media (max-width: 600px) {
  .page-header { flex-direction: column; }
  .filters { position: static; }
  .chart-box.tall { height: 340px; }
}
