/* Blockwise SF
   Fog-grey page, Pacific-navy ink, and one bold element: the street-sign plate.
   Type: Overpass (descended from US highway signage lettering). */

:root {
  color-scheme: light;
  --fog: #edf1f3;
  --surface: #fbfcfc;
  --ink: #102a43;
  --ink-2: #3f566c;
  --ink-3: #5d7184;
  --rule: #d3dce2;
  --rule-strong: #b7c4ce;
  --active-bg: #e3eaef;
  --plate: #102a43;
  --plate-ink: #f4f8fa;
  --plate-rule: rgba(244, 248, 250, 0.72);
  --focus: #1d6fd1;

  /* Layer colors: validated categorical palette, fixed order. Text on each fill: --on-*. */
  --c-311: #2a78d6;
  --c-police: #eb6834;
  --c-fire: #1baf7a;
  --c-permits: #eda100;
  --c-business: #e87ba4;
  --c-inspections: #008300;
  --c-evictions: #6250d6;
  --on-permits: #0b0b0b;

  /* Status: always paired with an icon and a word. */
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --warning-ink: #7a5200;
  --critical: #d03b3b;
  --critical-ink: #a32424;

  --font: 'Overpass', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius: 10px;
  --topbar-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --fog: #0c1620;
    --surface: #132230;
    --ink: #e5edf2;
    --ink-2: #b4c4cf;
    --ink-3: #93a6b4;
    --rule: #233648;
    --rule-strong: #34495c;
    --active-bg: #1b3043;
    --plate: #1c4466;
    --plate-ink: #f4f8fa;
    --focus: #6aa8f0;

    --c-311: #3987e5;
    --c-police: #d95926;
    --c-fire: #199e70;
    --c-permits: #c98500;
    --c-business: #d55181;
    --c-inspections: #008300;
    --c-evictions: #9085e9;
    --on-permits: #0b0b0b;

    --good-ink: #5fd35f;
    --warning-ink: #fab219;
    --critical-ink: #ff8a8a;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--fog);
  color: var(--ink);
  font: 400 16px/1.45 var(--font);
  font-feature-settings: 'kern';
  -webkit-font-smoothing: antialiased;
  padding-top: var(--safe-top);
}

h1, h2, h3, p, dl, dd, ol, ul { margin: 0; }
h2 { font-size: 1.3rem; font-weight: 800; line-height: 1.2; letter-spacing: -0.005em; }
h3 { font-size: 1.05rem; font-weight: 800; line-height: 1.25; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.skip {
  position: absolute; left: 12px; top: -48px; z-index: 50;
  background: var(--ink); color: var(--surface); padding: 8px 12px; border-radius: 6px;
}
.skip:focus { top: calc(8px + var(--safe-top)); }

.muted { color: var(--ink-3); font-size: 0.875rem; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px;
  border: 1.5px solid var(--ink); border-radius: 8px;
  background: var(--ink); color: var(--surface);
  font-weight: 600; font-size: 0.9375rem; line-height: 1;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: 0.55; cursor: default; filter: none; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--rule-strong); }
.btn-ghost:hover { background: var(--active-bg); filter: none; }
.btn-small { min-height: 34px; padding: 0 12px; font-size: 0.875rem; }
.btn-icon { width: 40px; padding: 0; }
.btn-danger { background: transparent; color: var(--critical-ink); border-color: currentColor; }
.btn[aria-pressed='true'] { background: transparent; color: var(--ink); border-color: var(--ink); }
.btn[aria-pressed='true']::before { content: '✓'; font-weight: 800; }

.chip {
  min-height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1.5px solid var(--rule-strong); background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 0.9375rem; cursor: pointer;
}
.chip:hover { border-color: var(--ink); }

