/* Northern Virginia Climate Resilience Atlas - application styles.
   All colors, spacing, and type live in :root variables. Light mode keeps
   the original values; dark mode overrides under [data-theme="dark"].
   Breakpoints: 640px (mobile) and 1280px (laptop/desktop). */

:root {
  /* Color tokens (light) */
  --ink: #1a2733;
  --ink-soft: #465664;
  --ink-faint: #5f7080;
  --paper: #ffffff;
  --paper-dim: #f4f6f8;
  --line: #dde4ea;
  --accent: #0f6e84;
  --accent-soft: #e3f0f3;
  --accent-contrast: #ffffff;
  --warn: #b3541e;
  --focus: #1d4ed8;
  --map-bg: #cfe0e8;
  --danger: #b3261e;
  --shadow: 0 2px 10px rgba(16, 32, 48, 0.14);
  --scrim: rgba(16, 32, 48, 0.45);
  --label-halo: #ffffff;

  /* Scrollbars */
  --sb-track: #eef1f4;
  --sb-thumb: #c0ccd6;
  --sb-thumb-hover: #9daebc;

  /* Type scale */
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --fs-0: 0.75rem;
  --fs-1: 0.8125rem;
  --fs-2: 0.9375rem;
  --fs-3: 1.0625rem;
  --fs-4: 1.25rem;

  /* Spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;

  --radius: 8px;
  --topbar-h: 52px;
  --panel-w: 360px;
}

html[data-theme="dark"] {
  --ink: #e8eef4;
  --ink-soft: #b9c6d1;
  --ink-faint: #97a7b5;
  --paper: #1b232c;
  --paper-dim: #131a21;
  --line: #303d49;
  --accent: #4fc0da;
  --accent-soft: #103741;
  --accent-contrast: #0c1418;
  --warn: #e8a266;
  --focus: #7ab3ff;
  --map-bg: #10161c;
  --danger: #ff8d85;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  --scrim: rgba(0, 0, 0, 0.55);
  --label-halo: #10161c;

  --sb-track: #151d25;
  --sb-thumb: #3a4855;
  --sb-thumb-hover: #536777;
}

/* ---------- Scrollbars (follow the theme) ---------- */

/* Firefox + any engine that implements the standard properties. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--sb-thumb) var(--sb-track);
}

/* WebKit/Blink. `color-scheme` alone would give a generic dark bar; these
   rules keep the bar on the same palette as the panels it scrolls. */
::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}

::-webkit-scrollbar-track {
  background: var(--sb-track);
}

::-webkit-scrollbar-thumb {
  background: var(--sb-thumb);
  border-radius: 999px;
  /* Inset the thumb so the track reads as a gutter, not a second bar. */
  border: 2px solid var(--sb-track);
}

::-webkit-scrollbar-thumb:hover { background: var(--sb-thumb-hover); }
::-webkit-scrollbar-corner { background: var(--sb-track); }

/* Form controls and native UI (date pickers, select dropdowns) pick their
   own light/dark rendering from this. */
html[data-theme="dark"] { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 16px;
  color: var(--ink);
  background: var(--paper-dim);
}

/* ---------- Top bar ---------- */

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 1200;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}

/* Virginia outline + flood-warning mark. The artwork is a white-filled state
   with black strokes, so it reads on both themes without inversion. */
.topbar-mark {
  height: 22px;
  width: auto;
  flex: none;
  display: block;
}

.topbar h1 {
  font-size: var(--fs-3);
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.beta-chip {
  font-size: var(--fs-0);
  font-weight: 600;
  color: var(--warn);
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 1px 8px;
  flex: none;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex: none;
}

.topbar-nav a {
  color: var(--accent);
  text-decoration: none;
  font-size: var(--fs-2);
  padding: var(--sp-2);
}

.topbar-nav a:hover, .topbar-nav a:focus-visible { text-decoration: underline; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0;
}

.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.icon-btn svg { width: 20px; height: 20px; }

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

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.seg button {
  font: var(--fs-1) var(--font);
  padding: 6px 12px;
  border: 0;
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
  min-height: 36px;
  touch-action: manipulation;
}

.seg button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-contrast);
}

