:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #5d6673;
  --border: #e3e6ea;
  --accent: #1f6feb;
  --accent-soft: #e7f0ff;
  --bar: #1f6feb;
  --bar-bg: #eef1f5;
  --hero1: #0b2545;
  --hero2: #13315c;
  --ok: #116329;
  --warn: #7d4e00;
  --bad: #a40e26;
  --flag: #6639ba;
  --btn-bg: #1f6feb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --text: #e6edf3;
    --muted: #8d96a0;
    --border: #2a313c;
    --accent: #4493f8;
    --accent-soft: #15233a;
    --bar: #4493f8;
    --bar-bg: #21262d;
    --hero1: #0a1a33;
    --hero2: #10284d;
    --ok: #3fb950;
    --warn: #d29922;
    --bad: #ff7b72;
    --flag: #bc8cff;
    --btn-bg: #1f6feb;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
code { font-size: .9em; background: var(--bar-bg); padding: 1px 5px; border-radius: 4px; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

.hero {
  background: linear-gradient(135deg, var(--hero1), var(--hero2));
  color: #fff;
  padding: 48px 0 88px;
}
.hero h1 { margin: 4px 0 8px; font-size: clamp(28px, 5vw, 44px); letter-spacing: -.02em; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: .08em; font-size: 12px; opacity: .75; font-weight: 600; }
.lede { margin: 0; max-width: 640px; opacity: .85; font-size: 17px; }

main { margin-top: -56px; }
.hero-cta {
  display: inline-block; margin-top: 16px; padding: 9px 16px; border-radius: 999px;
  background: rgba(255,255,255,.14); color: #fff; text-decoration: none; font-weight: 600; font-size: 14px;
}
.hero-cta:hover { background: rgba(255,255,255,.22); }
html { scroll-behavior: smooth; }
#search { scroll-margin-top: 12px; }

.loading {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 24px; text-align: center; color: var(--muted); box-shadow: var(--shadow);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .num { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .lbl { color: var(--muted); font-size: 13px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow); min-width: 0;
}
.card h2 { margin: 0 0 4px; font-size: 18px; letter-spacing: -.01em; }
.card h3 { margin: 0 0 10px; font-size: 14px; color: var(--muted); font-weight: 600; }
#mapHelp { min-height: 3em; max-width: 560px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 12px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-2 .card { margin-bottom: 0; }
.grid-2 { margin-bottom: 20px; }

.map-grid { display: grid; grid-template-columns: 1fr 280px; gap: 20px; }
#map { height: 480px; border-radius: 10px; border: 1px solid var(--border); z-index: 0; }

/* segmented control */
.seg { display: inline-flex; background: var(--bar-bg); border-radius: 10px; padding: 3px; }
.seg-btn {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px;
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 500;
}
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* bar lists */
.bars { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; align-items: center; gap: 10px; font-size: 14px; }
.bar-row .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row button.label { all: unset; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--accent); }
.bar-row button.label:hover { text-decoration: underline; }
.bar-track { background: var(--bar-bg); border-radius: 6px; height: 10px; overflow: hidden; }
.bar-fill { background: var(--bar); height: 100%; border-radius: 6px; }
.bar-row .val { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; min-width: 3.5em; text-align: right; }

/* timeline */
.timeline { margin-top: 14px; }
.timeline svg { width: 100%; height: 220px; display: block; }
.timeline .tl-bar { fill: var(--bar); }
.timeline .tl-bar:hover { opacity: .75; }
.timeline .tl-axis { fill: var(--muted); font-size: 11px; }
.timeline .tl-grid { stroke: var(--border); }

.tidbits { margin: 12px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.tidbits li { padding-left: 14px; border-left: 3px solid var(--accent); font-size: 14px; }
.tidbits strong { font-variant-numeric: tabular-nums; }

/* search */
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  font: inherit; font-size: 14px; font-weight: 500; padding: 8px 14px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; border-color: var(--border); }
.btn.primary { background: var(--btn-bg); border-color: var(--btn-bg); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); align-self: flex-end; }

.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; min-width: 150px; }
.field.grow { flex: 1 1 260px; }
.field input, .field select {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; min-width: 0;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.count { margin: 6px 0 10px; font-size: 13px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--bar-bg); cursor: pointer; user-select: none; position: sticky; top: 0; }
th.asc::after { content: " ▲"; font-size: 9px; }
th.desc::after { content: " ▼"; font-size: 9px; }
tbody tr.row { cursor: pointer; }
tbody tr.row:hover { background: var(--accent-soft); }
tbody tr.detail td { background: var(--bg); white-space: normal; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px 20px; font-size: 13px; }
.detail-grid div span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bar-bg); color: var(--muted); }
.pill.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.pill.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 13%, transparent); }
.pill.flag { color: var(--flag); background: color-mix(in srgb, var(--flag) 14%, transparent); }
.pill.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 15%, transparent); }

.pager { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 14px; font-size: 13px; }

.notes ul { margin: 10px 0 0; padding-left: 20px; font-size: 14px; color: var(--muted); }
.notes li { margin-bottom: 6px; }
.footer { padding: 10px 16px 40px; text-align: center; }

