:root {
    /* Brand Colors - Purple Roof */
    --brand-primary: #7e22ce;
    --brand-dark: #6b21a8;
    --brand-light: #9333ea;
    --brand-accent: #16a34a;
    
    /* Light Theme Backgrounds */
    --bg-base: #f4f7f6;
    --bg-panel: #ffffff;
    --bg-input: #f8fafc;
    --border-color: #cbd5e1;
    
    /* Text */
    --text-main: #1e293b;
    --text-muted: #64748b;
    
    /* Fonts */
    --font-head: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;

    /* Metrics */
    --radius-lg: 16px;
    --radius-md: 8px;
    --spacing: 24px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-base);
    color: var(--text-main);
    font-family: var(--font-body);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* Background */
.app-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
}

/* UI Structure */
.glass-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.01);
}

.app-header {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 14px 20px;
    padding: 1rem 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border-color);
}

.header-top-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 1 auto;
    min-width: 0;
}

/* Page footer — license reminder (tools using this stylesheet) */
.app-license-footer {
    margin-top: var(--spacing);
    padding: 0.65rem var(--spacing);
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    box-shadow: none;
}

.app-license-footer .license-notice-strip {
    font-size: 0.72rem;
    line-height: 1.45;
    color: var(--text-muted);
    margin: 0;
    text-align: center;
    max-width: 1600px;
    margin-left: auto;
    margin-right: auto;
}

