html,
        body {
            margin: 0;
            height: 100%;
            font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
            background: #08111c;
            color: #e5eef9;
        }

        :root {
            --panel-edge-gap: 14px;
            --cookie-reserve: 0px;
        }
        
        #map {
            position: absolute;
            inset: 0;
            contain: strict;
        }
        
        .panel {
            position: absolute;
            top: var(--panel-edge-gap);
            right: var(--panel-edge-gap);
            width: 360px;
            max-height: calc(100vh - (var(--panel-edge-gap) * 2) - var(--cookie-reserve));
            max-width: calc(100vw - (var(--panel-edge-gap) * 2));
            overflow: auto;
            z-index: 10;
            background: rgba(7, 16, 27, 0.96);
            border: 1px solid rgba(255, 255, 255, 0.12);
            border-radius: 16px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
            padding: 16px;
            will-change: transform;
            overscroll-behavior: contain;
        }

        .panel.collapsed {
            width: auto;
            max-height: none;
            overflow: visible;
            padding: 10px 12px;
        }

        .panel.collapsed .panel-body {
            display: none;
        }

        .panel-toggle {
            float: right;
            border: 1px solid rgba(255, 255, 255, 0.15);
            background: #0f172a;
            color: #e5eef9;
            border-radius: 8px;
            padding: 4px 10px;
            font-size: 12px;
            cursor: pointer;
        }

        .map-quick-controls {
            position: absolute;
            top: var(--panel-edge-gap);
            left: var(--panel-edge-gap);
            z-index: 11;
            display: grid;
            gap: 8px;
        }

        .quick-btn {
            border: 1px solid rgba(255, 255, 255, 0.14);
            background: rgba(7, 16, 27, 0.92);
            color: #e5eef9;
            border-radius: 10px;
            padding: 8px 10px;
            font-size: 12px;
            font-weight: 700;
            line-height: 1;
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
            min-width: 102px;
            text-align: center;
        }

        .quick-btn.secondary {
            background: rgba(15, 23, 42, 0.92);
        }
        
        .panel h1 {
            margin: 0 0 8px 0;
            font-size: 20px;
            line-height: 1.2;
        }
        
        .panel p {
            margin: 0 0 12px 0;
            font-size: 13px;
            line-height: 1.45;
            color: #b7c7db;
        }
        
        .group {
            margin: 14px 0;
            padding-top: 12px;
            border-top: 1px solid rgba(255, 255, 255, 0.08);
        }
        
        .group h2 {
            margin: 0 0 8px 0;
            font-size: 13px;
            text-transform: uppercase;
            letter-spacing: 0.06em;
            color: #78c4ff;
        }
        
        .row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
            margin: 8px 0;
            font-size: 13px;
        }
        
        .row label {
            display: flex;
            align-items: center;
            gap: 8px;
            cursor: pointer;
        }
        
        .stack {
            display: grid;
            gap: 8px;
        }
        
        .btns {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 8px;
            margin-top: 10px;
        }
        
        button {
            border: none;
            border-radius: 10px;
            padding: 10px 12px;
            background: #1d4ed8;
            color: white;
            font-weight: 600;
            cursor: pointer;
        }
        
        button.secondary {
            background: #0f172a;
            border: 1px solid rgba(255, 255, 255, 0.12);
        }
        
        input[type="range"],
        select {
            width: 100%;
        }
        
        select {
            background: #0f172a;
            color: #e5eef9;
            border: 1px solid rgba(255, 255, 255, 0.12);
            border-radius: 10px;
            padding: 8px 10px;
        }
        
        .metric-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 8px;
            margin-top: 10px;
        }
        
        .metric {
            background: rgba(255, 255, 255, 0.04);
            border: 1px solid rgba(255, 255, 255, 0.08);
            border-radius: 12px;
            padding: 10px;
        }
        
        .metric .label {
            font-size: 11px;
            color: #95abc3;
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }
        
        .metric .value {
            font-size: 18px;
            font-weight: 700;
            margin-top: 4px;
            color: #f8fbff;
        }

        .metric .subvalue {
            margin-top: 4px;
            font-size: 11px;
            color: #95abc3;
            line-height: 1.35;
        }
        
        .legend {
            display: grid;
            gap: 7px;
            font-size: 12px;
            color: #c7d6e7;
        }
        
        .legend-item {
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .swatch {
            width: 14px;
            height: 14px;
            border-radius: 4px;
            flex: 0 0 14px;
        }
        
        .swatch.boundary {
            background: #38bdf8;
        }
        
        .swatch.station {
            background: #eab308;
        }
        
        .swatch.confirmed {
            background: #ef4444;
        }
        
        .swatch.high-toxin {
            background: #7f1d1d;
        }
        
        .swatch.suspicious {
            background: #f59e0b;
        }
        
        .swatch.outfall {
            background: #a855f7;
        }

        .swatch.access {
            background: #2e84d7;
        }

        .swatch.spdes-surface {
            background: #2f9bc9;
        }

        .swatch.spdes-ground {
            background: #2f7d32;
        }

        .swatch.flow-path {
            background: #f87171;
        }

        .swatch.dem-ws {
            background: #34d399;
        }

        .swatch.pour-point {
            background: #a855f7;
        }

        .swatch.forecast-low {
            background: #22c55e;
            border-radius: 50%;
        }

        .swatch.forecast-watch {
            background: #eab308;
            border-radius: 50%;
        }

        .swatch.forecast-elevated {
            background: #f97316;
            border-radius: 50%;
        }

        .swatch.forecast-high {
            background: #dc2626;
            border-radius: 50%;
        }

        .forecast-disclaimer {
            padding: 9px 10px;
            border-left: 3px solid #f59e0b;
            border-radius: 8px;
            background: rgba(245, 158, 11, 0.09);
            color: #d8e4f1;
            font-size: 11px;
            line-height: 1.45;
        }

        .forecast-why {
            margin-top: 9px;
            padding: 10px;
            border: 1px solid rgba(120, 196, 255, 0.2);
            border-radius: 10px;
            background: rgba(56, 189, 248, 0.07);
            color: #d7e5f4;
            font-size: 12px;
            line-height: 1.45;
        }

        .risk-low { color: #4ade80 !important; }
        .risk-watch { color: #fde047 !important; }
        .risk-elevated { color: #fb923c !important; }
        .risk-high { color: #f87171 !important; }
        
        .field-label {
            font-size: 12px;
            margin-bottom: 4px;
            color: #a9bfd6;
        }
        
        .terrain-value {
            margin-bottom: 6px;
            font-size: 13px;
        }
        
        .status {
            margin-top: 8px;
            font-size: 12px;
            color: #9dc5e8;
            white-space: pre-line;
        }
        
        .maplibregl-popup-content {
            background: #09131f;
            color: #e5eef9;
            border-radius: 12px;
            border: 1px solid rgba(255, 255, 255, 0.08);
            padding: 12px 14px;
            min-width: 240px;
            max-width: 320px;
        }
        
        .maplibregl-popup-close-button {
            color: white;
        }
        
        .popup-title {
            font-weight: 700;
            margin-bottom: 6px;
            color: #8bd2ff;
        }
        
        .popup-grid {
            display: grid;
            gap: 4px;
            font-size: 12px;
            color: #d7e5f4;
        }

        .popup-subtitle {
            font-size: 11px;
            color: #8aa8c4;
            margin-bottom: 8px;
        }

        .popup-citation {
            margin-top: 10px;
            padding-top: 8px;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            font-size: 10px;
            color: #8aa8c4;
            line-height: 1.45;
        }

        .popup-citation a {
            color: #8bd2ff;
        }
        
        .credit {
            margin-top: 12px;
            font-size: 11px;
            color: #89a7c5;
        }

        .metric.highlight .value {
            color: #fbbf24;
        }

        .metric.wide {
            grid-column: 1 / -1;
        }

        .nutrient-note {
            margin-top: 8px;
            font-size: 11px;
            line-height: 1.45;
            color: #89a7c5;
        }

        button:disabled {
            opacity: 0.55;
            cursor: not-allowed;
        }

        /* ===== UI: TABBED CONTROL PANEL ===== */
        .panel-header {
            padding-right: 72px;
        }

        .panel-header p {
            margin-bottom: 10px;
        }

        .tabs {
            display: grid;
            grid-template-columns: repeat(4, minmax(0, 1fr));
            gap: 4px;
            position: sticky;
            top: -16px;
            z-index: 4;
            margin: 0 -4px 10px;
            padding: 8px 4px;
            background: rgba(7, 16, 27, 0.98);
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        .tab {
            min-width: 0;
            padding: 8px 5px;
            border-radius: 8px;
            background: transparent;
            color: #a9bfd6;
            font-size: 11px;
            line-height: 1.2;
        }

        .tab[aria-selected="true"] {
            background: #1d4ed8;
            color: #fff;
        }

        .tab-panel[hidden] {
            display: none;
        }

        button:focus-visible,
        input:focus-visible,
        select:focus-visible,
        summary:focus-visible,
        [role="tab"]:focus-visible {
            outline: 3px solid #fbbf24;
            outline-offset: 2px;
        }

        details.advanced {
            margin: 12px 0;
            border: 1px solid rgba(120, 196, 255, 0.18);
            border-radius: 12px;
            background: rgba(56, 189, 248, 0.04);
        }

        details.advanced > summary {
            padding: 10px 12px;
            cursor: pointer;
            color: #9ed8ff;
            font-size: 12px;
            font-weight: 700;
        }

        details.advanced > .advanced-body {
            padding: 0 12px 12px;
        }

        .conditions-card {
            display: grid;
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 8px;
            margin: 10px 0;
        }

        .condition-item {
            min-width: 0;
            padding: 9px;
            border: 1px solid rgba(255, 255, 255, 0.09);
            border-radius: 11px;
            background: rgba(255, 255, 255, 0.045);
        }

        .condition-item .label {
            color: #95abc3;
            font-size: 10px;
            letter-spacing: 0.05em;
            text-transform: uppercase;
        }

        .condition-item .value {
            overflow-wrap: anywhere;
            margin-top: 4px;
            color: #f8fbff;
            font-size: 15px;
            font-weight: 700;
        }

        .inline-actions {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            align-items: center;
            margin-top: 9px;
        }

        .inline-actions button {
            flex: 1 1 120px;
        }

        .selection-card {
            padding: 11px;
            border: 1px solid rgba(168, 85, 247, 0.35);
            border-radius: 12px;
            background: rgba(168, 85, 247, 0.08);
        }

        .selection-card strong {
            color: #d8b4fe;
        }

        .source-list {
            display: grid;
            gap: 7px;
        }

        .source-row {
            display: grid;
            grid-template-columns: minmax(0, 1fr) auto;
            gap: 8px;
            align-items: center;
            padding: 8px 9px;
            border-radius: 9px;
            background: rgba(255, 255, 255, 0.04);
            font-size: 12px;
        }

        .source-state {
            border-radius: 999px;
            padding: 3px 7px;
            background: #334155;
            color: #e5eef9;
            font-size: 10px;
            text-transform: uppercase;
        }

        .source-state.ready { background: #166534; }
        .source-state.cached { background: #854d0e; }
        .source-state.loading { background: #1d4ed8; }
        .source-state.unavailable { background: #991b1b; }

        .source-actions {
            display: flex;
            gap: 5px;
            align-items: center;
        }

        .source-retry {
            padding: 4px 7px;
            border-radius: 7px;
            font-size: 10px;
        }

        .help-text {
            color: #a9bfd6;
            font-size: 12px;
            line-height: 1.45;
        }
        
        @media (max-width: 900px) {
            :root {
                --cookie-reserve: 150px;
            }

            .panel {
                width: min(360px, calc(100vw - (var(--panel-edge-gap) * 2)));
                max-height: min(42vh, calc(100vh - (var(--panel-edge-gap) * 2) - var(--cookie-reserve)));
            }
            .panel.collapsed {
                width: auto;
                max-height: none;
            }

            .map-quick-controls {
                top: auto;
                left: var(--panel-edge-gap);
                bottom: calc(var(--panel-edge-gap) + var(--cookie-reserve));
                grid-template-columns: repeat(3, minmax(0, 1fr));
                width: min(320px, calc(100vw - (var(--panel-edge-gap) * 2)));
            }

            .quick-btn {
                min-width: 0;
            }

            .tabs {
                grid-template-columns: repeat(4, minmax(78px, 1fr));
                overflow-x: auto;
            }

            .tab {
                min-height: 42px;
            }
        }

        @media (max-width: 900px) and (max-height: 820px) {
            :root {
                --cookie-reserve: 180px;
            }
        }
