/* @grammaire v2
   ══════════════════════════════════════════════════════════════
   CARTE DES DÉFIBRILLATEURS — /defibrillateurs (gabarit CMS `aed-map`).
   La carte occupe tout l'écran ; le panneau (recherche, légende, crédits)
   flotte à gauche au bureau et devient une feuille sous la carte au
   téléphone. Les jetons (papier, encre, vert du défibrillateur) et les
   polices sont ceux du défi RCP, déclarés sur `.cpr` dans
   `zones/cpr-challenge.css`, que la page charge aussi.
   ══════════════════════════════════════════════════════════════ */

.aed {
    /* Les trois disponibilités déclarées. Le vert est celui de l'action ;
       « horaires déclarés » en anneau du même vert, « non renseigné » en gris :
       la forme double la couleur. */
    --aed-always: var(--cpr-action);
    /* Foncé : le Plan IGN dessine ses propres pictogrammes en gris clair, et
       une épingle « non renseigné » trop pâle s'y confondait. */
    --aed-unknown: #4f4c48;
    --aed-here: #1b5fd1;
    --aed-shadow: rgba(17, 17, 17, 0.5);
    --aed-panel-w: 390px;

    position: relative;
    min-height: 100vh;
    min-height: 100dvh;
}

.aed__main {
    position: relative;
    height: 100vh;
    height: 100dvh;
}

.aed__stage {
    position: absolute;
    inset: 0;
    z-index: 0;
}

.aed__map {
    position: absolute;
    inset: 0;
    background: var(--cpr-line-2);
}

/* Le logo en cartouche sur la carte, à côté du panneau. Huit rem au bureau,
   sept au téléphone (demande de l'ANCESU : sept à huit rem au moins). Au-dessus
   des tuiles et des marqueurs de Leaflet (400 à 700), sous ses contrôles (800
   et plus) et ses bulles. */
.aed__logo {
    position: absolute;
    left: calc(var(--aed-panel-w) + 32px);
    bottom: 24px;
    z-index: 750;
    display: block;
    padding: 8px 12px;
    background: var(--cpr-white);
    box-shadow: var(--cpr-shadow-lift);
}

/* Le Plan IGN est très coloré (routes orange, forêts vertes) : atténué, il
   laisse les épingles ressortir. Seules les TUILES sont filtrées, pas les
   marqueurs. */
.aed .leaflet-tile-pane { filter: saturate(.3) brightness(1.05); }

/* — Le panneau — */
.aed__panel {
    position: absolute;
    top: 16px;
    left: 16px;
    bottom: 16px;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-sizing: border-box;
    width: var(--aed-panel-w);
    padding: 20px 22px;
    overflow-y: auto;
    border-top: 6px solid var(--cpr-action);
    background: var(--cpr-paper);
    color: var(--cpr-ink);
    box-shadow: var(--cpr-shadow-lift);
}

.aed__head {
    display: flex;
    align-items: center;
    gap: 12px;
}

.aed__logo img {
    display: block;
    width: auto;
    height: 8rem;
}

.aed__back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 44px;
    font-size: 14px;
    font-weight: 800;
    text-decoration: none;
}

.aed__back:hover { text-decoration: underline; text-underline-offset: 4px; }

.aed__title {
    margin: 0;
    font-family: var(--cpr-display);
    font-stretch: 72%;
    font-weight: 800;
    font-size: clamp(32px, 3vw, 44px);
    line-height: .92;
    text-transform: uppercase;
}

.aed__lead {
    margin: 0;
    font-size: 15px;
    line-height: 1.5;
    color: var(--cpr-gray);
}

/* La fraîcheur des données, d'emblée sous le titre. */
.aed__freshness {
    align-self: flex-start;
    margin: 0;
    padding: 5px 10px;
    background: var(--cpr-ink);
    color: var(--cpr-white);
    font-size: 13px;
    font-weight: 800;
}

