/* Variables pour une maintenance facile */
:root {
    /* Couleurs de la marque */
    --ae-primary: #0d4d8c; /* Bleu principal */
    --ae-accent: #d9581b;  /* Orange accent (Logo) */

    /* Global page colors (light mode defaults) */
    --page-bg: #f8f9fa;
    --page-text-color: #212529;
    --card-bg: #ffffff;
    --muted-text: rgba(33,37,41,0.6);
    --border-color: rgba(0,0,0,0.08);
    --header-bg: #ffffff; /* Fond blanc pour la navbar en mode clair */
    --header-height: 64px;

    /* Sidebar specific (Light Mode) */
    --sidebar-width: 250px;
    --sidebar-bg-color: var(--ae-primary); /* Menu latéral sombre (couleur marque) en mode clair */
    --sidebar-text-color: rgba(255, 255, 255, 0.85);
    --sidebar-muted-text: rgba(255, 255, 255, 0.6);
    --sidebar-hover-bg: rgba(255, 255, 255, 0.05);
    --sidebar-hover-text: #ffffff;
    --sidebar-accent: var(--ae-accent);
    --sidebar-border-color: rgba(0,0,0,0.1);
    --sidebar-active-bg: linear-gradient(90deg, rgba(217, 88, 27, 0.12), transparent);
    --sidebar-active-shadow: rgba(217, 88, 27, 0.08);
}

/* Dark theme variable overrides (applied when html[data-bs-theme="dark"]) */
html[data-bs-theme="dark"] {
    /* Sidebar overrides */
    --sidebar-bg-color: #0b1a2a; /* Un bleu très sombre pour le mode nuit */
    --sidebar-text-color: rgba(255,255,255,0.92);
    --sidebar-muted-text: rgba(255,255,255,0.65);
    --sidebar-hover-bg: rgba(255,255,255,0.03);
    --sidebar-hover-text: rgba(255,255,255,0.95);
    --sidebar-border-color: rgba(255,255,255,0.04);
    --sidebar-active-bg: linear-gradient(90deg, rgba(217, 88, 27, 0.15), transparent);
    --sidebar-active-shadow: rgba(217, 88, 27, 0.05);

    /* Global dark mode overrides */
    --page-bg: #0b0f14;
    --page-text-color: #e6eef6;
    --card-bg: #0f1720;
    --muted-text: rgba(230,238,246,0.6);
    --border-color: rgba(255,255,255,0.08);
    --header-bg: #0f1720; /* Fond sombre, aligné avec les cartes */
}

/* Small header styles (the top small nav) */
.small-header { position: sticky; top: 0; z-index: 1030; background: var(--header-bg); box-shadow: 0 1px 4px var(--border-color); }
.small-header .navbar-brand { font-size: 0.98rem; color: var(--page-text-color); }
/* Header buttons and controls style */
.small-header .btn { color: var(--page-text-color); border-color: rgba(0,0,0,0.06); background: transparent; }
.small-header .btn i { color: var(--muted-text); }
.small-header .btn-outline-primary { color: var(--sidebar-accent); border-color: rgba(13,110,253,0.16); }
.small-header .btn-outline-secondary { border-color: var(--border-color); }
.small-header .dropdown-menu { min-width: 280px; background: var(--card-bg); color: var(--page-text-color); border: 1px solid var(--border-color); }
.small-header .dropdown-item { color: var(--page-text-color); }
.small-header .badge { color: #fff; }

html[data-bs-theme="dark"] .small-header { box-shadow: 0 1px 6px rgba(0,0,0,0.6); }
html[data-bs-theme="dark"] .small-header .navbar-brand, html[data-bs-theme="dark"] .small-header .small { color: rgba(255,255,255,0.9); }
html[data-bs-theme="dark"] .small-header .btn { color: var(--page-text-color); border-color: var(--border-color); }
html[data-bs-theme="dark"] .small-header .btn i { color: var(--muted-text); }
html[data-bs-theme="dark"] .small-header .btn-outline-secondary { border-color: var(--border-color); }
html[data-bs-theme="dark"] .small-header .btn-outline-primary { color: var(--sidebar-accent); border-color: rgba(255,255,255,0.08); }
html[data-bs-theme="dark"] .small-header .dropdown-menu { background: var(--card-bg); border-color: var(--border-color); }

/* Modern touch: nicer typography and spacing */
body { color-scheme: light dark; background: var(--page-bg); color: var(--page-text-color); }
.sidebar { font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial; }

/* Structure principale */
#wrapper {
    overflow-x: hidden;
    background: var(--page-bg); /* Couleur de fond pour le contenu */
}

