:root {
  color-scheme: dark;
  --surface-0: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);

  --series-1: #3987e5; /* blue   - Local government */
  --series-2: #d95926; /* orange - Federal government */
  --series-3: #199e70; /* aqua   - Law enforcement */
  --series-4: #c98500; /* yellow - Local gov & law enforcement */
  --series-5: #d55181; /* magenta- Courts */
  --series-6: #008300; /* green  - Corrections / detention */
  --series-7: #9085e9; /* violet - State government */
  --series-8: #e66767; /* red    - Child protective services */
  --series-other: #6f6d66; /* Other (folded categories) */

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #e66767;

  --font-sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 10px;
  --radius-sm: 6px;
  --max-width: 1240px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
a.link { color: var(--series-1); text-decoration: none; }
a.link:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 0.4em; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 2.1rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; color: var(--text-secondary); }

code, .mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

.container { max-width: var(--max-width); margin: 0 auto; padding: 0 24px; }

/* ---------- Nav ---------- */
.nav {
  position: sticky; top: 0; z-index: 40;
  background: rgba(13, 13, 13, 0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: var(--max-width); margin: 0 auto; padding: 0 24px;
  height: 58px; display: flex; align-items: center; gap: 28px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 1.05rem; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--series-1); box-shadow: 0 0 0 3px rgba(57,135,229,0.20); }
.nav-links { display: flex; gap: 22px; font-size: 0.92rem; color: var(--text-secondary); flex: 1; }
.nav-links a:hover { color: var(--text-primary); }
.nav-links a.active { color: var(--text-primary); }
.nav-search { position: relative; }
.nav-search input {
  width: 240px; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px 7px 32px; color: var(--text-primary); font-size: 0.88rem;
}
.nav-search input:focus { outline: none; border-color: var(--series-1); }
.nav-search svg { position: absolute; left: 9px; top: 8px; opacity: 0.5; }
.nav-search-results {
  position: absolute; top: 40px; right: 0; width: 360px; max-height: 420px; overflow-y: auto;
  background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0,0,0,0.5); display: none; padding: 6px;
}
.nav-search-results.open { display: block; }

@media (max-width: 720px) {
  .nav-inner { flex-wrap: wrap; height: auto; padding: 10px 20px; gap: 10px 14px; }
  .nav-links { order: 3; width: 100%; gap: 16px; font-size: 0.86rem; }
  .nav-search { order: 2; margin-left: auto; }
  .nav-search input { width: 150px; }
  .nav-search-results { width: 260px; }
}
.search-group-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); padding: 8px 10px 4px; }
.search-result { display: block; padding: 8px 10px; border-radius: var(--radius-sm); }
.search-result:hover { background: var(--surface-2); }
.search-result .name { font-size: 0.9rem; color: var(--text-primary); }
.search-result .meta { font-size: 0.76rem; color: var(--text-muted); }

/* ---------- Buttons / inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 9px 16px; font-size: 0.88rem; font-weight: 500; font-family: inherit;
}
.btn:hover { border-color: var(--text-muted); }
.btn.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.btn.primary:hover { background: #2f74c9; }
input[type="text"], input[type="email"], select {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 11px; color: var(--text-primary); font-size: 0.88rem; font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--series-1); }

/* ---------- Layout helpers ---------- */
.hero { padding: 64px 0 40px; }

/* ---------- Hero flare: ambient background + entrance, no JS ---------- */
.hero-flare { position: relative; overflow: hidden; }
.hero-flare-grid {
  position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(255,255,255,0.04) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,0.04) 1px, transparent 1px);
  background-size: 42px 42px;
  -webkit-mask-image: radial-gradient(ellipse 65% 75% at 18% 25%, black 0%, transparent 72%);
  mask-image: radial-gradient(ellipse 65% 75% at 18% 25%, black 0%, transparent 72%);
}
.hero-flare-glow {
  position: absolute; z-index: 0; pointer-events: none;
  width: 560px; height: 560px; left: -150px; top: -180px;
  background: radial-gradient(circle, rgba(57,135,229,0.28), transparent 70%);
}
.hero-flare .container { position: relative; z-index: 1; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 8px; font-size: 0.78rem; color: var(--text-secondary);
  background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: 999px;
  padding: 5px 12px 5px 10px; margin-bottom: 18px;
}
.eyebrow::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--series-1);
  box-shadow: 0 0 0 3px rgba(57,135,229,0.22); flex: none;
}
.hero-in > * { opacity: 0; animation: hero-fade-up 0.6s ease forwards; }
.hero-in > *:nth-child(1) { animation-delay: 0s; }
.hero-in > *:nth-child(2) { animation-delay: 0.08s; }
.hero-in > *:nth-child(3) { animation-delay: 0.16s; }
.hero-in > *:nth-child(4) { animation-delay: 0.24s; }
.hero-in > *:nth-child(5) { animation-delay: 0.32s; }
@keyframes hero-fade-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) {
  .hero-in > * { animation: none; opacity: 1; }
}

.section { padding: 40px 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 18px; gap: 16px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2,1fr);} }
@media (max-width: 600px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px;
}
.card.pad-sm { padding: 14px 16px; }

