:root {
    --brand-primary: #0284c7; /* Water blue for SWMM */
    --brand-accent: #0ea5e9;
    --bg-base: #f4f7f6;
    --bg-panel: #ffffff;
    --bg-input: #f8fafc;
    --border-color: #cbd5e1;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --font-head: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    background-color: var(--bg-base);
    color: var(--text-main);
    font-family: var(--font-body);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

.app-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    background: linear-gradient(135deg, #f0fdfa 0%, #e0f2fe 55%, #ecfeff 100%);
    overflow: hidden;
}

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

/* Matches stormwater-soils.html beta strip (shared look; SWMM page does not load stormwater-soils.css). */
.storm-beta-banner {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0.55rem 1.25rem;
    font-size: 0.8rem;
    line-height: 1.45;
    color: #7c2d12;
    background: linear-gradient(90deg, rgba(251, 191, 36, 0.35), rgba(254, 243, 199, 0.65));
    border-bottom: 1px solid rgba(180, 83, 9, 0.45);
    text-align: center;
}

body.dark-theme .storm-beta-banner {
    color: #fde68a;
    background: linear-gradient(90deg, rgba(120, 53, 15, 0.55), rgba(69, 26, 3, 0.45));
    border-bottom-color: rgba(251, 191, 36, 0.35);
}

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

.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: 6px;
    background: var(--bg-input);
    color: var(--text-main);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.nav-menu-toggle:hover {
    background: rgba(2, 132, 199, 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);
}

.app-license-footer {
    margin-top: auto;
    flex-shrink: 0;
    width: 100%;
    padding: 0.65rem 1.5rem;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    border-top: 1px solid var(--border-color);
    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;
}

.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-text-wrapper { min-width: 0; }
.logo-icon { font-size: 2rem; line-height: 1; }
.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); }

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

#btn-theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    padding-left: 12px;
    padding-right: 12px;
}

/* Dark theme (shared key with hydrocad-v2: 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 .console-box {
    background: #0f172a;
    color: #7dd3fc;
    border: 1px solid var(--border-color);
}

.app-grid { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 24px; padding: 24px; flex-grow: 1; min-height: 0; align-items: start; }

/* Let the chart column shrink inside the grid without forcing overflow overlap */
.app-grid > .viz-panel {
    min-height: 0;
}

