/**
 * FORMATIPS - Unified CSS Fixes
 * Ce fichier corrige tous les conflits CSS identifiés
 * À charger EN DERNIER dans toutes les pages
 */

/* ============================================================================
   VARIABLES CSS UNIFIÉES
   ============================================================================ */

:root {
    /* Z-index scale unifié */
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-fixed: 300;
    --z-sidebar-overlay: 900;
    --z-sidebar: 1000;
    --z-mobile-menu: 1001;
    --z-modal-backdrop: 1050;
    --z-modal: 1060;
    --z-tooltip: 1070;
    --z-fab: 1080;

    /* Largeurs unifiées */
    --sidebar-width: 260px;
    --sidebar-width-mobile: 280px;

    /* Breakpoints (référence) */
    /* Mobile: < 640px */
    /* Tablet: 640px - 1023px */
    /* Desktop: >= 1024px */
}

/* ============================================================================
   SIDEBAR - DÉFINITION UNIQUE
   ============================================================================ */

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: linear-gradient(180deg, #2c3e50 0%, #1a252f 100%);
    color: white;
    display: flex;
    flex-direction: column;
    z-index: var(--z-sidebar);
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform 0.3s ease;
}

/* Mobile/Tablet: sidebar cachée */
@media (max-width: 1023px) {
    .sidebar {
        width: var(--sidebar-width-mobile);
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }
}

/* Desktop: sidebar visible */
@media (min-width: 1024px) {
    .sidebar {
        transform: translateX(0);
    }
}

/* ============================================================================
   MAIN CONTENT - DÉFINITION UNIQUE
   ============================================================================ */

.main-content {
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
    padding: 2rem;
}

/* Mobile/Tablet: pleine largeur */
@media (max-width: 1023px) {
    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 1rem;
    }
}

/* Desktop: décalé pour la sidebar */
@media (min-width: 1024px) {
    .main-content {
        margin-left: var(--sidebar-width);
        width: calc(100% - var(--sidebar-width));
    }
}

/* ============================================================================
   BOUTON MENU MOBILE - DÉFINITION UNIQUE
   ============================================================================ */

.mobile-menu-toggle {
    position: fixed;
    top: 1rem;
    left: 1rem;
    width: 48px;
    height: 48px;
    background: white;
    border: none;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    z-index: var(--z-mobile-menu);
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: #2c3e50;
    transition: all 0.2s ease;
}

.mobile-menu-toggle:hover {
    background: #f5f5f5;
    transform: scale(1.05);
}

.mobile-menu-toggle:active {
    transform: scale(0.95);
}

/* Visible uniquement sur mobile/tablet */
@media (max-width: 1023px) {
    .mobile-menu-toggle {
        display: flex;
    }
}

/* Caché sur desktop */
@media (min-width: 1024px) {
    .mobile-menu-toggle {
        display: none !important;
    }
}

/* ============================================================================
   SIDEBAR OVERLAY - DÉFINITION UNIQUE
   ============================================================================ */

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-sidebar-overlay);
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

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

/* ============================================================================
   HEADER/PAGE-HEADER - Z-INDEX COHÉRENT
   ============================================================================ */

.header,
.page-header-enhanced,
.top-navbar {
    z-index: var(--z-sticky);
}

/* ============================================================================
   MODALS - Z-INDEX COHÉRENT
   ============================================================================ */

.modal,
.modal-overlay {
    z-index: var(--z-modal-backdrop);
}

.modal-content,
.modal-overlay .modal {
    z-index: var(--z-modal);
}

/* Fix pour les modals dans sessions.php et autres pages */
.modal-overlay .modal {
    display: block !important;
    position: relative;
    inset: auto;
}

/* ============================================================================
   FAB MENU - Z-INDEX COHÉRENT
   ============================================================================ */

.fab-container {
    z-index: var(--z-fab);
}

/* ============================================================================
   STATS GRID - DÉFINITION UNIQUE
   ============================================================================ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

@media (max-width: 639px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 640px) and (max-width: 1023px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ============================================================================
   CONTENT WRAPPER - PADDING UNIFIÉ
   ============================================================================ */

.content-wrapper {
    padding: 2rem;
    flex: 1;
}

@media (max-width: 1023px) {
    .content-wrapper {
        padding: 1rem;
        padding-top: 5rem; /* Espace pour le bouton menu */
    }
}

@media (max-width: 639px) {
    .content-wrapper {
        padding: 0.75rem;
        padding-top: 5rem;
    }
}

/* ============================================================================
   DARK THEME - COMPLÉMENTS MANQUANTS
   ============================================================================ */

/* Mobile menu toggle */
[data-theme="dark"] .mobile-menu-toggle {
    background: var(--bg-card, #252932);
    color: var(--text-primary, #e4e6eb);
    border: 1px solid var(--border-color, #3e4451);
}

[data-theme="dark"] .mobile-menu-toggle:hover {
    background: var(--bg-hover, #2d323e);
}

/* FAB Menu */
[data-theme="dark"] .fab-container .fab-main {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

[data-theme="dark"] .fab-container .fab-item {
    background: var(--bg-card, #252932);
    color: var(--text-primary, #e4e6eb);
    border: 1px solid var(--border-color, #3e4451);
}

[data-theme="dark"] .fab-container .fab-item:hover {
    background: var(--bg-hover, #2d323e);
}

/* Search bar */
[data-theme="dark"] .search-bar,
[data-theme="dark"] .search-box input,
[data-theme="dark"] .search-input {
    background: var(--bg-tertiary, #2d323e);
    border-color: var(--border-color, #3e4451);
    color: var(--text-primary, #e4e6eb);
}

[data-theme="dark"] .search-bar::placeholder,
[data-theme="dark"] .search-box input::placeholder,
[data-theme="dark"] .search-input::placeholder {
    color: var(--text-muted, #8a8d91);
}

/* Responsive table */
[data-theme="dark"] .responsive-table {
    background: var(--bg-card, #252932);
}

[data-theme="dark"] .table-container {
    background: var(--bg-card, #252932);
    border: 1px solid var(--border-color, #3e4451);
}

/* Introjs (tutorial) */
[data-theme="dark"] .introjs-tooltip {
    background: var(--bg-card, #252932);
    color: var(--text-primary, #e4e6eb);
    border: 1px solid var(--border-color, #3e4451);
}

[data-theme="dark"] .introjs-arrow.top {
    border-bottom-color: var(--bg-card, #252932);
}

[data-theme="dark"] .introjs-helperLayer {
    background: rgba(255, 255, 255, 0.05);
}

/* ============================================================================
   SUPPRESSION DES !IMPORTANT INUTILES
   Utiliser des sélecteurs plus spécifiques au lieu de !important
   ============================================================================ */

/* Stats grid mobile - sélecteur plus spécifique */
@media (max-width: 639px) {
    body .stats-grid,
    .main-content .stats-grid,
    .content-wrapper .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* Main content mobile - sélecteur plus spécifique */
@media (max-width: 1023px) {
    body .main-content,
    .app-container .main-content {
        margin-left: 0;
        width: 100%;
    }
}

/* ============================================================================
   PRINT STYLES
   ============================================================================ */

@media print {
    .sidebar,
    .mobile-menu-toggle,
    .sidebar-overlay,
    .fab-container {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .content-wrapper {
        padding: 0 !important;
    }
}
