:root {
  color-scheme: light;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #475569;
  --primary: #0369a1;
  --primary-hover: #075985;
  --topbar-bg: linear-gradient(135deg, #0c4a6e 0%, #0369a1 100%);
  --topbar-shadow: 0 2px 10px rgba(12, 74, 110, 0.25);
  --topbar-text: #ffffff;
  --topbar-sub: #e0f2fe;
  --topbar-muted: #bae6fd;
  --level-num: #0c4a6e;
  --safe: #0f766e;
  --safe-bg: #ccfbf1;
  --caution: #b45309;
  --caution-bg: #fef3c7;
  --caution-border: #f59e0b;
  --warning: #c2410c;
  --warning-bg: #ffedd5;
  --high: #dc2626;
  --high-bg: #fee2e2;
  --danger: #991b1b;
  --danger-bg: #fecaca;
  --pill-bg: #e2e8f0;
  --pill-text: #334155;
  --pill-active-bg: #dcfce7;
  --pill-active-text: #166534;
  --btn-sec-hover: #e2e8f0;
  --banner-warn-bg: #fef3c7;
  --banner-warn-border: #f59e0b;
  --banner-warn-text: #92400e;
  --code-bg: #e0f2fe;
  --code-text: #0369a1;
  --zone-safe: #14b8a6;
  --zone-bd1: #f59e0b;
  --zone-bd2: #ea580c;
  --zone-bd3: #dc2626;
  --chart-bd1: #f59e0b;
  --chart-bd2: #ea580c;
  --chart-bd3: #dc2626;
  --gauge-track: #e2e8f0;
  --gauge-marker: #0f172a;
  --gauge-tip-text: #ffffff;
  --tick-bd1: #b45309;
  --tick-bd2: #c2410c;
  --tick-bd3: #b91c1c;
  --tick-hist: #7f1d1d;
  --input-bg: #ffffff;
  --seg-active-text: #ffffff;
  --chart-grid: #e2e8f0;
  --chart-axis: #64748b;
  --chart-line: #0369a1;
  --chart-area: #0284c7;
  --chart-pt-stroke: #ffffff;
  --tooltip-bg: rgba(15, 23, 42, 0.95);
  --tooltip-text: #ffffff;
  --lake-bar-bg: #e2e8f0;
  --lake-bar-fill: #0284c7;
  --lake-releasing-bg: #fff7ed;
  --lake-releasing-border: #f97316;
  --lake-releasing-fill: #ea580c;
  --tag-basin-bg: #e0f2fe;
  --tag-basin-text: #0369a1;
  --tag-release-bg: #ffedd5;
  --tag-release-text: #c2410c;
  --rain-heavy: #b45309;
  --rain-extreme: #dc2626;
  --featured-bg: #eff6ff;
  --featured-border: #bfdbfe;
  --featured-text: #1e293b;
  --bulletin-badge-bg: #fee2e2;
  --bulletin-badge-text: #991b1b;
  --emergency-bg: #fef2f2;
  --emergency-border: #fecaca;
  --emergency-text: #7f1d1d;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --radius: 14px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151b23;
  --surface: #1c232d;
  --surface-alt: #222b37;
  --border: #2e3948;
  --text: #cfd8e3;
  --muted: #8b98a9;
  --primary: #6ea8cc;
  --primary-hover: #8ec0de;
  --topbar-bg: linear-gradient(135deg, #162a3a 0%, #1c2836 100%);
  --topbar-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
  --topbar-text: #dce5ef;
  --topbar-sub: #a7b8c9;
  --topbar-muted: #8fa6bc;
  --level-num: #7db8da;
  --safe: #5bb5a2;
  --safe-bg: rgba(91, 181, 162, 0.14);
  --caution: #d4a853;
  --caution-bg: rgba(212, 168, 83, 0.14);
  --caution-border: rgba(212, 168, 83, 0.36);
  --warning: #d98c56;
  --warning-bg: rgba(217, 140, 86, 0.15);
  --high: #d47474;
  --high-bg: rgba(212, 116, 116, 0.15);
  --danger: #df9191;
  --danger-bg: rgba(212, 116, 116, 0.2);
  --pill-bg: #2a3442;
  --pill-text: #b8c4d2;
  --pill-active-bg: rgba(91, 181, 162, 0.16);
  --pill-active-text: #7ecab9;
  --btn-sec-hover: #2c3645;
  --banner-warn-bg: rgba(212, 168, 83, 0.12);
  --banner-warn-border: rgba(212, 168, 83, 0.36);
  --banner-warn-text: #dec07c;
  --code-bg: rgba(110, 168, 204, 0.14);
  --code-text: #8ebbd6;
  --zone-safe: #2a8f82;
  --zone-bd1: #b88b35;
  --zone-bd2: #b86c39;
  --zone-bd3: #b44c4c;
  --chart-bd1: #c99b42;
  --chart-bd2: #c97b45;
  --chart-bd3: #c45c5c;
  --gauge-track: #2c3645;
  --gauge-marker: #cfd8e3;
  --gauge-tip-text: #151b23;
  --tick-bd1: #cca252;
  --tick-bd2: #cc8552;
  --tick-bd3: #cc7272;
  --tick-hist: #d68b8b;
  --input-bg: #171e27;
  --seg-active-text: #151b23;
  --chart-grid: #2a3442;
  --chart-axis: #8b98a9;
  --chart-line: #6ea8cc;
  --chart-area: #6ea8cc;
  --chart-pt-stroke: #1c232d;
  --tooltip-bg: rgba(22, 29, 38, 0.96);
  --tooltip-text: #d7e0ea;
  --lake-bar-bg: #2c3645;
  --lake-bar-fill: #5c98bd;
  --lake-releasing-bg: rgba(217, 140, 86, 0.1);
  --lake-releasing-border: rgba(217, 140, 86, 0.4);
  --lake-releasing-fill: #c47d4a;
  --tag-basin-bg: rgba(110, 168, 204, 0.14);
  --tag-basin-text: #8ebbd6;
  --tag-release-bg: rgba(217, 140, 86, 0.15);
  --tag-release-text: #d8a982;
  --rain-heavy: #d4a853;
  --rain-extreme: #d47a7a;
  --featured-bg: rgba(110, 168, 204, 0.08);
  --featured-border: rgba(110, 168, 204, 0.24);
  --featured-text: #bcc7d4;
  --bulletin-badge-bg: rgba(212, 116, 116, 0.16);
  --bulletin-badge-text: #daa0a0;
  --emergency-bg: rgba(212, 116, 116, 0.1);
  --emergency-border: rgba(212, 116, 116, 0.28);
  --emergency-text: #d4adad;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

* {
  box-sizing: border-box;
}

html,
body {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background-color 0.2s ease, color 0.2s ease;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  width: 100%;
  max-width: 1220px;
  margin: 0 auto;
  padding: 0 16px;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

/* Topbar */
.topbar {
  background: var(--topbar-bg);
  color: var(--topbar-text);
  padding: max(14px, env(safe-area-inset-top)) 0 16px;
  box-shadow: var(--topbar-shadow);
}

.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.16);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--topbar-sub);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.refresh-meta {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  text-align: right;
  color: var(--topbar-sub);
}

.refresh-meta .muted {
  color: var(--topbar-muted);
}

.status-pill {
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.01em;
}

.status-safe { background: var(--safe-bg); color: var(--safe); }
.status-caution { background: var(--caution-bg); color: var(--caution); }
.status-warning { background: var(--warning-bg); color: var(--warning); }
.status-high { background: var(--high-bg); color: var(--high); }
.status-danger { background: var(--danger-bg); color: var(--danger); }
.status-unknown { background: var(--pill-bg); color: var(--pill-text); }

/* Buttons */
.btn {
  border: none;
  border-radius: 10px;
  padding: 9px 15px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--btn-sec-hover);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.8rem;
}

.btn-theme {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.12);
  color: var(--topbar-text);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

html[data-theme="dark"] .btn-theme {
  border-color: rgba(207, 216, 227, 0.22);
  background: rgba(207, 216, 227, 0.08);
}

.btn-theme:hover {
  background: rgba(255, 255, 255, 0.24);
  border-color: rgba(255, 255, 255, 0.45);
}

.btn-theme:active {
  transform: translateY(1px);
}

.btn-theme:focus-visible {
  outline: 2px solid #bae6fd;
  outline-offset: 2px;
}

/* Main layout */
.main-grid {
  padding: 20px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Location selector & nationwide search bar */
.location-bar {
  padding: 12px 16px;
}

.location-bar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
}

.location-field {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 280px;
  min-width: 0;
}

.location-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.province-select {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 340px;
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}

.province-select:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.location-search-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.btn-search {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 7px 13px;
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.btn-search:hover {
  background: var(--btn-sec-hover);
  border-color: var(--primary);
}

.kbd-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 5px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
}

.location-meta {
  white-space: nowrap;
}

/* Native modal search dialog */
dialog.search-dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: min(82vh, 660px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.32);
}

