/* ==========================================================================
   Verkehrsunfälle Hamburg — dashboard styles

   Colour is declared once here as custom properties and referenced by role
   everywhere else, so the light/dark pair swaps in one place.  The seven
   categorical slots are validated (adjacent CVD ΔE 9.1 light / 8.4 dark,
   normal-vision 19.6 / 19.3).  Three light-mode slots sit below 3:1 against
   the surface, which is why every categorical chart is a row chart with a
   visible text label and the data table exists as the table-view twin.
   ========================================================================== */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page:      #f9f9f7;
  --ink-1:     #0b0b0b;
  --ink-2:     #52514e;
  --ink-muted: #898781;
  --grid:      #e1e0d9;
  --axis:      #c3c2b7;
  --hairline:  rgba(11, 11, 11, .10);
  --sunken:    rgba(11, 11, 11, .04);

  /* categorical — fixed slot order, never cycled, never reassigned by rank */
  --series-1: #2a78d6;  /* Pkw             */
  --series-2: #eb6834;  /* Lkw             */
  --series-3: #1baf7a;  /* Fahrrad/Pedelec */
  --series-4: #eda100;  /* Fußgänger       */
  --series-5: #e87ba4;  /* Krad            */
  --series-6: #008300;  /* Bus             */
  --series-7: #4a3aa7;  /* Sonstige        */

  /* sequential blue, 100 → 700 */
  --seq-100: #cde2fb; --seq-150: #b7d3f6; --seq-200: #9ec5f4; --seq-250: #86b6ef;
  --seq-300: #6da7ec; --seq-350: #5598e7; --seq-400: #3987e5; --seq-450: #2a78d6;
  --seq-500: #256abf; --seq-550: #1c5cab; --seq-600: #184f95; --seq-650: #104281;
  --seq-700: #0d366b;

  /* status — severity only, never a series */
  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;
  /* status yellow is 1.79:1 on the light surface — too low for text.
     KPI numerals use a darker step of the same hue instead. */
  --status-warning-ink: #8a6100;

  --radius: 6px;
  --gap: 14px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page:      #0d0d0d;
    --ink-1:     #ffffff;
    --ink-2:     #c3c2b7;
    --ink-muted: #898781;
    --grid:      #2c2c2a;
    --axis:      #383835;
    --hairline:  rgba(255, 255, 255, .10);
    --sunken:    rgba(255, 255, 255, .05);
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --series-4: #c98500; --series-5: #d55181; --series-6: #008300;
    --series-7: #9085e9;
    --status-warning-ink: #fab219;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page:      #0d0d0d;
  --ink-1:     #ffffff;
  --ink-2:     #c3c2b7;
  --ink-muted: #898781;
  --grid:      #2c2c2a;
  --axis:      #383835;
  --hairline:  rgba(255, 255, 255, .10);
  --sunken:    rgba(255, 255, 255, .05);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --series-4: #c98500; --series-5: #d55181; --series-6: #008300;
  --series-7: #9085e9;
  --status-warning-ink: #fab219;
}

/* --------------------------------------------------------------- shell -- */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink-1);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

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

.hdr {
  position: sticky; top: 0; z-index: 900;
  background: var(--surface-1);
  border-bottom: 1px solid var(--hairline);
  padding: 10px clamp(12px, 2vw, 24px) 0;
}