/* ---------- top bar ---------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: var(--topbar-h); padding: 0 16px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 800; font-size: 1.125rem; letter-spacing: -0.01em; }
.brand-mark { width: 26px; height: 26px; fill: var(--ink); }
.brand-mark .brand-dot { fill: var(--fog); stroke: var(--ink); stroke-width: 2.2; }
.topbar-actions { display: flex; gap: 6px; }
.topbar-actions .btn-ghost { border-color: transparent; padding: 0 10px; white-space: nowrap; }
.brand span { white-space: nowrap; }
.topbar .narrow { display: none; }
@media (max-width: 480px) {
  .topbar { padding: 0 10px 0 16px; gap: 6px; }
  .topbar .wide { display: none; }
  .topbar .narrow { display: inline; }
}

.banner {
  margin: 0 16px 12px; padding: 10px 14px; border-radius: 8px;
  background: color-mix(in srgb, var(--warning) 22%, var(--surface)); color: var(--ink);
  font-size: 0.9375rem; border: 1px solid color-mix(in srgb, var(--warning) 55%, var(--surface));
}
.banner::before { content: '!'; display: inline-grid; place-items: center; width: 20px; height: 20px; margin-right: 8px; border-radius: 50%; background: var(--warning); color: #0b0b0b; font-weight: 800; font-size: 0.8rem; }

/* ---------- layout ---------- */

.layout { display: block; }
.zone-sign { position: relative; z-index: 10; padding: 0 16px 16px; }
.zone-map { position: sticky; top: 0; z-index: 5; height: max(240px, 36vh); background: var(--active-bg); }
/* MapLibre's own CSS (loaded later) sets .maplibregl-map { position: relative }; the id selector wins. */
#map { position: absolute; inset: 0; width: 100%; height: 100%; }
.map-note { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--ink-2); font-size: 0.9375rem; }
.map-note.is-overlay { inset: auto 12px 12px 12px; padding: 8px 12px; border-radius: 8px; background: var(--surface); box-shadow: 0 6px 18px -8px rgba(16, 42, 67, 0.4); z-index: 2; }
.zone-report { padding: 20px 16px calc(32px + var(--safe-bottom)); outline: none; }

body[data-view='home'] .zone-map { position: relative; height: max(220px, 30vh); }
/* Phones: no map on the home screen; it loads once a place is picked. */
@media (max-width: 959px) { body[data-view='home'] .zone-map { display: none; } }
/* Keep scrolled-to headings clear of the pinned map on phones. */
.list-head, .property, .item, .saved h2 { scroll-margin-top: calc(max(240px, 36vh) + 12px); }

@media (min-width: 960px) {
  .layout {
    display: grid;
    grid-template-columns: minmax(400px, 470px) 1fr;
    grid-template-rows: auto 1fr;
    align-items: start;
  }
  .zone-sign { grid-column: 1; grid-row: 1; padding: 4px 24px 18px; }
  .zone-report { grid-column: 1; grid-row: 2; padding: 8px 24px 40px; }
  .list-head, .property, .item, .saved h2 { scroll-margin-top: 16px; }
  .zone-map, body[data-view='home'] .zone-map {
    grid-column: 2; grid-row: 1 / span 2;
    position: sticky; top: 0; height: 100dvh;
    border-left: 1px solid var(--rule);
  }
}

/* ---------- the plate (hero) ---------- */

.plate {
  position: relative;
  background: var(--plate); color: var(--plate-ink);
  border-radius: 14px; padding: 22px 22px 18px;
  /* The enamel-sign inner line is drawn with shadows: no layer sits on top of the search box. */
  box-shadow: inset 0 0 0 6px var(--plate), inset 0 0 0 7.5px var(--plate-rule);
}
.plate[data-mode='search'] .placard { display: none; }
.suggest { z-index: 3; }

