* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Now Alt', serif;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    background: #232253;
    color: white;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    font-size: 1.5rem;
}

/* Navigation Control */
.navigation-control {
    display: flex;
    align-items: center;
}

#regionSelector:hover {
    background: #ffffff;
}

#regionSelector option {
    background: white;
    color: #232253;
    font-family: 'Now Alt', serif;
    font-size: 13px;
}

/* Contrôles de navigation */
.navigation-control-container {
    background: #F1EDE6;
    padding: 5px;
    border-radius: 5px;
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
    max-width: 200px;
    margin-top: 10px;
}

.navigation-control-container h4 {
    margin: 0 0 2px 0;
    font-family: 'Now Alt', serif;
    font-size: 14px;
    border-bottom: 1px solid #ddd;
    padding-bottom: 5px;
}

#regionSelector {
    background: #F1EDE6;
    color: #232253;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Now Alt', serif;
    font-size: 14px;
    font-weight: 500;
    width: 100%;
}

#regionSelector:hover {
    background: #b8d8f0;
}

#regionSelector option {
    background: white;
    color: #232253;
    font-family: 'Now Alt', serif;
    font-size: 13px;
}

/* Carte */
#map {
    flex: 1;
    width: 100%;
}

/* Contrôles des couches */
.layer-controls-container {
    background: #F1EDE6;
    padding: 10px;
    border-radius: 5px;
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
    max-width: 200px;
}

.layer-controls-container h4 {
    margin: 0 0 8px 0;
    font-family: 'Now Alt', serif;
    font-size: 14px;
    border-bottom: 1px solid #ddd;
    padding-bottom: 5px;
}

.layer-controls-container label {
    display: block;
    margin-bottom: 5px;
    cursor: pointer;
    font-family: sans-serif;
    font-size: 12px;
    padding: 2px 0;
}

.layer-controls-container input {
    margin-right: 5px;
}

/* Légende */
.legend {
    background: #ffffff;
    padding: 10px;
    border-radius: 5px;
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
    font-family: 'Now Alt', serif;
    font-size: 12px;
    color: #232253;
    line-height: 1.3;
    max-height: 600px;
    overflow-y: auto;
    max-width: 250px;
}

.legend h4 {
    margin: 0 0 8px 0;
    font-size: 14px;
    font-weight: bold;
    border-bottom: 1px solid #ddd;
    padding-bottom: 5px;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 3px;
}

.color-box {
    width: 12px;
    height: 12px;
    margin-right: 6px;
    border: 1px solid #666;
    border-radius: 2px;
    flex-shrink: 0;
}

/* Style pour les popups Leaflet */
.leaflet-popup-content {
    margin: 8px;
    font-size: 11px;
    font-family: 'Now Alt', serif;
    line-height: 1;
}

.popup-content {
    min-width: 180px;
    max-width: 200px;
}

.popup-content p {
    margin: 3px 0;
    padding: 2px 0;
    font-size: 10px;
}

.popup-content strong {
    min-width: 80px;
    font-size: 10px;
    font-family: sans-serif;
}

.popup-content .value {
    font-size: 10px;
    color: #232253;
    font-family: sans-serif;
}

/* Style du conteneur popup Leaflet */
.leaflet-popup {
    bottom: 20px !important;
}

.leaflet-popup-tip {
    background: #ffffff;
}

.leaflet-popup-content-wrapper {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

/* Indicateur de chargement */
#loading-indicator {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    font-family: sans-serif;
}

.loading-content {
    text-align: center;
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    border: 2px solid #CDE5F6;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #CDE5F6;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px auto;
}

.loading-text {
    color: #232253;
    font-size: 16px;
    font-weight: bold;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Contrôle de recherche BAN */
.ban-search-control {
    background: #ffffff;
    padding: 12px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    margin-right: 10px;
    margin-top: 10px;
    max-width: 350px;
    border: 1px solid #e0e0e0;
    position: relative;
}

.search-header h4 {
    margin: 0 0 10px 0;
    color: #232253;
    font-family: 'Now Alt', serif;
    font-size: 14px;
    font-weight: 600;
    border-bottom: 2px solid #232253;
    padding-bottom: 5px;
}

.search-input-group {
    display: flex;
    gap: 5px;
    margin-bottom: 8px;
}

#banSearchInput {
    flex: 1;
    padding: 10px 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-family: 'Now Alt', serif;
    font-size: 14px;
    color: #232253;
    transition: all 0.3s;
}

