:root {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --ink: #171923;
    --muted: #667085;
    --line: #d9dee7;
    --blue: #2457c5;
    --green: #1b7f58;
    --amber: #b75e00;
    --red: #b42318;
    --violet: #6d3fc8;
    --shadow: 0 14px 34px rgba(22, 28, 45, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
}

button,
input,
textarea {
    font: inherit;
}

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

.app-shell {
    max-width: 1500px;
    margin: 0 auto;
    padding: 24px;
}

.topbar,
.panel-heading,
.subhead,
.topbar-actions,
.event-actions,
.paper-row {
    display: flex;
    align-items: center;
}

.topbar {
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.topbar h1,
.panel h2,
.subhead h3 {
    margin: 0;
    letter-spacing: 0;
}

.topbar h1 {
    font-size: 28px;
    line-height: 1.2;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--blue);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.topbar-actions {
    gap: 8px;
}

.button {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    min-height: 38px;
    padding: 0 14px;
    cursor: pointer;
    font-weight: 750;
}

.button:hover {
    border-color: #aab4c5;
}

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

.button.warn {
    border-color: #f0b35a;
    background: #fff3dc;
    color: #6e3a00;
}

.button.ghost {
    background: transparent;
}

.button.small {
    min-height: 30px;
    padding: 0 9px;
    font-size: 12px;
}

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

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

.metric span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
    text-transform: uppercase;
}

.metric strong {
    display: block;
    margin-top: 6px;
    font-size: 26px;
}

.workspace {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr) 310px;
    gap: 12px;
    align-items: start;
}

.monitor-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 12px;
    align-items: start;
}

.camera-stage {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #111827;
    aspect-ratio: 16 / 9;
}

.camera-stage video,
.camera-stage canvas,
.camera-placeholder {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.camera-stage video {
    object-fit: cover;
}

.camera-stage canvas {
    pointer-events: none;
}

.camera-placeholder {
    display: grid;
    place-items: center;
    color: #d9dee7;
    font-weight: 800;
}

.camera-status {
    margin-top: 10px;
    color: var(--muted);
    line-height: 1.45;
}

.check-row {
    display: flex;
    grid-template-columns: none;
    align-items: center;
    gap: 8px;
}

.check-row input {
    width: auto;
}

.monitor-log {
    display: grid;
    gap: 8px;
    max-height: 420px;
    overflow: auto;
}

.log-item {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfe;
    padding: 9px;
    color: #4b5565;
    line-height: 1.35;
}

.log-item.alert {
    border-color: #f2a6a0;
    background: #fff6f5;
    color: var(--red);
    font-weight: 800;
}

.log-item.error {
    border-color: #f0b35a;
    background: #fff3dc;
    color: #6e3a00;
}

.panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
    padding: 16px;
}

