/* The map pages on smaller screens (wwwroot/js/map-sheet.js).
   1100px and up: the panel is a column beside the map (map.css).
   768-1099px: the map takes the full width and the panel floats over its
   right-hand side as a card that folds up to its bar.
   Below 768px: the page is just the map, filling the screen under the header,
   with the panel as a sheet along the bottom; the page itself doesn't scroll,
   so one finger moves the map. */

:root { --sheet-bar: 3.25rem; }

/* The bar across the top of the panel: its title and a chevron to open or
   close it. Only shown when the panel is over the map. */
.map-sheet__handle {
    display: none;
    align-items: center;
    gap: 0.75rem;
    width: calc(100% + 2rem);
    min-height: var(--sheet-bar);
    margin: 0 -1rem 0.75rem;
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 1;
    background: #fff;
    border-bottom: 1px solid #f3f4f6;
}

.map-sheet__toggle {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 0.75rem;
    align-self: stretch;
    padding: 0;
    background: none;
    border: 0;
    font: 600 0.875rem var(--font-sans);
    color: #111827;
    text-align: left;
    cursor: pointer;
}

.map-sheet__toggle::after {
    content: "";
    flex: none;
    margin-left: auto;
    width: 0.5rem;
    height: 0.5rem;
    border-right: 2px solid #6b7280;
    border-bottom: 2px solid #6b7280;
    transform: translateY(2px) rotate(-135deg);
    transition: transform 0.15s;
}

.is-collapsed > .map-sheet__handle .map-sheet__toggle::after { transform: translateY(-2px) rotate(45deg); }
.is-collapsed > .map-sheet__handle { margin-bottom: 0; border-bottom: 0; }

/* Feedback, on phones, sits in the bar instead of over the map's controls. */
.map-sheet__feedback {
    display: none;
    flex: none;
    padding: 0.25rem 0.75rem;
    border: 1px solid var(--brand-red);
    border-radius: 999px;
    background: none;
    color: var(--brand-red);
    font: 600 0.75rem var(--font-sans);
    cursor: pointer;
}

/* Full screen: the panel is a Google control (map-fullscreen.js), and can fold up too. */
.map-legend.is-floating { padding-top: 0; }
.map-legend.is-floating > .map-sheet__handle { display: flex; }
.map-legend.is-floating.is-collapsed { padding-bottom: 0; }
.map-legend.is-floating.is-collapsed > :not(.map-sheet__handle) { display: none !important; }

@media (max-width: 1099px) {
    .map-layout {
        display: block;
        position: relative;
    }

    .map-layout > .map-legend {
        position: absolute;
        z-index: 5;
        overflow-y: auto;
        padding-top: 0;
        border: 0;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    }

    .map-layout > .map-legend:hover { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); }
    .map-layout > .map-legend > .map-sheet__handle { display: flex; }
    .map-layout > .map-legend.is-collapsed { padding-bottom: 0; }
    .map-layout > .map-legend.is-collapsed > :not(.map-sheet__handle) { display: none !important; }
}

@media (min-width: 768px) and (max-width: 1099px) {
    /* Under Google's full-screen button, clear of its zoom controls. */
    .map-layout > .map-legend {
        top: 60px;
        right: 10px;
        width: 19rem;
        max-width: calc(100% - 20px);
        max-height: calc(100% - 160px);
        min-height: 0;
    }

    .map-layout > .map-legend.is-collapsed { width: 15rem; }
}

@media (max-width: 767px) {
    body:has(.map-layout) {
        height: 100vh;
        height: 100dvh;
        min-height: 0;
        overflow: hidden;
    }

    body:has(.map-layout) .footer { display: none; }

    body:has(.map-layout) .page-content {
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
        min-height: 0;
        padding-top: 0.75rem;
        padding-bottom: 0;
    }

    .map-toolbar {
        gap: 0.5rem 1rem;
        margin-bottom: 0.625rem;
        padding-top: 0.75rem;
        padding-bottom: 0.625rem;
    }

    .map-toolbar__title { font-size: 1.375rem; }

    .map-toolbar .search-form--inline { flex: 1 1 14rem; }

    /* The other tools: one row to swipe along. */
    .map-toolbar__links {
        flex-wrap: nowrap;
        width: calc(100% + 2rem);
        margin: 0 -1rem;
        padding: 0 1rem 0.125rem;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .map-toolbar__links::-webkit-scrollbar { display: none; }
    .map-toolbar__links > a { flex: none; }

    /* Edge to edge, leaving the strip at the bottom for the sheet's bar. */
    .map-layout {
        flex: 1 1 auto;
        min-height: 0;
        margin: 0 -1rem;
        padding-bottom: var(--sheet-bar);
    }

    .map-layout > .map {
        height: 100%;
        min-height: 0;
        border-radius: 0;
        border-width: 1px 0 0;
    }

    .map-layout > .map-legend {
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 950;
        max-height: 62%;
        margin: 0;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.18);
        font-size: 0.875rem;
    }

    .map-layout > .map-legend:hover { box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.18); }
    .map-layout > .map-legend.is-collapsed { padding-bottom: env(safe-area-inset-bottom); }

    /* A grab bar, as phones' own sheets have. */
    .map-layout > .map-legend > .map-sheet__handle::before {
    pointer-events: none;
        content: "";
        position: absolute;
        top: 0.375rem;
        left: 50%;
        width: 2.25rem;
        height: 0.25rem;
        margin-left: -1.125rem;
        border-radius: 2px;
        background: #d1d5db;
    }

    /* It opens upwards, so the chevron points the other way. */
    .map-layout > .map-legend .map-sheet__toggle::after { transform: translateY(-2px) rotate(45deg); }
    .map-layout > .map-legend.is-collapsed .map-sheet__toggle::after { transform: translateY(2px) rotate(-135deg); }

    .map-layout > .map-legend .map-sheet__feedback { display: inline-block; }
    body:has(.map-layout) .feedback-button { display: none; }

    /* Below Google's map type buttons rather than over them. A fixed width,
       because Google doesn't re-centre the control when its text changes. */
    .map-banner {
        margin-top: 3.5rem;
        width: calc(100vw - 1.5rem);
        min-width: 0;
        max-width: none;
    }

    /* Inputs at 16px, so phones don't zoom in on them. */
    .map-legend input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
    .map-legend select,
    .map-toolbar input { font-size: 1rem; }
}