/* On a place page the search box stays, compact, above the address: a real field to tap. */
.plate[data-mode='place'] .search-label,
.plate[data-mode='place'] .search-hint,
.plate[data-mode='city'] .search-label,
.plate[data-mode='city'] .search-hint { display: none; }
.plate[data-mode='place'] #q,
.plate[data-mode='city'] #q {
  font-size: 1.0625rem; font-weight: 600; letter-spacing: 0;
  padding: 10px 12px; border-radius: 8px; border-bottom: 0;
}
.plate[data-mode='place'] .search-row,
.plate[data-mode='city'] .search-row { margin-top: 10px; }
.plate[data-mode='place'] #locateBtn,
.plate[data-mode='city'] #locateBtn { min-height: 34px; padding: 0 12px; font-size: 0.875rem; }
.plate[data-mode='place'] .placard,
.plate[data-mode='city'] .placard { margin-top: 16px; }

.search-label { display: block; font-size: 0.9375rem; font-weight: 600; opacity: 0.9; margin-bottom: 6px; }
#q {
  display: block; width: 100%;
  background: transparent; border: 0; border-bottom: 2px solid var(--plate-rule); border-radius: 0;
  color: var(--plate-ink);
  font-family: var(--font); font-weight: 800; font-size: 28px; line-height: 1.15;
  padding: 8px 12px 10px;
  background: rgba(244, 248, 250, 0.09); border-radius: 8px 8px 0 0; /* reads as a field, not a heading */
}
#q:focus { background: rgba(244, 248, 250, 0.14); }
/* MapLibre sets user-select:none on <html> while a map drag is in progress; on iPhone that can
   stop a text field from taking input. Fields always opt back in. */
input, textarea { -webkit-user-select: text; user-select: text; }
/* No double-tap-zoom wait on taps. */
button, a { touch-action: manipulation; }
#q::placeholder { color: rgba(244, 248, 250, 0.42); }
#q:focus-visible { outline: none; border-bottom-color: var(--plate-ink); }
.search-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-top: 14px; position: relative; }
.search-hint { font-size: 0.875rem; opacity: 0.78; }
.btn-plate { background: transparent; color: var(--plate-ink); border-color: var(--plate-rule); }
.btn-plate:hover { background: rgba(244, 248, 250, 0.1); filter: none; }

.placard-title {
  font-weight: 800; text-transform: uppercase;
  font-size: clamp(1.9rem, 8.6vw, 2.75rem); line-height: 1.02; letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}
/* The address itself is the way to search again: tap it to type over it. */
.placard-edit {
  all: unset; display: inline; cursor: text;
  font: inherit; text-transform: inherit; letter-spacing: inherit; color: inherit;
  text-decoration: underline 2px transparent; text-underline-offset: 0.12em;
  -webkit-tap-highlight-color: transparent;
}
.placard-edit:hover { text-decoration-color: var(--plate-rule); }
.placard-edit:focus-visible { outline: 3px solid var(--plate-ink); outline-offset: 4px; border-radius: 4px; }
.placard-sub { display: flex; flex-wrap: wrap; gap: 2px 16px; margin-top: 10px; font-size: 0.9375rem; opacity: 0.86; }
.placard-sub a { color: inherit; text-decoration: underline; text-decoration-color: var(--plate-rule); text-underline-offset: 3px; }
.placard-sub a:hover { text-decoration-color: currentColor; }
.placard-sub a:focus-visible { outline: 3px solid var(--plate-ink); outline-offset: 3px; border-radius: 3px; }
.placard-actions { position: relative; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.btn-plate-solid { background: var(--plate-ink); color: var(--plate); border-color: var(--plate-ink); }
.plate .btn[aria-pressed='true'] { background: transparent; color: var(--plate-ink); border-color: var(--plate-ink); }

.suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px);
  list-style: none; padding: 6px; margin: 0;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule-strong); border-radius: var(--radius);
  box-shadow: 0 14px 32px -12px rgba(16, 42, 67, 0.35);
  max-height: 60vh; overflow: auto;
}
.suggest li { display: flex; flex-direction: column; padding: 10px 12px; border-radius: 7px; cursor: pointer; }
.suggest li strong { font-weight: 600; }
.suggest li span { font-size: 0.875rem; color: var(--ink-3); }
.suggest li:hover, .suggest li.is-active { background: var(--active-bg); }
.suggest li.hint { cursor: default; color: var(--ink-2); font-size: 0.9375rem; }
.suggest li.hint:hover { background: transparent; }