/* Style du menu latéral */
#sidebar-wrapper {
    /* Positionnement et dimensions */
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: var(--sidebar-width);
    z-index: 1045;
    /* Apparence */
    background-color: var(--sidebar-bg-color);
    border-right: 1px solid var(--sidebar-border-color);
    box-shadow: 0 6px 18px rgba(0,0,0,0.12);
    backdrop-filter: saturate(120%) blur(6px);
    /* Comportement */
    transition: transform 0.28s ease, box-shadow 0.2s ease;
    transform: translateX(-110%);
}

#page-content-wrapper {
    flex: 1 1 auto;
    width: 100%;
    transition: margin 0.25s ease;
    min-height: 100vh;
    background: transparent;
}

/* Pour les pages sans sidebar (ex: formulaires publics), le contenu doit prendre toute la largeur */
#wrapper.full-page-wrapper #page-content-wrapper {
    width: 100% !important;
    margin-left: 0 !important;
    flex-grow: 1;
}

/* Affichage du menu latéral sur mobile (via JS) ou sur desktop (par défaut) */
#wrapper.toggled #sidebar-wrapper,
body.sidebar-open #sidebar-wrapper {
    transform: translateX(0);
}

/* Style des liens du menu */
.sidebar-heading {
    font-size: 1.2rem;
    font-weight: bold;
}

.list-group-item {
    background-color: transparent;
    color: var(--sidebar-text-color);
    border: 0;
    transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
}

.list-group-item:hover, .list-group-item:focus {
    background-color: var(--sidebar-hover-bg);
    color: var(--sidebar-hover-text);
}

.list-group-item i {
    min-width: 2rem;
}

/* Responsive: sur les grands écrans, le menu est visible par défaut */
/* Desktop: make sidebar fixed and content offset */
@media (min-width: 992px) {
    /* Par défaut sur grand écran, le menu est visible */
    #sidebar-wrapper {
        transform: translateX(0);
    }
    /* Et le contenu principal est décalé vers la droite */
    #page-content-wrapper {
        margin-left: var(--sidebar-width); /* C'est la règle clé qui résout le problème */
    }

    /* Quand le menu est volontairement masqué (via JS), on le cache et on supprime la marge */
    #wrapper.toggled #sidebar-wrapper { transform: translateX(calc(-1 * var(--sidebar-width))); }
    #wrapper.toggled #page-content-wrapper { margin-left: 0; }
}

.sidebar {
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    display: flex;
}

.sidebar-inner { display:flex; flex-direction:column; width:100%; height:100vh; }
.sidebar-header { border-bottom: 1px solid var(--sidebar-border-color); }
.sidebar-inner nav { flex: 1 1 auto; overflow-y: auto; padding-bottom: 0.5rem; }
.sidebar-footer { flex: 0 0 auto; }
.logo-circle { font-size: 1rem; }

.nav-link.list-group-item { color: var(--sidebar-text-color); padding: .75rem 1rem; border:0; transition: background .15s ease, color .15s ease, transform .15s ease; display:flex; align-items:center; }
.nav-link.list-group-item i{ min-width:1.6rem; }
.nav-link.list-group-item:hover, .nav-link.list-group-item:focus {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-hover-text);
    text-decoration:none;
    transform: translateX(3px);
}
.nav-link.list-group-item.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-hover-text);
    border-left: 3px solid var(--sidebar-accent); /* Bordure orange pour l'élément actif */
    box-shadow: inset 0 0 10px var(--sidebar-active-shadow);
}
.link-text { white-space:nowrap; }

