:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --ink: #172033;
    --muted: #6e7a8d;
    --line: #e4eaf2;
    --sidebar: #14205c;
    --sidebar-soft: rgba(255,255,255,.14);
    --brand: #2563eb;
    --green: #16a34a;
    --amber: #d97706;
    --red: #dc2626;
    --radius: 8px;
    --shadow: 0 16px 40px rgba(17, 24, 39, .08);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.admin-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 286px minmax(0, 1fr);
}

.sidebar {
    background: linear-gradient(180deg, #14205c 0%, #17266d 52%, #0d1746 100%);
    color: #dbe4f0;
    min-height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
    border-right: 1px solid rgba(255,255,255,.08);
}

.sidebar-head {
    padding: 22px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, #2563eb, #13b981);
    font-weight: 800;
}

.brand-row strong { display: block; color: #fff; font-size: 16px; }
.brand-row span { display: block; color: #9aa7bb; font-size: 12px; margin-top: 2px; }

.nav-list { padding: 14px 12px 26px; }
.nav-group { margin-bottom: 4px; }

.nav-link {
    width: 100%;
    border: 0;
    color: #cbd5e1;
    background: transparent;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 9px 10px;
    border-radius: 7px;
    text-align: left;
}

.nav-link:hover, .nav-link.active, .nav-group.is-open > .nav-link {
    color: #fff;
    background: var(--sidebar-soft);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}

.nav-icon {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    display: grid;
    place-items: center;
    background: rgba(255,255,255,.16);
    font-size: 11px;
    font-weight: 800;
}

.chevron { margin-left: auto; transition: transform .2s ease; }
.nav-group.is-open .chevron { transform: rotate(90deg); }

.sub-nav {
    display: none;
    margin: 4px 0 8px 38px;
    padding-left: 14px;
    border-left: 1px solid rgba(255,255,255,.1);
}

.nav-group.is-open .sub-nav { display: grid; gap: 2px; }

.sub-nav a {
    color: #9aa7bb;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 13px;
}

.sub-nav a:hover, .sub-nav a.active {
    background: rgba(255,255,255,.14);
    color: #fff;
}

.main-shell { min-width: 0; }

.topbar {
    height: 72px;
    position: sticky;
    top: 0;
    z-index: 5;
    background: rgba(244,247,251,.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 28px;
}

.menu-btn { display: none; }

.search-box {
    flex: 1;
    max-width: 520px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    color: var(--muted);
    font-size: 13px;
}

.search-box input {
    border: 0;
    outline: 0;
    width: 100%;
    color: var(--ink);
}

.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    border-radius: 8px;
    display: inline-grid;
    place-items: center;
    font-weight: 700;
}

.profile-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 8px;
    padding: 6px 10px 6px 6px;
}

.profile-chip > span {
    width: 32px;
    height: 32px;
    border-radius: 7px;
    display: grid;
    place-items: center;
    background: #e8f1ff;
    color: var(--brand);
    font-weight: 800;
    font-size: 12px;
}

.profile-chip strong, .profile-chip small { display: block; }
.profile-chip strong { font-size: 13px; }
.profile-chip small { color: var(--muted); font-size: 11px; }

.content {
    padding: 28px;
    display: grid;
    gap: 22px;
}

.page-head {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
}

.eyebrow {
    color: var(--brand);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.page-head h1, .card-title h2 {
    margin: 5px 0 6px;
    font-size: 30px;
    line-height: 1.15;
    letter-spacing: 0;
}

.page-head p, .login-copy p, .role-card p {
    margin: 0;
    color: var(--muted);
}

.head-actions { display: flex; gap: 10px; }

.primary-btn, .ghost-btn {
    min-height: 40px;
    border-radius: 8px;
    padding: 0 15px;
    border: 1px solid transparent;
    font-weight: 800;
}

.primary-btn {
    background: var(--brand);
    color: #fff;
}

.ghost-btn {
    background: #fff;
    border-color: var(--line);
    color: var(--ink);
}

.compact { min-height: 34px; padding: 0 12px; font-size: 13px; }
.full { width: 100%; }

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

.metric-card, .panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.metric-card {
    padding: 18px;
    position: relative;
    overflow: hidden;
}

.metric-card:after {
    content: "";
    position: absolute;
    inset: auto 18px 0 auto;
    width: 62px;
    height: 4px;
    border-radius: 4px 4px 0 0;
    background: currentColor;
}

.metric-card span, .metric-card small {
    display: block;
    color: var(--muted);
}

.metric-card strong {
    display: block;
    margin: 8px 0 4px;
    font-size: 28px;
}

.metric-card.blue { color: var(--brand); }
.metric-card.green { color: var(--green); }
.metric-card.amber { color: var(--amber); }
.metric-card.red { color: var(--red); }

.dashboard-grid, .split-grid, .form-grid, .settings-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(320px, .8fr);
    gap: 16px;
}

.panel { padding: 18px; min-width: 0; }
.panel.wide { min-height: 330px; }

.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.panel-head h2 {
    margin: 3px 0 0;
    font-size: 18px;
}

.bar-chart {
    height: 230px;
    display: flex;
    align-items: end;
    gap: 12px;
    padding-top: 20px;
}

.bar-chart span {
    flex: 1;
    min-width: 22px;
    border-radius: 7px 7px 0 0;
    background: linear-gradient(180deg, #2563eb, #13b981);
}

.timeline { display: grid; gap: 14px; }
.timeline div {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fbff;
}
.timeline strong, .timeline span { display: block; }
.timeline span { color: var(--muted); margin-top: 3px; }

.data-list { display: grid; gap: 10px; }
.data-list div {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
}
.data-list small { color: var(--muted); }
.data-list em { font-style: normal; font-size: 12px; color: var(--brand); font-weight: 800; }

.course-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
}
.course-dot.blue { background: var(--brand); }
.course-dot.green { background: var(--green); }
.course-dot.amber { background: var(--amber); }
.course-dot.red { background: var(--red); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
    text-align: left;
    padding: 13px 12px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
    font-size: 14px;
}
th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border-radius: 999px;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 800;
}
.badge.success { background: #dcfce7; color: #166534; }
.badge.warning { background: #fef3c7; color: #92400e; }
.badge.muted { background: #eef2f7; color: #475569; }
.table-action { width: 32px; height: 32px; }

.admin-form, .stack-form, .settings-list {
    display: grid;
    gap: 14px;
}

label span {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    padding: 11px 12px;
    outline: none;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.two-col {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.toggle-line, .check-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.toggle-line input, .check-line input { width: auto; }
.check-line { justify-content: flex-start; }
.check-line span { margin: 0; }

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

.role-icon {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #e8f1ff;
    color: var(--brand);
    font-weight: 800;
}

.role-card h2 { margin: 14px 0 8px; font-size: 18px; }
.permission-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.permission-tags span {
    border: 1px solid var(--line);
    background: #f8fbff;
    border-radius: 999px;
    padding: 6px 10px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px;
    background:
        linear-gradient(135deg, rgba(37,99,235,.14), rgba(19,185,129,.13)),
        #f3f6fb;
}

.login-shell {
    width: min(1040px, 100%);
    display: grid;
    grid-template-columns: 1.1fr .9fr;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(17,24,39,.16);
}

.login-panel {
    padding: 42px;
    background: #111827;
    color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 560px;
}

.login-copy h1 {
    max-width: 560px;
    margin: 10px 0 12px;
    font-size: 42px;
    line-height: 1.08;
    letter-spacing: 0;
}

.login-copy p { color: #b9c4d4; max-width: 450px; }

.login-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.login-stats div {
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 8px;
    padding: 14px;
    background: rgba(255,255,255,.06);
}
.login-stats strong, .login-stats span { display: block; }
.login-stats strong { font-size: 22px; }
.login-stats span { color: #aeb9ca; font-size: 12px; margin-top: 3px; }

.login-card {
    padding: 42px;
    display: grid;
    align-content: center;
}

.card-title { margin-bottom: 20px; }
.form-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    color: var(--muted);
    font-size: 13px;
}

@media (max-width: 1180px) {
    .metric-grid, .role-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid, .split-grid, .form-grid, .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
    .admin-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        z-index: 20;
        inset: 0 auto 0 0;
        width: 286px;
        transform: translateX(-100%);
        transition: transform .2s ease;
    }
    .sidebar.is-visible { transform: translateX(0); }
    .menu-btn { display: inline-grid; }
    .topbar { padding: 0 16px; }
    .profile-chip div, .search-box span { display: none; }
    .content { padding: 18px; }
    .page-head { display: grid; }
    .login-shell { grid-template-columns: 1fr; }
    .login-panel { min-height: auto; gap: 34px; }
}

@media (max-width: 620px) {
    .metric-grid, .role-grid, .two-col, .login-stats { grid-template-columns: 1fr; }
    .head-actions { width: 100%; }
    .head-actions button { flex: 1; }
    .page-head h1, .card-title h2 { font-size: 25px; }
    .login-copy h1 { font-size: 31px; }
    .login-panel, .login-card { padding: 28px; }
    .data-list div { grid-template-columns: auto 1fr; }
    .data-list em { grid-column: 2; }
}
