/* ── Design Tokens ──────────────────────────────────────────────────────────── */
:root {
  --bg-app:       #0d1117;
  --bg-sidebar:   #111318;
  --bg-panel:     #161b22;
  --border:       rgba(255,255,255,0.08);
  --border-light: rgba(255,255,255,0.05);

  --text:         #e6edf3;
  --text-sec:     #b1bac4;
  --text-muted:   #7d8590;

  --accent:       #2f81f7;
  --accent-glow:  rgba(47,129,247,0.25);

  --c-normal:     #2ea043;
  --c-attention:  #e3b341;
  --c-alert:      #f85149;

  --topbar-h:     52px;
  --sidebar-w:    320px;
  --font:         'Inter', system-ui, sans-serif;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body, #app { height: 100dvh; overflow: hidden; }

body {
  font-family: var(--font);
  background: var(--bg-app);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { opacity: 0.8; }
button { font-family: var(--font); cursor: pointer; }

/* ── Utilities ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Banners ────────────────────────────────────────────────────────────────── */
.banner {
  position: relative;
  z-index: 1200;
  flex: 0 0 auto;
  min-height: 30px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  overflow: hidden;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.25;
}
.banner.hidden { display: none; }
.banner-icon { flex: 0 0 auto; }
.banner-msg {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.banner-info    { background: rgba(47,129,247,0.15); border-bottom: 1px solid rgba(47,129,247,0.3); color: #79c0ff; }
.banner-warning { background: rgba(210,153,34,0.15); border-bottom: 1px solid rgba(210,153,34,0.3); color: #e3b341; }
.banner-error   { background: rgba(248,81,73,0.15);  border-bottom: 1px solid rgba(248,81,73,0.3);  color: #ffa198; }
.banner-btn     { background: transparent; border: 1px solid currentColor; color: inherit; border-radius: 4px; padding: 2px 8px; font-size: 11px; cursor: pointer; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100vw;
  position: fixed;
  overflow: hidden;
}

#body-row {
  display: flex;
  flex-direction: row;
  flex: 1;
  width: 100%;
  overflow: hidden;
}

#main-layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

/* ── Top Bar ────────────────────────────────────────────────────────────────── */
#topbar {
  height: var(--topbar-h);
  background: #111318;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  z-index: 1100;
  flex-shrink: 0;
}

.topbar-brand {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex: 0 0 auto;
  min-width: 0;
  white-space: nowrap;
  border-radius: 5px;
  text-decoration: none;
}
.topbar-brand:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 4px;
}
.publisher-logo {
  display: block;
  width: auto;
  max-width: 100%;
  object-fit: contain;
}
.publisher-logo-full { height: 26px; }
.publisher-logo-compact { display: none; height: 30px; }

.topbar-center {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 520px;
  margin: 0 auto;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.topbar-updated { font-size: 11px; color: var(--text-muted); }
.topbar-refresh {
  background: transparent; border: none;
  color: var(--text-muted); font-size: 16px;
  padding: 4px 6px; border-radius: 6px;
  transition: color 0.15s;
}
.topbar-refresh:hover { color: var(--text); }

/* Topbar probe button */
.topbar-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 0 14px;
  height: 32px;
  background: rgba(47,129,247,0.1);
  border: 1px solid rgba(47,129,247,0.35);
  border-radius: 20px;
  color: #79c0ff;
  font-size: 12px; font-weight: 600;
  white-space: nowrap;
  transition: all 0.2s;
}
.topbar-btn:hover   { background: rgba(47,129,247,0.2); color: #fff; }
.topbar-btn.active  { background: rgba(47,129,247,0.25); border-color: var(--accent); box-shadow: 0 0 10px var(--accent-glow); }
.topbar-btn:disabled { cursor: progress; opacity: .72; }
.location-btn { padding-inline: 10px; }
.location-btn-icon { flex: 0 0 auto; }
.location-btn.loading .location-btn-icon,
.location-pill-btn.loading .location-btn-icon { animation: flood-load-spin .8s linear infinite; }

.current-location-marker { filter: drop-shadow(0 1px 3px rgba(0,0,0,.8)); }
.location-toast {
  max-width: min(540px, calc(100vw - 32px));
  text-align: center;
  white-space: normal;
  animation: location-toast-in .18s ease-out both;
}
.location-toast.error { border-color: rgba(248,81,73,.55); color: #ffd8d5; }
@keyframes location-toast-in {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ── Regional address search (topbar) ───────────────────────────────────────── */
.map-search-wrap { position: relative; flex: 1; }

#map-search-input {
  width: 100%;
  height: 32px;
  padding: 0 38px 0 32px;
  background: rgba(255,255,255,0.05) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="%237d8590" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>') no-repeat 10px center;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  font-size: 12px; font-family: var(--font);
  outline: none; transition: all 0.2s;
}
#map-search-input:focus {
  background-color: rgba(255,255,255,0.07);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(47,129,247,0.15);
}
#map-search-input::placeholder { color: var(--text-muted); }

.map-search-submit {
  position: absolute;
  top: 3px;
  right: 4px;
  width: 27px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}
.map-search-submit:hover,
.map-search-submit:focus-visible {
  color: #fff;
  background: rgba(47,129,247,0.2);
  outline: none;
}

.map-search-results {
  position: absolute; top: calc(100% + 4px); left: 0; width: 100%;
  background: #1c2128;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  overflow-x: hidden;
  overflow-y: auto;
  max-height: min(420px, 60vh);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 2000;
}
.map-search-results.hidden { display: none; }
.search-result-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 9px 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  border: 0;
  border-bottom: 1px solid var(--border-light);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover,
.search-result-item.active,
.search-result-item:focus-visible {
  background: rgba(47,129,247,0.13);
  outline: none;
}
.search-result-item.search-result-twin-city {
  border-left: 2px solid #58a6ff;
}
.search-result-title {
  width: 100%;
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-result-subtitle {
  width: 100%;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-result-notice {
  width: 100%;
  color: #d29922;
  font-size: 9px;
  line-height: 1.35;
  white-space: normal;
}
.search-no-result { padding: 9px 12px; font-size: 12px; color: var(--text-muted); }
.search-loading { padding: 9px 12px; font-size: 12px; color: #79c0ff; }
.search-results-footer {
  position: sticky;
  bottom: 0;
  padding: 6px 10px;
  border-top: 1px solid var(--border-light);
  background: #161b22;
  color: var(--text-muted);
  font-size: 9px;
}



/* ── Map ────────────────────────────────────────────────────────────────────── */
#map-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%; height: 100%;
  background: #0d1117;
}

.low-level-warning {
  position: absolute;
  top: 15px;
  left: 50%;
  z-index: 1000;
  max-width: 600px;
  padding: 10px 20px;
  transform: translateX(-50%);
  border-left: 4px solid #888;
  border-radius: 8px;
  background: rgba(0, 0, 0, .8);
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .3);
  font-size: .9rem;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
}
.low-level-warning-mobile { display: none; }

/* Probe cursor */
#map.probe-mode,
#map.probe-mode .leaflet-grab { cursor: crosshair !important; }

/* Layer Pills (bottom-left) */
.map-layer-pills {
  position: absolute;
  bottom: 20px; left: 16px;
  z-index: 1000;
  display: flex; gap: 3px;
  background: rgba(13,17,23,0.88);
  backdrop-filter: blur(10px);
  padding: 4px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 18px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.layer-pill {
  background: transparent; border: none;
  color: var(--text-muted);
  padding: 5px 11px; border-radius: 14px;
  font-size: 11px; font-weight: 600; font-family: var(--font);
  cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.layer-pill:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.layer-pill.active { background: rgba(47,129,247,0.2); color: #79c0ff; }

/* ── Probe Popup ────────────────────────────────────────────────────────────── */
.probe-popup .leaflet-popup-content-wrapper {
  background: rgba(13,17,23,0.96); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px; color: var(--text);
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
  padding: 0;
}
.probe-popup .leaflet-popup-tip { background: rgba(13,17,23,0.96); }
.probe-popup .leaflet-popup-content { margin: 0; padding: 16px; width: 220px !important; font-family: var(--font); }

.probe-loading  { font-size: 13px; color: var(--text-muted); text-align: center; }
.probe-error    { font-size: 13px; color: var(--c-alert); text-align: center; }
.probe-result-title { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); font-weight: 600; margin-bottom: 4px; }
.probe-elev     { font-size: 20px; font-weight: 700; }
.probe-sub      { font-size: 12px; font-weight: 400; color: var(--text-muted); }
.probe-divider  { border: 0; border-top: 1px dashed rgba(255,255,255,0.1); margin: 10px 0; }
.probe-gauge-answer { margin-top: 2px; }
.probe-gauge-label { font-size: 12px; color: #e6edf3; line-height: 1.35; margin-bottom: 1px; }
.probe-gauge    { font-size: 27px; font-weight: 800; letter-spacing: -0.6px; line-height: 1.08; margin-bottom: 2px; }
.probe-gauge-station { font-size: 10px; color: var(--text-muted); line-height: 1.35; }
.probe-status {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.35;
}
.probe-status-unavailable { color: #e3b341; font-size: 11px; }
.probe-depth {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid rgba(255,255,255,.1);
}
.probe-depth span { max-width: 125px; color: #79c0ff; font-size: 10px; line-height: 1.25; }
.probe-depth strong { color: #fff; font-size: 17px; line-height: 1.1; white-space: nowrap; }
.probe-depth-dry span { color: var(--text-muted); }
.probe-depth-dry strong { color: #8b949e; font-size: 13px; }
.probe-diff     { font-size: 11px; color: var(--text-muted); line-height: 1.4; margin-bottom: 12px; }
.probe-sim-btn {
  width: 100%; padding: 7px;
  background: rgba(47,129,247,0.12); border: 1px solid rgba(47,129,247,0.4);
  color: #79c0ff; border-radius: 6px; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
}
.probe-sim-btn:hover { background: rgba(47,129,247,0.22); color: #fff; }

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-inner {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.sidebar-inner::-webkit-scrollbar { width: 4px; }
.sidebar-inner::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* ── Panel ──────────────────────────────────────────────────────────────────── */
.panel {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.panel:last-child { border-bottom: none; }

.panel-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Level Badge & Legend Row ─────────────────────────────────────────────────── */
.level-top-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 10px;
}

.level-badge-wrap {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
}

.level-badge {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: rgba(47,129,247,0.12);
  border: 2px solid rgba(47,129,247,0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0px;
  box-shadow: 0 0 24px rgba(47,129,247,0.15);
  transition: border-color 0.4s, background 0.4s, box-shadow 0.4s;
}
.level-badge-icon  { font-size: 14px; line-height: 1; margin-bottom: 2px; }
.level-badge-value { font-size: 16px; font-weight: 800; letter-spacing: -0.5px; color: #fff; line-height: 1; }

/* ── Metrics Row ────────────────────────────────────────────────────────────── */
.metrics-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}
.metric-col { min-width: 0; text-align: center; }
.metric-label-sm { font-size: 9px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 1px; }
.metric-val-sm   { font-size: 11px; font-weight: 600; color: var(--text); }

/* ── Alert Legend ───────────────────────────────────────────────────────────── */
.alert-legend { display: flex; flex-direction: column; gap: 5px; }
.legend-title { font-size: 11px; font-weight: 600; color: var(--text-sec); margin-bottom: 4px; }
.legend-item  { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--text-muted); }
.legend-dot   { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.alert-current-summary { flex: 0 1 150px; gap: 3px; min-width: 0; }
.legend-current-row { display: flex; align-items: center; gap: 7px; font-size: 11px; }
.legend-current-range,
.legend-current-context { padding-left: 16px; font-size: 9px; line-height: 1.35; color: var(--text-muted); }
.legend-current-context { font-weight: 600; }
.methodology-inline-link { padding-left: 16px; margin-top: 2px; font-size: 9px; color: var(--blue); text-decoration: none; }
.methodology-inline-link:hover { text-decoration: underline; }

.level-alert-scale {
  width: 100%;
  margin: 0 0 10px;
}
.level-alert-scale-title {
  margin-bottom: 4px;
  color: var(--text-muted);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: .35px;
  text-transform: uppercase;
}
.level-alert-scale-track {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
}
.level-alert-scale-band {
  min-width: 0;
  padding: 3px 2px 4px;
  border: 1px solid transparent;
  border-radius: 5px;
  opacity: .66;
  text-align: center;
  transition: opacity .2s, border-color .2s, background .2s;
}
.level-alert-scale-band.is-current {
  border-color: var(--alert-band-color);
  background: rgba(255, 255, 255, .035);
  opacity: 1;
}
.level-alert-scale-color {
  display: block;
  height: 4px;
  margin-bottom: 4px;
  border-radius: 2px;
  background: var(--alert-band-color);
}
.level-alert-scale-name,
.level-alert-scale-range {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.level-alert-scale-name {
  color: var(--text-sec);
  font-size: 8.2px;
  font-weight: 700;
  line-height: 1.2;
}
.level-alert-scale-range {
  margin-top: 1px;
  color: var(--text-muted);
  font-size: 7.7px;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.desktop-observed-trend {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding: 6px 8px;
  border: 1px solid rgba(139, 148, 158, 0.16);
  border-radius: 7px;
  background: rgba(22, 27, 34, 0.52);
}
.desktop-observed-trend > div { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.desktop-trend-label { color: var(--text-sec); font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .35px; }
.desktop-observed-trend small { color: var(--text-muted); font-size: 8px; line-height: 1.2; }
.desktop-observed-trend strong { font-size: 11px; white-space: nowrap; font-variant-numeric: tabular-nums; }

.sim-load-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 27px;
  margin: 5px 0 7px;
  padding: 4px 7px;
  border: 1px solid rgba(88, 166, 255, 0.28);
  border-radius: 6px;
  background: rgba(47, 129, 247, 0.09);
  color: #79c0ff;
  font-size: 9px;
  font-weight: 650;
  line-height: 1.25;
  text-align: center;
}
.sim-load-status[data-phase="corridor"] { border-color: rgba(46, 160, 67, .32); background: rgba(46, 160, 67, .09); color: #56d364; }
.sim-load-status.is-error { border-color: rgba(248, 81, 73, .35); background: rgba(248, 81, 73, .1); color: #ff7b72; }
.sim-load-status:not(.mobile-sim-load-status):not(.is-error) {
  width: 19px;
  min-height: 19px;
  margin: 4px auto 5px;
  padding: 0;
  border: 0;
  background: transparent;
}
.sim-load-status:not(.mobile-sim-load-status):not(.is-error) .sim-load-status-text {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.sim-load-spinner {
  width: 11px;
  height: 11px;
  flex: 0 0 11px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: flood-load-spin .75s linear infinite;
}
.sim-load-status.is-error .sim-load-spinner { display: none; }
@keyframes flood-load-spin { to { transform: rotate(360deg); } }
#map-container.flood-map-loading #map { cursor: progress; }

/* ── Simulator ──────────────────────────────────────────────────────────────── */
.sim-input-label { font-size: 10px; color: var(--text-muted); margin-bottom: 5px; }

.sim-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.sim-step-btn {
  width: 32px; height: 32px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
  font-size: 18px; line-height: 1;
  transition: all 0.15s;
}
.sim-step-btn:hover { background: rgba(255,255,255,0.1); }

.sim-input-wrap {
  flex: 1;
  display: flex; align-items: center; gap: 4px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0 10px;
  height: 32px;
}
.sim-input-wrap input {
  flex: 1;
  background: transparent; border: none; outline: none;
  color: var(--accent);
  font-size: 15px; font-weight: 700; font-family: var(--font);
  text-align: center;
  width: 60px;
}
.sim-unit { font-size: 13px; font-weight: 600; color: var(--accent); }

/* Slider */
.slider-wrapper { margin-bottom: 7px; }
.sim-slider {
  -webkit-appearance: none;
  width: 100%; height: 5px;
  border-radius: 3px;
  outline: none;
  background: rgba(255,255,255,0.1); /* overridden by JS */
}
.sim-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #2f81f7;
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(47,129,247,0.2);
  transition: transform 0.1s;
}
.sim-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.sim-slider::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; border: none;
  background: #2f81f7; cursor: pointer;
}
/* Firefox range track */
.sim-slider::-moz-range-track { height: 5px; border-radius: 3px; }
.sim-slider::-moz-range-progress { background: #2f81f7; height: 5px; border-radius: 3px; }

.sim-map-btn {
  width: 100%;
  height: 28px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-sec);
  font-size: 11px; font-weight: 600;
  transition: all 0.2s;
}
.sim-map-btn:hover { background: rgba(255,255,255,0.09); color: var(--text); border-color: rgba(255,255,255,0.15); }

/* Simulator unavailable */
.simulator-msg p { font-size: 12px; color: var(--text-muted); line-height: 1.5; }
.text-muted { color: var(--text-muted); }

/* ── Historical ─────────────────────────────────────────────────────────────── */
.historical-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.hist-btn {
  padding: 5px 4px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-sec);
  font-size: 11px; font-weight: 600;
  text-align: center;
  transition: all 0.2s;
}
.hist-btn:hover {
  background: rgba(47,129,247,0.12);
  border-color: rgba(47,129,247,0.3);
  color: #79c0ff;
}

/* ── Forecast ───────────────────────────────────────────────────────────────── */
.chart-source-badge {
  margin-left: auto;
  font-size: 9px; font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
}
.forecast-empty p { font-size: 12px; color: var(--text-muted); }

/* Custom Legend Top */
.custom-chart-legend {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2px;
  padding: 0 4px;
}
.ccl-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
}
.ccl-left { color: #7d8590; }
.ccl-right { color: rgba(47,129,247,0.7); }
.ccl-box {
  width: 12px; height: 12px;
  border-radius: 2px;
}

.chart-expand-btn {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-muted);
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.chart-expand-btn:hover,
.chart-expand-btn:focus-visible {
  color: var(--text);
  background: rgba(255,255,255,0.09);
  border-color: rgba(255,255,255,0.16);
  outline: none;
}
.chart-collapse-icon { display: none; }
.chart-expand-btn[aria-pressed="true"] .chart-expand-icon { display: none; }
.chart-expand-btn[aria-pressed="true"] .chart-collapse-icon { display: block; }

.chart-wrap { width: 100%; height: 180px; position: relative; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }
.chart-note { font-size: 10px; color: var(--text-muted); margin-top: 4px; }

body.chart-fullscreen-open { overflow: hidden; }

#panel-forecast.chart-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  z-index: 5000;
  width: 100vw !important;
  height: 100dvh !important;
  max-width: none !important;
  max-height: none !important;
  display: flex !important;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
  padding: clamp(14px, 2.5vw, 32px);
  background: var(--bg-app);
  border: 0;
  border-radius: 0;
}
#panel-forecast.chart-fullscreen .chart-tabs {
  width: min(100%, 720px);
  align-self: center;
  flex-shrink: 0;
  margin-bottom: 16px;
}
#panel-forecast.chart-fullscreen .history-controls,
#panel-forecast.chart-fullscreen .forecast-tip,
#panel-forecast.chart-fullscreen .custom-chart-legend,
#panel-forecast.chart-fullscreen .chart-alert-legend,
#panel-forecast.chart-fullscreen .chart-note {
  flex-shrink: 0;
}
#panel-forecast.chart-fullscreen .history-controls {
  width: min(100%, 720px);
  align-self: center;
}
#panel-forecast.chart-fullscreen #uv-chart-content {
  width: 100%;
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
}
#panel-forecast.chart-fullscreen .chart-wrap {
  flex: 1 1 0;
  height: 0;
  min-height: 260px;
}

@media (max-width: 768px), (max-width: 960px) and (max-height: 500px) and (orientation: landscape) {
  #panel-forecast.chart-fullscreen {
    padding: 12px;
  }
  #panel-forecast.chart-fullscreen .chart-tabs {
    margin-bottom: 10px;
  }
  #panel-forecast.chart-fullscreen .chart-wrap {
    min-height: 0;
  }
  #panel-forecast.chart-fullscreen .history-controls {
    gap: 6px;
  }
}

/* Compact alert level legend below chart */
.chart-alert-legend {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: nowrap;
  margin-top: 6px;
  margin-bottom: 2px;
}
.cal-item {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 9px;
  color: var(--text-muted);
  white-space: nowrap;
}
.cal-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Sidebar Footer ─────────────────────────────────────────────────────────── */
.sidebar-footer {
  padding: 12px 16px;
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ── Leaflet overrides ──────────────────────────────────────────────────────── */
.leaflet-popup-content-wrapper {
  background: rgba(17,19,24,0.97) !important;
  border: 1px solid rgba(255,255,255,0.1) !important;
  border-radius: 10px !important;
  color: var(--text) !important;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5) !important;
}
.leaflet-popup-tip { background: rgba(17,19,24,0.97) !important; }
.leaflet-popup-content { color: var(--text) !important; font-family: var(--font) !important; font-size: 13px !important; }
.leaflet-control-zoom a {
  background: rgba(17,19,24,0.92) !important;
  border-color: rgba(255,255,255,0.1) !important;
  color: var(--text) !important;
}
.leaflet-control-zoom a:hover { background: rgba(47,129,247,0.2) !important; color: #79c0ff !important; }
.leaflet-bar { box-shadow: 0 4px 12px rgba(0,0,0,0.5) !important; }
.leaflet-control-attribution { background: rgba(0,0,0,0.55) !important; color: rgba(255,255,255,0.4) !important; font-size: 9px !important; }
.leaflet-control-attribution a { color: rgba(255,255,255,0.5) !important; }

/* Keyless fallback for the dark basemap. The filter is applied to tile
   images only, so flood polygons and station markers keep their colors. */
.leaflet-container.basemap-dark .leaflet-tile-pane .leaflet-tile {
  filter: grayscale(1) invert(1) brightness(.62) contrast(1.15);
}

/* ── Mobile ─────────────────────────────────────────────────────────────────── */
#sidebar-toggle { display: none; }

@media (max-width: 768px), (max-width: 960px) and (max-height: 500px) and (orientation: landscape) {
  :root { --sidebar-w: 100%; --topbar-h: 48px; }

  .banner {
    min-height: 28px;
    align-items: flex-start;
    padding: 5px 10px;
    font-size: 10px;
  }
  .banner-msg {
    display: -webkit-box;
    overflow: hidden;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  #topbar { padding: 0 12px; gap: 8px; }
  .topbar-sub { display: none; }
  .topbar-btn { padding: 0 10px; }
  .topbar-btn span { display: none; } /* Hide text, keep icon */
  .topbar-right { display: none; }
  .topbar-center { max-width: none; }

  .map-layer-pills {
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
  }
  .leaflet-control-zoom {
    margin-bottom: 60px !important;
  }

  #main-layout { flex-direction: column; }

  #map-container { flex: 1; min-height: 55vh; }

  #sidebar {
    position: fixed; bottom: 0; left: 0; right: 0;
    width: 100%;
    height: 50vh;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    border-left: none;
    border-top: 1px solid var(--border);
    z-index: 900;
  }
  #sidebar.open { transform: translateY(0); }

  #sidebar-toggle {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    position: fixed; bottom: 0;
    left: 50%; transform: translateX(-50%);
    z-index: 950;
    height: 36px; padding: 0 18px;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 18px 18px 0 0;
    border-bottom: none;
    color: var(--text-muted);
    font-size: 12px; font-weight: 600;
    transition: bottom 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  }
  #sidebar-toggle.open { bottom: 50vh; }
  .toggle-arrow { font-size: 10px; transition: transform 0.3s; }
  #sidebar-toggle.open .toggle-arrow { transform: rotate(180deg); }
}

.disclaimer-box { margin-top: 8px; font-size: 0.65rem; background-color: rgba(255,165,0,0.1); border: 1px solid rgba(255,165,0,0.5); padding: 6px; border-radius: 4px; color: #d4a373; line-height: 1.2; }


/* Chart Tabs & History Controls */
.chart-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.chart-tab {
  flex: 1;
  background: var(--bg-secondary);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  padding: 8px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.chart-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.history-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-bottom: 12px;
}
.history-controls.hidden {
  display: none !important;
}
.history-date-row {
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
}
.hist-date-fields {
  min-width: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 6px;
}
.hist-date-field {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.hist-date-field span {
  padding-left: 2px;
  color: var(--text-muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.45px;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
}
.hist-nav-btn {
  background: rgba(255,255,255,0.045);
  border: 1px solid var(--border);
  color: white;
  border-radius: 6px;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.hist-nav-btn:hover {
  background: rgba(255,255,255,0.09);
}
.hist-date-input {
  width: 100%;
  min-width: 0;
  height: 32px;
  background: rgba(255,255,255,0.045);
  border: 1px solid var(--border);
  color: white;
  padding: 5px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  text-align: center;
  color-scheme: dark;
}
.hist-date-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(47,129,247,0.15);
  outline: none;
}
.hist-date-input.invalid,
.hist-date-input[aria-invalid="true"] {
  border-color: var(--c-alert);
  box-shadow: 0 0 0 2px rgba(248,81,73,0.14);
}
.history-presets {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
}
.history-preset-btn {
  height: 25px;
  padding: 0 4px;
  background: rgba(255,255,255,0.035);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.history-preset-btn:hover {
  color: var(--text);
  background: rgba(255,255,255,0.08);
}
.history-preset-btn.active {
  color: #79c0ff;
  background: rgba(47,129,247,0.14);
  border-color: rgba(47,129,247,0.4);
}


.has-data-dot {
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  background-color: #58a6ff;
  border-radius: 50%;
}
.flatpickr-day.selected .has-data-dot {
  background-color: white;
}

.topbar-sub-select { background: transparent; color: var(--text-muted); border: none; font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px; padding: 0; outline: none; cursor: pointer; font-family: 'Inter', sans-serif; }

.map-provider-warning {
  position: absolute;
  top: 14px;
  left: 50%;
  z-index: 1100;
  max-width: min(560px, calc(100% - 28px));
  padding: 9px 12px;
  border: 1px solid rgba(227, 179, 65, 0.45);
  border-radius: 7px;
  background: rgba(22, 27, 34, 0.96);
  color: #e6edf3;
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.4);
  font-size: 0.75rem;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.map-provider-warning.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