.app-license-footer .license-notice-strip a {
    color: var(--brand-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.app-license-footer .license-notice-strip a:hover {
    text-decoration-thickness: 2px;
}

.nav-menu-toggle {
    display: none;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-input);
    color: var(--text-main);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.nav-menu-toggle:hover {
    background: rgba(126, 34, 206, 0.08);
    border-color: var(--brand-primary);
}

.nav-menu-bars {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 22px;
    height: 18px;
}

.nav-menu-bars span {
    display: block;
    height: 2px;
    width: 100%;
    background: currentColor;
    border-radius: 1px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.app-header.nav-menu-open .nav-menu-bars span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.app-header.nav-menu-open .nav-menu-bars span:nth-child(2) {
    opacity: 0;
}

.app-header.nav-menu-open .nav-menu-bars span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.top-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 12px 14px;
    margin-left: auto;
    flex: 1 1 auto;
    min-width: 0;
}

.top-nav .nav-btn,
.top-nav .nav-link {
    flex-shrink: 0;
}

.nav-link {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    min-width: 0;
}

.logo-wordmark {
    display: block;
    height: 1.85rem;
    width: auto;
    max-width: min(42vw, 220px);
    max-height: 2rem;
    object-fit: contain;
    flex-shrink: 0;
}

.logo-icon {
    font-size: 2rem;
}

.logo-text-wrapper {
    display: flex;
    flex-direction: column;
}

.logo-text {
    font-family: var(--font-head);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.highlight {
    color: var(--brand-accent);
}

.subtext {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* Header offset (~5rem): tools row fills the viewport band so the sidebar scrolls, not the graph column. */
.app-grid {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: var(--spacing);
    padding: var(--spacing);
    max-width: 1600px;
    margin: 0 auto;
    align-items: stretch;
    min-height: 0;
    height: calc(100vh - 5rem);
    max-height: calc(100vh - 5rem);
    height: calc(100dvh - 5rem);
    max-height: calc(100dvh - 5rem);
}

/* Controls Panel */
.controls-panel {
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: var(--spacing);
    gap: var(--spacing);
}

/* Scrollbar hiding but keeps functionality for panels */
.scroller::-webkit-scrollbar { width: 6px; }
.scroller::-webkit-scrollbar-track { background: transparent; }
.scroller::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 10px; }

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

.panel-header h2 {
    font-family: var(--font-head);
    font-size: 1.25rem;
    font-weight: 600;
}

.controls-drawer-close {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin-left: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-input);
    color: var(--text-main);
    cursor: pointer;
    flex-shrink: 0;
}

.controls-drawer-close:hover {
    background: rgba(126, 34, 206, 0.08);
    border-color: var(--brand-primary);
}

.status-indicator {
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(34, 197, 94, 0.1);
    color: #22c55e;
    padding: 4px 10px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid rgba(34, 197, 94, 0.2);
}

.dot.live {
    width: 6px;
    height: 6px;
    background-color: #22c55e;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
    70% { box-shadow: 0 0 0 4px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* Control Groups */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.control-group h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    margin-bottom: -4px;
}

.input-row {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: border-color 0.2s, box-shadow 0.2s;
}

/* HTML [hidden] loses to `.input-row { display: flex }` (same specificity, author CSS wins) */
.control-group .input-row[hidden] {
    display: none;
}

.input-row:focus-within {
    border-color: var(--brand-light);
    box-shadow: 0 0 0 2px rgba(147, 51, 234, 0.2);
}

.input-row label {
    font-size: 0.9rem;
    font-weight: 500;
}

.input-row input[type="number"] {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    text-align: right;
    width: 80px;
    outline: none;
}

/* Combo Input Row (Slider + Number) */
.input-row.combo {
    flex-direction: row;
    align-items: flex-start;
    gap: 16px;
    padding: 12px;
}

.col {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.col.mini {
    flex: 0 0 70px;
    border-left: 1px solid var(--border-color);
    padding-left: 16px;
}

.col.mini input { width: 100%; text-align: left;}

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

.slider-wrapper input[type="number"] {
    width: 60px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    padding: 4px 8px;
    border-radius: 4px;
    text-align: center;
}

/* Custom Range Slider */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    background: transparent;
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    height: 18px;
    width: 18px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid var(--brand-accent);
    cursor: pointer;
    margin-top: -7px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: var(--border-color);
    border-radius: 2px;
}

/* Metrics Section */
.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.metric-box {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.02);
}

.metric-val {
    font-family: var(--font-head);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--brand-accent);
}

.metric-lbl {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 4px;
}

.detention-overflow-notice {
    font-size: 0.8rem;
    color: #b45309;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(180, 83, 9, 0.28);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    margin-top: 12px;
    line-height: 1.45;
}

body.dark-theme .detention-overflow-notice {
    color: #fcd34d;
    background: rgba(245, 158, 11, 0.1);
    border-color: rgba(251, 191, 36, 0.3);
}

/* Viz Section — hydrograph is primary; profile strip stays small */
.viz-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.viz-card {
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    padding: var(--spacing);
    min-height: 0;
}

.viz-card.top {
    flex: 0 0 auto;
}

.viz-card.bottom {
    flex: 1 1 0;
    min-height: 0;
}

/* Compact roof profile */
.profile-strip {
    padding: 10px 14px 12px;
}

.profile-strip-title {
    font-family: var(--font-head);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
    margin: 0 0 8px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.profile-strip-hint {
    font-weight: 500;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.viz-header {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px 12px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.row-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.viz-header h2 {
    font-family: var(--font-head);
    font-size: 1.15rem;
}

.viz-header > h2 {
    flex: 1 1 auto;
    min-width: 0;
}

.hydrocad-viz-header .hydrocad-chart-toggles {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.45rem 0.7rem;
}

.hydrocad-chart-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
}

.hydrocad-chart-toggle input {
    cursor: pointer;
}

.hydrocad-predev-cn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.hydrocad-predev-cn label {
    cursor: pointer;
}

.hydrocad-predev-cn input {
    width: 3.2rem;
    padding: 2px 4px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    color: var(--text-main);
    font-family: var(--font-body);
}

.hydrocad-target-release {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.hydrocad-target-release label {
    cursor: pointer;
}

.hydrocad-target-release input {
    width: 4.5rem;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    color: var(--text-main);
    font-family: var(--font-body);
}

.hydrocad-chart-toggles .nav-btn {
    padding: 4px 7px;
    font-size: 0.72rem;
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.badge {
    background: rgba(22, 163, 74, 0.1);
    color: var(--brand-accent);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid rgba(22, 163, 74, 0.2);
}

.canvas-container {
    flex-grow: 1;
    position: relative;
    width: 100%;
}

.profile-container {
    height: 96px;
    flex: 0 0 auto;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04);
}

.graph-container {
    flex: 1 1 auto;
    min-height: 220px;
    position: relative;
    width: 100%;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04);
}

body.dark-theme .graph-container {
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    touch-action: pan-y pinch-zoom;
}

/* Buttons */
.nav-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-family: var(--font-body);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.nav-btn.primary {
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-dark));
    color: white;
    box-shadow: 0 4px 12px rgba(126, 58, 242, 0.3);
}

.nav-btn.primary:hover {
    box-shadow: 0 6px 16px rgba(126, 58, 242, 0.5);
    transform: translateY(-1px);
}

.nav-btn.outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}
.nav-btn.outline:hover {
    background: rgba(255,255,255,0.05);
}