dialog.search-dialog[open] {
  display: flex;
  flex-direction: column;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background-color: rgba(15, 23, 42, 0.56);
  backdrop-filter: blur(2px);
}

.search-dialog-head {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}

.search-dialog-head h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.search-dialog-form {
  display: flex;
  flex-shrink: 0;
  flex-direction: column;
  gap: 6px;
  padding: 12px 16px 8px;
}

.search-dialog-input {
  width: 100%;
  flex-shrink: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: max(1rem, 1em);
}

.search-dialog-input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.search-dialog-status {
  min-height: 18px;
}

.search-results-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.search-group-title {
  margin: 8px 0 2px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.search-result-btn {
  width: 100%;
  flex-shrink: 0;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
  color: var(--text);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  font: inherit;
}

.search-result-btn:hover,
.search-result-btn.is-active {
  border-color: var(--primary);
  background: var(--code-bg);
}

.search-result-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.search-result-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.search-result-title {
  font-weight: 700;
  font-size: 0.92rem;
}

.search-result-sub {
  font-size: 0.8rem;
  color: var(--muted);
}

.search-result-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  font-size: 0.85rem;
  font-weight: 700;
}

.search-empty {
  padding: 18px 8px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Clickable station row button in province stations table */
.station-pick-btn {
  border: none;
  background: transparent;
  padding: 4px 0;
  margin: 0;
  font: inherit;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
  text-align: left;
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
}

.station-pick-btn:hover {
  text-decoration: underline;
}

.station-pick-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

.station-row-active {
  background: var(--featured-bg);
}

.gauge-track.gauge-no-thresholds {
  background: linear-gradient(90deg, var(--zone-safe) 0%, var(--primary) 100%);
  opacity: 0.85;
}

.banner {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.9rem;
  border: 1px solid transparent;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
}

.banner-retry-btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.banner-warn {
  background: var(--banner-warn-bg);
  border-color: var(--banner-warn-border);
  color: var(--banner-warn-text);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
  transition: background-color 0.2s ease, border-color 0.2s ease;
  min-width: 0;
  max-width: 100%;
}

[data-theme="dark"] .card {
  box-shadow: none;
}

.hero-card {
  border-color: rgba(2, 132, 199, 0.28);
  box-shadow: var(--shadow);
}

[data-theme="dark"] .hero-card {
  border-color: rgba(56, 189, 248, 0.26);
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.card-header > div {
  min-width: 0;
}

.card-header.compact {
  margin-bottom: 10px;
}

.card-header h2,
.card-header h3 {
  margin: 0;
  font-size: 1.08rem;
}

.eyebrow {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary);
  margin-bottom: 2px;
}

.code-tag {
  font-size: 0.8rem;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 2px 8px;
  border-radius: 6px;
  vertical-align: middle;
}

/* Hero grid */
.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  gap: 18px;
}