.mode-seg button { font-weight: 600; padding: 6px 14px; }

/* ---------- Shell layout ---------- */

.shell {
  position: relative;
  height: calc(100% - var(--topbar-h));
  display: flex;
}

#map {
  flex: 1;
  height: 100%;
  background: var(--map-bg);
}

/* ---------- Side panel ---------- */

.panel {
  width: var(--panel-w);
  flex: none;
  background: var(--paper);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 1100;
}

.panel-scroll {
  overflow-y: auto;
  padding: var(--sp-4);
  flex: 1;
}

.panel[hidden] { display: none; }

.panel-section { margin-bottom: var(--sp-5); }

.panel-section h2 {
  font-size: var(--fs-1);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin: 0 0 var(--sp-3);
}

.panel-toggle {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  z-index: 1150;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 14px;
  font: 600 var(--fs-2) var(--font);
  color: var(--ink);
  cursor: pointer;
  min-height: 44px;
  display: none;
}

.mode-intro {
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-2);
  line-height: 1.45;
  color: var(--ink);
  margin-bottom: var(--sp-4);
}

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

.layer-group {
  margin-bottom: var(--sp-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.group-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  border: 0;
  background: var(--paper-dim);
  color: var(--ink);
  font: 600 var(--fs-2) var(--font);
  padding: 10px var(--sp-3);
  cursor: pointer;
  min-height: 44px;
  text-align: left;
}

.group-icon { display: inline-flex; flex: none; }
.group-icon svg { width: 18px; height: 18px; }

.group-title { flex: 1; }

.group-count {
  font-size: var(--fs-0);
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: 999px;
  min-width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  flex: none;
}

.group-chevron { display: inline-flex; flex: none; color: var(--ink-faint); }
.group-chevron svg { width: 16px; height: 16px; transition: transform 0.15s; }
.group-header[aria-expanded="false"] .group-chevron svg { transform: rotate(-90deg); }

.group-body { padding: var(--sp-1) var(--sp-3) var(--sp-2); }

.layer-icon {
  display: inline-flex;
  flex: none;
  color: var(--ink-faint);
  margin-right: var(--sp-2);
  vertical-align: middle;
}
.layer-icon svg { width: 17px; height: 17px; }

.layer-row input:checked + label .layer-icon { color: var(--accent); }

.layer-title-text { vertical-align: middle; }

.group-swatch {
  width: 10px; height: 10px;
  border-radius: 3px;
  flex: none;
}

.layer-row {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: 6px 0;
}

.layer-row label {
  font-size: var(--fs-2);
  line-height: 1.35;
  cursor: pointer;
}

.layer-row input[type="checkbox"] {
  width: 18px; height: 18px;
  margin: 2px 0 0;
  accent-color: var(--accent);
  cursor: pointer;
  flex: none;
}

.layer-row.unavailable { opacity: 0.45; }

.layer-note {
  display: block;
  font-size: var(--fs-0);
  color: var(--ink-faint);
}

.layer-sub {
  margin: 2px 0 var(--sp-2) 26px;
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
}

.layer-sub select,
.style-editor select {
  font: var(--fs-1) var(--font);
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  max-width: 100%;
}

/* ---------- Legend (panel) ---------- */

.legend-block { margin-bottom: var(--sp-3); }

.legend-block h4 {
  font-size: var(--fs-1);
  margin: 0 0 var(--sp-1);
  font-weight: 600;
  color: var(--ink);
}

.legend-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-1);
  color: var(--ink-soft);
  padding: 1px 0;
}

.legend-swatch {
  width: 16px; height: 12px;
  border-radius: 3px;
  border: 1px solid var(--scrim);
  flex: none;
}

