/* ====================================
   MENU LATÉRAL - STYLES COMPLETS
   ==================================== */

/* Variables CSS pour le menu */
:root {
    --menu-width: 280px;
    --menu-width-collapsed: 60px;
    --menu-bg: #2c3e50;
    --menu-text: #ecf0f1;
    --menu-hover: #34495e;
    --menu-active: #3498db;
    --menu-border: #34495e;
    --transition-speed: 0.3s;
    --header-height: 70px;
}

/* ====================================
   STRUCTURE PRINCIPALE DU MENU
   ==================================== */

.sidebar-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--menu-width);
    height: 100vh;
    background: var(--menu-bg);
    color: var(--menu-text);
    transform: translateX(-100%);
    transition: transform var(--transition-speed) ease;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

.sidebar-menu.open {
    transform: translateX(0);
}

/* ====================================
   EN-TÊTE DU MENU
   ==================================== */

.menu-header {
    padding: 20px;
    border-bottom: 1px solid var(--menu-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--header-height);
}

.menu-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.menu-toggle {
    background: none;
    border: none;
    color: var(--menu-text);
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background var(--transition-speed);
}

.menu-toggle:hover {
    background: var(--menu-hover);
}

/* Icône hamburger animée */
.hamburger {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--menu-text);
    position: relative;
    transition: all var(--transition-speed);
}

.hamburger::before,
.hamburger::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 2px;
    background: var(--menu-text);
    transition: all var(--transition-speed);
}

.hamburger::before {
    top: -6px;
}

.hamburger::after {
    top: 6px;
}

/* Animation de l'icône hamburger quand le menu est ouvert */
.sidebar-menu.open .hamburger {
    background: transparent;
}

.sidebar-menu.open .hamburger::before {
    transform: rotate(45deg);
    top: 0;
}

.sidebar-menu.open .hamburger::after {
    transform: rotate(-45deg);
    top: 0;
}

/* ====================================
   CONTENU DU MENU
   ==================================== */

.menu-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
}

.menu-categories {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* ====================================
   ÉLÉMENTS DE MENU
   ==================================== */

.menu-item {
    margin: 0;
}

.menu-link {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--menu-text);
    text-decoration: none;
    transition: all var(--transition-speed);
    border-left: 3px solid transparent;
    font-size: 14px;
}

.menu-link:hover {
    background: var(--menu-hover);
    border-left-color: var(--menu-active);
}

.menu-link.active {
    background: var(--menu-active);
    border-left-color: #fff;
    font-weight: 600;
}

.menu-icon {
    margin-right: 12px;
    font-size: 16px;
    width: 20px;
    text-align: center;
}

/* ====================================
   SOUS-CATÉGORIES
   ==================================== */

.menu-subcategories {
    list-style: none;
    margin: 0;
    padding: 0;
    background: rgba(0, 0, 0, 0.1);
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--transition-speed) ease;
}

.menu-item.expanded .menu-subcategories {
    max-height: 500px; /* Ajustez selon le nombre de sous-catégories */
}

.menu-subcategories .menu-link {
    padding-left: 50px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.8);
}

.menu-subcategories .menu-link:hover {
    color: var(--menu-text);
    background: var(--menu-hover);
}

.menu-subcategories .menu-link.active {
    color: var(--menu-text);
    background: var(--menu-active);
}

/* Indicateur d'expansion */
.menu-expand-indicator {
    margin-left: auto;
    transition: transform var(--transition-speed);
    font-size: 12px;
}

.menu-item.expanded .menu-expand-indicator {
    transform: rotate(90deg);
}

/* ====================================
   PIED DU MENU
   ==================================== */

.menu-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--menu-border);
    text-align: center;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
}

/* ====================================
   OVERLAY POUR MOBILE
   ==================================== */

.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-speed);
}

.menu-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ====================================
   CONTENU PRINCIPAL ADAPTATIF
   ==================================== */

.main-content {
    transition: margin-left var(--transition-speed) ease;
    min-height: 100vh;
}

/* ====================================
   EN-TÊTE DE PAGE
   ==================================== */

.page-header {
    display: flex;
    align-items: center;
    gap: 15px;
    background: var(--menu-active);
    color: white;
    padding: 15px 20px;
    margin: 0;
}

.mobile-menu-btn {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background 0.3s;
}

.mobile-menu-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

#page-title {
    margin: 0;
    font-size: 20px;
    font-weight: 300;
    flex: 1;
}

/* ====================================
   RESPONSIVE - DESKTOP
   ==================================== */

@media (min-width: 1024px) {
    /* Menu toujours visible sur desktop */
    .sidebar-menu {
        transform: translateX(0);
        position: relative;
        height: auto;
        min-height: 100vh;
    }
    
    .main-content {
        margin-left: var(--menu-width);
    }
    
    .mobile-menu-btn {
        display: none;
    }
    
    .menu-overlay {
        display: none;
    }
    
    /* Ajustements pour desktop */
    .menu-header {
        position: sticky;
        top: 0;
        background: var(--menu-bg);
        z-index: 10;
    }
}