/* SWMM + stormwater soils: testing watermark (same padding/box as outline; SVG scales via contain) */
.nav-btn.outline.nav-app-testing,
.nav-link.nav-app-testing.nav-btn.outline {
    position: relative;
    background-color: rgba(254, 252, 232, 0.94);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 26' preserveAspectRatio='xMidYMid meet'%3E%3Ctext x='100' y='17' text-anchor='middle' font-family='system-ui,Segoe UI,sans-serif' font-size='11' font-weight='700' letter-spacing='0.14em' fill='%23a16207' fill-opacity='0.2'%3ETESTING%3C/text%3E%3C/svg%3E");
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    border-color: rgba(180, 83, 9, 0.42);
}

.nav-btn.outline.nav-app-testing:hover,
.nav-link.nav-app-testing.nav-btn.outline:hover {
    background-color: rgba(254, 243, 199, 0.98);
    border-color: rgba(146, 64, 14, 0.55);
}

/* Dark theme (toggled via body.dark-theme) */
body.dark-theme {
    --bg-base: #0f172a;
    --bg-panel: #1e293b;
    --bg-input: #334155;
    --border-color: #475569;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
}

body.dark-theme .app-background {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 55%, #0f172a 100%);
}

body.dark-theme .glass-panel {
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.35), 0 8px 10px -6px rgba(0, 0, 0, 0.2);
}

body.dark-theme .nav-btn.outline:hover {
    background: rgba(255, 255, 255, 0.08);
}

body.dark-theme .nav-btn.outline.nav-app-testing,
body.dark-theme .nav-link.nav-app-testing.nav-btn.outline {
    background-color: rgba(55, 32, 8, 0.72);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 26' preserveAspectRatio='xMidYMid meet'%3E%3Ctext x='100' y='17' text-anchor='middle' font-family='system-ui,Segoe UI,sans-serif' font-size='11' font-weight='700' letter-spacing='0.14em' fill='%23fde68a' fill-opacity='0.22'%3ETESTING%3C/text%3E%3C/svg%3E");
    border-color: rgba(251, 191, 36, 0.38);
}

body.dark-theme .nav-btn.outline.nav-app-testing:hover,
body.dark-theme .nav-link.nav-app-testing.nav-btn.outline:hover {
    background-color: rgba(69, 26, 3, 0.82);
    border-color: rgba(251, 191, 36, 0.5);
}

body.dark-theme .scroller::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
}

body.dark-theme .profile-container {
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
}

body.dark-theme .badge {
    background: rgba(34, 197, 94, 0.15);
    border-color: rgba(34, 197, 94, 0.35);
}

/* Storm Selector */
.storm-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.storm-selector label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.storm-selector select {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 6px 12px;
    border-radius: var(--radius-md);
    outline: none;
    font-family: var(--font-body);
}
.storm-selector select:focus {
    border-color: var(--brand-primary);
}

.results-bar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    flex-shrink: 0;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.result-stat {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.controls-drawer-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    min-height: 34px;
    font-size: 0.78rem;
}

.controls-drawer-backdrop {
    display: none;
}
.highlight-val {
    color: var(--brand-accent);
    font-size: 1.1rem;
    margin-left: 6px;
}

