:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #e0e7ff;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;

    /* Light theme */
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --bg-sidebar: #1e1b4b;
    --bg-input: #ffffff;
    --border: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.04);
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-width: 260px;
    --header-height: 64px;
}

[data-theme="dark"] {
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --bg-sidebar: #0f0d2b;
    --bg-input: #334155;
    --border: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --shadow: 0 1px 3px rgba(0,0,0,.3);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.4);
    --primary-light: #312e81;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background .3s, color .3s;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* Layout */
.app-layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    display: flex; flex-direction: column;
    z-index: 100;
    transition: width .3s, transform .3s;
    overflow: hidden;
}

.sidebar-brand {
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex; align-items: center; gap: 12px;
    position: relative;
}

.sidebar-brand h1 {
    font-size: 18px; font-weight: 700;
    color: #fff; white-space: nowrap;
    flex: 1; overflow: hidden;
}

.sidebar-brand .logo {
    width: 36px; height: 36px;
    background: var(--primary);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; color: #fff; font-size: 14px;
}

.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }

.nav-section { margin-bottom: 24px; }
.nav-section-title {
    font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .05em;
    color: rgba(255,255,255,.4);
    padding: 0 12px; margin-bottom: 8px;
}

.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    color: rgba(255,255,255,.7);
    font-size: 14px; font-weight: 500;
    transition: all .2s; cursor: pointer;
    margin-bottom: 2px;
}

.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }

.nav-item .icon { width: 20px; height: 20px; opacity: .8; }
.nav-item .badge {
    margin-left: auto;
    background: var(--danger);
    color: #fff; font-size: 11px;
    padding: 2px 7px; border-radius: 10px;
}

/* Main content */
.main-content {
    flex: 1; margin-left: var(--sidebar-width);
    display: flex; flex-direction: column;
    transition: margin-left .3s;
}

/* Header */
.header {
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 32px; gap: 16px;
    position: sticky; top: 0; z-index: 50;
    box-shadow: var(--shadow);
}

.header-left { display: flex; align-items: center; gap: 16px; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 16px; }

.btn-menu {
    display: none; background: none; border: none;
    color: var(--text-primary); cursor: pointer; font-size: 20px;
}

.search-box {
    position: relative; width: 300px;
}
.search-box input {
    width: 100%; padding: 8px 12px 8px 36px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg-input); color: var(--text-primary);
    font-size: 14px; transition: border .2s;
}
.search-box input:focus { outline: none; border-color: var(--primary); }
.search-box .search-icon {
    position: absolute; left: 10px; top: 50%;
    transform: translateY(-50%); color: var(--text-muted);
}

/* Theme toggle */
.theme-toggle {
    width: 40px; height: 40px;
    border-radius: 50%; border: 1px solid var(--border);
    background: var(--bg-input); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary); font-size: 18px;
    transition: all .2s;
}
.theme-toggle:hover { border-color: var(--primary); color: var(--primary); }

.user-avatar {
    width: 36px; height: 36px;
    border-radius: 50%; background: var(--primary);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 600; font-size: 14px;
}

/* Page content */
.page-content { padding: 32px; flex: 1; }

