: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);
  --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;
  --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: #0b1120;
  --surface: #111827;
  --surface-alt: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #38bdf8;
  --primary-hover: #7dd3fc;
  --topbar-bg: linear-gradient(135deg, #082f49 0%, #0f172a 100%);
  --topbar-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  --level-num: #38bdf8;
  --safe: #2dd4bf;
  --safe-bg: rgba(20, 184, 166, 0.18);
  --caution: #fbbf24;
  --caution-bg: rgba(245, 158, 11, 0.18);
  --caution-border: rgba(251, 191, 36, 0.55);
  --warning: #fb923c;
  --warning-bg: rgba(249, 115, 22, 0.2);
  --high: #f87171;
  --high-bg: rgba(239, 68, 68, 0.2);
  --danger: #fca5a5;
  --danger-bg: rgba(220, 38, 38, 0.28);
  --pill-bg: #334155;
  --pill-text: #cbd5e1;
  --pill-active-bg: rgba(34, 197, 94, 0.2);
  --pill-active-text: #86efac;
  --btn-sec-hover: #334155;
  --banner-warn-bg: rgba(245, 158, 11, 0.14);
  --banner-warn-border: rgba(245, 158, 11, 0.5);
  --banner-warn-text: #fde68a;
  --code-bg: rgba(56, 189, 248, 0.16);
  --code-text: #7dd3fc;
  --gauge-track: #334155;
  --gauge-marker: #f8fafc;
  --gauge-tip-text: #0f172a;
  --tick-bd1: #fbbf24;
  --tick-bd2: #fb923c;
  --tick-bd3: #f87171;
  --tick-hist: #fca5a5;
  --input-bg: #0f172a;
  --seg-active-text: #0f172a;
  --chart-grid: #334155;
  --chart-axis: #94a3b8;
  --chart-line: #38bdf8;
  --chart-area: #38bdf8;
  --chart-pt-stroke: #111827;
  --tooltip-bg: rgba(15, 23, 42, 0.96);
  --tooltip-text: #f8fafc;
  --lake-bar-bg: #334155;
  --lake-bar-fill: #38bdf8;
  --lake-releasing-bg: rgba(249, 115, 22, 0.14);
  --lake-releasing-border: rgba(251, 146, 60, 0.65);
  --lake-releasing-fill: #fb923c;
  --tag-basin-bg: rgba(56, 189, 248, 0.16);
  --tag-basin-text: #7dd3fc;
  --tag-release-bg: rgba(249, 115, 22, 0.22);
  --tag-release-text: #fdba74;
  --rain-heavy: #fbbf24;
  --rain-extreme: #f87171;
  --featured-bg: rgba(56, 189, 248, 0.1);
  --featured-border: rgba(56, 189, 248, 0.35);
  --featured-text: #cbd5e1;
  --bulletin-badge-bg: rgba(239, 68, 68, 0.22);
  --bulletin-badge-text: #fca5a5;
  --emergency-bg: rgba(239, 68, 68, 0.14);
  --emergency-border: rgba(248, 113, 113, 0.45);
  --emergency-text: #fecaca;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

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: #ffffff;
  padding: 16px 0;
  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: #e0f2fe;
}

.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: #e0f2fe;
}

.refresh-meta .muted {
  color: #bae6fd;
}

.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-primary {
  background: #ffffff;
  color: #0c4a6e;
}

.btn-primary:hover:not(:disabled) {
  background: #e0f2fe;
}

.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.28);
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  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;
}

.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;
}

.banner {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.9rem;
  border: 1px solid transparent;
}

.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: var(--shadow);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

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

.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: 1.65fr 1fr;
  gap: 18px;
}

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

.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;
}

.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 { background: #14b8a6; }
.zone-bd1 { background: #f59e0b; }
.zone-bd2 { background: #ea580c; }
.zone-bd3 {
  background: #dc2626;
  border-top-right-radius: 999px;
  border-bottom-right-radius: 999px;
}

.gauge-marker {
  position: absolute;
  top: -5px;
  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-ticks {
  position: relative;
  height: 22px;
  margin-top: 6px;
  font-size: 0.74rem;
  color: var(--muted);
}

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

.gauge-ticks .tick:first-child {
  transform: none;
}

.gauge-ticks .tick:last-child {
  transform: translateX(-85%);
}

.tick-bd1 { color: var(--tick-bd1); font-weight: 600; }
.tick-bd2 { color: var(--tick-bd2); font-weight: 600; }
.tick-bd3 { color: var(--tick-bd3); font-weight: 700; }
.tick-hist { color: var(--tick-hist); font-weight: 600; }

/* 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.74rem;
  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;
}

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

/* 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-btn.active {
  background: var(--primary);
  color: var(--seg-active-text);
}

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

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

.chart-empty {
  height: 280px;
  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.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
}

.tag-basin { background: var(--tag-basin-bg); color: var(--tag-basin-text); }
.tag-release { background: var(--tag-release-bg); color: var(--tag-release-text); }

.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 {
  overflow-x: auto;
}

.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);
}

.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:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.bulletin-badge {
  background: var(--bulletin-badge-bg);
  color: var(--bulletin-badge-text);
  font-size: 0.72rem;
  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: #f59e0b; }
.swatch.bd2 { background: #ea580c; }
.swatch.bd3 { background: #dc2626; }

.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;
}

.footer {
  padding: 0 16px 28px;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

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

@media (max-width: 640px) {
  .hero-metrics,
  .comparison-grid {
    grid-template-columns: 1fr;
  }

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

  .gauge-ticks {
    position: static;
    height: auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 4px 10px;
    font-size: 0.72rem;
  }

  .gauge-ticks .tick,
  .gauge-ticks .tick:last-child {
    position: static;
    transform: none;
  }

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