/* =====================================================================
   The San Francisco 311 Index — baseline styles
   ALL visual decisions live behind the tokens in :root. The interaction
   layer (js/) reads colors from these variables, including the choropleth
   ramp (--ramp-0..5). Claude Design can restyle the whole site by editing
   tokens here without touching any logic.
   ===================================================================== */

:root {
  /* — palette: an official, slightly austere civic-document feel — */
  --paper:        #f4f1ea;   /* page background (aged bond paper)        */
  --paper-2:      #ece7db;   /* panel background                         */
  --ink:          #1c1a17;   /* primary text                            */
  --ink-soft:     #57514696; /* muted text                               */
  --ink-soft-solid:#5b554a;
  --rule:         #cfc8b8;   /* hairline rules                           */
  --accent:       #8a1c1c;   /* oxblood — "official seal" red            */
  --accent-soft:  #b14a2a;

  /* — choropleth ramp: light parchment → deep oxblood (worst) — */
  --ramp-0: #efe9d8;
  --ramp-1: #e6c9a8;
  --ramp-2: #dca078;
  --ramp-3: #c9694a;
  --ramp-4: #a5332a;
  --ramp-5: #6d1414;
  --ramp-null: #ddd7c7;      /* regions with no data                     */

  /* — map — */
  --map-bg:       #e8e3d6;   /* blank base (no consumer basemap)         */
  --region-line:  #6d685c;   /* polygon outlines                         */
  --region-line-hover: #1c1a17;
  --region-line-sel:   #8a1c1c;

  /* — type — */
  --font-display: "Georgia", "Times New Roman", serif;
  --font-text:    system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono:    "SFMono-Regular", "Menlo", "Consolas", monospace;

  /* — geometry — */
  --wrap:    1180px;
  --gap:     clamp(16px, 3vw, 32px);
  --radius:  4px;
  --shadow:  0 1px 2px #00000014, 0 8px 24px #00000010;
  --map-h:   60vh;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: var(--wrap); margin-inline: auto; padding-inline: var(--gap); }

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--ink); color: var(--paper); padding: 8px 14px;
}
.skip-link:focus { left: 8px; top: 8px; }

/* ── Masthead ──────────────────────────────────────────────── */
.masthead {
  border-bottom: 3px double var(--ink);
  padding-block: clamp(28px, 6vw, 64px) clamp(20px, 4vw, 40px);
  text-align: center;
}
.masthead__eyebrow {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: .18em;
  font-size: 12px;
  color: var(--ink-soft-solid);
  margin: 0 0 18px;
}
.masthead__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(34px, 7vw, 76px);
  line-height: 1.02;
  letter-spacing: -.01em;
  margin: 0 0 .35em;
}
.masthead__standfirst {
  max-width: 56ch; margin: 0 auto 1.4em;
  font-size: clamp(15px, 2.2vw, 19px);
  color: var(--ink-soft-solid);
  font-style: italic;
}
.masthead__stat {
  font-family: var(--font-mono);
  font-size: clamp(13px, 2vw, 16px);
  max-width: 60ch; margin: 0 auto;
  padding-top: 1em; border-top: 1px solid var(--rule);
}
.masthead__stat strong { color: var(--accent); }

/* ── Control bar ───────────────────────────────────────────── */
.controls {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--rule);
}
.controls__inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding-block: 12px; flex-wrap: wrap;
}
.seg { display: inline-flex; align-items: center; gap: 8px; }
.seg__label {
  font-family: var(--font-mono); font-size: 11px; text-transform: uppercase;
  letter-spacing: .12em; color: var(--ink-soft-solid); margin-right: 2px;
}
.seg__btn {
  font: inherit; font-size: 14px;
  border: 1px solid var(--rule); background: var(--paper);
  color: var(--ink-soft-solid);
  padding: 7px 14px; cursor: pointer; border-radius: var(--radius);
}
.seg__btn:hover { border-color: var(--ink-soft-solid); }
.seg__btn.is-active {
  background: var(--ink); color: var(--paper); border-color: var(--ink);
}
.controls__metric {
  margin: 0; font-family: var(--font-mono); font-size: 12px;
  color: var(--ink-soft-solid); text-transform: uppercase; letter-spacing: .08em;
}