.hero-grid > *,
.two-col-grid > *,
.hero-metrics > * {
  min-width: 0;
}

.side-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.rapid-badge {
  background: var(--caution-bg);
  color: var(--caution);
  border: 1px solid var(--caution-border);
  font-weight: 700;
  font-size: 0.8rem;
  padding: 5px 11px;
  border-radius: 999px;
}

.hero-metrics {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.level-value-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.level-number {
  font-size: 3.1rem;
  font-weight: 800;
  line-height: 1;
  color: var(--level-num);
  letter-spacing: -0.02em;
}

.level-unit {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--muted);
}

.observed-time {
  margin-top: 6px;
  font-size: 0.88rem;
  color: var(--muted);
}

.alert-desc {
  margin-top: 4px;
  font-weight: 600;
  font-size: 0.95rem;
}

.next-threshold {
  margin-top: 4px;
  font-size: 0.84rem;
}

.trend-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metric-label {
  font-size: 0.78rem;
  color: var(--muted);
}

.metric-val {
  font-size: 1.2rem;
  color: var(--text);
}

.metric-sub {
  font-size: 0.78rem;
  color: var(--muted);
}

/* Gauge */
.gauge-wrap {
  margin: 14px 0 18px;
  padding-top: 26px;
}

.gauge-track {
  position: relative;
  height: 14px;
  border-radius: 999px;
  overflow: visible;
  display: flex;
  background: var(--gauge-track);
}

