:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-2: #eef4f2;
  --ink: #17201d;
  --muted: #5e6964;
  --rule: #d7ded8;
  --accent: #b64a2f;
  --accent-2: #2d6b62;
  --accent-3: #315d8c;
  --accent-4: #8a6f2f;
  --danger: #9b2f2f;
  --shadow: 0 10px 30px rgba(23, 32, 29, .08);
  --radius: 8px;
  --max: 1240px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--rule);
  backdrop-filter: blur(10px);
}

.topbar-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 250px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: #fff;
  border: 1px solid var(--rule);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .12);
  padding: 4px;
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand strong {
  display: block;
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.05;
}

.brand small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.nav-links {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.nav-links a {
  padding: 9px 11px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.nav-links a:hover,
.nav-links a.active {
  background: var(--surface-2);
  color: var(--ink);
}

.app-shell {
  max-width: var(--max);
  margin: 0 auto;
  padding: 24px 22px 52px;
}

.loading,
.error {
  border: 1px solid var(--rule);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
}

.error { border-color: rgba(155, 47, 47, .35); color: var(--danger); }

.page-head {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, .8fr);
  gap: 24px;
  align-items: end;
  margin: 12px 0 24px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--rule);
}

.eyebrow {
  margin: 0 0 10px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 800;
}

h1, h2, h3 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  max-width: 14ch;
  font-family: var(--serif);
  font-size: clamp(40px, 7vw, 76px);
  letter-spacing: 0;
}

h2 {
  font-family: var(--serif);
  font-size: clamp(26px, 4vw, 42px);
}

h3 {
  font-family: var(--serif);
  font-size: 22px;
}

.lede {
  max-width: 68ch;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 17px;
}