/* ── Stage layout ──────────────────────────────────────────── */
.stage {
  display: grid;
  grid-template-columns: 1.25fr .9fr;
  gap: var(--gap);
  padding-block: var(--gap) 64px;
  align-items: start;
}
.map-col { min-width: 0; }

/* ── Map ───────────────────────────────────────────────────── */
.map-shell {
  position: relative;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--map-bg);
}
#map { width: 100%; height: var(--map-h); }
.maplibregl-ctrl-attrib { font-size: 10px; opacity: .6; }

.legend {
  position: absolute; left: 12px; bottom: 12px;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 8px 10px; font-family: var(--font-mono); font-size: 10px;
  color: var(--ink-soft-solid); box-shadow: var(--shadow); max-width: 60%;
}
.legend__title { text-transform: uppercase; letter-spacing: .1em; margin-bottom: 6px; color: var(--ink); }
.legend__scale { display: flex; height: 10px; }
.legend__swatch { flex: 1; }
.legend__ticks { display: flex; justify-content: space-between; margin-top: 4px; }

.map-tooltip {
  position: absolute; z-index: 10; pointer-events: none;
  transform: translate(-50%, calc(-100% - 12px));
  background: var(--ink); color: var(--paper);
  padding: 8px 10px; border-radius: var(--radius);
  font-size: 12px; line-height: 1.35; max-width: 240px;
  box-shadow: var(--shadow);
}
.map-tooltip b { font-family: var(--font-display); font-size: 13px; }
.map-tooltip .tt-rank { color: #ffd9c2; font-family: var(--font-mono); }
.map-tooltip .tt-stat { font-family: var(--font-mono); }

/* ── Leaderboard ───────────────────────────────────────────── */
.board { margin-top: var(--gap); }
.board__head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; border-bottom: 2px solid var(--ink); padding-bottom: 8px;
}
.board__title { font-family: var(--font-display); font-size: 22px; margin: 0; }
.board__sort { font-family: var(--font-mono); font-size: 12px; color: var(--ink-soft-solid); }
.board__sort select {
  font: inherit; font-size: 12px; margin-left: 6px; padding: 3px 6px;
  border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper);
}
.board__list { list-style: none; margin: 0; padding: 0; counter-reset: none; }

.row {
  display: grid;
  grid-template-columns: 2.4rem 1fr auto;
  align-items: center; gap: 12px;
  padding: 9px 8px; border-bottom: 1px solid var(--rule);
  cursor: pointer; position: relative;
}
.row:hover, .row.is-hover { background: var(--paper-2); }
.row.is-active { background: color-mix(in srgb, var(--accent) 10%, var(--paper)); }
.row.is-active::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent);
}
.row__rank {
  font-family: var(--font-mono); font-size: 15px; font-weight: 700;
  color: var(--accent); text-align: right;
}
.row__main { min-width: 0; }
.row__name { font-family: var(--font-display); font-size: 16px; line-height: 1.15; }
.row__sig { font-size: 11px; color: var(--ink-soft-solid); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row__metric { text-align: right; }
.row__pc { font-family: var(--font-mono); font-size: 15px; font-weight: 700; }
.row__bar { height: 4px; margin-top: 4px; background: var(--rule); border-radius: 2px; overflow: hidden; width: 90px; margin-left: auto; }
.row__bar > i { display: block; height: 100%; background: var(--accent-soft); }
.row__metric small { font-family: var(--font-mono); font-size: 10px; color: var(--ink-soft-solid); }

.board__dq {
  padding: 12px 8px; font-size: 12px; color: var(--ink-soft-solid);
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
}
.dq__label { font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .08em; font-size: 10px; }
.dq__item {
  font: inherit; font-size: 12px; border: 1px solid var(--rule); background: var(--paper);
  color: var(--ink); padding: 2px 8px; border-radius: 999px; cursor: pointer;
}
.dq__item:hover { border-color: var(--ink-soft-solid); background: var(--paper-2); }
.dq__note { font-style: italic; flex-basis: 100%; }

/* ── Dossier ───────────────────────────────────────────────── */
.dossier { position: sticky; top: 72px; }
.dossier__empty {
  border: 1px dashed var(--rule); border-radius: var(--radius);
  padding: 28px; color: var(--ink-soft-solid); font-style: italic; text-align: center;
}
.dossier__card {
  border: 1px solid var(--rule); border-top: 4px solid var(--accent);
  border-radius: var(--radius); background: var(--paper);
  padding: 20px; box-shadow: var(--shadow);
}
.dossier__badge {
  font-family: var(--font-mono); font-size: 11px; text-transform: uppercase;
  letter-spacing: .14em; color: var(--accent); display: flex; justify-content: space-between;
}
.dossier__rank { font-size: 13px; font-weight: 700; }
.dossier__name { font-family: var(--font-display); font-size: 28px; margin: 6px 0 2px; line-height: 1.05; }
.dossier__verdict { font-style: italic; color: var(--ink-soft-solid); margin: 0 0 16px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.stat { border: 1px solid var(--rule); border-radius: var(--radius); padding: 10px; text-align: center; }
.stat__num { font-family: var(--font-mono); font-size: 20px; font-weight: 700; }
.stat__lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-soft-solid); }

