:root {
  --brand-blue: #015c8f;
  --brand-green: #168f2b;
  --bg-panel: #12181f;
  --bg-panel-2: #1a222b;
  --bg-track: #2f3a44;
  --border: #2a323c;
  --text: #e8e8e8;
  --text-muted: #8b93a0;
  --text-dim: #c7cdd6;
  --ok: #2a9d8f;
  --warn: #f4a261;
  --bad: #e63946;
  --info: #48cae4;
}

* { box-sizing: border-box; }

#errorBanner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 2000;
  background: #7a0d16; color: #fff; font: 12px/1.5 monospace;
  padding: 6px 12px; max-height: 30vh; overflow-y: auto;
  border-bottom: 2px solid #ffb703;
}
#errorBanner[hidden] { display: none; }
#errorBanner div { padding: 1px 0; }
#errorBanner div:first-child::before { content: "⚠ Script error(s) — see browser console for full detail:\A"; white-space: pre; font-weight: bold; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #0c1015;
  color: var(--text);
}

/* ---------- header ---------- */

#appHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 56px;
  padding: 0 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex: none;
}

#wordmark { display: flex; flex-direction: column; justify-content: center; line-height: 1.15; }
#wordmark .brand { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
#wordmark .brand .flood { color: var(--brand-blue); }
#wordmark .brand .trace { color: var(--brand-green); }
#wordmark .subtitle { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

#headerRight { display: flex; align-items: center; gap: 14px; }
#citySelect {
  background: var(--bg-panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
}
#headerRight a {
  color: var(--text-dim);
  font-size: 13px;
  text-decoration: none;
}
#headerRight a:hover { color: #fff; text-decoration: underline; }

/* ---------- city banner ---------- */

#cityBanner {
  flex: none; padding: 6px 16px; font-size: 15px; font-weight: 600;
  color: #fff; background: var(--bg-panel-2); border-bottom: 1px solid var(--border);
}

/* ---------- tabs ---------- */

