/* ===========================================================================
   Drought Intelligence Explorer — design system
   Clean, light scientific interface · deep navy sidebar · white workspace
   Palette tokens follow the project specification (§3).
   =========================================================================== */

:root {
  --navy: #14263D;
  --navy-2: #203B59;
  --navy-3: #0E1B2C;
  --navy-line: rgba(255, 255, 255, 0.09);
  --bg: #F5F7FA;
  --panel: #FFFFFF;
  --ink: #1F2937;
  --ink-2: #687588;
  --border: #E2E7EE;
  --border-2: #CBD5E1;
  --red: #B94747;          /* muted red — drought warnings */
  --sev: #8F252F;          /* severe drought */
  --mod: #D97745;          /* moderate drought */
  --mild: #E9BE54;         /* mild drought */
  --ok: #72A982;           /* normal conditions */
  --wet: #4F91B8;          /* wet conditions */
  --amber-bg: #FFF7E0;
  --amber-ink: #6E5310;
  --amber-line: #EBD79B;
  --focus: #4F91B8;
  --shadow: 0 1px 2px rgba(20, 38, 61, 0.06), 0 1px 6px rgba(20, 38, 61, 0.05);
  --radius: 6px;
  --font: 'Inter', 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar-w: 286px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }
/* The hidden attribute must always win over component display rules
   (modals use display:flex, buttons inline-flex). */
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; font-size: inherit; color: inherit; }
.mono { font-family: var(--mono); }
.small { font-size: 12px; color: var(--ink-2); }
.sr-only, .skip-link {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link:focus {
  position: fixed; top: 8px; left: 8px; z-index: 300;
  width: auto; height: auto; clip: auto; padding: 8px 14px;
  background: var(--navy); color: #fff; border-radius: 4px;
}
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------------------ topbar */
.topbar {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; gap: 18px;
  min-height: var(--topbar-h); padding: 0 18px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.nav-toggle { display: none; }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-logo { flex: 0 0 auto; border-radius: 50%; }
.brand-title {
  font-size: 14.5px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--navy); white-space: nowrap;
}
.brand-sub {
  font-size: 9.5px; font-weight: 600; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--ink-2); white-space: nowrap;
}
.topnav { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.topnav button {
  border: 0; background: transparent; cursor: pointer;
  padding: 7px 11px; border-radius: 4px; font-size: 12.5px; font-weight: 500;
  color: var(--ink-2); transition: background 0.12s, color 0.12s;
}
.topnav button:hover { background: #EEF2F6; color: var(--navy); }
.topbar-status {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end;
}
.chip {
  font-family: var(--mono); font-size: 9.5px; font-weight: 500;
  letter-spacing: 0.04em; text-transform: uppercase;
  padding: 3px 8px; border: 1px solid var(--border); border-radius: 3px;
  color: var(--ink-2); background: #FAFBFC; white-space: nowrap;
}
.chip-static { color: #44576D; border-color: #D3DCE5; }
.chip-demo { color: var(--amber-ink); border-color: var(--amber-line); background: var(--amber-bg); }

/* demo banner */
.demo-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 5px 18px; background: var(--amber-bg);
  border-bottom: 1px solid var(--amber-line); color: var(--amber-ink);
  font-size: 11.5px;
}
.demo-banner-text strong { font-weight: 600; }
.demo-banner-meta { font-family: var(--mono); font-size: 10px; white-space: nowrap; opacity: 0.85; }
.link-btn {
  border: 0; background: none; padding: 0; margin-left: 6px;
  color: inherit; text-decoration: underline; text-underline-offset: 2px;
  cursor: pointer; font-size: 11.5px;
}

/* ------------------------------------------------------------------ layout */
.layout { display: flex; align-items: flex-start; min-height: calc(100vh - var(--topbar-h) - 90px); }

/* ----------------------------------------------------------------- sidebar */
.sidebar {
  flex: 0 0 var(--sidebar-w); position: sticky; top: calc(var(--topbar-h) + 29px);
  align-self: flex-start;
  height: calc(100vh - var(--topbar-h) - 29px);
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--navy); color: #C7D2DE;
  padding-bottom: 12px;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: #2C4358; border-radius: 4px; }
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 10px; border-bottom: 1px solid var(--navy-line);
}
.sidebar-title {
  font-size: 10px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  color: #8FA3BA;
}
.sidebar-close { display: none; color: #8FA3BA; }
.side-sec { padding: 13px 16px 4px; border-bottom: 1px solid var(--navy-line); }
.side-sec:last-of-type { border-bottom: 0; }
.side-sec h2 {
  margin: 0 0 10px; font-size: 10px; font-weight: 700;
  letter-spacing: 0.13em; text-transform: uppercase; color: #8FA3BA;
}
.side-note { font-size: 11px; color: #7E93AB; margin: 4px 0; }
.side-note-inline { font-weight: 400; color: #7E93AB; font-size: 10px; }

.field { display: block; margin-bottom: 10px; }
.field-row { display: flex; gap: 8px; }
.field-row .field { flex: 1; min-width: 0; }
.field-label {
  display: flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 600; color: #A7B7C8; margin-bottom: 4px;
  letter-spacing: 0.02em;
}
select, input[type="search"] {
  width: 100%; appearance: none; -webkit-appearance: none;
  background: #1D3450; color: #E8EEF4;
  border: 1px solid #2E4660; border-radius: 4px;
  padding: 7px 24px 7px 9px; font-size: 12.5px; font-family: var(--font);
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238FA3BA' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
  cursor: pointer;
}
select:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
select:disabled { opacity: 0.45; cursor: not-allowed; }
input[type="range"] {
  width: 100%; accent-color: #4F91B8; cursor: pointer; margin: 6px 0 2px;
}
.field-divider { height: 1px; background: var(--navy-line); margin: 6px 0 12px; }

/* indicator radio list */
.ind-list { display: flex; flex-direction: column; gap: 2px; }
.ind-group-label {
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  color: #647891; margin: 8px 0 3px;
}
.ind-opt { position: relative; display: flex; align-items: center; }
.ind-opt input {
  position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer;
}
.ind-opt .ind-body {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; padding: 6px 9px; border-radius: 4px; border: 1px solid transparent;
  cursor: pointer; transition: background 0.1s;
}
.ind-opt .ind-body:hover { background: #1D3450; }
.ind-opt input:checked + .ind-body {
  background: #22405F; border-color: #35577C;
}
.ind-opt input:focus-visible + .ind-body { outline: 2px solid var(--focus); }
.ind-name { font-size: 12px; font-weight: 600; color: #DCE5EE; }
.ind-opt input:checked + .ind-body .ind-name { color: #fff; }
.ind-units { font-size: 10px; color: #7E93AB; font-family: var(--mono); white-space: nowrap; }

/* mode cards */
.mode-cards { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.mode-card { position: relative; display: block; cursor: pointer; }
.mode-card input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.mode-card .mode-name, .mode-card .mode-desc { display: block; }
.mode-card span {
  display: block; padding: 7px 10px; border: 1px solid #2E4660; border-radius: 5px;
  background: #18304A;
}
.mode-name { font-size: 12px; font-weight: 600; color: #DCE5EE; }
.mode-desc { font-size: 10.5px; color: #7E93AB; line-height: 1.35; }
.mode-card input:checked + span {
  background: #22405F; border-color: #4F91B8;
  box-shadow: inset 0 0 0 1px #4F91B8;
}
.mode-card input:focus-visible + span { outline: 2px solid var(--focus); }

/* switches */
.switch { display: flex; align-items: center; gap: 9px; margin-bottom: 9px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  flex: 0 0 auto; width: 30px; height: 16px; border-radius: 9px;
  background: #2E4660; position: relative; transition: background 0.15s;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px; border-radius: 50%; background: #9FB2C6;
  transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .switch-track { background: #4F91B8; }
.switch input:checked + .switch-track::after { transform: translateX(14px); background: #fff; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--focus); }
.switch-label { font-size: 12px; color: #C7D2DE; }
.switch.is-disabled { cursor: not-allowed; opacity: 0.55; }
.tag-na {
  font-size: 9px; font-family: var(--mono); text-transform: uppercase;
  border: 1px solid #3A5470; border-radius: 3px; padding: 0 4px; color: #8FA3BA;
}

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 4px; border: 1px solid var(--border-2);
  background: var(--panel); color: var(--ink);
  font-size: 12px; font-weight: 600; padding: 7px 13px; cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: #F0F3F7; border-color: #AEBBC9; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: #EEF2F6; }
.btn-solid { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn-solid:hover { background: var(--navy-2); border-color: var(--navy-2); }
.btn-block { width: 100%; margin-top: 4px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border: 1px solid var(--border-2); border-radius: 4px;
  background: transparent; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { background: #EEF2F6; color: var(--navy); }

/* tooltips */
.tip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%;
  border: 1px solid #46607C; color: #8FA3BA;
  font-size: 9px; font-weight: 700; cursor: help; flex: 0 0 auto;
  position: relative;
}
.tip::after {
  content: attr(data-tip);
  position: absolute; left: 50%; top: calc(100% + 6px); transform: translateX(-50%);
  background: var(--navy-3); color: #DCE5EE;
  font-size: 11px; font-weight: 400; line-height: 1.45; text-align: left;
  padding: 7px 10px; border-radius: 5px; width: 230px;
  opacity: 0; pointer-events: none; transition: opacity 0.12s;
  z-index: 40; box-shadow: var(--shadow); white-space: normal;
}
.tip:hover::after, .tip:focus::after { opacity: 1; }

/* --------------------------------------------------------------- workspace */
.workspace {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-direction: column; gap: 14px;
  padding: 14px 18px 0;
}
.tabs {
  display: flex; gap: 2px; border-bottom: 1px solid var(--border);
  background: var(--panel); border-radius: var(--radius) var(--radius) 0 0;
  padding: 0 6px;
}
.tabs button {
  border: 0; background: transparent; cursor: pointer;
  padding: 9px 16px; font-size: 12.5px; font-weight: 600; color: var(--ink-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--navy); border-bottom-color: var(--navy); }

/* KPI row */
.kpi-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
}
.kpi-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px 10px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 3px; position: relative;
}
.kpi-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.kpi-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--ink-2);
}
.kpi-demo-tag {
  font-family: var(--mono); font-size: 8.5px; font-weight: 600; text-transform: uppercase;
  color: var(--amber-ink); background: var(--amber-bg);
  border: 1px solid var(--amber-line); border-radius: 3px; padding: 1px 5px;
}
.kpi-value {
  font-size: 25px; font-weight: 700; color: var(--navy);
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em; line-height: 1.15;
}
.kpi-value.is-na { color: var(--ink-2); font-size: 20px; }
.kpi-sub { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.kpi-delta { font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; min-height: 16px; }
.kpi-delta .up { color: var(--red); }
.kpi-delta .down { color: var(--ok); }
.kpi-delta .flat { color: var(--ink-2); font-weight: 500; }
.kpi-foot { font-size: 10.5px; color: var(--ink-2); margin-top: 4px; }
.kpi-sub .cat-chip {
  display: inline-block; padding: 1px 7px; border-radius: 3px;
  font-size: 10.5px; font-weight: 600; color: #fff; margin-left: 4px;
}

/* panels */
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.panel-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 14px;
  flex-wrap: wrap; padding: 11px 14px; border-bottom: 1px solid var(--border);
}
.panel-titles { min-width: 0; }
.panel-title {
  margin: 0; font-size: 13px; font-weight: 700; color: var(--navy);
  letter-spacing: 0.01em;
}
.panel-meta { font-size: 11px; color: var(--ink-2); display: block; margin-top: 1px; }
.panel-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel-note { font-size: 10.5px; color: var(--ink-2); padding: 0 14px 10px; margin: 2px 0 0; }
.mini-field { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--ink-2); }
.mini-field select {
  width: auto; background-color: #F3F6F9; color: var(--ink);
  border-color: var(--border-2); padding: 5px 22px 5px 8px; font-size: 11.5px;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23687588' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
}
.check { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink); cursor: pointer; }
.check input { accent-color: var(--navy); width: 14px; height: 14px; }

/* map */
.map-body { display: grid; grid-template-columns: minmax(0, 1fr) 322px; }
.map-wrap { position: relative; min-width: 0; z-index: 0; }
#map { height: 560px; width: 100%; background: #EDF1F5; }
.map-corner-tag {
  position: absolute; left: 10px; bottom: 10px; z-index: 500;
  font-family: var(--mono); font-size: 9px; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--amber-ink); background: rgba(255, 247, 224, 0.92);
  border: 1px solid var(--amber-line); border-radius: 3px; padding: 2px 7px;
  pointer-events: none;
}
.map-rail {
  border-left: 1px solid var(--border); background: #FAFBFC;
  overflow-y: auto; max-height: 560px;
}
.rail-box { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.rail-box:last-child { border-bottom: 0; }
.rail-title {
  margin: 0 0 8px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--navy);
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
}
.rail-sub { font-weight: 500; color: var(--ink-2); text-transform: none; letter-spacing: 0; font-size: 10.5px; }
.rail-note { font-size: 10.5px; color: var(--ink-2); margin: 8px 0 0; }

.legend { display: flex; flex-direction: column; gap: 3px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 11.5px; }
.legend-swatch { width: 22px; height: 12px; border-radius: 2px; border: 1px solid rgba(0,0,0,0.12); flex: 0 0 auto; }
.legend-range { font-family: var(--mono); font-size: 10.5px; color: var(--ink-2); margin-left: auto; white-space: nowrap; }
.legend-continuous { margin: 4px 0; }
.legend-grad {
  height: 12px; border-radius: 2px; border: 1px solid rgba(0,0,0,0.12);
}
.legend-grad-labels { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 10px; color: var(--ink-2); margin-top: 2px; }
.legend-head { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-2); margin: 6px 0 3px; }

.selected-info { font-size: 12px; }
.selected-info .sel-name { font-size: 14px; font-weight: 700; color: var(--navy); }
.selected-info .sel-state { font-size: 11.5px; color: var(--ink-2); margin-bottom: 7px; }
.sel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 10px; margin-top: 4px; }
.sel-grid .k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-2); }
.sel-grid .v { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }

.region-summary { font-size: 12px; }
.region-summary .rs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 10px; }
.region-summary .rs-row { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px dashed var(--border); }
.region-summary .rs-k { color: var(--ink-2); font-size: 11.5px; }
.region-summary .rs-v { font-weight: 600; font-variant-numeric: tabular-nums; }
.top-list { margin-top: 8px; }
.top-list-title { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-2); margin-bottom: 4px; }
.top-list-row {
  display: flex; align-items: center; gap: 7px; font-size: 11.5px;
  padding: 2.5px 0; border-bottom: 1px dashed var(--border);
}
.top-list-row:last-child { border-bottom: 0; }
.top-list-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-list-val { font-family: var(--mono); font-size: 10.5px; color: var(--ink-2); }
.mini-chip {
  display: inline-block; padding: 0 6px; border-radius: 3px; color: #fff;
  font-size: 9.5px; font-weight: 600; white-space: nowrap;
}

/* charts */
.chart-grid { display: grid; grid-template-columns: minmax(0, 58fr) minmax(0, 42fr); gap: 12px; }
.chart-box { width: 100%; height: 320px; padding: 4px 6px 0; position: relative; z-index: 0; }
.chart-box-short { height: 288px; }
.chart-box-mini { height: 150px; }
.chart-foot {
  font-size: 10.5px; color: var(--ink-2); margin: 0; padding: 6px 14px 10px;
  border-top: 1px dashed var(--border);
}
.chart-state {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px; text-align: center;
  color: var(--ink-2); font-size: 12px; padding: 20px; background: #FAFBFC; border-radius: 4px;
}
.chart-state .code { font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--red); }

/* row 4 */
.row4 { display: grid; grid-template-columns: 1.25fr 1fr 1fr; gap: 12px; align-items: stretch; }
.hist-panel { display: flex; flex-direction: column; }
.stat-row { display: flex; gap: 16px; padding: 10px 14px 0; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; }
.stat b { font-size: 20px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.stat i { font-style: normal; font-size: 10.5px; color: var(--ink-2); }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 12px 14px 0; }
.stat-cell { border: 1px solid var(--border); border-radius: 4px; padding: 8px 10px; background: #FAFBFC; }
.stat-cell b { display: block; font-size: 18px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.stat-cell i { font-style: normal; font-size: 10px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; }
.row4-note { font-size: 10.5px; color: var(--ink-2); margin: -4px 0 0; padding: 0 2px; }

/* table */
.table-scroll { overflow-x: auto; }
.comp-table { width: 100%; border-collapse: collapse; font-size: 12px; min-width: 720px; }
.comp-table th {
  position: sticky; top: 0; background: #F3F6F9; z-index: 2;
  text-align: left; font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--ink-2);
  padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.comp-table th.num, .comp-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.comp-table th.sortable { cursor: pointer; user-select: none; }
.comp-table th.sortable:hover { color: var(--navy); }
.comp-table th.sortable::after { content: " ↕"; opacity: 0.45; font-size: 10px; }
.comp-table th.sorted-asc::after { content: " ↑"; opacity: 1; color: var(--navy); }
.comp-table th.sorted-desc::after { content: " ↓"; opacity: 1; color: var(--navy); }
.comp-table td { padding: 7px 12px; border-bottom: 1px solid var(--border); }
.comp-table tbody tr:hover { background: #F7F9FB; }
.comp-table tr.hit { background: #FDF3F3; box-shadow: inset 3px 0 0 var(--red); }
.comp-table tr.hit:hover { background: #FBEDED; }
.comp-table tr.is-sparse { color: var(--ink-2); }
.comp-table tr.is-selected-row { background: #EEF4F8; box-shadow: inset 3px 0 0 var(--navy); }
td .na { color: var(--ink-2); font-family: var(--mono); font-size: 11px; }
td .sparse-tag {
  font-family: var(--mono); font-size: 9px; text-transform: uppercase;
  color: var(--amber-ink); background: var(--amber-bg); border: 1px solid var(--amber-line);
  border-radius: 3px; padding: 0 4px; margin-left: 6px;
}
.table-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 14px; flex-wrap: wrap;
}
#tablePagerInfo { font-size: 11px; color: var(--ink-2); }
.pager { display: flex; gap: 4px; }
.pager button {
  min-width: 26px; height: 26px; border: 1px solid var(--border-2); border-radius: 4px;
  background: transparent; cursor: pointer; font-size: 11.5px; color: var(--ink-2);
}
.pager button:hover:not([disabled]) { background: #EEF2F6; color: var(--navy); }
.pager button[disabled] { opacity: 0.4; cursor: default; }
.pager button.cur { background: var(--navy); color: #fff; border-color: var(--navy); }
.search-input { width: 180px; }
.panel-actions .search-input { background-color: #fff; color: var(--ink); border-color: var(--border-2); }

/* analysis modules */
.module { margin-bottom: 0; }
.cmp-maps { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 12px 14px 0; }
.cmp-map-title { margin: 0 0 6px; font-size: 11.5px; font-weight: 700; color: var(--navy); }
.cmp-map { height: 420px; border: 1px solid var(--border); border-radius: 4px; background: #EDF1F5; position: relative; z-index: 0; }
.cmp-bottom { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 12px; padding: 12px 14px 0; }
.cmp-stats { font-size: 12px; }
.cmp-stats .cs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.cs-cell { border: 1px solid var(--border); border-radius: 4px; padding: 7px 9px; background: #FAFBFC; }
.cs-cell b { display: block; font-size: 16px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.cs-cell i { font-style: normal; font-size: 10px; color: var(--ink-2); }
.cmp-scatter { height: 340px; }
.seg { display: inline-flex; border: 1px solid var(--border-2); border-radius: 4px; overflow: hidden; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg span {
  display: block; padding: 5px 11px; font-size: 11.5px; font-weight: 600;
  color: var(--ink-2); cursor: pointer; background: #fff;
}
.seg input:checked + span { background: var(--navy); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--focus); }

/* module B */
.evo-body { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 12px; padding: 12px 14px 0; }
.evo-map-wrap { position: relative; }
.evo-map { height: 470px; border: 1px solid var(--border); border-radius: 4px; background: #EDF1F5; position: relative; z-index: 0; }
.evo-side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.evo-legend { border: 1px solid var(--border); border-radius: 4px; padding: 10px 12px; background: #FAFBFC; }
.evo-controls { gap: 6px; }
.evo-date { font-size: 12px; font-weight: 600; min-width: 82px; text-align: center; }
.evo-timeline { height: 150px; padding: 2px; }
.evo-slider { width: calc(100% - 28px); margin: 14px 14px 2px; }
.evo-slider[disabled] { opacity: 0.5; }

/* downloads */
.downloads { padding: 6px 14px 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dl-card {
  border: 1px solid var(--border); border-radius: 5px; padding: 11px 13px;
  display: flex; flex-direction: column; gap: 5px; background: #FAFBFC;
}
.dl-title { font-size: 12.5px; font-weight: 700; color: var(--navy); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dl-desc { font-size: 11.5px; color: var(--ink-2); }
.dl-meta { font-family: var(--mono); font-size: 10px; color: var(--ink-2); }
.dl-actions { display: flex; gap: 7px; margin-top: 3px; flex-wrap: wrap; }
.dl-group-title {
  grid-column: 1 / -1; font-size: 10px; font-weight: 700; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--ink-2); margin: 8px 0 -4px;
}
.cite-box {
  grid-column: 1 / -1; border: 1px dashed var(--border-2); border-radius: 5px;
  background: #fff; padding: 10px 12px; font-family: var(--mono); font-size: 11px;
  color: var(--ink); white-space: pre-wrap; word-break: break-word;
}

/* footer */
.app-footer {
  margin-top: 4px; background: var(--navy); color: #B7C4D2;
  border-radius: var(--radius) var(--radius) 0 0; padding: 22px 22px 14px;
}
.footer-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 26px; }
.footer-title { font-size: 14px; font-weight: 700; color: #fff; letter-spacing: 0.02em; margin-bottom: 8px; }
.footer-title-sm {
  font-size: 10px; font-weight: 700; letter-spacing: 0.11em; text-transform: uppercase;
  color: #8FA3BA; margin-bottom: 5px;
}
.footer-text { font-size: 12px; margin: 0 0 8px; }
.footer-author { font-size: 13px; font-weight: 600; color: #E6EDF4; margin: 0 0 8px; }
.footer-role { font-weight: 400; font-size: 11.5px; color: #9DAEC0; }
.footer-domains { font-size: 11px; color: #8FA3BA; margin: 0 0 12px; letter-spacing: 0.02em; }
.footer-links { display: flex; flex-wrap: wrap; gap: 5px 14px; }
.footer-links a { color: #9FC2D6; font-size: 12px; text-decoration: none; border-bottom: 1px solid #3D5570; }
.footer-links a:hover { color: #fff; border-bottom-color: #9FC2D6; }
.footer-disclaimer { font-size: 11px; line-height: 1.55; color: #9DAEC0; margin: 0; }
.footer-bottom {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--navy-line);
  font-family: var(--mono); font-size: 10px; color: #7E93AB;
}

/* modals — above Leaflet panes (z 400–1000) and Plotly modebars */
.modal-scrim {
  position: fixed; inset: 0; z-index: 1200;
  background: rgba(14, 27, 44, 0.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 16px; overflow-y: auto;
}
.modal {
  background: var(--panel); border-radius: 8px; width: 100%; max-width: 640px;
  box-shadow: 0 18px 50px rgba(14, 27, 44, 0.35); margin-bottom: 5vh;
}
.modal-wide { max-width: 880px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--panel); border-radius: 8px 8px 0 0; z-index: 2;
}
.modal-head h2 { margin: 0; font-size: 15px; font-weight: 700; color: var(--navy); }
.modal-close { font-size: 18px; width: 34px; height: 34px; }
.modal-body { padding: 16px 18px 20px; font-size: 13px; }
.modal-body h3 {
  font-size: 12px; font-weight: 700; color: var(--navy);
  letter-spacing: 0.04em; text-transform: uppercase; margin: 18px 0 6px;
}
.modal-body h3:first-child { margin-top: 0; }
.modal-body p { margin: 0 0 10px; }
.modal-body .lead { font-size: 14px; color: var(--ink); }
.modal-body ol, .modal-body ul { margin: 0 0 10px; padding-left: 20px; }
.meth-table { width: 100%; border-collapse: collapse; font-size: 11.5px; margin: 6px 0 12px; }
.meth-table th {
  text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-2); padding: 5px 9px; background: #F3F6F9; border: 1px solid var(--border);
}
.meth-table td { padding: 4px 9px; border: 1px solid var(--border); }
.meth-table .sw { display: inline-block; width: 16px; height: 10px; border-radius: 2px; border: 1px solid rgba(0,0,0,0.15); margin-right: 7px; vertical-align: baseline; }
.src-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.src-table td { padding: 6px 9px; border-bottom: 1px solid var(--border); vertical-align: top; }
.src-table td:first-child { font-weight: 600; white-space: nowrap; }
.src-table a { color: var(--wet); text-decoration: none; border-bottom: 1px solid #B9D2E0; word-break: break-all; }
.validation-report { font-family: var(--mono); font-size: 11px; }
.validation-report .vr-ok { color: var(--ok); }
.validation-report .vr-warn { color: var(--red); }
.validation-report ul { margin: 6px 0; padding-left: 18px; }
.validation-report li { margin-bottom: 2px; }

/* toasts */
.toast-stack {
  position: fixed; right: 16px; bottom: 16px; z-index: 1300;
  display: flex; flex-direction: column; gap: 8px; max-width: 340px;
}
.toast {
  background: var(--navy); color: #E6EDF4; border-radius: 5px;
  border-left: 3px solid var(--wet); padding: 10px 14px; font-size: 12px;
  box-shadow: 0 8px 24px rgba(14, 27, 44, 0.35); display: flex; gap: 9px; align-items: flex-start;
}
.toast.warn { border-left-color: var(--mild); }
.toast.error { border-left-color: var(--red); }
.toast .t-title { font-weight: 700; margin-bottom: 2px; }
.toast .t-body { font-size: 11.5px; color: #C0CCDA; }
.toast button {
  margin-left: auto; background: none; border: 0; color: #8FA3BA;
  cursor: pointer; font-size: 14px; line-height: 1; padding: 0;
}

/* boot overlay */
.boot-overlay {
  position: fixed; inset: 0; z-index: 1400; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.boot-overlay.is-hidden { display: none; }
.boot-card { text-align: center; max-width: 380px; padding: 20px; }
.boot-title {
  font-size: 15px; font-weight: 700; color: var(--navy);
  text-transform: uppercase; letter-spacing: 0.09em; margin-top: 12px;
}
.boot-status { font-size: 12px; color: var(--ink-2); margin: 6px 0 14px; min-height: 18px; }
.boot-bar { height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; }
.boot-bar-fill { height: 100%; width: 0%; background: var(--wet); transition: width 0.25s; }
.boot-error { color: var(--red); font-size: 12.5px; }

/* leaflet tweaks */
.leaflet-container { font-family: var(--font); font-size: 12px; }
.die-tooltip {
  background: var(--navy-3); color: #E6EDF4; border: 0; border-radius: 5px;
  padding: 7px 10px; box-shadow: 0 6px 18px rgba(14, 27, 44, 0.4); font-size: 11.5px;
}
.die-tooltip .tt-name { font-weight: 700; font-size: 12.5px; }
.die-tooltip .tt-state { color: #8FA3BA; font-size: 10.5px; margin-bottom: 4px; }
.die-tooltip .tt-row { display: flex; justify-content: space-between; gap: 14px; }
.die-tooltip .tt-k { color: #9DAEC0; }
.die-tooltip .tt-v { font-family: var(--mono); font-weight: 600; }
.leaflet-popup-content-wrapper { border-radius: 6px; }
.die-popup { font-size: 12px; min-width: 240px; }
.die-popup .p-name { font-size: 14px; font-weight: 700; color: var(--navy); }
.die-popup .p-state { color: var(--ink-2); font-size: 11.5px; margin-bottom: 7px; }
.die-popup table { border-collapse: collapse; width: 100%; }
.die-popup td { padding: 2.5px 6px 2.5px 0; border-bottom: 1px dashed var(--border); }
.die-popup td:last-child { text-align: right; font-family: var(--mono); font-weight: 600; white-space: nowrap; }
.die-popup td.p-k { color: var(--ink-2); font-size: 11px; }
.die-popup .p-note { font-size: 10px; color: var(--ink-2); margin-top: 6px; }
.map-label {
  color: #44576D; font-size: 10px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; text-shadow: 0 0 3px #fff, 0 0 6px #fff;
  pointer-events: none; white-space: nowrap;
}
.map-label.district { font-size: 8.5px; color: #687588; text-transform: none; letter-spacing: 0.02em; font-weight: 500; }

/* scrim for mobile drawer */
.scrim {
  position: fixed; inset: 0; z-index: 1400; background: rgba(14, 27, 44, 0.45);
}

/* ------------------------------------------------------------- responsive */
@media (max-width: 1280px) {
  .map-body { grid-template-columns: minmax(0, 1fr) 280px; }
  #map { height: 520px; }
  .map-rail { max-height: 520px; }
}
@media (max-width: 1100px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
  .row4 { grid-template-columns: 1fr 1fr; }
  .row4 #freqPanel { grid-column: 1 / -1; }
  .topbar-status { display: none; }
  .status-clone { display: flex !important; }
}
@media (max-width: 1024px) {
  .nav-toggle { display: inline-flex; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 1500;
    height: 100%; width: min(320px, 86vw);
    transform: translateX(-102%); transition: transform 0.2s ease;
    box-shadow: 0 0 40px rgba(14, 27, 44, 0.4);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-close { display: inline-flex; }
  .layout { display: block; }
  .workspace { padding: 12px 12px 0; }
  .map-body { grid-template-columns: 1fr; }
  .map-rail { max-height: none; border-left: 0; border-top: 1px solid var(--border); }
  .cmp-maps, .cmp-bottom, .evo-body { grid-template-columns: 1fr; }
  .downloads { grid-template-columns: 1fr; }
  .footer-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  body { font-size: 13px; }
  .topbar { gap: 10px; padding: 0 12px; }
  .brand-sub { display: none; }
  .brand-title { font-size: 12px; }
  .topnav button { padding: 7px 7px; font-size: 11.5px; }
  .demo-banner { flex-direction: column; align-items: flex-start; gap: 2px; padding: 5px 12px; }
  .kpi-row { grid-template-columns: 1fr; }
  #map { height: 400px; }
  .cmp-map, .evo-map { height: 340px; }
  .chart-box { height: 260px; }
  .row4 { grid-template-columns: 1fr; }
  .workspace { padding: 10px 10px 0; }
  .panel-actions { width: 100%; }
  .tabs { padding: 0 2px; }
  .tabs button { padding: 9px 11px; }
  .footer-bottom { flex-direction: column; gap: 3px; }
}
@media print {
  .topbar, .sidebar, .demo-banner, .tabs, .toast-stack, .panel-actions { display: none !important; }
  .layout { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
