.map-page {
    position: relative;
    display: grid;
    grid-template: minmax(0, 1fr) auto auto auto auto / minmax(0, 1fr);
    row-gap: .75rem;
    box-sizing: border-box;
    padding: .5rem max(1rem, env(safe-area-inset-right)) max(.5rem, env(safe-area-inset-bottom)) .5rem;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: #e5edf0;
    color: #243c37;
}

.map-viewport {
    position: absolute;
    inset: 0;
}

.map-viewport canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

.map-toolbar,
.map-attribution,
.map-message {
    position: absolute;
    z-index: 1;
    padding: .75rem 1rem;
    border-radius: .4rem;
    background: rgba(255, 255, 255, .95);
}

.map-top-panels {
    position: absolute;
    z-index: 2;
    top: max(1rem, env(safe-area-inset-top));
    left: max(1rem, env(safe-area-inset-left));
    right: max(1rem, env(safe-area-inset-right));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
    pointer-events: none;
}

.map-top-panels > * { pointer-events: auto; }

.map-toolbar {
    position: static;
    box-sizing: border-box;
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}

#map-share {
    border-color: #8fc79a;
    background-color: #d5f0d9;
    color: #243c37;
}

#map-share:hover:not(:disabled),
#map-share:focus-visible {
    border-color: #6fb07c;
    background-color: #bfe6c5;
}

.map-toolbar h1 {
    flex: 1 1 10rem;
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.map-brand {
    display: block;
    flex: 0 0 auto;
    border-radius: .2rem;
}

.map-brand img {
    display: block;
    width: 60px;
    height: auto;
}

.map-brand:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 4px;
}

.map-message {
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: max-content;
    max-width: calc(100% - 2rem);
    text-align: center;
    pointer-events: none;
}

.map-message[hidden] {
    display: none;
}

.map-error {
    color: #8a2424;
    border: 1px solid currentColor;
}

.map-attribution {
    right: max(.5rem, env(safe-area-inset-right));
    bottom: max(.5rem, env(safe-area-inset-bottom));
    max-width: calc(100% - 1rem);
    padding: .35rem .5rem;
    font-size: .5rem;
    line-height: 1.25;
    pointer-events: none;
}

/* Les trois contrôles suivent la hauteur réelle des couches, ouvertes ou repliées. */
.map-page > .map-layers { position: static; grid-row: 3; justify-self: end; }
.map-page > .map-attribution { position: static; grid-row: 4; justify-self: end; }

/* Lot 3 : nom du lieu ciblé, actions de la barre et message de position. */
.map-place {
    font-weight: 400;
}

.map-actions {
    display: flex;
    flex-wrap: wrap;
    margin-left: auto;
    gap: .5rem;
}

.map-quality-control[x-cloak],
.map-quality-notice[x-cloak] { display: none !important; }

.map-quality-control {
    display: flex;
    align-items: center;
    gap: .5rem;
    min-width: 0;
    padding: .25rem .5rem;
    border-radius: .4rem;
    background: rgba(255, 255, 255, .95);
    font-size: .875rem;
}

.map-quality-control > span { font-weight: 600; white-space: nowrap; }
.map-quality-control button,
.map-quality-actions button { height: auto; min-height: 36px; white-space: normal; }

.map-quality-notice {
    box-sizing: border-box;
    width: min(36rem, 100%);
    padding: .75rem 1rem;
    border: 1px solid #8a691b;
    border-radius: .4rem;
    background: #fff7dc;
    color: #493b19;
    font-size: .875rem;
    line-height: 1.4;
}

.map-quality-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.map-quality-actions > :first-child { flex: 1 1 14rem; }
.map-quality-control :focus-visible,
.map-quality-notice :focus-visible { outline: 3px solid #176b86; outline-offset: 3px; }

#map-superzoom {
    --superzoom-halo: 213, 0, 0;
    grid-row: 2;
    justify-self: end;
    z-index: 2;
    box-sizing: border-box;
    min-height: 52px;
    max-width: 100%;
    padding: .8rem 1.25rem;
    border: 2px solid transparent;
    border-radius: .5rem;
    background: #d50000;
    color: #fff;
    font: inherit;
    font-size: 1.125rem;
    font-weight: 750;
    line-height: 1.3;
    cursor: pointer;
    white-space: nowrap;
    transform-origin: center;
    box-shadow: 0 0 0 4px rgba(var(--superzoom-halo), .18);
}

