/* ─── Design Tokens ─────────────────────────────────────────────────────── */
:root {
    --primary:        #6366f1;
    --primary-hover:  #4f46e5;
    --primary-light:  rgba(99,102,241,0.1);
    --bg:             #f3f4f6;
    --surface:        #ffffff;
    --surface-2:      #f9fafb;
    --text:           #111827;
    --text-muted:     #6b7280;
    --border:         #e5e7eb;
    --danger:         #ef4444;
    --danger-light:   rgba(239,68,68,0.1);
    --success:        #10b981;
    --success-light:  rgba(16,185,129,0.1);
    --warning:        #f59e0b;
    --radius:         0.5rem;
    --radius-lg:      0.75rem;
    --shadow-sm:      0 1px 2px 0 rgb(0 0 0/0.05);
    --shadow:         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);
    --sidebar-w:      240px;
    --topbar-h:       64px;
    --transition:     0.2s ease;
}

[data-theme="dark"] {
    --primary:       #818cf8;
    --primary-hover: #6366f1;
    --primary-light: rgba(129,140,248,0.15);
    --bg:            #0f172a;
    --surface:       #1e293b;
    --surface-2:     #0f172a;
    --text:          #f1f5f9;
    --text-muted:    #94a3b8;
    --border:        #334155;
    --danger:        #f87171;
    --danger-light:  rgba(248,113,113,0.15);
    --success:       #34d399;
    --success-light: rgba(52,211,153,0.15);
    --warning:       #fbbf24;
    --shadow-sm:     0 1px 2px 0 rgb(0 0 0/0.3);
    --shadow:        0 1px 3px 0 rgb(0 0 0/0.3),0 1px 2px -1px rgb(0 0 0/0.3);
    --shadow-md:     0 4px 6px -1px rgb(0 0 0/0.4),0 2px 4px -2px rgb(0 0 0/0.4);
}

/* ─── Reset ─────────────────────────────────────────────────────────────── */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 0.9375rem;
    line-height: 1.6;
    background: var(--bg);
    color: var(--text);
    transition: background var(--transition), color var(--transition);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { display: block; }

/* ─── App Layout ────────────────────────────────────────────────────────── */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background var(--transition), border-color var(--transition);
}
.sidebar-header {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 1.25rem;
    font-size: 1.125rem;
    font-weight: 700;
    border-bottom: 1px solid var(--border);
    color: var(--primary);
    letter-spacing: -0.025em;
}
.logo-icon { font-size: 1.4rem; }
.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0.75rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.9rem;
    transition: background var(--transition), color var(--transition);
}
.nav-item:hover { background: var(--primary-light); color: var(--primary); text-decoration: none; }
.nav-item.active { background: var(--primary-light); color: var(--primary); }
.nav-icon { font-size: 1rem; opacity: 0.8; }
.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    font-size: 0.8125rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.sidebar-footer::before {
    content: '👤';
    font-size: 1rem;
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}
.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    gap: 1rem;
    flex-shrink: 0;
    transition: background var(--transition), border-color var(--transition);
}
.topbar-left { display: flex; align-items: center; }
.topbar-right { display: flex; align-items: center; gap: 0.625rem; }
.page-title {
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}
.content-area {
    flex: 1;
    padding: 1.75rem;
    overflow-y: auto;
}

/* ─── Cards ─────────────────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: background var(--transition), border-color var(--transition);
}

/* ─── Buttons ───────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--primary);
    color: #fff;
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    text-align: center;
    white-space: nowrap;
    transition: background var(--transition), box-shadow var(--transition), opacity var(--transition);
    line-height: 1.4;
    text-decoration: none;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; color: #fff; }
.btn:active { opacity: 0.9; }
.btn-outline {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}
.btn-outline:hover { background: var(--surface-2); color: var(--text); }
.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-muted);
    padding: 0.5rem 0.625rem;
}
.btn-ghost:hover { background: var(--primary-light); color: var(--primary); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 0.3125rem 0.75rem; font-size: 0.8125rem; }

/* ─── Forms ─────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.125rem; }
.form-group label {
    display: block;
    margin-bottom: 0.375rem;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text);
}
.form-control {
    display: block;
    width: 100%;
    padding: 0.5625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9375rem;
    line-height: 1.5;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
    -webkit-appearance: none;
}
.form-control::placeholder { color: var(--text-muted); opacity: 1; }
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 6rem; }

/* ─── Alerts ────────────────────────────────────────────────────────────── */
.alert {
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.875rem;
    border: 1px solid transparent;
}
.alert-danger  { background: var(--danger-light);  color: var(--danger);  border-color: rgba(239,68,68,0.25); }
.alert-success { background: var(--success-light); color: var(--success); border-color: rgba(16,185,129,0.25); }

/* ─── Auth Page ─────────────────────────────────────────────────────────── */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: var(--bg);
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-md);
}
.auth-brand {
    text-align: center;
    margin-bottom: 2rem;
}
.auth-brand .logo-icon { font-size: 2.5rem; display: block; margin: 0 auto 0.5rem; color: var(--primary); }
.auth-brand h1 { font-size: 1.5rem; font-weight: 700; color: var(--primary); margin-bottom: 0.25rem; }
.auth-brand p { color: var(--text-muted); font-size: 0.875rem; }
.auth-form { display: flex; flex-direction: column; gap: 0; }

/* ─── Tables ────────────────────────────────────────────────────────────── */
.data-table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    min-width: 700px;
    font-size: 0.9rem;
}
.data-table thead tr { background: var(--surface-2); border-bottom: 1px solid var(--border); }
.data-table th {
    padding: 0.875rem 1.125rem;
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}
.data-table td { padding: 0.9375rem 1.125rem; }
.data-table tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table-scroll { overflow-x: auto; }

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.78125rem;
    font-weight: 500;
    line-height: 1;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger  { background: var(--danger-light);  color: var(--danger); }
.badge-warning { background: rgba(245,158,11,0.1); color: var(--warning); }

/* Page header row */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}
.page-header h2 { font-size: 1.25rem; font-weight: 700; }
.page-header-actions { display: flex; gap: 0.625rem; flex-wrap: wrap; }

/* Stat Cards */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow-sm);
}
.stat-label { font-size: 0.78125rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.stat-value { font-size: 1.875rem; font-weight: 700; margin-top: 0.25rem; letter-spacing: -0.025em; }
.stat-value.danger { color: var(--danger); }
