/* Palette: dark navy, matching the logo (app/static/images/logo.svg) */
:root {
    --bg: #0B1630;
    --surface: #13213F;
    --raised: #1C2D52;
    --border: #2A3B63;
    --text: #E8EEF8;
    --muted: #9AA8C2;
    --accent: #2F7BF6;
    --accent-hover: #4A8DF8;
    --accent-tint: rgba(47, 123, 246, 0.15);
    --danger: #E5483B;
    --on-accent: #FFFFFF;
    --shadow: rgba(0, 0, 0, 0.35);
    --overlay: rgba(4, 9, 20, 0.6);
    /* Height of the top and bottom navbars, not counting the safe areas */
    --nav-h: 56px;
    /* Native controls (select menus, number spinners, scrollbars) in their dark style */
    color-scheme: dark;
}

/* General styles */
body {
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* TOP NAVBAR: full width, menu | brand | the tab's buttons. Safe-area padding keeps it clear of notches. */
.navtop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    padding-top: env(safe-area-inset-top);
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 6px var(--shadow);
}

.nav-inner {
    display: flex;
    align-items: center;
    height: var(--nav-h);
    padding: 0 max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
}

.nav-left,
.nav-center,
.nav-right {
    flex: 1;
    display: flex;
    align-items: center;
    min-width: 0;
}

.nav-center {
    justify-content: center;
}

.nav-right {
    justify-content: flex-end;
    gap: 4px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    text-decoration: none;
    font-size: 1.1em;
    font-weight: bold;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.brand img {
    /* The map fills only the middle of logo-mark.svg's square canvas (x 24-84, y 34-74 of 108);
       the negative margins trim the empty rest, leaving a 32 x 21px map */
    width: 58px;
    height: 58px;
    margin: -18px -13px;
}

.hamburger,
.nav-action {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: none;
    color: var(--text);
    font-size: 1.15em;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Only where there's a real pointer: on touch, :hover sticks after a tap */
@media (hover: hover) {
    .hamburger:hover,
    .nav-action:hover {
        background-color: var(--accent-tint);
    }
}

/* Three bars that turn into a cross while the menu is open */
.hamburger-icon {
    position: relative;
    width: 22px;
    height: 18px;
}

.hamburger-icon span {
    position: absolute;
    left: 0;
    width: 100%;
    height: 2.5px;
    border-radius: 9px;
    background-color: var(--text);
    transition: transform 0.25s ease-in-out, top 0.25s ease-in-out, opacity 0.2s, left 0.25s;
}

.hamburger-icon span:nth-child(1) { top: 0; }
.hamburger-icon span:nth-child(2) { top: 8px; }
.hamburger-icon span:nth-child(3) { top: 16px; }

.menu-open .hamburger-icon span:nth-child(1) {
    top: 8px;
    transform: rotate(135deg);
}

.menu-open .hamburger-icon span:nth-child(2) {
    opacity: 0;
    left: -40px;
}

.menu-open .hamburger-icon span:nth-child(3) {
    top: 8px;
    transform: rotate(-135deg);
}

/* The menu drops down full width under the navbar */
.nav-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 0;
    overflow: hidden;
    background-color: var(--surface);
    box-shadow: 0 6px 12px var(--shadow);
    transition: max-height 0.3s ease-in-out;
}

.menu-open .nav-menu {
    max-height: 320px;
    border-bottom: 1px solid var(--border);
}

.nav-menu a {
    display: block;
    padding: 14px max(20px, env(safe-area-inset-left));
    color: var(--text);
    text-decoration: none;
}

.nav-menu a:hover {
    background-color: var(--accent-tint);
}

/* The sliders button is for the Models tab's sheet on phones; data info is for the tabs showing a series */
#methodsButton,
[data-tab="settings"] #dataInfoButton {
    display: none;
}

/* BOTTOM NAVBAR: one equal column per tab, icon over label */
.navbot {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    height: var(--nav-h);
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background-color: rgba(19, 33, 63, 0.92);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px var(--shadow);
}

.nav-link-bottom {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--muted);
    text-decoration: none;
    font-size: 12px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: transform 200ms ease-out, background-color 0.2s;
}

.nav-link-bottom i {
    font-size: 19px;
}

.nav-link-bottom:active {
    transform: scale(0.94);
    transition: transform 80ms ease-in;
}

.nav-link-bottom.nav-link-selected {
    color: var(--text);
    background-color: var(--accent-tint);
    font-weight: 700;
}

.nav-link-bottom.nav-link-selected i {
    color: var(--accent-hover);
}

/* VIEWS: the space between the navbars; one shows at a time, chosen by body[data-tab] */
.views {
    position: fixed;
    top: calc(var(--nav-h) + env(safe-area-inset-top) + 1px);
    bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
    left: 0;
    right: 0;
}