.dossier__sub {
  font-family: var(--font-mono); font-size: 11px; text-transform: uppercase;
  letter-spacing: .1em; color: var(--ink-soft-solid);
  border-bottom: 1px solid var(--rule); padding-bottom: 4px; margin: 18px 0 10px;
}
.cats { display: grid; gap: 6px; }
.cat { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
.cat__bar { grid-column: 1 / -1; height: 5px; background: var(--rule); border-radius: 3px; overflow: hidden; }
.cat__bar > i { display: block; height: 100%; background: var(--ramp-3); }
.cat__pct { font-family: var(--font-mono); font-size: 12px; color: var(--ink-soft-solid); }

.spark { width: 100%; height: 34px; display: block; color: var(--accent-soft); }

.quotes { display: grid; gap: 10px; }
.quote {
  border-left: 2px solid var(--accent-soft); background: var(--paper-2);
  padding: 9px 12px; border-radius: 0 var(--radius) var(--radius) 0;
}
.quote__detail { font-size: 13.5px; }
.quote__detail::before { content: "\201C"; }
.quote__detail::after  { content: "\201D"; }
.quote__meta { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-soft-solid); margin-top: 4px; }

/* ── Methodology ───────────────────────────────────────────── */
.method { border-top: 3px double var(--ink); padding-block: 36px 64px; margin-top: 24px; }
.method__title { font-family: var(--font-display); font-size: 22px; margin: 0 0 12px; }
.method__body { columns: 2; column-gap: 40px; font-size: 13.5px; color: var(--ink-soft-solid); }
.method__body p { margin: 0 0 .8em; break-inside: avoid; }
.method__body a { color: var(--accent); }
.method__caveat {
  margin-top: 20px; padding: 14px 16px; border: 1px solid var(--rule);
  border-radius: var(--radius); font-style: italic; font-size: 13.5px; background: var(--paper-2);
}

/* ── Responsive: dossier becomes a bottom sheet ────────────── */
@media (max-width: 860px) {
  :root { --map-h: 52vh; }
  .stage { grid-template-columns: 1fr; }
  .method__body { columns: 1; }

  .dossier {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 40;
    transform: translateY(100%); transition: transform .28s ease;
    max-height: 78vh; overflow: auto;
    background: var(--paper); border-top: 1px solid var(--rule);
    box-shadow: 0 -8px 28px #00000026;
  }
  .dossier.is-open { transform: translateY(0); }
  .dossier__empty { display: none; }
  .dossier__card { border-radius: 0; border-top-width: 4px; padding-top: 28px; }
  .dossier__close {
    position: absolute; top: 8px; right: 10px; border: none; background: none;
    font-size: 26px; line-height: 1; cursor: pointer; color: var(--ink-soft-solid);
  }
}
@media (min-width: 861px) { .dossier__close { display: none; } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .dossier { transition: none; }
}