#map-superzoom[hidden] { display: none; }
#map-superzoom[data-state="off"],
#map-superzoom[data-state="on"] { animation: map-superzoom-pulse 1.5s ease-out infinite; }
#map-superzoom[data-state="on"] { --superzoom-halo: 176, 0, 0; background: #b00000; animation-duration: 1.6s; }
#map-superzoom[data-state="loading"] {
    animation: none;
    background: #e4e8eb;
    color: #42515c;
    border-color: #7b8993;
    border-style: dashed;
    box-shadow: none;
    cursor: wait;
}
#map-superzoom:disabled { cursor: wait; }
#map-superzoom:hover,
#map-superzoom:focus-visible { animation-play-state: paused; }
#map-superzoom:focus-visible { outline: 3px solid #172d3c; outline-offset: 5px; }

@keyframes map-superzoom-pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(var(--superzoom-halo), .5); }
    65% { transform: scale(1.04); box-shadow: 0 0 0 11px rgba(var(--superzoom-halo), 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 15px rgba(var(--superzoom-halo), 0); }
}

@media (prefers-reduced-motion: reduce) {
    #map-superzoom[data-state] { animation: none; transform: none; }
}

.map-notice {
    display: flex;
    align-items: center;
    gap: .75rem;
    position: static;
    z-index: 1;
    box-sizing: border-box;
    max-width: 100%;
    margin: 0;
    padding: .5rem .9rem;
    border-radius: .4rem;
    background: rgba(255, 255, 255, .95);
    font-size: .875rem;
    word-break: break-all;
}

.map-notice[hidden] {
    display: none;
}

.map-notice:has(> [hidden]) {
    display: none;
}

