/* Design tokens. This widget embeds in a white host page, so the surface is
   white and the theme is fixed light (no dark-mode flip — it would clash with
   the host). Magnitude is a sequential red ramp (ColorBrewer Reds). */
.viz-root {
  --page-plane:     #ffffff;
  --surface-1:      #ffffff;
  --text-primary:   #1a1a1a;
  --text-secondary: #565656;
  --text-muted:     #8a8a8a;
  --hairline:       #e8e6e3;
  --border:         rgba(0, 0, 0, 0.08);
  --zero-fill:      #f2f1ef;   /* reporting, zero out — distinct from white "no data" */
  /* sequential red ramp, low → high magnitude */
  --seq-1: #fee5d9;
  --seq-2: #fcae91;
  --seq-3: #fb6a4a;
  --seq-4: #de2d26;
  --seq-5: #a50f15;
  --accent: #c0211a;   /* interactive red; 4.9:1 on white for white-on-accent text */
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #ffffff;
}

.viz-root {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 24px 48px;
  color: var(--text-primary);
  background: var(--page-plane);
}

.page-header h1 {
  margin: 0 0 4px;
  font-size: 1.6rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.subtitle {
  margin: 0 0 24px;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* ---- stat tiles ---- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.stat-value {
  font-size: 1.7rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.stat-value-small { font-size: 1.05rem; padding-top: 6px; }

/* ---- filter row ---- */
.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.filter-label { font-size: 0.85rem; color: var(--text-secondary); }
.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-1);
}
.segmented button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.85rem;
  padding: 6px 14px;
  cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--hairline); }
.segmented button[aria-checked="true"] {
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
}
.segmented button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ---- cards ---- */
.card {
  position: relative;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}
.card-title {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 650;
}

/* ---- map ---- */
.map-container { width: 100%; }
.map-container svg { display: block; width: 100%; height: auto; }
.map-container.refreshing { opacity: 0.55; transition: opacity 0.2s; }

.state {
  stroke: var(--surface-1);
  stroke-width: 0.75;
  cursor: default;
}
.state--nodata { stroke: var(--hairline); } /* keeps the US silhouette visible */
.state:hover, .state:focus-visible {
  stroke: var(--text-primary);
  stroke-width: 1.5;
  outline: none;
}

/* ---- county drill-down layer ---- */
.county-backing {
  fill: transparent;      /* hole-free hit area for the hovered state */
  stroke: none;
}
.county {
  stroke: var(--surface-1);
  stroke-width: 0.3;
  cursor: default;
}
.county--nodata { stroke: var(--hairline); }
.county:hover {
  stroke: var(--text-primary);
  stroke-width: 1;
}
/* The exploded state reads as "lifted" — a crisp outline around the group. */
.county-layer { pointer-events: all; }

/* ---- legend ---- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 14px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-note {
  width: 100%;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 2px;
}
.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid var(--border);
}

/* ---- tooltip ---- */
.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  padding: 10px 12px;
  min-width: 170px;
  z-index: 10;
  font-size: 0.82rem;
}
.tooltip-title {
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.tooltip-value {
  font-size: 1.15rem;
  font-weight: 650;
  color: var(--text-primary);
}
.tooltip-sub { color: var(--text-muted); margin-top: 3px; }

/* ---- table ---- */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}
th, td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--hairline);
}
th.num, td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
th button {
  appearance: none;
  border: none;
  background: none;
  font: inherit;
  font-weight: 650;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
}
th button:hover, th button:focus-visible { color: var(--text-primary); }
th button[data-dir]::after { content: " ↓"; color: var(--text-muted); }
th button[data-dir="asc"]::after { content: " ↑"; }
tbody tr:hover { background: var(--zero-fill); }
td:first-child { color: var(--text-primary); }
td { color: var(--text-secondary); }

.page-footer {
  color: var(--text-muted);
  font-size: 0.8rem;
}
.page-footer code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.95em;
}

.error-banner {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 3px solid #d03b3b;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 20px;
  color: var(--text-secondary);
}

/* ---- mobile ---- */
@media (max-width: 640px) {
  .viz-root { padding: 16px 12px 24px; }
  .page-header h1 { font-size: 1.3rem; }
  .subtitle { font-size: 0.88rem; margin-bottom: 18px; }
  .stat-row { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-value { font-size: 1.35rem; }
  .card { padding: 14px; }
  .legend { font-size: 0.72rem; gap: 10px; }
}
