/* =========================================
   1. VARIABLES & THEME ENGINE
   ========================================= */
:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #6366f1;
    
    /* Light Mode Colors */
    --bg-main: #f8fafc;
    --bg-sidebar: #1e293b;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --nav-hover: rgba(255, 255, 255, 0.05);
}

body.dark-mode {
    --bg-main: #0f172a;
    --bg-sidebar: #020617;
    --bg-card: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --nav-hover: rgba(255, 255, 255, 0.1);
}

/* =========================================
   2. BASE STYLES
   ========================================= */
* { box-sizing: border-box; }

body { 
    font-family: 'Inter', -apple-system, sans-serif; 
    background-color: var(--bg-main); 
    color: var(--text-main);
    margin: 0; 
    transition: background 0.3s, color 0.3s;
    overflow-x: hidden;
}

/* =========================================
   3. LAYOUT STRUCTURE (Desktop)
   ========================================= */
.wrapper { 
    display: flex; 
    min-height: 100vh; 
}

#sidebar { 
    width: 260px; 
    min-width: 260px;
    background: var(--bg-sidebar); 
    color: white; 
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

#content { 
    flex: 1; 
    padding: 2rem; 
    max-width: 100%;
    transition: all 0.3s;
}

/* =========================================
   4. SIDEBAR COMPONENTS
   ========================================= */
.brand-section { 
    padding: 30px 20px; 
    text-align: center; 
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-logo { 
    width: 60px; height: 60px; 
    border-radius: 50%; 
    border: 2px solid var(--primary); 
    margin-bottom: 10px;
}

.nav-list { list-style: none; padding: 0; margin: 20px 0; }
.nav-list li a { 
    padding: 12px 24px; 
    display: flex; 
    align-items: center; 
    gap: 12px;
    color: #cbd5e1; 
    text-decoration: none; 
    font-size: 14px; 
    transition: 0.2s; 
}

.nav-list li a:hover { background: var(--nav-hover); color: white; }
.nav-divider { border: 0; border-top: 1px solid rgba(255,255,255,0.1); margin: 15px 0; }

.theme-btn {
    width: calc(100% - 40px); margin: 10px 20px; 
    padding: 10px; border-radius: 8px; 
    background: rgba(0,0,0,0.2); color: white; border: 1px solid rgba(255,255,255,0.1);
    cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px;
}

/* =========================================
   5. DASHBOARD CARDS & GRIDS
   ========================================= */
.stats-grid { 
    display: grid; 
    grid-template-columns: repeat(3, 1fr); 
    gap: 20px; 
    margin-bottom: 30px; 
}

.stat-card { 
    background: var(--bg-card); 
    padding: 1.5rem; 
    border-radius: 12px; 
    border-top: 4px solid var(--primary);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}

.stat-card.warning { border-top-color: var(--warning); }
.stat-card.info { border-top-color: var(--info); }

.card { 
    background: var(--bg-card); 
    border-radius: 12px; 
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 25px;
    overflow: hidden;
}

.dashboard-main-grid { 
    display: grid; 
    grid-template-columns: 1fr 2fr; 
    gap: 25px; 
}

/* =========================================
   6. TABLES
   ========================================= */
.table-responsive { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { 
    background: var(--bg-main); padding: 12px 15px; 
    text-align: left; font-size: 12px; text-transform: uppercase; color: var(--text-muted); 
}
td { padding: 15px; border-bottom: 1px solid var(--border-color); font-size: 14px; }

/* =========================================
   7. MOBILE OVERRIDES (THE FIX)
   ========================================= */
.mobile-nav-header {
    display: none; /* Hidden on Desktop */
    background: var(--bg-sidebar);
    padding: 15px 20px;
    color: white;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1100;
}

#sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
    z-index: 1050;
}

@media (max-width: 991px) {
    .mobile-nav-header { display: flex; }
    .wrapper { display: block; }

    #sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        transform: translateX(-100%); /* Completely off-screen */
        z-index: 1200;
        box-shadow: none;
    }

    #sidebar.mobile-active {
        transform: translateX(0); /* Slide in */
        box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    }

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

    #content { 
        padding: 15px; 
        width: 100% !important; 
    }

    .stats-grid, .dashboard-main-grid {
        display: flex;
        flex-direction: column;
        gap: 15px;
    }

    table { min-width: 700px; } /* Prevent table squashing */
}

/* =========================================
   8. UTILITIES
   ========================================= */
.btn { 
    background: var(--primary); color: white; border: none; 
    padding: 10px 20px; border-radius: 6px; cursor: pointer; font-weight: 600;
}
.badge { padding: 4px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; }
.logout-link { color: #f87171 !important; }