/* Roles first; the chart body is written against roles, never raw hex, so light/dark
   swaps in one place. Values from the validated reference palette. */
:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;   /* chart surface */
  --plane:          #f9f9f7;   /* page plane */
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --grid:           #e1e0d9;
  --axis:           #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --series-1:       #2a78d6;   /* the only data hue: one series, one color */
  --series-1-deep:  #1c5cab;   /* same ramp, for hover emphasis */
  --series-wash:    rgba(42, 120, 214, 0.10);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --plane:          #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --axis:           #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --series-1:       #3987e5;
    --series-1-deep:  #86b6ef;
    --series-wash:    rgba(57, 135, 229, 0.14);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --plane:          #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --axis:           #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --series-1:       #3987e5;
  --series-1-deep:  #86b6ef;
  --series-wash:    rgba(57, 135, 229, 0.14);
}

* { box-sizing: border-box; }

html { overflow-x: hidden; }
body {
  margin: 0;
  overflow-x: hidden;
  background: var(--plane);
  color: var(--text-primary);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--series-1); }

.topbar {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  max-width: 1100px; margin: 0 auto; padding: 28px 20px 8px;
}
h1 { font-size: 26px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
.sub { margin: 4px 0 0; color: var(--text-secondary); font-size: 14px; }

main { max-width: 1100px; margin: 0 auto; padding: 0 20px 56px; }

/* One filter row above everything it scopes — never inside a chart card. */
.filters {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  max-width: 1100px; margin: 12px auto 16px; padding: 0 20px;
}
.spacer { flex: 1 1 auto; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-secondary); }
.field.compact { font-size: 12px; }
select, .ghost, .primary {
  font: inherit; color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; min-height: 36px;
}
select { min-width: 190px; }
.ghost { cursor: pointer; }
.ghost:hover { background: var(--series-wash); }
.primary {
  cursor: pointer; min-width: 44px; font-size: 15px;
  background: var(--series-1); color: #fff; border-color: transparent;
}
.primary:hover { background: var(--series-1-deep); }
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; margin-bottom: 20px;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
h2 { font-size: 17px; font-weight: 600; margin: 0; }
.card-sub { margin: 3px 0 0; color: var(--text-secondary); font-size: 13px; }

/* Hero figure: >=48px, same sans, proportional figures (never tabular here). */
.hero { text-align: right; flex: 0 0 auto; }
.hero-value { font-size: 48px; font-weight: 600; line-height: 1; letter-spacing: -0.02em; }
.hero-label { color: var(--text-secondary); font-size: 12px; margin-top: 4px; }

/* --- race ------------------------------------------------------------- */
.chart { position: relative; height: 640px; padding-bottom: 34px; }
/* Value normally sits past the bar end; when there is no room it rides inside it,
   where white is the only legible ink. */
.val.inside { color: #fff; justify-content: flex-end; padding-right: 6px; padding-left: 0; }
.row { position: absolute; left: 0; right: 0; height: 22px; will-change: transform; }
.row-inner { position: absolute; inset: 0; display: flex; align-items: center; }

.bar {
  position: absolute; left: 210px; top: 1px; height: 20px;   /* <=24px thick */
  background: var(--series-1);
  border-radius: 0 4px 4px 0;                                 /* 4px rounded data-end */
  transform-origin: left center;
}
.row:hover .bar { background: var(--series-1-deep); }

.key {
  position: absolute; left: 0; width: 200px; height: 22px;
  display: flex; align-items: center; justify-content: flex-end;
  font-size: 13px; color: var(--text-primary);                /* text tokens, never the data color */
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.val {
  position: absolute; height: 22px; display: flex; align-items: center;
  padding-left: 8px; font-size: 12px; color: var(--text-secondary);
  font-variant-numeric: tabular-nums;                          /* a column of numbers */
  white-space: nowrap;
}
.rank { position: absolute; left: 0; width: 24px; text-align: right; color: var(--text-muted); font-size: 11px; }

.gridline { position: absolute; top: 0; bottom: 26px; width: 1px; background: var(--grid); }
.gridlabel { position: absolute; bottom: 0; transform: translateX(-50%); color: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.axisline { position: absolute; left: 210px; right: 0; bottom: 26px; height: 1px; background: var(--axis); }

/* --- line chart ------------------------------------------------------- */
.line-chart { position: relative; height: 220px; }
.line-chart svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* --- transport -------------------------------------------------------- */
.transport { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.slider { flex: 1 1 auto; accent-color: var(--series-1); height: 28px; }
.day-out { font-variant-numeric: tabular-nums; color: var(--text-secondary); font-size: 13px; min-width: 92px; text-align: right; }
.hint { color: var(--text-muted); font-size: 12px; margin: 8px 0 0; }

/* --- table view (the WCAG-clean twin) --------------------------------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
caption { text-align: left; color: var(--text-secondary); font-size: 13px; padding-bottom: 8px; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--grid); }
td:last-child, th:last-child { text-align: right; font-variant-numeric: tabular-nums; }

/* --- tooltip ---------------------------------------------------------- */
.tip {
  position: fixed; z-index: 10; pointer-events: none;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.14);
  max-width: 280px;
}
.tip .tip-k { font-weight: 600; }
.tip .tip-v { color: var(--text-secondary); font-variant-numeric: tabular-nums; }

.foot { color: var(--text-secondary); font-size: 13px; }
.muted { color: var(--text-muted); }

@media (max-width: 720px) {
  /* Two columns of filters instead of five stacked rows — five rows pushed the chart
     350px below the fold on a 412px-wide phone. */
  .filters {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
    margin: 8px auto 12px; padding: 0 12px;
  }
  .filters .field:first-child { grid-column: 1 / -1; }   /* Métrica gets the full row */
  .spacer { display: none; }
  select { min-width: 0; width: 100%; font-size: 13px; padding: 6px 8px; }
  #viewToggle { grid-column: 1 / -1; }

  .topbar { padding: 16px 12px 4px; }
  h1 { font-size: 21px; }
  .sub { font-size: 12px; }
  main { padding: 0 12px 32px; }
  .card { padding: 12px; border-radius: 10px; }

  .card-head { flex-direction: row; align-items: baseline; gap: 10px; }
  .hero { text-align: right; }
  .hero-value { font-size: 24px; }
  .hero-label { font-size: 10px; }
  h2 { font-size: 15px; }
  .card-sub { font-size: 11px; }

  .bar { left: 104px; height: 18px; top: 2px; }
  .key { width: 98px; font-size: 11px; }
  .val { font-size: 11px; padding-left: 5px; }
  .axisline { left: 104px; }
  .gridlabel { font-size: 10px; }
  .row { height: 24px; }

  .line-chart { height: 160px; }
  .day-out { min-width: 74px; font-size: 12px; }
  .primary { min-width: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  .row { transition: none !important; }
}
