:root {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --border: #e6e8ee;
    --ink: #1b1f2a;
    --ink-soft: #5b6172;
    --ink-faint: #9097a6;
    --sidebar: #161a25;
    --sidebar-soft: #232838;
    --accent: #5b4bdb;
    --accent-soft: #efedfc;
    --ok: #1f9d6b;
    --warn: #c9851f;
    --danger: #d3453f;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(20, 24, 38, .05), 0 8px 24px rgba(20, 24, 38, .04);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

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

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: #cdd2df;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 22px 22px 26px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: #fff;
    font-size: 1.05rem;
}
.brand-mark {
    width: 34px; height: 34px;
    display: grid; place-items: center;
    background: var(--accent);
    color: #fff;
    border-radius: 9px;
    font-weight: 700;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 12px; flex: 1; }
.sidebar-nav .nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 14px;
    color: #aeb4c4;
    border-radius: 9px;
    font-weight: 500;
    font-size: .94rem;
    transition: background .15s, color .15s;
}
.sidebar-nav .nav-link i { font-size: 1.1rem; }
.sidebar-nav .nav-link:hover { background: var(--sidebar-soft); color: #fff; }
.sidebar-nav .nav-link.active { background: var(--accent); color: #fff; }
.nav-group { color: var(--ink-faint); font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; padding: 16px 14px 6px; }

.sidebar-foot {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 18px;
    border-top: 1px solid rgba(255,255,255,.07);
}
.who { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.who-avatar {
    width: 36px; height: 36px; flex-shrink: 0;
    display: grid; place-items: center;
    background: var(--sidebar-soft); color: #fff;
    border-radius: 50%; font-weight: 600;
}
.who-meta { display: flex; flex-direction: column; min-width: 0; }
.who-name { color: #fff; font-weight: 600; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-role { color: var(--ink-faint); font-size: .76rem; }
.logout { color: #aeb4c4; font-size: 1.2rem; padding: 6px; border-radius: 8px; }
.logout:hover { color: #fff; background: var(--sidebar-soft); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    display: flex; align-items: center; gap: 14px;
    height: 64px;
    padding: 0 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 1.15rem; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.menu-toggle { display: none; background: none; border: none; font-size: 1.4rem; color: var(--ink); }

.content { padding: 28px; max-width: 1200px; width: 100%; }

/* ---------- Cards & utilities ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-pad { padding: 22px 24px; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.section-head p { margin: 2px 0 0; color: var(--ink-soft); font-size: .92rem; }
.section-head h2 { font-size: 1.25rem; font-weight: 600; margin: 0; letter-spacing: -0.01em; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 18px; margin-bottom: 26px; }
.stat {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow);
}
.stat-icon { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-size: 1.25rem; margin-bottom: 14px; background: var(--accent-soft); color: var(--accent); }
.stat-num { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.stat-label { color: var(--ink-soft); font-size: .9rem; margin-top: 6px; }

/* Buttons & accents */
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: #4a3cc4; border-color: #4a3cc4; color: #fff; }

/* Tables */
.table { margin: 0; }
.table thead th { font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-faint); font-weight: 600; border-bottom: 1px solid var(--border); padding: 14px 16px; }
.table tbody td { padding: 14px 16px; vertical-align: middle; border-color: var(--border); }
.table tbody tr:last-child td { border-bottom: none; }

.cell-user { display: flex; align-items: center; gap: 12px; }
.cell-avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 600; flex-shrink: 0; }
.cell-name { font-weight: 600; }
.cell-mail { color: var(--ink-soft); font-size: .85rem; }

.badge-role { font-weight: 600; font-size: .74rem; padding: 5px 10px; border-radius: 20px; }
.badge-admin { background: var(--accent-soft); color: var(--accent); }
.badge-user { background: #eef0f4; color: var(--ink-soft); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; }
.dot-active { background: var(--ok); }
.dot-inactive { background: var(--ink-faint); }

.icon-btn { border: 1px solid var(--border); background: var(--surface); color: var(--ink-soft); width: 34px; height: 34px; border-radius: 8px; display: inline-grid; place-items: center; }
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

.form-label { font-weight: 500; font-size: .9rem; }
.form-control:focus, .form-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 70% -10%, #2a2f45, var(--sidebar)); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 16px; padding: 38px 34px; box-shadow: 0 24px 60px rgba(0,0,0,.35); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; font-weight: 700; font-size: 1.2rem; }
.login-brand .brand-mark { width: 40px; height: 40px; font-size: 1.1rem; }
.login-card h2 { font-size: 1.4rem; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.02em; }
.login-card .sub { color: var(--ink-soft); font-size: .92rem; margin-bottom: 24px; }
.login-hint { margin-top: 18px; font-size: .82rem; color: var(--ink-faint); text-align: center; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .sidebar { position: fixed; z-index: 60; transform: translateX(-100%); transition: transform .22s ease; }
    .sidebar.open { transform: translateX(0); }
    .menu-toggle { display: block; }
    .content { padding: 20px 16px; }
    .topbar { padding: 0 16px; }
}
.scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 55; }
.scrim.show { display: block; }

.min-w-0 { min-width: 0; }
.code-block {
    background: #0f1322; color: #d7def0;
    border-radius: 10px; padding: 16px 18px; margin: 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .82rem; line-height: 1.5;
    max-height: 460px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}
.log-detail { background: #f7f8fb; border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.log-detail pre { margin: 0; font-size: .8rem; white-space: pre-wrap; word-break: break-word; max-height: 280px; overflow: auto; }
