@font-face {
    font-family: 'Public Sans';
    src: url('../assets/fonts/PublicSans-Regular.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Public Sans';
    src: url('../assets/fonts/PublicSans-Medium.woff2') format('woff2');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Public Sans';
    src: url('../assets/fonts/PublicSans-Bold.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Departure Mono';
    src: url('../assets/fonts/DepartureMono-Regular.woff2') format('woff2');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Departure Mono';
    src: url('../assets/fonts/DepartureMono-Regular.woff2') format('woff2');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

/* ── Variables ────────────────────────────────────────────────────────────── */
:root {
    --bg:           #0d1117;
    --surface:      #161b22;
    --surface2:     #21262d;
    --border:       #30363d;
    --text:         #e6edf3;
    --text-muted:   #8b949e;
    --normal:       #3fb950;
    --caution:      #d29922;
    --flood:        #f85149;
    --unknown:      #58a6ff;
    --rain:         #58a6ff;
    --offline:      #8b1a1a;
    --trend-up:     #f85149;
    --trend-down:   #3fb950;
    --trend-flat:   #8b949e;
    --accent:       #58a6ff;
    --ch-color:     #5b8fa8;
}

/* ── Light theme (HAL 9000 warm off-white) ────────────────────────────────── */
[data-theme="light"] {
    --bg:           #f0ebe0;
    --surface:      #e8e2d4;
    --surface2:     #ddd8cc;
    --border:       #c4beb4;
    --text:         #2c2c2a;
    --text-muted:   #7a7670;
    --normal:       #2d8a3e;
    --caution:      #a07820;
    --flood:        #c0392b;
    --unknown:      #5a7a9a;
    --rain:         #4a6e8a;
    --offline:      #6e2a2a;
    --trend-up:     #c0392b;
    --trend-down:   #2d8a3e;
    --trend-flat:   #7a7670;
    --accent:       #8a8278;
    --ch-color:     #6a8a9a;
}

[data-theme="light"] .leaflet-tile-pane {
    filter: brightness(1.0) saturate(0.75) sepia(0.12);
}

[data-theme="light"] .leaflet-popup-content-wrapper,
[data-theme="light"] .leaflet-popup-tip {
    background: var(--surface);
    border-color: var(--border);
}

[data-theme="light"] .leaflet-control-zoom a {
    background: var(--surface) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}

[data-theme="light"] .leaflet-control-zoom a:hover {
    background: var(--surface2) !important;
}

[data-theme="light"] .leaflet-control-attribution {
    background: rgba(240,235,224,0.85) !important;
    color: var(--text-muted) !important;
}

[data-theme="light"] .gage-tooltip {
    background: rgba(232,226,212,0.97) !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
}

[data-theme="light"] .stat-chip {
    background: rgba(240,235,224,0.92);
    border-color: var(--border);
}

[data-theme="light"] .ht-tube {
    background: rgba(221,216,204,0.95);
    border-color: var(--border);
}

[data-theme="light"] .ht-offline-wrap {
    background: rgba(232,226,212,0.97);
    border-color: var(--border);
}

[data-theme="light"] .gage-num-label {
    background: rgba(240,235,224,0.85);
    border-color: rgba(44,44,42,0.15);
    color: var(--text);
}

[data-theme="light"] .settings-btn {
    background: var(--surface) !important;
    color: var(--text-muted) !important;
    border-color: var(--border) !important;
}

[data-theme="light"] .settings-btn:hover {
    background: var(--surface2) !important;
    color: var(--text) !important;
}

[data-theme="light"] .settings-panel {
    background: var(--surface);
    border-color: var(--border);
}

[data-theme="light"] .settings-title {
    color: var(--text-muted);
    border-color: var(--border);
}

[data-theme="light"] .settings-label { color: var(--text-muted); }

[data-theme="light"] .settings-opt {
    background: var(--surface2);
    border-color: var(--border);
    color: var(--text-muted);
}

[data-theme="light"] .settings-opt:hover {
    background: var(--border);
    color: var(--text);
}

[data-theme="light"] .settings-opt.active {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

[data-theme="light"] .ws-btn {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text-muted);
}

[data-theme="light"] .ws-btn:hover {
    background: var(--surface2);
    color: var(--text);
    border-color: var(--accent);
}

[data-theme="light"] .ws-btn.active {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

[data-theme="light"] #watershed-toolbar {
    background: var(--bg);
    border-color: var(--border);
}

[data-theme="light"] header {
    background: var(--surface);
    border-color: var(--border);
}

[data-theme="light"] .ws-dropdown {
    background: var(--surface);
    border-color: var(--border);
}

[data-theme="light"] .ws-dropdown-item:hover {
    background: var(--surface2);
}

[data-theme="light"] .ws-dropdown-item.active {
    color: var(--accent);
}

[data-theme="light"] .search-bar-wrap {
    background: var(--surface) !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
}

[data-theme="light"] .search-btn {
    color: var(--text-muted) !important;
}

[data-theme="light"] .search-input {
    background: transparent !important;
    color: var(--text) !important;
}

[data-theme="light"] .search-results {
    background: var(--surface) !important;
    border-color: var(--border) !important;
}

[data-theme="light"] .search-result-item:hover {
    background: var(--surface2) !important;
}

[data-theme="light"] .search-group-label {
    color: var(--text-muted) !important;
    border-color: var(--border) !important;
}

[data-theme="light"] .pulse {
    background: var(--normal);
}

/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: 'Public Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
}

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

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.65rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 1000;
}

.logo {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

.logo span { color: var(--accent); }

.header-meta {
    font-family: 'Departure Mono', monospace;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

#last-updated b { color: var(--text); }

/* ── Pulse indicator ──────────────────────────────────────────────────────── */
.pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--normal);
    animation: pulse-ring 2s infinite;
    flex-shrink: 0;
}

@keyframes pulse-ring {
    0%   { box-shadow: 0 0 0 0 rgba(63,185,80,0.5); }
    70%  { box-shadow: 0 0 0 6px rgba(63,185,80,0); }
    100% { box-shadow: 0 0 0 0 rgba(63,185,80,0); }
}

/* ── Legend ───────────────────────────────────────────────────────────────── */
.legend {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    font-size: 0.7rem;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.25);
}

