/* ===================================
   SIDEBAR NAVIGATION SYSTEM
   =================================== */

/* Variables CSS pour faciliter la personnalisation */
:root {
    --sidebar-width: 230px;
    --sidebar-collapsed-width: 50px;
    --navbar-height: 56px;
    --transition-speed: 0.3s;
}

/* === Layout principal === */
body {
    overflow-x: hidden;
}

/* Navbar supérieure fixe */
.navbar-top {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1030;
    height: var(--navbar-height);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Wrapper pour sidebar + contenu */
.wrapper {
    display: flex;
    width: 100%;
    align-items: stretch;
    padding-top: var(--navbar-height);
    min-height: 100vh;
}

/* === SIDEBAR === */
#sidebar {
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    background: #f8f9fa;
    color: #333;
    transition: all var(--transition-speed) ease;
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    bottom: 0;
    z-index: 1020;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 2px 0 5px rgba(0,0,0,0.05);
}

/* Sidebar en mode réduit */
#sidebar.collapsed {
    min-width: var(--sidebar-collapsed-width);
    max-width: var(--sidebar-collapsed-width);
}

/* Contenu de la sidebar */
.sidebar-sticky {
    position: sticky;
    top: 0;
    padding: 45px 0 5px 0;
}

/* === LISTE PRINCIPALE === */
#sidebar ul.nav {
    padding-left: 0 !important;
    margin-left: 0 !important;
}

/* === ÉLÉMENTS DE LISTE === */
#sidebar .nav-item {
    list-style: none;
    padding-left: 0 !important;
    margin-left: 0 !important;
}

/* === LIENS DE NAVIGATION === */
#sidebar .nav-link {
    color: #495057 !important;
    padding: 5px 0px 5px 22px !important;
    font-size: 13px !important;
    display: flex !important;
    align-items: center !important;
    transition: all 0.2s;
    border-left: 3px solid transparent !important;
    white-space: nowrap !important;
    margin-left: 0px !important;
    margin-right: 0px !important;
}

/* Accueil sans indentation */
#sidebar .nav-item:first-child .nav-link {
    padding-left: 8px !important;
}

#sidebar .nav-link i {
    min-width: 20px;
    font-size: 15px;
    transition: all var(--transition-speed);
}

#sidebar .nav-link:hover {
    background-color: #e9ecef;
    border-left-color: #007bff;
    color: #007bff;
    text-decoration: none;
}

#sidebar .nav-link.active {
    background-color: #007bff;
    color: white;
    border-left-color: #0056b3;
}

#sidebar .nav-link.active:hover {
    background-color: #0056b3;
}

/* Texte des liens (caché quand sidebar repliée) */
#sidebar .link-text {
    margin-left: 5px;
    transition: opacity var(--transition-speed);
}

#sidebar.collapsed .link-text {
    opacity: 0;
    display: none;
}

/* === TITRES DE SECTION === */
.sidebar-heading {
    font-size: 0.75rem;
    text-transform: uppercase;
    padding: 4px 0px 0px 8px !important;
    color: #343a40;
    font-weight: 700;
    letter-spacing: 0.5px;
    transition: all var(--transition-speed);
    margin-bottom: 0;
    margin-left: 0px !important;
}

#sidebar.collapsed .sidebar-heading {
    opacity: 0;
    display: none;
}

/* Séparateur visuel */
.sidebar-divider {
    height: 1px;
    background-color: #dee2e6;
    margin: 3px 8px;
}

/* === CONTENU PRINCIPAL === */
#content {
    width: 100%;
    padding: 0;
    min-height: 100vh;
    transition: all var(--transition-speed) ease;
    margin-left: var(--sidebar-width);
}

#content.expanded {
    margin-left: var(--sidebar-collapsed-width);
}

/* Container interne avec padding */
#content .content-inner {
    padding: 20px;
}

/* === BOUTON TOGGLE === */
.sidebar-toggle {
    position: fixed;
    top: calc(var(--navbar-height) + 5px);
    left: calc(var(--sidebar-width) - 40px);
    z-index: 1025;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    width: 35px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-speed);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    font-size: 16px;
    color: #495057;
}

.sidebar-toggle:hover {
    background: #e9ecef;
    border-color: #007bff;
    color: #007bff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}

#sidebar.collapsed ~ .sidebar-toggle {
    left: 5px;
}

#sidebar.collapsed ~ .sidebar-toggle i {
    transform: rotate(180deg);
}

/* === BADGE DE NOTIFICATION === */
.sidebar-badge {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background-color: #dc3545;
    color: white;
    border-radius: 8px;
    padding: 1px 6px;
    font-size: 10px;
    font-weight: bold;
}

#sidebar.collapsed .sidebar-badge {
    display: none;
}

/* === RESPONSIVE === */

/* Tablettes (iPad, etc.) */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 210px;
    }

    #sidebar .nav-link {
        font-size: 12px;
        padding: 4px 10px;
    }
}

/* Mobile */
@media (max-width: 768px) {
    #sidebar {
        margin-left: calc(-1 * var(--sidebar-width));
    }

    #sidebar.active {
        margin-left: 0;
    }

    #content {
        margin-left: 0;
    }

    .sidebar-toggle {
        left: 10px;
        top: calc(var(--navbar-height) + 10px);
    }

    #sidebar.collapsed ~ .sidebar-toggle {
        left: 10px;
    }

    /* Overlay pour fermer la sidebar en mobile */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: var(--navbar-height);
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1015;
    }

    .sidebar-overlay.active {
        display: block;
    }
}

/* Très petits écrans */
@media (max-width: 576px) {
    #content .content-inner {
        padding: 15px 10px;
    }

    .navbar-top .navbar-brand {
        font-size: 16px;
    }
}

/* === SCROLLBAR PERSONNALISÉE === */
#sidebar::-webkit-scrollbar {
    width: 6px;
}

#sidebar::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#sidebar::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

#sidebar::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* === ANIMATIONS === */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

#sidebar .nav-item {
    animation: slideIn 0.3s ease forwards;
}

#sidebar .nav-item:nth-child(1) { animation-delay: 0.05s; }
#sidebar .nav-item:nth-child(2) { animation-delay: 0.1s; }
#sidebar .nav-item:nth-child(3) { animation-delay: 0.15s; }
#sidebar .nav-item:nth-child(4) { animation-delay: 0.2s; }
#sidebar .nav-item:nth-child(5) { animation-delay: 0.25s; }

/* === ÉTATS SPÉCIAUX === */
/* Lien actif avec indicateur */
#sidebar .nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: white;
}

/* Tooltip pour sidebar réduite */
#sidebar.collapsed .nav-link {
    position: relative;
}

#sidebar.collapsed .nav-link:hover::after {
    content: attr(data-title);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    background: #333;
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    white-space: nowrap;
    margin-left: 10px;
    font-size: 13px;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
