:root {
    --bg: #f3f2ef;
    --surface: #ffffff;
    --surface-soft: #f7f9fc;
    --text: #111827;
    --muted: #667085;
    --line: #d9e1ea;
    --line-soft: #edf1f5;
    --nav: #0f1720;
    --nav-2: #172433;
    --primary: #144f86;
    --primary-strong: #0f3f6d;
    --gold: #b7791f;
    --danger: #b42318;
    --ok-bg: #dcfce7;
    --ok-text: #166534;
    --teacher-bg: #e0f2fe;
    --teacher-text: #075985;
    --student-bg: #fef3c7;
    --student-text: #92400e;
    --shadow: 0 20px 50px rgba(16, 24, 40, .08);
    --shadow-soft: 0 1px 2px rgba(16, 24, 40, .08);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    margin: 0;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, .9), rgba(255, 255, 255, 0) 260px),
        radial-gradient(circle at top right, rgba(20, 79, 134, .08), transparent 340px),
        var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

a {
    color: inherit;
    text-decoration: none;
}

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

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 24px 18px;
    background: linear-gradient(180deg, #1d1d1b 0%, #20201e 100%);
    border-right: 1px solid rgba(255, 255, 255, .08);
    color: #f8fafc;
}

.brand {
    display: block;
    padding: 8px 8px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .1);
}

.brand-logo {
    display: block;
    width: 100%;
    max-width: 214px;
    height: auto;
    padding: 6px;
    border-radius: 6px;
    background: #fff;
}

.brand .brand-logo + small {
    margin-top: 9px;
}
.brand-mark {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: linear-gradient(135deg, #144f86, #1d65a8);
    box-shadow: 0 14px 28px rgba(20, 79, 134, .22);
    font-weight: 900;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    margin-top: 2px;
    color: #aebdca;
    font-size: 12px;
}

.side-nav {
    display: grid;
    gap: 8px;
    margin-top: 24px;
}

.side-nav a {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 42px;
    padding: 10px 12px 10px 16px;
    border-radius: 9px;
    color: #d9e4ee;
    font-weight: 750;
    transition: background .16s ease, color .16s ease, transform .16s ease;
}

.side-nav a::before {
    content: "";
    width: 7px;
    height: 7px;
    margin-right: 10px;
    border-radius: 999px;
    background: rgba(217, 228, 238, .45);
}

.side-nav a:hover,
.side-nav a.active {
    background: rgba(255, 255, 255, .1);
    color: #ffffff;
}

.side-nav a.active {
    box-shadow: inset 3px 0 0 #ffffff;
}

.side-nav a.active::before {
    background: #ffffff;
}

.side-nav a:hover {
    transform: translateX(2px);
}

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

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    padding: 18px 32px;
    background: rgba(255, 255, 255, .86);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

.topbar-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.topbar strong {
    display: block;
    color: #101828;
    font-size: 18px;
}

.eyebrow {
    display: block;
    color: var(--primary);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .1em;
    text-transform: uppercase;
}

.status-pill,
.badge,
.readonly-chip,
.user-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 24px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.user-pill {
    max-width: 260px;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid var(--line);
    color: #344054;
    text-overflow: ellipsis;
}

.status-pill {
    min-height: 30px;
    background: #eaf4df;
    color: #335d19;
    border: 1px solid #dcebcf;
}

.page {
    width: min(1220px, calc(100vw - 336px));
    margin: 0 auto;
    padding: 32px 0 58px;
}

.page-heading {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: flex-start;
    margin-bottom: 22px;
}

.hero-panel {
    padding: 24px;
    background: linear-gradient(135deg, #ffffff 0%, #f8fbfd 100%);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow-soft);
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 6px;
    color: #0f172a;
    font-size: 32px;
    line-height: 1.1;
}

h2 {
    margin-bottom: 0;
    color: #182230;
    font-size: 18px;
}

.page-heading p {
    max-width: 720px;
    margin-bottom: 0;
    color: var(--muted);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 15px;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
    font-weight: 800;
    transition: background .16s ease, border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}

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

.btn-primary:hover {
    background: var(--primary-strong);
    box-shadow: 0 12px 22px rgba(15, 118, 110, .18);
    transform: translateY(-1px);
}

.btn-secondary,
.btn-ghost {
    background: #ffffff;
    border-color: var(--line);
    color: #1f2937;
}

.btn-secondary:hover,
.btn-ghost:hover {
    background: var(--surface-soft);
    border-color: #c8d3df;
}

.notice {
    margin-bottom: 18px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 9px;
}

.notice.success {
    background: var(--ok-bg);
    color: var(--ok-text);
    border-color: #bbf7d0;
}

.badge-error {
    background: #fee4e2;
    color: var(--danger);
}

.toolbar,
.data-panel,
.form-panel,
.metric-card {
    background: rgba(255, 255, 255, .96);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.toolbar {
    margin-bottom: 18px;
    padding: 16px;
}

.search-form,
.filter-form,
.table-tools {
    display: flex;
    gap: 10px;
    align-items: center;
}

.search-form .form-control,
.filter-wide {
    flex: 1;
}

.filter-form {
    flex-wrap: wrap;
}

.filter-form .form-control,
.filter-form .form-select {
    flex: 0 1 180px;
}

.form-control,
.form-select,
.table-filter {
    width: 100%;
    min-height: 42px;
    border: 1px solid #cfd8e3;
    border-radius: 8px;
    background: #fbfcfe;
    color: var(--text);
    font: inherit;
    padding: 10px 12px;
    transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

.form-control::placeholder,
.table-filter::placeholder {
    color: #98a2b3;
}

.form-control:focus,
.form-select:focus,
.table-filter:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(20, 79, 134, .16);
    background: #ffffff;
    outline: none;
}

.data-panel {
    margin-bottom: 24px;
    overflow: hidden;
}

.table-scroll {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    min-width: 820px;
    border-collapse: separate;
    border-spacing: 0;
}

.data-table.compact {
    min-width: 1080px;
    font-size: 13px;
}

.data-table th,
.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--line-soft);
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f8fafc;
    color: #475467;
    font-size: 11px;
    letter-spacing: .07em;
    text-transform: uppercase;
}

.data-table tbody tr {
    transition: background .14s ease;
}

.data-table tbody tr:hover {
    background: #f8fcfb;
}

.data-table tbody tr:last-child td {
    border-bottom: 0;
}

code {
    display: inline-flex;
    color: #f8fafc;
    background: #1d1d1b;
    border: 1px solid #343434;
    border-radius: 6px;
    padding: 2px 7px;
    font-family: Consolas, "Liberation Mono", monospace;
}

.badge-ok {
    background: var(--ok-bg);
    color: var(--ok-text);
}

.badge-muted {
    background: #eef2f7;
    color: #475467;
}

.badge-teacher {
    background: var(--teacher-bg);
    color: var(--teacher-text);
}

.badge-student {
    background: var(--student-bg);
    color: var(--student-text);
}

.form-panel {
    padding: 24px;
}

.form-section {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 18px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--line-soft);
}