.legend-raindrop {
    width: 9px;
    height: 12px;
    background: var(--rain);
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    opacity: 0.85;
    flex-shrink: 0;
}

.legend-triangle {
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 11px solid var(--offline);
    flex-shrink: 0;
}

/* ── Watershed toolbar ────────────────────────────────────────────────────── */
#watershed-toolbar {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 1.25rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    overflow-x: auto;
    scrollbar-width: none;
    z-index: 999;
}

#watershed-toolbar::-webkit-scrollbar { display: none; }

.toolbar-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    white-space: nowrap;
    margin-right: 0.25rem;
    flex-shrink: 0;
}

.ws-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.22rem 0.6rem;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-family: 'Public Sans', sans-serif;
    font-size: 0.7rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    flex-shrink: 0;
}

.ws-btn:hover {
    background: var(--surface2);
    color: var(--text);
    border-color: var(--accent);
}

.ws-btn.active {
    background: var(--accent);
    color: #0d1117;
    border-color: var(--accent);
    font-weight: 600;
}

.ws-btn.overflow-active {
    border-color: var(--accent);
    color: var(--accent);
}

.ws-count {
    font-family: 'Departure Mono', monospace;
    font-size: 0.62rem;
    opacity: 0.7;
}

/* ── Watershed dropdown ───────────────────────────────────────────────────── */
.ws-dropdown {
    position: fixed;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 2000;
    min-width: 160px;
    max-height: 260px;
    overflow-y: auto;
    padding: 0.3rem 0;
}

.ws-dropdown-item {
    padding: 0.4rem 0.85rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.1s, color 0.1s;
}

.ws-dropdown-item:hover {
    background: var(--surface2);
    color: var(--text);
}

.ws-dropdown-item.active {
    color: var(--accent);
    font-weight: 600;
}

/* ── Map container ────────────────────────────────────────────────────────── */
#map {
    flex: 1;
    position: relative;
}

.leaflet-tile-pane {
    filter: brightness(0.85) saturate(0.7);
}

/* ── Stream gage markers ──────────────────────────────────────────────────── */
.gage-icon-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.gage-marker {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.25);
    cursor: pointer;
    position: relative;
    transition: opacity 0.3s;
}

