:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #2563eb;
    --primary-soft: #eff6ff;
    --ok: #10b981;
    --warn: #f59e0b;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
}
[data-theme="dark"] {
    --bg: #020617;
    --surface: #0f172a;
    --surface-2: #1e293b;
    --border: #1e293b;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --primary: #3b82f6;
    --primary-soft: #172554;
    --shadow: none;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }

.layout { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}
.brand {
    display: flex; align-items: center; gap: 10px;
    height: 56px; padding: 0 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}
.brand-mark {
    width: 28px; height: 28px; border-radius: 7px;
    background: var(--primary); color: #fff;
    display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.nav-scroll { flex: 1; overflow-y: auto; padding: 16px 12px; }
.nav-heading {
    margin: 16px 8px 8px; font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
}
.nav-heading:first-child { margin-top: 0; }
.nav { list-style: none; margin: 0; padding: 0; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px; margin-bottom: 2px; border-radius: 8px;
    font-weight: 500; color: var(--text); cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); }
.nav-item.disabled { color: var(--muted); cursor: not-allowed; }
.nav-item.disabled:hover { background: transparent; }
.badge {
    margin-left: auto; font-size: 10px; font-weight: 400;
    background: var(--surface-2); color: var(--muted);
    padding: 1px 6px; border-radius: 5px;
}
.sidebar-foot {
    padding: 12px 20px; border-top: 1px solid var(--border);
    font-size: 11px; color: var(--muted);
}

/* Main */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
    height: 56px; flex-shrink: 0;
    display: flex; align-items: center; gap: 16px;
    padding: 0 16px; background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.search {
    flex: 1; max-width: 420px; height: 36px;
    padding: 0 12px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--surface-2);
    color: var(--text);
}
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn {
    width: 36px; height: 36px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--surface);
    color: var(--text); cursor: pointer; font-size: 16px;
}
.icon-btn:hover { background: var(--surface-2); }
.theme-icon::before { content: "\263E"; }
[data-theme="dark"] .theme-icon::before { content: "\2600"; }
.user { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.user-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }

.content { flex: 1; overflow-y: auto; padding: 24px; }
.page { max-width: 1040px; margin: 0 auto; }
.page.center { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 12px; text-align: center; }
.page-head h1 { margin: 0 0 4px; font-size: 22px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 16px 0; }

