:root {
  --bg: #f6f7fb; --panel: #ffffff; --panel-2: #f1f3f9; --line: #e3e6ef; --text: #161a2b; --muted: #5d6478;
  --brand: #4f46e5; --brand-2: #6366f1; --brand-ink: #ffffff; --brand-soft: #eef0ff;
  --ok: #0f9d58; --ok-soft: #e6f6ee; --warn: #b7791f; --warn-soft: #fdf3e1; --bad: #d93025; --bad-soft: #fde8e7;
  --shadow: 0 1px 2px rgba(20,24,40,.06), 0 4px 16px rgba(20,24,40,.06);
  --radius: 12px; --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1020; --panel: #151a2e; --panel-2: #1b2139; --line: #283052; --text: #e8eaf6; --muted: #9aa2c0;
    --brand: #818cf8; --brand-2: #6366f1; --brand-ink: #0d1020; --brand-soft: #23284a;
    --ok: #34c77b; --ok-soft: #12301f; --warn: #f0b75a; --warn-soft: #33270f; --bad: #ff7b72; --bad-soft: #3a1717;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1020; --panel: #151a2e; --panel-2: #1b2139; --line: #283052; --text: #e8eaf6; --muted: #9aa2c0;
  --brand: #818cf8; --brand-2: #6366f1; --brand-ink: #0d1020; --brand-soft: #23284a;
  --ok: #34c77b; --ok-soft: #12301f; --warn: #f0b75a; --warn-soft: #33270f; --bad: #ff7b72; --bad-soft: #3a1717;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 Inter, system-ui, -apple-system, Segoe UI, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.25; }
h1 { font-size: 24px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
p { margin: 0 0 .8em; }
code, pre, textarea.mono { font-family: var(--mono); font-size: 13px; }
pre { white-space: pre-wrap; word-break: break-word; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }
.hidden { display: none !important; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--text); }
.logo:hover { text-decoration: none; }
.logo img { width: 26px; height: 26px; }
.logo span { color: var(--brand); }
.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); white-space: nowrap; }
.topbar nav a.on, .topbar nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.who { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.page { max-width: 1240px; margin: 0 auto; padding: 24px 20px 64px; }
.page.wide { max-width: none; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.head .crumbs { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.card h2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
a.card { display: block; color: inherit; transition: border-color .15s, transform .15s; }
a.card:hover { border-color: var(--brand); text-decoration: none; transform: translateY(-1px); }
.stat b { display: block; font-size: 26px; }
.stat span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

/* Controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--brand); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.btn.ghost { border-color: transparent; background: transparent; }
label { display: block; font-weight: 600; font-size: 12.5px; margin: 0 0 4px; color: var(--muted); }
.field { margin-bottom: 12px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); font: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--text); font-size: 13.5px; margin: 6px 0; }
.check input { width: 16px; height: 16px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }

table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--panel-2); position: sticky; top: 0; }
table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:hover td { background: color-mix(in srgb, var(--panel-2) 60%, transparent); }
.table-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 10px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mark-in { width: 70px !important; padding: 4px 6px !important; text-align: right; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { padding: 9px 14px; border: none; background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.note { padding: 10px 12px; border-radius: 9px; background: var(--brand-soft); color: var(--text); font-size: 13px; margin-bottom: 12px; }
.note.warn { background: var(--warn-soft); }
.note.bad { background: var(--bad-soft); }
.note.ok { background: var(--ok-soft); }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
#toast div { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 500; max-width: 90vw; }
#toast div.bad { background: var(--bad); color: #fff; }

.modal-bg { position: fixed; inset: 0; background: rgba(8,10,20,.55); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow: auto; }
.modal { background: var(--panel); border-radius: 14px; border: 1px solid var(--line); width: min(720px, 100%); padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal.xl { width: min(1280px, 100%); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Landing */
.hero { max-width: 1100px; margin: 0 auto; padding: 72px 20px 40px; display: grid; grid-template-columns: 1.1fr 1fr; gap: 40px; align-items: center; }
.hero h1 { font-size: 44px; letter-spacing: -.02em; }
.hero h1 em { font-style: normal; color: var(--brand); }
.hero p.lead { font-size: 17px; color: var(--muted); }
.hero-art { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 14px; }
.hero-art .tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.hero-art .tile { aspect-ratio: 16/10; border-radius: 8px; background: var(--panel-2); position: relative; overflow: hidden; }
.hero-art .tile::after { content: ''; position: absolute; left: 8px; right: 30%; top: 10px; height: 5px; border-radius: 3px; background: var(--line); box-shadow: 0 10px 0 var(--line), 0 20px 0 var(--line); }
.hero-art .tile.flag { outline: 2px solid var(--bad); }
.hero-art .tile.flag::before { content: 'phone'; position: absolute; right: 6px; bottom: 6px; font-size: 10px; font-weight: 700; color: #fff; background: var(--bad); padding: 1px 6px; border-radius: 99px; }
.features { max-width: 1100px; margin: 0 auto; padding: 20px 20px 80px; }
.features .card h3 { margin-top: 2px; }
@media (max-width: 860px) { .hero { grid-template-columns: 1fr; padding-top: 40px; } .hero h1 { font-size: 32px; } }

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth { width: min(420px, 100%); }
.auth .logo { justify-content: center; margin-bottom: 18px; font-size: 22px; }

/* Question / test editor */
.qcard { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); margin-bottom: 14px; }
.qcard > header { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.qcard > div { padding: 16px; }
.tc { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: start; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.tc textarea { min-height: 60px; font-family: var(--mono); font-size: 12.5px; }
.tc .opts { display: flex; flex-direction: column; gap: 4px; min-width: 120px; }

/* Exam room */
.exam { display: grid; grid-template-rows: auto 1fr; height: 100vh; overflow: hidden; }
.exam-bar { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.timer { font-family: var(--mono); font-weight: 700; font-size: 16px; padding: 4px 10px; border-radius: 8px; background: var(--panel-2); }
.timer.low { background: var(--bad-soft); color: var(--bad); }
.exam-body { display: grid; grid-template-columns: minmax(300px, 38%) 1fr; min-height: 0; }
.exam-q { overflow: auto; padding: 16px 18px; border-right: 1px solid var(--line); background: var(--panel); }
.exam-q .qnav { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.exam-q .qnav button { min-width: 38px; }
.exam-q .stmt { white-space: pre-wrap; line-height: 1.6; }
.sample { border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; overflow: hidden; }
.sample > div { display: grid; grid-template-columns: 1fr 1fr; }
.sample pre { padding: 8px 10px; background: var(--panel-2); min-height: 32px; }
.sample b { display: block; font-size: 11px; color: var(--muted); padding: 4px 10px; text-transform: uppercase; }
.exam-code { display: grid; grid-template-rows: auto 1fr auto; min-height: 0; }
.exam-code .tools { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
#editor { min-height: 0; }
.out { height: 32vh; overflow: auto; border-top: 1px solid var(--line); background: var(--panel); padding: 10px 14px; }
.out .res { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.out .res.pass { border-color: var(--ok); }
.out .res.fail { border-color: var(--bad); }
.self-view { position: fixed; right: 14px; bottom: 14px; z-index: 30; width: 200px; border-radius: 10px; overflow: hidden; border: 2px solid var(--ok); background: #000; box-shadow: var(--shadow); }
.self-view.bad { border-color: var(--bad); }
.self-view video { width: 100%; display: block; transform: scaleX(-1); }
.self-view .lbl { position: absolute; left: 6px; top: 6px; font-size: 10.5px; font-weight: 700; color: #fff; background: rgba(0,0,0,.55); padding: 1px 6px; border-radius: 99px; }
.lock { position: fixed; inset: 0; z-index: 60; background: rgba(8,10,20,.9); display: grid; place-items: center; padding: 20px; color: #fff; }
.lock .card { color: var(--text); max-width: 520px; }
.banner { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 70; max-width: 640px; width: calc(100% - 32px); }
.check-list { list-style: none; padding: 0; margin: 0 0 14px; }
.check-list li { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.check-list li .st { margin-left: auto; }
.precheck-media { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.precheck-media video { width: 100%; aspect-ratio: 16/10; background: #000; border-radius: 8px; object-fit: contain; }
@media (max-width: 900px) { .exam-body { grid-template-columns: 1fr; grid-template-rows: 40% 1fr; } .exam-q { border-right: none; border-bottom: 1px solid var(--line); } }

/* Live proctor console */
.console { display: grid; grid-template-columns: 1fr 340px; gap: 16px; }
@media (max-width: 1100px) { .console { grid-template-columns: 1fr; } }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.ptile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; position: relative; }
.ptile:hover { border-color: var(--brand); }
.ptile.risk-mid { border-color: var(--warn); }
.ptile.risk-high { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); }
.ptile.offline { opacity: .6; }
.ptile .shot { aspect-ratio: 16/10; background: var(--panel-2); position: relative; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.ptile .shot img.scr { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.ptile .shot img.cam { position: absolute; right: 6px; bottom: 6px; width: 30%; border-radius: 6px; border: 2px solid #fff; }
.ptile .meta { padding: 8px 10px; }
.ptile .meta .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dots { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.dot { font-size: 10.5px; padding: 1px 6px; border-radius: 99px; background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.dot.off { background: var(--bad-soft); color: var(--bad); }
.feed { max-height: 78vh; overflow: auto; }
.feed .fi { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.feed .fi:hover { background: var(--panel-2); }
.sev3 { color: var(--bad); font-weight: 700; } .sev2 { color: var(--warn); font-weight: 600; } .sev1 { color: var(--muted); }
.live-view { display: grid; grid-template-columns: 2.2fr 1fr; gap: 14px; }
.live-view video { width: 100%; background: #000; border-radius: 8px; }
.live-view .screen { aspect-ratio: 16/9; object-fit: contain; }
.timeline { max-height: 420px; overflow: auto; }
.timeline .ev { display: grid; grid-template-columns: 64px 1fr; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.timeline img { width: 100%; border-radius: 6px; margin-top: 4px; cursor: zoom-in; }
@media (max-width: 900px) { .live-view { grid-template-columns: 1fr; } }
.pager { display: flex; gap: 6px; align-items: center; justify-content: center; margin: 14px 0; }