.section-spaced {
    margin-top: 28px;
}

.readonly-chip {
    min-height: 32px;
    background: #f8ead4;
    color: #8a4d11;
    border: 1px solid #efd2a7;
}

.helper-text {
    color: var(--muted);
    font-size: 13px;
}

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

.field {
    display: grid;
    gap: 7px;
}

.field:focus-within .form-label {
    color: var(--primary-strong);
}

.span-2 {
    grid-column: span 2;
}

.span-all {
    grid-column: 1 / -1;
}

.form-label {
    color: #344054;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .02em;
}

.field-error,
.validation-summary {
    color: var(--danger);
    font-size: 13px;
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 10px;
}

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

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

.metric-card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--primary);
}

.metric-teacher::before {
    background: #0284c7;
}

.metric-student::before {
    background: var(--gold);
}

.metric-card span {
    color: var(--muted);
    font-weight: 800;
}

.metric-card strong {
    display: block;
    margin-top: 10px;
    color: #101828;
    font-size: 40px;
    line-height: 1;
}

.panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 24px 0 10px;
}

.data-panel .panel-title {
    margin: 0;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line-soft);
}

.table-tools {
    padding: 14px 16px;
    border-bottom: 1px solid var(--line-soft);
}

.inline-tools {
    padding: 0;
    border-bottom: 0;
}

.upload-form {
    display: grid;
    gap: 16px;
}

.import-table {
    min-width: 1320px;
}

.row-error {
    background: #fff7f7;
}

.error-cell {
    color: var(--danger);
    min-width: 240px;
}

.table-meta,
.pagination-bar {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line-soft);
    color: var(--muted);
}

.btn-mini {
    min-height: 30px;
    padding: 4px 10px;
    background: #1d1d1b;
    border-color: #343434;
    color: #f6f4ee;
    font-size: 12px;
}

.btn-mini.is-revealed {
    background: #fff8ea;
    border-color: #efd2a7;
    color: #744210;
    font-family: Consolas, "Liberation Mono", monospace;
}

.table-meta strong {
    color: #101828;
    font-size: 18px;
}

.pagination-bar {
    border-top: 1px solid var(--line-soft);
    border-bottom: 0;
}

.pagination-bar > div {
    display: flex;
    gap: 8px;
}

.btn.disabled {
    pointer-events: none;
    opacity: .45;
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        padding: 16px;
    }

    .brand {
        padding-bottom: 14px;
    }

    .side-nav {
        display: flex;
        margin-top: 14px;
        overflow-x: auto;
    }

    .page {
        width: min(100% - 28px, 780px);
        padding-top: 22px;
    }

    .page-heading,
    .topbar,
    .topbar-actions,
    .form-section {
        align-items: stretch;
        flex-direction: column;
    }

    .metric-grid,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: auto;
    }

    .search-form,
    .filter-form {
        align-items: stretch;
        flex-direction: column;
    }

    .filter-form .form-control,
    .filter-form .form-select {
        flex-basis: auto;
    }
}

.auth-body {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(90deg, #1d1d1b 0, #1d1d1b 30%, transparent 30%),
        var(--bg);
}

.auth-shell {
    width: min(100%, 460px);
}

.login-card {
    padding: 28px;
    background: rgba(255, 255, 255, .97);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
}

.login-brand {
    display: flex;
    gap: 14px;
    align-items: center;
    margin-bottom: 24px;
}

.login-brand h1 {
    margin: 2px 0 0;
    font-size: 28px;
}

.login-form {
    display: grid;
    gap: 16px;
}

.login-form .btn {
    width: 100%;
    margin-top: 4px;
}

.cover-thumb { width: 54px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); vertical-align: middle; }
.inline-upload { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-upload input[type=file] { max-width: 230px; font-size: 12px; }
