:root {
    --primary: #0f172a;
    --primary-accent: #2563eb;
    --primary-hover: #1e293b;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --dark: #1e293b;
    --light: #f8fafc;
    --body-bg: #f3f4f6;
    --card-bg: #ffffff;
    --text-color: #334155;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --sidebar-width: 260px;
    --header-height: 64px;
    --radius: 0.5rem;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

body.dark-mode {
    --body-bg: #0f172a;
    --card-bg: #1e293b;
    --text-color: #e2e8f0;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --light: #1e293b;
    --dark: #f8fafc;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--body-bg);
    color: var(--text-color);
    font-size: 0.95rem;
    line-height: 1.5;
    /* PWA Safe Area Support */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

a {
    text-decoration: none;
    color: var(--primary);
}

a:hover {
    text-decoration: underline;
}

/* Layout */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 50;
    /* Higher z-index for mobile overlay */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Mobile Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 2rem;
    width: calc(100% - var(--sidebar-width));
}

.top-bar {
    height: var(--header-height);
    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: 9;
}

/* Components */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-weight: 500;
    cursor: pointer;
    transition: 0.2s;
    border: none;
    font-size: 0.875rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    text-decoration: none;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-secondary {
    background: var(--light);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
    text-decoration: none;
}

.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 0.625rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--card-bg);
    color: var(--text-color);
    font-size: 0.875rem;
    transition: all 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Utilities */
.text-right {
    text-align: right;
}

.flex {
    display: flex;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-4 {
    gap: 1rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.text-danger {
    color: var(--danger);
}

.text-success {
    color: var(--success);
}

.bg-white {
    background: white;
}

/* Responsive */
.mobile-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    margin-right: 1rem;
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 1rem;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .mobile-toggle {
        display: block;
    }

    /* Hide user name on mobile */
    .header-right span {
        display: none;
    }

    /* Make sidebar active state slide in */
    .sidebar.active {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.1);
    }
}

/* Sidebar Menu */
.sidebar-brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    font-weight: bold;
    font-size: 1.25rem;
    color: var(--primary);
    border-bottom: 1px solid var(--border-color);
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: var(--text-color);
    transition: 0.2s;
    gap: 0.75rem;
}

.nav-link:hover,
.nav-link.active {
    background: var(--light);
    color: var(--primary);
}

.nav-icon {
    width: 1.25rem;
    height: 1.25rem;
}

/* Auth Layout */
.auth-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--body-bg);
}


/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    border-radius: 9999px;
    white-space: nowrap;
}

.badge-secondary {
    background-color: var(--light);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.badge-success {
    background-color: #ecfdf5;
    color: #059669;
    border: 1px solid #a7f3d0;
}

.badge-warning {
    background-color: #fffbeb;
    color: #d97706;
    border: 1px solid #fde68a;
}

.badge-danger,
.badge-error {
    background-color: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

/* Button Variants */
.btn-outline-secondary {
    background: transparent;
    color: var(--secondary);
    border: 1px solid var(--border-color);
}

.btn-outline-secondary:hover {
    background: var(--light);
    color: var(--text-color);
    border-color: var(--secondary);
}

.btn-outline-warning {
    background: transparent;
    color: var(--warning);
    border: 1px solid var(--warning);
}

.btn-outline-warning:hover {
    background: var(--warning);
    color: white;
}

.btn-sm {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
}

.btn-xs {
    padding: 0.2rem 0.5rem;
    font-size: 0.7rem;
}

/* Utilities */
.no-scrollbar::-webkit-scrollbar {
    display: none;
}

.no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.custom-scrollbar::-webkit-scrollbar {
    width: 4px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 2px;
}


/* Sidebar Brand & Nav (Moved from inline) */
.sidebar-brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    font-weight: bold;
    font-size: 1.25rem;
    color: var(--primary);
    border-bottom: 1px solid var(--border-color);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 0;
}

.sidebar-nav ul {
    list-style: none;
    padding: 0;
    margin: 0 0 1.5rem 0;
}

.nav-section {
    padding: 2rem 1rem 0.75rem 1.5rem;
    font-size: 0.65rem;
    font-weight: 800;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.5rem;
    color: var(--text-color);
    font-weight: 500;
    transition: all 0.2s;
    border-radius: 12px;
    margin: 0 1rem 4px 1rem;
}

.nav-link:hover {
    transform: translateX(4px);
    background: rgba(37, 99, 235, 0.04);
    color: var(--primary-accent);
    text-decoration: none;
}

.nav-link.active {
    background: #f1f5f9;
    color: #0f172a;
    font-weight: 600;
}

.nav-icon {
    width: 20px;
    height: 20px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.nav-link.active .nav-icon {
    opacity: 1;
    color: var(--primary-accent);
}

.sidebar-brand-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 900;
    font-size: 20px;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
    transition: transform 0.3s ease;
}

.sidebar-footer {
    padding: 1.5rem 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: white;
}

.user-avatar-premium {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #0f172a;
    border: 1px solid #e2e8f0;
}

.user-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.btn-logout {
    color: var(--text-muted);
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.2s;
}

.btn-logout:hover {
    background: #fee2e2;
    color: #ef4444;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Mobile Sidebar Close Button */
.mobile-sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    margin-left: auto;
}

@media (max-width: 768px) {
    .mobile-sidebar-close {
        display: block;
    }

    .sidebar-brand {
        justify-content: space-between;
    }
}

/* Utilities for Icons */
.w-5 {
    width: 1.25rem;
}

.h-5 {
    height: 1.25rem;
}

.w-6 {
    width: 1.5rem;
}

.h-6 {
    height: 1.5rem;
}

.item-icon {
    width: 18px;
    height: 18px;
    opacity: 0.7;
    flex-shrink: 0;
}

.dropdown-item svg {
    flex-shrink: 0;
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}