/* ============================================================
   ETHIO EXIT PREP — design system
   Single stylesheet for both the student and admin interfaces.
   Covers Phases 1–10.
   ============================================================ */

/* ============================================================
   1. Design tokens
   ============================================================ */
:root {
  /* Brand */
  --navy-900: #0b1b33;
  --navy-800: #12294a;
  --navy-700: #1a3a63;
  --navy-600: #23508c;
  --blue-500: #2f6fed;
  --blue-600: #245ad4;
  --cyan-500: #16b8c8;

  /* Surfaces */
  --bg:        #f5f7fb;
  --surface:   #ffffff;
  --surface-2: #f0f3f9;
  --border:    #dde3ee;

  /* Text */
  --text:  #16233a;
  --muted: #61708c;

  /* Semantic */
  --ok:       #1c8a5a;
  --ok-bg:    #e6f6ee;
  --bad:      #c0392b;
  --bad-bg:   #fdecea;
  --warn:     #b8730b;
  --warn-bg:  #fdf3e2;

  /* Sizing */
  --radius:    14px;
  --radius-sm: 10px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(16,32,60,.06);
  --shadow:    0 6px 24px rgba(16,32,60,.08);
  --shadow-lg: 0 18px 48px rgba(16,32,60,.16);

  /* Fonts */
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg:        #0a1424;
  --surface:   #101f36;
  --surface-2: #16273f;
  --border:    #22344f;
  --text:      #e7edf8;
  --muted:     #90a3bf;
  --ok-bg:     #10331f;
  --bad-bg:    #3a1a17;
  --warn-bg:   #3a2a10;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow:    0 6px 24px rgba(0,0,0,.4);
  --shadow-lg: 0 18px 48px rgba(0,0,0,.5);
}

/* ============================================================
   2. Reset and base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4 {
  margin: 0 0 .4em;
  line-height: 1.25;
  font-weight: 650;
  letter-spacing: -.01em;
}
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p  { margin: 0 0 .8em; }
a  { color: var(--blue-600); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: var(--mono); font-size: .88em; }
img, iframe, video { max-width: 100%; height: auto; }

/* Force [hidden] to win over class-level display rules */
[hidden] { display: none !important; }

/* Long words shouldn't blow out layouts */
.chat-body, .q-text, .lesson-body p, td, th {
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* ============================================================
   3. Accessibility — focus, skip link, sr-only
   ============================================================ */
:focus { outline: none; }

:focus-visible {
  outline: 3px solid var(--blue-500);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--blue-500);
  outline-offset: 2px;
}
[data-theme="dark"] :focus-visible {
  outline-color: #6aa3ff;
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute;
  top: -60px; left: 12px;
  background: var(--navy-900);
  color: #fff;
  padding: .65rem 1rem;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 650;
  z-index: 9999;
  transition: top .15s;
}
.skip-link:focus {
  top: 12px;
  outline: 3px solid var(--cyan-500);
  outline-offset: 2px;
}

