:root {
    --bg: #f6f7f4;
    --surface: #ffffff;
    --surface-2: #eef3f0;
    --text: #1e2528;
    --muted: #667276;
    --line: #d8dfdc;
    --primary: #116466;
    --primary-strong: #0b4f51;
    --accent: #c47a1c;
    --danger: #b73b3b;
    --success: #217a4a;
    --warning: #9a6b10;
    --shadow: 0 18px 42px rgba(31, 45, 50, 0.08);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    margin: 0;
    min-height: 100%;
    color: var(--text);
    background: var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button,
input,
select,
textarea {
    font: inherit;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    padding: 11px 12px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(17, 100, 102, 0.14);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

td small {
    display: block;
    color: var(--muted);
    margin-top: 2px;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 20px;
    min-height: 68px;
    padding: 0 28px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-weight: 800;
    white-space: nowrap;
}

.brand:hover {
    text-decoration: none;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-size: 13px;
    letter-spacing: 0;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    overflow-x: auto;
}

.menu-toggle {
    display: none;
    width: 42px;
    height: 42px;
    margin-left: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    place-items: center;
    gap: 4px;
}

.menu-toggle span:not(.sr-only) {
    display: block;
    width: 20px;
    height: 2px;
    border-radius: 2px;
    background: var(--text);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--muted);
    font-weight: 650;
    white-space: nowrap;
}

.nav-link.is-active,
.nav-link:hover {
    background: var(--surface-2);
    color: var(--text);
    text-decoration: none;
}

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

.user-chip {
    display: inline-flex;
    align-items: center;
    max-width: 360px;
    min-height: 34px;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.page {
    width: min(1240px, calc(100% - 32px));
    margin: 28px auto 56px;
}

.student-page {
    width: min(1080px, calc(100% - 32px));
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(17, 100, 102, 0.12), rgba(196, 122, 28, 0.08)),
        var(--bg);
}

.auth-panel {
    width: min(440px, 100%);
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

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

.auth-brand strong,
.auth-brand span {
    display: block;
}

.auth-brand span:not(.brand-mark) {
    color: var(--muted);
    font-size: 14px;
}

.auth-link {
    margin: 16px 0 0;
    text-align: center;
}

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

.page-header h1,
.auth-panel h1,
.student-entry h1,
.result-panel h1 {
    margin: 0;
    font-size: clamp(28px, 4vw, 42px);
    line-height: 1.08;
}

.page-header p,
.student-entry p,
.result-panel p,
.muted {
    color: var(--muted);
}

.panel,
.empty-state,
.test-card,
.question-editor,
.review-block,
.result-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.panel {
    padding: 20px;
}

.page > .panel,
.page > .empty-state {
    margin-bottom: 22px;
}

.panel-header,
.question-editor-head,
.review-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.panel-header h2,
.question-editor h3,
.review-block h2 {
    margin: 0;
}

.content-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
    gap: 20px;
    align-items: start;
}

.side-panel {
    position: sticky;
    top: 88px;
}

.narrow-panel {
    max-width: 760px;
}

.form-stack {
    display: grid;
    gap: 14px;
}

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

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

.field > span,
.checkbox-field span {
    color: var(--text);
    font-weight: 700;
}

.field-wide {
    grid-column: 1 / -1;
}

.field-hint {
    color: var(--muted);
}

.checkbox-field {
    display: flex;
    align-items: center;
    gap: 10px;
}

.checkbox-field input {
    width: 18px;
    height: 18px;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font-weight: 750;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.button:hover {
    text-decoration: none;
    border-color: var(--primary);
}

.button-primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.button-primary:hover {
    background: var(--primary-strong);
}

.button-ghost {
    background: transparent;
}

.button-small {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 13px;
}

.button-large {
    min-height: 48px;
    padding-inline: 22px;
}

.button-danger {
    border-color: rgba(183, 59, 59, 0.35);
    color: var(--danger);
}

.button[disabled] {
    cursor: not-allowed;
    opacity: 0.5;
}

.alert {
    padding: 12px 14px;
    margin-bottom: 18px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
}

.alert-success {
    border-color: rgba(33, 122, 74, 0.3);
    background: rgba(33, 122, 74, 0.08);
}

.alert-error,
.alert-warning {
    border-color: rgba(154, 107, 16, 0.32);
    background: rgba(196, 122, 28, 0.1);
}

.alert-error {
    border-color: rgba(183, 59, 59, 0.32);
    background: rgba(183, 59, 59, 0.08);
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 800;
    color: var(--text);
    background: var(--surface-2);
}

.badge-success {
    color: var(--success);
    background: rgba(33, 122, 74, 0.12);
}

.badge-warning {
    color: var(--warning);
    background: rgba(196, 122, 28, 0.13);
}

.badge-danger {
    color: var(--danger);
    background: rgba(183, 59, 59, 0.11);
}

.stat-grid,
.result-grid,
.student-work-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}

.stat-card,
.result-card,
.student-work-card {
    display: grid;
    gap: 6px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

tr.is-low-score td,
.student-work-card.is-low-score {
    border-color: rgba(183, 59, 59, 0.5);
    background: rgba(183, 59, 59, 0.1);
}

tr.is-low-score td:first-child,
.student-work-card.is-low-score strong {
    color: var(--danger);
}

.stat-card span,
.stat-card small,
.result-card span:not(.result-card-title),
.student-work-card span {
    color: var(--muted);
}

.stat-card strong {
    font-size: 34px;
    line-height: 1;
}

.result-card-title {
    color: var(--text);
    font-size: 18px;
    font-weight: 850;
}

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

.empty-state {
    padding: 42px 28px;
    text-align: center;
}

.empty-state h2 {
    margin: 0 0 8px;
}

.empty-state p {
    margin: 0 auto;
    max-width: 560px;
    color: var(--muted);
}

.empty-action {
    margin-top: 20px;
}

.student-entry {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
    gap: 40px;
    align-items: center;
    min-height: calc(100vh - 124px);
}

.entry-copy {
    max-width: 640px;
}

.entry-copy p:last-child {
    font-size: 18px;
}

.entry-form {
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--accent);
    font-size: 13px;
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: 0;
}

.secondary-link {
    justify-self: center;
}

.card-list {
    display: grid;
    gap: 14px;
}

.folder-heading {
    margin: 24px 0 2px;
    font-size: 18px;
}

.test-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 18px;
}