.gauge-zone {
  height: 100%;
}

.gauge-zone:first-child {
  border-top-left-radius: 999px;
  border-bottom-left-radius: 999px;
}

.zone-safe { width: 57.14%; background: var(--zone-safe); }
.zone-bd1 { width: 10.71%; background: var(--zone-bd1); }
.zone-bd2 { width: 10.71%; background: var(--zone-bd2); }
.zone-bd3 {
  width: 21.44%;
  background: var(--zone-bd3);
  border-top-right-radius: 999px;
  border-bottom-right-radius: 999px;
}

.gauge-marker {
  position: absolute;
  top: -5px;
  left: 0%;
  width: 4px;
  height: 24px;
  background: var(--gauge-marker);
  border-radius: 2px;
  transform: translateX(-50%);
  transition: left 0.35s ease;
}

.gauge-marker-tip {
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gauge-marker);
  color: var(--gauge-tip-text);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  white-space: nowrap;
}

.gauge-marker-tip.tip-left {
  left: 0;
  transform: translateX(-8%);
}

.gauge-marker-tip.tip-right {
  left: auto;
  right: 0;
  transform: translateX(8%);
}

.gauge-ticks {
  position: relative;
  height: 40px;
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--muted);
}

.gauge-ticks .tick {
  position: absolute;
  top: 4px;
  transform: translateX(-50%);
  white-space: nowrap;
}

.gauge-ticks .tick::before {
  content: '';
  position: absolute;
  top: -4px;
  left: 50%;
  width: 1px;
  height: 4px;
  background: currentColor;
  opacity: 0.6;
  transform: translateX(-50%);
}

.gauge-ticks .tick-zero {
  left: 0%;
  transform: none;
}

.gauge-ticks .tick-zero::before {
  left: 2px;
  transform: none;
}

.tick-bd1 { left: 57.14%; color: var(--tick-bd1); font-weight: 600; }
.tick-bd2 { left: 67.85%; top: 22px !important; color: var(--tick-bd2); font-weight: 600; }
.tick-bd3 { left: 78.57%; color: var(--tick-bd3); font-weight: 700; }
.gauge-ticks .tick-bd1-pull-left { transform: translateX(-92%); }
.gauge-ticks .tick-bd1-pull-left::before { left: 92%; }
.gauge-ticks .tick-bd3-push-right { transform: translateX(-8%); }
.gauge-ticks .tick-bd3-push-right::before { left: 8%; }
.gauge-ticks .tick-hist { left: 93.86%; top: 22px !important; color: var(--tick-hist); font-weight: 600; transform: translateX(-85%); }
.gauge-ticks .tick-max { right: 0%; left: auto; transform: none; }
.gauge-ticks .tick-mid { left: 50%; }

