/* =========================================
   VARIABLES GLOBALES ET RESET
========================================= */
* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* =========================================
   HEADER ET STATISTIQUES GLOBALES
========================================= */
header {
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    padding: 0 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    height: 100px;
    z-index: 3000;
}

.header-left h1 { 
    font-size: 1.8em; 
    margin-bottom: 5px; 
}

.header-left p { 
    opacity: 0.9; 
    font-size: 0.95em; 
}

.stats { 
    display: flex; 
    gap: 15px; 
    flex-wrap: wrap; 
    justify-content: flex-end; 
}

.stat-box {
    text-align: center; 
    background: rgba(255, 255, 255, 0.15);
    padding: 8px 15px; 
    border-radius: 8px;
}

.main-stat { 
    border-bottom: 3px solid #00C896; 
}

.sub-stat { 
    border-bottom: 3px solid rgba(255, 255, 255, 0.4); 
    background: rgba(255, 255, 255, 0.08); 
}

.stat-label { 
    font-size: 0.75em; 
    opacity: 0.9; 
    text-transform: uppercase; 
    letter-spacing: 0.5px;
}

.stat-value { 
    font-size: 1.4em; 
    font-weight: bold; 
    margin-top: 5px; 
    color: #fff;
}

/* =========================================
   CARTE ET CONTRÔLES (BOUTONS/FILTRES)
========================================= */
#map { 
    flex: 1; 
    height: calc(100vh - 100px); 
    z-index: 1; 
}

.controls {
    position: absolute; 
    top: 120px; 
    left: 20px; 
    z-index: 1000;
    display: flex; 
    flex-direction: column; 
    gap: 10px;
}

.btn {
    background: white; 
    border: none; 
    padding: 12px 20px; 
    border-radius: 8px;
    cursor: pointer; 
    font-size: 0.95em; 
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    transition: all 0.3s; 
    font-weight: 600; 
    color: #333; 
    text-align: center;
}

.btn:hover { 
    transform: translateY(-2px); 
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3); 
}

/* Filtres de la carte */
.filter-group {
    display: flex; 
    flex-direction: column; 
    gap: 8px; 
    background: white; 
    padding: 10px; 
    border-radius: 8px; 
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.filter-select {
    border: 1px solid #ddd; 
    padding: 8px; 
    border-radius: 6px;
    font-family: inherit; 
    font-size: 0.85em; 
    outline: none; 
    cursor: pointer;
    background: #f9f9f9; 
    color: #333; 
    font-weight: 500;
}

/* Classes utilitaires */
.hidden { 
    display: none !important; 
}

/* Marqueurs personnalisés (Pins) */
.custom-pin { 
    transition: transform 0.2s; 
}

.custom-pin:hover { 
    transform: scale(1.3); 
    z-index: 1000 !important; 
}

/* =========================================
   PANNEAU DE CLASSEMENT (RANKING)
========================================= */
#ranking-panel {
    position: fixed; 
    top: 100px; 
    right: -400px; 
    width: 400px; 
    height: calc(100vh - 100px);
    background: white; 
    box-shadow: -5px 0 20px rgba(0, 0, 0, 0.3);
    transition: right 0.4s ease; 
    z-index: 2000; 
    overflow-y: auto;
}

#ranking-panel:not(.hidden) { 
    right: 0; 
}

.panel-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white; 
    padding: 20px; 
    position: sticky; 
    top: 0; 
    z-index: 10;
}

.panel-header h2 { 
    font-size: 1.5em; 
    margin-bottom: 15px; 
}

.filter-buttons { 
    display: flex; 
    gap: 10px; 
}

.filter-btn {
    flex: 1; 
    background: rgba(255, 255, 255, 0.2); 
    border: 2px solid white; 
    color: white;
    padding: 8px; 
    border-radius: 6px; 
    cursor: pointer; 
    transition: all 0.3s; 
    font-weight: bold;
}

.filter-btn.active { 
    background: white; 
    color: #667eea; 
}

#ranking-list { 
    padding: 20px; 
}

.ranking-item {
    background: #f5f5f5; 
    padding: 15px; 
    margin-bottom: 10px; 
    border-radius: 8px;
    cursor: pointer; 
    transition: all 0.3s; 
    display: flex; 
    align-items: center; 
    gap: 15px;
}

.ranking-item:hover { 
    background: #e0e0e0; 
    transform: translateX(-5px); 
}