.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; box-shadow: var(--shadow);
}
.card-head {
    display: flex; align-items: baseline; justify-content: space-between;
    padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-head h3 { margin: 0; font-size: 13px; font-weight: 600; }
.card-body { padding: 16px 18px; }
.status-row { display: flex; align-items: center; gap: 10px; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.dot-ok { background: var(--ok); }
.dot-warn { background: var(--warn); }

.kpi { padding: 16px 18px; }
.kpi-label { margin: 0; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kpi-value { margin: 8px 0 0; font-size: 26px; font-weight: 600; }

.roadmap { list-style: none; margin: 0; padding: 0; }
.roadmap li { display: flex; align-items: center; gap: 12px; padding: 6px 0; }
.step {
    width: 24px; height: 24px; border-radius: 50%;
    background: var(--surface-2); color: var(--muted);
    display: grid; place-items: center; font-size: 12px; font-weight: 600;
}
.step-done { background: rgba(16, 185, 129, .15); color: var(--ok); }
.tick { margin-left: auto; color: var(--ok); }

.btn {
    display: inline-flex; align-items: center; padding: 8px 16px;
    background: var(--primary); color: #fff; border-radius: 8px; font-weight: 500;
}
.btn:hover { filter: brightness(1.05); }
.big-404 { font-size: 56px; font-weight: 700; color: var(--muted); margin: 0; }

@media (max-width: 860px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px) {
    .sidebar { display: none; }
    .grid-2 { grid-template-columns: 1fr; }
}

/* ===================== Module 2 — Auth & RBAC components ===================== */

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label { font-size: 13px; font-weight: 500; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], select, textarea {
    height: 40px; width: 100%; padding: 0 12px; font-size: 14px;
    color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: 8px;
}
textarea { height: auto; padding: 10px 12px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input:disabled, input[readonly] { opacity: .65; cursor: not-allowed; }
.check, .radio { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 400; cursor: pointer; }
.check input, .radio input { width: auto; height: auto; }
.radio.ok { color: #059669; } .radio.danger { color: #dc2626; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.inline-form { display: flex; gap: 10px; align-items: center; max-width: 460px; }

/* Buttons */
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { filter: none; background: var(--border); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-block { display: flex; width: 100%; justify-content: center; margin-top: 4px; }
.link { background: none; border: none; padding: 0; font: inherit; font-size: 13px; color: var(--primary); cursor: pointer; text-decoration: none; }
.link:hover { text-decoration: underline; }
.link.danger, .danger { color: #dc2626; }

/* Alerts */
.alert { padding: 10px 14px; margin-bottom: 14px; border-radius: 8px; font-size: 14px; border: 1px solid transparent; }
.alert-success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.alert-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-info { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
[data-theme="dark"] .alert-success { background: #052e2b; color: #6ee7b7; border-color: #065f46; }
[data-theme="dark"] .alert-error { background: #3f1d1d; color: #fca5a5; border-color: #7f1d1d; }
[data-theme="dark"] .alert-info { background: #172554; color: #93c5fd; border-color: #1e40af; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; padding: 10px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom: 1px solid var(--border); }
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.center-cell { text-align: center; padding: 24px; }
.row-actions { display: flex; gap: 12px; align-items: center; justify-content: flex-end; }
.row-actions form { display: inline; margin: 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

/* Badges / pills / tags */
.badge-blue { background: var(--primary-soft); color: var(--primary); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.pill-ok { background: rgba(16,185,129,.15); color: #059669; }
.pill-off { background: var(--surface-2); color: var(--muted); }
.tag { display: inline-block; margin: 2px; padding: 2px 8px; font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; }

/* Toolbar + pagination */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type="search"] { max-width: 320px; }
.toolbar select { width: auto; }
.pagination { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.page-link { padding: 6px 12px; font-size: 13px; color: var(--text); border: 1px solid var(--border); border-radius: 8px; }
.page-link.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Permission / checkbox grids */
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.perm-group { padding: 12px 0; border-bottom: 1px solid var(--border); }
.perm-group:last-child { border-bottom: none; padding-bottom: 0; }
.perm-resource { font-weight: 600; font-size: 13px; margin-bottom: 8px; text-transform: capitalize; }
.perm-rows { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 8px; }
.perm-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; background: var(--surface-2); border-radius: 8px; }
.perm-name { font-size: 13px; text-transform: capitalize; }
.perm-choices { display: flex; gap: 10px; }
.perm-choices .radio { font-size: 12px; }
.perm-tags { display: flex; flex-wrap: wrap; gap: 4px; }
details.card > summary.card-head { cursor: pointer; }
details.card > summary.card-head::-webkit-details-marker { display: none; }
details.card > summary.card-head { list-style: none; }

/* Auth pages */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; background: var(--bg); }
.auth-wrap { width: 100%; max-width: 400px; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 20px; font-weight: 600; font-size: 18px; }
.auth-card { padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.auth-title { margin: 0 0 18px; font-size: 20px; }
.auth-links { margin-top: 16px; text-align: center; font-size: 13px; }
.auth-foot { text-align: center; margin-top: 18px; }

/* User menu */
.user-menu { position: relative; }
.user-menu > summary { list-style: none; cursor: pointer; }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-avatar { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 12px; font-weight: 600; }
.user-menu .menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 170px; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(2,6,23,.18); z-index: 30; }
.menu-item { display: block; width: 100%; padding: 8px 12px; font-size: 14px; text-align: left; color: var(--text); background: none; border: none; border-radius: 8px; cursor: pointer; }
.menu-item:hover { background: var(--surface-2); }
.menu-form { margin: 0; }
@media (max-width: 640px) { .hide-sm { display: none; } }

/* Tabs + full-width field (Module 3) */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tab { padding: 8px 14px; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }
.span-2 { grid-column: 1 / -1; }
