:root {
    --bg-main: #f0f2f5;
    --bg-card: #ffffff;
    --text-main: #111827;
    --text-muted: #6b7280;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --sidebar-bg: #111827;
    --sidebar-bg-2: #0b1120;
    --sidebar-width: 304px;
    --sidebar-collapsed-width: 76px;
    --sidebar-text: #f3f4f6;
    --sidebar-hover: rgba(255, 255, 255, 0.08);
    --border: #e5e7eb;
    --border-light: #f3f4f6;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    --glass-bg: rgba(255, 255, 255, 0.75);
    --glass-border: rgba(255, 255, 255, 0.4);

    /* Status Colors */
    --danger-bg: #fef2f2;
    --danger-text: #ef4444;
    --success-bg: #f0fdf4;
    --success-text: #22c55e;
    --warning-bg: #fffbeb;
    --warning-text: #f59e0b;
    --info-bg: #eff6ff;
    --info-text: #3b82f6;
}

[data-theme="dark"] {
    --bg-main: #0B0E14;
    --bg-card: #151A23;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --sidebar-bg: #0D111A;
    --sidebar-bg-2: #0A0D14;
    --sidebar-text: #e2e8f0;
    --sidebar-hover: rgba(255, 255, 255, 0.05);
    --border: #262D3D;
    --border-light: #1A202C;
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
    --glass-bg: rgba(21, 26, 35, 0.7);
    --glass-border: rgba(255, 255, 255, 0.05);

    /* Status Colors */
    --danger-bg: rgba(239, 68, 68, 0.15);
    --danger-text: #fca5a5;
    --success-bg: rgba(34, 197, 94, 0.15);
    --success-text: #86efac;
    --warning-bg: rgba(245, 158, 11, 0.15);
    --warning-text: #fcd34d;
    --info-bg: rgba(59, 130, 246, 0.15);
    --info-text: #93c5fd;
}

/* Prevent transition flash on page load */
.preload,
.preload * {
    transition: none !important;
}

/* Base Resets */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

select {
    color: var(--text-main);
    background-color: var(--bg-card);
}

select option {
    background-color: var(--bg-card) !important;
    color: var(--text-main) !important;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
    font-size: 15px;
    line-height: 1.5;
}

a {
    text-decoration: none;
    color: inherit;
}

/* Glassmorphism utility */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
}

/* ════════════════════════════════════════════════
   SIDEBAR — new premium collapsible design
════════════════════════════════════════════════ */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
    color: var(--sidebar-text);
    position: fixed;
    height: 100vh;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255,255,255,0.06);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 28px rgba(0,0,0,0.22);
}

/* Collapsed state */
.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* Scrollable nav area — kept separate from .sidebar so the collapse
   button (which intentionally overflows the header's edge) never gets
   clipped by this container's own overflow-x: hidden */
.sidebar-scroll {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

/* Sidebar Branding */
.sidebar-header {
    padding: 22px 18px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
    min-height: 78px;
    position: relative;
}

.sidebar-logo {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.sidebar.collapsed .sidebar-logo {
    width: 40px !important;
    height: 40px !important;
}

.sidebar.collapsed .sidebar-logo img {
    max-width: 40px !important;
}

.sidebar-brand-text {
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    opacity: 1;
    transition: opacity 0.2s, width 0.3s;
    letter-spacing: -0.3px;
}

.sidebar.collapsed .sidebar-brand-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

.brand-icon {
    font-size: 23px;
    color: var(--primary);
    background: rgba(99, 102, 241, 0.15);
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Collapse toggle button */
.sidebar-collapse-btn {
    position: absolute;
    right: -14px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #232b3d;
    border: 1px solid rgba(255,255,255,0.22);
    color: rgba(255,255,255,0.85);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    transition: all 0.2s;
    z-index: 10;
    box-shadow: 0 2px 10px rgba(0,0,0,0.45), 0 0 0 4px var(--sidebar-bg);
}

.sidebar-collapse-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    transform: translateY(-50%) scale(1.08);
}

.sidebar.collapsed .sidebar-collapse-btn i {
    transform: rotate(180deg);
}

/* User profile block */
.user-profile-sidebar {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 14px 12px;
    border-radius: 14px;
    background: rgba(255,255,255,0.045);
    border: 1px solid rgba(255,255,255,0.07);
    transition: background 0.2s, border-color 0.2s;
    flex-shrink: 0;
    min-height: 60px;
    overflow: hidden;
}

.user-profile-sidebar:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.12);
}

.sidebar.collapsed .user-profile-sidebar {
    padding: 10px;
    margin: 14px 10px;
    justify-content: center;
}

.sidebar.collapsed .sidebar-text-fade {
    display: none;
}

.user-role-badge {
    display: inline-block;
    margin-top: 3px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    padding: 1px 7px;
    border-radius: 20px;
    background: rgba(99, 102, 241, 0.16);
    color: #a5b4fc;
}

/* Navigation Menu */
.menu-section {
    padding: 10px 0 4px;
}

.menu-label {
    padding: 10px 18px 6px;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(255, 255, 255, 0.32);
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.2s;
}

.sidebar.collapsed .menu-label {
    opacity: 0;
    height: 0;
    padding: 0;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 11px 16px;
    margin: 2px 10px;
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.58);
    transition: all 0.15s ease;
    font-weight: 500;
    gap: 12px;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    position: relative;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
}

