body, html {
    margin: 0; padding: 0; width: 100%; height: 100%;
    overflow: hidden; font-family: 'Segoe UI', Roboto, sans-serif;
}
#map { width: 100%; height: 100%; }

/* --- En-tête principal --- */
.map-header {
    position: absolute; top: 16px; left: 16px;
    background: rgba(15, 23, 42, 0.95); color: #fff;
    padding: 10px 16px; border-radius: 10px; z-index: 10;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3); border: 1px solid #334155;
    display: flex; align-items: center; gap: 12px;
}
.map-header h1 { margin: 0; font-size: 14px; color: #38bdf8; font-weight: 700; }
.map-header p { margin: 2px 0 0 0; font-size: 11px; color: #94a3b8; }

.btn-menu-drawer {
    background: #0284c7; color: #fff; border: none;
    padding: 8px 12px; border-radius: 6px; font-size: 13px; font-weight: 700;
    cursor: pointer; transition: background 0.2s;
}
.btn-menu-drawer:hover { background: #0369a1; }

/* --- Barre d'outils (Bas-gauche) --- */
.map-tools-bar {
    position: absolute; bottom: 10px; left: 54px; z-index: 10;
    display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
}
.btn-tool {
    background: rgba(15, 23, 42, 0.92); color: #f8fafc; border: 1px solid #334155;
    padding: 7px 11px; border-radius: 8px; font-size: 11px; font-weight: 700;
    cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,0.3); transition: all 0.2s;
}
.btn-tool:hover { background: #0284c7; color: #fff; border-color: #38bdf8; }
.maplibregl-ctrl-bottom-left { bottom: 10px !important; left: 10px !important; }

/* --- Tiroir Rétractable (Menu Gauche) --- */
.drawer-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(2px); z-index: 1000;
}
.drawer-overlay.open { display: block; }

.left-drawer {
    position: fixed; top: 0; left: 0; width: 320px; max-width: 85vw; height: 100vh;
    background: rgba(15, 23, 42, 0.97); color: #f8fafc; backdrop-filter: blur(12px);
    box-shadow: 4px 0 25px rgba(0,0,0,0.5); z-index: 1001;
    transform: translateX(-100%); transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto; padding: 20px; box-sizing: border-box; display: flex; flex-direction: column;
    border-right: 1px solid #334155;
}
.left-drawer.open { transform: translateX(0); }
.drawer-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #334155; padding-bottom: 12px; margin-bottom: 12px; }
.drawer-header h3 { margin: 0; font-size: 15px; color: #38bdf8; }
.close-drawer-btn { background: none; border: none; color: #94a3b8; font-size: 22px; cursor: pointer; }

.drawer-section-title { font-size: 11px; font-weight: 700; text-transform: uppercase; color: #38bdf8; margin: 14px 0 6px 0; border-bottom: 1px solid #1e293b; padding-bottom: 4px; }
.drawer-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.drawer-btn-item {
    background: rgba(30, 41, 59, 0.7); color: #e2e8f0; border: 1px solid #334155;
    padding: 8px 12px; border-radius: 6px; font-size: 12px; text-align: left;
    cursor: pointer; transition: all 0.2s; display: flex; justify-content: space-between; align-items: center;
}
.drawer-btn-item:hover { background: #0284c7; color: #ffffff; border-color: #38bdf8; }

.layer-group { background: rgba(30, 41, 59, 0.5); border: 1px solid #334155; padding: 10px; border-radius: 8px; }
.layer-item { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; cursor: pointer; font-size: 12px; font-weight: 500; color: #cbd5e1; }
.layer-item:last-child { margin-bottom: 0; }
.layer-item input { accent-color: #0284c7; width: 15px; height: 15px; }
.drawer-credits-footer { margin-top: 20px; padding-top: 12px; border-top: 1px solid #334155; text-align: center; }
.btn-credits-link { background: none; border: none; color: #94a3b8; font-size: 11px; cursor: pointer; text-decoration: underline; }

/* --- Panneau d'Information (Panneau Droit) --- */
.side-panel {
    position: fixed; top: 0; right: 0; width: 450px; max-width: 90vw; height: 100vh;
    background: #ffffff; box-shadow: -4px 0 25px rgba(0,0,0,0.3); z-index: 1000;
    transform: translateX(100%); transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0; box-sizing: border-box; display: flex; flex-direction: column; overflow: hidden;
}
.side-panel.open { transform: translateX(0); }

.panel-header-sticky {
    position: sticky; top: 0; background: #ffffff; z-index: 10;
    padding: 20px 24px 14px 24px; border-bottom: 2px solid #e2e8f0;
    display: flex; justify-content: space-between; align-items: center;
}
.panel-header-sticky h2 { margin: 0; font-size: 18px; color: #0f172a; }

.panel-body-scroll {
    flex: 1; overflow-y: auto; padding: 20px 24px 24px 24px;
    display: flex; flex-direction: column;
}

.close-btn {
    background: #f1f5f9; border: none; width: 32px; height: 32px;
    border-radius: 50%; font-size: 20px; cursor: pointer; color: #475569;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.close-btn:hover { background: #e2e8f0; color: #0f172a; }

/* --- Cards UI --- */
.card-tech { background: #f8fafc; border: 1px solid #e2e8f0; padding: 14px; border-radius: 8px; margin-bottom: 12px; }
.card-eau { background: #f0f9ff; border: 1px solid #bae6fd; padding: 14px; border-radius: 8px; margin-bottom: 12px; }
.card-chauffage { background: #fff7ed; border: 1px solid #ffedd5; padding: 14px; border-radius: 8px; margin-bottom: 12px; }
.card-vmc { background: #f0fdf4; border: 1.5px solid #86efac; padding: 14px; border-radius: 8px; margin-bottom: 12px; }
.card-loge { background: #fefce8; border: 1px solid #fef08a; padding: 14px; border-radius: 8px; margin-bottom: 12px; }
.card-urgance-coupure { background: #fef2f2; border: 1.5px solid #ef4444; padding: 14px; border-radius: 8px; margin-bottom: 12px; }
.card-collecte { background: #fffbe3; border: 1.5px solid #fde047; padding: 14px; border-radius: 8px; margin-bottom: 12px; }

.card-tech h4, .card-eau h4, .card-chauffage h4, .card-vmc h4, .card-loge h4, .card-urgance-coupure h4, .card-collecte h4 {
    margin: 0 0 8px 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px;
}
.card-tech h4 { color: #334155; }
.card-eau h4 { color: #0369a1; }
.card-chauffage h4 { color: #c2410c; }
.card-vmc h4 { color: #15803d; }
.card-loge h4 { color: #a16207; }
.card-urgance-coupure h4 { color: #dc2626; }
.card-collecte h4 { color: #854d0e; }

.tech-list { list-style: none; padding: 0; margin: 0; font-size: 13px; color: #334155; line-height: 1.6; }
.tech-list li { display: flex; justify-content: space-between; border-bottom: 1px dashed #cbd5e1; padding: 4px 0; }
.tech-list li:last-child { border-bottom: none; }

.btn-gps {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; padding: 12px; background: #0284c7; color: #ffffff;
    border: none; border-radius: 8px; font-size: 13px; font-weight: 600;
    cursor: pointer; text-decoration: none; margin-top: 16px; transition: background 0.2s;
}
.btn-gps:hover { background: #0369a1; }

.btn-fermer-panel {
    display: block; width: 100%; padding: 14px; margin-top: auto;
    background: #e2e8f0; color: #334155; border: 1px solid #cbd5e1;
    border-radius: 8px; font-size: 14px; font-weight: 700; cursor: pointer; text-align: center;
}
.btn-fermer-panel:hover { background: #cbd5e1; }

.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.7); backdrop-filter: blur(4px); z-index: 2000;
    align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: #ffffff; width: 90%; max-width: 500px; padding: 24px;
    border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); position: relative;
}

@media (max-width: 768px) {
    .side-panel {
        top: auto; 
        bottom: 10px; 
        left: 8px; 
        right: 8px; 
        width: auto; 
        max-width: none; 
        height: auto; 
        max-height: 90vh; /* Permet d'occuper presque tout l'écran */
        overflow-y: auto !important; /* Active le défilement sur le conteneur principal */
        -webkit-overflow-scrolling: touch;
        border-radius: 16px; 
        transform: translateY(150%);
    }
    .side-panel.open { transform: translateY(0); }
}

/* --- Boutons Urgence & Sous-Menu --- */
#btn-mode-urgence {
    transition: transform 0.2s, background-color 0.2s;
}
#btn-mode-urgence:active {
    transform: scale(0.97);
    background-color: #b91c1c;
}

.sub-list-container {
    display: flex; flex-direction: column; gap: 3px;
    padding-left: 12px; margin-bottom: 6px;
}

.btn-subitem {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #cbd5e1; padding: 5px 8px; border-radius: 4px;
    text-align: left; font-size: 12px; cursor: pointer;
    width: 100%; transition: all 0.15s ease;
}
.btn-subitem:hover {
    background: rgba(56, 189, 248, 0.25);
    border-color: #38bdf8; color: #ffffff;
}

/* --- VISIBILITÉ MARQUEURS MAPLIBRE (Pas de display:flex !important) --- */
.marker-nocodb, .marker-statique {
    display: flex;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.marker-hidden {
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.marker-visible {
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* --- CLIGNOTEMENT VERT FLUO / JAUNE (Point sélectionné) --- */
@keyframes pulseFluoYellow {
    0% {
        background-color: #ccff00 !important;
        border-color: #ffffff !important;
        box-shadow: 0 0 14px 6px #ccff00, 0 0 28px #ccff00 !important;
    }
    50% {
        background-color: #facc15 !important;
        border-color: #ffffff !important;
        box-shadow: 0 0 28px 14px #facc15, 0 0 45px #facc15 !important;
    }
    100% {
        background-color: #ccff00 !important;
        border-color: #ffffff !important;
        box-shadow: 0 0 14px 6px #ccff00, 0 0 28px #ccff00 !important;
    }
}

.marker-active-highlight {
    animation: pulseFluoYellow 0.8s infinite ease-in-out !important;
    z-index: 99999 !important;
}

/* --- ANIMATION URGENCE ROUGE / JAUNE --- */
@keyframes pulse-urgence {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.9) !important;
        border-color: #ef4444 !important;
    }
    50% {
        box-shadow: 0 0 20px 10px rgba(239, 68, 68, 0.7) !important;
        border-color: #facc15 !important;
    }
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.9) !important;
        border-color: #ef4444 !important;
    }
}

.urgence-active {
    animation: pulse-urgence 1s infinite !important;
    border-color: #ef4444 !important;
    z-index: 99999 !important;
}

/* --- MARQUEURS CLIQUABLES & SUPERPOSITION --- */
.marker-nocodb, .marker-statique {
    display: flex;
    pointer-events: auto !important;
    z-index: 1000 !important;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.marker-hidden {
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.marker-visible {
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}
/* --- ACCESSIBILITÉ DU BOUTON RECENTRER & CLICS MARQUEURS --- */
.maplibregl-marker {
    pointer-events: auto !important;
    z-index: 1000 !important;
}
/* --- PRIORITÉ D'AFFICHAGE (Z-INDEX) --- */
.side-panel {
    z-index: 20000 !important; /* Passe devant tous les marqueurs 3D */
}

.left-drawer, .drawer-overlay {
    z-index: 25000 !important;
}

.modal-overlay {
    z-index: 30000 !important;
}
/* --- SÉCURITÉ PREMIER PLAN INTERFACE (SMARTPHONE & PC) --- */
.app-header, 
#menu-container,
.left-drawer, 
.drawer-overlay, 
.menu-toggle-btn {
    z-index: 99999 !important;
}

/* Le bouton hamburger/menu doit toujours rester accessible */
header button, .app-header button {
    pointer-events: auto !important;
}
/* --- SÉCURITÉ TIROIRS & PANNEAUX (SANS CASSER LES TRANSITIONS) --- */
.left-drawer, 
.side-panel, 
.drawer-overlay,
.app-header {
    z-index: 25000 !important;
    isolation: isolate; /* Crée un contexte d'empilement propre sans toucher aux coordonnées transform */
}

/* Forcer le tiroir gauche à se cacher à gauche quand il n'est pas actif */
.left-drawer:not(.open):not(.active) {
    transform: translateX(-100%) !important;
}

/* Forcer le panneau droit à se cacher à droite quand aucune fiche n'est ouverte */
.side-panel:not(.open):not(.active) {
    transform: translateX(100%) !important;
}

/* Compatibilité tactile Safari iOS */
.marker-nocodb, 
.marker-statique {
    cursor: pointer !important;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}



.side-panel:not(.open):not(.active) {
    transform: translateX(110%) !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

@media (max-width: 768px) {
    .side-panel:not(.open):not(.active) {
        transform: translateY(150%) !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }
}