.gage-marker.status-normal  { background: rgba(63,185,80,0.6); }
.gage-marker.status-caution { background: rgba(210,153,34,0.6); }
.gage-marker.status-flood   { background: rgba(248,81,73,0.6); box-shadow: 0 0 8px rgba(248,81,73,0.5); }
.gage-marker.status-unknown { background: rgba(88,166,255,0.35); }

/* ── Gage number label ────────────────────────────────────────────────────── */
.gage-num-label {
    display: none;
    font-family: 'Departure Mono', monospace;
    font-size: 0.55rem;
    color: var(--text-muted);
    background: rgba(13,17,23,0.75);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 3px;
    padding: 0 3px;
    margin-top: 2px;
    white-space: nowrap;
    pointer-events: none;
    line-height: 1.5;
}

/* ── Rain gage marker ─────────────────────────────────────────────────────── */
.rain-marker-svg {
    cursor: pointer;
    transition: opacity 0.3s;
}

/* ── Offline/unresponsive marker ──────────────────────────────────────────── */
.offline-marker-svg {
    display: block;
    cursor: pointer;
    transition: opacity 0.3s;
}

/* ── Ripple animation ─────────────────────────────────────────────────────── */
.gage-ripple {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    transform: translate(-50%,-50%) scale(1);
    opacity: 0.75;
    pointer-events: none;
    animation: ripple-out 1.3s ease-out forwards;
}

@keyframes ripple-out {
    0%   { transform: translate(-50%,-50%) scale(1); opacity: 0.75; }
    100% { transform: translate(-50%,-50%) scale(4); opacity: 0; }
}

/* ── Hover tooltip ────────────────────────────────────────────────────────── */
.gage-hover-tooltip {
    position: fixed;
    z-index: 3000;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.ht-site-num {
    font-family: 'Departure Mono', monospace;
    font-size: 0.62rem;
    color: var(--accent);
    margin-bottom: 0.3rem;
    letter-spacing: 0.04em;
}

.ht-tube-wrap {
    display: flex;
    justify-content: center;
}

.ht-tube {
    width: 18px;
    height: 72px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 9px;
    position: relative;
    overflow: hidden;
    will-change: transform;
}

.ht-tob-line {
    position: absolute;
    left: 0; right: 0; top: 0;
    height: 2px;
    background: rgba(248,81,73,0.9);
    z-index: 3;
}

.ht-fli-line {
    position: absolute;
    left: 0; right: 0;
    height: 1px;
    background: rgb(255, 215, 0);
    z-index: 3;
}

.ht-fill {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: rgba(88,166,255,0.55);
    border-radius: 0 0 9px 9px;
    transition: height 0.6s cubic-bezier(0.4,0,0.2,1);
}

.ht-rain-fill {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    border-radius: 0 0 9px 9px;
    background: linear-gradient(to top, rgba(88,166,255,0.85), rgba(88,166,255,0.35));
    transition: height 0.6s cubic-bezier(0.4,0,0.2,1);
}

.ht-rain-val {
    font-family: 'Departure Mono', monospace;
    font-size: 0.6rem;
    color: var(--rain);
    margin-top: 0.25rem;
}

.ht-no-data {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-style: italic;
    padding: 0.4rem 0.6rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.ht-offline-wrap {
    background: rgba(22,27,34,0.96);
    border: 1px solid #30363d;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    padding: 0.4rem 0.6rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
}

.ht-offline-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: #e05050;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.ht-offline-time {
    font-family: 'Departure Mono', monospace;
    font-size: 0.6rem;
    color: var(--text-muted);
}

/* ── Popup wrapper ────────────────────────────────────────────────────────── */
.leaflet-popup-content-wrapper {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    padding: 0;
}

.leaflet-popup-tip { background: var(--surface); }
.leaflet-popup-content { margin: 0; width: auto !important; }

/* ── Popup layout ─────────────────────────────────────────────────────────── */
.popup {
    min-width: 300px;
    max-width: 420px;
}

.popup-header {
    padding: 0.7rem 1rem 0.65rem;
    border-bottom: 1px solid var(--border);
}

.popup-site-id {
    font-family: 'Departure Mono', monospace;
    font-size: 0.75rem;
    color: var(--accent);
    letter-spacing: 0.05em;
    margin-bottom: 0.18rem;
}

.popup-name {
    color: var(--text);
    font-family: 'Public Sans', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.3;
}

.popup-unitno {
    font-family: 'Departure Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.12rem;
    letter-spacing: 0.04em;
}

.popup-watershed {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.12rem;
    /*font-style: italic;*/
}

/* Status bar — shared base */
.popup-status-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 1rem;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

/* Stream variant: badge · level · timestamp spread full width */
.popup-status-bar--stream {
    justify-content: space-between;
}

.popup-lvl-inline {
    font-family: 'Departure Mono', monospace;
    display: inline-flex;
    align-items: center;
    background-color: #ffffff22;
    border-radius: 20px;
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text);
    padding: 0.05rem 0.5rem;
    text-align: center;
}