.menu-item.active {
    background: rgba(99, 102, 241, 0.16);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.25);
}

.menu-item.active i {
    color: #a5b4fc;
}

.menu-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 22%;
    bottom: 22%;
    width: 3px;
    background: var(--primary);
    border-radius: 0 3px 3px 0;
    margin-left: -10px;
}

.menu-item i {
    font-size: 18.5px;
    width: 22px;
    display: flex;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s, color 0.15s;
}

.menu-item:hover i {
    transform: translateX(1px);
}

/* Department menu items — colored dot */
.dep-menu-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-right: 2px;
    box-shadow: 0 0 0 3px rgba(255,255,255,0.05);
}

/* Hide text when collapsed */
.sidebar.collapsed .menu-item span,
.sidebar.collapsed .menu-item .dep-badge { display: none; }

/* Department dot stays visible when collapsed — it's the only
   visual identifier for that item since departments have no icon.
   Must re-declare display: the generic "span" rule above sets
   display: none and this needs to win it back. */
.sidebar.collapsed .menu-item .dep-menu-dot {
    display: block;
    width: 10px;
    height: 10px;
    margin-right: 0;
}

.sidebar.collapsed .menu-item {
    justify-content: center;
    padding: 11px;
    margin: 2px 10px;
}

.sidebar.collapsed .menu-item i {
    width: auto;
}

/* Tooltip for collapsed state */
.sidebar.collapsed .menu-item {
    position: relative;
}

.sidebar.collapsed .menu-item::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background: #1e293b;
    color: #f1f5f9;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.08);
}

.sidebar.collapsed .menu-item:hover::after {
    opacity: 1;
}

/* Dep badge */
.dep-badge {
    margin-left: auto;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

/* Context actions (footer) */
.sidebar-footer {
    margin-top: auto;
    padding: 14px 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

.theme-toggle,
.logout {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-radius: 10px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    width: 100%;
    background: transparent;
    text-align: left;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
}

.theme-toggle {
    color: var(--sidebar-text);
    margin-bottom: 4px;
}

.theme-toggle:hover {
    background: var(--sidebar-hover);
}

.logout {
    color: #f87171;
}

.logout:hover {
    background: rgba(239, 68, 68, 0.1);
}

.logout i,
.theme-toggle i {
    font-size: 18px;
    width: 22px;
    flex-shrink: 0;
}

.sidebar.collapsed .theme-toggle span,
.sidebar.collapsed .logout span {
    display: none;
}

.sidebar.collapsed .theme-toggle,
.sidebar.collapsed .logout {
    justify-content: center;
    padding: 10px;
}

/* ════════════════════════════════════════════════
   Department switcher (page header dropdown)
════════════════════════════════════════════════ */
.dept-switcher {
    position: relative;
    display: block;
    width: fit-content;
}

.dept-switcher {
    margin-bottom: 10px;
}

.dept-switcher-btn {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 5px 12px 5px 10px;
    margin: 0;
    cursor: default;
    font-family: inherit;
    transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}

.dept-switcher-btn i:first-child {
    font-size: 13px;
    color: var(--primary);
    flex-shrink: 0;
}

.dept-switcher-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dept-switcher-btn.clickable {
    cursor: pointer;
}

.dept-switcher-btn.clickable:hover {
    color: var(--text-main);
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.06);
}

.dept-switcher-caret {
    font-size: 10px;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.dept-switcher.open .dept-switcher-caret {
    transform: rotate(180deg);
}

.dept-switcher-menu {
    display: none;
    position: absolute;
    left: 0;
    top: calc(100% + 6px);
    min-width: 240px;
    max-height: 320px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 6px;
    z-index: 500;
}

.dept-switcher.open .dept-switcher-menu {
    display: block;
}

.dept-switcher-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-main);
    transition: background 0.15s;
}

.dept-switcher-item:hover {
    background: var(--sidebar-hover, rgba(99, 102, 241, 0.08));
}

.dept-switcher-item.active {
    color: var(--primary);
    font-weight: 600;
}

.dept-switcher-item i {
    font-size: 14px;
    color: var(--primary);
}

/* Filter-bar variant — same pill dropdown, but sitting inline in a row
   of controls rather than under a page title, so it doesn't need the
   header spacing margin. */
.dept-switcher.filter-dropdown {
    margin-bottom: 0;
}

.filter-chip.active-danger {
    color: #fff;
    border-color: #ef4444;
    background: #ef4444;
}

.filter-chip.active-danger i:first-child {
    color: #fff;
}

.filter-chip.active-danger:hover {
    color: #fff;
    border-color: #dc2626;
    background: #dc2626;
}

.dept-switcher-btn.filter-active {
    color: var(--primary);
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.08);
}

/* Main content wrapper */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 36px 40px;
    min-height: 100vh;
    min-width: 0;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.page-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.5px;
}

/* Mobile Nav Toggle */
.mobile-nav-toggle {
    display: none;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Responsive constraints */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
    }

    .sidebar.open,
    .sidebar.active {
        transform: translateX(0);
        box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.5);
    }

    .main-content {
        margin-left: 0 !important;
        padding: 24px;
    }

    .mobile-nav-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .content-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }
}