.gauge-ticks .tick-bd2::before,
.gauge-ticks .tick-hist::before {
  top: -22px;
  height: 22px;
}

.gauge-ticks .tick-hist::before {
  left: 85%;
}

.data-quality-row {
  margin-top: 10px;
  padding: 8px 11px;
  border-radius: 9px;
  font-size: 0.8rem;
  background: var(--banner-warn-bg);
  border: 1px solid var(--banner-warn-border);
  color: var(--banner-warn-text);
}

.data-quality-row.info {
  background: var(--featured-bg);
  border-color: var(--featured-border);
  color: var(--featured-text);
}

/* Sources comparison */
.comparison-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.source-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.source-box-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 600;
}

.source-box-body {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 6px 0 4px;
}

.source-box-body strong {
  font-size: 1.15rem;
}

.source-link {
  font-size: 0.8rem;
  font-weight: 600;
}

.dot {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

.dot-ok { background: var(--safe-bg); color: var(--safe); }
.dot-stale { background: var(--caution-bg); color: var(--caution); }
.dot-err { background: var(--high-bg); color: var(--high); }
.dot-idle { background: var(--pill-bg); color: var(--muted); }

/* Weather & Personal alert */
.weather-main {
  display: flex;
  align-items: center;
  gap: 14px;
}

.weather-temp {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
}

.weather-cond {
  font-weight: 600;
}

.pill-mini {
  background: var(--pill-bg);
  color: var(--pill-text);
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.pill-mini.active {
  background: var(--pill-active-bg);
  color: var(--pill-active-text);
}

.config-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 10px 0;
  font-size: 0.9rem;
}

.config-row input {
  width: 96px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--input-bg);
  color: var(--text);
}

.config-toggles {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  flex-shrink: 0;
  cursor: pointer;
}

.config-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}

#testBeepBtn {
  flex-shrink: 0;
  white-space: nowrap;
}

/* Chart */
.chart-card {
  position: relative;
}

.segmented {
  display: inline-flex;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}

.seg-btn {
  border: none;
  background: transparent;
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.seg-short {
  display: none;
}

.seg-btn.active {
  background: var(--primary);
  color: var(--seg-active-text);
}

.btn:focus-visible,
.seg-btn:focus-visible,
.chart-svg:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 8px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.chart-meta-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 14px;
  font-size: 0.8rem;
  color: var(--muted);
  margin: -4px 0 8px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--muted);
  margin: -2px 0 8px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-line {
  width: 18px;
  height: 0;
  border-top: 2.5px solid currentColor;
  display: inline-block;
}

.legend-line-observed {
  border-top-color: var(--chart-line);
}

.legend-line-forecast {
  border-top-color: #fb923c;
}

.legend-line.dashed {
  border-top-style: dashed;
}

.chart-container {
  width: 100%;
  min-height: 240px;
}

.chart-container svg {
  display: block;
  width: 100%;
  height: auto;
  touch-action: pan-y;
}

.chart-pt,
.chart-hit {
  cursor: pointer;
}

.tooltip-source {
  color: #93c5fd;
}

.chart-empty {
  height: 240px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  padding: 8px 11px;
  border-radius: 9px;
  font-size: 0.8rem;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.25);
  z-index: 20;
  white-space: nowrap;
}

/* Two column grid */
.two-col-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

/* Reservoirs */
.reservoirs-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lake-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 13px;
  background: var(--surface-alt);
}

.lake-item.releasing {
  border-color: var(--lake-releasing-border);
  background: var(--lake-releasing-bg);
}

.lake-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.lake-title {
  font-weight: 700;
  font-size: 0.95rem;
}

.lake-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
}

.rain-station-name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
}

.tag-basin { background: var(--tag-basin-bg); color: var(--tag-basin-text); }
.tag-release { background: var(--tag-release-bg); color: var(--tag-release-text); }
.tag-stale { background: var(--pill-bg); color: var(--pill-text); }
.tag-warn-bd { background: var(--warning-bg); color: var(--warning); }