/* Reponsive */
@media (max-width: 1024px) {
    .app-grid {
        grid-template-columns: 1fr;
        height: auto;
        max-height: none;
        /* Stacked layout: page scrolls; keep parameters in a bounded scroll region */
        min-height: 0;
        padding: 14px;
        gap: 14px;
    }
    .controls-drawer-toggle {
        display: inline-flex;
    }
    .controls-drawer-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        border: none;
        margin: 0;
        padding: 0;
        background: rgba(15, 23, 42, 0.45);
        backdrop-filter: blur(1px);
        z-index: 8180;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }
    body.controls-drawer-open .controls-drawer-backdrop {
        opacity: 1;
        pointer-events: auto;
    }
    .controls-panel {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(92vw, 420px);
        max-width: 100%;
        max-height: none;
        z-index: 8200;
        border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
        box-shadow: 0 22px 44px -14px rgba(2, 6, 23, 0.48);
        transform: translateX(-108%);
        transition: transform 0.24s ease;
        will-change: transform;
        overscroll-behavior: contain;
    }
    body.controls-drawer-open {
        overflow: hidden;
    }
    body.controls-drawer-open .controls-panel {
        transform: translateX(0);
    }
    .controls-drawer-close {
        display: inline-flex;
    }
    .viz-panel {
        flex: 1 1 auto;
        overflow: visible;
        align-self: start;
        width: 100%;
        min-height: 0;
        gap: 14px;
    }
    .viz-card.bottom {
        min-height: 280px;
        flex: 0 1 auto;
        padding: 14px;
    }
    .graph-container {
        flex: 0 1 auto;
        min-height: 260px;
        height: clamp(260px, 42vh, 420px);
    }
}

/* Compact header + hamburger drawer (tablets / small laptops — avoids nav overlapping the title) */
@media (max-width: 1200px) {
    .app-header {
        flex-wrap: wrap;
        padding: 0.75rem 1rem;
        align-items: center;
    }

    .header-top-row {
        flex: 1 1 100%;
        justify-content: space-between;
        min-width: 0;
    }

    .logo-text {
        font-size: 1.15rem;
    }

    .logo-wordmark {
        max-width: min(34vw, 150px);
        height: 1.45rem;
        max-height: 1.6rem;
    }

    .subtext {
        font-size: 0.65rem;
    }

    .nav-menu-toggle {
        display: inline-flex;
    }

    .top-nav {
        display: none;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        flex-wrap: nowrap;
        width: 100%;
        margin-left: 0;
        margin-top: 4px;
        padding: 10px 12px;
        gap: 8px;
        border-radius: var(--radius-md);
        border: 1px solid var(--border-color);
        background: var(--bg-panel);
        box-shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.15);
    }

    body.dark-theme .top-nav {
        box-shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.45);
    }

    .app-header.nav-menu-open .top-nav {
        display: flex;
    }

    .top-nav .nav-btn,
    .top-nav .nav-link {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }

    .top-nav .nav-btn svg {
        flex-shrink: 0;
    }

    .app-header.nav-menu-open {
        z-index: 8100;
    }

    .viz-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .viz-header .rain-toggle {
        align-self: flex-start;
    }

    .hydrocad-viz-header {
        align-items: flex-start;
        gap: 0.65rem;
    }

    .hydrocad-viz-header .hydrocad-chart-toggles {
        width: 100%;
        max-width: 100%;
        justify-content: flex-start;
        gap: 0.5rem 0.75rem;
    }

    .hydrocad-chart-toggle {
        white-space: normal;
        font-size: 0.8rem;
        line-height: 1.25;
    }

    .results-bar {
        flex-wrap: nowrap;
        justify-content: flex-start;
        gap: 14px;
        text-align: left;
        overflow-x: auto;
        overflow-y: hidden;
        padding-bottom: 2px;
    }

    .result-stat {
        font-size: 0.83rem;
        white-space: nowrap;
        flex: 0 0 auto;
    }
}

@media (max-width: 480px) {
    .controls-panel {
        width: 100vw;
        border-radius: 0;
        padding: 14px;
    }
    .controls-panel .panel-header {
        gap: 8px;
    }
    .graph-container {
        min-height: 220px;
        height: clamp(220px, 44vh, 380px);
    }
    .results-bar {
        gap: 10px;
    }
    .result-stat {
        font-size: 0.78rem;
    }
    .highlight-val {
        font-size: 1rem;
    }
}