/* ---------- property facts under the plate ---------- */

.facts-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 12px 16px;
  margin-top: 14px; padding: 0 4px;
}
.fact dt { font-size: 0.8125rem; color: var(--ink-3); }
.fact dd { font-weight: 800; font-size: 1.0625rem; line-height: 1.2; }
.fact-note { display: block; font-weight: 400; font-size: 0.8125rem; color: var(--ink-2); margin-top: 2px; }

/* ---------- home ---------- */

.lede { font-size: 1.0625rem; line-height: 1.5; max-width: 60ch; color: var(--ink-2); }
.examples { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; }
.examples-label { font-weight: 600; margin-right: 4px; }
.saved { margin-top: 32px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.saved-list { list-style: none; padding: 0; border-top: 1px solid var(--rule); }
.saved-item { display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--rule); }
.saved-open {
  flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 14px 0; background: none; border: 0; text-align: left; cursor: pointer;
}
.saved-open strong { font-weight: 800; font-size: 1.0625rem; }
.saved-open span { font-size: 0.875rem; color: var(--ink-3); }
.saved-open .pill-new { margin: 4px 0 0; color: var(--surface); font-size: 0.75rem; }

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

.controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px 20px; }
.seg { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: nowrap; }
.seg legend { font-size: 0.8125rem; color: var(--ink-3); margin-bottom: 6px; padding: 0; }
.seg-opt { position: relative; }
.seg-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg-opt label {
  display: inline-flex; align-items: center; min-height: 38px; padding: 0 12px;
  border: 1.5px solid var(--rule-strong); margin-left: -1.5px;
  background: var(--surface); font-weight: 600; font-size: 0.9375rem; cursor: pointer; white-space: nowrap;
}
.seg-opt:first-of-type label { border-radius: 8px 0 0 8px; margin-left: 0; }
.seg-opt:last-of-type label { border-radius: 0 8px 8px 0; }
/* Native select (the phone's own picker). 16px text, or iPhone zooms the page when it opens. */
.pick { display: flex; flex-direction: column; flex: 0 1 300px; min-width: 0; max-width: 100%; }
.pick > span { font-size: 0.8125rem; color: var(--ink-3); margin-bottom: 6px; }
.pick select {
  appearance: none; -webkit-appearance: none; width: 100%; min-height: 38px; padding: 0 36px 0 12px;
  border: 1.5px solid var(--rule-strong); border-radius: 8px; color: var(--ink); font: inherit; font-weight: 600; font-size: 1rem;
  background-color: var(--surface);
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 19px) 55%, calc(100% - 14px) 55%; background-size: 5px 5px; background-repeat: no-repeat;
  cursor: pointer;
}
.pick select:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.seg-opt input:checked + label { background: var(--ink); color: var(--surface); border-color: var(--ink); position: relative; z-index: 1; }
.seg-opt input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; z-index: 2; }

/* ---------- ledger: legend, filter and counts in one ---------- */