.view {
    display: none;
    height: 100%;
    box-sizing: border-box;
}

[data-tab="historic"] #view-chart,
[data-tab="models"] #view-chart {
    display: flex;
}

[data-tab="settings"] #view-settings,
[data-tab="hypothesis"] #view-hypothesis {
    display: block;
}

/* .views is fixed, so it's its own stacking context: lift it over the bottom navbar while
   the projection sheet (inside it) is open */
.controls-open .views {
    z-index: 1100;
}

.view-chart {
    flex-direction: row;
    gap: 10px;
    padding: 10px max(10px, env(safe-area-inset-right)) 10px max(10px, env(safe-area-inset-left));
}

/* Chart container */
.chart-container {
    flex: 2;
    background-color: var(--surface);
    border-radius: 8px;
    box-shadow: 0 2px 6px var(--shadow);
    padding: 10px;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 0;
}

.metric-bar {
    display: flex;
    margin-bottom: 6px;
}

.metric-select {
    max-width: 360px;
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background-color: var(--raised);
    color: var(--text);
    font-size: 15px;
}

.metric-select option,
.metric-select optgroup {
    background-color: var(--raised);
    color: var(--text);
}

#chart {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.chart-info {
    margin-top: 10px;
    padding: 10px;
    background-color: var(--raised);
    border-radius: 4px;
}

.chart-info p {
    margin: 5px 0;
    color: var(--muted);
    font-size: 0.9em;
}

.chart-info a {
    color: var(--accent-hover);
    text-decoration: none;
}

.chart-info a:hover {
    text-decoration: underline;
}

/* Projection panel: a sidebar on the Models tab (a bottom sheet on phones, below) */
.panel-container {
    display: none;
    flex: 1;
    max-width: 260px;
    height: 100%;
    flex-direction: column;
}

[data-tab="models"] .panel-container {
    display: flex;
}

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

.sheet-close,
.sheet-backdrop {
    display: none;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 2000; /* above both navbars and the sheet */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: var(--overlay);
}

.modal-content {
    background-color: var(--surface);
    border: 1px solid var(--border);
    box-shadow: 0 6px 20px var(--shadow);
    margin: 15% auto;
    padding: 20px;
    border-radius: 8px;
    width: 50%;
    max-width: 500px;
    position: relative;
}

.modal-content h2 {
    margin-top: 0;
    color: var(--text);
}

.modal-content p {
    margin: 10px 0;
    color: var(--muted);
    font-size: 0.9em;
    line-height: 1.5;
}

.email-link {
    margin-top: 20px;
    text-align: center;
}

.email-link a {
    color: var(--accent-hover);
    text-decoration: none;
    font-weight: bold;
}

.email-link a:hover {
    text-decoration: underline;
}

.close-button {
    position: absolute;
    right: 20px;
    top: 10px;
    font-size: 28px;
    font-weight: bold;
    color: var(--muted);
    cursor: pointer;
}

.close-button:hover {
    color: var(--text);
}

.panel {
    background-color: var(--surface);
    border-radius: 8px;
    box-shadow: 0 2px 6px var(--shadow);
    padding: 15px;
    height: 100%;
    box-sizing: border-box;
    overflow-y: auto;
}

.panel h2 {
    margin-top: 0;
    color: var(--text);
    font-size: 1.2em;
    margin-bottom: 15px;
}

/* Form controls */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.form-group input[type="number"] {
    width: 100%;
    box-sizing: border-box;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background-color: var(--raised);
    color: var(--text);
    font-size: 14px;
}

.form-group input[type="number"]:focus,
.form-group select:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
}

.method-list input[type="checkbox"] {
    accent-color: var(--accent);
}

.forecast-button {
    width: 100%;
    padding: 10px;
    background-color: var(--accent);
    color: var(--on-accent);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s;
}

.forecast-button:hover {
    background-color: var(--accent-hover);
}

.forecast-button i {
    margin-right: 5px;
}

.control-readout {
    margin: 8px 0 0;
    min-height: 1.4em;
    color: var(--text);
    font-size: 0.9em;
}

.method-list .method-heading {
    font-weight: bold;
}

.method-list .method-heading span {
    font-weight: normal;
    color: var(--muted);
    font-size: 0.9em;
}

.method-list .method-option {
    font-weight: normal;
    display: block;
    margin: 8px 0;
    cursor: pointer;
}

.method-list .method-option .method-note {
    font-weight: normal;
    display: block;
    margin-left: 22px;
    color: var(--muted);
}

.method-list .method-option.skipped span {
    color: var(--muted);
    opacity: 0.6;
    text-decoration: line-through;
}


.form-group select {
    width: 100%;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background-color: var(--raised);
    color: var(--text);
    font-size: 14px;
}

/* Keep native drop-down lists readable where the browser ignores color-scheme */
.form-group select option,
.form-group select optgroup {
    background-color: var(--raised);
    color: var(--text);
}


