.map-page {
    --map-header-offset: 118px;
    --map-toolbar-gap: 14px;
    /* Fallback until JS measures the real toolbar height (handles wrap). */
    --map-control-offset: 96px;
}

.site-main.map-page {
    width: 100%;
    padding: 0;
    position: relative;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.site-footer {
    display: none;
}

/* Overlay the header on the map page. Keeping it in normal flow while also
   offsetting #map by the header height created a double-tall grey gap. */
.site-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
}

.site-header__inner {
    width: min(calc(100% - 32px), var(--site-max));
    align-items: flex-start;
}

#map {
    position: absolute;
    top: var(--map-header-offset);
    bottom: 0;
    left: 0;
    right: 0;
    transition: right 0.3s ease;
}

#map.panel-open {
    right: 400px;
}

#side-panel {
    position: absolute;
    top: var(--map-header-offset);
    right: -400px;
    width: 400px;
    height: calc(100% - var(--map-header-offset));
    background: white;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    transition: right 0.3s ease;
    padding: 20px;
    overflow-y: auto;
    z-index: 1000;
}

#side-panel.open {
    right: 0;
}

.map-toolbar {
    position: absolute;
    top: calc(var(--map-header-offset) + var(--map-toolbar-gap));
    left: 20px;
    right: auto;
    z-index: 850;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    max-width: min(860px, calc(100% - 48px));
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid #d9d9d9;
    padding: 10px 12px;
}

/* Keep controls clear of the right-hand overview drawer on desktop. */
.map-page:has(#side-panel.open) .map-toolbar {
    max-width: min(860px, calc(100% - 440px));
}

.leaflet-top.leaflet-left {
    top: calc(var(--map-header-offset) + var(--map-control-offset));
}

.map-toolbar label {
    font-size: 0.9rem;
    font-weight: 700;
    color: #111111;
}

.map-select {
    font-size: 0.95rem;
    font-weight: 600;
    padding: 8px 10px;
    border: 1px solid #bfbfbf;
    background: white;
    color: #111111;
}

.map-mode-indicator {
    display: inline-flex;
    align-items: center;
    padding: 8px 10px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #ffffff;
    background: #111111;
    border: 1px solid #111111;
}

.map-mode-helper {
    font-size: 0.85rem;
    color: #444444;
    font-weight: 600;
}

.map-overview-btn {
    cursor: pointer;
}

.legend {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: white;
    padding: 15px;
    border: 1px solid #d8dde0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 800;
}

@media (max-width: 900px) {
    /* Reclaim vertical space: the tagline is not worth a map row on phones. */
    .map-page .site-tagline {
        display: none;
    }

    .map-page {
        --map-control-offset: 118px;
    }

    #map.panel-open {
        right: 0;
    }

    /* Bottom sheet: hidden off-screen until .open. The previous rule applied the
       open layout to #side-panel itself, so the overview never dismissed and the
       map stayed a thin strip above it. */
    #side-panel {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: min(48vh, 420px);
        max-height: calc(100dvh - var(--map-header-offset) - 72px);
        transform: translateY(110%);
        transition: transform 0.28s ease;
        pointer-events: none;
        box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.14);
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    }

    #side-panel.open {
        transform: translateY(0);
        pointer-events: auto;
    }

    /* Full-width compact strip directly under the header instead of a
       floating box that covers the map. */
    .map-toolbar,
    .map-page:has(#side-panel.open) .map-toolbar {
        top: var(--map-header-offset);
        left: 0;
        right: 0;
        width: auto;
        max-width: none;
        border-left: none;
        border-right: none;
        padding: 8px 10px;
        gap: 8px;
    }

    .postcode-search {
        flex: 1 1 100%;
    }

    .postcode-search__input {
        flex: 1;
        width: auto;
        min-width: 0;
    }

    .close-btn {
        min-width: 44px;
        min-height: 44px;
        z-index: 2;
    }
}

@media (max-width: 640px) {
    .map-page {
        --map-control-offset: 132px;
    }

    .map-toolbar label {
        display: none;
    }

    .map-select {
        font-size: 0.85rem;
        padding: 6px 8px;
    }

    .postcode-search__button {
        font-size: 0.85rem;
        padding: 6px 10px;
    }

    /* The legend eats a big corner of a small screen; colour intensity is
       self-explanatory enough on phones. */
    .legend {
        display: none;
    }

    #side-panel {
        height: min(52vh, 460px);
    }
}