/* ============================================================
   4. Typography helpers
   ============================================================ */
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.tiny  { font-size: .74rem; }
.stack > * + * { margin-top: .8rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
hr.sep { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

/* ============================================================
   5. Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .6rem 1.05rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--blue-600); color: #fff; }
.btn-primary:hover { background: var(--blue-500); text-decoration: none; }

.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-2); text-decoration: none; }

.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); text-decoration: none; }

.btn-sm { padding: .38rem .7rem; font-size: .82rem; }

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px; height: 38px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: background .15s;
}
.icon-btn:hover { background: var(--surface-2); }

/* ============================================================
   6. Shell — sidebar, topbar, main
   ============================================================ */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 246px;
  flex: 0 0 246px;
  background: var(--navy-900);
  color: #cfd9ea;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  gap: .7rem;
  align-items: center;
  padding: 1.1rem 1.1rem .9rem;
}
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 11px;
  flex: 0 0 38px;
  background: linear-gradient(135deg, var(--blue-500), var(--cyan-500));
  color: #fff;
  font-weight: 800;
  display: grid;
  place-items: center;
  font-size: .9rem;
  letter-spacing: .04em;
}
.brand-mark.big { width: 52px; height: 52px; flex-basis: 52px; border-radius: 14px; font-size: 1.1rem; }

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { color: #fff; font-size: .92rem; letter-spacing: .02em; }
.brand-text span   { font-size: .74rem; color: #8ea4c6; }

.nav { display: flex; flex-direction: column; padding: .4rem .6rem 1rem; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .7rem;
  border-radius: 9px;
  color: #b9c7de;
  font-size: .88rem;
  font-weight: 500;
  margin-bottom: 2px;
}
.nav-item:hover {
  background: rgba(255,255,255,.07);
  color: #fff;
  text-decoration: none;
}
.nav-item.active { background: var(--blue-600); color: #fff; }
.nav-item .ico { width: 18px; text-align: center; opacity: .85; font-size: .95rem; }

.nav-sep {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: #6a7f9f;
  padding: 1rem .7rem .35rem;
}

.sidebar-foot {
  padding: .8rem 1rem 1.2rem;
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-foot p { font-size: .72rem; color: #8ea4c6; margin: .4rem 0 0; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .8rem 1.4rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-title { font-weight: 650; font-size: 1rem; flex: 1; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: .6rem; }

.streak {
  background: var(--warn-bg);
  color: var(--warn);
  font-size: .78rem;
  font-weight: 650;
  padding: .35rem .7rem;
  border-radius: 999px;
  white-space: nowrap;
}
.flame { margin-right: .25rem; }
.menu-btn { display: none; }

.view {
  padding: 1.4rem;
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}
.view:focus { outline: none; }

/* ============================================================
   7. Cards and grids
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 1rem; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .7rem;
}
.card-head h3 { margin: 0; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

@media (max-width: 1050px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 700px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* Stat tiles */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.stat .label {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  font-weight: 600;
}
.stat .value {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -.02em;
  margin-top: .2rem;
}
.stat .sub { font-size: .78rem; color: var(--muted); }

/* ============================================================
   8. Progress bars
   ============================================================ */
.bar {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--blue-600);
  border-radius: 999px;
  transition: width .4s ease;
}
.bar.ok  > span { background: var(--ok); }
.bar.bad > span { background: var(--bad); }
.bar.thin { height: 6px; }

.bar-row { display: flex; align-items: center; gap: .7rem; }
.bar-row .bar { flex: 1; }
.bar-row .pct {
  font-size: .78rem;
  font-weight: 650;
  color: var(--muted);
  min-width: 44px;
  text-align: right;
}

/* ============================================================
   9. Pills
   ============================================================ */
.pill {
  display: inline-block;
  padding: .18rem .55rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 650;
  letter-spacing: .02em;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.pill-ok   { background: var(--ok-bg);   color: var(--ok);   border-color: transparent; }
.pill-bad  { background: var(--bad-bg);  color: var(--bad);  border-color: transparent; }
.pill-warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.pill-blue { background: #e8efff; color: var(--blue-600); border-color: transparent; }
[data-theme="dark"] .pill-blue { background: #1a2b4d; }

/* ============================================================
   10. Forms
   ============================================================ */
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; }
.field > span { font-size: .8rem; font-weight: 600; color: var(--muted); }
.field em { font-style: normal; font-weight: 400; opacity: .75; }

input[type=text],
input[type=date],
input[type=number],
input[type=email],
input[type=password],
input[type=search],
input[type=file],
input[type=datetime-local],
select,
textarea {
  font: inherit;
  font-size: .9rem;
  padding: .55rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--blue-500);
  outline-offset: 1px;
  border-color: var(--blue-500);
}
textarea { min-height: 88px; resize: vertical; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  align-items: center;
  margin-bottom: 1rem;
}
.toolbar .field { margin: 0; min-width: 150px; }
.search-input { min-width: 220px; }

/* ============================================================
   11. Tables
   ============================================================ */
table.tbl { width: 100%; border-collapse: collapse; font-size: .87rem; }
table.tbl th,
table.tbl td {
  text-align: left;
  padding: .55rem .6rem;
  border-bottom: 1px solid var(--border);
}
table.tbl th {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  font-weight: 650;
}
table.tbl tr:last-child td { border-bottom: none; }
table.tbl td.num,
table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Tables on small screens — horizontal scroll, no layout break */
@media (max-width: 700px) {
  table.tbl {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ============================================================
   12. Course cards
   ============================================================ */
.course-card {
  display: flex;
  flex-direction: column;
  gap: .55rem;
}
.course-card .cc-top {
  display: flex;
  justify-content: space-between;
  gap: .6rem;
  align-items: flex-start;
}
.course-card h3 { margin: 0; font-size: .98rem; word-break: break-word; }
.course-card .desc { font-size: .82rem; color: var(--muted); flex: 1; }

/* ============================================================
   13. Question UI
   ============================================================ */
.q-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
}
.q-meta { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .8rem; }
.q-text { font-size: 1.02rem; font-weight: 550; margin-bottom: 1rem; }

.options { display: flex; flex-direction: column; gap: .5rem; }

.option {
  display: flex;
  align-items: flex-start;
  gap: .7rem;
  padding: .7rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--surface);
  transition: border-color .15s, background .15s;
  text-align: left;
  font: inherit;
  color: inherit;
  width: 100%;
}
.option:hover { border-color: var(--blue-500); background: var(--surface-2); }
.option .letter {
  width: 24px; height: 24px; flex: 0 0 24px;
  border-radius: 7px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-size: .78rem;
  font-weight: 700;
  color: var(--muted);
}
.option.selected { border-color: var(--blue-600); background: #eaf1ff; }
[data-theme="dark"] .option.selected { background: #16294a; }
.option.selected .letter { background: var(--blue-600); color: #fff; }

.option.correct { border-color: var(--ok); background: var(--ok-bg); }
.option.correct .letter { background: var(--ok); color: #fff; }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); }
.option.wrong .letter { background: var(--bad); color: #fff; }
.option:disabled { cursor: default; }

.feedback {
  margin-top: 1rem;
  padding: .85rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .88rem;
}
.feedback.ok  { background: var(--ok-bg);  color: var(--ok); }
.feedback.bad { background: var(--bad-bg); color: var(--bad); }
.feedback strong { display: block; margin-bottom: .3rem; }
.feedback .expl { color: var(--text); font-weight: 400; margin-top: .4rem; }

.q-nav {
  display: flex;
  align-items: center;
  gap: .7rem;
  margin-top: 1.1rem;
  flex-wrap: wrap;
}
.q-nav .spacer { flex: 1; }

/* ============================================================
   14. Exam navigator and timer
   ============================================================ */
.exam-layout {
  display: grid;
  grid-template-columns: 1fr 268px;
  gap: 1rem;
  align-items: start;
}
@media (max-width: 900px) {
  .exam-layout { grid-template-columns: 1fr; }
}

.exam-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--navy-700);
  background: var(--surface-2);
  padding: .35rem .8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  min-width: 90px;
  text-align: center;
}
.exam-timer.low {
  color: var(--bad);
  background: var(--bad-bg);
  border-color: transparent;
}

.navigator {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: .35rem;
}
.nav-cell {
  aspect-ratio: 1;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: .75rem;
  font-weight: 650;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-family: inherit;
}
.nav-cell.answered { background: var(--blue-600); border-color: var(--blue-600); color: #fff; }
.nav-cell.flagged  { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.nav-cell.current  { outline: 2px solid var(--navy-800); outline-offset: 1px; }

.nav-legend {
  display: flex;
  flex-wrap: wrap;
  gap: .7rem;
  font-size: .74rem;
  color: var(--muted);
  margin-top: .7rem;
}
.nav-legend i {
  width: 11px; height: 11px;
  border-radius: 3px;
  display: inline-block;
  margin-right: .3rem;
  vertical-align: -1px;
}

@media (max-width: 700px) {
  .navigator { grid-template-columns: repeat(5, 1fr); }
}

/* ============================================================
   15. Flashcards
   ============================================================ */
.flashcard { perspective: 1200px; max-width: 620px; margin: 0 auto; }
.flashcard-inner {
  position: relative;
  width: 100%;
  min-height: 280px;
  transition: transform .55s;
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }

.flash-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.6rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  box-shadow: var(--shadow);
  overflow-y: auto;
}
.flash-face.back { transform: rotateY(180deg); }
.flash-face .kicker {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  font-weight: 650;
  margin-bottom: .5rem;
}
.flash-face .body { font-size: 1.02rem; }

/* ============================================================
   16. PDF viewer
   ============================================================ */
.pdf-frame {
  width: 100%;
  height: 78vh;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #525659;
}
.pdf-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: .75rem 0;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}
.pdf-list-item:last-child { border-bottom: none; }
.pdf-list-item:hover { background: var(--surface-2); }
.pdf-list-item .row { flex-shrink: 0; }

@media (max-width: 700px) {
  .pdf-list-item {
    flex-direction: column;
    align-items: flex-start;
    gap: .6rem;
  }
  .pdf-list-item .row { width: 100%; }
  .pdf-list-item .row .btn { flex: 1; }
}

/* ============================================================
   17. Lesson reader
   ============================================================ */
.lesson-body { font-size: 1rem; line-height: 1.7; }
.lesson-body h1 { font-size: 1.5rem;  margin: 1.2rem 0 .6rem; }
.lesson-body h2 { font-size: 1.25rem; margin: 1.1rem 0 .5rem; }
.lesson-body h3 { font-size: 1.08rem; margin: 1rem 0 .4rem; }
.lesson-body p { margin: 0 0 .9rem; }
.lesson-body ul,
.lesson-body ol { margin: 0 0 .9rem 1.2rem; padding: 0; }
.lesson-body li { margin-bottom: .3rem; }
.lesson-body code {
  background: var(--surface-2);
  padding: .12rem .35rem;
  border-radius: 4px;
  font-size: .88em;
}
.lesson-body pre {
  background: var(--navy-900);
  color: #e7edf8;
  padding: .9rem 1rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0 0 1rem;
  line-height: 1.5;
}
[data-theme="dark"] .lesson-body pre { background: #060f1e; }
.lesson-body pre code { background: transparent; padding: 0; color: inherit; }
.lesson-body strong { font-weight: 650; }
.lesson-body em { font-style: italic; }

/* ============================================================
   18. Empty state
   ============================================================ */
.empty {
  text-align: center;
  padding: 2.4rem 1.2rem;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.empty .big { font-size: 1.7rem; margin-bottom: .4rem; opacity: .5; }
.empty h3 { color: var(--text); }

/* ============================================================
   19. Onboarding / Auth
   ============================================================ */
.onboarding {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background: linear-gradient(160deg, var(--navy-900), var(--navy-700));
}
.ob-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 2rem;
  max-width: 640px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.ob-brand {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.2rem;
}
.ob-brand h1 { margin: 0; font-size: 1.35rem; letter-spacing: .01em; }
.tagline { margin: .1rem 0 0; color: var(--muted); font-size: .86rem; }
.ob-lead { color: var(--muted); font-size: .92rem; }

.ob-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
  margin: 1rem 0 .5rem;
}
@media (max-width: 560px) { .ob-grid { grid-template-columns: 1fr; } }

.ob-actions {
  display: flex;
  gap: .7rem;
  flex-wrap: wrap;
  margin-top: .6rem;
}
.ob-note { font-size: .76rem; color: var(--muted); margin-top: 1rem; }

/* Auth tabs */
.auth-tabs {
  display: flex;
  gap: .3rem;
  background: var(--surface-2);
  padding: .3rem;
  border-radius: 12px;
  margin-bottom: 1rem;
}
.auth-tab {
  flex: 1;
  padding: .55rem;
  border: none;
  background: transparent;
  border-radius: 9px;
  font: inherit;
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
  color: var(--muted);
}
.auth-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
#authForm,
#adminLoginForm { display: flex; flex-direction: column; gap: .2rem; }
#authForm .btn,
#adminLoginForm .btn { width: 100%; margin-top: .4rem; padding: .7rem; }
#authError,
#aErr { margin: .3rem 0 .4rem; }

/* ============================================================
   20. Modal and toast
   ============================================================ */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8,18,34,.55);
}
.modal {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.3rem 1.4rem;
  max-width: 480px;
  width: calc(100% - 2rem);
  box-shadow: var(--shadow-lg);
  max-height: 86vh;
  overflow-y: auto;
}
.modal :focus-visible {
  outline: 3px solid var(--blue-500);
  outline-offset: 2px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: .6rem;
  margin-top: 1.1rem;
}

.toast {
  position: fixed;
  bottom: 1.4rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy-900);
  color: #fff;
  padding: .7rem 1.1rem;
  border-radius: 10px;
  font-size: .86rem;
  z-index: 300;
  box-shadow: var(--shadow-lg);
  max-width: calc(100% - 2rem);
}

@media (max-width: 560px) {
  .modal {
    width: calc(100% - 1rem);
    padding: 1rem;
    max-height: 92vh;
    border-radius: 12px;
  }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }
  .toast { left: 1rem; right: 1rem; transform: none; max-width: none; text-align: center; }
}

/* ============================================================
   21. Lists
   ============================================================ */
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li {
  padding: .55rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: .7rem;
  align-items: center;
}
.list-plain li:last-child { border-bottom: none; }

/* ============================================================
   22. Community chat
   ============================================================ */
.chat-card {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  max-height: calc(100vh - 220px);
  min-height: 420px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.2rem;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.chat-empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.chat-empty .big { font-size: 2rem; margin-bottom: .4rem; opacity: .5; }

.chat-day {
  text-align: center;
  color: var(--muted);
  font-size: .74rem;
  margin: 1rem 0 .5rem;
  text-transform: uppercase;
  letter-spacing: .1em;
}

.chat-msg { display: flex; margin-bottom: .3rem; }
.chat-msg.mine { justify-content: flex-end; }

.chat-bubble {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: .55rem .8rem .5rem;
  max-width: min(72%, 620px);
  min-width: 200px;
  box-shadow: var(--shadow-sm);
}
.chat-msg.mine .chat-bubble {
  background: #eaf1ff;
  border-color: #d0e0ff;
}
[data-theme="dark"] .chat-msg.mine .chat-bubble {
  background: #1a2b4d;
  border-color: #26406e;
}
.chat-bubble.announcement {
  background: var(--warn-bg);
  border-color: var(--warn);
}
[data-theme="dark"] .chat-bubble.announcement {
  background: #3a2a10;
  border-color: #b8730b;
}

.chat-msg-head {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
  margin-bottom: .25rem;
}
.chat-author { font-weight: 650; font-size: .85rem; }
.chat-time { font-size: .7rem; color: var(--muted); margin-left: auto; }

.chat-body {
  font-size: .92rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-body.muted { color: var(--muted); font-style: italic; }

.chat-reply-preview {
  background: rgba(0,0,0,.04);
  border-left: 3px solid var(--blue-600);
  padding: .35rem .55rem;
  border-radius: 6px;
  margin-bottom: .35rem;
}
[data-theme="dark"] .chat-reply-preview { background: rgba(255,255,255,.05); }
.chat-reply-preview .small {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-attachments {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  margin-top: .5rem;
}
.chat-image {
  max-width: 260px;
  max-height: 220px;
  border-radius: 10px;
  border: 1px solid var(--border);
  object-fit: cover;
  display: block;
}
.chat-file {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .45rem .65rem;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  font-size: .85rem;
}
.chat-file:hover { background: var(--surface-2); text-decoration: none; }
.chat-file .ico  { font-size: 1rem; }
.chat-file .name { flex: 1; word-break: break-all; }

.chat-actions {
  display: flex;
  gap: .2rem;
  margin-top: .35rem;
  opacity: 0;
  transition: opacity .12s;
}
.chat-bubble:hover .chat-actions { opacity: 1; }
.chat-bubble:focus-within .chat-actions { opacity: 1; }
.chat-actions .btn { padding: .15rem .4rem; font-size: .74rem; }

.chat-composer {
  border-top: 1px solid var(--border);
  padding: .7rem .9rem;
  background: var(--surface);
}
.chat-input-row {
  display: flex;
  gap: .5rem;
  align-items: flex-end;
}
.chat-input-row textarea {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 160px;
  font-size: .92rem;
  line-height: 1.4;
  padding: .55rem .7rem;
}
.chat-input-row .icon-btn { flex: 0 0 38px; height: 40px; }

.chat-reply-banner,
.chat-file-preview {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .4rem .6rem;
  background: var(--surface-2);
  border-radius: 8px;
  margin-bottom: .5rem;
}
.chat-file-preview { font-size: .84rem; }

.chat-composer-help { margin-top: .35rem; text-align: right; }

@media (max-width: 700px) {
  .chat-bubble { max-width: 88%; min-width: 0; }
  .chat-image { max-width: 200px; max-height: 200px; }
  .chat-card { max-height: calc(100vh - 180px); }
}

/* ============================================================
   23. Notifications
   ============================================================ */
.notif-bell { position: relative; }

.notif-badge {
  position: absolute;
  top: -4px; right: -4px;
  background: var(--bad);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--surface);
}

.notif-row {
  display: flex;
  gap: .7rem;
  align-items: flex-start;
  padding: .8rem .9rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
}
.notif-row:last-child { border-bottom: none; }
.notif-row:hover { background: var(--surface-2); }
.notif-row.read { opacity: .55; }

.notif-dot {
  width: 8px; height: 8px;
  margin-top: .5rem;
  flex: 0 0 8px;
  border-radius: 50%;
  background: var(--blue-600);
}
.notif-row.read .notif-dot { background: transparent; }

/* ============================================================
   24. Analytics — weekly bar chart
   ============================================================ */
.week-chart {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  height: 160px;
  padding: .5rem 0;
}
.week-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  height: 100%;
}
.week-bar-wrap {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.week-bar {
  width: 70%;
  max-width: 42px;
  background: linear-gradient(180deg, var(--blue-500), var(--blue-600));
  border-radius: 6px 6px 0 0;
  transition: height .3s ease;
  min-height: 4px;
}
.week-count { font-size: .74rem; font-weight: 650; color: var(--text); margin-top: .3rem; }
.week-label {
  font-size: .68rem;
  color: var(--muted);
  margin-top: .15rem;
  white-space: nowrap;
}

@media (max-width: 700px) {
  .week-chart { height: 120px; }
  .week-count { font-size: .68rem; }
  .week-label { font-size: .62rem; }
}

/* ============================================================
   25. Analytics — 30-day activity heat strip
   ============================================================ */
.activity-heat {
  display: grid;
  grid-template-columns: repeat(30, 1fr);
  gap: 3px;
  height: 70px;
  margin-top: .3rem;
}
.activity-cell {
  display: flex;
  align-items: flex-end;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}
.activity-cell.zero { background: var(--surface-2); }
.activity-bar {
  width: 100%;
  background: var(--blue-600);
  transition: height .2s;
}
.activity-cell.lo  .activity-bar { background: #7da3e8; }
.activity-cell.mid .activity-bar { background: var(--blue-500); }
.activity-cell.hi  .activity-bar { background: var(--blue-600); }

@media (max-width: 700px) {
  .activity-heat { grid-template-columns: repeat(15, 1fr); height: 100px; }
}

/* ============================================================
   26. Skeleton loaders
   ============================================================ */
.skeleton-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  margin-bottom: 1rem;
}
.skeleton-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(
    90deg,
    var(--surface-2) 0%,
    var(--border)    50%,
    var(--surface-2) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s linear infinite;
  margin-bottom: .55rem;
}
.skeleton-line.w-40 { width: 40%; }
.skeleton-line.w-60 { width: 60%; }

.skeleton-list { display: flex; flex-direction: column; gap: .8rem; }
.skeleton-row  { display: flex; gap: .8rem; align-items: center; }
.skeleton-avatar {
  width: 34px; height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  background: linear-gradient(
    90deg,
    var(--surface-2) 0%,
    var(--border)    50%,
    var(--surface-2) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s linear infinite;
}
@keyframes skeleton-shimmer {
  0%   { background-position:  200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================
   27. Offline banner + noscript
   ============================================================ */
.offline-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--warn);
  color: #fff;
  text-align: center;
  padding: .55rem;
  font-size: .88rem;
  font-weight: 600;
  z-index: 500;
}
.noscript-warning {
  max-width: 640px;
  margin: 3rem auto;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}

/* ============================================================
   28. Error pages
   ============================================================ */
.error-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background: linear-gradient(160deg, var(--navy-900), var(--navy-700));
}

/* ============================================================
   29. Mobile bottom nav
   ============================================================ */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 60px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 90;
  box-shadow: 0 -4px 16px rgba(0,0,0,.06);
}
[data-theme="dark"] .mobile-nav { box-shadow: 0 -4px 16px rgba(0,0,0,.35); }
.mobile-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 1.15rem;
  color: var(--muted);
  text-decoration: none;
  padding: .35rem 0;
  min-height: 44px;
}
.mobile-nav a span { font-size: .68rem; font-weight: 600; }
.mobile-nav a.active { color: var(--blue-600); }
.mobile-nav a:focus-visible { outline-offset: -3px; }

@media (max-width: 860px) {
  .mobile-nav { display: flex; }
  .view { padding-bottom: 80px; }
  .sidebar { z-index: 100; }
}

/* ============================================================
   30. Sidebar drawer on mobile
   ============================================================ */
@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    z-index: 100;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-flex; }
  .view { padding: 1rem 1rem 80px; }
  .topbar { padding: .7rem 1rem; }
}

/* ============================================================
   31. Touch targets on mobile
   ============================================================ */
@media (max-width: 860px) {
  .btn { min-height: 44px; padding: .7rem 1rem; }
  .btn-sm { min-height: 38px; padding: .5rem .8rem; }
  .icon-btn { width: 44px; height: 44px; }
  .nav-item { padding: .75rem .8rem; min-height: 44px; }
  /* Prevent iOS zoom on focus */
  input, select, textarea { font-size: 16px; }
}

/* ============================================================
   32. Auth screen polish on small screens
   ============================================================ */
@media (max-width: 560px) {
  .onboarding { padding: 1rem .6rem; }
  .auth-tabs { font-size: .85rem; }
  .ob-actions { flex-direction: column; }
  .ob-actions .btn { width: 100%; }
  .ob-card { padding: 1.3rem; border-radius: 14px; }
}

/* ============================================================
   33. Reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .skeleton-line,
  .skeleton-avatar { animation: none; }
  .flashcard-inner  { transition: none; }
}

/* ============================================================
   34. High contrast preference
   ============================================================ */
@media (prefers-contrast: more) {
  :root {
    --border: #b6c1d3;
    --muted:  #47536a;
  }
  [data-theme="dark"] {
    --border: #435a7e;
    --muted:  #c4d3ea;
  }
  .btn-outline { border-width: 2px; }
  .pill { border-width: 2px; }
}

/* ============================================================
   35. Dark mode fallback when no data-theme is set
   ============================================================ */
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    --bg:        #0a1424;
    --surface:   #101f36;
    --surface-2: #16273f;
    --border:    #22344f;
    --text:      #e7edf8;
    --muted:     #90a3bf;
  }
}
/* ============================================================
   Markdown images in lessons
   ============================================================ */
.md-img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin: .6rem 0;
  display: block;
}