.hdr__top {
  display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
  margin-bottom: 8px;
}
.hdr__title { font-size: 17px; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.hdr__sub   { font-size: 12px; color: var(--ink-2); margin: 0; }
.hdr__spacer { flex: 1 1 auto; }

/* --------------------------------------------------------- controls ----- */

.ctl {
  display: inline-flex; align-items: center; gap: 0;
  border: 1px solid var(--hairline); border-radius: var(--radius);
  overflow: hidden; background: var(--surface-1);
}
.ctl button, .btn {
  font: inherit; font-size: 12px; color: var(--ink-2);
  background: transparent; border: 0; padding: 5px 10px; cursor: pointer;
  min-height: 26px;
}
.ctl button + button { border-left: 1px solid var(--hairline); }
.ctl button[aria-pressed="true"] { background: var(--series-1); color: #fff; }
.ctl button:hover:not([aria-pressed="true"]) { background: var(--sunken); }

.btn {
  border: 1px solid var(--hairline); border-radius: var(--radius);
  background: var(--surface-1);
}
.btn:hover { background: var(--sunken); }
.btn--quiet { border-color: transparent; }

/* ------------------------------------------------ multi-year context ---- */

.context {
  display: flex; align-items: flex-end; gap: 14px;
  padding: 2px 0 6px;
}
.context__chart { flex: 0 0 auto; }
.context__note { font-size: 11px; color: var(--ink-muted); padding-bottom: 4px; }

/* ------------------------------------------------------- year tabs ------ */

.years { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; padding-bottom: 8px; }
.years__tab {
  font: inherit; font-size: 13px; font-variant-numeric: tabular-nums;
  border: 1px solid transparent; border-bottom: 2px solid transparent;
  background: transparent; color: var(--ink-2);
  padding: 5px 11px; cursor: pointer; border-radius: var(--radius) var(--radius) 0 0;
}
.years__tab:hover { background: var(--sunken); }
.years__tab[aria-selected="true"] {
  color: var(--ink-1); font-weight: 650;
  border-bottom-color: var(--series-1);
  background: var(--sunken);
}
.years__tab[data-extra="true"] {
  border-bottom-color: var(--series-2); color: var(--ink-1);
}
.years__hint { font-size: 11px; color: var(--ink-muted); margin-left: 10px; }

/* ----------------------------------------------------- filter chips ----- */

.chips {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 7px clamp(12px, 2vw, 24px);
  background: var(--surface-1);
  border-bottom: 1px solid var(--hairline);
  min-height: 38px;
  position: sticky; top: var(--hdr-h, 0); z-index: 890;
}
.chips__label { font-size: 11px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .06em; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 3px 6px 3px 9px;
  border: 1px solid var(--hairline); border-radius: 999px;
  background: var(--sunken); color: var(--ink-1);
}
.chip__x {
  border: 0; background: transparent; cursor: pointer;
  color: var(--ink-2); font-size: 14px; line-height: 1;
  padding: 2px 4px; border-radius: 999px; min-width: 20px;
}
.chip__x:hover { background: var(--hairline); color: var(--ink-1); }
.chip--dropped {
  border-style: dashed; opacity: .8;
  border-color: var(--status-serious);
}
.chips__none { font-size: 12px; color: var(--ink-muted); }

/* -------------------------------------------------------------- KPIs ---- */

.kpis {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  padding: var(--gap) clamp(12px, 2vw, 24px) 0;
}
.kpi {
  background: var(--surface-1); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 11px 13px;
}
.kpi__value { font-size: 25px; font-weight: 620; letter-spacing: -.02em; line-height: 1.15; }
.kpi__label { font-size: 11.5px; color: var(--ink-2); margin-top: 2px; }
.kpi__sub   { font-size: 11px; color: var(--ink-muted); margin-top: 1px; }
.kpi--critical .kpi__value { color: var(--status-critical); }
.kpi--serious  .kpi__value { color: var(--status-serious); }
.kpi--warning  .kpi__value { color: var(--status-warning-ink); }

/* ------------------------------------------------------------- map ------ */

.mapwrap {
  margin: var(--gap) 0 0;
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  background: var(--surface-1);
  position: relative;
}
#map { width: 100%; height: 560px; background: var(--page); }
.map__bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 7px clamp(12px, 2vw, 24px);
  border-bottom: 1px solid var(--hairline);
  font-size: 12px; color: var(--ink-2);
}
.map__legend { display: flex; align-items: center; gap: 12px; margin-left: auto; flex-wrap: wrap; }
.map__key { display: inline-flex; align-items: center; gap: 5px; }
.map__dot { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 0 2px var(--surface-1); }
.map__ramp { display: inline-flex; align-items: center; gap: 5px; }
.map__ramp i { width: 74px; height: 9px; border-radius: 2px; display: inline-block;
  background: linear-gradient(90deg, var(--seq-100), var(--seq-400), var(--seq-700)); }
.map__hint { font-size: 11px; color: var(--ink-muted); }
label.map__check { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }

/* --------------------------------------------------------- chart grid -- */

.grid {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(12, 1fr);
  padding: var(--gap) clamp(12px, 2vw, 24px);
}
.card {
  background: var(--surface-1); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 11px 13px 6px;
  min-width: 0;
  grid-column: span 4;
}
.card--wide { grid-column: span 7; }
.card--half { grid-column: span 5; }
.card--full { grid-column: span 12; }
@media (max-width: 1180px) {
  .card, .card--wide, .card--half { grid-column: span 6; }
}
@media (max-width: 720px) {
  .card, .card--wide, .card--half, .card--full { grid-column: span 12; }
}

.card__hd { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.card__title { font-size: 12.5px; font-weight: 620; margin: 0; }
.card__note  { font-size: 11px; color: var(--ink-muted); }
.card__reset {
  margin-left: auto; font-size: 11px; color: var(--series-1);
  background: none; border: 0; cursor: pointer; padding: 2px 4px; visibility: hidden;
}
.card__reset[data-active="true"] { visibility: visible; }
.card__reset:hover { text-decoration: underline; }

/* toggle-chip filters (boolean flags) — a 2-slice pie would be an anti-pattern */
.flags { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0 8px; }
.flags button {
  font: inherit; font-size: 12px; cursor: pointer;
  border: 1px solid var(--hairline); border-radius: 999px;
  background: transparent; color: var(--ink-2); padding: 4px 11px; min-height: 26px;
}
.flags button:hover { background: var(--sunken); }
.flags button[aria-pressed="true"] {
  background: var(--series-1); border-color: var(--series-1); color: #fff;
}
.flags button .n { font-variant-numeric: tabular-nums; opacity: .75; margin-left: 4px; }

/* --------------------------------------------------------- dc overrides - */

.dc-chart { font-family: var(--font); }
.dc-chart g.axis text, .dc-chart .axis text { fill: var(--ink-muted); font-size: 10.5px; }
.dc-chart g.axis path.domain, .dc-chart .axis line { stroke: var(--axis); shape-rendering: crispEdges; }
.dc-chart .grid-line line { stroke: var(--grid); stroke-dasharray: none; opacity: 1; }
.dc-chart .grid-line.vertical { display: none; }

/* Fill is set in JS (charts.js), never here: a CSS `fill` beats the SVG
   presentation attribute dc writes, which would collapse the seven fixed
   vehicle hues into one colour.  Only the 2px surface gap and the
   deselected fade live in CSS. */
.dc-chart g.row rect { stroke: var(--surface-1); stroke-width: 2px; }
.dc-chart g.row.deselected rect { opacity: .3; }
.dc-chart g.row text { fill: var(--ink-1); font-size: 11.5px; }
.dc-chart g.row.deselected text { fill: var(--ink-muted); }
.dc-chart .row title { pointer-events: none; }

.dc-chart rect.bar { stroke: var(--surface-1); stroke-width: 0.5px; }
.dc-chart rect.bar.deselected { opacity: .35; }
.dc-chart .brush rect.selection { fill: var(--series-1); fill-opacity: .12; stroke: var(--series-1); }
.dc-chart .brush .custom-brush-handle { fill: var(--series-1); }

.dc-chart .heatmap g.box-group rect.heat-box { stroke: var(--surface-1); stroke-width: 2px; }
.dc-chart .heatmap g.box-group.deselected rect.heat-box { opacity: .3; }
.dc-chart .heatmap .cols.axis text, .dc-chart .heatmap .rows.axis text {
  fill: var(--ink-muted); font-size: 10.5px;
}

.dc-chart .empty-chart .pie-slice { fill: var(--ink-muted); }
.dc-chart text.value { display: none; }   /* no number on every mark */

/* ------------------------------------------------------------ table ----- */

.tablewrap { padding: 0 clamp(12px, 2vw, 24px) 40px; }
.tablecard { background: var(--surface-1); border: 1px solid var(--hairline); border-radius: var(--radius); }
.tablecard__hd {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 13px; border-bottom: 1px solid var(--hairline);
}
.tablecard__count { font-size: 12.5px; color: var(--ink-2); }
.tablecard__count strong { color: var(--ink-1); font-variant-numeric: tabular-nums; }
.tablecard__body { overflow-x: auto; }

table.dc-data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
table.dc-data-table th, table.dc-data-table td {
  text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--grid);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
table.dc-data-table th { color: var(--ink-muted); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .04em; }
table.dc-data-table tr:hover td { background: var(--sunken); }
table.dc-data-table td.num { text-align: right; }
.pager { display: flex; align-items: center; gap: 8px; padding: 9px 13px; font-size: 12px; color: var(--ink-2); }
.pager .btn { font-size: 12px; }

/* ------------------------------------------------------------ misc ------ */

.loading { position: relative; }
/* hold the previous render at reduced opacity — no skeleton flash, no jump */
.is-swapping .kpis, .is-swapping .grid, .is-swapping .tablewrap, .is-swapping #map {
  opacity: .38; transition: opacity .12s ease-out; pointer-events: none;
}
.boot {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--page); z-index: 2000; font-size: 13px; color: var(--ink-2);
}
.boot[hidden] { display: none; }
.err {
  margin: 24px; padding: 14px 16px; border-radius: var(--radius);
  border: 1px solid var(--status-critical); color: var(--ink-1);
  background: color-mix(in srgb, var(--status-critical) 8%, var(--surface-1));
  font-size: 13px; white-space: pre-wrap;
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Leaflet needs explicit dark treatment — it does not follow color-scheme */
.leaflet-container { background: var(--page); font-family: var(--font); }
.leaflet-control-zoom a {
  background: var(--surface-1); color: var(--ink-1); border-color: var(--hairline);
}
.leaflet-control-zoom a:hover { background: var(--sunken); }
.leaflet-control-attribution {
  background: color-mix(in srgb, var(--surface-1) 82%, transparent);
  color: var(--ink-muted); font-size: 10px;
}
.leaflet-control-attribution a { color: var(--ink-2); }
.leaflet-tooltip {
  background: var(--surface-1); color: var(--ink-1);
  border: 1px solid var(--hairline); box-shadow: 0 2px 10px rgba(0,0,0,.16);
  font-size: 12px;
}
.leaflet-tooltip-top:before { border-top-color: var(--hairline); }
.st-shape { transition: none; }
.map__select-box {
  position: absolute; border: 1.5px dashed var(--series-1);
  background: color-mix(in srgb, var(--series-1) 10%, transparent);
  pointer-events: none; z-index: 800;
}