.ledger { margin-top: 20px; border-top: 2px solid var(--ink); }
.ledger-row {
  display: grid; grid-template-columns: 26px 1fr auto; align-items: start; gap: 12px;
  width: 100%; padding: 12px 12px 12px 10px;
  background: transparent; border: 0; border-bottom: 1px solid var(--rule);
  text-align: left; cursor: pointer;
}
.ledger-row:hover { background: color-mix(in srgb, var(--active-bg) 60%, transparent); }
.ledger-row.is-active { background: var(--active-bg); box-shadow: inset 4px 0 0 var(--ink); }
.ledger-row:first-child .ledger-label { font-weight: 800; }
.ledger-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ledger-label { font-weight: 600; font-size: 1rem; line-height: 1.25; }
.ledger-line { font-size: 0.875rem; color: var(--ink-2); }
.ledger-sub { font-size: 0.8125rem; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ledger-count { font-weight: 800; font-size: 1.375rem; line-height: 1.1; font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
.ledger-count.is-loading::after {
  content: ''; display: inline-block; width: 2.2ch; height: 0.9em; border-radius: 4px;
  background: var(--rule); animation: pulse 1.1s ease-in-out infinite;
}
.ledger-row.is-error .ledger-count { color: var(--critical-ink); }

.swatch {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--c); color: var(--on, #fff);
  font-weight: 800; font-size: 0.75rem; line-height: 1;
  box-shadow: 0 0 0 2px var(--surface);
}
.swatch[style*='permits'] { --on: var(--on-permits); }
.swatch-all { background: transparent; border: 2.5px solid var(--ink); box-shadow: none; }
.swatch-sm { width: 22px; height: 22px; font-size: 0.6875rem; margin-top: 1px; }

.pill-new {
  display: inline-block; margin-left: 8px; padding: 1px 7px 0;
  border-radius: 999px; background: var(--ink); color: var(--surface);
  font-size: 0.75rem; font-weight: 800; line-height: 1.5; vertical-align: 0.12em;
}

/* ---------- item list ---------- */

.list-head { margin-top: 28px; }
.list-note { margin-top: 4px; font-size: 0.875rem; color: var(--ink-3); max-width: 62ch; }
.items { list-style: none; padding: 0; margin-top: 10px; border-top: 1px solid var(--rule); }
.item {
  position: relative;
  display: grid; grid-template-columns: 22px 1fr auto; gap: 12px; align-items: start;
  padding: 14px 6px 14px 4px; border-bottom: 1px solid var(--rule);
}
.item-hit { position: absolute; inset: 0; width: 100%; background: none; border: 0; cursor: pointer; border-radius: 0; }
.item-hit:hover { background: color-mix(in srgb, var(--active-bg) 55%, transparent); }
.item.is-selected { background: var(--active-bg); }
.item.is-selected .item-hit { box-shadow: inset 4px 0 0 var(--ink); }
/* The whole row is one button underneath; content sits above it and lets taps fall through. */
.item > .swatch, .item-body, .item > .badge { position: relative; pointer-events: none; }
.item-body { min-width: 0; }
.item-body a, .item-body details { pointer-events: auto; position: relative; z-index: 1; }
.item-title { font-weight: 600; line-height: 1.3; }
.item-detail { font-size: 0.9375rem; color: var(--ink-2); margin-top: 2px; overflow-wrap: anywhere; }
.item-meta { display: flex; flex-wrap: wrap; gap: 0 14px; font-size: 0.8125rem; color: var(--ink-3); margin-top: 4px; }
.item-extra { font-size: 0.8125rem; color: var(--ink-3); margin-top: 2px; }
.item-link { display: inline-block; margin-top: 6px; font-size: 0.875rem; font-weight: 600; }
.item-notes { margin-top: 6px; font-size: 0.875rem; color: var(--ink-2); }
.item-notes summary { cursor: pointer; font-weight: 600; color: var(--ink); width: max-content; }
.item-notes p { margin-top: 6px; max-width: 62ch; }
.empty { padding: 20px 4px; color: var(--ink-2); }
.more { margin-top: 14px; width: 100%; }

.badge {
  justify-self: end; white-space: nowrap;
  padding: 2px 9px 1px; border-radius: 999px; border: 1.5px solid var(--rule-strong);
  font-size: 0.75rem; font-weight: 600; line-height: 1.5; color: var(--ink-2);
}
.badge.tone-open { border-color: var(--ink); color: var(--ink); }
.badge.tone-good { border-color: var(--good); color: var(--good-ink); }
.badge.tone-warning { border-color: var(--warning); color: var(--warning-ink); }
.badge.tone-critical { border-color: var(--critical); color: var(--critical-ink); }
.badge.tone-good::before { content: '✓ '; }
.badge.tone-warning::before { content: '! '; font-weight: 800; }
.badge.tone-critical::before { content: '✕ '; }

@keyframes pulse { 50% { opacity: 0.4; } }
@keyframes flash { from { background: color-mix(in srgb, var(--focus) 22%, var(--surface)); } }
.item.is-selected { animation: flash 900ms ease-out; }

/* ---------- property ---------- */

.property { margin-top: 32px; border-top: 2px solid var(--ink); padding-top: 4px; }
.property summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; padding: 12px 0; }
.property summary::-webkit-details-marker { display: none; }
.property summary::after { content: '+'; font-weight: 800; font-size: 1.4rem; line-height: 1; }
.property[open] summary::after { content: '−'; }
#propertyBody > * + * { margin-top: 12px; }
#propertyBody h3 { margin-top: 22px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.kv dt { font-size: 0.8125rem; color: var(--ink-3); }
.kv dd { font-weight: 600; }
.history { list-style: none; padding: 0; border-top: 1px solid var(--rule); }
.history li { display: grid; grid-template-columns: 92px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--rule); font-size: 0.9375rem; }
.history-date { color: var(--ink-3); font-size: 0.8125rem; font-variant-numeric: tabular-nums; padding-top: 2px; }
.history-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.history-body .muted { font-size: 0.8125rem; }

