/* ================== VARIABLES CSS & RESET ================== */
:root {
    --primary-dark: rgb(25 44 64);      /* Bleu foncé du logo */
    --primary-medium: #2A60A4;    /* Bleu moyen */
    --primary-light: #2d93f0;     /* Bleu clair d'accentuation */
    
    --bg-light: #F8F9FA;         /* Fond principal (très clair) */
    --bg-widget: #FFFFFF;        /* Fond des cartes */
    
    --text-dark: #333333;        /* Texte principal */
    --text-light: #FFFFFF;       /* Texte sur fond sombre */
    --text-muted: #6c757d;       /* Texte secondaire */
    
    --border-color: #EAECEE;     /* Bordures discrètes */

    --color-red: #D0021B;
    --color-green: #1D9A50;
    --color-cyan: #4AABC5;
    --color-black: #333333;
    
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    
    --sidebar-width: 300px;
    --border-radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg-light);
    color: var(--text-dark);
    line-height: 1.6;
    overflow-x: hidden; /* Empêche le scroll horizontal */
}

ul {
    list-style: none;
}

a {
    text-decoration: none;
    color: inherit;
}

canvas {
    width: 100% !important;
}

/* ================== LAYOUT PRINCIPAL ================== */
.dashboard-container {
    display: flex;
    min-height: 100vh;
}

/* ================== BARRE LATÉRALE (SIDEBAR) ================== */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--primary-dark);
    color: var(--text-light);
    padding: 20px;
    position: fixed;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto; /* Permet de scroller si le menu est long */
    z-index: 100; /* S'assure qu'elle est au-dessus */
}
.sidebar-header {
    margin-bottom: 50px;
    text-align: center;
    height: 115px;
}

.logo {
    max-width: 181px;
    margin-top: 23px;
}

.nav-links {
    display: flex;
    flex-direction: column;
    gap: 5px; /* Espace réduit entre les éléments */
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    border-radius: 8px;
    transition: background-color 0.3s ease, color 0.3s ease;
    font-weight: 500;
    font-size: 0.95em; /* Taille de police ajustée */
}

.nav-link i {
    font-size: 20px;
    margin-right: 15px;
    min-width: 25px;
    text-align: center;
}

.nav-link:hover {
    background-color: var(--primary-medium);
}

.nav-link.active,
.nav-link.open { /* Gère l'état ouvert de l'accordéon */
    background-color: var(--primary-light);
    color: var(--text-light);
    font-weight: 600;
}

.nav-link .arrow {
    margin-left: auto;
    transition: transform 0.3s ease;
}

.nav-link.open .arrow {
    transform: rotate(180deg);
}

.sub-menu {
    /* display: none; est géré par JS */
    padding-left: 45px; /* Indentation */
    margin-top: 5px;
}

.sub-menu li a {
    padding: 8px 10px;
    display: block;
    font-size: 0.9em;
    opacity: 0.8;
    border-radius: 6px;
}

.sub-menu li a:hover {
    opacity: 1;
    background-color: var(--primary-medium);
}

.nav-link .badge {
    margin-left: auto;
    background-color: #fff; /* Badge blanc */
    color: var(--primary-dark); /* Texte foncé */
    font-size: 0.7em;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 10px;
}

.nav-link.active .badge,
.nav-link.open .badge {
    background-color: var(--primary-dark); /* Inverse les couleurs */
    color: #fff;
}


/* ================== CONTENU PRINCIPAL ================== */
.main-content {
    flex-grow: 1;
    margin-left: var(--sidebar-width);
    padding: 30px;
    width: calc(100% - var(--sidebar-width)); /* S'assure qu'il ne dépasse pas */
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.header h2 {
    font-weight: 600;
    display: flex;
    align-items: center;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.3s ease;
}

.icon-btn:hover {
    color: var(--text-dark);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: var(--bg-widget);
    padding: 5px 10px;
    border-radius: 20px;
    cursor: pointer;
    border: 1px solid var(--border-color);
    font-weight: 500;
}

.user-profile img {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover; /* S'assure que l'image de profil n'est pas déformée */
}

/* ================== SECTION FILTRES ================== */
.filter-section {
    margin-bottom: 20px;
    padding: 0; /* Padding géré par les enfants */
}

.filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    cursor: pointer;
}

.filter-header .widget-title {
    margin-bottom: 0;
}

.filter-header .arrow {
    font-size: 20px;
    transition: transform 0.3s ease;
}

.filter-header.open .arrow {
    transform: rotate(180deg);
}

.filter-body {
    /* display: none; est géré par JS */
    padding: 0 20px 20px 20px;
    border-top: 1px solid var(--border-color);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-weight: 500;
    font-size: 0.9em;
    margin-bottom: 5px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-family: 'Poppins', sans-serif;
    background-color: #fff; /* S'assure que le fond est blanc */
}

/* Style pour le calendrier flatpickr */
input[type="text"][placeholder="Sélectionner une plage de dates"] {
    background-color: #fff;
    cursor: pointer;
}

.filter-actions {
    display: flex;
    gap: 10px;
}

/* ================== BOUTONS ================== */
.btn-primary,
.btn-secondary {
    border: none;
    padding: 10px 18px;
    font-size: 15px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background-color: var(--primary-light);
    color: var(--text-light);
}

.btn-primary:hover {
    background-color: var(--primary-medium);
}

.btn-secondary {
    background-color: var(--bg-widget);
    color: var(--primary-light);
    border: 2px solid var(--primary-light);
}

