:root {
    --bg: #ffffff;
    --card-bg: #ffffff;
    --ink: #1a1a1a;
    --muted: #767676;
    --meter-track: #dde1e8;
    --meter-fill: #3b4a6b;
    --border: #e2e5ea;
}

[data-theme="dark"] {
    /* One flat color for the page and every card -- intentionally the same
       value, so there's no second "elevated" shade of dark blue sitting
       next to the page background. */
    --bg: #0f1c2e;
    --card-bg: #0f1c2e;
    --ink: #e7edf6;
    --muted: #93a3bc;
    --meter-track: #1c2e47;
    --meter-fill: #8fa8d9;
    --border: #28395a;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Overpass', monospace;
    background-color: var(--bg);
    color: var(--ink);
}

#page-root {
    position: relative;
    min-height: 100vh;
    background-color: var(--bg);
    color: var(--ink);
    padding: 0 20px 32px;
    box-sizing: border-box;
    /* No transition here on purpose -- a fade on a full-page background/text
       swap reads as laggy rather than smooth, so the toggle is instant. */
}

.page-title {
    color: var(--ink);
    margin: 0;
    padding-top: 16px;
    text-align: center;
}

.page-subtitle {
    color: var(--muted);
    text-align: center;
    margin: 4px 0 0 0;
}

.sample-data-banner {
    color: #92400e;
    background-color: #fef3c7;
    text-align: center;
    margin: 10px auto 0 auto;
    max-width: 480px;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 14px;
}

.section-heading {
    color: var(--ink);
}

/* Unobtrusive theme toggle, pinned to the corner instead of competing with
   the title -- icon-only on narrow screens. */
.theme-toggle-btn {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: 12px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'Overpass', monospace;
    font-size: 13px;
    background-color: var(--card-bg);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 12px;
    cursor: pointer;
    opacity: 0.8;
}

.theme-toggle-btn:hover {
    opacity: 1;
}

.toggle-emoji {
    font-size: 15px;
    line-height: 1;
}

@media (max-width: 768px) {
    .theme-toggle-btn {
        padding: 6px;
        gap: 0;
    }

    .toggle-label {
        display: none;
    }
}

/* Reporting meter */
.meter-container {
    max-width: 480px;
    margin: 12px auto 20px auto;
}

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

.meter-label {
    font-size: 15px;
    color: var(--muted);
}

.meter-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--ink);
}

.meter-track {
    width: 100%;
    height: 12px;
    background-color: var(--meter-track);
    border-radius: 6px;
    overflow: hidden;
    margin-top: 4px;
}

.meter-fill {
    height: 100%;
    background-color: var(--meter-fill);
    border-radius: 6px;
}

.meter-caption {
    font-size: 13px;
    color: var(--muted);
    margin-top: 4px;
    text-align: right;
}

/* Dashboard layout -- flex-wrap + min-width:0 so Plotly's intrinsically
   wide SVG/canvas can actually shrink instead of overflowing on narrow
   screens (the #1 cause of the "atrocious" mobile view: a flex child's
   default min-width is auto, which uses the content's natural width). */
.dashboard-row {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    max-width: 1400px;
    margin: 0 auto;
}

.dashboard-col {
    min-width: 0;
}

.dashboard-col-left {
    flex: 1 1 380px;
}

.dashboard-col-right {
    flex: 2 1 480px;
}

.graph-table {
    height: 25vh;
    width: 100%;
}

.graph-bar {
    height: 45vh;
    width: 100%;
}

.graph-map {
    height: 80vh;
    width: 100%;
}

/* Plain-HTML replacement for the map's old in-figure legend -- Plotly
   wouldn't wrap a legend that didn't fit (see the bar chart's legend fix),
   and generating one trace per category to get a discrete legend at all
   meant the ~4.6MB geojson got duplicated once per category. A normal CSS
   flex-wrap row avoids both problems and is already theme-aware for free
   via the --ink/--muted variables. */
.map-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px 16px;
    padding: 10px 8px 4px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}

.legend-label {
    font-size: 12px;
    color: var(--muted);
}

@media (max-width: 768px) {
    #page-root {
        padding: 0 12px 24px;
    }

    .page-title {
        font-size: 22px;
        /* Clears the fixed toggle button in the corner so a wrapped second
           line of the title doesn't run underneath it. */
        padding-right: 52px;
    }

    .page-subtitle {
        font-size: 13px;
    }

    .dashboard-row {
        flex-direction: column;
        gap: 16px;
    }

    .dashboard-col-left,
    .dashboard-col-right {
        flex: none;
        width: 100%;
    }

    /* Legends moved inside the figures themselves (bottom, horizontal) --
       see display_barchart/display_choropleth in app.py -- so these heights
       only need to fit the plot, not a sidebar legend anymore. */
    .graph-table {
        height: 22vh;
    }

    .graph-bar {
        /* Taller than before: the legend fix below needed a much bigger
           bottom margin on the figure to stop overlapping its own rotated
           x-axis labels, which eats into the plot area otherwise. */
        height: 52vh;
    }

    .graph-map {
        height: 60vh;
    }
}