.lake-bar {
  height: 8px;
  background: var(--lake-bar-bg);
  border-radius: 999px;
  overflow: hidden;
  margin: 6px 0;
}

.lake-bar-fill {
  height: 100%;
  background: var(--lake-bar-fill);
  border-radius: 999px;
}

.lake-item.releasing .lake-bar-fill {
  background: var(--lake-releasing-fill);
}

.lake-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Tables */
.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th,
.data-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.data-table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  color: var(--muted);
}

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.rain-heavy { color: var(--rain-heavy); font-weight: 700; }
.rain-extreme { color: var(--rain-extreme); font-weight: 700; }

/* Bulletins */
.featured-bulletin {
  background: var(--featured-bg);
  border: 1px solid var(--featured-border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
}

.featured-bulletin h4 {
  margin: 0 0 6px;
  font-size: 0.98rem;
}

.featured-bulletin p {
  margin: 6px 0;
  font-size: 0.9rem;
  color: var(--featured-text);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.bulletin-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bulletin-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
  font-size: 0.88rem;
}

.bulletin-list li > span {
  white-space: nowrap;
  flex-shrink: 0;
}

.bulletin-list li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.bulletin-badge {
  background: var(--bulletin-badge-bg);
  color: var(--bulletin-badge-text);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  margin-right: 6px;
}

/* Guide */
.threshold-legend {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 0.88rem;
}

.threshold-legend li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
  margin-top: 5px;
}

.swatch.bd1 { background: var(--zone-bd1); }
.swatch.bd2 { background: var(--zone-bd2); }
.swatch.bd3 { background: var(--zone-bd3); }

/* Downstream Bridges */
.downstream-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  gap: 12px;
}

