/* ============================================================
   DS Athena — App Stylesheet
   public/assets/css/app.css
   Sibling of DS Eos: same crimson structure, olive accent.
   See design/DESIGN.md for the token rationale.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --crimson:   #8B1A3C;
  --crimson-d: #6a1330;
  --crimson-l: #f7e8ed;
  --olive:     #C3CF5B;
  --olive-d:   #5F6B1A;
  --olive-l:   #f2f4e1;
  --ink:       #1A1A1A;
  --muted:     #6b625b;
  --border:    #e0dbd9;
  --surface:   #f8f6f4;
  --white:     #fff;
  --green:     #2e7d52;
  --blue:      #185fa5;
  --amber:     #8a5a10;
  --red:       #b3261e;
  --card-bg:        #ffffff;
  --nav-bg:         #ffffff;
  --modal-bg:       #ffffff;
  --header-bg:      #8B1A3C;
  --header-accent:  #C3CF5B;
  --th-bg:          #8B1A3C;
  --th-color:       #ffffff;
  --row-hover:      #faf8f7;
  --bar-track:      #ede8e5;
  --border-subtle:  #f0ebe8;
  --surface-raised: #fafafa;
  --pill-green-bg: #eaf3de; --pill-green: #27500a;
  --pill-amber-bg: #faeeda; --pill-amber: #8a5a10;
  --pill-red-bg:   #fcebeb; --pill-red:   #a32d2d;
  --pill-blue-bg:  #e6f1fb; --pill-blue:  #185fa5;
  --pill-grey-bg:  #f1efe8; --pill-grey:  #5f5e5a;
  --focus: #5F6B1A;
  --mono: 'DM Mono', ui-monospace, monospace;
}

[data-theme="dark"] {
  --crimson:        #e0668a;
  --crimson-d:      #c8385e;
  --crimson-l:      #2a121c;
  --olive:          #C3CF5B;
  --olive-d:        #b4c04f;
  --olive-l:        #1c1f0c;
  --ink:            #ece6e0;
  --muted:          #a59b8c;
  --border:         #2e2823;
  --surface:        #0e0c0a;
  --white:          #181410;
  --green:          #3ec077;
  --blue:           #6aaee6;
  --amber:          #e0a548;
  --red:            #f0857c;
  --card-bg:        #181410;
  --nav-bg:         #120f0c;
  --modal-bg:       #1c1814;
  --header-bg:      #5c1228;
  --th-bg:          #300e1a;
  --th-color:       #f2e0e6;
  --row-hover:      #201c18;
  --bar-track:      #2a2520;
  --border-subtle:  #221d19;
  --surface-raised: #1c1814;
  --pill-green-bg: #14301f; --pill-green: #7ed9a4;
  --pill-amber-bg: #33240a; --pill-amber: #f0bd6a;
  --pill-red-bg:   #3a1614; --pill-red:   #f5a29b;
  --pill-blue-bg:  #10263b; --pill-blue:  #8cc3f0;
  --pill-grey-bg:  #26221d; --pill-grey:  #b9b0a3;
  --focus: #C3CF5B;
  color-scheme: dark;
}

html, body { height: 100%; }
body {
  font-family: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--surface);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
a { color: var(--crimson); }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
img { max-width: 100%; }
h1, h2, h3 { font-weight: 600; line-height: 1.25; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Focus ───────────────────────────────────────────────── */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
#app-header :focus-visible, .boot-screen .btn-ms:focus-visible { outline-color: #fff; }

::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d6cdc9; border-radius: 3px; }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #2e2a24; }

