:root {
  --bg: #f3f7fd;
  --surface: #ffffff;
  --surface-2: #eef3fb;
  --text: #0e2b3d;
  --body: #4a5868;
  --muted: #6b7785;
  --border: #dfe6f1;
  --primary: #086ad8;
  --primary-dark: #0c4da2;
  --primary-ink: #ffffff;
  --primary-soft: #e3eefc;
  --navy: #001d4c;
  --ok: #1a8a4a;
  --ok-soft: #e4f5ea;
  --warn: #a96500;
  --warn-soft: #fff3dc;
  --bad: #c0362c;
  --bad-soft: #fde8e6;
  --info: #086ad8;
  --info-soft: #e3eefc;
  --radius: 10px;
  --shadow: 0 2px 6px rgba(0, 29, 76, .05), 0 8px 24px rgba(0, 29, 76, .05);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--body); font-size: 15px; line-height: 1.55; min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { color: var(--text); }
h1 { font-size: 1.7rem; line-height: 1.25; margin: 0 0 .4rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
img { max-width: 100%; }

/* Layout */
.container { max-width: 1240px; width: 100%; margin: 0 auto; padding: 24px 16px 48px; flex: 1; }
.narrow { max-width: 480px; }
.narrow-wide { max-width: 860px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.mt { margin-top: 16px; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.small { font-size: .85rem; }
.muted { color: var(--muted); }
.text-ok { color: var(--ok); }
.text-bad { color: var(--bad); }
.hint { color: var(--muted); font-weight: 400; font-size: .82rem; }
.pre { white-space: pre-wrap; }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { padding: 4px 0; border-bottom: 1px solid var(--border); }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid-2 > .card + .card, .grid-main > .card + .card, .course-grid > .card + .card, .stats > .card + .card { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.empty { text-align: center; padding: 32px 20px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.actions, .row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form, .row-actions form { margin: 0; }
.crumbs { margin-bottom: 12px; font-size: .9rem; }
.danger-zone { border-color: var(--bad-soft); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; line-height: 1.2; text-decoration: none; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled, .btn.disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger-ghost { color: var(--bad); }
.btn-small { padding: 5px 10px; font-size: .85rem; }
.btn-block { width: 100%; }
.link-btn { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }
.link-btn:hover { text-decoration: underline; }
.link-btn.text-bad { color: var(--bad); }

/* Forms */
.form label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 14px; }
.form label > input, .form label > select, .form label > textarea { margin-top: 6px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], input:not([type]), select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; }
.mono-soft { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }
.form label.check, label.check { display: flex; align-items: flex-start; gap: 8px; font-weight: 400; margin-bottom: 10px; cursor: pointer; }
label.check input { margin-top: 4px; width: auto; }
label.inline { display: flex; align-items: center; gap: 8px; font-weight: 400; }
label.inline input { width: auto; margin: 0; }
.fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px 6px; margin: 0 0 16px; }
.fieldset legend { font-weight: 700; padding: 0 6px; }
.fieldset .sub { border-top: 1px dashed var(--border); padding-top: 12px; margin-top: 4px; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filters input, .filters select { width: auto; min-width: 200px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { width: auto; }
.file-current { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0 16px; margin-bottom: 8px; }
.assign-form { border-top: 1px solid var(--border); margin-top: 16px; padding-top: 16px; }
.assign-list { max-height: 360px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin: 8px 0 14px; }

/* Uploader */
.uploader { border: 2px dashed var(--border); border-radius: 10px; padding: 14px; margin-bottom: 10px; background: var(--surface-2); }
.uploader.dragover { border-color: var(--primary); background: var(--primary-soft); }
.uploader input[type=file] { width: 100%; }
.uploader.done { border-style: solid; border-color: var(--ok); }
.up-progress { margin-top: 10px; }

/* Alerts & badges */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 14px; border: 1px solid transparent; }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-bad { background: var(--bad-soft); color: var(--bad); }
.alert-info { background: var(--info-soft); color: var(--info); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; vertical-align: middle; 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-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: var(--surface-2); color: var(--muted); }
a.badge:hover { text-decoration: none; filter: brightness(.95); }
.creds-box { white-space: pre; font-family: ui-monospace, monospace; background: var(--surface); color: var(--text); padding: 10px 12px; border-radius: 8px; margin: 10px 0; font-size: .9rem; overflow-x: auto; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table.compact th, .table.compact td { padding: 6px 8px; overflow-wrap: anywhere; }
.table tr.inactive td { opacity: .55; }
.table-scroll { overflow-x: auto; padding: 0; }
.matrix th, .matrix td { white-space: nowrap; }
.matrix .sticky { position: sticky; left: 0; background: var(--surface); z-index: 1; }
.lesson-th { display: inline-block; max-width: 140px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
.cell { display: inline-grid; place-items: center; min-width: 30px; height: 26px; padding: 0 6px; border-radius: 6px; font-size: .8rem; font-weight: 700; }
.cell.st-completed { background: var(--ok-soft); color: var(--ok); }
.cell.st-in_progress { background: var(--warn-soft); color: var(--warn); }
.cell.st-not_started { background: var(--surface-2); color: var(--muted); }
.quiz-score { display: block; font-size: .75rem; font-weight: 700; }
.legend { margin-bottom: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pager { display: flex; gap: 8px; justify-content: center; margin-top: 16px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-num { font-size: 1.9rem; font-weight: 800; color: var(--primary); }
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.activity li:last-child { border-bottom: 0; }
.activity li > .small, .activity li > .muted { display: block; }

/* Progress */
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; display: block; margin: 8px 0 4px; }
.progress-bar { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .4s; }
.ring { --pct: 0; width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 8px;
  background: radial-gradient(closest-side, var(--surface) 78%, transparent 80% 100%), conic-gradient(var(--primary) calc(var(--pct) * 1%), var(--surface-2) 0); }
.ring span { font-weight: 800; font-size: 1.2rem; }
.ring.big { width: 120px; height: 120px; margin: 0; flex: none; }
.ring.big span { font-size: 1.5rem; }

/* Learner */
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.course-card { color: var(--text); display: flex; flex-direction: column; transition: transform .15s, box-shadow .15s; }
.course-card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: 0 6px 20px rgba(20,30,60,.08); }
.course-card h3 { font-size: 1.1rem; margin: 10px 0 6px; }
.course-card-top { display: flex; justify-content: space-between; align-items: center; }
.course-card .progress { margin-top: auto; }
.course-hero { display: flex; gap: 24px; margin-bottom: 24px; }
.course-hero-main { flex: 1; }
.course-hero-side { width: 220px; display: flex; flex-direction: column; gap: 10px; }
.lesson-list { list-style: none; padding: 0; margin: 0; }
.lesson-item { display: flex; align-items: center; gap: 14px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.lesson-item:last-child { border-bottom: 0; }
.lesson-item.locked { opacity: .55; }
.lesson-icon { width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-weight: 700; flex: none; font-size: .9rem; }
.lesson-item.st-completed .lesson-icon { background: var(--ok-soft); color: var(--ok); }
.lesson-meta { flex: 1; }
.lesson-meta a { font-weight: 600; }
.lesson-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 20px; align-items: start; }
.lesson-side { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; padding: 16px; }
.side-lessons { list-style: none; padding: 0; margin: 12px 0 0; }
.side-lessons li { display: flex; gap: 10px; align-items: flex-start; padding: 7px 8px; border-radius: 8px; font-size: .9rem; }
.side-lessons li.current { background: var(--primary-soft); font-weight: 600; }
.side-lessons li.locked { opacity: .5; }
.side-lessons .dot { width: 22px; height: 22px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: .7rem; flex: none; font-weight: 700; }
.side-lessons li.st-completed .dot { background: var(--ok-soft); color: var(--ok); }
.side-lessons a { color: var(--text); }
.lesson-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.player-wrap { background: #000; border-radius: var(--radius); overflow: hidden; }
.player-wrap video { width: 100%; max-height: 72vh; display: block; background: #000; }
.player-wrap.ratio { position: relative; aspect-ratio: 16 / 9; }
.player-wrap.ratio iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.watch-meter { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.watch-meter .progress { flex: 1; margin: 0; }
.slides { padding: 12px; }
.slides-stage { position: relative; background: var(--surface-2); border-radius: 8px; display: grid; place-items: center; min-height: 300px; overflow: hidden; }
.slides-stage canvas { max-width: 100%; height: auto; display: block; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.slides-loading { position: absolute; color: var(--muted); }
.slides-bar { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; }
.slides-count { min-width: 80px; text-align: center; font-weight: 600; }
.slides:fullscreen { background: #000; display: flex; flex-direction: column; justify-content: center; }
.slides:fullscreen .slides-stage { background: #000; flex: 1; }
.slides:fullscreen canvas { max-height: calc(100vh - 120px); width: auto !important; }
.prose p:last-child { margin-bottom: 0; }
.prose { overflow-wrap: anywhere; }
.lesson-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 24px; }
.quiz-box-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.quiz-box h2 { margin-bottom: 2px; }
.quiz-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.quiz-actions form { display: flex; gap: 10px; align-items: center; margin: 0; }

/* Quiz */
.question { border: 1px solid var(--border); }
.question legend { font-weight: 600; font-size: 1.02rem; padding: 0; margin-bottom: 10px; float: left; width: 100%; }
.question legend + * { clear: both; }
.qnum { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: .8rem; font-weight: 700; margin-right: 6px; }
.options { display: grid; gap: 8px; margin-top: 10px; clear: both; }
.option { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border: 1px solid var(--border); border-radius: 9px; cursor: pointer; font-weight: 400; }
.option:hover { background: var(--surface-2); }
.option input { margin-top: 4px; }
.option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.quiz-submit { display: flex; justify-content: space-between; align-items: center; position: sticky; bottom: 12px; margin-top: 16px; }
.timer { font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; background: var(--surface); border: 1px solid var(--border); padding: 6px 14px; border-radius: 10px; }
.timer.low { color: var(--bad); border-color: var(--bad); }
.result-hero { display: flex; gap: 24px; align-items: center; margin-bottom: 20px; }
.result-hero.is-pass { border-color: var(--ok); }
.result-hero.is-fail { border-color: var(--bad); }
.review.ok { border-left: 4px solid var(--ok); }
.review.bad { border-left: 4px solid var(--bad); }
.review-head { font-weight: 600; display: flex; gap: 6px; align-items: flex-start; }
.review-mark { margin-left: auto; font-size: 1.2rem; }
.review.ok .review-mark { color: var(--ok); }
.review.bad .review-mark { color: var(--bad); }
.review-options { list-style: none; padding: 0; margin: 10px 0; }
.review-options li { padding: 6px 10px; border-radius: 6px; }
.review-options li.is-correct { background: var(--ok-soft); }
.review-options li.is-picked:not(.is-correct) { background: var(--bad-soft); }
.explanation { background: var(--surface-2); padding: 10px 12px; border-radius: 8px; }

/* Admin: sortable & enrollments */
.sortable { list-style: none; padding: 0; margin: 0; }
.sortable li { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; background: var(--surface); }
.sortable li.dragging { opacity: .5; }
.sortable .handle { cursor: grab; color: var(--muted); user-select: none; }
.sortable .pos { width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: .8rem; font-weight: 700; flex: none; }
.enroll { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; }
.enroll summary { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(80px, 1fr) auto auto; gap: 14px; align-items: center; padding: 12px 14px; cursor: pointer; }
.enroll-title { font-weight: 600; }
.enroll-body { padding: 0 14px 14px; }
.enroll-bar .progress { margin: 0; }

/* Quiz editor */
.ai-panel summary { cursor: pointer; }
.ai-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 12px; }
.ai-grid label, .ai-panel > label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 12px; }
.ai-grid input, .ai-grid select, .ai-panel textarea { margin-top: 6px; }
.ai-types { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.ai-types label.check { margin: 0; }
.qe-q { margin-bottom: 14px; }
.qe-q-head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.qe-q-head select { width: auto; }
.qe-q-head .tools { margin-left: auto; display: flex; gap: 4px; }
.qe-q-head .tools button { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; cursor: pointer; color: var(--muted); }
.qe-q-head .tools button:hover { color: var(--text); background: var(--surface-2); }
.qe-q.new-ai { border-color: var(--primary); }
.qe-opt { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.qe-opt input[type=text] { flex: 1; }
.qe-opt .correct { display: flex; align-items: center; gap: 4px; font-size: .8rem; color: var(--muted); white-space: nowrap; cursor: pointer; }
.qe-opt.is-correct input[type=text] { border-color: var(--ok); background: var(--ok-soft); }
.qe-opt button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1.1rem; }
.qe-q textarea { margin-bottom: 8px; }
.qe-q .qe-row { display: flex; gap: 12px; align-items: center; margin-top: 8px; }
.qe-q .qe-row input[type=number] { width: 80px; }
.qe-settings { position: sticky; top: 76px; }
.savebar { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); border-radius: 12px; padding: 10px 12px 10px 18px; display: flex; gap: 16px; align-items: center; box-shadow: 0 10px 30px rgba(0,0,0,.25); z-index: 30; }

/* Auth */
.auth-wrap { max-width: 460px; width: 100%; margin: 56px auto 64px; padding: 0 16px; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 1.3rem; font-weight: 800; margin-bottom: 20px; }
.auth-card h1 { font-size: 1.4rem; }
.error-code { font-size: 3rem; font-weight: 800; color: var(--primary); }

/* Responsive */
@media (max-width: 960px) {
  .grid-main, .lesson-layout { grid-template-columns: 1fr; }
  .lesson-side { position: static; max-height: none; order: 2; }
  .qe-settings { position: static; }
  .ai-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .grid-2 { grid-template-columns: 1fr; }
  .uname { display: none; }
  .course-hero { flex-direction: column; }
  .course-hero-side { width: auto; }
  .enroll summary { grid-template-columns: 1fr auto; }
  .enroll-bar { display: none; }
  .table { font-size: .9rem; }
  .result-hero { flex-direction: column; text-align: center; }
  .card { padding: 16px; }
}