.popup-ts-inline {
    font-family: 'Departure Mono', monospace;
    align-items: center;
    border-radius: 20px;
    font-size: 0.65rem;
    color: var(--text-muted);
    padding: 0.05rem 0.5rem;
    white-space: nowrap;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    border-radius: 20px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
    flex-shrink: 0;
}

.status-badge.normal  { background: rgba(63,185,80,0.15);  color: var(--normal); }
.status-badge.caution { background: rgba(210,153,34,0.15); color: var(--caution); }
.status-badge.flood   { background: rgba(248,81,73,0.15);  color: var(--flood); }
.status-badge.unknown { background: rgba(88,166,255,0.12); color: var(--unknown); }
.status-badge.rain    { background: rgba(88,166,255,0.15); color: var(--rain); }
.status-badge.offline { background: rgba(139,26,26,0.2);   color: #e05050; }

/* Popup body */
.popup-body {
    padding: 0.75rem 1rem;
    display: flex;
    gap: 0;
    align-items: flex-start;
}

.popup-body--cols {
    padding: 0;
}

.popup-body--no-rain .popup-stream-col {
    width: 100%;
    border-right: none;
}

.popup-stream-col {
    width: 66.66%;
    padding: 0.75rem 0.75rem 0.75rem 1rem;
    border-right: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.popup-body--rain-only {
    justify-content: center;
    padding: 0.85rem 1rem;
}

.popup-col-label {
    font-family: 'Public Sans', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-muted);
    line-height: 1.3;
    text-align: center;
}

.popup-col-sublabel {
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.6rem;
}

/* ── Annotated tube diagram ───────────────────────────────────────────────── */

.gage-diagram-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    user-select: none;
}

.gage-diagram {
    display: flex;
    align-items: stretch;
    gap: 4px;
}

/* ── Left gutter ─────────────────────────────────────────────────────────── */
.tube-ann-col {
    position: relative;
    width: 80px;
    flex-shrink: 0;
    height: 200px;
}

.tube-ann {
    position: absolute;
    right: 0;
    font-family: 'Departure Mono', monospace;
    font-size: 0.6rem;
    line-height: 1;
    pointer-events: none;
    white-space: nowrap;
    text-align: right;
}

/* TOB: text only, centred on TOB line at bottom:89% */
.tube-ann--tob {
    color: #d09f63;
    bottom: 89%;
    /*transform: translateY(50%);*/
}

/* FLI: centred on FLI line; bottom:X% set inline */
.tube-ann--fli {
    color: rgb(255, 215, 0);
    /*transform: translateY(50%);*/
}

/* BOC: centred on absolute bottom of tube (bottom:0) */
.tube-ann--boc {
    color: var(--text-muted);
    bottom: 0;
    transform: translateY(1.4em);
}

/* ── Tube ────────────────────────────────────────────────────────────────── */
.gage-tube {
    width: 40px;
    height: 200px;
    background: var(--surface2);
    border-radius: 20px;
    border: 1px solid var(--border);
    position: relative;
    flex-shrink: 0;
    overflow: hidden;
}

.gage-tube-fill {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    border-radius: 0 0 20px 20px;
    background: linear-gradient(to top, rgba(88,166,255,0.85), rgba(88,166,255,0.45));
    transition: height 0.9s cubic-bezier(0.4,0,0.2,1);
}

/* TOB line — bottom:89% set inline */
.gage-tob-line {
    position: absolute;
    left: 0; right: 0;
    height: 2px;
    background: rgba(184,149,106,0.9);
    z-index: 4;
}