/* SETTINGS AND HYPOTHESIS: scrolling pages of cards */
.view-page {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.page {
    max-width: 860px;
    margin: 0 auto;
    padding: 16px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
}

.page h1 {
    font-size: 1.4em;
    margin: 4px 0 12px;
}

.lede {
    color: var(--muted);
    margin: -4px 0 14px;
    line-height: 1.4;
}

.card {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 14px;
}

.card h2 {
    font-size: 1.05em;
    margin: 0 0 12px;
}

.card p {
    color: var(--muted);
    line-height: 1.5;
    margin: 0 0 10px;
}

.card .form-group select,
.card .form-group input[type="number"] {
    max-width: 360px;
}

.hint {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.85em;
    line-height: 1.4;
}

.label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.check {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    cursor: pointer;
    line-height: 1.4;
}

.check input {
    accent-color: var(--accent);
    margin-top: 3px;
}

.link-button {
    background: none;
    border: none;
    padding: 0;
    color: var(--accent-hover);
    font-size: 1em;
    cursor: pointer;
}

/* Two-option toggle built from radio buttons */
.segmented {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

/* Not the .form-group label margin and weight */
.segmented label {
    display: block;
    margin: 0;
    font-weight: normal;
}

.segmented input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.segmented span {
    display: block;
    padding: 8px 14px;
    background-color: var(--raised);
    color: var(--muted);
    cursor: pointer;
}

.segmented label + label span {
    border-left: 1px solid var(--border);
}

.segmented input:checked + span {
    background-color: var(--accent);
    color: var(--on-accent);
}

.segmented input:focus-visible + span {
    outline: 2px solid var(--accent-hover);
    outline-offset: -2px;
}

.hyp-result.loading {
    opacity: 0.5;
    transition: opacity 0.2s;
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.stat {
    background-color: var(--raised);
    border-left: 4px solid var(--group-color);
    border-radius: 8px;
    padding: 10px 12px;
}

.stat-label {
    color: var(--muted);
    font-size: 0.85em;
}

.stat-value {
    font-size: 1.35em;
    font-weight: bold;
    margin: 4px 0;
}

.stat-note {
    color: var(--muted);
    font-size: 0.8em;
}

.card .hyp-verdict {
    color: var(--text);
}

.card .hyp-chance {
    font-size: 0.9em;
}

.hyp-chart {
    height: 280px;
    margin-top: 6px;
}

.hyp-caveat {
    margin: 0 4px;
}

/* Mobile layout (phones in either orientation): full-width chart, projection panel in a bottom sheet.
   Keep this query in step with isNarrow() in chart.html. */
@media (max-width: 768px), (max-height: 500px) {
    .view-chart {
        padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
    }

    .chart-container {
        flex: 1;
        border-radius: 0;
        box-shadow: none;
        padding: 6px;
    }

    .chart-info {
        margin-top: 4px;
        padding: 6px 8px;
    }

    .chart-info p,
    .control-readout {
        font-size: 0.8em;
    }

    /* Room for a three-line readout, so the chart doesn't resize on every tap */
    .control-readout {
        min-height: 3.9em;
        margin-top: 4px;
    }

    [data-tab="models"] #methodsButton {
        display: flex;
    }

    .sheet-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1100;
        background-color: var(--overlay);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s;
    }

    /* Over the bottom navbar while open */
    [data-tab="models"] .panel-container {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1150;
        max-width: none;
        height: auto;
        max-height: 75dvh;
        background-color: var(--surface);
        border-radius: 14px 14px 0 0;
        box-shadow: 0 -4px 16px var(--shadow);
        transform: translateY(100%);
        transition: transform 0.25s ease-out;
    }

    .panel {
        border-radius: 14px 14px 0 0;
        box-shadow: none;
        padding: 14px max(15px, env(safe-area-inset-right)) max(15px, env(safe-area-inset-bottom)) max(15px, env(safe-area-inset-left));
        min-height: 0;
        height: auto;
    }

    .sheet-close {
        display: block;
        background: none;
        border: none;
        font-size: 28px;
        line-height: 1;
        color: var(--muted);
        cursor: pointer;
        padding: 0 4px;
    }

    .controls-open .panel-container {
        transform: translateY(0);
    }

    .controls-open .sheet-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .modal-content {
        width: 85%;
        margin: 20% auto;
    }

    .page {
        padding-top: 12px;
    }

    .hyp-chart {
        height: 220px;
    }
}

/* Phones in landscape: slimmer navbars, icons only, and nearly all the height for the chart */
@media (max-height: 500px) and (orientation: landscape) {
    :root {
        --nav-h: 44px;
    }

    .nav-link-bottom span {
        display: none;
    }

    .chart-info {
        display: none;
    }

    .control-readout {
        min-height: 2.6em;
    }
}