.test-card h3 {
    margin: 8px 0 4px;
}

.test-card p {
    margin: 0;
    color: var(--muted);
}

.card-kicker,
.result-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
}

.card-actions {
    flex: 0 0 auto;
}

.test-session {
    position: relative;
}

.test-topbar {
    position: sticky;
    top: 68px;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(12px);
}

.test-topbar h1 {
    margin: 0;
    font-size: clamp(22px, 3vw, 32px);
}

.timer {
    min-width: 124px;
    padding: 10px 14px;
    border-radius: 8px;
    background: var(--text);
    color: #fff;
    text-align: center;
    font-size: 18px;
    font-weight: 900;
}

.timer-box {
    display: grid;
    gap: 5px;
    justify-items: end;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.timer.is-low {
    background: var(--danger);
}

.proctor-note {
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid rgba(196, 122, 28, 0.34);
    border-radius: 8px;
    background: rgba(196, 122, 28, 0.1);
    color: #6f4a0d;
}

.test-form,
.question-editor-list,
.review-list {
    display: grid;
    gap: 16px;
}

.question-block {
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.question-number {
    color: var(--accent);
    font-weight: 850;
    font-size: 13px;
}

.question-block h2 {
    margin: 8px 0 18px;
    font-size: clamp(20px, 2.4vw, 28px);
}

.answer-list {
    display: grid;
    gap: 10px;
}

.answer-option {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
}

.answer-option:hover {
    border-color: var(--primary);
    background: var(--surface-2);
}

.answer-option input {
    width: 18px;
    height: 18px;
    margin-top: 3px;
}

.answer-text {
    max-width: 680px;
}

.submit-panel {
    display: flex;
    justify-content: flex-end;
    padding: 18px 0;
}

.security-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    place-items: center;
    padding: 24px;
    background: rgba(30, 37, 40, 0.78);
    color: #fff;
}

.security-overlay.is-visible {
    display: grid;
}

.security-overlay > div {
    max-width: 480px;
    padding: 26px;
    border-radius: 8px;
    background: #1e2528;
    text-align: center;
}

.result-panel {
    max-width: 720px;
    margin: 60px auto;
    padding: 34px;
    text-align: center;
}

.score-big {
    margin: 22px auto;
    font-size: clamp(54px, 10vw, 96px);
    line-height: 1;
    font-weight: 950;
    color: var(--primary);
}

.score-done {
    font-size: clamp(42px, 8vw, 72px);
}

.details-list {
    display: grid;
    gap: 10px;
}

.group-details {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
}

.group-details summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    cursor: pointer;
}

.group-details summary strong,
.group-details summary small {
    display: block;
}

.group-details summary small {
    color: var(--muted);
    margin-top: 2px;
}

.details-metrics {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.group-details .table-wrap {
    border-top: 1px solid var(--line);
}

.result-meta {
    justify-content: center;
    margin-bottom: 24px;
}

.inline-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.question-editor {
    padding: 18px;
}

.review-block {
    padding: 20px;
}

.answer-review {
    display: grid;
    gap: 8px;
    padding: 0;
    margin: 0;
    list-style: none;
}

.answer-review li,
.text-review {
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.answer-review li.is-selected {
    border-color: var(--accent);
    background: rgba(196, 122, 28, 0.1);
}

.answer-review li.is-correct {
    border-color: rgba(33, 122, 74, 0.42);
    background: rgba(33, 122, 74, 0.1);
}

.duration-pill {
    display: inline-flex;
    color: var(--muted);
}

@media (max-width: 980px) {
    .app-header {
        align-items: flex-start;
        flex-wrap: wrap;
        padding: 14px 16px;
    }

    .menu-toggle {
        display: grid;
    }

    .main-nav {
        order: 3;
        width: 100%;
        display: none;
        flex-direction: column;
        align-items: stretch;
        padding-top: 10px;
        overflow: visible;
    }

    .main-nav.is-open {
        display: flex;
    }

    .nav-link {
        width: 100%;
    }

    .header-actions {
        order: 4;
        width: 100%;
        margin-left: 0;
    }

    .content-grid,
    .student-entry,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .side-panel {
        position: static;
    }
}

@media (max-width: 640px) {
    .page,
    .student-page {
        width: min(100% - 20px, 1240px);
        margin-top: 16px;
    }

    .app-header {
        min-height: auto;
    }

    .header-actions,
    .page-header,
    .test-card,
    .test-topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .user-chip {
        max-width: 100%;
    }

    .group-details summary {
        align-items: flex-start;
        flex-direction: column;
    }

    .details-metrics {
        justify-content: flex-start;
    }

    .panel,
    .entry-form,
    .question-block,
    .result-panel {
        padding: 16px;
    }

    .card-actions,
    .card-actions form,
    .button {
        width: 100%;
    }

    th,
    td {
        padding: 10px;
    }
}