.downstream-item {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.downstream-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.downstream-head h4 {
  margin: 0;
  font-size: 0.98rem;
}

.downstream-loc {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

.downstream-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.83rem;
  color: var(--muted);
}

.downstream-meta strong {
  color: var(--text);
}

.downstream-notice {
  margin-top: 12px;
  padding: 10px 13px;
  border-radius: 10px;
  background: var(--featured-bg);
  border: 1px solid var(--featured-border);
  font-size: 0.83rem;
  color: var(--featured-text);
  overflow-wrap: anywhere;
}

.downstream-excerpt {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

.emergency-bar {
  background: var(--emergency-bg);
  border: 1px solid var(--emergency-border);
  color: var(--emergency-text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.86rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
}

.emergency-links {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}

.emergency-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(127, 29, 29, 0.06);
}

[data-theme="dark"] .emergency-chip {
  background: rgba(255, 255, 255, 0.06);
}

.tel-link {
  color: inherit;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.footer {
  padding: 0 16px max(28px, env(safe-area-inset-bottom));
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 960px) {
  .hero-grid,
  .two-col-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (min-width: 641px) and (max-width: 960px) {
  .side-stack {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 14px;
  }
}

@media (max-width: 640px) {
  .container {
    padding: 0 12px;
  }

  .location-bar {
    padding: 12px;
  }

  .location-field {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    flex: 1 1 100%;
  }

  .province-select {
    max-width: none;
    width: 100%;
    min-height: 44px;
    font-size: max(1rem, 1em);
  }

  .location-search-wrap {
    width: 100%;
    justify-content: space-between;
  }

  .btn-search {
    flex: 1 1 100%;
    justify-content: center;
    min-height: 44px;
  }

  .kbd-hint {
    display: none;
  }

  .location-meta {
    white-space: normal;
  }

  .station-pick-btn {
    min-height: 44px;
  }

  .topbar {
    padding: max(10px, env(safe-area-inset-top)) 0 12px;
  }

  .topbar-inner {
    gap: 10px;
  }

  .brand {
    gap: 10px;
  }

  .brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
  }

  .brand h1 {
    font-size: 1.04rem;
    line-height: 1.25;
  }

  .subtitle {
    font-size: 0.78rem;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
  }

  .topbar .status-pill {
    flex: 1 1 100%;
    text-align: center;
  }

  .refresh-meta {
    text-align: left;
  }

  .btn-theme {
    min-height: 44px;
    padding: 8px 14px;
  }

  .main-grid {
    padding: 14px 12px 24px;
    gap: 14px;
  }

  .card {
    padding: 14px;
    border-radius: 12px;
  }

  .hero-metrics {
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 14px;
  }

  .level-number {
    font-size: 2.6rem;
  }

  .trend-grid {
    gap: 8px;
  }

  .metric-box {
    padding: 10px;
  }

  .metric-val {
    font-size: 1.06rem;
  }

  .comparison-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .gauge-ticks {
    height: 40px;
    font-size: 0.75rem;
    letter-spacing: -0.02em;
  }

  .btn {
    min-height: 44px;
  }

  .btn-sm {
    min-height: 44px;
    padding: 8px 14px;
  }

  .checkbox-label {
    min-height: 44px;
  }

  .config-row input {
    font-size: 16px;
    min-height: 44px;
  }

  .segmented {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    overflow: visible;
  }

  .seg-btn {
    min-width: 0;
    min-height: 44px;
    padding: 6px 2px;
    font-size: 0.78rem;
    text-align: center;
  }

  .seg-full {
    display: none;
  }

  .seg-short {
    display: inline;
  }

  .lake-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .lake-meta {
    flex-direction: column;
    gap: 4px;
  }

  .data-table {
    font-size: 0.82rem;
  }

  .data-table th,
  .data-table td {
    padding: 8px 6px;
  }

  .data-table .num {
    white-space: nowrap;
  }

  .bulletin-list li {
    flex-direction: column;
    gap: 2px;
  }

  .downstream-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  .refresh-meta {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    text-align: left;
    gap: 1px;
  }

  .topbar-actions .btn-theme {
    flex: 0 0 auto;
    justify-content: center;
  }

  .trend-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .source-box-head {
    flex-wrap: wrap;
  }
}

@media (max-width: 360px) {
  .segmented {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
  }

  .seg-btn {
    padding: 6px 1px;
    font-size: 0.75rem;
  }
}

@media (max-width: 310px) {
  .segmented {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }

  .trend-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.theme-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

@media (pointer: coarse), (max-width: 900px) {
  .kbd-hint {
    display: none;
  }

  .station-pick-btn {
    min-height: 44px;
    min-width: 48px;
    padding: 8px 4px;
  }

  .btn-theme,
  .btn-sm,
  .btn-search,
  .province-select,
  .search-result-btn,
  .seg-btn,
  .checkbox-label,
  .config-row input {
    min-height: 44px;
  }

  .source-link,
  .bulletin-list a,
  .tel-link,
  .footer a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }

  .tel-link {
    min-width: 44px;
    justify-content: center;
    padding: 0 8px;
  }
}

@media (max-height: 450px) and (orientation: landscape) {
  .topbar {
    padding: 6px 0;
  }

  .subtitle {
    display: none;
  }

  .main-grid {
    padding-top: 10px;
    gap: 10px;
  }

  .hero-card {
    padding: 10px 14px;
  }

  .hero-card .card-header {
    margin-bottom: 6px;
  }

  .hero-metrics {
    grid-template-columns: 1.15fr 1fr;
    gap: 8px;
    margin-bottom: 6px;
  }

  .level-number {
    font-size: 2.2rem;
  }

  .metric-box {
    padding: 6px 10px;
  }

  .gauge-wrap {
    padding-top: 18px;
  }

  dialog.search-dialog {
    max-height: 92vh;
  }

  .search-dialog-head {
    padding: 8px 14px 6px;
  }

  .search-dialog-form {
    padding: 6px 14px 4px;
    gap: 4px;
  }

  .search-dialog-input {
    min-height: 44px;
    padding: 8px 10px;
  }

  .search-dialog-status {
    font-size: 0.75rem;
    min-height: 14px;
  }

  .search-results-list {
    padding: 2px 14px 10px;
    gap: 4px;
  }

  .search-result-btn {
    padding: 6px 10px;
  }
}