/* TOB value — just above TOB line; bottom:% set inline */
.tube-tob-val {
    position: absolute;
    left: 0; right: 0;
    text-align: center;
    font-family: 'Departure Mono', monospace;
    font-size: 0.6rem;
    font-weight: 400;
    color: #d09f63;
    z-index: 5;
    line-height: 1;
    pointer-events: none;
}

/* FLI line — bottom:% set inline */
.gage-fli-line {
    position: absolute;
    left: 0; right: 0;
    height: 1px;
    background: rgb(255, 215, 0);
    z-index: 4;
}

/* FLI elevation value — bottom:% set inline */
.tube-fli-val {
    position: absolute;
    left: 0; right: 0;
    text-align: center;
    font-family: 'Departure Mono', monospace;
    font-size: 0.6rem;
    font-weight: 400;
    color: rgb(255, 215, 0);
    z-index: 5;
    line-height: 1;
    pointer-events: none;
}

/* Current level label — bottom:% set inline */
.tube-lvl {
    position: absolute;
    left: 0; right: 0;
    text-align: center;
    font-family: 'Departure Mono', monospace;
    font-size: 0.62rem;
    font-weight: 400;
    color: rgba(88,166,255,0.85);
    z-index: 6;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    line-height: 1;
}

.tube-lvl--inside {
    color: rgba(30,30,28,0.9);
}

[data-theme="light"] .tube-lvl--inside {
    color: rgba(255,255,255,0.92);
}

.tube-lvl-val { line-height: 1; }

.tube-arrow { font-size: 0.45rem; line-height: 1; }
.tube-arrow--up   { color: var(--trend-up); }
.tube-arrow--dn   { color: var(--trend-down); }
.tube-arrow--flat { color: var(--trend-flat); }

/* BOC value: centred directly below the tube.
   Uses the same gutter+gap offset so it aligns under the tube face. */
.tube-boc-row {
    display: flex;
    gap: 4px;
    margin-top: 0.2rem;
    align-items: baseline;
}

.tube-boc-spacer {
    width: 80px;
    flex-shrink: 0;
}

.tube-boc-val {
    width: 40px;
    text-align: center;
    font-family: 'Departure Mono', monospace;
    font-size: 0.6rem;
    font-weight: 400;
    color: var(--text-muted);
    line-height: 1;
}

/* ── Rain column (right 1/3) ──────────────────────────────────────────────── */
.popup-rain-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.75rem 0.75rem 0.75rem 0.5rem;
    gap: 0.3rem;
}

.popup-rain-tube-wrap {
    flex: 1;
    display: flex;
    align-items: center;
}

.popup-rain-tube {
    width: 40px;
    height: 200px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 20px;
    position: relative;
    overflow: hidden;
}

.popup-rain-fill {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    border-radius: 0 0 20px 20px;
    background: linear-gradient(to top, rgba(88,166,255,0.85), rgba(88,166,255,0.4));
    transition: height 0.6s cubic-bezier(0.4,0,0.2,1);
}

.popup-rain-val {
    font-family: 'Departure Mono', monospace;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--rain);
    text-align: center;
}

/* ── Misc popup elements ──────────────────────────────────────────────────── */
.sensor-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.3rem 0;
}

.trend { font-size: 0.8rem; margin-left: 0.15rem; }
.trend.up   { color: var(--trend-up); }
.trend.down { color: var(--trend-down); }
.trend.flat { color: var(--trend-flat); }

.no-data {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    padding: 0.2rem 0;
}

.popup-footer {
    padding: 0.45rem 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.popup-timestamp {
    font-family: 'Departure Mono', monospace;
    font-size: 0.65rem;
    color: var(--text-muted);
}

.popup-link {
    font-size: 0.72rem;
    color: var(--accent);
    text-decoration: none;
}

.popup-link:hover { text-decoration: underline; }

/* ── Stats bar ────────────────────────────────────────────────────────────── */
#stats-bar {
    position: absolute;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    gap: 0.5rem;
    pointer-events: none;
}

.stat-chip {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    background: rgba(22,27,34,0.92);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.72rem;
    backdrop-filter: blur(8px);
}