#banSearchInput:focus {
    outline: none;
    border-color: #232253;
    box-shadow: 0 0 0 3px rgba(35, 34, 83, 0.1);
}

#banSearchButton {
    padding: 10px 15px;
    background: #232253;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.3s;
    min-width: 44px;
}

#banSearchButton:hover {
    background: #3a3a7a;
}

/* Résultats de recherche */
.search-results {
    position: absolute;
    width: 100%;
    max-width: 350px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    margin-top: 5px;
    max-height: 400px;
    overflow-y: auto;
    display: none;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.search-result-item {
    padding: 12px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    font-family: 'Now Alt', serif;
    transition: background 0.2s;
    position: relative;
}

.search-result-item:hover {
    background: #f8f9fa;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item.exact-match {
    background: #f0f7ff;
    border-left: 3px solid #232253;
}

.result-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.result-main strong {
    color: #232253;
    font-size: 14px;
    font-weight: 600;
}

.postcode {
    background: #e9ecef;
    color: #495057;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.result-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: #666;
}

.result-details small {
    flex: 1;
}

.insee-code {
    background: #232253;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    margin-left: 8px;
}

.badge-municipality {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #28a745;
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 3px;
}

/* État de chargement et erreur */
.search-loading,
.no-results,
.error-results {
    padding: 20px;
    text-align: center;
    color: #666;
}

.search-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.search-loading::before {
    content: "";
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-top-color: #232253;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.no-results strong {
    color: #dc3545;
    display: block;
    margin-bottom: 5px;
}

.error-results button {
    margin-top: 10px;
    padding: 6px 12px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.error-results button:hover {
    background: #c82333;
}

.search-info {
    text-align: center;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #eee;
    color: #888;
    font-size: 11px;
}

/* Marqueur de recherche */
.search-marker {
    background: transparent;
    border: none;
}

.marker-pin {
    width: 30px;
    height: 30px;
    border-radius: 50% 50% 50% 0;
    background: #232253;
    position: absolute;
    transform: rotate(-45deg);
    left: 50%;
    top: 50%;
    margin: -20px 0 0 -15px;
}

.marker-pin::after {
    content: '';
    width: 24px;
    height: 24px;
    margin: 3px 0 0 3px;
    background: white;
    position: absolute;
    border-radius: 50%;
}

.marker-pulse {
    background: rgba(35, 34, 83, 0.2);
    border-radius: 50%;
    height: 14px;
    width: 14px;
    position: absolute;
    left: 50%;
    top: 50%;
    margin: -7px 0 0 -7px;
    transform: rotateX(55deg);
    z-index: -2;
    animation: pulse 1.5s ease-out infinite;
}

@keyframes pulse {
    0% {
        height: 14px;
        width: 14px;
        opacity: 1;
    }
    100% {
        height: 50px;
        width: 50px;
        opacity: 0;
    }
}

/* Popup de recherche */
.search-popup {
    min-width: 200px;
}

.search-popup h4 {
    margin: 0 0 10px 0;
    color: #232253;
    border-bottom: 2px solid #232253;
    padding-bottom: 5px;
}

.search-popup .popup-details p {
    margin: 5px 0;
    font-size: 12px;
}

.search-popup .popup-details em {
    color: #666;
    font-size: 11px;
    display: block;
    margin-top: 10px;
    font-style: italic;
}

/* Responsive */
@media (max-width: 768px) {
    .ban-search-control {
        max-width: calc(100% - 20px);
        margin: 10px;
    }
    
    .search-results {
        max-width: calc(100% - 20px);
    }
}

/* AJOUTS POUR LES CONTOURS DES COMMUNES */
.leaflet-interactive {
    transition: all 0.1s ease-out;
}

.leaflet-interactive:hover {
    stroke-width: 2px !important;
    stroke-opacity: 0.8 !important;
    stroke-linejoin: round !important;
    stroke-linecap: round !important;
}

/* Contours plus nets aux grands zooms */
.leaflet-zoom-animated path {
    shape-rendering: geometricPrecision;
}

/* Amélioration de la transition lors du zoom */
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-image-layer,
.leaflet-pane > svg path,
.leaflet-pane > svg rect {
    transition: opacity 0.2s ease;
}

/* Style spécifique pour les contours aux différents niveaux de zoom */
.leaflet-zoom-10 .leaflet-interactive,
.leaflet-zoom-11 .leaflet-interactive {
    stroke: rgba(255, 255, 255, 0.3);
    stroke-width: 0.5px;
}

.leaflet-zoom-12 .leaflet-interactive,
.leaflet-zoom-13 .leaflet-interactive {
    stroke: rgba(255, 255, 255, 0.5);
    stroke-width: 1px;
}

.leaflet-zoom-14 .leaflet-interactive,
.leaflet-zoom-15 .leaflet-interactive,
.leaflet-zoom-16 .leaflet-interactive {
    stroke: rgba(51, 51, 51, 0.7);
    stroke-width: 1.5px;
}

.leaflet-zoom-17 .leaflet-interactive,
.leaflet-zoom-18 .leaflet-interactive,
.leaflet-zoom-19 .leaflet-interactive {
    stroke: rgba(35, 34, 83, 0.8);
    stroke-width: 2px;
}

/* Pour la couche de prévisions avec contours plus clairs */
.layer-previsions .leaflet-interactive {
    stroke: rgba(255, 255, 255, 0.6) !important;
}

/* ===== STYLES POUR LES ÉLÉMENTS REPLIABLES ===== */

/* Styles communs pour tous les conteneurs repliables */
.legend,
.layer-controls-container,
.ban-search-control {
    transition: all 0.3s ease;
    position: relative;
}

/* Style du bouton toggle pour tous les panneaux */
.legend .legend-toggle,
.layer-controls-container .toggle-btn,
.ban-search-control .toggle-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    cursor: pointer;
    font-size: 14px;
    color: #232253;
    background: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    transition: transform 0.3s ease, background 0.3s ease;
    z-index: 10;
    border: 1px solid #e0e0e0;
    line-height: 1;
}

.legend .legend-toggle:hover,
.layer-controls-container .toggle-btn:hover,
.ban-search-control .toggle-btn:hover {
    background: #f0f0f0;
    transform: scale(1.1);
}

/* Animation du triangle quand replié */
.legend.collapsed .legend-toggle,
.layer-controls-container.collapsed .toggle-btn,
.ban-search-control.collapsed .toggle-btn {
    transform: rotate(180deg);
}

/* ===== STYLES POUR LA LÉGENDE REPLIABLE ===== */
.legend {
    overflow: hidden;
}

.legend.collapsed {
    max-height: 40px !important;
    min-width: 40px !important;
    padding: 5px !important;
    cursor: pointer;
}

.legend.collapsed h4 {
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 25px;
}

.legend.collapsed .legend-item {
    display: none;
}

/* ===== STYLES POUR LE PANNEAU VUES REPLIABLE ===== */
.layer-controls-container {
    overflow: hidden;
}

.layer-controls-container.collapsed {
    max-height: 40px !important;
    min-width: 40px !important;
    padding: 5px !important;
    cursor: pointer;
}

.layer-controls-container.collapsed h4 {
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 25px;
}

.layer-controls-container.collapsed label,
.layer-controls-container.collapsed .navigation-control-container {
    display: none;
}

/* ===== STYLES POUR LA RECHERCHE REPLIABLE ===== */
.ban-search-control {
    overflow: visible !important; /* Permet aux résultats de sortir */
}

.ban-search-control .search-header {
    padding-right: 25px;
}

/* État replié */
.ban-search-control.collapsed {
    max-height: 40px !important;
    min-width: 40px !important;
    padding: 5px !important;
    cursor: pointer;
    overflow: visible !important; /* CRITIQUE : permet aux résultats fixed d'être visibles */
    background: #ffffff;
}

.ban-search-control.collapsed .search-header h4 {
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 25px;
}

.ban-search-control.collapsed .search-input-group,
.ban-search-control.collapsed .search-info {
    display: none;
}

/* Résultats en mode replié - position fixed */
.ban-search-control.collapsed .search-results {
    display: block !important;
    position: fixed !important;
    top: 60px !important;
    right: 10px !important;
    width: 350px !important;
    max-width: 350px !important;
    z-index: 9999 !important;
    background: white !important;
    border: 1px solid #e0e0e0 !important;
    border-radius: 6px !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
    max-height: 400px !important;
    overflow-y: auto !important;
}

/* Résultats en mode ouvert */
.ban-search-control:not(.collapsed) .search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 350px;
    z-index: 1000;
}