.map-notice p { min-width: 0; }
.map-notice button { flex-shrink: 0; }
.map-notice button:focus-visible { outline: 3px solid #176b86; outline-offset: 3px; }

/* Aide commune à la page autonome et au dialog natif. */
.map-bottom-controls {
    grid-row: 5;
    justify-self: start;
    display: flex;
    align-items: center;
    gap: .5rem;
    max-width: 100%;
    z-index: 2;
}

.map-help-button {
    flex-shrink: 0;
    background: #cce9ff;
    border-color: #79b9e6;
    color: #17415f;
    font-weight: 600;
}
.map-help-button:hover,
.map-help-button:focus-visible { background: #b5dfff; border-color: #3986bd; color: #17415f; }

.map-help-dialog {
    box-sizing: border-box;
    width: min(40rem, 92vw);
    max-width: none;
    max-height: 85vh;
    margin: auto;
    padding: 0;
    border: 0;
    border-radius: .5rem;
    background: #fff;
    color: #243c37;
    overflow: hidden;
}

.map-help-dialog[open] { display: flex; flex-direction: column; }
.map-help-dialog::backdrop { background: rgba(0, 0, 0, .55); }
.map-help-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem; border-bottom: 1px solid #ddd; }
.map-help-header h2 { font-size: 1.25rem; font-weight: 700; }
.map-help-body { padding: 0 1.25rem 1.25rem; overflow-y: auto; overscroll-behavior: contain; }
.map-help-page { max-width: 46rem; margin: auto; padding: 1.5rem; color: #243c37; }
.map-help-content { line-height: 1.6; }
.map-help-content h2 { margin: 1.25rem 0 .5rem; font-size: 1.2rem; font-weight: 700; }
.map-help-content h3 { margin: .75rem 0 .25rem; font-weight: 600; }
.map-help-content p + p { margin-top: .5rem; }
.map-help-content ul { margin: .5rem 0 .5rem 1.25rem; list-style: disc; }
.map-help-content .map-help-legend { margin-left: 0; list-style: none; }
.map-help-legend li { display: flex; align-items: baseline; gap: .75rem; margin: .4rem 0; }
.map-help-symbol { display: inline-block; flex: 0 0 auto; width: .6rem; height: .6rem; margin: 0 .2rem; background: #1d2124; }
.map-help-subprefecture { border-radius: 50%; }
.map-help-canton, .map-help-commune { width: .35rem; height: .35rem; margin: 0 .325rem; border-radius: 50%; }
.map-help-commune { background: #454c54; }
.map-help-peak { background: #6b4423; width: 1rem; height: .85rem; margin: 0; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.map-help-snow { background: #b3121b; }
.map-help-button:focus-visible, .map-help-dialog :focus-visible, .map-help-page :focus-visible { outline: 3px solid #176b86; outline-offset: 3px; }

@media (max-width: 599px) {
    .map-help-dialog { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
    .map-help-header { padding-top: max(1rem, env(safe-area-inset-top)); }
    .map-help-body { padding-bottom: max(1.25rem, env(safe-area-inset-bottom)); }
}

/* Fiches publiques et fenêtre d'objet : couleurs explicites pour les contrastes AA. */
.map-object-dialog {
    box-sizing: border-box;
    width: min(40rem, 92vw);
    max-width: none;
    max-height: 85dvh;
    margin: auto;
    padding: 0;
    border: 2px solid #61716d;
    border-radius: .5rem;
    background: #fff;
    color: #243c37;
    overflow: hidden;
}
.map-object-dialog[open] { display: flex; flex-direction: column; }
.map-object-dialog::backdrop { background: rgba(0, 0, 0, .55); }
.map-object-header { display: flex; flex-shrink: 0; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem; border-bottom: 1px solid #61716d; }
.map-object-header h2, .map-object-page h1 { font-size: 1.3rem; font-weight: 700; overflow-wrap: anywhere; }
.map-object-body { padding: 1rem 1.25rem; overflow-y: auto; overscroll-behavior: contain; }
.map-object-page { max-width: 46rem; margin: auto; padding: 1.5rem; background: #fff; color: #243c37; }
.map-object-content { line-height: 1.6; overflow-wrap: anywhere; }
.map-object-name { font-weight: 700; }
.map-object-content dl { margin: .75rem 0 1rem; }
.map-object-content dt { font-weight: 600; }
.map-object-content dd { margin: 0 0 .5rem; }
.map-object-content h2 { margin-top: 1rem; font-weight: 700; }
.map-object-content ul { margin: .5rem 0; list-style: none; }
.map-object-content a { display: inline-block; min-height: 24px; padding: .15rem 0; color: #125b78; text-decoration: underline; }
.map-object-dialog .button, .map-object-page .button { min-width: 24px; min-height: 32px; border: 1px solid #61716d; background: #fff; color: #243c37; }
.map-object-dialog :focus-visible, .map-object-page :focus-visible { outline: 3px solid #176b86; outline-offset: 3px; }
.map-visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
@media (max-width: 599px) {
    .map-object-dialog { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
    .map-object-header { padding-top: max(1rem, env(safe-area-inset-top)); }
    .map-object-body { padding-bottom: max(1.25rem, env(safe-area-inset-bottom)); }
}

/* Recherche R.B : le template ne pilote que l'interface, le moteur applique les vues. */
.map-search {
    position: relative;
    flex: 1 1 19rem;
    max-width: 30rem;
    min-width: 0;
}
/* Libellé lu par les lecteurs d'écran : à l'écran, le texte d'exemple du champ suffit et la barre reste basse. */
.map-search-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
#map-search-input {
    box-sizing: border-box;
    width: 100%;
    min-height: 44px;
    padding: .5rem .75rem;
    border: 1px solid #61716d;
    border-radius: .3rem;
    background: #fff;
    color: #243c37;
    font: inherit;
    font-size: 16px;
}
.map-search-popup[x-cloak], .map-search-card[x-cloak] { display: none !important; }
.map-search-popup {
    position: absolute;
    z-index: 6;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: .25rem;
    border: 1px solid #61716d;
    border-radius: .3rem;
    background: #fff;
    box-shadow: 0 .25rem .75rem #243c3733;
    max-height: min(38dvh, 23rem);
    overflow-y: auto;
    overflow-wrap: anywhere;
    overscroll-behavior: contain;
}
.map-search-popup p { padding: .6rem; margin: 0; }
.map-search-popup a { color: #125b78; display: inline-block; min-height: 44px; align-content: center; }
#map-search-list { list-style: none; padding: 0; margin: 0; }
#map-search-list [role="option"] {
    box-sizing: border-box;
    min-height: 44px;
    padding: .5rem .75rem;
    border-bottom: 1px solid #d7e1df;
    cursor: pointer;
}
#map-search-list .is-active { background: #d5e9ef; outline: 2px solid #176b86; outline-offset: -2px; }
#map-search-list [aria-disabled="true"] { cursor: wait; }
.map-search-name { display: block; font-weight: 600; }
.map-search-context { display: block; font-size: .85rem; }
.map-search-count { display: block; padding: .35rem .75rem; font-size: .8rem; }
.map-search-card {
    box-sizing: border-box;
    align-self: flex-start;
    width: min(100%, 29rem);
    padding: .65rem .8rem;
    border: 1px solid #61716d;
    border-radius: .4rem;
    background: rgba(255, 255, 255, .97);
    overflow-wrap: anywhere;
}
.map-search-card h2 { margin: 0; font-size: 1rem; }
.map-search-card p { margin: .25rem 0 .5rem; font-size: .9rem; }
.map-search-card-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.map-search-card .button { min-height: 44px; white-space: normal; height: auto; }
#map-search-input:focus-visible, .map-search-card button:focus-visible, .map-search-popup a:focus-visible {
    outline: 3px solid #176b86;
    outline-offset: 2px;
}
@media (max-width: 650px) {
    .map-toolbar { gap: .4rem; padding: .5rem; }
    .map-toolbar h1 { flex-basis: 9rem; }
    .map-search { order: 3; flex-basis: 100%; max-width: none; }
    .map-actions { gap: .4rem; }
    .map-actions .button { min-height: 44px; }
    .map-search-card { padding: .5rem; }
    .map-search-card-actions { gap: .3rem; }
    .map-search-card .button { padding-left: .5rem; padding-right: .5rem; font-size: .85rem; }
}

/* D28 : les nouveaux contrôles sont absents de la mise en page du bureau. */
.map-mobile-bar, .map-mobile-menu, .map-mobile-layers-header, .map-mobile-search-close { display: none; }

@media (max-width: 650px), (max-height: 500px) {
    .map-page {
        --map-bar-height: calc(52px + env(safe-area-inset-bottom));
        --map-result-height: 0px;
        --map-notice-height: 0px;
        --map-quality-height: 0px;
        display: block;
        padding: 0;
    }
    .map-top-panels { position: static; display: contents; }
    .map-toolbar { display: contents; }
    .map-brand, .map-toolbar h1, .map-actions, .map-bottom-controls,
    .map-page > .map-attribution, .map-page > .map-layers, .map-search { display: none; }
    .map-mobile-bar {
        position: absolute;
        z-index: 8;
        inset: auto 0 0;
        display: flex;
        padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
        background: #fff;
        border-top: 1px solid #61716d;
    }
    .map-mobile-bar button { flex: 1; min-height: 52px; }
    .map-mobile-bar button + button { border-left: 1px solid #61716d; }
    .map-mobile-bar button, .map-mobile-menu button, .map-mobile-menu a,
    .map-mobile-layers-header button, .map-mobile-search-close {
        box-sizing: border-box;
        min-width: 44px;
        min-height: 44px;
        padding: .5rem .75rem;
        border: 0;
        background: #fff;
        color: #243c37;
        font: inherit;
        cursor: pointer;
        text-align: left;
    }
    .map-mobile-bar button { text-align: center; }
    .map-mobile-bar [aria-expanded="true"] { background: #d5e9ef; }
    .map-mobile-menu a { display: block; text-decoration: underline; color: #125b78; }
    .map-mobile-menu button:disabled { color: #58645f; cursor: wait; }
    .map-mobile-bar :focus-visible, .map-mobile-menu :focus-visible,
    .map-mobile-layers-header :focus-visible, .map-mobile-search-close:focus-visible {
        outline: 3px solid #176b86; outline-offset: -3px;
    }
    .map-mobile-menu, .map-page > .map-layers {
        position: absolute;
        z-index: 7;
        bottom: calc(var(--map-bar-height) + .5rem);
        left: max(.5rem, env(safe-area-inset-left));
        right: max(.5rem, env(safe-area-inset-right));
        width: auto;
        justify-self: stretch;
        max-width: none;
        max-height: calc(100dvh - var(--map-bar-height) - env(safe-area-inset-top) - 1rem);
        overflow-y: auto;
        overscroll-behavior: contain;
        border: 1px solid #61716d;
        border-radius: .4rem;
        background: #fff;
        color: #243c37;
        box-shadow: 0 .2rem .8rem #243c3733;
    }
    .map-page[data-mobile-panel="menu"] .map-mobile-menu { display: flex; flex-direction: column; }
    .map-mobile-menu header, .map-mobile-layers-header {
        display: flex; align-items: center; justify-content: space-between;
        padding-left: .75rem; border-bottom: 1px solid #61716d;
    }
    .map-mobile-menu > button, .map-mobile-menu > a { flex-shrink: 0; }
    .map-mobile-layers-header { display: none; }
}

/* Téléphone à l'horizontale : menu sur deux colonnes, toutes les entrées visibles sans défilement. */
@media (max-height: 500px) and (orientation: landscape) {
    .map-page[data-mobile-panel="menu"] .map-mobile-menu {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-content: start;
    }
    .map-mobile-menu header { grid-column: 1 / -1; }
}

@media (max-width: 650px), (max-height: 500px) {
    .map-page[data-mobile-panel="layers"] > .map-layers {
        display: block;
        max-height: calc(100dvh - var(--map-bar-height) - env(safe-area-inset-top) - 1rem);
    }
    .map-page[data-mobile-panel="layers"] .map-mobile-layers-header {
        display: flex;
        position: sticky;
        z-index: 2;
        top: 0;
        background: #fff;
        border: 1px solid #61716d;
        border-radius: .4rem;
    }
    .map-page > .map-layers button, .map-page > .map-layers select, .map-page > .map-layers label { min-height: 44px; }
    .map-page > .map-layers .map-layers-toggle[hidden] { display: none; }
    .map-page > .map-layers label.is-unavailable, .map-page > .map-layers .map-layers-note { color: #58645f; }
    .map-page[data-mobile-panel="search"] .map-search {
        display: block;
        position: absolute;
        z-index: 7;
        top: 0; left: 0; right: 0;
        width: 100%; max-width: none;
        padding: max(.5rem, env(safe-area-inset-top)) calc(52px + env(safe-area-inset-right)) .5rem max(.5rem, env(safe-area-inset-left));
        background: #fff;
        pointer-events: auto;
    }
    .map-mobile-search-close { display: block; position: absolute; right: env(safe-area-inset-right); bottom: .5rem; }
    .map-search-popup { margin: 0; max-height: calc(100dvh - var(--map-bar-height) - env(safe-area-inset-top) - 65px); box-shadow: none; }
    .map-search-card {
        position: absolute;
        z-index: 3;
        bottom: calc(var(--map-bar-height) + .5rem);
        left: max(.5rem, env(safe-area-inset-left));
        right: max(.5rem, env(safe-area-inset-right));
        width: auto;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 0 .4rem;
        padding: .35rem .5rem;
    }
    .map-search-card h2, .map-search-card p { grid-column: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
    .map-search-card p { margin: 0; font-size: .75rem; }
    .map-search-card-actions { grid-column: 2; grid-row: 1 / 3; flex-wrap: nowrap; align-items: center; }
    .map-search-card .map-search-copy { display: none; }
    .map-search-card .button { padding: .35rem; font-size: .75rem; }
    .map-notice, .map-quality-notice {
        position: absolute;
        z-index: 5;
        left: max(.5rem, env(safe-area-inset-left));
        right: max(.5rem, env(safe-area-inset-right));
        width: auto;
        max-height: calc(100dvh - var(--map-bar-height) - var(--map-result-height) - 1.5rem);
        overflow-y: auto;
        padding: .4rem .6rem;
        font-size: .8rem;
        pointer-events: auto;
    }
    .map-notice { bottom: calc(var(--map-bar-height) + var(--map-result-height) + 1rem); word-break: break-word; }
    .map-quality-notice { bottom: calc(var(--map-bar-height) + var(--map-result-height) + var(--map-notice-height) + 1.5rem); }
    .map-quality-actions { margin-top: .25rem; gap: .25rem; }
    .map-quality-actions > :first-child { flex-basis: 10rem; }
    .map-quality-notice button, .map-notice button { min-height: 44px; }
    #map-superzoom {
        position: absolute;
        z-index: 4;
        right: max(.75rem, env(safe-area-inset-right));
        bottom: calc(var(--map-bar-height) + var(--map-result-height) + var(--map-notice-height) + var(--map-quality-height) + 1.5rem);
        max-width: calc(100% - 1.5rem);
        min-height: 44px;
        padding: .6rem .75rem;
        font-size: .9rem;
        white-space: normal;
    }
    .map-help-dialog, .map-object-dialog { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
    .map-help-header, .map-object-header { padding-top: max(.5rem, env(safe-area-inset-top)); }
    .map-help-body, .map-object-body { padding-bottom: max(1rem, env(safe-area-inset-bottom)); }
    .map-help-header button, .map-object-header button { min-height: 44px; }
}