.meta-panel {
  border: 1px solid var(--rule);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.meta-item span,
.stat-label,
.table-note,
.mini-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.meta-item strong,
.mini-value {
  display: block;
  margin-top: 3px;
  color: var(--ink);
  font-size: 20px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.intro-panel {
  display: grid;
  grid-template-columns: minmax(0, .9fr) minmax(360px, 1.1fr);
  gap: 18px;
  align-items: start;
  margin-bottom: 24px;
}

.intro-copy,
.indicator-item {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
}

.intro-copy {
  padding: 22px;
}

.intro-copy h2 {
  max-width: 13ch;
}

.intro-copy p {
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.intro-copy strong,
.indicator-item p strong {
  color: var(--ink);
  font-weight: 800;
}

.intro-copy em,
.indicator-item p em {
  color: var(--ink);
  font-style: italic;
}

.intro-copy a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.indicator-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.indicator-item {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 14px;
  min-height: 192px;
}

.indicator-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.indicator-number {
  font-family: var(--mono);
  color: var(--accent);
  font-weight: 800;
  font-size: 12px;
}

.indicator-visual {
  display: grid;
  place-items: center;
  min-height: 74px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #f8faf7;
  overflow: hidden;
}

.indicator-visual svg {
  display: block;
  width: 100%;
  height: 76px;
}

.indicator-visual text {
  fill: var(--muted);
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.indicator-item > strong {
  display: block;
  color: var(--ink);
  font-size: 15px;
}

.indicator-status {
  display: inline-flex;
  width: fit-content;
  padding: 3px 7px;
  border-radius: 999px;
  background: #eef4f2;
  color: var(--accent-2);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.indicator-status.partial {
  background: #fff8e7;
  color: #7b5a17;
}

.indicator-status.gap {
  background: #f1f0ed;
  color: var(--muted);
}

.indicator-item p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.kpi {
  min-height: 132px;
  padding: 17px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  display: grid;
  align-content: space-between;
}

.kpi:nth-child(2n) { background: #f8fbff; }
.kpi:nth-child(3n) { background: #f7fbf6; }

.kpi-value {
  font-family: var(--serif);
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1;
}

.kpi-unit {
  margin-left: 4px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 12px;
}

.kpi-label {
  margin-top: 8px;
  color: var(--ink);
  font-weight: 800;
  font-size: 14px;
}

.kpi-note {
  color: var(--muted);
  font-size: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr);
  gap: 18px;
  margin-bottom: 18px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.panel {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 18px;
  min-width: 0;
}

.wide-panel {
  margin-top: 18px;
}

.district-map-panel {
  margin-bottom: 24px;
}

.explorer-focus-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr);
  gap: 18px;
  align-items: start;
  margin-bottom: 18px;
}

.map-panel-body {
  display: grid;
  gap: 14px;
}

.map-toolbar {
  display: grid;
  grid-template-columns: minmax(230px, 300px) minmax(0, 1fr);
  gap: 12px;
  align-items: end;
}

.explorer-map-controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 260px);
  gap: 10px;
  align-items: end;
}

.map-control {
  margin: 0;
  padding: 8px;
  border: 1px solid rgba(49, 93, 140, .36);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #eef4fb 0%, #fbfdff 100%);
  box-shadow: 0 8px 20px rgba(49, 93, 140, .08);
}

.map-control label {
  color: var(--accent-3);
  font-weight: 800;
}

.map-control select {
  min-height: 36px;
  border-color: var(--accent-3);
  background: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(49, 93, 140, .14);
  font-size: 14px;
  font-weight: 700;
  padding-top: 7px;
  padding-bottom: 7px;
}

.map-control select:hover,
.map-control select:focus {
  border-color: #173b63;
  outline: 3px solid rgba(49, 93, 140, .18);
}

.map-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.district-map-wrap {
  position: relative;
  min-height: clamp(178px, 29vw, 306px);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #f8faf7;
  overflow: hidden;
}

.explorer-map-wrap {
  min-height: clamp(260px, 35vw, 410px);
}

.district-map-wrap svg {
  display: block;
  width: 100%;
  height: auto;
}

.district-map-wrap path {
  transition: fill .15s ease, stroke-width .15s ease;
}

.map-tooltip {
  position: absolute;
  z-index: 5;
  max-width: 240px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .12s ease, transform .12s ease;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  font-size: 12px;
}

.map-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.map-tooltip strong,
.map-tooltip b,
.map-tooltip span,
.map-tooltip small {
  display: block;
}

.map-tooltip span,
.map-tooltip small {
  color: var(--muted);
  margin-top: 3px;
}

.map-tooltip b {
  margin-top: 8px;
}

.map-legend {
  display: grid;
  gap: 7px;
  padding: 10px 12px;
  border-top: 1px solid var(--rule);
  background: rgba(255, 255, 255, .74);
}

.legend-gradient {
  height: 10px;
  border: 1px solid rgba(0, 0, 0, .08);
  border-radius: 999px;
}

.legend-scale {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.legend-scale span {
  min-width: 0;
  white-space: nowrap;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  margin-bottom: 14px;
}

.panel-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.chart-wrap {
  position: relative;
  height: 330px;
  min-height: 260px;
}

.chart-wrap.short { height: 250px; }

.mini-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.insight-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.insight-card {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px;
  min-height: 145px;
}

.insight-card p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.method-list {
  display: grid;
  gap: 10px;
}

.method-item {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fbfcfa;
  padding: 12px;
}

.method-item strong {
  display: block;
  margin-top: 5px;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
}

.method-item p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.mini-stat {
  min-height: 96px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid transparent;
}

.mini-stat:nth-child(2n) { background: #f8f2ed; }
.mini-stat:nth-child(3n) { background: #eef3fb; }

.bar-list {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 180px) minmax(0, 1fr) minmax(170px, 220px);
  gap: 12px;
  align-items: center;
  font-size: 13px;
}

.bar-stack {
  display: grid;
  gap: 5px;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: #e7ebe8;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent-2);
}

.bar-fill.hc { background: var(--accent-2); }
.bar-fill.sip { background: var(--accent-3); }

.table-wrap {
  overflow: auto;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  background: var(--surface);
}

th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f1f5f2;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

th.sortable {
  cursor: pointer;
  color: var(--ink);
}

tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.strong { font-weight: 800; }

tr.clickable-row {
  cursor: pointer;
}

tr.clickable-row:hover td {
  background: #f7faf7;
}

tr.selected-row td {
  background: #eef4fb;
  box-shadow: inset 0 1px 0 rgba(49, 93, 140, .08), inset 0 -1px 0 rgba(49, 93, 140, .08);
}

.district-detail {
  display: grid;
  gap: 14px;
}

.district-title strong {
  display: block;
  margin-top: 4px;
  font-family: var(--serif);
  font-size: 28px;
  line-height: 1.05;
}

.district-trend-wrap {
  min-height: 280px;
}

.controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) repeat(3, minmax(145px, 210px)) minmax(130px, auto);
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.explorer-filter-controls {
  grid-template-columns: minmax(220px, 1fr) repeat(2, minmax(160px, 230px));
}

.district-table-panel {
  display: grid;
  gap: 12px;
}

.geography-panel {
  margin-bottom: 18px;
}

.geo-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.geo-summary-block {
  display: grid;
  gap: 10px;
  padding: 12px 0 0;
  border-top: 1px solid var(--rule);
}

.geo-summary-block.empty {
  color: var(--muted);
}

.geo-summary-block.empty p {
  margin: 0;
  max-width: 48ch;
}

.geo-summary-title {
  display: block;
  font-family: var(--serif);
  font-size: 24px;
  line-height: 1.05;
}

.table-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.table-toolbar .control {
  min-width: 190px;
}

.control label {
  display: block;
  margin-bottom: 5px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.control input,
.control select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 9px 10px;
}

.btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  padding: 9px 14px;
  font-weight: 800;
}

.btn.secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--rule);
}

.btn:hover { filter: brightness(.96); }

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.link-card,
.note-card {
  display: block;
  min-height: 150px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px;
}

.link-card:hover {
  border-color: var(--accent-2);
  box-shadow: var(--shadow);
}

.link-card span {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .08em;
  color: var(--accent);
  text-transform: uppercase;
  font-weight: 800;
}

.link-card strong {
  display: block;
  margin: 14px 0 8px;
  font-size: 20px;
}

.link-card p,
.note-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.caveat-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.caveat-list li { margin-bottom: 10px; }

.footer-note {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.ok {
  background: #e8f3ed;
  color: #24563b;
}

.badge.warn {
  background: #fff4d8;
  color: #7a5700;
}

.badge.muted {
  background: #eef0ef;
  color: #5e6964;
}

@media (max-width: 1000px) {
  .page-head,
  .intro-panel,
  .map-toolbar,
  .explorer-focus-grid,
  .geo-summary-grid,
  .grid-2 {
    grid-template-columns: 1fr;
  }

  .kpi-grid,
  .insight-grid,
  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-3 {
    grid-template-columns: 1fr;
  }

  .controls {
    grid-template-columns: 1fr 1fr;
  }

  .explorer-filter-controls {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .topbar-inner,
  .app-shell {
    padding-left: 14px;
    padding-right: 14px;
  }

  .brand { min-width: 0; }
  .nav-links {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }

  .nav-links a {
    white-space: nowrap;
  }

  .kpi-grid,
  .insight-grid,
  .indicator-list,
  .cards,
  .mini-grid,
  .explorer-map-controls,
  .controls {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 14px;
  }

  h1 {
    font-size: 40px;
  }

  .chart-wrap {
    height: 280px;
  }

  .table-toolbar {
    justify-content: stretch;
  }

  .table-toolbar .control,
  .table-toolbar .btn {
    width: 100%;
  }

  .bar-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}