/* ----------------------------- */
/* Leaflet Map Overrides */
/* ----------------------------- */

.leaflet-map-container {
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.3));
    margin-bottom: 8px;
}

.leaflet-control-zoom a {
    background-color: var(--bg-input) !important;
    color: var(--text-main) !important;
    border-color: var(--border-color) !important;
}

.leaflet-control-zoom a:hover {
    background-color: var(--brand-primary) !important;
}

/* FAQ page (standalone main, no app-grid) */
.faq-main {
    max-width: 720px;
    margin: 1rem auto 2.5rem;
    padding: 1.35rem 1.5rem 1.75rem;
    border-radius: var(--radius-lg);
}

.faq-intro {
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.55;
    margin-bottom: 1.25rem;
    padding: 1rem 1.1rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.faq-list {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.faq-main details {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.65rem 1rem;
}

.faq-main summary {
    font-family: var(--font-head);
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--brand-primary);
    cursor: pointer;
    list-style-position: outside;
    padding: 0.25rem 0;
}

.faq-main details[open] summary {
    margin-bottom: 0.5rem;
}

.faq-main .answer {
    font-size: 0.88rem;
    color: var(--text-main);
    line-height: 1.5;
    padding-left: 0.25rem;
}

.faq-main .answer a {
    color: var(--brand-primary);
    font-weight: 600;
}

.faq-footer {
    margin-top: 2rem;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.faq-footer a {
    color: var(--brand-primary);
}

/* First-run license gate (tools) */
.license-gate-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10050;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

body.dark-theme .license-gate-backdrop {
    background: rgba(0, 0, 0, 0.65);
}

.license-gate-dialog {
    width: 100%;
    max-width: 520px;
    max-height: min(88vh, 640px);
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.license-gate-dialog--export {
    max-width: 440px;
    max-height: none;
}

.license-gate-dialog h2 {
    font-family: var(--font-head);
    font-size: 1.2rem;
    padding: 1.1rem 1.25rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.license-gate-body {
    padding: 1rem 1.25rem;
    overflow-y: auto;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text-main);
}

.license-gate-body p {
    margin-bottom: 0.65rem;
}

.license-gate-body h3 {
    font-family: var(--font-head);
    font-size: 0.88rem;
    margin: 0.85rem 0 0.35rem;
    color: var(--text-main);
}

.license-gate-body h3:first-child {
    margin-top: 0;
}

.license-gate-body ul {
    margin: 0.35rem 0 0.65rem 1.1rem;
    padding: 0;
}

.license-gate-body li {
    margin-bottom: 0.35rem;
}

.license-gate-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.25rem 1.1rem;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.license-gate-actions a {
    font-size: 0.85rem;
    color: var(--brand-primary);
    font-weight: 600;
}

.license-gate-agree {
    margin-left: auto;
}

/* In-page full license reader (nested over export confirm; export-license-confirm.js) */
.license-read-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10150;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

body.dark-theme .license-read-backdrop {
    background: rgba(0, 0, 0, 0.65);
}

.license-read-dialog.license-gate-dialog {
    max-width: min(560px, 96vw);
    max-height: min(85vh, 720px);
}

.license-read-body {
    padding: 0.75rem 1.25rem 1rem;
    overflow: auto;
    max-height: min(52vh, 440px);
    font-size: 0.78rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    color: var(--text-main);
    flex: 1;
    min-height: 0;
}

.license-read-body.is-loading {
    font-family: var(--font-body);
    color: var(--text-muted);
}

.license-read-body a {
    color: var(--brand-primary);
    font-weight: 600;
}

.inline-license-link {
    display: inline;
    padding: 0;
    margin: 0;
    border: none;
    background: none;
    color: var(--brand-primary);
    font: inherit;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.inline-license-link:hover {
    text-decoration-thickness: 2px;
}

.leaflet-popup-content-wrapper, .leaflet-popup-tip {
    background: var(--bg-panel);
    color: var(--text-main);
    box-shadow: 0 10px 20px rgba(0,0,0,0.15);
    border: 1px solid var(--border-color);
}