/* — La barre de recherche, en tête de la carte : toute la largeur moins le
   panneau, pour qu'une adresse longue tienne. — */
.aed__searchbar {
    position: absolute;
    top: 16px;
    left: calc(var(--aed-panel-w) + 32px);
    right: 16px;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
}

.aed__search {
    display: flex;
    gap: 8px;
    padding: 8px;
    border-top: 4px solid var(--cpr-action);
    background: var(--cpr-paper);
    box-shadow: var(--cpr-shadow-lift);
    pointer-events: auto;
}

.aed__search .cpr-btn { flex-shrink: 0; }

.aed__legend-title {
    margin: 0;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.aed__input {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 50px;
    padding: 0 12px;
    border: 2px solid var(--cpr-ink);
    border-radius: 2px;
    background: var(--cpr-white);
    color: var(--cpr-ink);
    font: inherit;
    font-size: 16px;
}

.aed__status {
    align-self: flex-start;
    margin: 0;
    padding: 6px 10px;
    background: var(--cpr-ink);
    color: var(--cpr-white);
    font-size: 14px;
    font-weight: 700;
    pointer-events: auto;
}

.aed__status:empty { display: none; }

/* — Les plus proches, après une recherche : le chemin accessible — */
.aed__nearest {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.aed__near {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    border-left: 4px solid var(--cpr-action);
    background: var(--cpr-white);
}

.aed__near-button {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--cpr-ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.aed__near-button:hover .aed__near-name { text-decoration: underline; }

.aed__near-distance {
    flex-shrink: 0;
    font-family: var(--cpr-display);
    font-stretch: 72%;
    font-weight: 800;
    font-size: 20px;
    color: var(--cpr-action);
}

.aed__near-name { font-weight: 800; font-size: 15px; }
.aed__near-address { font-size: 13px; color: var(--cpr-gray); }

/* — Légende — */
.aed__legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    margin: 0;
    padding: 14px 16px;
    border: 0;
    background: var(--cpr-white);
}

.aed__legend-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 14px;
}

/* Une ligne de légende est une case à cocher : toute la ligne se clique. */
.aed__filter {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    cursor: pointer;
}

.aed__filter-box {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    margin: 0;
    accent-color: var(--cpr-ink);
    cursor: pointer;
}

.aed__filter-pin {
    flex-shrink: 0;
    width: 20px;
    height: 25px;
}

.aed__filter:has(.aed__filter-box:not(:checked)) .aed__filter-pin,
.aed__filter:has(.aed__filter-box:not(:checked)) .aed__filter-text { opacity: .4; }

.aed__legend-count {
    margin-left: auto;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.aed__legend-total,
.aed__hint {
    margin: 0;
    font-size: 13px;
    color: var(--cpr-gray);
}

.aed__training {
    font-size: 15px;
    font-weight: 800;
    color: var(--cpr-action);
}

/* — Crédits, toujours visibles en pied de panneau — */
.aed__credits {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: auto;
    padding-top: 12px;
    border-top: 2px solid var(--cpr-ink);
    font-size: 12px;
    line-height: 1.45;
    color: var(--cpr-gray);
}

.aed__credits p { margin: 0; }
.aed__credits a { font-weight: 700; color: var(--cpr-ink); }

.aed__disclaimer {
    font-size: 13px;
    font-weight: 700;
    color: var(--cpr-ink);
}

/* — Marqueurs : l'épingle du défibrillateur, trois habillages — */
.aed-pin {
    filter: drop-shadow(0 1px 2px var(--aed-shadow));
    cursor: pointer;
}

.aed-pin__svg {
    display: block;
    width: 100%;
    height: 100%;
}

.aed-pin__body { stroke-width: 2; }

.aed-pin--always .aed-pin__body { fill: var(--aed-always); stroke: var(--cpr-white); }
.aed-pin--always .aed-pin__heart { fill: var(--cpr-white); }
.aed-pin--always .aed-pin__bolt { fill: var(--aed-always); }

.aed-pin--hours .aed-pin__body { fill: var(--cpr-white); stroke: var(--aed-always); stroke-width: 3; }
.aed-pin--hours .aed-pin__heart { fill: var(--aed-always); }
.aed-pin--hours .aed-pin__bolt { fill: var(--cpr-white); }

.aed-pin--unknown .aed-pin__body { fill: var(--aed-unknown); stroke: var(--cpr-white); }
.aed-pin--unknown .aed-pin__heart { fill: var(--cpr-white); }
.aed-pin--unknown .aed-pin__bolt { fill: var(--aed-unknown); }

/* Le pinceau de la légende reprend le même dessin, sans ombre. */
.aed__filter-pin.aed-pin { filter: none; cursor: inherit; }

.aed-here { fill: var(--aed-here); fill-opacity: .25; stroke: var(--aed-here); }

/* Deux classes : la feuille de Leaflet, chargée APRÈS celle-ci, pose
   `display: block` sur `.leaflet-marker-icon`, et à spécificité égale elle
   l'emportait — le chiffre se collait en haut à gauche, rogné par la bordure. */
.aed .aed-cluster {
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid var(--cpr-white);
    border-radius: 50%;
    background: var(--cpr-ink);
    color: var(--cpr-white);
    font-family: var(--cpr-sans);
    font-size: 13px;
    font-weight: 800;
    box-shadow: var(--cpr-shadow-lift);
    cursor: pointer;
}

/* — La fiche dans sa bulle — */
.aed-popup .leaflet-popup-content-wrapper { border-radius: 2px; }
.aed-popup .leaflet-popup-content { margin: 14px 16px; font-family: var(--cpr-sans); }

.aed-pop {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--cpr-ink);
}

.aed-pop p { margin: 0; }

.aed-pop__availability {
    align-self: flex-start;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.aed-pop__availability--always { background: var(--aed-always); color: var(--cpr-white); }
.aed-pop__availability--hours { border: 2px solid var(--aed-always); color: var(--aed-always); }
.aed-pop__availability--unknown { background: var(--cpr-line-2); color: var(--cpr-gray); }

.aed-pop__name { font-weight: 800; font-size: 15px; }
.aed-pop__address { font-size: 14px; }
.aed-pop__where { font-size: 14px; font-style: italic; }
.aed-pop__tags,
.aed-pop__pending { font-size: 12px; color: var(--cpr-gray); }
.aed-pop__hours-title { font-size: 12px; font-weight: 800; }

.aed-pop__hours ul {
    margin: 2px 0 0;
    padding-left: 16px;
    font-size: 13px;
}

.aed-pop__links {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    font-weight: 700;
}

.aed-pop__loading { font-size: 14px; }

/* Le Plan IGN porte ses propres libellés : l'attribution reste lisible. */
.aed .leaflet-control-attribution { font-size: 11px; }

/* — Téléphone : la carte en haut, le panneau en feuille dessous — */
@media (width < 48em) {
    .aed__main {
        display: flex;
        flex-direction: column;
        height: auto;
    }

    .aed__searchbar {
        position: static;
        padding: 12px 12px 0;
        background: var(--cpr-paper);
    }

    .aed__search {
        flex-wrap: wrap;
        padding: 0;
        border-top: 0;
        box-shadow: none;
    }

    .aed__input { flex-basis: 100%; }

    .aed__search .cpr-btn { flex: 1 1 auto; }

    .aed__status { margin-bottom: 8px; }

    .aed__stage {
        position: relative;
        height: 62vh;
        height: 62dvh;
    }

    .aed__logo {
        left: 12px;
        bottom: 12px;
        padding: 6px 8px;
    }

    .aed__logo img { height: 7rem; }

    .aed__panel {
        position: static;
        width: auto;
        overflow: visible;
        box-shadow: none;
    }
}