.panel-heading {
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.panel-heading p {
    margin: 4px 0 0;
    color: var(--muted);
}

.stack {
    display: grid;
    gap: 12px;
}

.stack.compact {
    gap: 10px;
}

label {
    display: grid;
    gap: 6px;
    color: #394150;
    font-size: 12px;
    font-weight: 750;
}

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

textarea {
    resize: vertical;
    line-height: 1.45;
}

input:focus,
textarea:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(36, 87, 197, 0.12);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.split {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.subhead {
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.subhead span {
    color: var(--muted);
    font-size: 12px;
}

.seat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
    gap: 8px;
}

.seat {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    min-height: 116px;
    background: #fbfcfe;
    overflow: hidden;
}

.seat.alert {
    border-color: #f2a6a0;
    background: #fff6f5;
}

.seat.assigned {
    border-color: #9fd8c1;
}

.seat-top,
.student-line {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.seat-top strong {
    font-size: 18px;
}

.status-pill {
    align-self: flex-start;
    border-radius: 999px;
    padding: 3px 7px;
    background: #edf2ff;
    color: var(--blue);
    font-size: 11px;
    font-weight: 800;
}

.status-pill.high,
.status-pill.new {
    background: #fff1f0;
    color: var(--red);
}

.status-pill.confirmed {
    background: #e8f7f0;
    color: var(--green);
}

.status-pill.dismissed {
    background: #edf0f5;
    color: #5c6676;
}

.status-pill.review {
    background: #fff3dc;
    color: var(--amber);
}

.student-line {
    margin-top: 10px;
    color: var(--muted);
    min-width: 0;
}

.student-line span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.paper-id {
    display: block;
    margin-top: 8px;
    color: #111827;
    font-weight: 850;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.event-list,
.paper-list {
    display: grid;
    gap: 8px;
    max-height: 640px;
    overflow: auto;
}

.event {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 11px;
}

.event.high {
    border-left: 4px solid var(--red);
}

.event.medium {
    border-left: 4px solid var(--amber);
}

.event h4 {
    margin: 0;
    font-size: 14px;
}

.event p {
    margin: 8px 0;
    color: #4b5565;
    line-height: 1.35;
}

.event .event-note {
    color: #667085;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
    overflow-wrap: anywhere;
}

.event-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
}

.event-actions {
    gap: 6px;
    margin-top: 10px;
}

.divider {
    height: 1px;
    margin: 16px 0;
    background: var(--line);
}

.paper-row {
    justify-content: space-between;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px;
    background: #fbfcfe;
}

.paper-row div {
    min-width: 0;
}

.paper-row strong,
.paper-row span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.paper-row span {
    color: var(--muted);
    font-size: 12px;
}

.toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    max-width: 360px;
    border: 1px solid #f2a6a0;
    border-radius: 8px;
    background: #fff6f5;
    color: var(--red);
    padding: 14px 16px;
    box-shadow: 0 18px 50px rgba(22, 28, 45, 0.18);
    font-weight: 800;
}

.paper-body {
    background: #e7eaf0;
}

.paper-sheet {
    width: 210mm;
    min-height: 297mm;
    margin: 18px auto;
    padding: 16mm;
    background: #fff;
    color: #111827;
    box-shadow: 0 18px 60px rgba(17, 24, 39, 0.18);
}

.paper-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    border-bottom: 2px solid #111827;
    padding-bottom: 12px;
}

.paper-header h1 {
    margin: 0 0 6px;
    font-size: 28px;
}

.paper-header p {
    margin: 0;
}

.paper-marker {
    display: grid;
    justify-items: center;
    gap: 4px;
    min-width: 168px;
    max-width: 190px;
    color: #111827;
}

.paper-marker .qr {
    width: 116px;
    height: 116px;
}

.paper-marker strong {
    font-size: 14px;
}

.paper-marker span {
    color: #4b5565;
    font-size: 12px;
    font-weight: 800;
}

.identity-strip {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 12px 0;
}

.identity-strip div {
    border: 1px solid #cdd5df;
    border-radius: 6px;
    padding: 9px;
}

.identity-strip span {
    display: block;
    color: #667085;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
}

.identity-strip strong {
    display: block;
    margin-top: 4px;
}

.policy-line {
    border: 1px solid #cdd5df;
    border-radius: 6px;
    background: #f8fafc;
    padding: 8px;
    font-size: 11px;
    color: #475467;
}

.canary-page {
    max-width: 560px;
    margin: 12vh auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 28px;
    box-shadow: var(--shadow);
}

.canary-page h1 {
    margin: 0 0 10px;
}

.canary-page p {
    color: #4b5565;
    line-height: 1.5;
}

.resource-card-page {
    max-width: 620px;
    margin: 10vh auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 28px;
    box-shadow: var(--shadow);
}

.resource-card-page h1 {
    margin: 0 0 12px;
}

.resource-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.resource-card-meta span {
    border: 1px solid var(--line);
    border-radius: 999px;
    color: #4b5565;
    padding: 5px 9px;
}

.resource-card-lines {
    display: grid;
    gap: 10px;
    border: 1px solid #cdd5df;
    border-radius: 8px;
    background: #f8fafc;
    margin: 0;
    padding: 16px 18px 16px 30px;
    line-height: 1.55;
}

.resource-card-note {
    color: var(--red);
    font-weight: 800;
    margin: 14px 0 0;
}

.question {
    margin-top: 14px;
    break-inside: avoid;
    position: relative;
}

.q-meta {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
    border-bottom: 1px solid #111827;
    padding-bottom: 4px;
}

.q-meta span {
    color: #475467;
    font-size: 12px;
    font-weight: 800;
}

.q-resource {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    max-width: 210px;
    position: relative;
    color: #1f2937;
    font-size: 9px;
    font-weight: 750;
    line-height: 1.25;
    text-align: left;
}

.q-resource .qr {
    width: 132px;
    height: 132px;
    flex: 0 0 auto;
    border: 1px solid #f1f4f8;
    padding: 3px;
}

.q-resource .qr-caption {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.q-resource span.qr-triggerhint {
    position: absolute;
    left: -10px;
    right: -10px;
    top: -11px;
    width: auto;
    max-height: 9px;
    overflow: hidden;
    color: #dce4ef;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 2.8px;
    font-weight: 900;
    line-height: 1.02;
    letter-spacing: 0;
    opacity: 0.86;
    pointer-events: none;
    user-select: none;
    text-align: left;
}

.q-resource span.qr-microhint {
    position: absolute;
    left: -14px;
    right: -14px;
    bottom: -16px;
    width: auto;
    max-height: 14px;
    overflow: hidden;
    color: #e5eaf2;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 2.4px;
    font-weight: 800;
    line-height: 1.05;
    opacity: 0.72;
    pointer-events: none;
    user-select: none;
    text-align: left;
}

.q-resource span {
    color: #1f2937;
    font-size: 11px;
    overflow-wrap: anywhere;
}

.q-resource code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-weight: 850;
}

.resource-note {
    color: #667085;
    font-size: 9px;
    font-weight: 800;
    line-height: 1.2;
    margin: -4px 0 8px;
}

.question p:not(.machine-hint):not(.resource-note) {
    font-size: 15px;
    line-height: 1.45;
}

.question .qr-dependency-notice {
    border-left: 2px solid #cdd5df;
    color: #475467;
    font-size: 10px;
    font-weight: 750;
    margin: 8px 0 0;
    padding: 4px 8px;
}

.answer-lines {
    height: 88px;
    background-image: linear-gradient(to bottom, transparent 30px, #d6dbe4 31px);
    background-size: 100% 31px;
}

@media (max-width: 1180px) {
    .workspace,
    .split,
    .monitor-grid {
        grid-template-columns: 1fr;
    }

    .metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .app-shell {
        padding: 12px;
    }

    .topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .metrics,
    .seat-grid,
    .identity-strip {
        grid-template-columns: 1fr;
    }

    .paper-sheet {
        width: auto;
        margin: 0;
        padding: 12mm;
        box-shadow: none;
    }
}

@media print {
    body.paper-body {
        background: #fff;
    }

    .paper-sheet {
        margin: 0;
        box-shadow: none;
        width: auto;
        min-height: auto;
    }
}
