/* Styles généraux de la page */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #e9ecef;
    margin: 0;
    color: #343a40;
}

main {
    padding: 10px;
}

.header-section {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 25px;
    margin-top: 80px;
}

.header-title {
    color: #1f2937;
    font-size: 1.8rem;
    font-weight: 700;
    margin: 0 auto;
    text-align: center;
}

.error-message {
    background-color: #fee2e2;
    border: 1px solid #fca5a5;
    color: #b91c1c;
    padding: 15px;
    border-radius: 8px;
    margin: 80px auto 20px auto;
    max-width: 800px;
    text-align: center;
}

/* Conteneur des cartes de stats */
.stats-container {
    margin-bottom: 40px;
    padding: 15px;
    border-radius: 15px;
    background-color: #f3f4f6;
    border: 1px solid #c8cdd7;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.stats-header-grid {
    display: grid;
    gap: 15px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media screen and (min-width: 1100px) {
    .stats-header-grid {
        grid-template-columns: repeat(9, minmax(0, 1fr));
    }
}

.stat-card {
    background-color: white;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    border-left: 7px solid;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 118px;
    height: auto;
    color: inherit;
    text-decoration: none;
    box-sizing: border-box;
}

.stat-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 10px rgba(0, 0, 0, 0.08);
}

.stat-sub-value {
    font-size: 0.78em;
    width: 100%;
    text-align: center;
    font-weight: 500;
    color: #6b7280;
    line-height: 1.25;
}

.stat-progress-bar {
    width: 100%;
    height: 6px;
    margin-top: 8px;
    border-radius: 999px;
    background: #e5e7eb;
    overflow: hidden;
}

.stat-progress-bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--stat-color, #4f46e5);
}

.stat-value-large {
    font-size: 2.2em;
    width: 100%;
    text-align: center;
    font-weight: 700;
}

.stat-footer {
    display: flex;
    align-items: end;
    gap: 10px;
    width: 100%;
    padding: 10px 5px 0 5px;
}

.stat-footer i {
    font-size: 1.4rem;
}

.stat-label {
    font-size: 0.9rem;
    font-weight: 500;
}

/* Couleurs des cartes */
.stat-total-full { border-left-color: #4f46e5; --stat-color: #4f46e5; }
.stat-ok { border-left-color: #10b981; --stat-color: #10b981; }
.stat-ko { border-left-color: #ef4444; --stat-color: #ef4444; }
.stat-reforme { border-left-color: #272727; --stat-color: #272727; }
.stat-uncontrolled { border-left-color: #6b7280; --stat-color: #6b7280; }
.stat-not-found { border-left-color: #0876e3; --stat-color: #0876e3; }
.stat-repair { border-left-color: #f59e0b; --stat-color: #f59e0b; }

.stat-card .stat-value-large,
.stat-card .stat-footer i {
    color: var(--stat-color);
}

/* Grille pour les tableaux */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.dashboard-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* Styles des conteneurs de tableau */
.dashboard-table-container {
    background-color: #f3f4f6;
    border: 1px solid #c8cdd7;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.chart-header {
    display: flex;
    flex-direction: column; /* Met les éléments en colonne : titre puis boutons */
    margin-bottom: 15px;
}

.list-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: #1f2937;
    text-align: center; /* Centrage du titre */
    margin-bottom: 15px; /* Espace sous le titre */
}

.table-wrapper {
    max-height: 400px;
    overflow-y: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid #dee2e6;
}

thead th {
    background-color: #e9ecef;
    position: sticky;
    top: 0;
}

tbody tr:hover {
    background-color: #e9ecef;
}

td a {
    color: #4f46e5;
    text-decoration: none;
    font-weight: 500;
}

td a:hover {
    text-decoration: underline;
}

/* Responsive */
@media screen and (max-width: 992px) {
    .dashboard-grid,
    .dashboard-grid-3 {
        grid-template-columns: 1fr;
    }
}

@media screen and (max-width: 767px) {
    /* Comportement mobile : 2 colonnes comme sur la page des lits/pesons */
    .stats-header-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* =================================== */
/* NOUVEAU: GRAPHIQUES (Chart.js)      */
/* =================================== */

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 20px;
    margin-bottom: 20px; /* Espace ajouté sous la grille des graphiques */
}

.charts-grid-pies .chart-container:not(.evolution-chart-container) {
    min-height: 380px;
}

.chart-container {
    background-color: #f3f4f6;
    border: 1px solid #c8cdd7;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    position: relative; /* Nécessaire pour le z-index des boutons */
    height: 400px; /* Hauteur fixe pour le conteneur du graphique */
}

.chart-container canvas {
    max-height: 100%;
    max-width: 100%;
}

.evolution-chart-container {
    grid-column: span 2; /* Chaque graphique d'évolution prend toute la largeur */
    height: 450px; /* Hauteur augmentée pour une meilleure lisibilité sur tous les écrans */
    padding-bottom: 40px; /* Espace ajouté en bas pour éviter que les labels ne sortent du cadre */
} 

.evolution-chart-controls {
    display: flex;    
    gap: 5px;
    background-color: #e5e7eb;
    padding: 5px;
    border-radius: 8px;
    z-index: 10;
    align-self: flex-end; /* Aligne le bloc de boutons à droite */
}

.evolution-btn,
.evolution-btn-details {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    background-color: transparent;
    color: #4b5563;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s, box-shadow 0.2s;
}

.evolution-btn.active,
.evolution-btn-details.active,
.evolution-btn:hover,
.evolution-btn-details:hover { /* Ajout du hover pour le 2ème graphique */
    background-color: #ffffff;
    color: #4f46e5;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

@media screen and (max-width: 992px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
    
    .evolution-chart-container {
        /* Assure que les graphiques d'évolution ne forcent pas 2 colonnes sur mobile */
        grid-column: span 1;
        /* La hauteur de 450px est maintenant héritée de la règle de base */
    }

    .chart-header {
        justify-content: center; /* Centre les éléments sur mobile */
        align-items: center; /* Centre le bloc de boutons */
    }

    .evolution-chart-controls {
        align-self: center; /* Assure le centrage sur mobile */
        justify-content: center; /* Centre les boutons eux-mêmes */
        width: 100%;
    }
}

/* =================================== */
/* NOUVEAU: FILTRE PAR ANNÉE / SITE    */
/* =================================== */

.filter-container {
    margin-bottom: 20px;
    text-align: center;
}

.dashboard-filters-form {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-end;
    gap: 12px 20px;
}

.dashboard-filter-field {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

.dashboard-filter-field label,
.filter-container label {
    font-weight: 600;
    color: #374151;
    font-size: 0.9rem;
}

.dashboard-filter-field select,
.filter-container select {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    font-size: 1rem;
    background: #fff;
    min-width: 180px;
    max-width: 100%;
}

.dashboard-filter-hint {
    margin: 10px 0 0;
    color: #4f46e5;
    font-size: 0.95rem;
}

.progress-summary {
    max-width: 900px;
    margin: 0 auto 22px;
    padding: 14px 16px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid #c8cdd7;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.progress-summary-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 8px;
}

.progress-summary-head strong {
    color: #4f46e5;
    font-size: 1.15rem;
}

.progress-bar {
    width: 100%;
    height: 10px;
    border-radius: 999px;
    background: #e5e7eb;
    overflow: hidden;
}

.progress-bar-fill {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #6366f1, #10b981);
}

.progress-summary-meta {
    margin-top: 8px;
    font-size: 0.9rem;
    color: #6b7280;
    text-align: left;
}