:root {
    --bg: #f1f5f9;
    --panel: #ffffff;
    --text: #0f172a;
    --text-light: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-dark: #cbd5e1;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --input-bg: #f8fafc;
    --item-hover: #f1f5f9;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);

    --sidebar-bg: #1e293b;
    --sidebar-bg-hover: #334155;
    --sidebar-text: #cbd5e1;
    --sidebar-text-active: #ffffff;
    --sidebar-border: #334155;
    --sidebar-w: 260px;
    --sidebar-collapsed: 68px;
    --topbar-h: 56px;

    --radius: 8px;
    --radius-lg: 12px;
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --bg: #0b1120;
    --panel: #1e293b;
    --text: #f1f5f9;
    --text-light: #94a3b8;
    --text-muted: #64748b;
    --border: #334155;
    --border-dark: #475569;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #1e3a5f;
    --success: #22c55e;
    --success-light: #14532d;
    --danger: #ef4444;
    --danger-light: #7f1d1d;
    --warning: #f59e0b;
    --warning-light: #78350f;
    --input-bg: #0f172a;
    --item-hover: #334155;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.5);

    --sidebar-bg: #0f172a;
    --sidebar-bg-hover: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #ffffff;
    --sidebar-border: #1e293b;
}

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

html, body { height: 100%; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    transition: background var(--transition), color var(--transition);
    -webkit-font-smoothing: antialiased;
}

svg { vertical-align: middle; flex-shrink: 0; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

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

.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 500;
    transition: width var(--transition), transform var(--transition);
    overflow: hidden;
}
.sidebar .sidebar-header { padding: 18px 20px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--sidebar-border); }
.sidebar .sidebar-header .logo { width: 36px; height: 36px; background: var(--primary); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 1rem; flex-shrink: 0; }
.sidebar .sidebar-header .brand-name { font-size: 1rem; font-weight: 700; color: var(--sidebar-text-active); white-space: nowrap; }
.sidebar .sidebar-header .brand-sub { font-size: 0.7rem; color: var(--sidebar-text); text-transform: uppercase; letter-spacing: 1px; }

.sidebar .sidebar-scroll { flex-grow: 1; overflow-y: auto; overflow-x: hidden; padding: 12px; }

.sidebar .sidebar-section { margin-bottom: 20px; }
.sidebar .sidebar-section-title { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 1.5px; color: var(--text-muted); padding: 8px 12px 6px; font-weight: 600; white-space: nowrap; overflow: hidden; }

.sidebar .nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius); cursor: pointer; color: var(--sidebar-text); font-size: 0.88rem; font-weight: 500; transition: background var(--transition), color var(--transition); margin-bottom: 2px; white-space: nowrap; }
.sidebar .nav-item:hover { background: var(--sidebar-bg-hover); color: var(--sidebar-text-active); }
.sidebar .nav-item.active { background: var(--primary); color: #fff; }
.sidebar .nav-item .nav-icon { flex-shrink: 0; display: flex; }
.sidebar .nav-item .nav-label { overflow: hidden; text-overflow: ellipsis; }

.sidebar .sidebar-footer { padding: 14px 12px; border-top: 1px solid var(--sidebar-border); }

.sidebar .user-block { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius); cursor: pointer; transition: background var(--transition); }
.sidebar .user-block:hover { background: var(--sidebar-bg-hover); }
.sidebar .user-block .avatar { width: 34px; height: 34px; background: var(--primary); color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; flex-shrink: 0; }
.sidebar .user-block .user-info { overflow: hidden; }
.sidebar .user-block .user-name { font-size: 0.85rem; font-weight: 600; color: var(--sidebar-text-active); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .user-block .user-role { font-size: 0.72rem; color: var(--sidebar-text); white-space: nowrap; }

.main-area { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
    height: var(--topbar-h);
    flex-shrink: 0;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar .btn-menu { display: none; }
.topbar-title { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.main-scroll { flex-grow: 1; overflow-y: auto; padding: 24px; }

/* ===== Views & Cards ===== */
.app-view { display: none; flex-direction: column; gap: 20px; }
.app-view.active-view { display: flex; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-body { padding: 20px; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-title { font-size: 0.95rem; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; }

.welcome-screen { display: none; flex-direction: column; align-items: center; justify-content: center; flex-grow: 1; text-align: center; color: var(--text-muted); gap: 12px; }
.welcome-screen.show { display: flex; }
.welcome-screen .welcome-icon { color: var(--border-dark); }
.welcome-screen h2 { border: none; color: var(--text); }
.welcome-screen p { font-size: 0.9rem; }

/* ===== Utilities ===== */
.text-danger { color: var(--danger); } .text-success { color: var(--success); } .text-primary { color: var(--primary); } .text-warning { color: var(--warning); }
.text-muted { color: var(--text-muted); }
.fw-bold { font-weight: 700; } .fw-600 { font-weight: 600; }
.w-100 { width: 100%; } .flex-1 { flex: 1; } .min-w-0 { min-width: 0; }
.flex { display: flex; } .flex-col { flex-direction: column; } .items-center { align-items: center; } .items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; } .justify-end { justify-content: flex-end; } .justify-center { justify-content: center; }
.flex-wrap { flex-wrap: wrap; } .gap-1 { gap: 6px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.mt-2 { margin-top: 12px; } .mt-3 { margin-top: 20px; } .mt-4 { margin-top: 28px; } 
.mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 20px; } .mb-4 { margin-bottom: 28px; }
.p-3 { padding: 12px; } .p-4 { padding: 16px; }
.cursor-pointer { cursor: pointer; } .list-none { list-style: none; }
.text-sm { font-size: 0.85rem; } .text-xs { font-size: 0.75rem; } .text-lg { font-size: 1.1rem; }
.text-center { text-align: center; } .text-right { text-align: right; }
.overflow-hidden { overflow: hidden; } .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

h2 { font-size: 1.15rem; font-weight: 700; color: var(--text); }
h3 { font-size: 0.95rem; font-weight: 600; color: var(--text); margin-bottom: 10px; }
label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-light); margin-bottom: 8px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }

/* ===== Responsive ===== */
@media (max-width: 1023px) {
    .sidebar { position: fixed; top: 0; left: 0; height: 100%; transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 400; }
    .sidebar-overlay.open { display: block; }
    .topbar .btn-menu { display: inline-flex; }
    .main-scroll { padding: 16px; }
    .grid-2, .grid-3, .grid-auto { grid-template-columns: 1fr; }
}

@media (min-width: 1024px) and (max-width: 1279px) {
    .sidebar { width: var(--sidebar-collapsed); }
    .sidebar .brand-name, .sidebar .brand-sub, .sidebar .nav-label, .sidebar .sidebar-section-title, .sidebar .user-info, .sidebar .sidebar-section { display: none; }
    .sidebar .sidebar-header { justify-content: center; }
    .sidebar .nav-item { justify-content: center; padding: 12px; }
    .sidebar .user-block { justify-content: center; }
}

@media (max-width: 1279px) {
    .sidebar { position: fixed; top: 0; left: 0; height: 100%; transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 400; }
    .sidebar-overlay.open { display: block; }
    .topbar .btn-menu { display: inline-flex; }
    .main-scroll { padding: 16px; }
    .grid-2, .grid-3, .grid-auto { grid-template-columns: 1fr; }
}