* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
[hidden] { display: none !important; }

:root {
  --page: #ffffff;
  --surface: #ffffff;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #898781;
  --hairline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-soft: #eaf2fc;
  --flag: #d03b3b;
  --shadow: 0 1px 2px rgba(11,11,11,0.04), 0 8px 24px rgba(11,11,11,0.05);
}

/* Partner theme: Charlottesville-region foundation (teal brand accent).
   Applied via data-theme on <html>, set from the page's CVI_PAGE_CONFIG. */
:root[data-theme="cacf"] {
  --accent: #0e9484;
  --accent-soft: #e6f2f0;
}
:root[data-theme="cacf"] .stat {
  background: linear-gradient(180deg, #e9f3f1 0%, #ddecea 100%);
}
:root[data-theme="cacf"] .stat__value { color: #135f56; }

body {
  margin: 0;
  font-family: "Familjen Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial;
  background: var(--page);
  color: var(--ink);
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap {
  width: min(1160px, calc(100% - 48px));
  margin: 0 auto;
  padding: 24px 0 48px;
  display: grid;
  gap: 24px;
}

/* ---------------------------------------------------------------- topbar */

.topbar {
  position: sticky; top: 0; z-index: 1000;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hairline);
}
.topbar__inner {
  width: min(1160px, calc(100% - 48px));
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
}

.brand { display: flex; align-items: center; }
.brand__title {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.brand__sub { color: var(--ink-3); font-size: 0.88rem; }

.nav { display: flex; gap: 4px; align-items: center; }
.nav a {
  padding: 8px 12px; border-radius: 10px;
  color: var(--ink-2);
}
.nav a:hover { background: rgba(11,11,11,0.05); text-decoration: none; }
.nav a.nav--current { color: var(--ink); font-weight: 700; }
.nav__sep {
  width: 1px;
  height: 18px;
  background: var(--hairline);
  margin: 0 6px;
}

/* ------------------------------------------------------------------ intro */

.pageIntro { padding: 8px 0 0; }
h1 { margin: 0 0 6px; font-size: clamp(1.6rem, 2.6vw, 2.2rem); line-height: 1.15; letter-spacing: -0.02em; }
.lead { margin: 0; color: var(--ink-2); max-width: 78ch; }

/* ------------------------------------------------------------------ cards */

.card {
  padding: 24px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.card__head h2 { margin: 0; font-size: 1.3rem; letter-spacing: -0.01em; }
.card__head p { margin: 6px 0 18px; color: var(--ink-2); font-size: 0.92rem; max-width: 90ch; }

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

.controls {
  display: grid;
  grid-template-columns: 1fr 1.3fr auto;
  gap: 12px;
  align-items: end;
}
.control { display: grid; gap: 6px; }
.control--btns { display: flex; gap: 8px; }
label { font-size: 0.85rem; color: var(--ink-2); font-weight: 600; }

input, select {
  background: var(--surface);
  border: 1px solid var(--hairline);
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 10px;
  outline: none;
  font: inherit;
}
input:focus, select:focus { border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn--ghost {
  background: var(--surface);
  border-color: var(--hairline);
  color: var(--ink-2);
}
.btn--ghost:hover { border-color: var(--ink-3); filter: none; }

.aboutBox {
  margin-top: 12px;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: var(--page);
}
.aboutBox summary {
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 700;
  color: var(--ink-2);
  list-style-position: inside;
}
.aboutBox summary:hover { color: var(--ink); }
.aboutBox[open] summary { border-bottom: 1px solid var(--hairline); color: var(--ink); }
.aboutBox p { margin: 10px 14px; color: var(--ink-2); max-width: 100ch; }

/* ------------------------------------------------------------- stat cards */

.statRow {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.stat {
  padding: 20px 22px 18px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(180deg, #eef4fc 0%, #e7effa 100%);
  display: grid;
  align-content: center;
  gap: 2px;
}
.stat__value {
  font-weight: 850;
  font-size: 1.8rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: #1c5cab;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stat__label {
  color: var(--ink-2);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ------------------------------------------------------------------- map */

.mapRow {
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: 16px;
  align-items: stretch;
}
.card--map { display: flex; flex-direction: column; }
.mapSide {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
}
.card--dist { display: flex; flex-direction: column; }

.map {
  flex: 1;
  min-height: 480px;
  border-radius: 10px;
  border: 1px solid var(--hairline);
  overflow: hidden;
  background: #eef0f2;
}

.mapLegend {
  background: rgba(255,255,255,0.95);
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.82rem;
  line-height: 1.55;
}
.mapLegend__title { font-weight: 800; margin-bottom: 4px; }
.mapLegend__row { display: flex; align-items: center; gap: 8px; }
.mapLegend__swatch {
  width: 14px; height: 14px; border-radius: 4px; display: inline-block;
  border: 1px solid rgba(0,0,0,0.15);
}

/* --------------------------------------------------------- county report */

.callouts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.callout {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(11,11,11,0.04), 0 6px 18px rgba(11,11,11,0.05);
  color: var(--ink);
  font-size: 0.9rem;
}
.callout__icon {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
}
.callout__icon svg { width: 20px; height: 20px; }
.callout__icon--alert   { background: #fdecea; color: #c23434; }
.callout__icon--health  { background: #fceaf3; color: #b8377f; }
.callout__icon--trend   { background: #fdf3df; color: #9a6a06; }
.callout__icon--drivers { background: #f0ecfc; color: #6349c6; }
.callout__icon--ok      { background: #e7f5e9; color: #157f3d; }
.callout__title { font-weight: 800; font-size: 0.9rem; margin-bottom: 1px; }
.callout__text { color: var(--ink-2); line-height: 1.45; }

.reportGrid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 16px;
  align-items: stretch;
}
.reportMain {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
}
.reportSide {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
}

.subpanel {
  padding: 18px 20px;
  border-radius: 12px;
  border: none;
  background: #f7f7f4;
  display: flex;
  flex-direction: column;
}
/* Table panels (Populations at Risk, Community Investment): white with a
   visible gray outline. The chart panels on the right keep the gray fill. */
.reportMain .subpanel {
  background: var(--surface);
  border: 1px solid #d6d5cd;
}
.subpanel__title { font-weight: 800; }
.subpanel__sub { color: var(--ink-3); font-size: 0.86rem; margin: 2px 0 10px; }
.subpanel__foot { color: var(--ink-3); font-size: 0.78rem; margin-top: auto; padding-top: 10px; line-height: 1.45; }

.tableWrap { overflow-x: auto; }
.demoTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}
.demoTable th {
  text-align: right;
  font-size: 0.78rem;
  color: var(--ink-3);
  font-weight: 700;
  padding: 6px 8px;
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}
.demoTable th:first-child { text-align: left; }
.demoTable td {
  padding: 5px 8px;
  text-align: right;
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}
.demoTable td:first-child { text-align: left; color: var(--ink-2); white-space: normal; }
.demoTable__county { font-weight: 700; }
.demoTable__change { color: var(--ink-3); }
.demoTable__group td {
  text-align: left;
  font-weight: 800;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-3);
  padding-top: 13px;
  border-bottom: 1px solid var(--hairline);
}
.demoTable__flag { color: var(--flag); font-size: 0.8em; }
.demoTable__flag--strong { font-weight: 900; }

.drivers { display: grid; gap: 9px; align-content: start; }
.driver__top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.driver__name { font-size: 0.9rem; font-weight: 600; }
.driver__val { font-size: 0.8rem; color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.driver__bar {
  height: 6px;
  border-radius: 4px;
  background: var(--hairline);
  overflow: hidden;
  margin-top: 3px;
}
.driver__fill { height: 100%; border-radius: 4px; background: var(--accent); }
.driver__cat { color: var(--ink-3); font-size: 0.76rem; margin-top: 1px; }

/* ---------------------------------------------------- highest & lowest */

.extremes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  flex: 1;
}
.extremes__label {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-3);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 4px;
}
.extremes__list { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.extremes__list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}
.extremes__link {
  background: none;
  border: none;
  padding: 2px 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  text-align: left;
}
.extremes__link:hover { text-decoration: underline; }
.extremes__link--active { font-weight: 800; }
.extremes__val { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: 0.9rem; }

/* ----------------------------------------------------------- state cards */

.stateCards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.stateCard { display: block; }
.stateCard:hover { text-decoration: none; border-color: var(--accent); }
.stateCard__name {
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.stateCard__meta { color: var(--ink-3); margin: 2px 0 16px; }
.stateCard__cta { color: var(--accent); font-weight: 700; }

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

.footer {
  padding-top: 4px;
  color: var(--ink-3);
  font-size: 0.88rem;
}
.footer__credit {
  font-size: 0.78rem;
  opacity: 0.65;
  margin-left: 8px;
  white-space: nowrap;
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 980px) {
  .controls { grid-template-columns: 1fr; }
  .statRow { grid-template-columns: 1fr 1fr; }
  .reportGrid { grid-template-columns: 1fr; }
  .mapRow { grid-template-columns: 1fr; }
  .map { min-height: 56vh; }
  .stateCards { grid-template-columns: 1fr; }
  .nav { display: none; }
}

/* ----------------------------------------------------------------- print */

@media print {
  @page { margin: 12mm; }

  body { background: #fff; }
  .topbar, .card--controls, .nav, .leaflet-control-zoom { display: none !important; }
  .wrap { width: 100%; padding: 0; gap: 10px; }

  .card, .stat, .subpanel, .callout {
    box-shadow: none;
    border-color: #ccc;
  }
  .stat, .subpanel {
    background: #fff;
    border: 1px solid #ccc;
  }
  .stat__value { color: var(--ink); }
  .card { break-inside: avoid; padding: 12px; }
  #report { break-inside: auto; break-before: page; }
  .callouts, .subpanel, .stat, .demoTable tr, .driver { break-inside: avoid; }
  .contextRow { break-inside: avoid; }

  .statRow { grid-template-columns: repeat(4, 1fr); }
  .mapRow { grid-template-columns: 1fr; }
  .mapSide { grid-template-rows: none; grid-template-columns: 1fr 1fr; }
  .map { min-height: 0; height: 420px; flex: none; }
  .reportGrid { grid-template-columns: 1fr; }

  .extremes__link { color: var(--ink); }
  a { color: var(--ink); }
}