/* ── Loading + auth screens (Eos pattern) ────────────────── */
.boot-screen {
  position: fixed; inset: 0; background: #8B1A3C; z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 16px;
}
.boot-inner { color: #fff; text-align: center; }
.boot-word { font-size: 28px; font-weight: 600; margin-bottom: 4px; }
.boot-word span, .auth-word span { color: #C3CF5B; }
.boot-tag { font-size: 13px; color: rgba(255,255,255,.75); letter-spacing: .08em; text-transform: uppercase; margin-bottom: 32px; }
.boot-spinner {
  width: 40px; height: 40px; border: 3px solid rgba(255,255,255,.2); border-top-color: #C3CF5B;
  border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.auth-card {
  background: #fff; color: #1A1A1A; border-radius: 12px; padding: 36px 48px 32px; max-width: 380px; width: 100%;
  text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.auth-icon { border-radius: 12px; margin-bottom: 14px; }
.auth-word { font-size: 22px; font-weight: 600; color: #8B1A3C; margin-bottom: 4px; }
.auth-word span { color: #5F6B1A; }
.auth-tag { font-size: 11px; color: #6b625b; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 28px; }
.btn-ms {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: #0078d4; color: #fff; padding: 12px 24px; border-radius: 8px;
  font-size: 14px; font-weight: 500; text-decoration: none; transition: background .15s;
}
.btn-ms:hover { background: #005ba3; }
.auth-card .btn-ms:focus-visible { outline: 2px solid #1A1A1A; outline-offset: 2px; }
.auth-note { font-size: 11px; color: #6b625b; margin-top: 20px; }
.auth-dev { display: inline-block; margin-top: 14px; font-size: 12px; color: #6b625b; }
.auth-dev:hover { color: #8B1A3C; }
@media (max-width: 420px) { .auth-card { padding: 30px 24px 26px; } }

/* ── Shell ───────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
#app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--header-bg); border-bottom: 3px solid var(--header-accent);
  height: calc(52px + env(safe-area-inset-top)); flex-shrink: 0; z-index: 100; position: relative;
  padding: env(safe-area-inset-top) max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
  color: #fff;
}
.hdr-left, .hdr-right { display: flex; align-items: center; gap: 14px; min-width: 0; }
.hdr-brand { color: #fff; font-size: 17px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.hdr-brand span { color: var(--header-accent); }
.hdr-divider { width: 1px; height: 22px; background: rgba(255,255,255,.25); }
.hdr-app { color: rgba(255,255,255,.8); font-size: 12px; font-weight: 500; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
#nav-toggle {
  display: none; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.25); color: #fff;
  width: 36px; height: 36px; border-radius: 8px; cursor: pointer; align-items: center; justify-content: center; flex-shrink: 0;
}
#hdr-userbox { text-align: right; line-height: 1.25; min-width: 0; }
#hdr-userbox .n { font-size: 12px; font-weight: 500; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
#hdr-userbox .r { font-size: 10px; color: rgba(255,255,255,.75); }
.avatar-btn {
  width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.2); border: 1.5px solid rgba(255,255,255,.4);
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; color: #fff; cursor: pointer;
}
.user-menu {
  position: absolute; right: max(12px, env(safe-area-inset-right)); top: calc(48px + env(safe-area-inset-top));
  background: var(--modal-bg); color: var(--ink); border: 1px solid var(--border); border-radius: 10px; padding: 8px;
  min-width: 220px; box-shadow: 0 8px 28px rgba(0,0,0,.28); z-index: 600;
}
.user-menu .um-head { padding: 6px 10px 10px; border-bottom: 1px solid var(--border-subtle); margin-bottom: 6px; }
.user-menu .um-head .n { font-weight: 600; font-size: 13px; }
.user-menu .um-head .e { font-size: 11px; color: var(--muted); word-break: break-all; }
.user-menu a, .user-menu button {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 9px 10px; border-radius: 6px;
  background: none; border: none; cursor: pointer; font-size: 13px; color: var(--ink); text-decoration: none;
}
.user-menu a:hover, .user-menu button:hover { background: var(--surface); }

.shell-body { display: flex; flex: 1; min-height: 0; }
#sidebar {
  width: 224px; background: var(--nav-bg); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto; flex-shrink: 0;
}
.nav-group { padding: 10px 0 2px; }
.nav-label { font-size: 10px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); padding: 0 16px 5px; }
.nav-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 16px; cursor: pointer; transition: background .12s, color .12s;
  font-size: 13px; font-weight: 400; color: var(--muted); border-left: 3px solid transparent; user-select: none; text-decoration: none;
}
.nav-item svg { flex-shrink: 0; }
.nav-item:hover  { background: var(--surface); color: var(--ink); }
.nav-item.active { background: var(--crimson-l); color: var(--crimson); font-weight: 600; border-left-color: var(--crimson); }
.nav-item:focus-visible { outline-offset: -2px; }
.nav-foot { margin-top: auto; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); font-size: 11px; color: var(--muted); border-top: 1px solid var(--border-subtle); }
.nav-foot a { color: var(--muted); }
#sidebar-backdrop { display: none; }
#main-content { flex: 1; overflow-y: auto; padding: 20px 24px calc(28px + env(safe-area-inset-bottom)); min-width: 0; }
#main-content:focus { outline: none; }
.page { max-width: 1180px; margin: 0 auto; }
.page-narrow { max-width: 860px; }

/* ── Page head ───────────────────────────────────────────── */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-title { font-size: 22px; font-weight: 600; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--crimson); text-decoration: underline; }
.section-title { font-size: 15px; font-weight: 600; margin: 22px 0 10px; display: flex; align-items: center; gap: 8px; }
.section-title .count { font-family: var(--mono); font-size: 11px; color: var(--muted); background: var(--bar-track); border-radius: 10px; padding: 1px 7px; font-weight: 500; }

/* ── Cards ───────────────────────────────────────────────── */
.card { background: var(--card-bg); border: 0.5px solid var(--border); border-radius: 10px; margin-bottom: 16px; overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 0.5px solid var(--border); flex-wrap: wrap; gap: 8px; }
.card-title { font-size: 14px; font-weight: 600; color: var(--ink); }
.card-body { padding: 16px; }
[data-theme="dark"] .card { box-shadow: 0 1px 4px rgba(0,0,0,.4); }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; margin-bottom: 4px; }
.stat { background: var(--card-bg); border: 0.5px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.stat .k { font-size: 10px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.stat .v { font-family: var(--mono); font-size: 24px; font-weight: 500; margin-top: 2px; }
.stat.bad .v { color: var(--red); }
.stat.good .v { color: var(--green); }

.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.course-card {
  display: flex; flex-direction: column; background: var(--card-bg); border: 0.5px solid var(--border); border-radius: 10px;
  overflow: hidden; text-decoration: none; color: var(--ink); transition: border-color .12s, transform .12s, box-shadow .12s;
}
.course-card:hover { border-color: var(--crimson); transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.08); }
.cover {
  aspect-ratio: 16 / 9; background: linear-gradient(135deg, #5a0f26, #8B1A3C 60%, #a3214a); position: relative;
  display: flex; align-items: center; justify-content: center; color: rgba(195,207,91,.9); font-size: 34px; font-weight: 600; overflow: hidden;
}
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover .cover-cat { position: absolute; left: 10px; top: 10px; background: rgba(0,0,0,.45); color: #fff; font-size: 10px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; padding: 3px 8px; border-radius: 20px; }
.cover .cover-status { position: absolute; right: 10px; top: 10px; }
.course-card .cc-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.course-card .cc-title { font-size: 14px; font-weight: 600; }
.course-card .cc-sum { font-size: 12.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.course-card .cc-meta { margin-top: auto; padding-top: 6px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; font-size: 11.5px; color: var(--muted); }

/* list rows (assigned, continue, path items, lesson list) */
.rows { list-style: none; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 0.5px solid var(--border-subtle);
  text-decoration: none; color: var(--ink);
}
.rows > li:last-child > .row, .rows > .row:last-child { border-bottom: none; }
a.row:hover, button.row:hover { background: var(--row-hover); }
button.row { width: 100%; background: none; border-left: none; border-right: none; border-top: none; text-align: left; cursor: pointer; }
.row .r-main { flex: 1; min-width: 0; }
.row .r-title { font-weight: 600; font-size: 14px; }
.row .r-sub { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row .r-side { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.row .r-bar { width: 110px; display: block; }
.row.overdue { box-shadow: inset 3px 0 0 var(--red); }
.row .chev { color: var(--muted); flex-shrink: 0; }
.type-ico {
  width: 34px; height: 34px; border-radius: 8px; background: var(--crimson-l); color: var(--crimson);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.tick {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--border); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: transparent; background: var(--card-bg);
}
.tick.done { background: var(--green); border-color: var(--green); color: #fff; }
.tick.part { border-color: var(--blue); background: linear-gradient(90deg, var(--blue) 50%, transparent 50%); }

/* ── Progress ────────────────────────────────────────────── */
.bar { height: 6px; background: var(--bar-track); border-radius: 3px; overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--olive-d); border-radius: 3px; transition: width .3s; }
.bar.done > i { background: var(--green); }
.bar-wrap { display: flex; align-items: center; gap: 8px; }
.bar-wrap .bar { flex: 1; }
.bar-wrap .pct { font-family: var(--mono); font-size: 11.5px; color: var(--muted); min-width: 34px; text-align: right; }

/* ── Pills / chips ───────────────────────────────────────── */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; background: var(--pill-grey-bg); color: var(--pill-grey); }
.pill.green { background: var(--pill-green-bg); color: var(--pill-green); }
.pill.amber { background: var(--pill-amber-bg); color: var(--pill-amber); }
.pill.red   { background: var(--pill-red-bg);   color: var(--pill-red); }
.pill.blue  { background: var(--pill-blue-bg);  color: var(--pill-blue); }
.pill.olive { background: var(--olive-l); color: var(--olive-d); }
.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  padding: 6px 13px; border-radius: 20px; border: 1px solid var(--border); background: var(--card-bg); color: var(--ink);
  font-size: 12.5px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.chip:hover { border-color: var(--crimson); }
.chip[aria-pressed="true"] { background: var(--crimson); border-color: var(--crimson); color: #fff; }
[data-theme="dark"] .chip[aria-pressed="true"] { background: var(--crimson-d); border-color: var(--crimson-d); }
.overdue-text { color: var(--red); font-weight: 600; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  font-size: 13px; font-weight: 500; cursor: pointer; border: 1px solid transparent; transition: background .12s, border-color .12s;
  white-space: nowrap; text-decoration: none; line-height: 1.3;
}
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-crimson { background: #8B1A3C; color: #fff; }
.btn-crimson:hover:not([disabled]) { background: #6a1330; }
.btn-olive { background: var(--olive); color: #1A1A1A; font-weight: 600; }
.btn-olive:hover:not([disabled]) { background: #b3c04a; }
.btn-ghost { background: var(--card-bg); color: var(--ink); border-color: var(--border); }
.btn-ghost:hover:not([disabled]) { background: var(--surface); }
.btn-danger { background: var(--card-bg); color: var(--red); border-color: var(--red); }
.btn-danger:hover:not([disabled]) { background: var(--pill-red-bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 20px; font-size: 14px; }
.btn-block { width: 100%; }
.icon-btn {
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px;
  background: none; border: 1px solid transparent; color: var(--muted); cursor: pointer; flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface); color: var(--ink); border-color: var(--border); }
.icon-btn[disabled] { opacity: .35; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Forms ───────────────────────────────────────────────── */
.form-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; display: block; }
.form-input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
  outline: none; background: var(--surface); color: var(--ink); min-height: 36px;
}
textarea.form-input { min-height: 90px; resize: vertical; line-height: 1.45; }
.form-input:focus { border-color: var(--crimson); background: var(--card-bg); box-shadow: 0 0 0 2px var(--crimson-l); }
.form-input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.form-hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; min-height: 32px; }
.check input { width: 17px; height: 17px; accent-color: #8B1A3C; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.toolbar .field { min-width: 150px; flex: 1; max-width: 260px; }
.toolbar .field.grow { max-width: none; flex: 2; }
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-wrap .form-input { padding-left: 32px; }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { background: var(--th-bg); color: var(--th-color); padding: 8px 12px; text-align: left; font-size: 10px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
.tbl td { padding: 9px 12px; border-bottom: 0.5px solid var(--border-subtle); vertical-align: middle; }
.tbl tbody tr:hover td { background: var(--row-hover); }
.tbl td.num, .tbl th.num { text-align: right; font-family: var(--mono); font-size: 12px; }
.tbl .t-strong { font-weight: 600; }
.tbl .t-sub { font-size: 11.5px; color: var(--muted); }
.tbl tr.is-overdue td:first-child { box-shadow: inset 3px 0 0 var(--red); }

/* ── Empty / error / skeleton ────────────────────────────── */
.empty { text-align: center; color: var(--muted); padding: 36px 16px; font-size: 13.5px; }
.empty svg { color: var(--border); margin-bottom: 8px; }
.empty .e-title { color: var(--ink); font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }
.error-panel { border: 1px solid var(--red); background: var(--pill-red-bg); color: var(--pill-red); border-radius: 10px; padding: 14px 16px; }
.view-loading { display: flex; justify-content: center; padding: 60px 0; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--bar-track); border-top-color: var(--crimson); border-radius: 50%; animation: spin .8s linear infinite; }

/* ── Modals ──────────────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal {
  background: var(--modal-bg); border-radius: 12px; width: 560px; max-width: 100%; max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); border: 1px solid var(--border);
}
.modal.wide { width: 780px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ── Toasts ──────────────────────────────────────────────── */
.toast-wrap { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; gap: 8px; align-items: center; width: max-content; max-width: calc(100vw - 24px); pointer-events: none; }
.toast { background: #240a13; color: #f6eef1; padding: 10px 16px; border-radius: 8px; font-size: 13px; box-shadow: 0 8px 28px rgba(0,0,0,.3); border-left: 4px solid #C3CF5B; pointer-events: auto; animation: toast-in .18s ease-out; }
.toast.error { border-left-color: #ff8a80; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ── Course page ─────────────────────────────────────────── */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.hero-main .cover { border-radius: 10px; margin-bottom: 14px; max-height: 280px; width: 100%; }
.hero-title { font-size: 24px; font-weight: 600; margin: 6px 0; }
.meta-line { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); align-items: center; }
.meta-line span { display: inline-flex; gap: 5px; align-items: center; }
.prose { font-size: 14.5px; line-height: 1.6; overflow-wrap: anywhere; }
.prose h1, .prose h2, .prose h3 { margin: 1.1em 0 .4em; }
.prose h1 { font-size: 20px; } .prose h2 { font-size: 17px; } .prose h3 { font-size: 15px; }
.prose p, .prose ul, .prose ol, .prose table, .prose blockquote { margin: 0 0 .8em; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose img, .prose video { max-width: 100%; height: auto; border-radius: 6px; }
.prose table { border-collapse: collapse; } .prose td, .prose th { border: 1px solid var(--border); padding: 5px 8px; }
.prose blockquote { border-left: 3px solid var(--olive); padding-left: 12px; color: var(--muted); }
.ring { --p: 0; width: 76px; height: 76px; border-radius: 50%; background: conic-gradient(var(--olive-d) calc(var(--p) * 1%), var(--bar-track) 0); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ring.done { background: conic-gradient(var(--green) 100%, var(--bar-track) 0); }
.ring > span { width: 60px; height: 60px; border-radius: 50%; background: var(--card-bg); display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 15px; font-weight: 500; }
.side-card .card-body { display: flex; flex-direction: column; gap: 12px; }
.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.kv .k { color: var(--muted); }

/* ── Lesson player ───────────────────────────────────────── */
.player { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.player-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.player-head h1 { font-size: 19px; flex: 1; min-width: 200px; }
.stage { background: var(--card-bg); border: 0.5px solid var(--border); border-radius: 10px; overflow: hidden; }
.stage-pad { padding: 20px; }
.video-box { background: #000; aspect-ratio: 16 / 9; width: 100%; display: flex; }
.video-box video, .video-box iframe { width: 100%; height: 100%; border: 0; background: #000; }
.doc-frame { width: 100%; height: min(78vh, 900px); border: 0; display: block; background: #525659; }
.stage-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-top: 0.5px solid var(--border); flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.player-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; }
.player-nav .btn { max-width: 48%; overflow: hidden; text-overflow: ellipsis; }
.lesson-rail .row { padding: 10px 14px; }
.lesson-rail .row.current { background: var(--crimson-l); box-shadow: inset 3px 0 0 var(--crimson); }
.lesson-rail .r-title { font-size: 13px; font-weight: 500; }

/* ── Quiz ────────────────────────────────────────────────── */
.quiz { max-width: 720px; margin: 0 auto; padding: 22px 20px 20px; }
.quiz-progress { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; font-size: 12px; color: var(--muted); }
.quiz-progress .bar { flex: 1; }
.quiz-q { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.quiz-q .prose { font-size: 17px; font-weight: 600; line-height: 1.4; }
.quiz-hint { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.opts { display: flex; flex-direction: column; gap: 8px; border: 0; }
.opt { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border: 1.5px solid var(--border); border-radius: 10px; cursor: pointer; background: var(--card-bg); font-size: 14.5px; }
.opt:hover { border-color: var(--olive-d); }
.opt input { width: 18px; height: 18px; accent-color: #5F6B1A; flex-shrink: 0; }
.opt:has(input:checked) { border-color: var(--olive-d); background: var(--olive-l); }
.opt:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.quiz-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 20px; }
.result { text-align: center; padding: 10px 0 4px; }
.result-badge { width: 84px; height: 84px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.result.pass .result-badge { background: var(--pill-green-bg); color: var(--green); }
.result.fail .result-badge { background: var(--pill-red-bg); color: var(--red); }
.result h2 { font-size: 22px; }
.result .score { font-family: var(--mono); font-size: 44px; font-weight: 500; margin: 6px 0 2px; }
.result.pass .score { color: var(--green); } .result.fail .score { color: var(--red); }
.feedback { text-align: left; margin-top: 20px; }
.feedback .fb { border: 0.5px solid var(--border); border-left: 4px solid var(--green); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; font-size: 13px; }
.feedback .fb.wrong { border-left-color: var(--red); }
.feedback .fb .fb-a { color: var(--muted); margin-top: 3px; font-size: 12.5px; }

/* ── Learning path ───────────────────────────────────────── */
.phase { margin-bottom: 18px; }
.phase-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 0.5px solid var(--border); flex-wrap: wrap; }
.phase-num { width: 28px; height: 28px; border-radius: 50%; background: var(--crimson); color: #fff; font-family: var(--mono); font-size: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
[data-theme="dark"] .phase-num { background: var(--header-bg); }
.phase-num.done { background: var(--green); }
.phase-name { font-weight: 600; font-size: 14.5px; flex: 1; min-width: 120px; }
.phase-meta { font-size: 12px; color: var(--muted); font-family: var(--mono); }
.due { font-size: 12px; white-space: nowrap; }
.due.overdue { color: var(--red); font-weight: 600; }
.due.soon { color: var(--amber); font-weight: 600; }

/* ── Certificates ────────────────────────────────────────── */
.cert-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.cert { background: var(--card-bg); border: 0.5px solid var(--border); border-radius: 10px; padding: 16px; display: flex; flex-direction: column; gap: 8px; border-top: 4px solid var(--olive); }
.cert .c-title { font-weight: 600; font-size: 15px; }
.cert .c-num { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.cert-frame { width: 100%; height: 70vh; border: 0; background: #fff; display: block; }

/* ── Admin editor ────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 9px 14px; font-size: 13px; font-weight: 500; color: var(--muted); background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; text-decoration: none; margin-bottom: -1px; }
.tab:hover { color: var(--ink); }
.tab.active, .tab[aria-selected="true"] { color: var(--crimson); border-bottom-color: var(--crimson); font-weight: 600; }
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.sortable .row { cursor: default; padding: 8px 10px 8px 6px; gap: 8px; }
.sortable li[draggable="true"] { transition: background .1s; }
.sortable li.dragging { opacity: .4; }
.sortable li.drop-before { box-shadow: inset 0 3px 0 var(--olive-d); }
.sortable li.drop-after { box-shadow: inset 0 -3px 0 var(--olive-d); }
.grip { cursor: grab; color: var(--muted); padding: 6px 2px; display: flex; touch-action: none; }
.upload { border: 1.5px dashed var(--border); border-radius: 10px; padding: 14px; background: var(--surface); }
.upload.drag { border-color: var(--olive-d); background: var(--olive-l); }
.upload .u-file { font-size: 13px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; overflow-wrap: anywhere; }
.upload progress { width: 100%; height: 8px; accent-color: #5F6B1A; }
.q-card { border: 0.5px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; display: flex; gap: 10px; align-items: flex-start; }
.q-card .q-n { font-family: var(--mono); font-size: 12px; color: var(--muted); padding-top: 2px; }
.q-card .q-main { flex: 1; min-width: 0; font-size: 13px; }
.opt-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.opt-row input[type=checkbox], .opt-row input[type=radio] { width: 18px; height: 18px; accent-color: #2e7d52; flex-shrink: 0; }

/* ── Responsive ──────────────────────────────────────────── */
@media (min-width: 1200px) {
  .player.with-rail { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
}
@media (max-width: 1000px) {
  .hero { grid-template-columns: 1fr; }
  .editor-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  body { font-size: 15px; }
  #nav-toggle { display: inline-flex; }
  #app-header { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .hdr-left { gap: 10px; }
  #hdr-userbox { display: none; }
  #sidebar {
    position: fixed; top: calc(52px + env(safe-area-inset-top)); left: 0; bottom: 0; z-index: 400;
    width: 250px; max-width: 82vw; transform: translateX(-100%); transition: transform .22s ease; box-shadow: 8px 0 32px rgba(0,0,0,.28);
    visibility: hidden;
  }
  body.nav-open #sidebar { transform: translateX(0); visibility: visible; }
  #sidebar-backdrop {
    display: block; position: fixed; inset: calc(52px + env(safe-area-inset-top)) 0 0 0; z-index: 390;
    background: rgba(0,0,0,.42); opacity: 0; pointer-events: none; transition: opacity .22s ease; border: 0;
  }
  body.nav-open #sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .nav-item { padding: 12px 18px; font-size: 14px; }
  #main-content { padding: 14px 13px calc(24px + env(safe-area-inset-bottom)); }
  .btn { padding: 10px 14px; min-height: 40px; }
  .btn-sm { padding: 7px 11px; min-height: 34px; }
  .icon-btn { width: 38px; height: 38px; }
  .form-input, select.form-input, textarea.form-input { font-size: 16px; min-height: 42px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .page-title { font-size: 20px; }
  .hero-title { font-size: 21px; }
  .course-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .toolbar .field { max-width: none; min-width: 46%; }
}
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .course-grid { grid-template-columns: 1fr; }
  .course-card { flex-direction: row; }
  .course-card .cover { width: 104px; aspect-ratio: auto; flex-shrink: 0; font-size: 26px; }
  .course-card .cover .cover-cat { display: none; }
  .course-card .cover .cover-status { right: auto; left: 6px; top: 6px; }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal, .modal.wide { width: 100%; max-height: 94vh; max-height: 94dvh; border-radius: 14px 14px 0 0; }
  .modal-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .stage { border-radius: 0; margin: 0 -13px; border-left: 0; border-right: 0; }
  .doc-frame { height: 68vh; }
  .quiz { padding: 16px 14px; }
  .quiz-actions .btn { flex: 1; }
  .row { padding: 12px 13px; }
  .row .r-bar { display: none; }
  /* stacked tables */
  .table-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { padding: 10px 13px; border-bottom: 0.5px solid var(--border); }
  .table-stack td { padding: 2px 0; border: 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table-stack td::before { content: attr(data-label); color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; text-align: left; flex-shrink: 0; padding-top: 2px; font-family: 'DM Sans', system-ui, sans-serif; }
  .table-stack td.t-head { display: block; text-align: left; font-weight: 600; padding-bottom: 4px; }
  .table-stack td.t-head::before { content: none; }
  .table-stack tbody tr:hover td { background: none; }
  .table-stack tr.is-overdue { box-shadow: inset 3px 0 0 var(--red); }
  .table-stack tr.is-overdue td:first-child { box-shadow: none; }
}
@media (max-width: 420px) {
  #main-content { padding: 12px 10px calc(24px + env(safe-area-inset-bottom)); }
  .stage { margin: 0 -10px; }
  .card-header { padding: 10px 12px; }
  .hdr-divider, .hdr-app { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: .001s !important; }
  .boot-spinner, .spinner { animation-duration: 1.2s !important; }
}
@media print {
  #app-header, #sidebar, .toast-wrap { display: none !important; }
  body { overflow: visible; } #app { height: auto; } #main-content { overflow: visible; }
}
