:root {
  color-scheme: dark;
  --ink: #f5f7fa;
  --muted: #9aa9b8;
  --panel: #0c1a28;
  --panel-2: #112131;
  --border: #243648;
  --restrict: #ef6461;
  --allow: #25c1a1;
  --conditions: #f6b73c;
  --advisory: #7189a6;
  --brand-gold: #e5b94a;
  --brand-highlight: #f4ce72;
  --focus: #f4ce72;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #06111d;
  color: var(--ink);
  overflow: hidden;
}

button, select, input { font: inherit; }
button, select, input, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.app-shell { height: 100%; display: grid; grid-template-rows: 68px minmax(0, 1fr); }
.embed-mode .app-shell { grid-template-rows: minmax(0, 1fr); }
.embed-mode .topbar { display: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 20px;
  background: #071522;
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 20;
}

.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-symbol { width: 50px; height: 50px; overflow: hidden; flex: 0 0 50px; display: block; }
.brand-symbol img { display: block; height: 50px; width: auto; max-width: none; }
.wordmark { margin: 0; color: var(--brand-gold); font-size: 16px; line-height: 1.05; font-weight: 760; letter-spacing: .015em; }
.eyebrow, .kicker { margin: 0; color: var(--brand-gold); font-weight: 700; text-transform: uppercase; letter-spacing: .11em; font-size: 12px; }
.topbar h1 { margin: 3px 0 0; color: var(--ink); font-size: 19px; line-height: 1.1; letter-spacing: -.01em; }
.status-pill { color: #ffe19a; background: rgba(246, 183, 60, .12); border: 1px solid rgba(246, 183, 60, .28); padding: 8px 11px; border-radius: 999px; font-size: 13px; font-weight: 650; }

.workspace { min-height: 0; display: grid; grid-template-columns: 380px minmax(0, 1fr); }
.control-panel { min-height: 0; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--border); position: relative; z-index: 10; }
.mobile-drawer-handle { display: none; }
.intro { padding: 22px 22px 18px; border-bottom: 1px solid var(--border); }
.intro h2 { margin: 6px 0 8px; font-size: 24px; line-height: 1.1; letter-spacing: -.025em; }
.intro p:last-child { margin: 0; color: var(--muted); line-height: 1.45; font-size: 14px; }
.intro .dataset-date { margin: 11px 0 0; color: var(--brand-highlight); font-size: 12px; font-weight: 700; letter-spacing: .02em; }

.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--border); }
.metric-grid div { padding: 14px 18px; border-right: 1px solid var(--border); }
.metric-grid div:last-child { border-right: 0; }
.metric-grid strong { display: block; font-size: 23px; line-height: 1; }
.metric-grid span { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; }

