:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2230;
  --muted: #6b7384;
  --border: #e3e6ec;
  --primary: #2f5bea;
  --primary-hover: #2449c4;
  --primary-soft: #eaf0ff;
  --green: #1c8b52;
  --green-soft: #e5f5ec;
  --red: #c93434;
  --red-soft: #fcebeb;
  --amber: #a86500;
  --amber-soft: #fff4de;
  --blue: #2f5bea;
  --blue-soft: #eaf0ff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, 0.06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 4px; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1.05rem; margin: 0; }
code { font-family: ui-monospace, Consolas, monospace; font-size: 0.9em; background: #f0f2f6; padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 0.87rem; }
.prewrap { white-space: pre-wrap; word-break: break-word; }
.truncate { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { flex: 1; }
.print-only { display: none; }

/* ---------- Topbar ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 24px; min-height: 58px; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: #fff; font-weight: 700; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { color: var(--muted); padding: 6px 12px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.userbox form { margin: 0; }
.userbox-name { font-weight: 500; margin-right: 4px; }

/* ---------- Layout ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; }
.narrow { max-width: 760px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 2px 0; }
.page-head h1 .badge { vertical-align: middle; margin-left: 8px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin: 24px 0 12px; }
.section-head h2 { margin: 0; }
.back { display: inline-block; font-size: 0.9rem; margin-bottom: 6px; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 > .card, .grid-2 > .stack { margin-bottom: 16px; }
.grid-side { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.stack > .card:last-child { margin-bottom: 0; }
.empty { text-align: center; padding: 40px 20px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-group form { margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap; line-height: 1.3;
}
.btn:hover { background: #f0f2f6; text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #a92828; }
.btn-danger-ghost { color: var(--red); }
.btn-danger-ghost:hover { background: var(--red-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 0.87rem; }
.btn-lg { padding: 12px 24px; font-size: 1.05rem; }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form > .btn:not(.btn-block) { align-self: flex-start; }
.form label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; font-size: 0.93rem; }
.form .row { display: flex; gap: 12px; flex-wrap: wrap; }
.form .row > label { flex: 1; min-width: 160px; }
.form .row-end { align-items: flex-end; justify-content: space-between; }
input, select, textarea {
  font: inherit; color: inherit; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--primary); }
label.check { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 400 !important; cursor: pointer; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
legend { font-weight: 600; font-size: 0.93rem; padding: 0 6px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.checks-col { flex-direction: column; }
.tabs { flex-wrap: wrap; }
.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input { flex: 1; min-width: 180px; }
.filters select { width: auto; }
.option-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.option-row label.check { min-width: 58px; }
.flash ul { margin: 6px 0 0; padding-left: 20px; }

/* ---------- Flash / badges ---------- */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; border: 1px solid transparent; }
.flash-success { background: var(--green-soft); color: #145c38; border-color: #bfe5cf; }
.flash-error { background: var(--red-soft); color: #8e2020; border-color: #f2c4c4; }
.flash-info { background: var(--blue-soft); color: #1f3e9e; border-color: #cbd8fb; }
.flash-warn { background: var(--amber-soft); color: #7a4a00; border-color: #f5dca6; }
.publish-banner { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.publish-banner form { margin: 0; }
.badge { display: inline-block; font-size: 0.78rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: #eef0f4; color: var(--muted); white-space: nowrap; }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions form { display: inline; margin: 0; }
.table tr.inactive td { opacity: 0.55; }
.section-card-scroll, .card:has(> .table) { overflow-x: auto; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { display: flex; flex-direction: column; gap: 2px; margin: 0; color: inherit; }
a.stat:hover { border-color: var(--primary); text-decoration: none; }
.stat-value { font-size: 1.6rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.9rem; }
.stat-warn { border-color: #f5dca6; background: var(--amber-soft); }
.steps { margin: 0; padding-left: 22px; }
.steps li { margin-bottom: 6px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.danger-zone { border-color: #f2c4c4; }
.bar { height: 8px; border-radius: 4px; background: #eef0f4; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--green); }
.bar span.mid { background: #d99a1e; }
.bar span.low { background: var(--red); }

/* ---------- Questions ---------- */
.question-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.question-head form { margin: 0; }
.qnum { display: inline-grid; place-items: center; min-width: 28px; height: 28px; padding: 0 6px; border-radius: 8px; background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 0.9rem; }
.question-text { font-size: 1.02rem; margin-bottom: 12px; }
.options { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.options li { padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; display: flex; align-items: center; gap: 8px; }
.options li.correct { border-color: #bfe5cf; background: var(--green-soft); }
.options li.wrong { border-color: #f2c4c4; background: var(--red-soft); }
.options li.picked { font-weight: 600; }
.opt-mark { width: 16px; text-align: center; font-weight: 700; color: var(--green); }
.options li.wrong .opt-mark { color: var(--red); }
.legend-picked { font-weight: 700; }
.text-answer { padding: 10px 12px; background: #f7f8fa; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; }
.answer-ok { border-left: 4px solid var(--green); }
.answer-bad { border-left: 4px solid var(--red); }
.answer-review { border-left: 4px solid #d99a1e; }
.points-input { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; }
.points-input input { width: 80px; padding: 4px 8px; }
.score-box { text-align: right; }
.score-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.score-value small { font-size: 1rem; color: var(--muted); font-weight: 500; }
.sticky-actions { position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); text-align: right; }

/* ---------- Auth ---------- */
.auth-page .container { display: grid; place-items: center; min-height: calc(100vh - 60px); padding-top: 0; }
.auth-card { width: 100%; max-width: 380px; padding: 32px; text-align: center; }
.auth-card .form { text-align: left; margin-top: 16px; }
.auth-logo { display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 14px; background: var(--primary); color: #fff; font-size: 1.6rem; font-weight: 700; margin-bottom: 12px; }

/* ---------- Credentials ---------- */
.cred-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.cred { margin: 0; break-inside: avoid; }
.cred-name { font-weight: 700; }
.cred-row { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 0.9rem; }
.cred-row code { font-size: 1rem; }

/* ---------- Student ---------- */
.exam-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.exam-card { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.exam-card-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.exam-card .meta { list-style: none; padding: 0; margin: 0 0 auto; color: var(--muted); font-size: 0.9rem; }
.exam-card form { margin: 0; }
.status-open, .status-in_progress { border-color: #cbd8fb; }

.take-layout { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 20px; align-items: start; }
.take-head { margin-bottom: 16px; }
.take-side .sticky { position: sticky; top: 76px; }
.timer { font-size: 2.2rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; margin-bottom: 6px; }
.timer.warn { color: var(--amber); }
.timer.danger { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }
.progress-text { margin-bottom: 12px; }
.qnav { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 6px; margin-bottom: 12px; }
.qnav a { display: grid; place-items: center; height: 34px; border-radius: 8px; border: 1px solid var(--border); color: var(--muted); font-weight: 600; font-size: 0.9rem; }
.qnav a:hover { text-decoration: none; border-color: var(--primary); }
.qnav a.done { background: var(--primary); border-color: var(--primary); color: #fff; }
.save-status.error { color: var(--red); }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.choice:hover { border-color: #b9c6ef; background: #fafbff; }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice input { margin: 0; }
.choice-letter { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: #eef0f4; font-size: 0.8rem; font-weight: 700; color: var(--muted); flex-shrink: 0; }
.choice:has(input:checked) .choice-letter { background: var(--primary); color: #fff; }
.take-submit { text-align: center; }
.question { scroll-margin-top: 76px; }

.result-card { text-align: center; padding: 32px; }
.big-score { font-size: 3.2rem; font-weight: 800; line-height: 1.1; margin-top: 12px; color: var(--primary); }
.big-score small { font-size: 1.4rem; color: var(--muted); font-weight: 500; }
.result-msg { font-size: 1.05rem; }
.result-list { display: flex; flex-direction: column; gap: 8px; }
.result-row { display: flex; align-items: center; gap: 12px; margin: 0; padding: 12px 16px; }
.result-row .truncate { flex: 1; max-width: none; }
.result-state { white-space: nowrap; font-weight: 600; }
.answer-ok .result-state { color: var(--green); }
.answer-bad .result-state { color: var(--red); }

/* ---------- Import ---------- */
.howto { margin: 0 0 16px; padding: 14px 20px 14px 40px; font-size: 0.93rem; }
.howto li { margin: 2px 0; }
.import-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.import-input { display: flex; flex-direction: column; gap: 14px; margin: 0; }
.import-input textarea { font-family: ui-monospace, Consolas, monospace; font-size: 0.9rem; line-height: 1.5; min-height: 420px; }
.import-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.import-toolbar h2 { margin: 0; }
.import-preview { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow-y: auto; margin: 0; }
.import-preview .import-toolbar { margin-bottom: 12px; }
.preview-list { display: flex; flex-direction: column; gap: 10px; }
.preview-q { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.preview-q .question-text { margin-bottom: 8px; }
.preview-q.has-error { border-color: #f2c4c4; background: #fffafa; }
.preview-q-error { color: var(--red); margin-top: 6px; }
.format-help summary { cursor: pointer; font-weight: 500; color: var(--primary); }
.format-help .table { margin-top: 8px; }
.format-help td:first-child { white-space: nowrap; }
.prompt-dialog { width: min(760px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: 12px; padding: 20px; box-shadow: 0 20px 60px rgba(20, 30, 50, 0.25); }
.prompt-dialog::backdrop { background: rgba(20, 30, 50, 0.45); }
.prompt-dialog-head { display: flex; justify-content: space-between; align-items: center; }
.prompt-dialog-head h2 { margin: 0; }
.prompt-dialog textarea { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; background: #f7f8fa; margin: 8px 0 12px; }
.prompt-dialog-actions { width: 100%; }

/* ---------- Lessons ---------- */
.badge-red { background: var(--red-soft); color: var(--red); }
.text-error { color: var(--red); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; }
.center { justify-content: center; }
.empty-hero { text-align: center; padding: 32px 20px; border: 2px dashed #cbd8fb; background: #fafbff; }
.section-head-card { margin: 0 0 12px; }
.group-title { margin: 24px 0 12px; font-size: 1.05rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.group-title:first-of-type { margin-top: 0; }

.markdown { line-height: 1.7; word-wrap: break-word; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { margin: 1.4em 0 0.5em; line-height: 1.3; scroll-margin-top: 76px; }
.markdown h1 { font-size: 1.5rem; }
.markdown h2 { font-size: 1.3rem; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.markdown h3 { font-size: 1.1rem; }
.markdown p, .markdown ul, .markdown ol, .markdown blockquote, .markdown pre, .markdown table { margin: 0 0 1em; }
.markdown ul, .markdown ol { padding-left: 1.6em; }
.markdown li { margin: 0.2em 0; }
.markdown blockquote { border-left: 4px solid #cbd8fb; background: var(--primary-soft); padding: 10px 14px; border-radius: 0 8px 8px 0; color: #2b3a67; }
.markdown blockquote > :last-child { margin-bottom: 0; }
.markdown pre { background: #1e2433; color: #e7ebf3; padding: 14px 16px; border-radius: 8px; overflow-x: auto; font-size: 0.88rem; line-height: 1.5; }
.markdown pre code { background: none; padding: 0; color: inherit; font-size: inherit; }
.markdown table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 7px 12px; text-align: left; }
.markdown th { background: #f4f6fa; font-weight: 600; }
.markdown img { max-width: 100%; height: auto; border-radius: 8px; }
.markdown hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }
.theory { padding: 28px 32px; font-size: 1.02rem; }
.theory-collapsed { max-height: 320px; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }

.editor-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.editor-pane { margin: 0; display: flex; flex-direction: column; gap: 12px; }
.editor-pane textarea { font-family: ui-monospace, Consolas, monospace; font-size: 0.9rem; min-height: 60vh; line-height: 1.55; }
.editor-pane .markdown { max-height: 70vh; overflow-y: auto; }
.md-field { display: flex; flex-direction: column; gap: 5px; }
.md-field > label { font-weight: 500; font-size: 0.93rem; }
.md-split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.md-split textarea { font-family: ui-monospace, Consolas, monospace; font-size: 0.88rem; }
.md-preview-box { border: 1px dashed var(--border); border-radius: 8px; padding: 10px 14px; max-height: 360px; overflow-y: auto; background: #fcfcfd; font-size: 0.93rem; }

.file-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.file-list li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; flex-wrap: wrap; }
.file-list li form { margin: 0; }
.file-list li a:first-of-type { font-weight: 500; word-break: break-all; }
.file-icon { font-size: 1.1rem; }
.upload-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.upload-row input[type=file] { width: auto; flex: 1; min-width: 200px; }

.task-list { display: flex; flex-direction: column; gap: 8px; }
.task-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; flex-wrap: wrap; color: inherit; }
.task-row .btn-group form { margin: 0; }
.task-link:hover { border-color: var(--primary); text-decoration: none; background: #fafbff; }
.task-icon { font-size: 1.4rem; }
.task-main { flex: 1; min-width: 180px; }
.task-score { white-space: nowrap; }

.lesson-card { display: flex; flex-direction: column; gap: 8px; margin: 0; color: inherit; }
.lesson-card:hover { border-color: var(--primary); text-decoration: none; }
.lesson-card p { margin: 0; }
.lesson-card-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }
.lesson-layout { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 20px; align-items: start; }
.lesson-layout:has(> :only-child) { grid-template-columns: 1fr; }
.toc ul { list-style: none; padding: 0; margin: 6px 0 12px; font-size: 0.9rem; }
.toc li { margin: 4px 0; }
.toc .toc-3 { padding-left: 14px; font-size: 0.85rem; }
.feedback { margin-top: 14px; padding: 12px 14px; background: var(--primary-soft); border-radius: 8px; text-align: left; }

.dropzone { display: flex !important; flex-direction: column; align-items: center; justify-content: center; gap: 6px !important; padding: 28px 16px; border: 2px dashed #b9c6ef; border-radius: 12px; background: #fafbff; text-align: center; cursor: pointer; font-weight: 400 !important; }
.dropzone input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone.drag, .dropzone:hover { border-color: var(--primary); background: var(--primary-soft); }
.dropzone.has-files { border-style: solid; border-color: var(--green); background: var(--green-soft); }
.dropzone-files { font-weight: 600; color: var(--green); word-break: break-all; }

.review-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.review-main { margin: 0; }
.review-side .sticky { position: sticky; top: 76px; }
.review-side form:last-child { margin-top: 8px; }
.viewer-frame { width: 100%; height: 75vh; border: 1px solid var(--border); border-radius: 8px; background: #f7f8fa; }

.viewer { margin-bottom: 16px; }
.viewer-pdf { width: 100%; height: calc(100vh - 190px); min-height: 480px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.viewer-text { background: #fff; }
.viewer-img { max-width: 100%; display: block; margin: 0 auto; border-radius: 8px; box-shadow: var(--shadow); }
.viewer-media { max-width: 100%; display: block; margin: 0 auto; }
.docx-page { background: #fff; max-width: 820px; margin: 0 auto; padding: 48px 56px; border: 1px solid var(--border); border-radius: 4px; box-shadow: 0 2px 12px rgba(20, 30, 50, 0.08); }
.file-title { word-break: break-all; }
.embed-body { background: #fff; }
.embed-body .viewer { margin: 0; }
.embed-body .viewer-pdf { height: 100vh; min-height: 0; border: 0; border-radius: 0; }
.embed-body .docx-page { border: 0; box-shadow: none; padding: 24px; }
.embed-body .viewer-img { padding: 12px; box-shadow: none; }

.gradebook-wrap { overflow-x: auto; }
.gradebook th { text-transform: none; letter-spacing: 0; white-space: nowrap; }
.gradebook td:first-child, .gradebook th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 180px; }
.grade-cell { display: inline-block; min-width: 34px; padding: 2px 8px; border-radius: 6px; font-weight: 600; text-align: center; }
.grade-cell:hover { text-decoration: none; }
.grade-graded { background: var(--green-soft); color: var(--green); }
.grade-pending { background: var(--amber-soft); color: var(--amber); }

.preview-section { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; }
.preview-section-title { margin: 0 0 8px; font-size: 1rem; }
.preview-section .preview-list { margin-top: 10px; }
.preview-theory, .preview-instr { max-height: 420px; overflow-y: auto; margin-top: 8px; font-size: 0.93rem; }

/* ---------- Файлын урьдчилсан харагдац, PowerPoint ---------- */
.file-block { border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 14px; }
.file-block-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.file-block-name { word-break: break-all; }
.preview-img-link { display: block; text-align: center; background: #f4f6fa; border-radius: 8px; }
.preview-img { max-width: 100%; max-height: 80vh; display: inline-block; border-radius: 6px; }
.preview-frame { width: 100%; height: 70vh; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.slide-card h2 { word-break: break-word; }

.pptx-holder { position: absolute; left: -100000px; top: 0; }
.pptx-viewer { position: relative; outline: none; }
.pptx-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.pptx-pager { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pptx-pages { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pptx-page { min-width: 32px; height: 32px; padding: 0 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-size: 0.87rem; font-weight: 500; cursor: pointer; font-variant-numeric: tabular-nums; }
.pptx-page:hover { border-color: var(--primary); color: var(--primary); }
.pptx-page.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pptx-gap { color: var(--muted); padding: 0 2px; }
.pptx-counter { font-variant-numeric: tabular-nums; }
.pptx-stage { display: block; }
/* Нэг удаад зөвхөн одоогийн слайд харагдана */
.slide-frame { display: none; position: relative; width: 100%; overflow: hidden; background: #fff; border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow); cursor: pointer; user-select: none; }
.slide-frame.current { display: block; }
.pptx-viewer:focus-visible .slide-frame.current { outline: 2px solid var(--primary-soft); }
.pptx-present-nav { display: none; }

/* Үзүүлэх горим: бүтэн дэлгэц, нэг слайд */
.pptx-viewer.presenting { position: fixed; inset: 0; z-index: 1000; background: #000; display: flex; align-items: center; justify-content: center; }
.pptx-viewer.presenting .pptx-toolbar { display: none; }
.pptx-viewer.presenting .slide-frame { border: 0; border-radius: 0; box-shadow: none; margin: 0 auto; outline: none; }
.pptx-viewer.presenting .pptx-present-nav { display: flex; position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); align-items: center; gap: 10px; background: rgba(20, 24, 33, 0.72); padding: 6px 10px; border-radius: 999px; opacity: 0.25; transition: opacity 0.2s; z-index: 1001; }
.pptx-viewer.presenting .pptx-present-nav:hover { opacity: 1; }
.pptx-nav-btn { background: transparent; color: #fff; border: 0; font-size: 1.5rem; line-height: 1; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; }
.pptx-nav-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.15); }
.pptx-nav-btn:disabled { opacity: 0.3; cursor: default; }
.pptx-exit { font-size: 1.1rem; }
.pptx-nav-count { color: #fff; font-variant-numeric: tabular-nums; min-width: 64px; text-align: center; }
body.pptx-lock { overflow: hidden; }
@media (max-width: 600px) {
  .pptx-pager .btn { padding: 4px 8px; }
  .pptx-page { min-width: 28px; height: 28px; padding: 0 6px; }
}
.embed-body .pptx-viewer { padding: 12px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .grid-2, .grid-side, .take-layout, .import-layout, .editor-layout, .md-split, .lesson-layout, .review-layout { grid-template-columns: 1fr; }
  .lesson-side { display: none; }
  .theory { padding: 18px; }
  .docx-page { padding: 20px; }
  .review-side .sticky { position: static; }
  .import-preview { position: static; max-height: none; }
  .take-side { order: -1; }
  .take-side .sticky { top: 58px; z-index: 5; display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; align-items: center; padding: 12px 16px; }
  .take-side .qnav, .take-side .save-status { grid-column: 1 / -1; }
  .take-side .qnav { margin-bottom: 0; }
  .timer { font-size: 1.6rem; margin: 0; }
  .userbox-name { display: none; }
  .truncate { max-width: 180px; }
}

@media print {
  .topbar, .no-print, .flash { display: none !important; }
  .print-only { display: block; }
  body { background: #fff; }
  .container { padding: 0; }
  .card { box-shadow: none; }
}