.legend-swatch.point { border-radius: 50%; width: 12px; }

/* ---------- On-map widget: active layers + legend ---------- */

.map-widget {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 280px;
  max-height: 55vh;
  overflow-y: auto;
  font: var(--fs-1) var(--font);
  color: var(--ink);
}

.map-widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  cursor: pointer;
  font-weight: 600;
  background: none;
  border: 0;
  width: 100%;
  color: var(--ink);
  font-size: var(--fs-1);
  min-height: 40px;
}

.map-widget-header svg { width: 16px; height: 16px; flex: none; transition: transform 0.15s; }
.map-widget.collapsed .map-widget-header svg { transform: rotate(-90deg); }
.map-widget.collapsed .map-widget-body { display: none; }
.map-widget-body { padding: 0 var(--sp-3) var(--sp-3); }

.mw-layer { border-top: 1px solid var(--line); padding: var(--sp-2) 0; }

.mw-layer-head {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.mw-layer-title {
  flex: 1;
  font-weight: 600;
  font-size: var(--fs-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mw-actions { display: flex; gap: 2px; opacity: 0; transition: opacity 0.12s; }
.mw-layer-head:hover .mw-actions,
.mw-layer-head:focus-within .mw-actions { opacity: 1; }

.mw-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 0;
}
.mw-btn:hover { background: var(--paper-dim); color: var(--accent); }
.mw-btn.remove:hover { color: var(--danger); }
.mw-btn svg { width: 15px; height: 15px; }

.mw-legend { margin-top: 2px; }

/* ---------- Style editor ---------- */

.style-editor {
  margin-top: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: var(--paper-dim);
  border-radius: var(--radius);
  display: grid;
  gap: var(--sp-2);
}

.style-editor label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  font-size: var(--fs-0);
  color: var(--ink-soft);
}

.style-editor input[type="color"] {
  width: 36px; height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px;
  background: var(--paper);
  cursor: pointer;
}

.style-editor input[type="range"] { width: 120px; accent-color: var(--accent); }

.style-editor .se-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); }

.se-revert {
  font: var(--fs-0) var(--font);
  color: var(--accent);
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  min-height: 28px;
}
.se-revert:hover { border-color: var(--accent); }

/* ---------- Mobile style editor: bottom sheet ---------- */

.style-sheet-overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 2300;
  display: flex;
  align-items: flex-end;
}

.style-sheet {
  width: 100%;
  background: var(--paper);
  color: var(--ink);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -4px 18px var(--scrim);
  padding: var(--sp-3) var(--sp-4) calc(var(--sp-5) + env(safe-area-inset-bottom, 0px));
}

.style-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}
.style-sheet-head h3 { margin: 0; font-size: var(--fs-3); }

/* Roomier controls than the 200px map-widget editor. */
.style-sheet .style-editor { background: none; padding: 0; gap: var(--sp-3); }
.style-sheet .style-editor label { font-size: var(--fs-2); min-height: 44px; }
.style-sheet .style-editor input[type="color"] { width: 56px; height: 40px; }
.style-sheet .style-editor input[type="range"] { width: min(60vw, 240px); }
.style-sheet .se-revert { min-height: 40px; padding: 8px 14px; }

/* ---------- Basemap switcher (top-left, under zoom) ---------- */

.basemap-widget {
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border-radius: var(--radius);
  overflow: hidden;
}

.bm-btn {
  font: 600 var(--fs-0) var(--font);
  padding: 7px 10px;
  min-width: 92px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
  text-align: left;
}
.bm-btn:last-child { border-bottom: 0; }
.bm-btn:hover { color: var(--accent); }
.bm-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-contrast);
}

@media (max-width: 640px) {
  .bm-btn { min-width: 74px; padding: 8px; }
}

/* ---------- Hover info box ---------- */

.hover-box {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--sp-2) var(--sp-3);
  max-width: 280px;
  font: var(--fs-1) var(--font);
  color: var(--ink);
  pointer-events: none;
}

