/* ============================================================================
   Grading Platform v2 — single stylesheet.
   Sections: 1 base · 2 chrome · 3 components · 4 forms · 5 help tooltips ·
   6 charts/bars · 7 workbench · 8 viewer overlays (shared grader/student) ·
   9 responsive. Design tokens up top; keep new styles on these variables.
   ========================================================================== */

:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1c2733;
  --muted: #66788c;
  --line: #dde4ec;
  --brand: #14532d;      /* deep green */
  --brand-soft: #e6f4ea;
  --accent: #1d4ed8;
  --danger: #b91c1c;
  --warn-bg: #fef3c7;
  --ok: #15803d;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
  font-size: 15px;
}

/* 1 ── base -------------------------------------------------------------- */
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: .2rem 0 .8rem; }
h2 { font-size: 1.1rem; margin: .2rem 0 .7rem; }
h3 { font-size: 1rem; }
code { background: #eef2f7; padding: .05rem .3rem; border-radius: 4px; font-size: .85em; }
blockquote { margin: .4rem 0; padding: .4rem .8rem; border-left: 3px solid var(--line); color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* 2 ── chrome ------------------------------------------------------------ */
.topbar { display: flex; align-items: center; gap: 1.2rem; background: var(--brand); color: #fff; padding: .55rem 1.2rem; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.topnav { display: flex; gap: .9rem; flex-wrap: wrap; }
.topnav a { color: #d9e8dd; }
.topnav a:hover { color: #fff; text-decoration: none; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: .6rem; color: #d9e8dd; }
.userbox a { color: #d9e8dd; }
.username { font-weight: 600; color: #fff; }
.main { max-width: 1180px; margin: 1.2rem auto 3rem; padding: 0 1rem; }
.main-bare { margin: 0; padding: 0; }
.flash { max-width: 1180px; margin: .6rem auto 0; padding: .55rem .9rem; border-radius: var(--radius); font-size: .92rem; }
.flash-success { background: #dcfce7; color: #14532d; }
.flash-error { background: #fee2e2; color: #7f1d1d; }
.flash-info { background: #dbeafe; color: #1e3a8a; }
.crumbs { margin: 0 0 .4rem; font-size: .9rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* 3 ── components ---------------------------------------------------------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.2rem; margin-bottom: 1rem; }
.card.narrow { max-width: 560px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.card-link { display: block; color: inherit; }
.card-link:hover { text-decoration: none; border-color: var(--brand); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.error-card { max-width: 560px; margin: 3rem auto; text-align: center; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: .45rem .55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table thead th { color: var(--muted); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
.table .actions { white-space: nowrap; }
.row-muted { opacity: .55; }
.row-warn { background: var(--warn-bg); }
.q-cell { max-width: 420px; }
.scroll-x { overflow-x: auto; }
.chip { display: inline-block; background: #eef2f7; border-radius: 999px; padding: .08rem .55rem; font-size: .78rem; margin-right: .15rem; }
.chip-ok { background: #dcfce7; color: var(--ok); }
.chip-pending { background: var(--warn-bg); color: #92400e; }
.chip-warn { background: #fee2e2; color: var(--danger); }
.chip-co { background: var(--brand-soft); color: var(--brand); }
.chip-draft { background: #e5e7eb; }
.chip-grading { background: #dbeafe; color: #1e3a8a; }
.chip-released { background: #dcfce7; color: var(--ok); }
.stat-row { display: flex; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem 1rem; }
.stat-num { font-size: 1.3rem; font-weight: 700; margin-right: .3rem; }
.tabs { display: flex; gap: .2rem; margin-bottom: 1rem; border-bottom: 2px solid var(--line); flex-wrap: wrap; }
.tabs a { padding: .45rem .9rem; color: var(--muted); border-radius: 8px 8px 0 0; }
.tabs a.active { background: var(--card); color: var(--brand); font-weight: 600; border: 1px solid var(--line); border-bottom: 2px solid var(--card); margin-bottom: -2px; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.invite-code { font-size: 1.2rem; letter-spacing: .08em; background: var(--brand-soft); padding: .1rem .5rem; border-radius: 6px; }
.q-item { border-bottom: 1px solid var(--line); padding: .6rem 0; }
.q-text { margin: 0 0 .3rem; }
.q-meta { margin: 0 0 .3rem; }
.q-item .actions { margin: 0; }
.student-comment { background: var(--brand-soft); border-radius: 6px; padding: .25rem .55rem; margin-top: .3rem; font-size: .88rem; }
.recheck-item { border-bottom: 1px solid var(--line); padding: .4rem 0; }
.guide li { margin-bottom: .5rem; }
.help-list dt { margin-top: .6rem; }
.help-list dd { margin: .15rem 0 0 1rem; color: var(--muted); }
.status-card { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; }

/* 4 ── forms & buttons ----------------------------------------------------- */
label { display: block; margin-bottom: .7rem; font-size: .92rem; font-weight: 500; }
input[type=text], input[type=email], input[type=password], select, textarea {
  display: block; width: 100%; margin-top: .25rem; padding: .45rem .6rem;
  border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #a7c4ee; border-color: var(--accent); }
input.wide { min-width: 20rem; }
input[readonly] { background: #f1f5f9; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 .8rem; }
legend { font-size: .9rem; font-weight: 600; padding: 0 .3rem; }
.checkline { display: flex; gap: .5rem; align-items: flex-start; font-weight: 400; }
.checkline input { width: auto; margin-top: .25rem; }
.row-form { display: flex; gap: .8rem; align-items: flex-end; flex-wrap: wrap; }
.row-form label { margin-bottom: 0; }
.row-form input, .row-form select { width: auto; min-width: 8rem; }
.stack { display: flex; flex-direction: column; }
.btn { display: inline-block; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: .42rem .9rem; font: inherit; font-size: .9rem; cursor: pointer; color: var(--ink); }
.btn:hover { border-color: var(--brand); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: #0d3d20; }
.btn-small { padding: .2rem .6rem; font-size: .82rem; }
.btn-danger { color: var(--danger); border-color: #fca5a5; }
.linklike { background: none; border: none; color: inherit; cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }
.inline { display: inline; }
.inline-details { display: inline-block; }
.inline-details > summary { list-style: none; cursor: pointer; }
details > summary.btn { display: inline-block; margin: .3rem 0; }
.auth-card { max-width: 420px; margin: 3.5rem auto; }
.notice { background: var(--warn-bg); padding: .5rem .8rem; border-radius: 8px; }

/* 5 ── help tooltips -------------------------------------------------------- */
.help-tip { display: inline-flex; align-items: center; justify-content: center; width: 1.05rem; height: 1.05rem; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-size: .72rem; font-weight: 700; cursor: help; position: relative; vertical-align: middle; margin-left: .25rem; }
.help-pop { display: none; position: absolute; z-index: 60; left: 50%; transform: translateX(-50%); bottom: 140%; width: 20rem; max-width: 74vw; background: #1f2937; color: #f9fafb; font-weight: 400; font-size: .8rem; line-height: 1.4; padding: .55rem .7rem; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.25); white-space: normal; text-align: left; }
.help-tip:hover .help-pop, .help-tip:focus .help-pop { display: block; }

/* 6 ── attainment bars ------------------------------------------------------ */
.bar-row { display: flex; align-items: center; gap: .6rem; margin: .3rem 0; }
.bar-label { width: 3.4rem; font-weight: 600; font-size: .88rem; cursor: default; }
.bar { flex: 1; height: .8rem; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--brand); border-radius: 999px; }
.bar-fill.bar-alt { background: var(--accent); }
.bar-num { min-width: 4.5rem; font-size: .85rem; text-align: right; }

/* 7 ── workbench ------------------------------------------------------------ */
body.bare { background: #e8ecf1; }
#wb { display: flex; flex-direction: column; height: 100vh; }
.wb-loading { padding: 3rem; text-align: center; color: var(--muted); }
.wb-top { display: flex; align-items: center; gap: .7rem; background: #10331d; color: #fff; padding: .4rem .8rem; flex-wrap: wrap; }
.wb-back { color: #cde3d3; font-size: 1.2rem; padding: 0 .3rem; }
.wb-title { font-weight: 600; }
.wb-flex { flex: 1; }
.wb-btn { background: #1d4a2c; color: #fff; border: 1px solid #2f6b42; border-radius: 8px; padding: .3rem .8rem; font: inherit; font-size: .88rem; cursor: pointer; }
.wb-btn:hover { background: #276038; }
.wb-btn.wb-primary { background: #1d4ed8; border-color: #1d4ed8; }
.wb-stunav { display: flex; align-items: center; gap: .3rem; }
.wb-stunav select { max-width: 22rem; padding: .3rem .4rem; border-radius: 8px; border: none; font-size: .88rem; }
.wb-modechk, .wb-abschk { display: flex; align-items: center; gap: .3rem; font-size: .85rem; color: #cde3d3; cursor: pointer; }
.wb-savedot { width: .8rem; height: .8rem; border-radius: 50%; display: inline-block; }
.wb-savedot.saved { background: #34d399; }
.wb-savedot.saving { background: #d1d5db; animation: wbpulse 1s infinite; }
.wb-savedot.savefail { background: #f87171; }
@keyframes wbpulse { 50% { opacity: .4; } }
.wb-body { display: flex; flex: 1; overflow: hidden; }
.wb-script { flex: 1.35; display: flex; flex-direction: column; overflow: hidden; border-right: 1px solid var(--line); }
.wb-tools { display: flex; gap: .3rem; align-items: center; padding: .35rem .6rem; background: #f9fafb; border-bottom: 1px solid var(--line); }
.wb-tools-off { color: var(--muted); font-size: .88rem; }
.wb-tool { width: 2.1rem; height: 2.1rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; font-size: 1rem; }
.wb-tool.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.wb-tools-hint { margin-left: .6rem; font-size: .82rem; color: var(--muted); }
.wb-pages { flex: 1; overflow: auto; padding: .8rem; }
.wb-noscript { padding: 2rem; color: var(--muted); text-align: center; }
.wb-panel { flex: 1; overflow: auto; padding: .8rem; background: var(--bg); }
.wb-sheetline { display: flex; align-items: center; gap: .5rem; margin-bottom: .6rem; flex-wrap: wrap; }
.wb-total { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.wb-qpick { margin-bottom: .6rem; font-size: .9rem; display: flex; gap: .5rem; align-items: center; }
.wb-qpick select { width: auto; display: inline-block; }
.wb-q { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .55rem .7rem; margin-bottom: .55rem; }
.wb-q.active { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.wb-q-head { display: flex; gap: .5rem; align-items: baseline; }
.wb-qno { font-weight: 700; cursor: pointer; color: var(--brand); white-space: nowrap; }
.wb-qtext { flex: 1; font-size: .86rem; color: var(--muted); }
.wb-qmarks { white-space: nowrap; font-variant-numeric: tabular-nums; }
.wb-marks { display: inline-block; width: 3.6rem; text-align: right; padding: .25rem .4rem; margin: 0; }
.wb-marks.saved { border-color: #34d399; }
.wb-marks.saving { border-color: #d1d5db; }
.wb-marks.savefail { border-color: #f87171; background: #fef2f2; }
.wb-q-flags { font-size: .78rem; color: var(--muted); margin-top: .15rem; }
.wb-guide { margin-top: .3rem; font-size: .85rem; }
.wb-guide summary { cursor: pointer; color: var(--accent); }
.wb-comments { margin-top: .4rem; }
.wb-chip { display: inline-block; background: var(--brand-soft); border-radius: 8px; padding: .2rem .5rem; font-size: .82rem; margin: 0 .25rem .25rem 0; }
.wb-chip em { color: var(--muted); font-style: normal; font-size: .76rem; }
.wb-chip-x, .wb-chip-promote { background: none; border: none; cursor: pointer; font-size: .8rem; padding: 0 .15rem; color: var(--muted); }
.wb-chip-x:hover { color: var(--danger); }
.wb-chip-promote:hover { color: var(--brand); }
.wb-cbox { position: relative; margin-top: .25rem; }
.wb-cinput { font-size: .85rem; padding: .3rem .5rem; }
.wb-csuggest { position: absolute; z-index: 40; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line); border-radius: 0 0 8px 8px; box-shadow: var(--shadow); max-height: 14rem; overflow: auto; }
.wb-csug { padding: .35rem .6rem; font-size: .85rem; cursor: pointer; border-bottom: 1px solid #f1f5f9; }
.wb-csug:hover { background: var(--brand-soft); }
.wb-regions { margin-top: .35rem; display: flex; gap: .3rem; flex-wrap: wrap; }
.wb-regionlink { background: #fff; border: 1px dashed #7c3aed; color: #7c3aed; border-radius: 6px; font-size: .78rem; padding: .12rem .45rem; cursor: pointer; }
#wb-toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: #1f2937; color: #fff; padding: .6rem 1rem; border-radius: 8px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 100; max-width: 80vw; }
#wb-toast.show { opacity: 1; }
#wb-transcribe { position: fixed; right: 1rem; bottom: 1rem; width: 22rem; max-width: 92vw; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.2); padding: .8rem; z-index: 90; }
.wb-transcribe-head { font-weight: 600; margin-bottom: .4rem; }
.wb-transcribe-actions { display: flex; gap: .5rem; margin-top: .5rem; }
#wb-transcribe .wb-btn { background: #fff; color: var(--ink); border-color: var(--line); }
#wb-transcribe .wb-btn.wb-primary { background: var(--brand); color: #fff; border-color: var(--brand); }

/* 8 ── viewer overlays (shared grader + student) ----------------------------- */
.gv2-page { position: relative; margin: 0 auto 1rem; max-width: 900px; box-shadow: 0 1px 6px rgba(0,0,0,.18); background: #fff; user-select: none; }
.gv2-page img { display: block; width: 100%; height: auto; }
.gv2-overlay, .gv2-ink { position: absolute; inset: 0; width: 100%; height: 100%; }
.gv2-ink { pointer-events: none; }
.gv2-ink .gv2-el { pointer-events: stroke; cursor: pointer; }
.gv2-pageno { position: absolute; top: .3rem; right: .3rem; background: rgba(31,41,55,.75); color: #fff; font-size: .72rem; padding: .1rem .4rem; border-radius: 6px; }
.gv2-el { position: absolute; }
.gv2-comment { border: 2px solid; background: rgba(255, 245, 230, .92); font-size: .78rem; line-height: 1.3; padding: .15rem .3rem; border-radius: 4px; color: #7f1d1d !important; cursor: pointer; overflow-wrap: break-word; }
.gv2-mark { font-size: 1.3rem; font-weight: 700; transform: translate(-50%, -50%); cursor: pointer; text-shadow: 0 0 3px #fff; }
.gv2-region { border: 2px dashed #7c3aed; background: rgba(124, 58, 237, .07); cursor: pointer; }
.gv2-region.transcribed { border-style: solid; }
.gv2-region-label { position: absolute; top: -1.15rem; left: 0; background: #7c3aed; color: #fff; font-size: .7rem; padding: 0 .35rem; border-radius: 4px; white-space: nowrap; }
.gv2-marquee { position: absolute; border: 2px dashed #c22; background: rgba(204, 34, 34, .07); pointer-events: none; }
.gv2-marquee.region { border-color: #7c3aed; background: rgba(124, 58, 237, .07); }
.gv2-inline-editor { position: absolute; z-index: 50; min-height: 3.4rem; font-size: .8rem; border: 2px solid #c22; border-radius: 4px; padding: .25rem .35rem; background: #fffdf5; resize: both; }
#student-viewer .gv2-page { cursor: default; }

/* 9 ── responsive ------------------------------------------------------------ */
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .wb-body { flex-direction: column; }
  .wb-script { border-right: none; border-bottom: 1px solid var(--line); min-height: 45vh; }
  .wb-stunav select { max-width: 12rem; }
  .main { margin-top: .6rem; }
  input.wide { min-width: 0; }
}
@media (max-width: 600px) {
  .topbar { gap: .6rem; padding: .5rem .8rem; }
  .table { font-size: .84rem; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .help-pop { width: 15rem; }
}
