:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --bg-body: #f8fafc;
    --sidebar-bg: #ffffff;
    --sidebar-color: #64748b;
    --sidebar-active-bg: #f1f5f9;
    --sidebar-active-color: #4f46e5;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --radius-lg: 0.75rem;
    --radius-md: 0.5rem;
}

.text-main {
    color: var(--text-main) !important;
}

.text-muted {
    color: var(--text-muted) !important;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-main);
}

a {
    color: var(--primary-color);
}

a:hover {
    color: var(--primary-hover);
}

[data-theme="dark"] {
    --bg-body: #0b0f19;
    --sidebar-bg: #111827;
    --sidebar-color: #94a3b8;
    --sidebar-active-bg: #1f2937;
    --sidebar-active-color: #818cf8;
    --card-bg: #111827;
    --text-main: #f9fafb;
    --text-muted: #94a3b8;
    --border-color: #1f2937;
}

.theme-switcher {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-main);
    transition: all 0.2s ease;
}

.theme-switcher:hover {
    background: var(--sidebar-active-bg);
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    overflow-x: hidden;
    transition: background-color 0.3s ease;
}

/* Sidebar */
.sidebar {
    width: 260px;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

/* Collapsed Sidebar */
.sidebar.collapsed {
    width: 80px;
}

.sidebar.collapsed .sidebar-header h5,
.sidebar.collapsed .sidebar-user div,
.sidebar.collapsed .menu-label,
.sidebar.collapsed .menu-link span,
.sidebar.collapsed .ms-auto {
    display: none !important;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 1.5rem 0.5rem;
}

.sidebar.collapsed .menu-link {
    justify-content: center;
    padding: 0.75rem;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 2rem;
}

/* Sidebar Custom Scrollbar */
.sidebar-content::-webkit-scrollbar {
    width: 4px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
}

[data-theme="dark"] .sidebar-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.05);
}

.sidebar-user {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-user img {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: 2px solid var(--primary-color);
    padding: 2px;
}

.user-status {
    font-size: 0.7rem;
    color: #22c55e;
    display: flex;
    align-items: center;
    gap: 4px;
}

.user-status::before {
    content: '';
    width: 6px;
    height: 6px;
    background: #22c55e;
    border-radius: 50%;
    display: inline-block;
}

.sidebar-header {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
    width: 32px;
    height: 32px;
    background: var(--primary-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
}

.sidebar-menu {
    padding: 1rem;
    list-style: none;
    margin: 0;
}

.menu-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    padding-left: 0.75rem;
}

.menu-item {
    margin-bottom: 0.25rem;
}

.menu-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    color: var(--sidebar-color);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
    cursor: pointer;
    user-select: none;
}

.menu-link:hover {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-color);
}

.menu-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-color);
    font-weight: 500;
}

.menu-link[data-bs-toggle="collapse"]::after {
    display: none;
}

/* Submenu Chevron Rotation */
.menu-link[data-bs-toggle="collapse"] i:last-child {
    transition: transform 0.3s ease;
}

.menu-link:not(.collapsed) i:last-child {
    transform: rotate(90deg);
}

/* CSS-only Collapse Logic */
.collapse:not(.show) {
    display: none !important;
}

.collapse.show {
    display: block !important;
}

.dropdown-menu {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
}

.dropdown-item {
    color: var(--text-main);
}

.dropdown-item:hover {
    background-color: var(--sidebar-active-bg);
    color: var(--text-main);
}

.table {
    color: var(--text-main);
}

.table thead th {
    background-color: var(--sidebar-active-bg);
    color: var(--text-muted);
    border-color: var(--border-color);
}

.table td {
    border-color: var(--border-color);
}

.list-group-item {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    color: var(--text-main);
}

.modal-content {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    color: var(--text-main);
}

.modal-header,
.modal-footer {
    border-color: var(--border-color);
}

.card-header,
.card-footer {
    background-color: rgba(0, 0, 0, 0.02);
    border-color: var(--border-color);
}

[data-theme="dark"] .card-header,
[data-theme="dark"] .card-footer {
    background-color: rgba(255, 255, 255, 0.02);
}

.collapsing {
    height: 0;
    overflow: hidden;
    transition: height 0.35s ease;
}