.leaflet-container { font-family: inherit; background: var(--bar-bg); }
.legend {
  background: var(--surface); color: var(--text); padding: 8px 10px; border-radius: 8px;
  font-size: 12px; line-height: 1.6; box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.legend i { display: inline-block; width: 14px; height: 10px; margin-right: 6px; border-radius: 2px; vertical-align: middle; }
.leaflet-tooltip.hood-tip { font-family: inherit; font-size: 12px; }

@media (max-width: 860px) {
  .grid-2, .map-grid { grid-template-columns: 1fr; }
  #map { height: 380px; }
}
@media (max-width: 560px) {
  .field { min-width: 0; flex: 1 1 45%; }
  .card { padding: 16px; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; }
}

.field select { max-width: 240px; }
td .pill { white-space: normal; max-width: 210px; }
.legend-sub { color: var(--muted); font-size: 11px; }

/* ---------- map extras ---------- */
.map-pan-btn {
  font: inherit; font-size: 13px; font-weight: 600; padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,.25); cursor: pointer;
}
.map-pan-btn.active { background: var(--btn-bg); border-color: var(--btn-bg); color: #fff; }
.legend { cursor: pointer; max-width: 230px; }
.legend.collapsed { max-height: 22px; overflow: hidden; }
.legend.collapsed::after { content: " ▸"; }
.hood-pop { font-family: Inter, system-ui, sans-serif; font-size: 13px; line-height: 1.45; }
.hood-pop .popup-btn { display: block; width: 100%; margin-top: 10px; font-size: 14px; padding: 9px 12px; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }

/* ---------- tablets ---------- */
@media (max-width: 860px) {
  .card-head { flex-direction: column; align-items: stretch; }
  .seg { width: 100%; }
  .seg-btn { flex: 1; padding: 9px 6px; }
  #mapHelp { min-height: 0; }
}

/* ---------- phones ---------- */
@media (max-width: 640px) {
  body { font-size: 15px; }
  .hero { padding: 28px 0 72px; }
  .lede { font-size: 15px; }
  main { margin-top: -52px; }

  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat .num { font-size: 22px; }
  .stat:first-child { grid-column: 1 / -1; }

  .card { padding: 16px; border-radius: 12px; margin-bottom: 14px; }
  .grid-2 { gap: 14px; margin-bottom: 14px; }
  .card h2 { font-size: 17px; }

  #map { height: min(62vh, 440px); }
  .map-grid { gap: 14px; }
  .seg-btn { font-size: 12.5px; min-height: 40px; }

  /* bar lists: name on its own line, bar + value underneath (no truncation) */
  .bars { gap: 10px; }
  .bar-row { grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 14px; }
  .bar-row .label, .bar-row button.label { grid-column: 1 / -1; white-space: normal; padding: 2px 0; }
  .bar-row .bar-track { grid-column: 1; }
  .bar-row .val { grid-column: 2; }

  /* filters: search full width, others two-up; 16px inputs stop iOS zooming */
  .filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .field, .field.grow { min-width: 0; }
  .field.grow { grid-column: 1 / -1; }
  .field input, .field select { font-size: 16px; padding: 10px; max-width: none; width: 100%; }
  .btn.ghost { justify-self: start; align-self: end; padding: 10px 0; }
  .actions { flex-direction: row; }
  .actions .btn { flex: 1; padding: 10px 8px; font-size: 13px; }

  /* table becomes a list of cards */
  .table-wrap { border: 0; overflow: visible; }
  #table thead { display: none; }
  #table, #table tbody { display: block; }
  #table tr.row {
    display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
    border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px;
    background: var(--surface);
  }
  #table tr.row td { display: block; padding: 0; border: 0; white-space: normal; font-size: 13px; color: var(--muted); }
  #table tr.row td.c-name { grid-column: 1; grid-row: 1; font-size: 16px; font-weight: 600; color: var(--text); }
  #table tr.row td.c-status { grid-column: 2; grid-row: 1; justify-self: end; }
  #table tr.row td.c-roll, #table tr.row td.c-addr, #table tr.row td.c-hood,
  #table tr.row td.c-date, #table tr.row td.c-pl { grid-column: 1 / -1; }
  #table tr.row td.c-zip { display: none; }
  #table tr.row td[data-label]:not(:empty)::before { content: attr(data-label) ": "; font-weight: 500; }
  #table tr.row td:empty { display: none; }
  #table tr.row td.c-addr { color: var(--text); font-size: 14px; }
  #table tr.detail { display: block; margin: -6px 0 10px; }
  #table tr.detail td { display: block; border: 1px solid var(--border); border-top: 0; border-radius: 0 0 10px 10px; padding: 12px 14px; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  td .pill { max-width: 150px; text-align: center; }

  .pager .btn { padding: 10px 16px; }
  .notes ul { padding-left: 18px; }
}

/* ---------- accessibility ---------- */
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 2000; background: var(--surface); color: var(--text);
  padding: 10px 14px; border-radius: 8px; font-weight: 600; box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.skip-link:focus { top: 12px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.bar-row button.label:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
main:focus, #search:focus { outline: none; }

th button {
  all: unset; cursor: pointer; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit;
}
th button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.row-toggle {
  all: unset; cursor: pointer; color: var(--text); font-weight: 500;
}
.row-toggle:hover { color: var(--accent); text-decoration: underline; }
.row-toggle:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
@media (max-width: 640px) {
  #table tr.row td.c-name .row-toggle { font-size: 16px; font-weight: 600; }
}

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

/* iPhone notch / home-bar safe areas */
.wrap { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
.footer { padding-bottom: max(40px, env(safe-area-inset-bottom)); }

/* ---------- FAQ ---------- */
.faq details { border-top: 1px solid var(--border); padding: 12px 0; }
.faq details:first-of-type { margin-top: 10px; }
.faq summary {
  cursor: pointer; font-weight: 600; font-size: 15px; list-style: none; display: flex; justify-content: space-between; gap: 12px;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--muted); font-weight: 400; font-size: 18px; line-height: 1; }
.faq details[open] summary::after { content: "−"; }
.faq details p { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