.hover-box[hidden] { display: none; }
.hover-box .popup h3 { margin: 0 0 2px; font-size: var(--fs-1); }
.hover-box .popup td { padding: 1px 6px 1px 0; font-size: var(--fs-0); }

/* ---------- Map text labels ---------- */

.map-label {
  background: none;
  border: 0;
  box-shadow: none;
  pointer-events: none;
  color: var(--ink);
  text-shadow:
    -1px -1px 0 var(--label-halo), 1px -1px 0 var(--label-halo),
    -1px 1px 0 var(--label-halo), 1px 1px 0 var(--label-halo),
    0 0 4px var(--label-halo);
  white-space: nowrap;
  transform: translate(-50%, -50%);
  width: max-content !important;
  font-family: var(--font);
}

.map-label.county {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.map-label.city { font-size: 12.5px; font-weight: 600; }
.map-label.town { font-size: 11.5px; font-style: italic; color: var(--ink-soft); }

/* ---------- Readout ---------- */

.readout-title { font-size: var(--fs-3); font-weight: 600; margin: 0 0 2px; }
.readout-sub { font-size: var(--fs-1); color: var(--ink-faint); margin: 0 0 var(--sp-3); }

.readout-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.stat {
  background: var(--paper-dim);
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-3);
}

.stat .v { font-size: var(--fs-3); font-weight: 600; display: block; }
.stat .k { font-size: var(--fs-0); color: var(--ink-soft); }

.flag-list { margin: 0; padding: 0; list-style: none; }
.flag-list li {
  font-size: var(--fs-1);
  padding: 4px 0 4px 18px;
  position: relative;
}
.flag-list li::before {
  content: "";
  position: absolute;
  left: 2px; top: 9px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--warn);
}
.flag-list li.ok::before { background: #4b8a3f; }

.muted { color: var(--ink-faint); font-size: var(--fs-1); }

/* ---------- Analytics widget ---------- */

.an-select { width: 100%; margin-bottom: var(--sp-3); font: var(--fs-1) var(--font); padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); color: var(--ink); }
.an-note {
  font-size: var(--fs-0);
  color: var(--ink-faint);
  margin-top: var(--sp-2);
}
.an-note a { color: var(--accent); }

/* ---------- Leaflet overrides (theme-aware) ---------- */

.leaflet-container { font: var(--fs-1) var(--font); background: var(--map-bg); }

.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.leaflet-popup-content { margin: var(--sp-3) var(--sp-4); }

.popup h3 { margin: 0 0 4px; font-size: var(--fs-2); }
.popup table { border-collapse: collapse; }
.popup td { padding: 2px 8px 2px 0; font-size: var(--fs-1); vertical-align: top; }
.popup td:first-child { color: var(--ink-soft); }

.leaflet-bar a, .leaflet-bar a:hover {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--line);
}

.leaflet-control-attribution {
  font-size: 11px;
  background: var(--scrim) !important;
  color: var(--label-halo);
}
html[data-theme="light"] .leaflet-control-attribution,
html:not([data-theme]) .leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.8) !important;
  color: var(--ink-soft);
}
.leaflet-control-attribution a { color: var(--accent); }

a:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- Report builder ---------- */

.rb-launch {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font: 600 var(--fs-2) var(--font);
  padding: 10px var(--sp-3);
  cursor: pointer;
  min-height: 44px;
}
.rb-launch:hover { border-color: var(--accent); color: var(--accent); }
.rb-launch svg { width: 18px; height: 18px; flex: none; }

.report-overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
}

.report-modal {
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(880px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.report-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.report-toolbar h2 { margin: 0; font-size: var(--fs-3); }

.report-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-1);
}

.report-controls select {
  font: var(--fs-1) var(--font);
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
}