/* ====================================
   RESPONSIVE - TABLETTE
   ==================================== */

@media (min-width: 768px) and (max-width: 1023px) {
    .sidebar-menu {
        width: 250px;
    }
    
    :root {
        --menu-width: 250px;
    }
}

/* ====================================
   RESPONSIVE - MOBILE
   ==================================== */

@media (max-width: 767px) {
    .sidebar-menu {
        width: 280px;
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .page-header {
        padding: 12px 15px;
    }
    
    #page-title {
        font-size: 16px;
    }
    
    .menu-header {
        padding: 15px;
    }
    
    .menu-link {
        padding: 15px 20px;
        font-size: 16px;
    }
}

/* ====================================
   ANIMATIONS ET TRANSITIONS
   ==================================== */

@keyframes slideInRight {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.menu-item {
    animation: slideInRight 0.3s ease forwards;
}

.menu-item:nth-child(1) { animation-delay: 0.1s; }
.menu-item:nth-child(2) { animation-delay: 0.15s; }
.menu-item:nth-child(3) { animation-delay: 0.2s; }
.menu-item:nth-child(4) { animation-delay: 0.25s; }
.menu-item:nth-child(5) { animation-delay: 0.3s; }

/* ====================================
   ÉTATS SPÉCIAUX
   ==================================== */

/* Focus pour l'accessibilité */
.menu-link:focus,
.menu-toggle:focus,
.mobile-menu-btn:focus {
    outline: 2px solid var(--menu-active);
    outline-offset: 2px;
}

/* Désactivé */
.menu-link.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Badge de notification (optionnel) */
.menu-badge {
    background: #e74c3c;
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 10px;
    margin-left: auto;
    min-width: 18px;
    text-align: center;
}

/* ====================================
   SOUS-CATÉGORIES DÉPLIÉES PAR DÉFAUT
   ==================================== */

/* État par défaut : sous-catégories visibles */
.menu-subcategories {
    list-style: none;
    margin: 0;
    padding: 0;
    background: rgba(0, 0, 0, 0.1);
    max-height: 1000px; /* ✅ Grande hauteur par défaut */
    overflow: hidden;
    transition: max-height var(--transition-speed) ease;
}

/* Quand la catégorie est fermée (pas de classe expanded) */
.menu-item:not(.expanded) .menu-subcategories {
    max-height: 0;
}

/* Quand la catégorie est ouverte */
.menu-item.expanded .menu-subcategories {
    max-height: 1000px;
}

/* Indicateur d'expansion mis à jour */
.menu-expand-indicator {
    margin-left: auto;
    transition: transform var(--transition-speed);
    font-size: 12px;
}

/* État déplié par défaut */
.menu-item.expanded .menu-expand-indicator {
    transform: rotate(0deg); /* ✅ Flèche vers le bas par défaut */
}

/* État replié */
.menu-item:not(.expanded) .menu-expand-indicator {
    transform: rotate(-90deg); /* ✅ Flèche vers la droite quand fermé */
}

/* Animation d'apparition des sous-catégories */
.menu-subcategories .menu-item {
    opacity: 0;
    transform: translateX(-10px);
    animation: slideInSubmenu 0.3s ease forwards;
}

.menu-item.expanded .menu-subcategories .menu-item:nth-child(1) { animation-delay: 0.1s; }
.menu-item.expanded .menu-subcategories .menu-item:nth-child(2) { animation-delay: 0.15s; }
.menu-item.expanded .menu-subcategories .menu-item:nth-child(3) { animation-delay: 0.2s; }
.menu-item.expanded .menu-subcategories .menu-item:nth-child(4) { animation-delay: 0.25s; }
.menu-item.expanded .menu-subcategories .menu-item:nth-child(5) { animation-delay: 0.3s; }
.menu-item.expanded .menu-subcategories .menu-item:nth-child(6) { animation-delay: 0.35s; }
.menu-item.expanded .menu-subcategories .menu-item:nth-child(7) { animation-delay: 0.4s; }
.menu-item.expanded .menu-subcategories .menu-item:nth-child(8) { animation-delay: 0.45s; }
.menu-item.expanded .menu-subcategories .menu-item:nth-child(9) { animation-delay: 0.5s; }

@keyframes slideInSubmenu {
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Amélioration visuelle des sous-catégories */
.menu-subcategories .menu-link {
    padding-left: 50px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.8);
    position: relative;
}

.menu-subcategories .menu-link::before {
    content: '├';
    position: absolute;
    left: 35px;
    color: rgba(255, 255, 255, 0.3);
    font-family: monospace;
}

.menu-subcategories .menu-item:last-child .menu-link::before {
    content: '└';
}

.menu-subcategories .menu-link:hover {
    color: var(--menu-text);
    background: var(--menu-hover);
}

.menu-subcategories .menu-link.active {
    color: var(--menu-text);
    background: var(--menu-active);
}