:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --border: #e5e7eb;
    --sidebar: #111827;
    --sidebar-text: #e5e7eb;
    --success-bg: #ecfdf5;
    --success-text: #065f46;
    --error-bg: #fef2f2;
    --error-text: #991b1b;
    --radius: 12px;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: "Segoe UI", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
    background: var(--sidebar);
    color: var(--sidebar-text);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}
.brand { display: flex; align-items: center; gap: .75rem; }
.brand-mark {
    width: 42px; height: 42px; border-radius: 10px;
    background: var(--primary); color: #fff;
    display: grid; place-items: center; font-weight: 700;
}
.brand small, .muted { color: var(--muted); display: block; }
.sidebar .brand small { color: #9ca3af; }
.nav { display: flex; flex-direction: column; gap: .35rem; }
.nav-link {
    color: var(--sidebar-text);
    padding: .65rem .8rem;
    border-radius: 8px;
}
.nav-link:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav-link.active { background: rgba(37, 99, 235, 0.35); font-weight: 600; }
.nav-section {
    font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
    color: #6b7280; margin-top: .85rem; padding: 0 .8rem .25rem;
}
.nav-section:first-child { margin-top: 0; }
.nav-link.muted { color: #9ca3af; font-size: .9rem; }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: .75rem; }
.user-chip span { display: block; font-weight: 600; }
.user-chip small { color: #9ca3af; }

.main { padding: 1.5rem 2rem; }
.topbar h1 { margin: 0 0 1rem; font-size: 1.6rem; }
.content { display: flex; flex-direction: column; gap: 1rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
}
.stat-value { font-size: 1.4rem; font-weight: 700; margin: .25rem 0; }
.module-list { margin: 0; padding-left: 1.2rem; }
.badge {
    font-size: .75rem; background: #eef2ff; color: #4338ca;
    padding: .15rem .45rem; border-radius: 999px;
}
.abm-grid { margin-top: 0; }
.abm-card { position: relative; display: flex; flex-direction: column; gap: .5rem; }
.abm-card h3 { margin: 0; }
.abm-order {
    position: absolute; top: 1rem; right: 1rem;
    width: 28px; height: 28px; border-radius: 50%;
    background: #eef2ff; color: #4338ca;
    display: grid; place-items: center; font-size: .85rem; font-weight: 700;
}
.form-fieldset {
    border: 1px solid var(--border); border-radius: 8px;
    padding: 1rem 1.25rem; margin: 0 0 1rem;
}
.form-fieldset legend {
    font-weight: 600; padding: 0 .35rem; color: var(--text);
}

.toolbar { display: flex; gap: .75rem; flex-wrap: wrap; justify-content: space-between; align-items: center; }
.search-form { display: flex; gap: .5rem; flex: 1; max-width: 480px; }
.search-form input { flex: 1; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: .75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 2rem !important; }
.actions { white-space: nowrap; display: flex; gap: .35rem; align-items: center; }
.inline-form { display: inline; }

.form label { display: flex; flex-direction: column; gap: .35rem; font-size: .92rem; font-weight: 600; }
.form input, .form select, .form textarea {
    font: inherit; padding: .65rem .75rem;
    border: 1px solid var(--border); border-radius: 8px;
    background: #fff; font-weight: 400;
}
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}
.span-2 { grid-column: span 2; }
.checkbox-label { flex-direction: row !important; align-items: center; font-weight: 500 !important; }
.form-actions { display: flex; gap: .75rem; justify-content: flex-end; margin-top: 1.25rem; }
.form-card { max-width: 900px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); background: #fff; color: var(--text);
    padding: .55rem .9rem; border-radius: 8px; cursor: pointer; font: inherit;
}
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-sm { padding: .35rem .6rem; font-size: .85rem; }
.btn-block { width: 100%; }

.pill {
    display: inline-block; padding: .2rem .55rem; border-radius: 999px; font-size: .8rem;
}
.pill-success { background: var(--success-bg); color: var(--success-text); }
.pill-muted { background: #f3f4f6; color: var(--muted); }

.alert {
    padding: .85rem 1rem; border-radius: 8px; margin-bottom: 1rem;
}
.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-error { background: var(--error-bg); color: var(--error-text); }

.auth-body {
    min-height: 100vh; display: grid; place-items: center;
    background: linear-gradient(135deg, #111827, #1e3a8a);
}
.auth-card {
    width: min(420px, 92vw);
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}
.auth-brand { margin-bottom: 1.5rem; }
.error-card, .placeholder-card { max-width: 640px; }

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { min-height: auto; }
    .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: span 1; }
}