.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 28px; flex-wrap: wrap; gap: 16px;
}
.page-title { font-size: 24px; font-weight: 700; }
.page-subtitle { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: box-shadow .2s, transform .2s;
}
.card:hover { box-shadow: var(--shadow-lg); }
.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { font-size: 16px; font-weight: 600; }
.card-body { padding: 24px; }

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px; margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    display: flex; align-items: flex-start; gap: 16px;
    box-shadow: var(--shadow);
    transition: all .2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.stat-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
}
.stat-icon.purple { background: #ede9fe; color: #7c3aed; }
.stat-icon.green { background: #d1fae5; color: #059669; }
.stat-icon.blue { background: #dbeafe; color: #2563eb; }
.stat-icon.orange { background: #fef3c7; color: #d97706; }

[data-theme="dark"] .stat-icon.purple { background: #2e1065; }
[data-theme="dark"] .stat-icon.green { background: #064e3b; }
[data-theme="dark"] .stat-icon.blue { background: #1e3a5f; }
[data-theme="dark"] .stat-icon.orange { background: #451a03; }

.stat-info h4 { font-size: 28px; font-weight: 700; line-height: 1.2; }
.stat-info p { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 20px; border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 500;
    border: none; cursor: pointer;
    transition: all .2s; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; transform: translateY(-1px); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: .9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-outline {
    background: transparent; border: 1px solid var(--border);
    color: var(--text-primary);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 28px; font-size: 16px; }

/* Tables */
.table-wrapper { overflow-x: auto; }
table {
    width: 100%; border-collapse: collapse;
    font-size: 14px;
}
thead th {
    padding: 12px 16px; text-align: left;
    font-weight: 600; font-size: 12px;
    text-transform: uppercase; letter-spacing: .03em;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
tbody td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
tbody tr { transition: background .15s; }
tbody tr:hover { background: var(--primary-light); }

/* Badges */
.badge {
    display: inline-flex; align-items: center;
    padding: 4px 10px; border-radius: 20px;
    font-size: 12px; font-weight: 500;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-danger { background: #fee2e2; color: #991b1b; }

[data-theme="dark"] .badge-success { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .badge-warning { background: #451a03; color: #fcd34d; }
[data-theme="dark"] .badge-info { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .badge-danger { background: #450a0a; color: #fca5a5; }

/* Forms */
.form-group { margin-bottom: 20px; }
.form-group label {
    display: block; font-size: 13px;
    font-weight: 500; margin-bottom: 6px;
    color: var(--text-secondary);
}
.form-control {
    width: 100%; padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 14px; transition: border .2s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.1); }

.password-wrapper {
    position: relative;
}
.password-wrapper input { padding-right: 42px; }
.password-toggle {
    position: absolute; right: 12px; top: 50%;
    transform: translateY(-50%);
    background: none; border: none;
    cursor: pointer; font-size: 18px;
    color: var(--text-muted);
    transition: color .2s;
}
.password-toggle:hover { color: var(--primary); }

select.form-control { appearance: none; cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 100px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Alerts */
.alert {
    padding: 14px 20px; border-radius: var(--radius-sm);
    font-size: 14px; margin-bottom: 20px;
    display: flex; align-items: center; gap: 10px;
}
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

[data-theme="dark"] .alert-success { background: #064e3b; color: #6ee7b7; border-color: #065f46; }
[data-theme="dark"] .alert-error { background: #450a0a; color: #fca5a5; border-color: #991b1b; }

/* Modal */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5); backdrop-filter: blur(4px);
    display: none; align-items: center; justify-content: center;
    z-index: 1000;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    width: 90%; max-width: 560px;
    box-shadow: var(--shadow-lg);
    animation: modalIn .2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } }
.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 18px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 12px; justify-content: flex-end; }

/* Empty state */
.empty-state {
    text-align: center; padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; color: var(--text-primary); margin-bottom: 8px; }

/* Sidebar collapse */
.sidebar-collapse-btn {
    background: rgba(255,255,255,.08); border: none; color: rgba(255,255,255,.7);
    width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
    font-size: 12px; transition: all .2s; margin-left: auto; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}
.sidebar-collapse-btn:hover { background: rgba(255,255,255,.15); color: #fff; }

.sidebar.collapsed { width: 72px; }
.sidebar.collapsed .sidebar-brand h1 { display: none; }
.sidebar.collapsed .sidebar-brand { justify-content: center; padding: 20px 0; gap: 0; }
.sidebar.collapsed .sidebar-collapse-btn { position: absolute; top: 24px; right: 8px; margin: 0; transform: rotate(180deg); width: 22px; height: 22px; font-size: 10px; }
.sidebar.collapsed .nav-section-title { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px 0; font-size: 0; gap: 0; }
.sidebar.collapsed .nav-item .icon { font-size: 18px; margin: 0; }
.sidebar.collapsed .sidebar-nav { padding: 16px 8px; }
.sidebar.collapsed ~ .main-content { margin-left: 72px; }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .btn-menu { display: block; }
    .page-content { padding: 20px 16px; }
    .stats-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .search-box { width: 100%; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Animations */
.fade-in { animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Login page */
.login-page {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #4338ca 100%);
}
.login-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 48px 40px;
    width: 100%; max-width: 420px;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,.25);
}
.login-card h2 { font-size: 24px; font-weight: 700; margin-bottom: 8px; text-align: center; }
.login-card p { color: var(--text-secondary); text-align: center; margin-bottom: 32px; font-size: 14px; }
.login-card .btn { width: 100%; justify-content: center; padding: 12px; }