/* ============================================================
   Admin identity in chat
   ============================================================ */
.chat-bubble.admin-bubble {
  border-left: 4px solid #d4a017;
  background: linear-gradient(135deg, var(--surface-2), #fff8e6);
}
[data-theme="dark"] .chat-bubble.admin-bubble {
  background: linear-gradient(135deg, #16273f, #2a2410);
}
.chat-author.admin-author {
  color: #d4a017;
}
.chat-author.admin-author::after {
  content: " · Administrator";
  font-size: .7rem;
  font-weight: 500;
  opacity: .7;
  margin-left: .2rem;
}

/* ============================================================
   Question editor (mockup-style two-column form)
   ============================================================ */
.modal.modal-wide {
  max-width: 780px;
}

.qedit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.3rem;
}
@media (max-width: 720px) {
  .qedit-grid { grid-template-columns: 1fr; }
}

.qedit-col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.qedit-section {
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.qedit-label {
  font-size: .82rem;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: .01em;
}

.qedit-qtext {
  min-height: 110px;
  font-size: 1rem;
  font-family: var(--font);
  line-height: 1.5;
}

.qedit-option {
  display: flex;
  align-items: center;
  gap: .6rem;
}
.qedit-option input { flex: 1; }

.qedit-letter {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 7px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: .82rem;
  color: var(--muted);
  transition: background .12s, color .12s;
}
.qedit-option:focus-within .qedit-letter {
  background: var(--blue-600);
  color: #fff;
}

.qedit-expl {
  min-height: 140px;
  line-height: 1.55;
}

.qedit-more {
  border-top: 1px solid var(--border);
  padding-top: .6rem;
  margin-top: .2rem;
}
.qedit-more summary {
  list-style: none;
  cursor: pointer;
  padding: .3rem 0;
  user-select: none;
}
.qedit-more summary::-webkit-details-marker { display: none; }
.qedit-more summary::before {
  content: "▸ ";
  color: var(--muted);
}
.qedit-more[open] summary::before {
  content: "▾ ";
}