.rb-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  color: var(--ink-soft);
  user-select: none;
}
.rb-check input { accent-color: var(--accent); margin: 0; }
.rb-check:has(input:checked) { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.rb-actions { display: flex; gap: var(--sp-2); margin-left: auto; }

.btn {
  font: 600 var(--fs-1) var(--font);
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  min-height: 38px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn:hover { border-color: var(--accent); }

.report-preview {
  overflow-y: auto;
  padding: var(--sp-4) var(--sp-5);
}

.report-doc h1 { font-size: 1.35rem; margin: 0 0 2px; }
.report-doc .rp-sub { color: var(--ink-faint); font-size: var(--fs-1); margin: 0 0 var(--sp-4); }
.report-doc h2 {
  font-size: var(--fs-3);
  margin: var(--sp-5) 0 var(--sp-2);
  padding-bottom: 4px;
  border-bottom: 2px solid var(--accent);
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
}
.report-doc table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--fs-1);
  margin: var(--sp-2) 0;
}
.report-doc th, .report-doc td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
}
.report-doc th { background: var(--paper-dim); }
.report-doc td.num, .report-doc th.num { text-align: right; font-variant-numeric: tabular-nums; }
.report-doc .rp-note { font-size: var(--fs-0); color: var(--ink-faint); }
.report-doc .readout-grid { grid-template-columns: repeat(4, 1fr); }

/* Print: only the report document */
@media print {
  body.print-report > *:not(.report-overlay) { display: none !important; }
  body.print-report .report-overlay { position: static; padding: 0; background: none; }
  body.print-report .report-modal { max-height: none; box-shadow: none; width: 100%; }
  body.print-report .report-toolbar,
  body.print-report .report-controls { display: none !important; }
  body.print-report .report-preview { overflow: visible; padding: 0; }
  body.print-report { background: #fff; }
}

/* ---------- Info window: unified click popup + full-screen modal ---------- */

.info-popup .leaflet-popup-content {
  margin: var(--sp-3) var(--sp-3) var(--sp-3) var(--sp-4);
  width: auto !important;
}

.popup-multi { min-width: 268px; }

.pm-head { display: flex; align-items: flex-start; gap: var(--sp-2); }
.pm-head-text { flex: 1; min-width: 0; }
.pm-head-text h3 { margin: 0 0 2px; }
.pm-head-text .readout-sub { margin: 0; }

.pm-count {
  margin: var(--sp-1) 0 0;
  font-size: var(--fs-0);
  font-weight: 600;
  color: var(--accent);
}

.pm-max {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink-faint);
  cursor: pointer;
  padding: 0;
}
.pm-max:hover { color: var(--accent); border-color: var(--accent); }
.pm-max svg { width: 14px; height: 14px; }

.pm-section {
  border-top: 1px solid var(--line);
  margin-top: var(--sp-2);
  padding-top: var(--sp-2);
}

.pm-sec-head { display: flex; align-items: center; gap: 6px; }
.pm-sec-head h4 { margin: 0; font-size: var(--fs-1); flex: 1; min-width: 0; }
.pm-sec-icon { display: inline-flex; flex: none; color: var(--accent); }
.pm-sec-icon svg { width: 15px; height: 15px; }
.pm-sec-head .pm-max { width: 24px; height: 24px; border: 0; background: none; }

.pm-chart { margin: var(--sp-2) 0 0; }
.pm-chart figcaption {
  font-size: var(--fs-0);
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 2px;
}
.pm-chart svg { color: var(--ink); }

.pm-note { font-size: var(--fs-0); color: var(--ink-faint); margin: 3px 0 0; }
.pm-credit { opacity: 0.85; }

/* Stands in for a chart whose inputs are all missing. */
.pm-nodata {
  background: var(--paper-dim);
  border-radius: 6px;
  padding: var(--sp-2) var(--sp-3);
  font-style: italic;
  margin-top: 2px;
}

.pm-expand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: var(--sp-3);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper-dim);
  color: var(--accent);
  font: 600 var(--fs-1) var(--font);
  cursor: pointer;
  min-height: 38px;
}
.pm-expand:hover { border-color: var(--accent); }
.pm-expand svg { width: 14px; height: 14px; flex: none; }