#tabBar {
  display: flex;
  gap: 2px;
  background: #0c1015;
  border-bottom: 1px solid var(--border);
  flex: none;
  padding: 0 12px;
  overflow-x: auto;
}
.tab-btn {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 13px;
  padding: 10px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: #fff; border-bottom-color: var(--brand-green); }

#appBody { position: relative; flex: 1; min-height: 0; }
.tab-panel { position: absolute; inset: 0; display: none; }
.tab-panel.active { display: block; }

/* ---------- shared map/panel layout ---------- */

.map-container { position: absolute; top: 0; left: 0; right: 340px; bottom: 0; background: #0c1015; }
.side-panel {
  position: absolute; top: 0; right: 0; width: 340px; bottom: 0;
  overflow-y: auto;
  background: var(--bg-panel); color: var(--text);
  padding: 14px 16px; font-size: 13px; border-left: 1px solid var(--border);
}
.side-panel h2 { font-size: 15px; margin: 2px 0 10px; }
.side-panel h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin: 16px 0 6px; }
.side-panel h3:first-of-type { margin-top: 0; }
.side-panel p { line-height: 1.45; }
.side-panel select, .side-panel button {
  width: 100%; background: var(--bg-panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; font-size: 13px;
  margin-bottom: 8px; cursor: pointer;
}
.side-panel button:hover { border-color: var(--brand-green); }
.side-panel label { display: block; margin: 5px 0; cursor: pointer; font-size: 13px; }
.side-panel .row-flex { display: flex; gap: 8px; }
.side-panel .row-flex > * { flex: 1; }

.score-big { font-size: 17px; font-weight: 700; line-height: 1.3; }
.bar-label { font-size: 12px; color: var(--text-dim); text-transform: capitalize; }
.bar-track { background: var(--bg-track); height: 9px; border-radius: 5px; overflow: hidden; margin: 2px 0 8px; }
.bar-fill { height: 100%; }
.bar-pct { font-size: 11px; color: var(--text-muted); margin-top: -6px; margin-bottom: 8px; }
.hint { color: var(--text-muted); font-size: 11px; margin: 0 0 10px; }
.scenario-description { color: var(--text-dim); font-size: 12.5px; line-height: 1.4; margin: 0 0 2px; }
.muted { color: var(--text-muted); font-size: 12px; margin-top: 12px; }
.side-panel ul { margin: 0; padding-left: 18px; }
.side-panel li { margin-bottom: 6px; line-height: 1.4; }
.stat-row { display: flex; justify-content: space-between; font-size: 12.5px; padding: 3px 0; border-bottom: 1px dotted var(--border); }
.stat-row b { color: #fff; }
.chip { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 10px; background: var(--bg-track); color: var(--text-dim); margin: 2px 3px 2px 0; }
.chip.yes { background: rgba(42,157,143,.25); color: #9be3d8; }
.chip.no { background: rgba(230,57,70,.25); color: #f3aab0; }
.chip.unknown { background: var(--bg-track); color: var(--text-muted); }

/* ---------- floating overlays (toolbar/legend/what-is) ---------- */

/* Floating map overlays (toolbar/legend/mitigation/water-banner) all sit at
   the same tier, comfortably above Leaflet's own control-container z-index
   (1000) — a sibling `.map-container` with position:absolute but no z-index
   of its own doesn't establish a stacking context, so Leaflet's internal
   layers would otherwise be free to paint over these regardless of DOM
   order. Reserve 1800+ for the true modal dialogs (.info-modal) below. */
.floating-toolbar {
  position: absolute; top: 10px; left: 10px; z-index: 1100;
  background: rgba(18,24,31,.92); color: var(--text);
  padding: 10px 12px; border-radius: 8px; font-size: 13px; max-width: 240px;
}
.floating-toolbar label { display: block; margin: 4px 0; cursor: pointer; }
.floating-toolbar select {
  width: 100%; max-width: 100%; margin-bottom: 8px; font-size: 12px;
  text-overflow: ellipsis; overflow: hidden; white-space: nowrap;
}
.floating-toolbar button {
  margin-top: 6px; background: #2a2f38; color: #eee; border: 1px solid #454c58;
  border-radius: 5px; padding: 4px 8px; font-size: 12px; cursor: pointer; width: 100%;
}

#legend, .legend-panel {
  position: absolute; bottom: 14px; left: 10px; z-index: 1100;
  background: rgba(18,24,31,.92); color: var(--text);
  padding: 10px 12px; border-radius: 8px; font-size: 12px; max-width: 260px;
  max-height: calc(100% - 28px); overflow-y: auto;
}
#legend h4, .legend-panel h4 { margin: 10px 0 6px; font-size: 12px; }
#legend h4:first-child, .legend-panel h4:first-child { margin-top: 0; }
#legend .row, .legend-panel .row { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
#legend .sw, .legend-panel .sw { width: 12px; height: 12px; border-radius: 50%; flex: none; }
#legend .sw.line, .legend-panel .sw.line { border-radius: 2px; width: 16px; height: 4px; }
.info-icon { cursor: help; color: var(--text-muted); font-size: 12px; border-bottom: 1px dotted var(--text-muted); }
.info-icon:hover, .info-icon:focus { color: #fff; }

.floating-toolbar label.disabled { color: #5a626e; cursor: not-allowed; }
.floating-toolbar .tb-hint { font-size: 11px; color: var(--text-muted); margin: 0 0 6px; line-height: 1.35; }

.what-is-box {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 1100;
  background: #fff; color: #1c2430; padding: 14px 18px; border-radius: 8px; max-width: 480px;
  box-shadow: 0 4px 20px rgba(0,0,0,.4); font-size: 13px; line-height: 1.45;
}
.what-is-box h3 { margin: 0 0 6px; font-size: 14px; }
.what-is-box button.close-x { position: absolute; top: 6px; right: 8px; border: none; background: none; font-size: 16px; cursor: pointer; }

/* True modal dialogs ("What this is / isn't") — centred on the *viewport*
   (not the tab-panel, so no side-panel or mobile layout can ever cover
   them), the highest z-index in the app, and a close button on a
   non-scrolling outer box so it's always reachable regardless of how long
   the content is — plus Esc-to-close, wired in main.js. */
.info-modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 1800; display: flex; flex-direction: column;
  max-height: calc(100vh - 40px); max-width: min(480px, calc(100vw - 32px));
}
.info-modal .close-x { position: absolute; top: 6px; right: 8px; z-index: 1; }
.info-modal .info-modal-content { overflow-y: auto; padding-right: 4px; }

.about-btn {
  background: rgba(18,24,31,.9); color: #eee; border: 1px solid #454c58;
  border-radius: 6px; padding: 6px 10px; font-size: 12px; cursor: pointer; margin-top: 6px;
}

/* ---------- attribution footer ---------- */

#appFooter {
  flex: none; height: 30px; line-height: 30px; background: #0c1015;
  color: var(--text-muted); font-size: 11.5px;
  border-top: 1px solid var(--border); padding: 0 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.link-btn {
  background: none; border: none; color: var(--text-dim); font-size: 11.5px;
  cursor: pointer; padding: 0; text-decoration: underline;
}
.link-btn:hover { color: #fff; }
.credits-list { margin: 0; padding-left: 18px; font-size: 12.5px; line-height: 1.6; color: #33404f; }

/* ---------- app shell (flex column: header, tabs, body, footer) ---------- */

#app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- Leaflet popup readability on dark UI ---------- */

.leaflet-popup-content { font-size: 12.5px; line-height: 1.4; }
.leaflet-popup-content b { display: block; margin-bottom: 3px; }
.ok-mark { color: var(--ok); font-weight: 700; }
.no-mark { color: var(--bad); font-weight: 700; }
.unk-mark { color: var(--text-muted); font-weight: 700; }

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 1600;
  display: flex; align-items: center; justify-content: center;
}
.modal-backdrop[hidden] { display: none; }
.modal-box {
  background: #fff; color: #1c2430; max-width: 560px; width: calc(100% - 40px);
  max-height: calc(100% - 60px); overflow-y: auto; border-radius: 10px;
  padding: 22px 24px; box-shadow: 0 10px 40px rgba(0,0,0,.5); position: relative;
}
.modal-box h2 { margin: 0 0 4px; font-size: 18px; }
.modal-box .modal-sub { color: #55606e; font-size: 12.5px; margin: 0 0 16px; }
.modal-box button.close-x { position: absolute; top: 10px; right: 12px; border: none; background: none; font-size: 18px; cursor: pointer; }
.fund-card { border: 1px solid #dfe3e8; border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.fund-card h4 { margin: 0 0 4px; font-size: 13.5px; }
.fund-card .meta { font-size: 11.5px; color: #6b7684; margin-bottom: 6px; }
.fund-card p { margin: 0; font-size: 12.5px; line-height: 1.4; }
.modal-footer { font-size: 11.5px; color: #8a93a0; text-align: center; margin-top: 14px; font-style: italic; }

/* ---------- mitigation panel ---------- */

.mitigation-box {
  position: absolute; top: 150px; right: 356px; z-index: 1100; width: 300px;
  background: var(--bg-panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 14px; font-size: 12.5px; max-height: calc(100% - 160px); overflow-y: auto;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.mitigation-box[hidden] { display: none; }
.mitigation-box h3 { margin: 0 0 4px; font-size: 13.5px; }
.mitigation-box .seg-meta { color: var(--text-muted); font-size: 11.5px; margin-bottom: 10px; }
.mit-idea { border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; }
.mit-idea h4 { margin: 0 0 2px; font-size: 12.5px; }
.mit-idea .cost { color: var(--warn); font-size: 11.5px; }
.mit-idea .cba { color: var(--text-muted); font-size: 11px; margin-top: 3px; }
.partners { font-size: 11.5px; color: var(--text-muted); }
.partners li { list-style: none; margin-bottom: 3px; }

/* ---------- water balance tab ---------- */

/* Banner across the top of the map itself — not a centred overlay box, so
   it can never look like "just a map" with the message missing/hidden
   behind it; the same text is repeated in the side-panel per-tab
   convention (see .side-panel above). */
.water-banner {
  position: absolute; top: 0; left: 0; right: 340px; z-index: 1100;
  background: rgba(18,24,31,.94); color: var(--text);
  padding: 10px 20px; border-bottom: 1px solid var(--border);
}
.water-banner h2 { margin: 0 0 4px; font-size: 15px; }
.water-banner p { margin: 0; font-size: 12.5px; color: var(--text-dim); line-height: 1.4; max-width: 720px; }

.water-layer-toggle { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 13px; }
.water-layer-toggle input { transform: scale(1.1); }

/* ---------- responsive ---------- */

@media (max-width: 760px) {
  .map-container { right: 0; bottom: 46%; }
  .side-panel { top: 54%; width: 100%; left: 0; }
  .mitigation-box { right: 10px; width: calc(100% - 20px); }
  .water-banner { right: 0; }
  #wordmark .subtitle { display: none; }
}