/* Main Content */
.main-content {
    margin-left: 260px;
    min-height: 100vh;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.main-content.expanded {
    margin-left: 80px;
}

/* Top Navbar */
.top-navbar {
    height: 70px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 999;
}

.search-bar {
    position: relative;
    max-width: 400px;
    width: 100%;
}

.search-bar input {
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.5rem 1rem 0.5rem 2.5rem;
    width: 100%;
    color: var(--text-main);
}

.search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

/* Dashboard Cards */
.stats-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.stats-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0) 100%);
    border-radius: 0 0 0 100%;
}

.stats-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
}

.bg-primary {
    background-color: var(--primary-color) !important;
}

.btn-white {
    background-color: var(--card-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-white:hover {
    background-color: var(--sidebar-active-bg);
    color: var(--text-main);
}

/* Glassmorphism utility */
.glass {
    background: rgba(255, 255, 255, 0.7) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
}

[data-theme="dark"] .glass {
    background: rgba(17, 24, 39, 0.7) !important;
    border: 1px solid rgba(255, 255, 255, 0.05) !important;
}

.stats-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
}

.icon-blue {
    background: rgba(79, 70, 229, 0.1);
    color: #4f46e5;
}

.icon-green {
    background: rgba(34, 197, 94, 0.1);
    color: #22c55e;
}

.icon-orange {
    background: rgba(249, 115, 22, 0.1);
    color: #f97316;
}

.icon-purple {
    background: rgba(168, 85, 247, 0.1);
    color: #a855f7;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: fadeIn 0.5s ease forwards;
}

.auth-logo {
    width: 48px;
    height: 48px;
    background: var(--primary-color);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
    margin: 0 auto 1.5rem;
}

.error-code {
    font-size: 8rem;
    font-weight: 900;
    color: var(--primary-color);
    line-height: 1;
    margin-bottom: 1rem;
    opacity: 0.2;
}

/* Form Controls Dark Mode */
.form-control,
.form-select {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    color: var(--text-main);
}

.form-control:focus,
.form-select:focus {
    background-color: var(--card-bg);
    border-color: var(--primary-color);
    color: var(--text-main);
    box-shadow: 0 0 0 0.25rem rgba(79, 70, 229, 0.1);
}

.form-control::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

.form-label {
    color: var(--text-main);
}

.form-check-label {
    color: var(--text-muted);
}

/* Auth & Error Pages Wrapper Support */
.auth-wrapper {
    min-height: calc(100vh - 70px);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-body);
}

.auth-card {
    max-width: 450px;
    width: 100%;
    background: var(--card-bg);
    border-radius: 1.5rem;
    box-shadow: var(--shadow-md);
    padding: 2.5rem;
    border: 1px solid var(--border-color);
}

.error-wrapper {
    min-height: calc(100vh - 70px);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-body);
    text-align: center;
    padding: 2rem;
}

[data-theme="dark"] .auth-wrapper,
[data-theme="dark"] .error-wrapper {
    background: var(--bg-body);
}

/* Badge Fixes */
.badge.bg-success-subtle {
    background-color: rgba(34, 197, 94, 0.15) !important;
    color: #22c55e !important;
}

.badge.bg-danger-subtle {
    background-color: rgba(239, 68, 68, 0.15) !important;
    color: #ef4444 !important;
}

.badge.bg-warning-subtle {
    background-color: rgba(245, 158, 11, 0.15) !important;
    color: #f59e0b !important;
}

.badge.bg-info-subtle {
    background-color: rgba(6, 182, 212, 0.15) !important;
    color: #06b6d4 !important;
}

/* Mobile Responsive Adjustments */
@media (max-width: 991.98px) {
    .sidebar {
        left: -260px;
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    }

    .sidebar.active {
        left: 0;
    }

    .main-content {
        margin-left: 0 !important;
    }

    .top-navbar {
        padding: 0 1rem;
    }

    .search-bar {
        display: none !important;
        /* Hide search on mobile header to save space */
    }

    /* Mobile Overlay */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.show {
        display: block;
        opacity: 1;
    }

    /* Stats Card Grid */
    .p-4 {
        padding: 1.5rem !important;
    }

    .stats-card {
        padding: 1.25rem;
    }

    h3 {
        font-size: 1.5rem;
    }
}

@media (max-width: 575.98px) {
    .top-navbar {
        height: 60px;
    }

    .auth-card {
        padding: 1.5rem;
        margin: 1rem;
    }

    .error-code {
        font-size: 5rem;
    }
}