/* Subtle badges and section titles */
.sidebar .section-title { color: var(--sidebar-muted-text); font-size: .75rem; text-transform: uppercase; padding: .5rem 1rem; margin-top: .5rem; }

/* Custom scrollbar for sidebar */
.sidebar-inner nav::-webkit-scrollbar { width: 8px; }
.sidebar-inner nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 8px; }
.sidebar-inner nav::-webkit-scrollbar-track { background: transparent; }

/* Compact desktop: show icons only when collapsed (optional) */
@media (min-width: 992px) {
    body.sidebar-collapsed #page-content-wrapper { margin-left: 72px; }
    body.sidebar-collapsed #sidebar-wrapper { width: 72px; }
    body.sidebar-collapsed .link-text { display: none; }
    body.sidebar-collapsed .nav-link.list-group-item { justify-content: center; }
}

/* Dark mode scrollbar tweaks */
html[data-bs-theme="dark"] .sidebar-inner nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); }

.sidebar-footer { background: linear-gradient(0deg, rgba(0,0,0,0.03), transparent); }
.avatar{ width:40px; height:40px; font-weight:700; }

/* Styles responsives pour les écrans < 992px */
@media (max-width:991.98px){
    /* Le contenu prend toute la largeur */
    #page-content-wrapper { margin-left: 0; }
    /* Les boutons du footer passent en colonne */
    .sidebar-footer .d-flex { flex-direction: column; gap: .4rem; }
    .sidebar-footer .btn { width: 100%; }
    /* Fond assombri derrière le menu latéral ouvert */
    body.sidebar-open::after {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.35);
        z-index: 1040;
    }
}

/* Small header responsive tweaks */
.small-header .container-fluid { gap: 0.5rem; }
.small-header .navbar-brand { display:flex; align-items:center; gap:.5rem; }
@media (max-width:575.98px){
    .small-header .d-none.d-md-flex { display:none !important; }
    .small-header .ms-auto { gap:.5rem; }
}

/* Homepage hero and features styling */
.hero { padding: 4.5rem 0; background: linear-gradient(180deg, rgba(13,110,253,0.06), transparent); display:flex; align-items:center; }
.hero .hero-card { border-radius: 12px; overflow: hidden; }
.hero .hero-card .card-body { padding: 2rem; }
.hero .display-5 { color: var(--page-text-color); }
.hero p.lead { color: rgba(33,37,41,0.7); }

.feature-card { background: var(--card-bg); border-radius: 10px; }
.feature-card h5 { margin-bottom: .5rem; }

.cta { background: linear-gradient(180deg, rgba(13,110,253,0.02), transparent); }

@media (prefers-color-scheme: dark) {
    .hero { background: linear-gradient(180deg, rgba(13,110,253,0.02), transparent); }
    .hero p.lead { color: rgba(230,238,246,0.8); }
}

/* Full height hero on large screens */
@media (min-width: 992px) {
    .hero { min-height: calc(100vh - var(--header-height)); padding: 2rem 0; }
}

/* --- Fix pour les Dropdowns (Notifications, etc.) --- */
/* Empêche le débordement horizontal et force le retour à la ligne */
.dropdown-menu {
    max-width: 350px; /* Largeur maximale fixe pour éviter que le menu ne soit trop large */
    white-space: normal; /* Permet le retour à la ligne globalement */
}

.dropdown-item {
    white-space: normal; /* Force le texte à revenir à la ligne */
    word-wrap: break-word; /* Coupe les mots longs proprement */
    overflow-wrap: break-word; /* Standard moderne pour la césure */
    padding: 0.5rem 1rem; /* Espacement confortable pour la lecture */
}
