:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #4f46e5;
  --brand-soft: #eef2ff;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --key: #2563eb;
  --key-soft: #dbeafe;
  --edit: #7c3aed;
  --edit-soft: #ede9fe;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 4px 16px rgba(15, 23, 42, 0.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 58px;
  background: #0f172a; color: #fff;
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: #fff; }
/* the Digi OMR mark (the logo's target "O" on a white tile) */
.logo-dot { width: 28px; height: 28px; flex: none; background: url(/img/icon.svg) center / contain no-repeat; }
/* the full logo (light backgrounds: login, license) */
.brand-logo { display: block; height: 54px; width: auto; margin: 0 auto 6px; }
.tabs { display: flex; gap: 4px; }
.tab { padding: 8px 14px; border-radius: 8px; color: #cbd5e1; cursor: pointer; font-weight: 500; border: 0; background: none; font: inherit; }
.tab:hover { color: #fff; background: rgba(255,255,255,.06); }
.tab.active { color: #fff; background: rgba(255,255,255,.12); }

.page { max-width: 1400px; margin: 0 auto; padding: 24px; }

/* cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-b { padding: 16px 18px; }
.stack > * + * { margin-top: 16px; }

/* buttons + inputs */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  height: 36px; padding: 0 14px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: #4338ca; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); border-color: #fecaca; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #f1f5f9; }
label.f { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=search], input[type=tel], input[type=email], input[type=password], select, textarea {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; font: inherit; background: #fff; color: var(--ink);
}
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d2fe; border-color: var(--brand); }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #f1f5f9; color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.key { background: var(--key-soft); color: var(--key); }
.badge.edit { background: var(--edit-soft); color: var(--edit); }

/* layout: exams */
/* minmax(0, …): wide content (a 150-question answer grid) scrolls inside its box instead of widening the page */
.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; align-items: start; }
.list { display: flex; flex-direction: column; }
.list-item { padding: 12px 18px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: #f8fafc; }
.list-item.active { background: var(--brand-soft); box-shadow: inset 3px 0 0 var(--brand); }
.list-item .t { font-weight: 600; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.stat { padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; background: #fafbff; }
.stat .v { font-size: 22px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }

/* answer key grid */
.keygrid { display: flex; gap: 6px 22px; max-height: 680px; overflow: auto; padding: 4px; }
/* one column per bubble grid of the printed sheet: 1, 2, 3 … run down */
.keycol { display: flex; flex-direction: column; gap: 6px; flex: none; }
/* large screens: 10 questions per column, still counting down (1–10, 11–20 …) */
@media (min-width: 1200px) {
  .keygrid { display: grid; grid-auto-flow: column; grid-template-rows: repeat(10, auto); justify-content: start; }
  .keycol { display: contents; }
}
.keyq { display: flex; align-items: center; gap: 6px; }
.keyq .n { width: 26px; text-align: right; font-weight: 600; font-size: 12px; color: var(--muted); }
.opt {
  width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid #cbd5e1; background: #fff;
  font-size: 11px; font-weight: 600; cursor: pointer; color: var(--muted); display: inline-grid; place-items: center; padding: 0;
}
.opt:hover { border-color: var(--brand); color: var(--brand); }
.opt.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* dropzone */
.drop {
  display: block;
  border: 2px dashed #c7d2fe; border-radius: 12px; padding: 28px; text-align: center; background: #fafaff; cursor: pointer; transition: .15s;
}
.drop:hover, .drop.over { background: var(--brand-soft); border-color: var(--brand); }
.drop .big { font-size: 16px; font-weight: 600; }
.queue { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.qitem { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 13px; }
.qitem .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spin { width: 14px; height: 14px; border: 2px solid #c7d2fe; border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* table */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #f8fafc; position: sticky; top: 0; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8fafc; }
.thumb { width: 38px; height: 50px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); background: #f1f5f9; }
.pbar { height: 6px; border-radius: 3px; background: #e2e8f0; width: 90px; overflow: hidden; }
.pbar > i { display: block; height: 100%; background: var(--ok); }

/* templates */
.tgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.tcard { overflow: hidden; }
.tcard img { width: 100%; aspect-ratio: 1 / 1.2; object-fit: cover; object-position: top; display: block; border-bottom: 1px solid var(--line); background: #f8fafc; }
.tcard .card-b { padding: 12px 14px; }

/* editor */
.editor { display: grid; grid-template-columns: 1fr 360px; gap: 20px; align-items: start; }
.canvas-wrap { position: relative; overflow: auto; max-height: calc(100vh - 160px); background: #e2e8f0; border-radius: 10px; }
.canvas-wrap canvas { display: block; margin: 0 auto; cursor: crosshair; }
.blocklist { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow: auto; }
.bitem { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.bitem.sel { border-color: var(--brand); box-shadow: 0 0 0 2px #c7d2fe; }
.steps { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.step { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: #f1f5f9; color: var(--muted); font-weight: 600; }
.step.on { background: var(--brand-soft); color: var(--brand); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: 100%; max-width: 460px; }
/* sheet review in a popup (review page in embed mode) */
.review-modal { width: min(1600px, 100%); height: calc(100vh - 32px); border-radius: 12px; overflow: hidden; background: var(--bg, #f6f7fb); box-shadow: var(--shadow); }
.review-modal iframe { width: 100%; height: 100%; border: 0; display: block; }
.embed-only { display: none; }
body.embed .embed-only { display: inline-flex; }
body.embed .topbar .logo, body.embed .topbar .tabs { display: none; }
.open-page { color: var(--muted); text-decoration: none; padding: 4px 6px; border-radius: 6px; }
.open-page:hover { background: var(--brand-soft); color: var(--brand); }
.row-acts { white-space: nowrap; }
.card-link { display: inline-flex; align-items: center; gap: 4px; margin-right: 4px; font-size: 12px; font-weight: 600; border: 1px solid var(--line); background: var(--panel); }
.card-link:hover { border-color: var(--brand); }
.card-link:focus-visible, .open-page:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

/* toast */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { padding: 10px 14px; border-radius: 10px; background: #0f172a; color: #fff; box-shadow: var(--shadow); max-width: 380px; animation: pop .2s ease; }
.toast.err { background: var(--bad); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* review page */
.review { display: grid; grid-template-columns: minmax(0, 1fr) 470px; gap: 20px; align-items: start; }
.viewer { position: sticky; top: 78px; }
.viewer .imgbox { overflow: auto; max-height: calc(100vh - 160px); background: #1e293b; border-radius: 0 0 var(--radius) var(--radius); text-align: center; }
.viewer img { max-width: 100%; display: block; margin: 0 auto; cursor: zoom-in; }
.viewer img.zoom { max-width: none; width: 160%; cursor: zoom-out; }
.seg { display: inline-flex; background: #f1f5f9; border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 10px; border-radius: 7px; font: inherit; font-size: 13px; cursor: pointer; color: var(--muted); font-weight: 500; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.score-ring { width: 86px; height: 86px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; }
.score-ring > div { width: 70px; height: 70px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-weight: 700; font-size: 18px; }
.qlist { max-height: calc(100vh - 470px); min-height: 240px; overflow: auto; }
.qrow { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.qrow.flag { background: #fffbeb; }
.qrow .qn { font-weight: 700; color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  position: relative; width: 34px; height: 34px; border-radius: 50%; border: 2px solid #cbd5e1; background: #fff; font-weight: 700; font-size: 12px; color: var(--muted); cursor: pointer; padding: 0;
}
.chip:hover { border-color: var(--edit); }
.chip .fill { position: absolute; left: 4px; right: 4px; bottom: -7px; height: 3px; border-radius: 2px; background: #e2e8f0; overflow: hidden; }
.chip .fill i { display: block; height: 100%; background: #64748b; }
.chip.key { border-color: var(--key); border-style: dashed; color: var(--key); }
.chip.sel { background: var(--bad); border-color: var(--bad); color: #fff; }
.chip.sel.right { background: var(--ok); border-color: var(--ok); }
.chip.sel.nokey { background: var(--edit); border-color: var(--edit); }
.replace-box { border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 6px; }
.qlist.busy { opacity: 0.6; pointer-events: none; }
.chip.keysel { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--key); }
.chip.part { border: 2px dashed var(--warn); background: var(--warn-soft); color: var(--warn); }
.chip.was::after { content: ""; position: absolute; top: -3px; right: -3px; width: 9px; height: 9px; border-radius: 50%; background: var(--edit); border: 2px solid #fff; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.kbd { font: 11px ui-monospace, monospace; border: 1px solid var(--line); border-bottom-width: 2px; padding: 0 5px; border-radius: 4px; background: #fff; }
.history { max-height: 160px; overflow: auto; font-size: 12px; }
.history div { padding: 4px 0; border-bottom: 1px dashed var(--line); }

/* marking scheme widget */
.marking { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: #fafbff; }
.marking .mk-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.marking .mk-row > div { width: 96px; }
.marking .mk-row > .mk-mode { width: 240px; }
.marking .mk-group { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; }
.marking .mk-group input[type=number] { width: 70px; height: 32px; }
.set-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 13px; }
.set-row select { width: auto; height: 32px; }
.set-tabs { margin-top: 10px; }
.set-tabs button .cnt { font-size: 11px; color: var(--muted); margin-left: 4px; }
.idsub { font-size: 11px; color: var(--muted); font-weight: 400; white-space: nowrap; }
.marking .mk-sum { margin-top: 8px; font-size: 12px; color: var(--muted); }
.marking + .marking { margin-top: 10px; }

/* generator */
.gen { display: grid; grid-template-columns: 520px minmax(0, 1fr); gap: 20px; align-items: start; }
.num { width: 24px; height: 24px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.gen-preview { background: #e2e8f0; min-height: 300px; }
.gen-preview img { box-shadow: 0 2px 12px rgba(0,0,0,.15); }
.opt.k { border-style: dashed; border-color: var(--key); }
.opt.on.k { border-style: solid; }
.keyq.multi { background: var(--warn-soft); border-radius: 999px; }
.keyq.multi .n { color: var(--warn); }
.keyq.multi .opt.on { background: var(--warn); border-color: var(--warn); }

@media (max-width: 1100px) {
  .gen { grid-template-columns: 1fr; }
  /* minmax(0, …): the single column may shrink below its widest content (tables scroll inside) */
  .layout, .editor, .review { grid-template-columns: minmax(0, 1fr); }
  .viewer { position: static; }
  .qlist { max-height: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .page { padding: 16px; }
  .topbar { padding: 0 16px; gap: 10px; height: auto; min-height: 58px; flex-wrap: wrap; }
  .card-h { flex-wrap: wrap; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  #resSearch { width: 100% !important; }
  .review { gap: 12px; }
}

/* review page: Student ID, set and other ID grids, one per row, boxes lined up */
.id-label { margin: 0 !important; min-width: 96px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.id-input { height: 32px; max-width: 180px; font-weight: 700; }

/* exam page tabs: Results · Add sheets · Answer key & marking */
.ex-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 4px; }
.ex-tabs button { border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; align-items: center; gap: 6px; }
.ex-tabs button:hover { color: var(--ink); }
.ex-tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.ex-count { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: #f1f5f9; color: var(--muted); }
.ex-count:empty { display: none; }
.ex-tabs button.on .ex-count { background: var(--brand-soft); color: var(--brand); }
.pane-off { display: none !important; }

/* desktop app (js/desktop.js) */
.dk-opts select { width: auto; height: 34px; }
.dk-big { height: 40px; padding: 0 18px; font-size: 15px; }
.dk-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; user-select: none; }
.dk-banner { padding: 8px 12px; border-radius: 9px; background: var(--warn-soft); color: #92400e; font-size: 13px; }
#dkStatus.busy { color: var(--brand); font-weight: 600; }
#dkStatus.ok { color: var(--ok); }
#dkStatus.bad { color: var(--bad); }
.dk-job { display: grid; grid-template-columns: minmax(0, 1.2fr) 100px minmax(0, 1.6fr) auto; gap: 10px; align-items: center; font-size: 13px; padding: 6px 10px; border-radius: 8px; background: #f8fafc; }
.dk-job .n, .dk-job .d { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dk-job .d { color: var(--muted); }
.dk-job .d.bad, .dk-job .s.failed { color: var(--bad); }
.dk-job .s { font-weight: 600; font-size: 12px; }
.dk-job .s.uploading { color: var(--brand); }
.dk-job .s.done { color: var(--ok); }
.dk-top { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; }
.dk-pill { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.06); color: #e2e8f0; font: inherit; font-size: 13px; cursor: pointer; }
.dk-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; }
.dk-pill .dot.on { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.2); }
.dk-pill.icon { width: 34px; padding: 0; justify-content: center; font-size: 16px; }

/* exam list: search + client filter */
.exam-filters { padding: 10px 18px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }

/* desktop: Scanner setup helper */
.dk-setup { max-width: 560px; }
.dk-setup-state { display: flex; gap: 14px; align-items: flex-start; }
.dk-setup-state h3 { margin: 2px 0 4px; }
.dk-setup-state p { margin: 0; }
.dk-ic { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 17px; background: #f1f5f9; color: var(--muted); }
.dk-setup-state.ok .dk-ic { background: var(--ok-soft); color: var(--ok); }
.dk-setup-state.warn .dk-ic { background: var(--warn-soft); color: var(--warn); }
.dk-steps { margin: 14px 0 0; padding-left: 22px; display: flex; flex-direction: column; gap: 12px; }
.dk-steps li > div { margin-top: 6px; }
.dk-setup-foot { padding: 10px 18px; border-top: 1px solid var(--line); }
.dk-setup-state .spin { display: inline-block; vertical-align: -2px; margin-right: 8px; }

/* desktop: Server / Offline choice */
.dk-choice { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.dk-choice input { margin-top: 4px; }
.dk-choice > span { display: flex; flex-direction: column; }
.dk-sub { margin: 0 0 0 26px; padding-top: 2px; }
.dk-mode { cursor: default; background: rgba(251, 191, 36, .16); border-color: rgba(251, 191, 36, .4); color: #fde68a; }

/* send results to guardians (demo) */
.gd-list { max-height: 380px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.gd-row { display: grid; grid-template-columns: 70px 170px 110px minmax(0, 1fr) 70px; gap: 10px; align-items: center; padding: 7px 12px; border-bottom: 1px solid #f1f5f9; font-size: 13px; }
.gd-row:last-child { border-bottom: 0; }
.gd-row.off { color: var(--muted); background: #fafafa; }
.gd-id { font-weight: 600; font-variant-numeric: tabular-nums; }
.gd-name, .gd-msg { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gd-msg { color: var(--muted); font-size: 12px; }
.gd-phone { font-variant-numeric: tabular-nums; color: var(--muted); }
#gdTemplate { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; font: inherit; font-size: 14px; line-height: 1.6; resize: vertical; color: var(--ink); background: var(--panel); transition: border-color .15s ease, box-shadow .15s ease; }
#gdTemplate:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

.gd-modal { max-width: 620px; position: relative; overflow: hidden; animation: pop .2s ease; }
.gd-head { display: flex; align-items: center; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.gd-head-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.gd-head-text { flex: 1; min-width: 0; }
.gd-head-text h3 { font-size: 16px; }
.gd-head-text .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gd-body { padding: 18px 20px 4px; }

.gd-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 18px; }
.gd-chip { height: 28px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: inherit; font-size: 12px; cursor: pointer; transition: background-color .15s ease, border-color .15s ease, color .15s ease; }
.gd-chip:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.gd-chip:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.gd-chip:active { transform: translateY(1px); }

.gd-preview { border-radius: 12px; background: var(--bg); padding: 14px 16px 16px; margin-bottom: 16px; }
.gd-preview-h { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
.gd-bubble { position: relative; max-width: 88%; padding: 10px 14px; border-radius: 16px 16px 16px 4px; background: var(--panel); border: 1px solid var(--line); font-size: 14px; line-height: 1.55; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04); }

.gd-foot { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--panel); }
.gd-send { display: inline-flex; align-items: center; gap: 8px; min-width: 104px; justify-content: center; }
.gd-send.is-sending, .gd-send.is-sending:disabled { pointer-events: none; opacity: 1; cursor: progress; }
.gd-send.is-sending svg { animation: gd-fly .9s ease-in-out infinite; }
@keyframes gd-fly { 50% { transform: translate(3px, -3px); opacity: .6; } }

.gd-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--brand-soft); overflow: hidden; }
.gd-progress span { display: block; height: 100%; width: 100%; background: var(--brand); transform-origin: left; transform: scaleX(0); transition: transform .12s linear; }

.gd-done { padding: 30px 28px 22px; text-align: center; }
.gd-done-mark { color: var(--ok); display: inline-grid; width: 72px; height: 72px; place-items: center; border-radius: 50%; background: var(--ok-soft); margin-bottom: 14px; }
.gd-done-mark circle { stroke-dasharray: 151; stroke-dashoffset: 151; animation: gd-draw .5s ease-out forwards; }
.gd-done-mark path { stroke-dasharray: 40; stroke-dashoffset: 40; animation: gd-draw .35s .4s ease-out forwards; }
@keyframes gd-draw { to { stroke-dashoffset: 0; } }
.gd-done h3 { font-size: 20px; margin-bottom: 6px; }
.gd-done p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.gd-done .gd-bubble { margin: 0 auto; text-align: left; }
.gd-bubble-sent { background: var(--brand); border-color: var(--brand); color: #fff; border-radius: 16px 16px 4px 16px; }

@media (prefers-reduced-motion: reduce) {
  .gd-modal, .gd-send.is-sending svg, .gd-done-mark circle, .gd-done-mark path { animation: none; }
  .gd-done-mark circle, .gd-done-mark path { stroke-dashoffset: 0; }
  .gd-progress span { transition: none; }
}

/* exam header: name + tools, then "Share results" on its own line */
.ex-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.ex-title { flex: 1; min-width: 260px; }
.ex-tools { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.ex-share { display: flex; align-items: center; gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.ex-share-l { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-right: 6px; }
/* students */
.st-excel { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 14px 16px; border: 1px dashed #c7d2fe; border-radius: 10px; background: var(--brand-soft); }
.st-excel-t { flex: 1; min-width: 240px; }
.st-excel-b { flex-wrap: wrap; }
.st-result { padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: #f8fafc; font-size: 14px; }
.st-result.ok { background: var(--ok-soft); border-color: #bbf7d0; }
.st-result ul { margin: 6px 0 0; padding-left: 18px; max-height: 140px; overflow: auto; color: var(--bad); font-size: 13px; }
.st-table { overflow: auto; max-height: calc(100vh - 360px); min-height: 200px; border: 1px solid var(--line); border-radius: 10px; }
.st-table td { font-size: 14px; }
.st-table td.id { font-weight: 600; font-variant-numeric: tabular-nums; }
.st-table td.act { white-space: nowrap; text-align: right; }
.st-table td.ph { font-variant-numeric: tabular-nums; white-space: nowrap; }
.list-item .cnt { float: right; }
.sm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.sm-grid .wide { grid-column: 1 / -1; }
.sm-grid input[type=tel] { font-variant-numeric: tabular-nums; letter-spacing: .3px; }
@media (max-width: 460px) { .sm-grid { grid-template-columns: 1fr; } .sm-grid > div:empty { display: none; } }
.all-comp { align-items: flex-start; line-height: 1.4; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; }
.all-comp input { margin-top: 3px; }
/* subject-wise pass marks */
.pass-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.pass-tbl td { padding: 8px 12px; }
.pass-tbl tr.pass-total td { background: #f8fafc; }
.pass-in { display: flex; gap: 6px; align-items: center; }
.pass-in input[type=number] { width: 90px; }
.pass-in select { width: 92px; }

/* either / or partners in the layout editor */
.eo-box { border: 1px solid var(--line); border-left-width: 4px; border-radius: 10px; padding: 10px 12px; background: #fafbff; }
.eo-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; max-height: 220px; overflow: auto; }
.eo-item { display: flex; gap: 8px; align-items: flex-start; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; font-size: 13px; }
.eo-item:hover { border-color: #c7d2fe; }
.eo-item.on { border-color: var(--brand); background: var(--brand-soft); }
.eo-item input { margin-top: 2px; }
.eo-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: -1px; }
.eo-adv summary { cursor: pointer; color: var(--muted); margin-top: 8px; }

/* sections: answer key by subject */
.keygrid.by-sec { display: flex; flex-direction: column; gap: 14px; max-height: none; }
.keysec { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.keysec-h { padding: 8px 12px; background: #f8fafc; border-bottom: 1px solid var(--line); font-size: 14px; }
/* numbers run down each column, like the printed sheet */
.keysec-b { columns: 190px auto; column-gap: 18px; padding: 10px 12px; }
.keysec-b .keyq { break-inside: avoid; margin-bottom: 6px; }
.sec-tbl td { padding: 6px 8px; }
.sec-tbl input[type=text] { min-width: 110px; }
.sec-tbl input[type=number] { width: 68px; padding: 0 6px; }
.sec-tbl td[data-n] { white-space: nowrap; }
.sec-copy { width: auto; max-width: 320px; height: 30px; font-size: 13px; }
.res-marks { font-size: 12px; color: var(--muted); margin-top: 3px; max-width: 260px; line-height: 1.5; }
.res-marks .bad { color: var(--bad); font-weight: 600; }
.sec-eo { width: auto; min-width: 120px; max-width: 170px; height: 34px; font-size: 13px; }
.par-box { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--ink); white-space: nowrap; }
.par-box select { width: auto; height: 32px; font-size: 13px; font-weight: 400; }

/* delete sheet pictures dialog */
.btn.danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-solid:hover:not(:disabled) { background: #b91c1c; border-color: #b91c1c; }
.btn.danger-solid:disabled { opacity: .45; cursor: not-allowed; }
.pm-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 12px 14px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); }
.pm-exam { flex: 1; min-width: 160px; font-weight: 600; }
.pm-exam .muted { font-weight: 400; display: block; font-size: 12px; }
.pm-nums { display: flex; gap: 18px; }
.pm-nums div { display: flex; flex-direction: column; align-items: flex-end; }
.pm-nums b { font-size: 20px; line-height: 1.1; }
.pm-nums span { font-size: 11px; color: var(--muted); }
.pm-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pm-col { border-radius: 10px; padding: 10px 12px; border: 1px solid; }
.pm-col.ok { background: var(--ok-soft); border-color: #bbf7d0; }
.pm-col.bad { background: var(--bad-soft); border-color: #fecaca; }
.pm-col h4 { margin: 0 0 4px; font-size: 13px; }
.pm-col.ok h4 { color: var(--ok); }
.pm-col.bad h4 { color: var(--bad); }
.pm-col ul { margin: 0; padding-left: 18px; font-size: 12.5px; }
.pm-col li { margin: 2px 0; }
.pm-what { display: grid; gap: 6px; }
.pm-what label { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: baseline; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.pm-what label:has(input:checked) { border-color: var(--brand); background: var(--bg); }
.pm-what label > span { grid-column: 2; }
.pic-modal[data-what="scans"] .pm-all-only, .pic-modal[data-what="all"] .pm-scans-only { display: none; }
.pm-confirm { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; padding: 8px 10px; border: 1px dashed #fecaca; border-radius: 8px; cursor: pointer; }
.pm-confirm input { margin-top: 3px; }
@media (max-width: 560px) { .pm-cols { grid-template-columns: 1fr; } .pm-nums { width: 100%; justify-content: space-between; } .pm-nums div { align-items: flex-start; } }
/* review page: sheet whose pictures were deleted */
.pic-gone { display: grid; place-items: center; text-align: center; gap: 6px; min-height: 320px; padding: 24px; color: var(--muted); background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; }
.pic-gone .small { max-width: 420px; margin: 4px auto 0; }
.pic-gone b { color: var(--ink); font-size: 15px; }

/* own marks per section (custom feature) */
.sec-tbl td.sec-mk input { width: 74px; }
/* the section's own mark (differs from the exam marking) */
.sec-tbl td.sec-mk input.own { border-color: var(--edit); background: var(--edit-soft); color: var(--edit); font-weight: 600; }

/* custom features per client */
.cl-feat { border: 1px solid var(--edit-soft); background: color-mix(in srgb, var(--edit-soft) 45%, var(--panel)); border-radius: 10px; padding: 10px 12px; display: grid; gap: 8px; }
.cl-feat-h { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.cl-feat-h b { color: var(--edit); }
.cl-feat-row { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.cl-feat-row input { margin-top: 3px; }
.cl-feat-row > span { display: grid; }

/* review page: answers read-only (client without 'Change student answers') */
#qlist.readonly .chip:disabled { cursor: default; opacity: 1; }

/* answer key from a master sheet */
.key-sheet { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 10px; border: 1px dashed var(--line); border-radius: 10px; }
.key-sheet .btn.busy { opacity: .6; pointer-events: none; }
.keyq.check { outline: 2px solid var(--warn); outline-offset: 1px; border-radius: 6px; background: var(--warn-soft); }

/* review page: graded view drawn over a picture kept on the PC */
.sheet-svg svg { width: 100%; height: auto; display: block; cursor: zoom-in; }
.sheet-svg.zoom svg { width: 200%; cursor: zoom-out; }
.thumb-none { display: inline-grid; place-items: center; width: 44px; height: 58px; border: 1px dashed var(--line); border-radius: 6px; color: var(--muted); font-size: 18px; }
.me-name { color: #cbd5e1; margin-right: 4px; }

/* only what this person may do (api.js puts can-<permission> on <body>; hidden until known) */
body:not(.can-exams-manage) [data-perm~="exams.manage"],
body:not(.can-sheets-delete) [data-perm~="sheets.delete"],
body:not(.can-templates-manage) [data-perm~="templates.manage"],
body:not(.can-students-manage) [data-perm~="students.manage"],
body:not(.can-clients-manage) [data-perm~="clients.manage"],
body:not(.can-settings-manage) [data-perm~="settings.manage"],
body:not(.can-licenses-read) [data-perm~="licenses.read"],
body:not(.can-users-manage) [data-perm~="users.manage"] { display: none !important; }
/* desktop app: license ends soon */
.lic-warn { background: #fef3c7; color: #92400e; border-bottom: 1px solid #fde68a; padding: 8px 16px; font-size: 13px; text-align: center; }

/* ---------- login / license pages: brand poster + card (light, brand slate #4E6672 + maroon #8E1033) ---------- */
body.auth { --slate: #4a5a63; --slate-dark: #33414a; --maroon: #80002a; min-height: 100vh; margin: 0; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(380px, .85fr); background: radial-gradient(900px 600px at 8% 0%, rgba(74, 90, 99, .16) 0%, transparent 62%), radial-gradient(800px 560px at 60% 100%, rgba(128, 0, 42, .10) 0%, transparent 60%), #f6f8f9; color: var(--slate-dark); position: relative; overflow-x: hidden; }
/* the two brand colours as a stripe on top */
body.auth::after { content: ""; position: fixed; left: 0; right: 0; top: 0; height: 5px; background: linear-gradient(90deg, var(--slate) 0 62%, var(--maroon) 62% 100%); z-index: 2; }
/* slowly drifting bubble pattern */
body.auth::before { content: ""; position: fixed; inset: -60px; pointer-events: none; background-image: radial-gradient(circle, rgba(74, 90, 99, .16) 2px, transparent 2.6px); background-size: 30px 30px; animation: auth-drift 60s linear infinite; mask-image: linear-gradient(90deg, #000 0%, rgba(0, 0, 0, .55) 55%, transparent 80%); -webkit-mask-image: linear-gradient(90deg, #000 0%, rgba(0, 0, 0, .55) 55%, transparent 80%); }
@keyframes auth-drift { to { transform: translate(30px, 60px); } }
.auth-poster { position: relative; isolation: isolate; display: flex; flex-direction: column; justify-content: center; gap: 16px; padding: 32px clamp(28px, 5vw, 72px); }
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand img { width: 44px; height: 44px; filter: drop-shadow(0 4px 10px rgba(74, 90, 99, .25)); }
.auth-brand b { font-size: 22px; letter-spacing: .2px; color: var(--slate); }
.auth-brand span { display: block; font-size: 12px; color: var(--maroon); font-weight: 700; }
.auth-poster h1 { margin: 0; font-size: clamp(26px, 3vw, 38px); line-height: 1.15; color: var(--slate-dark); max-width: 15em; }
.auth-poster h1 em { font-style: normal; color: var(--maroon); }
.auth-poster .art { width: min(540px, 100%); max-height: 58vh; height: auto; }
.auth-points { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; max-width: 30em; }
.auth-points li { display: flex; gap: 10px; align-items: flex-start; color: var(--slate); font-size: 14px; font-weight: 500; }
.auth-points li::before { content: ""; flex: none; width: 16px; height: 16px; margin-top: 2px; border-radius: 50%; border: 3px solid var(--maroon); background: radial-gradient(circle, var(--maroon) 3px, #fff 3.5px); }
.auth-foot { display: flex; align-items: center; gap: 10px; font-size: 12px; color: #8a9aa3; }
.auth-foot img { height: 34px; width: auto; }
/* floating bubble rings behind the poster */
.auth-orbs { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: -1; }
.auth-orbs i { position: absolute; bottom: -80px; border-radius: 50%; border: 3px solid var(--maroon); opacity: 0; animation: auth-rise linear infinite; }
.auth-orbs i::after { content: ""; position: absolute; inset: 30%; border-radius: 50%; background: currentColor; }
.auth-orbs i:nth-child(odd) { border-color: var(--slate); color: var(--slate); }
.auth-orbs i:nth-child(even) { color: var(--maroon); }
.auth-orbs i:nth-child(1) { left: 6%; width: 34px; height: 34px; animation-duration: 18s; animation-delay: 0s; }
.auth-orbs i:nth-child(2) { left: 22%; width: 18px; height: 18px; animation-duration: 14s; animation-delay: 3s; }
.auth-orbs i:nth-child(3) { left: 41%; width: 46px; height: 46px; animation-duration: 22s; animation-delay: 6s; }
.auth-orbs i:nth-child(4) { left: 58%; width: 22px; height: 22px; animation-duration: 16s; animation-delay: 1.5s; }
.auth-orbs i:nth-child(5) { left: 74%; width: 30px; height: 30px; animation-duration: 20s; animation-delay: 9s; }
.auth-orbs i:nth-child(6) { left: 88%; width: 14px; height: 14px; animation-duration: 13s; animation-delay: 5s; }
.auth-orbs i:nth-child(7) { left: 32%; width: 26px; height: 26px; animation-duration: 24s; animation-delay: 12s; }
@keyframes auth-rise { 0% { transform: translateY(0) rotate(0); opacity: 0; } 10% { opacity: .22; } 85% { opacity: .18; } 100% { transform: translateY(-115vh) rotate(160deg); opacity: 0; } }
.auth-poster .art { animation: auth-float 7s ease-in-out infinite; }
@keyframes auth-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.auth-panel { display: grid; place-items: center; padding: 24px 16px; position: relative; }
body.auth .card { border: 1px solid #e3e8eb; box-shadow: 0 24px 60px rgba(52, 69, 78, .14), 0 2px 6px rgba(52, 69, 78, .06); }
body.auth .btn.primary { background: var(--maroon); border-color: var(--maroon); }
body.auth .btn.primary:hover { background: #66001f; border-color: #66001f; }
body.auth a { color: var(--maroon); }
body.auth input:focus { border-color: var(--slate); box-shadow: 0 0 0 3px rgba(74, 90, 99, .18); outline: none; }
@media (max-width: 900px) { body.auth { grid-template-columns: 1fr; } .auth-poster { display: none; } }
@media (prefers-reduced-motion: reduce) { body.auth::before, .auth-orbs i, .auth-poster .art { animation: none; } .auth-orbs { display: none; } }

/* password fields: show / hide + Caps Lock hint (api.js enhancePasswords) */
.pw-wrap { position: relative; display: block; width: 100%; }
.pw-wrap > input { width: 100%; padding-right: 40px; }
.pw-eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--muted, #64748b); cursor: pointer; padding: 0; }
.pw-eye:hover { color: var(--ink, #0f172a); background: rgba(100, 116, 139, .1); }
.pw-eye:focus-visible { outline: 2px solid var(--brand, #4f46e5); }
.pw-caps { margin-top: 4px; font-size: 12px; color: #b45309; }
.forgot summary { cursor: pointer; color: var(--muted, #64748b); width: max-content; }
.forgot summary:hover { color: var(--ink, #0f172a); }
.forgot div { margin-top: 6px; }

/* login page: why it opened */
.notice { margin-top: 10px; padding: 8px 10px; border-radius: 10px; background: #eef2f5; color: #33414a; font-size: 13px; }

/* review page: reject a sheet */
.topbar .reject-btn { color: #b91c1c; border-color: #fecaca; background: #fff; }
.topbar .reject-btn:hover { background: var(--bad-soft); border-color: #fca5a5; }
.topbar .reject-btn.on { color: #fff; background: var(--bad); border-color: var(--bad); }
.topbar .reject-btn.on:hover { background: #b91c1c; }
.rejected-bar { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid #fecaca; border-left: 4px solid var(--bad); border-radius: 12px; background: var(--bad-soft); color: #7f1d1d; }
.rejected-bar .rj-icon { font-size: 26px; line-height: 1; color: var(--bad); }
.rejected-bar .rj-text { flex: 1; min-width: 0; }
.rejected-bar .rj-text b { color: var(--bad); }
.rejected-bar .rj-meta { color: #991b1b; opacity: .8; margin-top: 2px; }
body.is-rejected .viewer .imgbox { opacity: .55; filter: grayscale(.6); }
.reject-modal { max-width: 520px; max-height: calc(100vh - 32px); overflow-y: auto; }
.rj-who { display: flex; align-items: baseline; gap: 10px; padding: 8px 12px; border-radius: 10px; background: var(--bg); }
.rj-who b { font-size: 18px; letter-spacing: .5px; }
.rj-reasons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }
.rj-reasons label { display: flex; gap: 8px; align-items: flex-start; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; transition: border-color .12s, background .12s; }
.rj-reasons label:hover { border-color: #fca5a5; }
.rj-reasons label:has(input:checked) { border-color: var(--bad); background: var(--bad-soft); }
.rj-reasons input { margin-top: 3px; accent-color: var(--bad); }
.rj-reasons span { display: grid; gap: 1px; }
.rj-reasons b { font-size: 13.5px; }
.rj-reasons small { color: var(--muted, #64748b); font-size: 12px; line-height: 1.3; }
.rj-info { padding: 8px 10px; border-radius: 10px; background: #fff7ed; color: #9a3412; }
@media (max-width: 560px) { .rj-reasons { grid-template-columns: 1fr; } }
/* exam page: rejected sheets (own tab) */
#resFilter .seg-rejected.on { color: var(--bad); }
tr.row-rejected td { background: #fffafa; }
tr.row-rejected td:not(:last-child) b, tr.row-rejected .pbar { opacity: .6; }
.rj-why { max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