/* ---------- citywide stats ---------- */

:root { --s1: var(--c-311); --s2: var(--c-police); } /* chart series 1 and 2 (validated pair) */
body[data-view='city'] .zone-map { display: none; }
@media (min-width: 960px) {
  body[data-view='city'] .layout { grid-template-columns: minmax(0, 900px); justify-content: center; }
}
.home-city { margin-top: 16px; }
.city .controls { margin-top: 4px; }
.stat-section { margin-top: 28px; border-top: 2px solid var(--ink); padding-top: 14px; transition: opacity 200ms ease; }
.stat-section.is-stale { opacity: 0.5; }
.stat-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.stat-through { font-size: 0.8125rem; color: var(--ink-3); }
.stat-sub { margin-top: 22px; }
@media (min-width: 760px) {
  .stat-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0 40px; align-items: start; }
}
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px 20px; margin-top: 14px; }
.tile dt { font-size: 0.8125rem; color: var(--ink-3); }
.tile dd { font-weight: 800; font-size: 1.75rem; line-height: 1.1; margin-top: 2px; }
.tile-sub { display: block; font-weight: 400; font-size: 0.8125rem; line-height: 1.35; color: var(--ink-2); margin-top: 4px; }
.tile-link { display: inline-block; margin-top: 6px; font-weight: 600; font-size: 0.875rem; line-height: 1.3; text-decoration: none; }
.tile-link > span:first-child { text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: 3px; }
.tile-link:hover > span:first-child { text-decoration-color: currentColor; }
.tile-arrow { color: var(--ink-3); }

.bars { list-style: none; padding: 0; margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: baseline; padding: 4px 6px; margin: 0 -6px; border-radius: 6px; }
.bar-row:hover, .bar-row:focus-visible { background: var(--active-bg); }
.bar-label { font-size: 0.9375rem; min-width: 0; overflow-wrap: anywhere; }
.bar-value { font-weight: 600; font-size: 0.9375rem; font-variant-numeric: tabular-nums; }
.bar-track { grid-column: 1 / -1; height: 12px; }
.bar-fill { display: block; height: 100%; background: var(--c); border-radius: 0 4px 4px 0; }
a.bar-row { color: inherit; text-decoration: none; }
a.bar-row .bar-label { text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: 3px; }
a.bar-row .bar-label::after { content: '›'; display: inline-block; margin-left: 5px; color: var(--ink-3); } /* inline-block keeps the underline off the arrow */
a.bar-row:hover .bar-label { text-decoration-color: currentColor; }
.cmp tbody th a { color: inherit; text-decoration-color: var(--rule-strong); text-underline-offset: 3px; }
.cmp tbody th a:hover { text-decoration-color: currentColor; }
#cityHint { margin-top: 10px; }

