/* Tokens: --harvest and --other colour the two incident groups (categorical slots 1-2, validated in both modes). */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6d68;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --harvest: #2a78d6;
  --other: #eb6834;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #9a988f;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --harvest: #3987e5;
    --other: #d95926;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #9a988f;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --harvest: #3987e5;
  --other: #d95926;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
}
.viz-root { max-width: 1120px; margin: 0 auto; padding: 24px 16px 48px; }

/* Masthead */
.masthead { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
h1 { font-size: 26px; line-height: 1.25; margin: 0 0 6px; }
h2 { font-size: 17px; margin: 0 0 4px; }
.lede { margin: 0; color: var(--text-secondary); max-width: 62ch; }
.updated { margin: 6px 0 0; color: var(--text-muted); font-size: 13px; }
.langs { display: flex; gap: 4px; }
.langs button, .ghost {
  font: inherit; font-size: 14px; color: var(--text-secondary);
  background: transparent; border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 12px; cursor: pointer;
}
.langs button[aria-pressed="true"] { color: var(--text-primary); border-color: var(--text-secondary); font-weight: 600; }
.langs button:hover, .ghost:hover { background: var(--border); }

/* Incident group: the first choice, above the other filters */
.group-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 24px 0 0; }
.group-label { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.segmented { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; }
.segmented button {
  display: inline-flex; align-items: center; font: inherit; font-size: 15px; color: var(--text-secondary);
  background: transparent; border: 1px solid transparent; border-radius: 7px; padding: 7px 14px; cursor: pointer;
}
.segmented button:hover { background: var(--border); }
.segmented button[aria-checked="true"] { color: var(--text-primary); font-weight: 600; background: var(--page);
  border-color: var(--text-secondary); }
.segmented button:focus-visible { outline: 2px solid var(--text-primary); outline-offset: 1px; }
@media (max-width: 480px) { .segmented button { font-size: 14px; padding: 6px 9px; } }

/* Filters: one row above everything they scope */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin: 14px 0 16px; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-secondary); }
.filters input, .filters select, .search {
  font: inherit; font-size: 14px; color: var(--text-primary); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; min-height: 34px;
}
.filters select { max-width: 220px; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.tile .label { font-size: 13px; color: var(--text-secondary); }
.tile .value { font-size: 30px; font-weight: 600; line-height: 1.2; margin-top: 4px; }
.tile.hero .value { font-size: 48px; }
.tile .split { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: 13px; color: var(--text-secondary); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 18px 18px 16px; margin-bottom: 16px; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 .card { margin-bottom: 0; }
.grid-2 + .card { margin-top: 16px; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }
.note { color: var(--text-muted); font-size: 13px; margin: 0 0 12px; }
.note:empty { display: none; }
h3 { font-size: 14px; font-weight: 600; color: var(--text-secondary); margin: 20px 0 0; }

/* Incident groups: swatches and legends */
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-inline-end: 6px; vertical-align: baseline; }
.swatch.harvest { background: var(--harvest); }
.swatch.other { background: var(--other); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.card .note:last-child { margin: 10px 0 0; }
footer.note { margin-top: 24px; }

/* Map */
#map { height: 720px; border-radius: 8px; margin-top: 8px; background: var(--page); overflow: hidden; }
@media (max-width: 600px) { #map { height: 520px; } }
.maplibregl-map { font: inherit; }
.maplibregl-popup-content {
  background: var(--surface); color: var(--text-secondary); font-size: 13px;
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
}
.maplibregl-popup-content strong { display: block; color: var(--text-primary); font-size: 15px; }
.maplibregl-popup-tip { display: none; }
.maplibregl-popup { z-index: 1000; }
.tab-line { display: block; }
.pie { cursor: pointer; line-height: 0; }
.pie svg { overflow: visible; }
.pie .slice { opacity: 0.85; stroke: var(--surface); stroke-width: 1; }
.pie .slice.harvest { fill: var(--harvest); }
.pie .slice.other { fill: var(--other); }
.pie .ring { fill: none; stroke: var(--surface); stroke-width: 1.5; }
.pie:hover .slice, .pie:focus-visible .slice { opacity: 1; }
.pie:focus-visible { outline: 2px solid var(--text-primary); outline-offset: 2px; border-radius: 50%; }

/* Timeline (SVG) */
.timeline { width: 100%; margin-top: 12px; direction: ltr; }
.timeline svg { display: block; width: 100%; height: auto; overflow: visible; }
.timeline .grid { stroke: var(--grid); stroke-width: 1; }
.timeline .baseline { stroke: var(--axis); stroke-width: 1; }
.timeline .tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.timeline .seg.harvest { fill: var(--harvest); }
.timeline .seg.other { fill: var(--other); }
.timeline .bar.provisional { opacity: 0.45; }
.timeline .hit { fill: transparent; cursor: default; }
.timeline .hit:hover + .bar, .timeline .hit:focus + .bar { opacity: 0.75; }
.timeline .hit:focus { outline: none; }

/* Horizontal bars (HTML, so they mirror in RTL automatically) */
.hbars { display: grid; gap: 6px; margin-top: 12px; }
.hbar {
  display: grid; grid-template-columns: minmax(90px, 38%) 1fr; gap: 10px; align-items: center;
  font: inherit; color: inherit; text-align: start; background: none; border: 0; padding: 2px 0; border-radius: 4px;
}
button.hbar { cursor: pointer; }
button.hbar:hover, button.hbar:focus-visible { background: var(--border); outline: none; }
.hbar .name { font-size: 14px; color: var(--text-secondary); overflow-wrap: anywhere; }
.hbar .track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hbar .stack { display: flex; gap: 2px; height: 16px; min-width: 2px; border-radius: 0 4px 4px 0; overflow: hidden; }
[dir="rtl"] .hbar .stack { border-radius: 4px 0 0 4px; }
.hbar .fill { min-width: 2px; }
.hbar .fill.harvest { background: var(--harvest); }
.hbar .fill.other { background: var(--other); }
.hbar .num { font-size: 13px; color: var(--text-primary); font-variant-numeric: tabular-nums; }

/* Incident list (the table view) */
.search { width: 100%; max-width: 360px; margin: 8px 0 12px; }
.incidents { width: 100%; border-collapse: collapse; font-size: 14px; }
.incidents th { text-align: start; font-size: 12px; font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--axis); padding: 6px 8px; }
.incidents td { vertical-align: top; border-bottom: 1px solid var(--grid); padding: 8px; }
.incidents td:first-child { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--text-secondary); }
@media (max-width: 640px) {
  .incidents thead { display: none; }
  .incidents tr { display: block; border-bottom: 1px solid var(--grid); padding: 8px 0; }
  .incidents td { display: inline; border: 0; padding: 0 8px 0 0; }
  .incidents td:last-child { display: block; padding-top: 4px; }
}
#more { margin-top: 12px; }

/* Tooltip */
.tooltip {
  position: fixed; z-index: 1000; pointer-events: none; max-width: 240px;
  background: var(--surface); color: var(--text-secondary); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 10px; font-size: 13px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
}
.tooltip strong { display: block; color: var(--text-primary); font-size: 15px; }
.tooltip span { display: block; }
.tooltip .swatch { display: inline-block; }