.btn-secondary:hover {
    background-color: var(--primary-light);
    color: var(--text-light);
}


/* ================== GRILLE DES WIDGETS ================== */
.widgets-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

.widget {
    background-color: var(--bg-widget);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.widget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.widget-title {
    font-size: 1.05em; /* Légèrement plus grand */
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 10px;
}

.widget-link {
    font-size: 0.9em;
    font-weight: 500;
    color: var(--primary-light);
}

.widget-link-inline {
    font-size: 0.8em;
    font-weight: 500;
    color: var(--primary-light);
    margin-left: 8px;
}

.widget-filter {
    padding: 5px 8px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    font-size: 0.9em;
    background-color: var(--bg-light);
}

/* ----- Cartes KPI ----- */
.kpi-card {
    display: flex;
    flex-direction: column;
}
.kpi-card .kpi-value {
    font-size: 2.2em;
    font-weight: 600;
    margin-bottom: 0px;
    line-height: 1.2;
}
.kpi-card .kpi-value span {
    font-size: 0.7em;
    font-weight: 500;
    color: var(--text-muted);
}
.kpi-card .kpi-subtext {
    font-size: 0.9em;
    color: var(--text-muted);
    height: 20px; /* Espace pour le sparkline */
}
.kpi-card .sparkline {
    margin-top: auto; /* Pousse le sparkline en bas */
    padding-top: 10px;
    height: 40px; /* Hauteur fixe pour le conteneur du sparkline */
}

/* ==================================
===== CORRECTIFS GRAPHIQUES ====
================================== */
.chart-card {
    position: relative; /* FIX 1: Base pour le rendu */
    grid-column: span 2;
    transform: translateZ(0); /* FIX 2: Anti-scintillement */
    -webkit-transform: translateZ(0);
    
    /* FIX 3: La carte est un conteneur flex vertical */
    display: flex;
    flex-direction: column;
    min-height: 320px; /* Hauteur minimale pour la carte */
    
    /* height: 300px; <-- SUPPRIMÉ ! C'EST L'ERREUR. */
}

/* NOUVEAU DIV : le conteneur du canvas */
.chart-canvas-container {
    position: relative;
    flex-grow: 1; /* C'EST LE FIX : il prend tout l'espace restant */
    min-height: 250px; /* Hauteur minimale pour le graphique lui-même */
}


/* ----- Bouton Flottant (FAB) ----- */
.fab {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 55px;
    height: 55px;
    border-radius: 50%;
    background-color: var(--primary-light);
    color: var(--text-light);
    border: none;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    z-index: 1000;
}

.fab:hover {
    background-color: var(--primary-medium);
    transform: translateY(-2px);
}

/* ================== RESPONSIVE DESIGN (MOBILE) ================== */

/* ----- Cache le bouton burger sur PC ----- */
.burger-btn {
    display: none;
}

/* ----- Mobiles ----- */
@media (max-width: 768px) {
    .dashboard-container {
        flex-direction: column;
    }
    .sidebar-header {
        margin-bottom: 0;
        height: 100%;
    }
    .sidebar {
        width: 100%;
        height: 70px; /* Hauteur fixe pour l'en-tête mobile */
        position: fixed; /* Reste en haut */
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding: 10px 20px;
        overflow-y: visible; /* Empêche le scroll vertical */
        z-index: 1000; /* Au-dessus de tout */
    }
    .sidebar-header .logo {
        height: 100%;
        max-width: unset;
        margin: 0;
    }

    /* ----- Le bouton Burger ----- */
    .burger-btn {
        display: block; /* S'affiche sur mobile */
        font-size: 30px;
        color: white;
        cursor: pointer;
        background: none;
        border: none;
        padding: 0;
        z-index: 1001; /* Au-dessus de la sidebar */
    }

    /* ----- Le menu qui s'ouvre ----- */
    .nav-links {
        display: none; /* Caché par défaut */
        position: fixed; /* Couvre tout l'écran */
        top: 70px; /* Juste en dessous de l'en-tête */
        left: 0;
        width: 100%;
        height: calc(100vh - 70px); /* Prend tout le reste de l'écran */
        background-color: var(--primary-dark);
        flex-direction: column;
        gap: 10px;
        padding: 20px;
        overflow-y: auto; /* Permet de scroller le menu s'il est long */
        z-index: 999;
    }
    .nav-links.mobile-open {
        display: flex; /* S'affiche au clic */
    }
    .nav-link .nav-text {
        display: block; /* Affiche le texte sur mobile */
    }
    .sub-menu {
        padding-left: 20px; /* Moins d'indentation */
    }


    .main-content {
        margin-left: 0;
        padding: 20px;
        padding-top: 90px; /* Espace pour la sidebar fixe */
        width: 100%; /* Prend toute la largeur */
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .header h2 {
        font-size: 1.5em;
    }
    .user-profile span {
        display: none; /* Cache "Bonjour, Votre Nom" */
    }
    
    .widgets-grid {
        grid-template-columns: 1fr; /* Une seule colonne */
    }
    
    .widget.span-2 {
        grid-column: span 1; /* S'adapte à une colonne */
    }
    
    .chart-card {
        min-height: 280px; /* Hauteur minimale réduite pour mobile */
    }
    .chart-canvas-container {
        min-height: 200px; /* Hauteur minimale du graphique réduite */
    }

    .form-row {
        grid-template-columns: 1fr; /* Champs de filtre en colonne */
    }

    .fab {
        bottom: 20px;
        right: 20px;
        z-index: 500;
    }
}