/* ---------- Stat tiles ---------- */
.stat-tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.stat-tile .label { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 8px; }
.stat-tile .value { font-size: 1.9rem; font-weight: 600; letter-spacing: -0.01em; }
.stat-tile .sub { font-size: 0.78rem; color: var(--text-secondary); margin-top: 4px; }
.hero-figure { font-size: 3rem; font-weight: 700; letter-spacing: -0.02em; }

/* ---------- Badges (category identity) ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 0.76rem; color: var(--text-secondary); padding: 3px 9px 3px 7px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; }
.badge .swatch { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.badge.role { text-transform: capitalize; }

/* ---------- Table ---------- */
table.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th { text-align: left; font-weight: 500; color: var(--text-muted); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 8px 12px; border-bottom: 1px solid var(--gridline); }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--gridline); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface-2); }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Map ---------- */
#map { width: 100%; height: 560px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); position: relative; }
.map-detail-card {
  position: absolute; bottom: 14px; left: 14px; z-index: 5;
  width: 300px; max-width: calc(100% - 28px);
  background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: 0 14px 36px rgba(0,0,0,0.55); padding: 14px 16px;
  animation: card-in 0.12s ease-out;
}
@keyframes card-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.map-detail-card .close-btn {
  position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-muted);
  background: transparent; border: none; font-size: 15px; line-height: 1; font-family: inherit;
}
.map-detail-card .close-btn:hover { background: var(--surface-2); color: var(--text-primary); }
.map-detail-card h4 { margin: 0 22px 6px 0; font-size: 0.95rem; font-weight: 600; }
.map-detail-card .meta-line { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 3px; }
.map-detail-card .meta-line a { color: var(--series-1); }
.map-detail-card .view-link {
  display: inline-block; margin-top: 10px; font-size: 0.82rem; font-weight: 500; color: var(--series-1);
}
.map-detail-card .skeleton-line { height: 11px; border-radius: 4px; margin: 6px 0; }
.map-zoom-hint {
  position: absolute; top: 12px; left: 12px; z-index: 4;
  background: rgba(13,13,13,0.72); color: var(--text-secondary); font-size: 0.76rem;
  padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border); pointer-events: none;
}
.map-legend {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px;
}
.map-legend .badge { cursor: pointer; user-select: none; }
.map-legend .badge.off { opacity: 0.35; }
.maplibregl-popup-content { background: var(--surface-1) !important; color: var(--text-primary) !important; border-radius: 8px !important; box-shadow: 0 8px 24px rgba(0,0,0,0.5) !important; font-family: var(--font-sans) !important; }
.maplibregl-popup-tip { border-top-color: var(--surface-1) !important; border-bottom-color: var(--surface-1) !important; }
.map-popup .name { font-weight: 600; font-size: 0.88rem; margin-bottom: 3px; }
.map-popup .meta { font-size: 0.78rem; color: var(--text-secondary); }
.map-popup a { color: var(--series-1); font-size: 0.78rem; }

/* ---------- Charts (hand-built SVG, per dataviz mark specs) ---------- */
.chart-svg text { font-family: var(--font-sans); }
.chart-bar { fill: var(--series-1); }
.chart-bar-track { fill: var(--surface-2); }
.axis-label { fill: var(--text-muted); font-size: 11px; }
.value-label { fill: var(--text-secondary); font-size: 11.5px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 130px; align-items: center; gap: 10px; padding: 7px 0; }
.bar-row .bar-label { font-size: 0.82rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .bar-track { position: relative; height: 20px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-row .bar-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--series-1); }
.bar-row .bar-value { font-size: 0.8rem; color: var(--text-secondary); text-align: right; font-variant-numeric: tabular-nums; }

.sparkline { display: block; }

/* ---------- Misc ---------- */
.tag-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 18px; }
.pill-filter {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 13px; font-size: 0.82rem; color: var(--text-secondary); cursor: pointer;
}
.pill-filter.active { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.empty-state { color: var(--text-muted); font-size: 0.9rem; padding: 24px; text-align: center; }
.skeleton { background: linear-gradient(90deg, var(--surface-1) 25%, var(--surface-2) 37%, var(--surface-1) 63%); background-size: 400% 100%; animation: shimmer 1.4s infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

.footer { border-top: 1px solid var(--border); padding: 28px 0; margin-top: 60px; color: var(--text-muted); font-size: 0.82rem; }
.footer a { color: var(--text-secondary); }

.pagination { display: flex; align-items: center; gap: 10px; justify-content: center; margin-top: 18px; font-size: 0.85rem; color: var(--text-secondary); }
.pagination button { background: var(--surface-1); border: 1px solid var(--border); color: var(--text-primary); border-radius: 6px; padding: 6px 10px; cursor: pointer; font-family: inherit; }
.pagination button:disabled { opacity: 0.35; cursor: default; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 0.88rem; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; color: var(--text-primary); }

.breadcrumb { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 10px; }
.breadcrumb a:hover { color: var(--text-primary); }

.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
