:root {
    --paper: #f5f4f0;
    --surface: #ffffff;
    --sunk: #fbfaf8;
    --ink: #1a1b1e;
    --ink-2: #44474d;
    --muted: #767980;
    --line: #e2e0da;
    --line-strong: #cfccc4;
    --accent: #1f3f66;
    --accent-hover: #17314f;
    --accent-soft: #e8eef6;
    --good: #2d6a3e;   --good-soft: #e6f1e9;
    --warn: #8a5a12;   --warn-soft: #f8efdf;
    --bad: #9b3426;    --bad-soft: #f8e6e2;
    --radius: 8px;
    --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 14px/1.5 var(--sans); }
a { color: var(--accent); }
button, input, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 17px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--ink-2); }
.hint { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

/* ---------- top bar ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 12px 24px; display: flex; align-items: center; gap: 20px; }
.brand { display: flex; align-items: baseline; gap: 12px; min-width: 0; margin-right: auto; }
.brand-name { font-weight: 600; font-size: 17px; letter-spacing: -0.01em; }
.brand-sub { color: var(--muted); font-size: 13px; white-space: nowrap; }
.switch { display: inline-flex; background: #efede8; border-radius: 7px; padding: 3px; gap: 2px; }
.switch a { text-decoration: none; color: var(--ink-2); font-size: 13px; font-weight: 500; padding: 6px 14px; border-radius: 5px; }
.switch a:hover { color: var(--ink); }
.switch a.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.grader { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: none; }
.dot.off { background: var(--bad); }

/* ---------- layout ---------- */
.layout { max-width: 1240px; margin: 0 auto; padding: 28px 24px 64px; display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 28px; align-items: start; }
.layout > * { min-width: 0; }
.narrow { max-width: 720px; margin: 0 auto; padding: 32px 24px 64px; }
.stack > * + * { margin-top: 20px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { padding: 18px 20px 0; }
.panel-body { padding: 16px 20px 20px; }
.section { padding: 18px 20px; border-top: 1px solid var(--line); }

/* ---------- forms ---------- */
.drop { display: block; border: 1.5px dashed var(--line-strong); border-radius: var(--radius); padding: 28px 16px; text-align: center; cursor: pointer; background: var(--sunk); transition: border-color .15s, background .15s; }
.drop:hover, .drop.is-over { border-color: var(--accent); background: var(--accent-soft); }
.drop:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.drop-title { font-weight: 500; }
.drop-types { color: var(--muted); font-size: 12px; margin-top: 2px; }
.drop-file { margin-top: 10px; font-size: 13px; color: var(--accent); font-weight: 500; word-break: break-all; }
.drop-file:empty { display: none; }
label.field { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin: 18px 0 6px; }
textarea { width: 100%; resize: vertical; min-height: 110px; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); font-size: 13px; line-height: 1.5; }
textarea:focus, input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.field-note { color: var(--muted); font-size: 12px; margin-top: 6px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); border-radius: 6px; padding: 8px 14px; font-weight: 500; font-size: 13px; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f3f2ee; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-block { width: 100%; padding: 11px 14px; margin-top: 18px; font-size: 14px; }
.btn[disabled] { opacity: .65; cursor: progress; }
.btn-link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 500; font-size: 13px; cursor: pointer; text-decoration: none; }
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--muted); }
.btn-link.danger:hover { color: var(--bad); }