.info-overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 2100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
}

.info-modal {
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(1040px, 100%);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.info-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.info-toolbar h2 { margin: 0; font-size: var(--fs-4); }
.info-sub { margin: 2px 0 0; font-size: var(--fs-1); color: var(--ink-faint); }
.info-toolbar .btn { display: inline-flex; align-items: center; gap: 6px; }
.info-toolbar .btn svg { width: 15px; height: 15px; }

.info-body {
  overflow-y: auto;
  padding: var(--sp-4);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--sp-3);
  align-items: start;
}

.info-body .pm-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--sp-3);
  margin: 0;
  background: var(--paper);
  break-inside: avoid;
}
.info-body .pm-sec-head h4 { font-size: var(--fs-2); }
.info-body .pm-section.pm-focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

@media (max-width: 640px) {
  .info-overlay { padding: 0; }
  .info-modal {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
  }
  .info-body { grid-template-columns: 1fr; }
}

/* Print: only the location details modal */
@media print {
  body.print-info {
    background: #fff;
    /* Force light tokens so a dark-theme session still prints on white. */
    --ink: #1a2733;
    --ink-soft: #465664;
    --ink-faint: #5f7080;
    --paper: #ffffff;
    --paper-dim: #f4f6f8;
    --line: #dde4ea;
    --accent: #0f6e84;
    --accent-soft: #e3f0f3;
    --scrim: rgba(16, 32, 48, 0.45);
  }
  body.print-info > *:not(.info-overlay) { display: none !important; }
  body.print-info .info-overlay { position: static; padding: 0; background: none; }
  body.print-info .info-modal { max-height: none; box-shadow: none; width: 100%; }
  body.print-info .info-toolbar .rb-actions { display: none !important; }
  body.print-info .info-body { overflow: visible; display: block; }
  body.print-info .info-body .pm-section { margin-bottom: 12px; page-break-inside: avoid; }
}

/* ---------- Touch + motion ---------- */

@media (pointer: coarse) {
  .seg button { min-height: 44px; }
  .layer-sub select { min-height: 44px; }
  .layer-row input[type="checkbox"] { width: 22px; height: 22px; }
  .mw-btn { width: 36px; height: 36px; }
  .mw-actions { opacity: 1; } /* hover is unavailable on touch */
}

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

/* ---------- Mobile (<=640px) ---------- */

@media (max-width: 640px) {
  .topbar h1 { font-size: 12px; }
  .topbar { padding: 0 var(--sp-2); gap: var(--sp-1); }
  .topbar-nav { gap: var(--sp-1); }
  .topbar-nav a { padding: var(--sp-1); font-size: var(--fs-0); }
  .mode-seg button { padding: 6px 8px; font-size: var(--fs-0); }
  .icon-btn { width: 36px; height: 36px; }
  .beta-chip { display: none; }
  /* Keep the mark on mobile — it identifies the app better than the
     truncated title does — just smaller. */
  .topbar-mark { height: 18px; }

  .shell { display: block; }

  .panel-toggle { display: block; }

  .panel {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    width: 100%;
    max-height: 62vh;
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -4px 18px var(--scrim);
  }

  .panel::before {
    content: "";
    display: block;
    width: 42px; height: 4px;
    border-radius: 2px;
    background: var(--line);
    margin: 8px auto 0;
  }

  .map-widget { max-width: 200px; max-height: 38vh; }
}

/* ---------- Laptop (641-1280px): collapsible docked panel ---------- */

@media (min-width: 641px) and (max-width: 1280px) {
  :root { --panel-w: 320px; }
  .panel-toggle { display: block; right: auto; left: var(--sp-3); }
  /* keep the zoom control clear of the Layers toggle */
  .leaflet-top.leaflet-left { margin-top: 60px; }
}
