/**
 * Styles universels pour les sidebars
 * Garantit une cohérence visuelle et fonctionnelle
 */

:root {
    --sidebar-width: 300px;
    --bg-primary: #f9fafb;
    --bg-secondary: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --sidebar-bg: #ffffff;
    --sidebar-text: #6b7280;
    --sidebar-hover: #f3f4f6;
    --sidebar-active-bg: #eef2ff;
    --sidebar-active-text: #6366f1;
    --card-bg: #ffffff;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    --input-bg: #f8fafc;
    --input-border: #e2e8f0;
    --table-header: #f9fafb;
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --sidebar-bg: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-hover: #334155;
    --sidebar-active-bg: #312e81;
    --sidebar-active-text: #818cf8;
    --card-bg: #1e293b;
    --card-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --input-bg: #0f172a;
    --input-border: #334155;
    --table-header: #0f172a;
}

/* Application globale des couleurs de thème */
body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s, color 0.3s;
}

/* Overlay pour mobile */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Sidebar principale */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    max-width: 85vw;
    height: 100%;
    background: var(--sidebar-bg);
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s ease, background-color 0.3s;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Sidebar ouverte */
.sidebar.active {
    transform: translateX(0);
}

/* Header de la sidebar */
.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header .logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.5rem;
    font-weight: 800;
    color: #6366f1;
}

.sidebar-header .logo i {
    font-size: 1.8rem;
    color: #10b981;
}

.sidebar-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: all 0.2s;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-close:hover {
    background: #fee2e2;
    color: #dc2626;
}

.sidebar-close:active {
    transform: scale(0.95);
}

/* Bouton hamburger dans le header principal */
.hamburger-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 998;
    background: var(--bg-secondary);
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.hamburger-btn:hover {
    background: var(--sidebar-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}

.hamburger-btn:active {
    transform: translateY(0);
}

/* Cacher le bouton hamburger quand la sidebar est ouverte (tous écrans) */
body.sidebar-is-open .hamburger-btn {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-100%);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Navigation */
.sidebar-nav {
    flex: 1;
    padding: 20px 0;
    overflow-y: auto;
}

.user-info {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1 0%, #10b981 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
}

.user-details {
    flex: 1;
}

.user-name {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.user-role {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

/* Theme Toggle Button */
.theme-toggle {
    background: var(--sidebar-hover);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    color: #6366f1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

.theme-toggle:hover {
    background: #6366f1;
    color: white;
    transform: rotate(30deg);
}

.theme-toggle .fa-sun {
    display: none;
}

[data-theme="dark"] .theme-toggle .fa-moon {
    display: none;
}

[data-theme="dark"] .theme-toggle .fa-sun {
    display: block;
}

[data-theme="dark"] .theme-toggle {
    color: #facc15;
}

/* Menu de navigation */
.nav-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-item {
    margin: 5px 0;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.nav-link:hover {
    background: var(--sidebar-hover);
    color: #6366f1;
    border-left-color: #6366f1;
}

.nav-item.active .nav-link {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    border-left-color: #6366f1;
    font-weight: 600;
}

.nav-link i {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
}

/* Footer de la sidebar */
.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

.logout-btn {
    width: 100%;
    padding: 12px;
    background: #fee2e2;
    color: #dc2626;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-weight: 600;
    transition: all 0.2s;
}

[data-theme="dark"] .logout-btn {
    background: rgba(220, 38, 38, 0.2);
}

.logout-btn:hover {
    background: #fecaca;
    transform: translateY(-1px);
}

[data-theme="dark"] .logout-btn:hover {
    background: rgba(220, 38, 38, 0.3);
}

.nav-submenu {
    list-style: none;
    margin: 0;
    padding: 0;
    background: var(--bg-primary);
    border-left: 3px solid #6366f1;
    overflow: hidden;
    transition: all 0.3s ease;
}

.nav-submenu-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px 12px 50px;
    color: var(--text-primary);
    text-decoration: none;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.nav-submenu-link:hover {
    background: var(--sidebar-hover);
    color: #6366f1;
}

.nav-submenu-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
}

/* Contenu principal avec sidebar */
.main-content-with-sidebar {
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s ease;
}

.main-content.sidebar-open {
    margin-left: 0;
}

/* Responsive - Desktop */
@media (min-width: 993px) {

    /* Sidebar peut être ouverte/fermée sur desktop */
    .sidebar {
        position: fixed;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    /* Sidebar ouverte sur desktop */
    .sidebar.active {
        transform: translateX(0);
    }

    /* Pas d'overlay sur desktop */
    .sidebar-overlay {
        display: none !important;
    }

    /* Bouton de fermeture visible sur desktop */
    .sidebar-close {
        display: flex !important;
    }

    /* Bouton hamburger visible sur desktop (sauf quand sidebar ouverte) */
    .hamburger-btn {
        display: flex !important;
        opacity: 1;
        pointer-events: auto;
        transform: translateX(0);
    }

    /* Cacher le bouton hamburger quand la sidebar est ouverte sur desktop */
    body.sidebar-is-open .hamburger-btn {
        opacity: 0;
        pointer-events: none;
        transform: translateX(-100%);
    }

    /* Contenu principal avec marge pour la sidebar quand elle est ouverte */
    .main-content-with-sidebar {
        margin-left: 0;
        transition: margin-left 0.3s ease;
    }

    /* Quand la sidebar est ouverte, ajouter la marge */
    body:has(.sidebar.active) .main-content-with-sidebar,
    .main-content-with-sidebar.sidebar-open {
        margin-left: var(--sidebar-width);
    }

    /* Body toujours scrollable sur desktop */
    body.sidebar-is-open {
        overflow: visible !important;
    }
}

/* Responsive - Mobile */
@media (max-width: 992px) {
    .main-content-with-sidebar {
        margin-left: 0;
    }

    .sidebar-close {
        display: flex;
    }

    .hamburger-btn {
        display: flex;
        opacity: 1;
        pointer-events: auto;
        transform: translateX(0);
    }

    /* Cacher le bouton hamburger quand la sidebar est ouverte sur mobile */
    body.sidebar-is-open .hamburger-btn {
        opacity: 0;
        pointer-events: none;
        transform: translateX(-100%);
    }

    /* Sidebar cachée par défaut sur mobile */
    .sidebar {
        transform: translateX(-100%);
    }

    /* Sidebar visible quand active sur mobile */
    .sidebar.active {
        transform: translateX(0);
    }
}

/* Scrollbar personnalisée */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

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

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

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