.cmp-wrap .btn { margin-top: 8px; }
.cmp { width: 100%; border-collapse: collapse; font-size: 0.9375rem; margin-top: 8px; }
.cmp th, .cmp td { padding: 8px 4px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
.cmp thead th { font-size: 0.8125rem; font-weight: 600; color: var(--ink-3); padding-top: 4px; }
.cmp tbody th { font-weight: 600; }
.cmp .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.chart { margin: 18px 0 0; }
.chart-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; margin-bottom: 6px; }
.chart-title { font-weight: 600; font-size: 0.9375rem; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 0.8125rem; color: var(--ink-2); }
.line-key { display: inline-block; width: 16px; height: 3px; border-radius: 2px; background: var(--k); margin-right: 6px; vertical-align: 3px; }
.chart-plot { border-radius: 6px; touch-action: pan-y; }
.chart-plot:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke-width: 2; }
.chart .cross { stroke: var(--ink-3); stroke-width: 1; }
.legend-key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--k); margin-right: 6px; vertical-align: -1px; }
.chart-plot { width: 100%; }
.chart svg { display: block; max-width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--ink-3); font: 11px var(--font); font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--rule); stroke-width: 1; }
.chart .hit { fill: transparent; }
.chart figcaption { margin-top: 6px; }
.chart-table { margin-top: 10px; font-size: 0.875rem; }
.chart-table summary { cursor: pointer; font-weight: 600; width: max-content; }

.tip { position: fixed; z-index: 70; pointer-events: none; max-width: 260px; padding: 8px 10px; border-radius: 8px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--rule-strong); font-size: 0.8125rem; line-height: 1.45;
  box-shadow: 0 10px 24px -12px rgba(16, 42, 67, 0.45); }
.tip strong { font-size: 0.9375rem; }
.tip-title { font-weight: 600; margin-bottom: 2px; }
.tip-key { display: inline-block; width: 12px; height: 2px; border-radius: 1px; background: var(--k); vertical-align: middle; margin-right: 6px; }
.tip-muted { color: var(--ink-3); }