/* Ajustement pour le conteneur Leaflet */
.leaflet-control-container .leaflet-top.leaflet-right {
    z-index: 1000;
}

.leaflet-control-container .leaflet-bottom.leaflet-right {
    z-index: 1000;
}

/* Responsive pour les résultats fixed */
@media (max-width: 768px) {
    .ban-search-control.collapsed .search-results {
        width: calc(100% - 20px) !important;
        right: 10px !important;
        left: 10px !important;
        top: 50px !important;
    }
}

/* Animation douce pour les transitions */
.legend,
.layer-controls-container,
.ban-search-control {
    transition: max-height 0.3s ease, padding 0.3s ease, min-width 0.3s ease;
}

/* Empêcher l'interaction avec les éléments cachés */
.ban-search-control.collapsed .search-input-group,
.ban-search-control.collapsed .search-info,
.layer-controls-container.collapsed label,
.layer-controls-container.collapsed .navigation-control-container {
    display: none !important;
}
/* Bouton d'information */
.info-button {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 40px;
    height: 40px;
    background: #232253;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 20px;
    font-weight: bold;
    font-family: 'Now Alt', serif;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
    z-index: 1000;
    border: 2px solid white;
}

.info-button:hover {
    background: #3a3a7a;
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

/* Modale d'information */
.info-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    justify-content: center;
    align-items: center;
}