.stat-chip .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ── Leaflet overrides ────────────────────────────────────────────────────── */
.gage-tooltip {
    background: rgba(22,27,34,0.95) !important;
    border: 1px solid #30363d !important;
    border-radius: 4px !important;
    color: #e6edf3 !important;
    font-family: 'Public Sans', sans-serif !important;
    font-size: 0.75rem !important;
    padding: 0.25rem 0.6rem !important;
    white-space: nowrap !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4) !important;
}

.gage-tooltip::before { display: none !important; }

.leaflet-popup-close-button {
    color: #8b949e !important;
    font-size: 1rem !important;
    top: 6px !important;
    right: 8px !important;
}

.leaflet-popup-close-button:hover { color: #e6edf3 !important; }

.leaflet-control-zoom a {
    background: #161b22 !important;
    color: #e6edf3 !important;
    border-color: #30363d !important;
}

.leaflet-control-zoom a:hover { background: #21262d !important; }

.leaflet-control-attribution {
    background: rgba(13,17,23,0.8) !important;
    color: #8b949e !important;
    font-size: 0.65rem !important;
}

.leaflet-control-attribution a { color: #58a6ff !important; }

/* ── Channel labels ───────────────────────────────────────────────────────── */
.channel-label {
    font-family: 'Departure Mono', monospace;
    font-size: 9px;
    fill: #7ab3cc;
    opacity: 0.85;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* ── Search control ───────────────────────────────────────────────────────── */
.search-control {
    margin-top: 0.5rem;
    position: relative;
}

.search-bar-wrap {
    display: flex;
    align-items: center;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 4px;
    overflow: visible;
    height: 30px;
}

.search-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 28px;
    background: transparent;
    border: none;
    color: #8b949e;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    transition: color 0.15s;
}

.search-btn:hover { color: #e6edf3; }

.search-input {
    width: 200px;
    height: 28px;
    background: transparent;
    border: none;
    color: #e6edf3;
    font-family: 'Public Sans', sans-serif;
    font-size: 0.75rem;
    padding: 0 0.5rem 0 0.25rem;
    outline: none;
}

.search-input::placeholder { color: #8b949e; }

.search-results {
    position: absolute;
    top: 32px;
    left: 0;
    min-width: 240px;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 4px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 2000;
    max-height: 320px;
    overflow-y: auto;
}

.search-group-label {
    padding: 0.35rem 0.75rem 0.2rem;
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #8b949e;
    border-bottom: 1px solid #30363d;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    font-size: 0.75rem;
    color: #e6edf3;
    transition: background 0.1s;
}

.search-result-item:hover { background: #21262d; }

.search-result-id {
    font-family: 'Departure Mono', monospace;
    font-size: 0.65rem;
    color: #58a6ff;
    flex-shrink: 0;
    min-width: 2.5rem;
}

.search-result-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-empty {
    padding: 0.6rem 0.75rem;
    font-size: 0.75rem;
    color: #8b949e;
    font-style: italic;
}

/* ── Settings control ─────────────────────────────────────────────────────── */
.settings-control {
    margin-top: 0.5rem;
}

.settings-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 30px !important;
    height: 30px !important;
    background: #161b22 !important;
    color: #8b949e !important;
    border-color: #30363d !important;
    transition: color 0.15s, background 0.15s;
}

.settings-btn:hover {
    background: #21262d !important;
    color: #e6edf3 !important;
}

.settings-panel {
    position: absolute;
    left: 34px;
    top: 0;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    padding: 0.75rem;
    min-width: 180px;
    z-index: 1000;
}

.settings-title {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #8b949e;
    margin-bottom: 0.6rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #30363d;
}

.settings-section {
    margin-bottom: 0.6rem;
}

.settings-label {
    font-size: 0.72rem;
    color: #8b949e;
    margin-bottom: 0.35rem;
}

.settings-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.settings-opt {
    padding: 0.2rem 0.5rem;
    border-radius: 20px;
    border: 1px solid #30363d;
    background: #21262d;
    color: #8b949e;
    font-family: 'Departure Mono', monospace;
    font-size: 0.68rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.settings-opt:hover {
    background: #30363d;
    color: #e6edf3;
}

.settings-opt.active {
    background: #58a6ff;
    color: #0d1117;
    border-color: #58a6ff;
    font-weight: 600;
}

/* ── Rain overlay canvas ──────────────────────────────────────────────────── */
#rain-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 450;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
    .legend { display: none; }
}
