:root {
  color-scheme: light dark;
  --bg: light-dark(#f5f6f8, #16181d);
  --card: light-dark(#ffffff, #1f2229);
  --fg: light-dark(#1d2129, #e6e8ec);
  --muted: light-dark(#5a6270, #a3aab6);
  --line: light-dark(#e1e4e9, #343944);
  --accent: light-dark(#1f5fbf, #7fb0ff);
  --focus: light-dark(#1f5fbf, #9cc3ff);
  --warn-bg: light-dark(#fff6dd, #3a3220);
  --warn-line: light-dark(#e0a800, #d9a520);
  --error: light-dark(#b3261e, #ff8a80);
  --shadow: 0 1px 2px rgb(0 0 0 / .08), 0 6px 20px rgb(0 0 0 / .12);
  --radius: 12px;
  --peek: 112px;
}
:root[data-theme=light] { color-scheme: light; }
:root[data-theme=dark] { color-scheme: dark; --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 24px rgb(0 0 0 / .5); }

.sev-0 { --sev: #ffe066; --ink: #1a1a1a; }
.sev-1 { --sev: #fdb53a; --ink: #1a1a1a; }
.sev-2 { --sev: #f48a1f; --ink: #1a1a1a; }
.sev-3 { --sev: #e04b1a; --ink: #111; }
.sev-4 { --sev: #a3141b; --ink: #fff; }
.sev-5 { --sev: #220000; --ink: #fff; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--fg); background: var(--bg);
}
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
/* The map fills the viewport, so an outside outline would be clipped. */
#map:focus-visible { outline-offset: -3px; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

#map { position: fixed; inset: 0; background: var(--bg); }

#sidebar {
  position: fixed; z-index: 1000; top: 12px; left: 12px; width: 370px;
  max-height: calc(100% - 24px); display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
#head { padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
/* Open/closed is pure CSS so the first paint is final: desktop is open unless .collapsed, phone is closed unless .open. */
@media (min-width: 701px) {
  #sidebar.collapsed #head { border-bottom: 0; }
  #sidebar.collapsed #panel, #sidebar.collapsed .if-open, #sidebar:not(.collapsed) .if-closed { display: none; }
}
#panel { overflow-y: auto; padding: 4px 14px 14px; overscroll-behavior: contain; }
h1 { font-size: 15px; line-height: 1.3; margin: 0 0 8px; letter-spacing: -.01em; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 0 8px; }
.bar { display: flex; align-items: center; gap: 6px; }
#count { flex: 1; margin: 0; min-height: 2.9em; font-weight: 600; font-variant-numeric: tabular-nums; }

button {
  font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 10px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
#theme[aria-pressed=true] { background: var(--fg); color: var(--card); }

.summary { padding-left: 18px; margin: 10px 0; }
.summary li { margin-bottom: 6px; }
.disclaimer { background: var(--warn-bg); border-left: 4px solid var(--warn-line); border-radius: 6px; padding: 8px 10px; margin: 10px 0; }
.updated, .hint { color: var(--muted); font-size: 12px; margin: 4px 0; }

fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 10px; padding: 6px 10px 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; }
legend { font-weight: 600; padding: 0 4px; }
fieldset label { display: flex; align-items: center; gap: 6px; min-height: 28px; cursor: pointer; }
input[type=checkbox] { width: 18px; height: 18px; margin: 0; flex: none; }
.field { display: block; margin-bottom: 8px; font-weight: 600; }
select, input[type=date], input[type=search] {
  display: block; width: 100%; margin-top: 3px; padding: 5px 6px; font: inherit; font-weight: 400;
  color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
.dates { display: flex; gap: 8px; }
.dates label { flex: 1; }
[aria-invalid=true] { border-color: var(--error); outline: 2px solid var(--error); }
#date-warn { color: var(--error); font-weight: 600; margin: 0 0 8px; }

.sw { display: inline-block; flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--sev); border: 1px solid rgb(0 0 0 / .45); vertical-align: -1px; margin-right: 4px; }
.sw.hollow { background: transparent; border: 2px dashed #c0392b; }
.sw.cl { width: 16px; height: 16px; background: var(--sev); border: 2px solid rgb(255 255 255 / .8); box-shadow: 0 0 0 1px rgb(0 0 0 / .4); }

#top-list { list-style: none; padding: 0; margin: 0; min-height: 288px; }
#top-list button { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; width: 100%; min-height: 32px; text-align: left; background: none; border-color: transparent; padding: 4px 6px; }
#top-list button:hover, #top-list button[aria-pressed=true] { background: var(--bg); border-color: var(--line); }
#top-list button[aria-pressed=true] { font-weight: 600; }
.stack { grid-column: 1 / -1; display: flex; height: 6px; border-radius: 3px; overflow: hidden; background: var(--line); }
.stack span { background: var(--sev); }

/* Skip link: off-screen until focused */
.skip { position: fixed; z-index: 1100; top: 12px; left: -999px; padding: 8px 12px; background: var(--card); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); font-weight: 600; }
.skip:focus { left: 400px; }

/* Severity mix of the shown incidents. Fixed heights so the late render shifts nothing. */
#mix-bar { height: 8px; border-radius: 4px; margin: 0 0 6px; }
#mix { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; min-height: 66px; font-variant-numeric: tabular-nums; }
#mix li { display: flex; align-items: center; gap: 4px; min-height: 22px; white-space: nowrap; }
#mix li.zero { color: var(--muted); }
#mix strong { font-weight: 600; }

/* Search */
input[type=search] { -webkit-appearance: none; appearance: none; }
.hint#q-hint { margin: -4px 0 10px; }

/* Timeline: one bar per day, stacked by severity */
h3.sub { font-size: 13px; margin: 12px 0 2px; }
#timeline { list-style: none; padding: 0; margin: 4px 0 8px; display: flex; gap: 4px; height: 96px; }
#timeline li { flex: 1; min-width: 0; display: flex; }
#timeline button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 2px; padding: 4px 2px 2px; background: none; border-color: transparent; font-size: 11px; line-height: 1.2; }
#timeline button:hover, #timeline button[aria-pressed=true] { background: var(--bg); border-color: var(--line); }
#timeline button[aria-pressed=true] { font-weight: 700; }
#timeline button.out { opacity: .55; }
#timeline .n { font-weight: 600; font-variant-numeric: tabular-nums; }
#timeline .tbar { width: 70%; max-width: 32px; min-height: 0; flex: none; display: flex; flex-direction: column-reverse; border-radius: 3px 3px 0 0; overflow: hidden; background: var(--line); transition: height .2s; }
#timeline .tbar span { background: var(--sev); }
#timeline .d { color: var(--muted); white-space: nowrap; }

/* Actions row and share box */
.actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.actions button { padding: 5px 8px; }
#status { min-height: 1.5em; margin: 6px 0 0; }
#share { display: block; width: 100%; margin-top: 4px; padding: 5px 6px; font: inherit; font-size: 12px; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }

/* Incident list */
#list-sec { margin-top: 16px; border-top: 1px solid var(--line); }
#list-sec summary { cursor: pointer; min-height: 32px; display: flex; align-items: center; gap: 6px; }
#list-sec summary h2 { display: inline; margin: 0; }
#list { list-style: none; padding: 0; margin: 0; }
.item { padding: 8px 0; border-top: 1px solid var(--line); break-inside: avoid; }
.item .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--muted); font-size: 12px; }
.item .meta .small { margin-left: auto; }
.item h3 { margin: 4px 0 2px; font-size: 14px; }
.item .loc { font-weight: 400; color: var(--muted); }
.item p { margin: 3px 0; }
.item .approx { color: light-dark(#8a4b00, #ffb366); font-style: italic; }
button.small { padding: 2px 8px; font-size: 12px; }

/* Spider legs follow the theme */
.leaflet-cluster-spider-leg, path.spider-leg { stroke: var(--fg); }

/* Map markers */
.pin { border-radius: 50%; background: var(--sev); border: 1px solid rgb(0 0 0 / .65); box-shadow: 0 0 0 1px rgb(255 255 255 / .5); }
.pin.hollow { background: rgb(255 255 255 / .2); border: 2px dashed var(--sev); box-shadow: 0 0 0 1px rgb(0 0 0 / .45); }
.sev-0.pin.hollow { border-color: #c9a200; }
.cluster {
  display: grid; place-items: center; border-radius: 50%; background: var(--sev); color: var(--ink);
  font-weight: 700; font-size: 12px; border: 2px solid rgb(255 255 255 / .85); box-shadow: 0 0 0 1px rgb(0 0 0 / .35), 0 2px 6px rgb(0 0 0 / .3);
}
.leaflet-marker-icon:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Dark basemap: CARTO Dark Matter now needs an API key, so OSM tiles are inverted instead. */
:root[data-theme=dark] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.85) saturate(.6); }

/* Leaflet chrome follows the theme */
.leaflet-container { font: inherit; background: var(--bg); }
.leaflet-bar a, .leaflet-control-attribution, .legend { background: var(--card) !important; color: var(--fg) !important; }
.leaflet-control-attribution { background: color-mix(in srgb, var(--card) 85%, transparent) !important; }
.leaflet-control-attribution a { color: var(--accent); }
.leaflet-bar, .legend { border: 1px solid var(--line) !important; box-shadow: var(--shadow) !important; border-radius: 8px; }
.leaflet-bar a { border-bottom-color: var(--line); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--card); color: var(--fg); box-shadow: var(--shadow); }
.leaflet-popup-content-wrapper { border-radius: var(--radius); }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }

.legend { padding: 8px 12px; line-height: 1.7; max-width: 230px; }
.legend summary { font-weight: 600; cursor: pointer; min-height: 24px; }
.legend small { display: flex; gap: 4px; align-items: flex-start; line-height: 1.35; margin-top: 6px; color: var(--muted); }

.popup { min-width: 220px; }
.popup .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--muted); font-size: 12px; }
.chip { background: var(--sev); color: var(--ink); border-radius: 999px; padding: 1px 8px; font-weight: 700; font-size: 12px; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .2); }
.popup h3 { margin: 6px 0 0; font-size: 15px; }
.popup .loc { margin: 0 0 6px; color: var(--muted); }
.popup p { margin: 5px 0; }
.popup .approx { color: light-dark(#8a4b00, #ffb366); font-style: italic; }

@media (max-width: 700px) {
  #map { bottom: var(--peek); }
  #head { height: var(--peek); overflow: hidden; }
  #head h1 { font-size: 14px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
  #sidebar:not(.open) #head { border-bottom: 0; }
  #sidebar:not(.open) #panel, #sidebar:not(.open) .if-open, #sidebar.open .if-closed { display: none; }
  #sidebar { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: none; border-radius: var(--radius) var(--radius) 0 0; border-bottom: 0; }
  #panel { max-height: calc(70vh - var(--peek)); max-height: calc(70dvh - var(--peek)); }
  .legend { max-width: 190px; font-size: 12px; }
}
@media (max-width: 700px) {
  .skip:focus { left: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .leaflet-cluster-anim .leaflet-marker-icon, .leaflet-cluster-spider-leg, #timeline .tbar { transition: none; }
}

/* Print: the summary, sources, disclaimer and the incident list; no map. */
.print-only { display: none; }
@media print {
  :root, :root[data-theme] { color-scheme: light !important; --shadow: none; }
  #map, #theme, #toggle, .skip, .actions, #status, #share, .if-open, .if-closed,
  #filters > h2, #filters .field, #q-hint, #filters fieldset, .dates, #date-warn, .item .small { display: none !important; }
  #mix { grid-template-columns: repeat(3, 1fr); min-height: 0; }
  #sidebar { position: static; width: auto; max-height: none; border: 0; box-shadow: none; display: block; }
  #head { height: auto; overflow: visible; }
  #panel { display: block !important; overflow: visible; max-height: none; padding: 0; }
  .print-only { display: block; color: var(--muted); font-size: 12px; word-break: break-all; }
  #list-sec summary { list-style: none; }
  #list-sec summary::-webkit-details-marker { display: none; }
  .item a::after { content: " " attr(href); font-size: 11px; color: var(--muted); word-break: break-all; }
  #timeline button { border-color: var(--line); }
}