.split-bar { display: flex; gap: 2px; height: 8px; margin-top: 10px; }
.split-bar span { border-radius: 999px; }
.split-bar .tone-good, .split-icon.tone-good { background: var(--good); color: #fff; }
.split-bar .tone-warning, .split-icon.tone-warning { background: var(--warning); color: #0b0b0b; }
.split-bar .tone-critical, .split-icon.tone-critical { background: var(--critical); color: #fff; }
.split-list { list-style: none; padding: 0; margin-top: 10px; }
.split-list li { border-bottom: 1px solid var(--rule); }
.split-row { display: grid; grid-template-columns: 22px 1fr auto 3.2em; gap: 10px; align-items: center; padding: 6px 0; }
a.split-row { color: inherit; text-decoration: none; margin: 0 -6px; padding: 6px; border-radius: 6px; }
a.split-row:hover, a.split-row:focus-visible { background: var(--active-bg); }
a.split-row .split-name { text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: 3px; }
a.split-row .split-name::after { content: '›'; display: inline-block; margin-left: 5px; color: var(--ink-3); }
a.split-row:hover .split-name { text-decoration-color: currentColor; }
.split-icon { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; font-size: 0.75rem; font-weight: 800; }
.split-n, .split-pct { font-variant-numeric: tabular-nums; text-align: right; }
.split-pct { color: var(--ink-3); font-size: 0.875rem; }

/* ---------- record lists behind the numbers ---------- */

.sheet {
  width: min(680px, calc(100vw - 32px)); max-width: none; height: min(880px, calc(100dvh - 48px)); max-height: none;
  padding: 0; border: 0; border-radius: 14px;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 24px 60px -20px rgba(16, 42, 67, 0.5);
}
.sheet[open] { display: flex; flex-direction: column; animation: sheet-in 180ms ease-out; }
.sheet::backdrop { background: rgba(16, 42, 67, 0.45); }
html:has(.sheet[open]) { overflow: hidden; }
@keyframes sheet-in { from { transform: translateY(18px); opacity: 0; } }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 14px; border-bottom: 2px solid var(--ink); }
.sheet-heading { min-width: 0; }
.sheet-kicker { font-size: 0.8125rem; font-weight: 600; color: var(--ink-3); }
.sheet-head h2 { margin-top: 2px; overflow-wrap: anywhere; }
.sheet-sub { display: flex; flex-wrap: wrap; gap: 0 14px; margin-top: 6px; font-size: 0.875rem; color: var(--ink-2); }
.sheet-actions { display: flex; gap: 6px; flex: none; margin: -4px -6px 0 0; }
.sheet-body { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 0 20px calc(20px + var(--safe-bottom)); }
@media (max-width: 640px) {
  /* Phones: a sheet from the bottom, nearly full height. */
  .sheet { width: 100%; height: calc(100dvh - 10px - var(--safe-top)); margin: auto 0 0; border-radius: 14px 14px 0 0; }
  .sheet-head { padding: 16px 16px 12px; }
  .sheet-body { padding: 0 16px calc(20px + var(--safe-bottom)); }
}
.records { list-style: none; padding: 0; margin: 0; }
.record { display: grid; grid-template-columns: 1fr auto; gap: 0 12px; align-items: start; padding: 14px 0; border-bottom: 1px solid var(--rule); }
.record-body { min-width: 0; }
.record-wide { grid-column: 1 / -1; }
.record .item-title { overflow-wrap: anywhere; }
.record-links { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 8px; font-size: 0.875rem; font-weight: 600; }
.reasons { margin: 6px 0 0; padding-left: 18px; max-width: 62ch; }
.reasons li + li { margin-top: 4px; }
.records-status { padding: 14px 0 0; }

/* ---------- footer ---------- */

.sources { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--rule); font-size: 0.8125rem; color: var(--ink-3); max-width: 64ch; }
.sources p + p { margin-top: 8px; }

/* ---------- dialog, toast, map popups ---------- */

.dialog {
  width: min(520px, calc(100vw - 24px)); padding: 0; border: 0; border-radius: 14px;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 24px 60px -20px rgba(16, 42, 67, 0.5);
}
.dialog::backdrop { background: rgba(16, 42, 67, 0.45); }
.dialog-body { padding: 22px; display: flex; flex-direction: column; gap: 18px; }
.dialog-section p { margin-top: 4px; color: var(--ink-2); font-size: 0.9375rem; }
.dialog-section .btn { margin-top: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-weight: 600; }
.field input { min-height: 42px; padding: 0 12px; border-radius: 8px; border: 1.5px solid var(--rule-strong); background: var(--fog); }
.field small { color: var(--ink-3); font-size: 0.8125rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(18px + var(--safe-bottom)); z-index: 60;
  transform: translate(-50%, 140%); opacity: 0;
  max-width: min(520px, calc(100vw - 32px)); padding: 12px 16px; border-radius: 10px;
  background: var(--ink); color: var(--surface); font-weight: 600; font-size: 0.9375rem;
  transition: transform 220ms ease, opacity 220ms ease; pointer-events: none;
}
.toast.is-visible { transform: translate(-50%, 0); opacity: 1; }

#map .maplibregl-popup-content { font-family: var(--font); background: var(--surface); color: var(--ink); border-radius: 10px; padding: 12px 30px 12px 12px; box-shadow: 0 10px 28px -10px rgba(16, 42, 67, 0.45); }
#map .maplibregl-popup-tip { border-top-color: var(--surface) !important; border-bottom-color: var(--surface) !important; }
#map .maplibregl-popup-close-button { font-size: 20px; width: 28px; height: 28px; color: var(--ink); }
.popup { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.popup-title { font-weight: 800; line-height: 1.25; }
.popup-meta { font-size: 0.8125rem; color: var(--ink-3); white-space: pre-line; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media (forced-colors: active) {
  .swatch { border: 2px solid CanvasText; }
  .ledger-row.is-active, .item.is-selected .item-hit { outline: 2px solid Highlight; }
}