.filters { padding: 16px 22px 18px; border-bottom: 1px solid var(--border); }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.section-heading h3 { margin: 0; font-size: 14px; letter-spacing: .01em; }
.section-heading > span { color: var(--muted); font-size: 12px; }
.text-button { border: 0; padding: 2px; background: none; color: var(--brand-highlight); cursor: pointer; font-size: 13px; }
.filter-status { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 12px 0 2px; padding: 9px 10px; color: var(--muted); background: rgba(229,185,74,.06); border-left: 3px solid var(--brand-gold); font-size: 12px; }
.compact-button, .detail-actions button, .legend-action { color: var(--brand-highlight); background: transparent; border: 1px solid rgba(229,185,74,.42); border-radius: 6px; padding: 5px 8px; cursor: pointer; font-size: 12px; font-weight: 700; white-space: nowrap; }
.compact-button:hover, .detail-actions button:hover, .legend-action:hover { background: rgba(229,185,74,.1); }
.filters label, .filter-label { display: block; margin: 14px 0 7px; color: var(--muted); font-size: 13px; font-weight: 650; }
.filters select, .filters input { width: 100%; color: var(--ink); background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 11px; }
.filters select:focus, .filters input:focus { border-color: var(--brand-gold); }
.filters input::placeholder { color: #71879a; }
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.filter-grid label { min-width: 0; }
.stance-controls { display: flex; flex-wrap: wrap; gap: 7px; }
.stance-button { color: #c7d2dc; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 7px 10px; cursor: pointer; font-size: 12px; font-weight: 650; }
.stance-button[aria-pressed="true"] { color: #07121e; border-color: transparent; }
.stance-button[data-stance="All"][aria-pressed="true"] { background: #dce7f0; }
.stance-button[data-stance="Restrict"][aria-pressed="true"] { background: var(--restrict); }
.stance-button[data-stance="Allow"][aria-pressed="true"] { background: var(--allow); }
.stance-button[data-stance="Conditions"][aria-pressed="true"] { background: var(--conditions); }
.stance-button[data-stance="Advisory"][aria-pressed="true"] { background: var(--advisory); }

.results { min-height: 0; flex: 1; display: flex; flex-direction: column; padding: 16px 12px 0 22px; }
.results .section-heading { padding-right: 10px; margin-bottom: 10px; }
.measure-list { overflow-y: auto; padding: 0 10px 18px 0; scrollbar-color: #395069 transparent; }
.measure-card { width: 100%; text-align: left; color: var(--ink); background: transparent; border: 1px solid transparent; border-bottom-color: var(--border); padding: 12px 10px; cursor: pointer; display: block; border-radius: 7px; }
.measure-card:hover { background: rgba(133, 163, 191, .08); border-color: rgba(133, 163, 191, .2); }
.measure-card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 7px; }
.stance-tag, .theme-tag { font-size: 11px; font-weight: 750; letter-spacing: .04em; text-transform: uppercase; }
.theme-tag { color: var(--brand-highlight); }
.stance-tag[data-stance="Restrict"] { color: #ff8582; }
.stance-tag[data-stance="Allow"] { color: #45dbbd; }
.stance-tag[data-stance="Conditions"] { color: #ffc961; }
.stance-tag[data-stance="Advisory"] { color: #9bb2ff; }
.mapping-state { color: var(--muted); font-size: 11px; }
.mapping-state.pending { color: #ffc961; }
.mapping-state[data-quality="state-level"] { color: var(--advisory); }
.measure-jurisdiction { display: block; font-size: 15px; }
.measure-name { display: block; color: var(--muted); margin-top: 4px; font-size: 13px; line-height: 1.35; }
.empty-state { color: var(--muted); padding: 24px 8px; line-height: 1.5; }

.map-stage { min-width: 0; min-height: 0; position: relative; background: #06111d; overflow: hidden; }
#map { position: absolute; inset: 0; }
.cluster-labels { position: absolute; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; }
.cluster-label { position: absolute; transform: translate(-50%, -50%); min-width: 24px; color: #06111d; font-size: 11px; line-height: 1; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; text-shadow: 0 1px 0 rgba(255,255,255,.2); }
.maplibregl-canvas { cursor: grab; }
.maplibregl-canvas:active { cursor: grabbing; }
.maplibregl-ctrl-group { background: #102131; }
.maplibregl-ctrl-group button { filter: invert(1); }
.maplibregl-ctrl-attrib { background: rgba(7,18,30,.82) !important; color: #9fb0bf; }
.maplibregl-ctrl-attrib a { color: #c4d5e3; }

.map-note, .map-legend { position: absolute; z-index: 4; background: rgba(6, 17, 29, .94); border: 1px solid var(--border); backdrop-filter: blur(12px); }
.map-note { top: 16px; left: 16px; border-radius: 8px; padding: 9px 11px; color: #bfd0de; font-size: 12px; display: flex; align-items: center; gap: 8px; }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--allow); box-shadow: 0 0 0 5px rgba(37,193,161,.12); }
.map-legend { left: 16px; bottom: 28px; border-radius: 9px; padding: 10px 12px; display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: #c3d0db; }
.map-legend span { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend-swatch.verified { background: var(--conditions); }
.legend-swatch.pending { background: var(--advisory); }
.legend-swatch.cluster { background: var(--allow); border-radius: 50%; }
.legend-action { margin: -4px -5px -4px 2px; }

.detail-panel { position: absolute; z-index: 6; top: 16px; right: 16px; width: min(410px, calc(100% - 32px)); max-height: calc(100% - 72px); overflow-y: auto; background: rgba(12, 26, 40, .98); border: 1px solid var(--brand-gold); border-top: 3px solid var(--brand-highlight); border-radius: 12px; padding: 20px 22px 22px; box-shadow: 0 20px 50px rgba(0,0,0,.4); transform: translateX(calc(100% + 32px)); transition: transform .24s ease; }
.detail-panel.open { transform: translateX(0); }
.close-button { position: absolute; right: 12px; top: 10px; width: 34px; height: 34px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: #b9c8d5; font-size: 26px; cursor: pointer; line-height: 1; }
.close-button:hover { background: rgba(255,255,255,.07); }
.detail-state { margin: 0 42px 4px 0; color: var(--conditions); font-size: 12px; font-weight: 750; text-transform: uppercase; letter-spacing: .09em; }
.detail-panel > h2 { margin: 0 36px 18px 0; font-size: 25px; letter-spacing: -.02em; }
.detail-location { margin: -9px 38px 18px 0; color: var(--muted); line-height: 1.4; font-size: 13px; }
.detail-location[data-quality="state-level"] { color: #b5c0cd; border-left: 3px solid var(--advisory); padding-left: 10px; }
.detail-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 7px; margin: 0 0 17px; }
.detail-actions button:disabled { color: #687887; border-color: var(--border); cursor: default; opacity: .65; }
.detail-measure { border-top: 1px solid var(--border); padding: 16px 0 2px; }
.detail-measure:first-child { border-top: 0; padding-top: 0; }
.detail-measure h3 { margin: 7px 0 8px; font-size: 17px; line-height: 1.25; }
.detail-measure p { margin: 0 0 12px; color: var(--muted); line-height: 1.5; font-size: 14px; }
.detail-measure a { color: var(--brand-highlight); font-weight: 650; font-size: 13px; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.detail-warning { color: #ffd483 !important; border-left: 3px solid var(--conditions); padding-left: 10px; }
.detail-meta { color: #91a6b8 !important; font-size: 12px !important; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.maplibregl-popup-content { background: #0d1f2e; color: var(--ink); border: 1px solid #31465a; border-radius: 8px; padding: 9px 11px; box-shadow: 0 10px 24px rgba(0,0,0,.28); }
.maplibregl-popup-tip { border-top-color: #0d1f2e !important; }
.map-tooltip strong { display: block; font-size: 13px; }
.map-tooltip span { color: #a9bac8; font-size: 12px; }

.methodology-dialog { width: min(560px, calc(100% - 30px)); color: var(--ink); background: var(--panel); border: 1px solid var(--brand-gold); border-top: 3px solid var(--brand-highlight); border-radius: 12px; padding: 24px; box-shadow: 0 24px 70px rgba(0,0,0,.55); }
.methodology-dialog::backdrop { background: rgba(2,8,14,.72); backdrop-filter: blur(4px); }
.methodology-dialog h2 { margin: 7px 36px 16px 0; }
.methodology-dialog p { color: var(--muted); line-height: 1.55; }
.methodology-dialog strong { color: var(--ink); }

@media (max-width: 820px) {
  body { overflow: hidden; }
  .app-shell { height: 100%; min-height: 100%; grid-template-rows: auto minmax(0, 1fr); }
  .topbar { position: sticky; top: 0; }
  .status-pill { max-width: 160px; text-align: center; font-size: 11px; }
  .workspace { display: block; position: relative; min-height: 0; }
  .map-stage { height: 100%; min-height: 430px; }
  .control-panel { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; height: 82vh; min-height: 0; border: 1px solid var(--border); border-bottom: 0; border-radius: 14px 14px 0 0; box-shadow: 0 -18px 45px rgba(0,0,0,.45); transform: translateY(calc(100% - 56px)); transition: transform .24s ease; overflow: hidden; }
  body.mobile-panel-open .control-panel { transform: translateY(0); }
  .mobile-drawer-handle { min-height: 56px; display: flex; align-items: center; justify-content: space-between; flex: 0 0 56px; width: 100%; padding: 0 20px; color: var(--ink); background: var(--panel-2); border: 0; border-bottom: 1px solid var(--border); font-weight: 750; }
  body.mobile-panel-open .mobile-drawer-handle span:last-child { transform: rotate(180deg); }
  .results { min-height: 220px; }
  .detail-panel { inset: auto 10px 10px; width: auto; max-height: 68%; transform: translateY(calc(100% + 22px)); }
  .detail-panel.open { transform: translateY(0); }
  .map-note { top: 10px; left: 10px; }
  .map-legend { left: 10px; bottom: 25px; right: 10px; gap: 10px; }
  .filter-grid { grid-template-columns: 1fr; gap: 0; }
  .embed-mode .app-shell { grid-template-rows: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .detail-panel { transition: none; }
}
