/* ============================================================================
 * CARTE RANDONNÉE — Styles externalisés
 * Fichier : css/hr-carte-rando.css
 * Thème enfant : Free-DIVI-Child-Theme-by-Pee-Aye-Creative
 * 
 * Remplace le bloc <style> inline de Carte_randonnee.php
 * Les propriétés dynamiques (hauteur carte, largeur max) restent en inline
 * via style="" sur les éléments HTML.
 * 
 * Convention de classes :
 *   .hr-carte-rando          → wrapper principal
 *   .hr-carte-rando .hr-map  → conteneur de la carte Leaflet
 *   .hr-carte-rando .hr-elev → conteneur du profil d'altitude
 *   .hr-tooltip-rando        → tooltip du profil (enfant direct de body)
 * ============================================================================ */

/* === WRAPPER PRINCIPAL === */
.hr-carte-rando {
    position: relative;
    width: 100%;
    /* max-width: dynamique via style="" */
    border: 2px solid #ddd;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    box-sizing: border-box;
    margin: 20px auto;
}

/* === TITRE INTÉGRÉ === */
.hr-carte-rando .map-title-integrated {
    background: #05668d;
    color: #fff;
    padding: 6px 12px;
    font-size: 0.95em;
    font-weight: 600;
    text-align: left;
    position: relative;
    z-index: 1;
}

/* === CONTENEUR CARTE === */
.hr-carte-rando .hr-map {
    /* height: dynamique via style="" */
    width: 100%;
    position: relative;
}

/* === INSTRUCTION TACTILE (mobile 2 doigts) === */
.hr-carte-rando .hr-map .map-touch-instruction {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    z-index: 10000;
    pointer-events: none;
    text-align: center;
    padding: 30px;
}

.hr-carte-rando .hr-map .map-touch-instruction.show {
    display: flex;
}

/* === CONTRÔLES LEAFLET === */
.hr-carte-rando .hr-map .leaflet-control-zoom a {
    text-decoration: none !important;
}

.hr-carte-rando .hr-map .leaflet-control-attribution {
    display: none !important;
}

/* === MARQUEURS CUSTOM (start/end icons) === */
.hr-carte-rando .hr-map .leaflet-marker-icon.custom-marker-icon {
    background: none !important;
    border: none !important;
}

.hr-carte-rando .hr-map .custom-marker-icon {
    background: transparent !important;
    border: none !important;
}

/* === MARQUEURS DE REPÈRE (numérotés, style épingle) === */
.hr-carte-rando .hr-map .repere-marker {
    background: linear-gradient(135deg, #00a896 0%, #008577 100%);
    color: white;
    border: 3px solid white;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    cursor: pointer;
    line-height: 1;
    position: relative;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
}

.hr-carte-rando .hr-map .repere-marker:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.4);
}

/* Petit triangle en bas — effet épingle */
.hr-carte-rando .hr-map .repere-marker::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 8px solid #ffffff;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.2));
}

/* === POPUPS LEAFLET === */
.hr-carte-rando .hr-map .repere-popup {
    font-size: 13px;
    line-height: 1.5;
}

.hr-carte-rando .hr-map .leaflet-popup-content-wrapper {
    padding: 1px;
}

.hr-carte-rando .hr-map .leaflet-popup-content {
    max-width: 250px;
    margin: 5px 8px 5px 8px;
    padding-right: 10px;
}

.hr-carte-rando .hr-map .leaflet-popup-tip-container {
    width: 20px;
    height: 10px;
    position: absolute;
    left: 50%;
    margin-left: -10px;
    overflow: hidden;
    pointer-events: none;
}

.hr-carte-rando .hr-map .leaflet-popup-tip {
    width: 17px;
    height: 17px;
    padding: 1px;
    margin: -10px auto 0;
    transform: rotate(45deg);
}

/* === ATTRIBUTION CUSTOM === */
.hr-carte-rando .hr-map .custom-attribution-container {
    position: absolute;
    bottom: 10px;
    right: 10px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 8px;
}