.info-modal.active {
    display: flex;
}

.info-modal-content {
    background: white;
    border-radius: 12px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    position: relative;
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.info-modal-header {
    background: #232253;
    color: white;
    padding: 15px 20px;
    border-radius: 12px 12px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.info-modal-header h3 {
    margin: 0;
    font-family: 'Now Alt', serif;
    font-size: 18px;
    font-weight: 600;
}

.info-modal-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s;
}

.info-modal-close:hover {
    background: rgba(255,255,255,0.2);
}

.info-modal-body {
    padding: 20px;
    font-family: 'Now Alt', serif;
    font-size: 14px;
    line-height: 1.5;
    color: #333;
}

.info-modal-body h4 {
    color: #232253;
    margin: 15px 0 10px 0;
    font-size: 16px;
    font-weight: 600;
    border-left: 3px solid #232253;
    padding-left: 10px;
}

.info-modal-body h4:first-of-type {
    margin-top: 0;
}

.info-modal-body p {
    margin-bottom: 12px;
    text-align: justify;
}

.info-modal-body ul {
    margin: 10px 0;
    padding-left: 20px;
}

.info-modal-body li {
    margin-bottom: 8px;
}

.info-modal-footer {
    padding: 15px 20px;
    border-top: 1px solid #eee;
    text-align: right;
    background: #f9f9f9;
    border-radius: 0 0 12px 12px;
}

.info-modal-footer button {
    background: #232253;
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Now Alt', serif;
    font-size: 14px;
    transition: background 0.3s;
}

.info-modal-footer button:hover {
    background: #3a3a7a;
}

/* Responsive */
@media (max-width: 768px) {
    .info-modal-content {
        width: 95%;
        max-height: 85vh;
    }
    
    .info-modal-body {
        font-size: 13px;
        padding: 15px;
    }
}