.controls-panel { border-radius: 12px; display: flex; flex-direction: column; overflow-x: hidden; }
.panel-header { padding: 20px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.panel-header h2 { font-family: var(--font-head); font-size: 1.25rem; }

.status-indicator { font-size: 0.75rem; display: flex; align-items: center; gap: 6px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.idle { background: #94a3b8; }
.dot.live { background: #f59e0b; box-shadow: 0 0 8px rgba(245, 158, 11, 0.5); animation: pulse 1s infinite alternate; }
.dot.done { background: #10b981; }

.control-group { padding: 20px; border-bottom: 1px solid var(--border-color); }
.control-group h3 { font-size: 0.85rem; text-transform: uppercase; color: var(--text-muted); margin-bottom: 15px; letter-spacing: 0.05em; }
.helper-text { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 15px; line-height: 1.4; }

.nav-btn { font-family: var(--font-body); font-size: 0.875rem; font-weight: 600; border-radius: 6px; cursor: pointer; transition: 0.2s; padding: 10px 14px; }
.nav-btn.primary { background: var(--brand-primary); color: white; border: none; }
.nav-btn.primary:hover { background: var(--brand-accent); }
.nav-btn.secondary.outline { background: var(--bg-panel); color: var(--text-main); border: 1px solid var(--border-color); }
.nav-btn.secondary.outline:hover { border-color: var(--brand-primary); color: var(--brand-primary); }

.nav-btn.secondary.outline.nav-app-testing {
    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.secondary.outline.nav-app-testing:hover {
    background-color: rgba(254, 243, 199, 0.98);
    border-color: var(--brand-primary);
    color: var(--brand-primary);
}

body.dark-theme .nav-btn.secondary.outline.nav-app-testing {
    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);
    color: var(--text-main);
}

body.dark-theme .nav-btn.secondary.outline.nav-app-testing:hover {
    background-color: rgba(69, 26, 3, 0.82);
    border-color: var(--brand-accent);
    color: var(--brand-accent);
}
.nav-btn.full-width { width: 100%; display: block; text-align: center; }
.nav-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.action-row { display: flex; gap: 10px; margin-top: 4px; flex-wrap: wrap; }
.flex-1 { flex: 1; min-width: 120px; }

.console-box { background: #1e293b; color: #38bdf8; font-family: monospace; font-size: 0.72rem; padding: 8px 10px; border-radius: 6px; margin-top: 12px; max-height: 64px; height: 64px; overflow-y: auto; white-space: pre-wrap; word-break: break-all; }

.panel-notes { margin-top: 0.35rem; font-size: 0.85rem; }
.panel-notes summary {
    cursor: pointer;
    color: var(--brand-primary);
    font-weight: 600;
    list-style-position: outside;
}
.panel-notes .helper-text.small { margin-bottom: 0.5rem; }
.panel-notes .helper-text.small:last-child { margin-bottom: 0; }

.climate-hourly-details { margin-top: 8px; }
.climate-hourly-details summary {
    cursor: pointer;
    color: var(--brand-primary);
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 8px;
}
.climate-hourly-details .climate-table-wrap { margin-bottom: 0; }
.climate-hourly-details .helper-text.small { margin-top: 8px; margin-bottom: 0; }

.viz-panel {
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    overflow-x: hidden;
    overflow-y: visible;
    gap: 16px;
    min-height: 0;
    flex: 1;
    align-items: stretch;
}
.viz-card { padding: 20px; display: flex; flex-direction: column; border-radius: 12px; min-height: 0; position: relative; z-index: 0; }
.map-card { flex: 0 0 auto; }

/* LID monthly chart: below climate; explicit height so x-axis is not clipped */
.lid-chart-card {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: visible;
}

.lid-graph-container {
    position: relative;
    width: 100%;
    min-height: min(400px, 55vh);
    height: min(440px, 58vh);
    flex: 0 0 auto;
    overflow: visible;
}

/* Subcatchment runoff: extra room so Chart.js legend / plot area is not clipped */
.subcatchment-runoff-card {
    overflow: visible;
    padding-bottom: 8px;
}
.subcatch-graph-container {
    position: relative;
    width: 100%;
    min-height: min(440px, 58vh);
    height: min(480px, 62vh);
    flex: 0 0 auto;
    overflow: visible;
}
.viz-header.row-between { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.viz-header h2 { font-family: var(--font-head); font-size: 1.25rem; margin-bottom: 4px; }

.metrics-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.metric-box { background: var(--bg-input); padding: 12px; border-radius: 8px; text-align: center; border: 1px solid var(--border-color); }
.metric-val { display: block; font-size: 1.5rem; font-weight: 700; color: var(--brand-primary); font-family: var(--font-head); }
.metric-lbl { font-size: 0.7rem; text-transform: uppercase; color: var(--text-muted); font-weight: 600; }

.summary-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.summary-table th { text-align: left; border-bottom: 2px solid var(--border-color); padding: 8px 4px; color: var(--text-muted); }
.summary-table td { padding: 10px 4px; border-bottom: 1px solid var(--bg-input); font-weight: 500;}

.viz-select { padding: 8px 12px; border-radius: 6px; border: 1px solid var(--border-color); background: var(--bg-panel); font-family: var(--font-body); font-size: 0.9rem; color: var(--text-main); cursor: pointer; }

@keyframes pulse { from { opacity: 0.6; } to { opacity: 1; transform: scale(1.2); } }

.helper-text.small { font-size: 0.78rem; margin-bottom: 0.75rem; }

.coord-row .col label,
.date-row .col label { display: block; font-size: 0.8rem; margin-bottom: 4px; color: var(--text-muted); }
.coord-row input[type="number"],
.date-row input { width: 100%; background: var(--bg-input); border: 1px solid var(--border-color); color: var(--text-main); padding: 8px; border-radius: 6px; outline: none; font-family: var(--font-body); }
.col-shrink { flex: 0 0 auto; align-self: flex-end; }
.col-year { flex: 0 1 100px; min-width: 80px; }

.swmm-map {
    height: min(360px, 42vh);
    width: 100%;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    z-index: 1;
    background: var(--bg-input);
}

.graph-container {
    position: relative;
    width: 100%;
}

.climate-series-card {
    flex: 0 0 auto;
    flex-shrink: 0;
}

.climate-series-graph {
    position: relative;
    width: 100%;
    height: min(420px, 50vh);
    min-height: 240px;
    flex: 0 0 auto;
    overflow: hidden;
}

/* Let Chart.js size the canvas inside the sized wrapper — absolute positioning
   was collapsing flex layout and letting charts paint on top of each other. */
.climate-series-graph canvas,
.graph-container canvas,
.subcatch-graph-container canvas {
    display: block;
    max-width: 100%;
}

.climate-panel { border-top: 1px solid var(--border-color); }
.climate-meta { font-size: 0.85rem; color: var(--text-main); margin-bottom: 8px; line-height: 1.4; }
.climate-api-link {
    display: inline-block;
    font-size: 0.75rem;
    color: var(--brand-primary);
    word-break: break-all;
    margin-bottom: 10px;
}
.climate-stats { margin-bottom: 10px; }
.climate-stat { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; font-size: 0.85rem; margin-bottom: 6px; }
.climate-stat .lbl { color: var(--text-muted); font-weight: 600; }
.climate-stat .val { font-weight: 700; color: var(--brand-primary); font-family: var(--font-head); }
.climate-stat .sub { color: var(--text-muted); font-size: 0.8rem; }

.monthly-details { margin-top: 8px; font-size: 0.8rem; }
.monthly-details summary { cursor: pointer; color: var(--brand-primary); font-weight: 600; margin-bottom: 6px; }
.monthly-mini { width: 100%; font-size: 0.75rem; border-collapse: collapse; }
.monthly-mini th, .monthly-mini td { padding: 4px 6px; border-bottom: 1px solid var(--border-color); text-align: left; }
.monthly-mini .climate-col-sub,
.climate-table .climate-col-sub { color: var(--text-muted); font-weight: 500; }

.climate-table-wrap {
    max-height: 220px;
    overflow: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 8px;
}
.climate-table { width: 100%; border-collapse: collapse; font-size: 0.75rem; }
.climate-table th {
    position: sticky;
    top: 0;
    background: var(--bg-panel);
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-muted);
    font-weight: 600;
}
.climate-table td { padding: 6px 10px; border-bottom: 1px solid var(--bg-input); font-variant-numeric: tabular-nums; }
.download-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.summary-table-wrap { margin-top: 1rem; }

@media (max-width: 1024px) {
    .app-grid { grid-template-columns: 1fr; height: auto; overflow: visible; }
    .swmm-map { height: 280px; }
}

/* Match other apps: collapse nav into hamburger before buttons crowd 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: 6px;
        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;
    }
}

/* First-run license gate (shared behavior with license-gate.js) */
.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: 16px;
    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 (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;
}