.rank-number {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white; 
    width: 40px; 
    height: 40px; 
    border-radius: 50%; 
    display: flex;
    align-items: center; 
    justify-content: center; 
    font-weight: bold; 
    font-size: 1.1em;
}

.rank-info { 
    flex: 1; 
}

.dept-name { 
    font-weight: bold; 
    font-size: 1.1em; 
    margin-bottom: 5px; 
    color:#333; 
}

.dept-stats { 
    font-size: 0.9em; 
    color: #666; 
}

.rank-bar { 
    width: 100%; 
    height: 6px; 
    background: #ddd; 
    border-radius: 3px; 
    margin-top: 8px; 
    overflow: hidden; 
}

.rank-bar-fill { 
    height: 100%; 
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%); 
    transition: width 0.5s ease; 
}

/* Boutons de fermeture généraux */
.close-btn {
    position: absolute; 
    top: 15px; 
    right: 15px; 
    background: rgba(0, 0, 0, 0.1);
    border: none; 
    color: #333; 
    width: 30px; 
    height: 30px; 
    border-radius: 50%;
    cursor: pointer; 
    font-size: 1.2em; 
    line-height: 30px; 
    text-align: center; 
    z-index: 100;
}

.panel-header .close-btn { 
    color: white; 
    background: rgba(255, 255, 255, 0.2); 
}

/* =========================================
   SIDEBAR (DÉTAILS DES SITES)
========================================= */
#sidebar {
    position: fixed; 
    top: 100px; 
    right: -450px; 
    width: 450px; 
    height: calc(100vh - 100px);
    background: white; 
    box-shadow: -5px 0 20px rgba(0, 0, 0, 0.3);
    transition: right 0.4s ease; 
    z-index: 2000; 
    overflow-y: auto;
}

#sidebar:not(.hidden) { 
    right: 0; 
}

#sidebar-back-btn {
    position: absolute; 
    top: 15px; 
    left: 15px;
    background: rgba(102, 126, 234, 0.1); 
    color: #667eea; 
    border: none;
    padding: 6px 12px; 
    border-radius: 6px; 
    font-weight: bold; 
    font-size: 0.9em;
    cursor: pointer; 
    z-index: 100; 
    transition: background 0.2s;
}

#sidebar-back-btn:hover { 
    background: rgba(102, 126, 234, 0.2); 
}

.sidebar-content { 
    padding: 50px 30px 30px 30px; 
}

.dc-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white; 
    padding: 25px; 
    border-radius: 12px; 
    margin-bottom: 25px;
}

#dc-name { 
    font-size: 1.4em; 
    font-weight: bold; 
    margin-bottom: 10px; 
}

#dc-address { 
    opacity: 0.9; 
    margin-bottom: 8px; 
    font-size: 0.9em; 
}

.naf-badge {
    display: inline-block; 
    background: rgba(255, 255, 255, 0.2); 
    color: white;
    padding: 4px 12px; 
    border-radius: 12px; 
    font-size: 0.85em; 
    margin-top: 8px; 
    font-weight: bold;
}

.info-section { 
    background: #f8f9fa; 
    padding: 20px; 
    border-radius: 10px; 
    margin-bottom: 20px; 
}

.info-title { 
    font-weight: bold; 
    margin-bottom: 15px; 
    color: #667eea; 
    font-size: 1.1em; 
}

.conso-display { 
    text-align: center; 
    margin: 15px 0; 
}

.conso-value { 
    font-size: 2.2em; 
    font-weight: bold; 
    color: #333; 
}

.conso-bar-container { 
    width: 100%; 
    height: 8px; 
    background: #e0e0e0; 
    border-radius: 4px; 
    overflow: hidden; 
    margin-top: 10px; 
}

#conso-bar { 
    height: 100%; 
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%); 
    transition: width 0.5s ease; 
}

/* =========================================
   TABLEAUX (HISTORIQUE ET LISTES)
========================================= */
table { 
    width: 100%; 
    border-collapse: collapse; 
}

th, td { 
    padding: 12px 8px; 
    text-align: left; 
    border-bottom: 1px solid #e0e0e0; 
    font-size: 0.9em; 
    color: #333;
}

th { 
    background: #f5f5f5; 
    font-weight: 600; 
    color: #667eea; 
    border-bottom: 2px solid #ddd;
}

tr:hover { 
    background: #fff; 
}