/* ---------- messages ---------- */
.flash, .notice { border-radius: var(--radius); padding: 12px 14px; font-size: 13px; border: 1px solid; }
.flash { margin-bottom: 16px; }
.flash.success, .notice.good { background: var(--good-soft); border-color: #c6dfcd; color: var(--good); }
.flash.warning, .notice.warn { background: var(--warn-soft); border-color: #ead7b4; color: var(--warn); }
.flash.error { background: var(--bad-soft); border-color: #ecc9c1; color: var(--bad); }
.notice.info { background: var(--accent-soft); border-color: #cfdbea; color: var(--accent); }

/* ---------- rubric list (student upload page) ---------- */
.rubric-list { list-style: none; margin: 8px 0 0; padding: 0; }
.rubric-list li { display: grid; grid-template-columns: 44px 1fr; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.rubric-list li:first-child { border-top: 0; }
.rubric-list .w { font-weight: 600; font-variant-numeric: tabular-nums; }
.rubric-list .d { color: var(--muted); }

.mine { list-style: none; margin: 0; padding: 0; }
.mine li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 13px; }
.mine li:first-child { border-top: 0; }
.mine .when { color: var(--muted); white-space: nowrap; }

/* ---------- lecturer ranking ---------- */
.rank-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 18px 20px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.stats { display: flex; gap: 28px; margin-top: 12px; flex-wrap: wrap; }
.stat-value { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--muted); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 14px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfaf7; }
th:first-child, td:first-child { padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; }
.col-rank { width: 44px; color: var(--muted); font-variant-numeric: tabular-nums; }
.student-name { font-weight: 500; color: var(--ink); text-decoration: none; }
a.student-name:hover { color: var(--accent); text-decoration: underline; }
.reg { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
.reg.missing { font-family: var(--sans); color: var(--warn); }
.score { width: 104px; }
.score-num { font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums; }
.score-num small { font-weight: 400; color: var(--muted); font-size: 12px; }
.bar { height: 4px; background: #ebe9e3; border-radius: 2px; margin-top: 6px; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 2px; }
.bar .high { background: var(--good); } .bar .mid { background: var(--accent); } .bar .low { background: var(--warn); }
.feedback p { margin: 0; font-size: 13px; color: var(--ink-2); display: grid; grid-template-columns: 14px 1fr; gap: 4px; }
.feedback p + p { margin-top: 4px; }
.sign { font-weight: 600; }
.plus .sign { color: var(--good); }
.minus .sign { color: var(--warn); }
.none { color: var(--muted); font-style: italic; }
.file { font-size: 12px; margin-top: 6px; display: inline-block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: top; }
.status { display: inline-block; font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 4px; white-space: nowrap; }
.status.Approved { background: var(--good-soft); color: var(--good); }
.status.Draft { background: var(--accent-soft); color: var(--accent); }
.status.Pending { background: var(--warn-soft); color: var(--warn); }
.actions { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; white-space: nowrap; }
.actions form { margin: 0; }
.empty { padding: 56px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-weight: 500; margin-bottom: 4px; }

/* ---------- student report ---------- */
.back { display: inline-block; font-size: 13px; margin-bottom: 14px; text-decoration: none; }
.back:hover { text-decoration: underline; }
.report-head { display: flex; justify-content: space-between; gap: 20px; padding: 22px 20px; align-items: flex-start; }
.report-head .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.big-score { text-align: right; flex: none; }
.big-score .num { font-size: 34px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.big-score .num small { font-size: 15px; font-weight: 400; color: var(--muted); }
.big-score .status { margin-top: 8px; }
.crit { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 4px 20px; padding: 14px 0; border-top: 1px solid var(--line); }
.crit:first-of-type { border-top: 0; padding-top: 6px; }
.crit-name { font-weight: 500; }
.crit-name small { color: var(--muted); font-weight: 400; margin-left: 4px; }
.crit-score { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.crit-score small { color: var(--muted); font-weight: 400; font-size: 12px; }
.crit .bar { grid-column: 1 / -1; margin-top: 2px; }
.crit-comment { grid-column: 1 / -1; color: var(--ink-2); font-size: 13px; margin: 4px 0 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.two-col p, .prose { margin: 6px 0 0; color: var(--ink-2); }
.label-plus { color: var(--good); }
.label-minus { color: var(--warn); }
.note { background: var(--sunk); border-left: 3px solid var(--accent); padding: 12px 14px; border-radius: 0 6px 6px 0; margin-top: 8px; color: var(--ink-2); }

.doc-actions { display: flex; align-items: center; gap: 14px; margin-top: 12px; }
.members { list-style: none; margin: 8px 0 0; padding: 0; columns: 2; column-gap: 28px; }
.members li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; break-inside: avoid; }
.reg.dup { color: var(--bad); font-weight: 500; }

/* ---------- brief completeness checklist ---------- */
.req-list { list-style: none; margin: 8px 0 0; padding: 0; }
.req-list li { display: grid; grid-template-columns: 20px 1fr; gap: 6px; padding: 5px 0; font-size: 13px; color: var(--ink-2); }
.req-list .mark { font-weight: 700; text-align: center; }
.req-list .ok .mark { color: var(--good); }
.req-list .no .mark { color: var(--bad); }
.req-list .no em { color: var(--bad); font-style: normal; font-size: 12px; }
.req-list.compact li { font-size: 12.5px; padding: 3px 0; }

/* ---------- course materials ---------- */
.text-input { width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); }
.file-input { width: 100%; font-size: 13px; }
.check { display: flex; gap: 8px; align-items: flex-start; margin-top: 14px; font-size: 12.5px; color: var(--ink-2); line-height: 1.4; }
.check input { margin-top: 2px; flex: none; }
.mat-actions form { margin: 0; }
.mat-list { list-style: none; margin: 16px 0 0; padding: 0; }
.panel-body > .mat-list:first-child { margin-top: 0; }
.mat-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.mat-list li:first-child { border-top: 0; }
.mat-main { min-width: 0; display: flex; flex-direction: column; }
.mat-main a, .mat-title { font-weight: 500; overflow-wrap: anywhere; }
.mat-meta { color: var(--muted); font-size: 12px; }
.mat-actions { display: flex; align-items: center; gap: 14px; flex: none; }

/* ---------- document viewer ---------- */
.viewer-layout.single { grid-template-columns: minmax(0, 1fr); max-width: 1100px; }
.viewer-layout { max-width: 1400px; margin: 0 auto; padding: 24px 24px 64px; display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.viewer-layout > * { min-width: 0; }
.doc-bar { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.doc-title { min-width: 0; }
.doc-title .back { margin-bottom: 6px; }
.doc-title h1 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-title .meta { color: var(--muted); font-size: 13px; }
.doc-stage { background: #e8e6e0; padding: 24px; border-radius: 0 0 var(--radius) var(--radius); min-height: 60vh; }
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.pdf-page { width: 100%; height: auto; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 4px 14px rgba(0, 0, 0, .06); }
.docx-sheet { background: #fff; max-width: 820px; margin: 0 auto; padding: 56px 64px; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); color: #222; font-size: 14px; line-height: 1.6; overflow-wrap: break-word; }
.docx-sheet img { max-width: 100%; height: auto; }
.docx-sheet table { border-collapse: collapse; margin: 12px 0; }
.docx-sheet td, .docx-sheet th { border: 1px solid #d6d3cc; padding: 6px 8px; }
.docx-sheet h1, .docx-sheet h2, .docx-sheet h3 { color: #111; margin: 1.2em 0 .4em; }
.doc-loading { color: var(--muted); text-align: center; padding: 48px 0; margin: 0; }
.code-sheet { background: #fff; margin: 0 auto; max-width: 960px; padding: 20px 24px; font: 13px/1.6 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); border-radius: 4px; }
#fallback .notice { max-width: 960px; margin: 0 auto 16px; }
.eval-panel { position: sticky; top: 76px; }
.eval-score { display: flex; align-items: baseline; gap: 6px; margin: 14px 0 6px; }
.eval-score .num { font-size: 30px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.eval-score small { color: var(--muted); }
.eval-score .status { margin-left: auto; }
.mini-crit { padding: 10px 0; border-top: 1px solid var(--line); }
.mini-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 500; }
.mini-head small { color: var(--muted); font-weight: 400; }
.mini-crit p { margin: 6px 0 0; font-size: 12.5px; color: var(--ink-2); }

/* ---------- dialog ---------- */
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; width: min(500px, calc(100vw - 32px)); color: var(--ink); box-shadow: 0 20px 50px rgba(20, 20, 30, .18); }
dialog::backdrop { background: rgba(26, 27, 30, .45); }
.dlg-head { padding: 18px 20px 0; }
.dlg-body { padding: 4px 20px 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
dialog label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin: 14px 0 6px; }
dialog input, dialog textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); }
dialog textarea { min-height: 70px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
    .viewer-layout { grid-template-columns: minmax(0, 1fr); padding: 16px 16px 48px; }
    .eval-panel { position: static; }
}
@media (max-width: 960px) {
    .layout { grid-template-columns: minmax(0, 1fr); padding: 20px 16px 48px; }
    .narrow { padding: 20px 16px 48px; }
    .topbar-inner { padding: 10px 16px; gap: 12px; }
    .brand-sub { display: none; }
}
@media (max-width: 720px) {
    table, tbody, tr, td { display: block; }
    thead { display: none; }
    tr { position: relative; padding: 16px 16px 16px 48px; border-bottom: 1px solid var(--line); }
    tr:last-child { border-bottom: 0; }
    td, td:first-child, td:last-child { padding: 0; border: 0; }
    td + td { margin-top: 10px; }
    td.col-rank { position: absolute; left: 16px; top: 16px; margin: 0; }
    .score { width: auto; }
    .bar { max-width: 180px; }
    .crit .bar { max-width: none; }
    .file { max-width: 100%; }
    .actions { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 16px; }
    .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .doc-stage { padding: 10px; }
    .docx-sheet { padding: 24px 18px; }
    .code-sheet { padding: 14px; }
    .doc-bar { align-items: flex-start; flex-direction: column; }
    .members { columns: 1; }
}
@media (max-width: 520px) {
    .grader-text { display: none; }
    .brand-name { font-size: 16px; }
    .report-head { flex-direction: column; }
    .big-score { text-align: left; }
    .grid-2 { grid-template-columns: 1fr; }
}
