/* Riverbed Surveys layer-toggle option has multi-line label content (title,
   subtitle, risk swatches), so the default vertical-centered checkbox floats
   next to the middle of the whole block instead of the "Riverbed Surveys"
   title. Pin it to the top of that option only -- the other layer-toggle
   options are single-line and stay centered via the inline labelStyle. */
#layer-toggle .dash-options-list-option-wrapper:first-child .dash-options-list-option,
#layer-toggle > label:first-child {
    align-items: flex-start !important;
}

#layer-toggle .dash-options-list-option-wrapper:first-child .dash-options-list-option-checkbox,
#layer-toggle > label:first-child input[type="checkbox"] {
    margin-top: 3px;
}

/* "?" info badge next to each layer-toggle label -- pure CSS hover tooltip, no
   click handling needed (and none wanted, since these labels sit inside the
   checkbox's <label> and a click would toggle the layer). */
.layer-info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    margin-left: 6px;
    border-radius: 50%;
    border: 1px solid #888;
    color: #888;
    font-size: 10px;
    line-height: 1;
    cursor: help;
    position: relative;
    flex-shrink: 0;
    vertical-align: middle;
}

.layer-info-icon .layer-info-tooltip {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    z-index: 1000;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 200px;
    background: #1b3a5c;
    color: #fff;
    font-family: 'DM Sans', sans-serif;
    font-size: 12px;
    line-height: 1.4;
    text-align: left;
    padding: 8px 10px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    transition: opacity 0.15s ease;
    pointer-events: none;
}

.layer-info-icon:hover .layer-info-tooltip {
    visibility: visible;
    opacity: 1;
}

/* Riverbed Surveys tooltip has a longer explanation plus a 3-line risk
   breakdown, so it needs more width than the default 200px box to stay
   readable instead of turning into a tall, narrow column. */
.layer-info-icon .layer-info-tooltip-wide {
    width: 300px;
}

/* ==========================================================================
   Mobile layout (phones / narrow tablets)
   The desktop layout is built from fixed-px floating panels over a full-height
   map, which is fine on a laptop screen but overflows or clips on a phone.
   Everything below only kicks in under 768px; desktop is untouched. Most of
   these panels get their base look from inline `style={}` dicts set in
   app.py's Python layout (and swapped between hidden/visible dicts by
   callbacks), so overriding them here requires `!important`.
   ========================================================================== */
@media (max-width: 768px) {

    /* Header: title + nav no longer fit in one row, so stack them instead of
       letting the row overflow sideways */
    #app-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        height: auto !important;
        padding: 10px 14px !important;
        gap: 8px;
    }
    #app-title {
        margin: 0 !important;
        font-size: 18px !important;
        letter-spacing: 0.5px !important;
    }
    #nav-links {
        width: 100%;
        flex-wrap: wrap;
        gap: 4px 14px;
    }
    #nav-links button {
        margin-left: 0 !important;
        font-size: 12px !important;
        padding: 4px 2px !important;
    }

    /* Map fills whatever's left under the now-taller (wrapped) header */
    #map-container {
        height: 85vh !important;
    }

    /* Year/layers control box: the desktop version (year dropdown + 5-layer
       checklist, one of which has a full risk-tier breakdown) is tall enough
       to cover most of a phone screen. Cap it to a fraction of the viewport
       in both directions and let it scroll internally instead. */
    #map-controls {
        max-width: 58vw !important;
        max-height: 42vh !important;
        overflow-y: auto;
    }
    #year-select-wrapper, #layer-toggle-wrapper {
        width: 100% !important;
    }

    /* Floating detail panels (notice/survey/gage click-throughs) are sized in
       px for a desktop map; cap them so they can't run off a phone screen */
    #notice-detail-box,
    #gage-detail-box,
    #survey-detail-banner,
    #survey-legend-box,
    #insights-2026-box,
    #current-gage-box,
    #survey-zoom-memo {
        max-width: 78vw !important;
        width: auto !important;
    }

    /* Survey banner + depth legend + current-gage + zoom-memo stack together
       top-right when a survey dot is tapped -- on a short phone screen that
       whole column can run past the bottom of the viewport. Cap the stack as
       a group and let it scroll rather than spilling off-screen. */
    #survey-panels-stack {
        max-height: 55vh !important;
        overflow-y: auto !important;
    }

    /* Gage-frequency panel reserves a 330px gap on its right for the survey
       legend column on desktop -- on a phone that leaves almost no room, so
       just span the width instead */
    #gage-freq-panel {
        left: 10px !important;
        right: 10px !important;
    }

    /* Price-plots and insights-summary slide-out panels: their desktop widths
       are wider than most phones, which pushes their left edge off-screen.
       Only applies when open (the closed state is width:0, matched by the
       open-state widths instead) */
    #plots-panel[style*="420px"],
    #insights-panel[style*="380px"] {
        width: 90vw !important;
    }
    #insights-toggle,
    #plots-toggle {
        font-size: 11px !important;
        padding: 8px 5px !important;
    }

    /* Full-page sections: desktop padding is generous, phones need it tight */
    #demand-page, #about-page {
        padding: 16px 14px !important;
    }

    /* Demand-page explanation boxes and chart columns are flex items with a
       400px min-width for the desktop side-by-side layout -- on a phone that
       min-width is wider than the screen itself, forcing horizontal scroll.
       Let them shrink to full-width single-column instead. */
    .demand-explanation-box, .crop-chart-col {
        min-width: 0 !important;
        width: 100% !important;
    }

    /* Compare-years modal holds fixed-width (596px) Plotly figures that won't
       resize themselves -- cap the modal to the viewport and let the figures
       scroll horizontally inside it rather than blowing out the page */
    #compare-years-box {
        width: 92vw !important;
        max-width: 92vw !important;
        padding: 30px 10px 16px 10px !important;
        overflow-x: auto;
    }
    #compare-years-toggle {
        font-size: 14px !important;
        padding: 10px 16px !important;
        width: 100%;
        box-sizing: border-box;
    }
}