.hr-carte-rando .hr-map .custom-attribution-text {
    background: white;
    border: 2px solid rgba(0,0,0,0.2);
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 11px;
    line-height: 1.4;
    box-shadow: 0 1px 5px rgba(0,0,0,0.4);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    white-space: nowrap;
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hr-carte-rando .hr-map .custom-attribution-text.show {
    opacity: 1;
    visibility: visible;
}

.hr-carte-rando .hr-map .custom-attribution-button {
    background: white;
    border: 2px solid rgba(0,0,0,0.2);
    border-radius: 4px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 1px 5px rgba(0,0,0,0.4);
    transition: background-color 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
}

.hr-carte-rando .hr-map .custom-attribution-button:hover {
    background: #f4f4f4;
    transform: scale(1.05);
}

/* === PROFIL D'ALTITUDE === */
.hr-carte-rando .hr-elev {
    height: 200px;
    width: 100%;
    background: white;
    border-top: 1px solid #ddd;
    position: relative;
    touch-action: none;
    cursor: crosshair;
}

.hr-carte-rando .elevation-div {
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
}

.hr-carte-rando .elevation-div svg {
    width: 100%;
    height: 100%;
}

/* === TOOLTIP ALTITUDE (positionné en fixed, hors du wrapper) === */
.hr-tooltip-rando {
    position: fixed;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 12px;
    pointer-events: none;
    z-index: 10000;
    display: none;
    white-space: nowrap;
    box-shadow: 0 3px 12px rgba(0,0,0,0.4);
    line-height: 1.1;
}

.hr-tooltip-rando div {
    color: white;
    margin: 2px 0;
}

/* === BOUTON PLEIN ÉCRAN === */
.hr-carte-rando .hr-map .leaflet-top.leaflet-left {
    display: flex;
    flex-direction: column;
    gap: 0px;
}

.hr-carte-rando .hr-map .leaflet-control-fullscreen a {
    background-image: none !important;
    font-size: 18px;
    line-height: 26px !important;
    text-align: center;
}

.hr-carte-rando .hr-map .leaflet-control-fullscreen a:before {
    content: '⛶';
}

.hr-carte-rando .hr-map .leaflet-fullscreen-on .leaflet-control-fullscreen a:before {
    content: '✕';
}

/* === BOUTON HOME === */
.hr-carte-rando .hr-map .leaflet-control-home {
    background: white;
    border: 2px solid rgba(0,0,0,0.2);
    border-radius: 4px;
    width: 30px;
    height: 30px;
    cursor: pointer;
    box-shadow: 0 1px 5px rgba(0,0,0,0.4);
}

.hr-carte-rando .hr-map .leaflet-control-home a {
    width: 30px;
    height: 30px;
    line-height: 30px;
    display: block;
    text-align: center;
    text-decoration: none;
    color: #333;
    font-size: 18px;
    background-image: none !important;
}

.hr-carte-rando .hr-map .leaflet-control-home a:hover {
    background: #f4f4f4;
}

/* === PLEIN ÉCRAN — Version classe body ===
 * Le JS ajoute .hr-fs-active sur <body> et data-hr-fs sur le wrapper actif.
 * Pas besoin d'ID unique : un seul plein écran à la fois. */

body.hr-fs-active {
    overflow: hidden !important;
}

body.hr-fs-active > *:not(script):not(style):not(link) {
    visibility: hidden !important;
}

body.hr-fs-active .hr-carte-rando[data-hr-fs],
body.hr-fs-active .hr-carte-rando[data-hr-fs] * {
    visibility: visible !important;
}

body.hr-fs-active .hr-carte-rando[data-hr-fs] {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important; /* override : viewport dynamique (mobile) */
    max-width: 100vw !important;
    margin: 0 !important;
    z-index: 2147483647 !important;
    border: none !important;
    display: flex !important;
    flex-direction: column !important;
    background: #fff !important;
}

body.hr-fs-active .hr-carte-rando[data-hr-fs] .map-title-integrated {
    position: relative !important;
    width: 100% !important;
    flex-shrink: 0 !important;
}

body.hr-fs-active .hr-carte-rando[data-hr-fs] .hr-map {
    flex: 1 !important;
    height: auto !important;
    min-height: 0 !important;
    position: relative !important;
}

body.hr-fs-active .hr-carte-rando[data-hr-fs] .hr-elev {
    height: 200px !important;
    flex-shrink: 0 !important;
    width: 100% !important;
    position: relative !important;
}

/* Plein écran mobile : carte seule, sans titre ni profil */
@media screen and (max-width: 768px) {
    body.hr-fs-active .hr-carte-rando[data-hr-fs] .map-title-integrated {
        display: none !important;
    }

    body.hr-fs-active .hr-carte-rando[data-hr-fs] .hr-elev {
        display: none !important;
    }

    body.hr-fs-active .hr-carte-rando[data-hr-fs] .hr-map {
        flex: 1 !important;
        height: 100% !important;
        min-height: 0 !important;
    }
}

/* Backup : anciens styles Leaflet fullscreen pour compatibilité */
.leaflet-fullscreen-on .hr-carte-rando {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-width: 100vw !important;
    margin: 0 !important;
    z-index: 2147483647 !important;
    border: none !important;
    display: flex !important;
    flex-direction: column !important;
}

.leaflet-fullscreen-on .hr-carte-rando .map-title-integrated {
    position: relative !important;
    width: 100% !important;
    flex-shrink: 0 !important;
}

.leaflet-fullscreen-on .hr-carte-rando .hr-map {
    flex: 1 !important;
    height: auto !important;
    min-height: 0 !important;
    position: relative !important;
}

.leaflet-fullscreen-on .hr-carte-rando .hr-map .leaflet-control-container {
    z-index: 2147483647 !important;
}

.leaflet-fullscreen-on .hr-carte-rando .hr-elev {
    height: 200px !important;
    flex-shrink: 0 !important;
    width: 100% !important;
    position: relative !important;
}

/* === H2 SCREEN-READER ONLY === */
.hr-carte-rando .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

/* === RESPONSIVE === */
@media screen and (max-width: 768px) {
    .hr-carte-rando {
        margin: 10px auto;
        max-width: 100% !important;
    }

    .hr-carte-rando .hr-map {
        height: 400px !important;
    }

    .hr-carte-rando .map-title-integrated {
        font-size: 0.9em;
        padding: 5px 10px;
    }

    .hr-carte-rando .hr-elev {
        height: 180px;
    }

    .hr-carte-rando .hr-map .custom-attribution-text {
        max-width: 180px;
        font-size: 10px;
    }
}

@media screen and (max-width: 480px) {
    .hr-carte-rando .hr-map {
        height: 400px !important;
    }

    .hr-carte-rando .map-title-integrated {
        font-size: 0.85em;
    }

    .hr-carte-rando .hr-map .leaflet-control-zoom {
        transform: scale(0.9);
    }

    .hr-carte-rando .hr-elev {
        height: 170px;
    }
}