:root {
  --brand: #1f4e79;
  --brand-dark: #153a5b;
  --accent: #f0a500;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1c2733;
  --muted: #5d6b7a;
  --line: #dde3ea;
  --ok: #1e8e4e;
  --bad: #c0392b;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

/* Header with logo + institution name */
.site-header {
  background: var(--brand);
  color: #fff;
  border-bottom: 4px solid var(--accent);
}
.site-header .inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.site-header img { height: 56px; width: auto; max-width: 30vw; border-radius: 6px; background: #fff; object-fit: contain; }
.site-header .name { font-size: 1.25rem; font-weight: 700; line-height: 1.2; }
.site-header .spacer { flex: 1; }
.site-header .who { font-size: .9rem; opacity: .9; }
@media (max-width: 560px) {
  .site-header img { height: 44px; }
  .site-header .name { font-size: 1rem; }
}

main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 20px 16px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.login-card { max-width: 400px; margin: 24px auto; }
h1 { font-size: 1.4rem; margin: 0 0 6px; }
h2 { font-size: 1.15rem; margin: 0 0 10px; }
p.muted, .muted { color: var(--muted); }

label { display: block; font-weight: 600; margin: 14px 0 4px; }
input[type=text], input[type=password], input[type=email] {
  width: 100%;
  padding: 11px 12px;
  font-size: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
input:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
button, .btn {
  display: inline-block;
  margin-top: 18px;
  padding: 11px 18px;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--brand);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
}
button:hover, .btn:hover { background: var(--brand-dark); }
button:disabled { opacity: .6; cursor: wait; }
button.full { width: 100%; }
button.secondary { background: #fff; color: var(--brand); border: 1px solid var(--brand); margin-top: 0; padding: 7px 14px; }

.msg { margin-top: 14px; padding: 10px 12px; border-radius: 8px; font-size: .95rem; display: none; }
.msg.show { display: block; }
.msg.error { background: #fdecea; color: var(--bad); border: 1px solid #f5c6c0; }
.msg.ok { background: #e8f6ee; color: var(--ok); border: 1px solid #bfe3cd; }

.site-footer { text-align: center; padding: 16px; color: var(--muted); font-size: .95rem; border-top: 1px solid var(--line); background: #fff; }

/* ---------- Admin navigation ---------- */
.nav { background: #fff; border-bottom: 1px solid var(--line); }
.nav .inner { max-width: 1100px; margin: 0 auto; padding: 0 12px; display: flex; gap: 4px; overflow-x: auto; }
.nav a { padding: 12px 14px; color: var(--muted); text-decoration: none; font-weight: 600; white-space: nowrap; border-bottom: 3px solid transparent; }
.nav a:hover { color: var(--brand); }
.nav a.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---------- Layout helpers ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.page-head h1 { margin: 0; flex: 1; min-width: 160px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar input, .toolbar select { margin: 0; width: auto; min-width: 150px; flex: 1; max-width: 320px; }
.toolbar button, .page-head button, .btn-sm { margin-top: 0; padding: 9px 14px; font-size: .95rem; }
button.danger { background: var(--bad); }
button.danger:hover { background: #962d22; }
button.small, .small { padding: 5px 10px; font-size: .85rem; margin-top: 0; }
select, textarea {
  width: 100%; padding: 10px 12px; font-size: 1rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-family: inherit;
}
select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat { text-align: center; }
.stat .num { font-size: 2rem; font-weight: 700; color: var(--brand); line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: .9rem; }
.stack > * + * { margin-top: 14px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: #f0f3f7; font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 12px; color: var(--muted); }
.pager button { margin-top: 0; padding: 6px 12px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 700; background: #e8edf3; color: var(--muted); }
.badge.green { background: #e1f4e8; color: var(--ok); }
.badge.red { background: #fdecea; color: var(--bad); }
.badge.amber { background: #fff3d6; color: #8a5a00; }

/* ---------- Subjects inside a course card ---------- */
.subject-list { list-style: none; margin: 10px 0 0; padding: 0; }
.subject-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.subject-list .t { flex: 1; }
.subject-list .ord { color: var(--muted); width: 1.6em; text-align: right; }

/* ---------- Modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 25, 40, .55); display: flex; align-items: flex-start; justify-content: center; padding: 24px 12px; overflow-y: auto; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 480px; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal.wide { max-width: 640px; }
.modal h2 { margin-top: 0; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.modal .actions button { margin-top: 0; }
.modal label.check { display: flex; gap: 8px; align-items: center; font-weight: 500; margin: 10px 0 0; }
.modal label.check input { width: auto; }
.modal .help { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.err-list { max-height: 220px; overflow-y: auto; margin: 8px 0 0; padding-left: 20px; font-size: .9rem; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1c2733; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 80; max-width: 90vw; }
.toast.error { background: var(--bad); }
.loading { text-align: center; color: var(--muted); padding: 28px; }

/* ---------- Progress bars, player, student pages ---------- */
.bar { height: 10px; background: #e3e9f0; border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar > div { height: 100%; background: var(--ok); border-radius: 99px; transition: width .4s; }
.bar.big { height: 16px; }
.watchmap { position: relative; height: 14px; background: #e3e9f0; border-radius: 6px; overflow: hidden; margin-top: 6px; }
.watchmap i { position: absolute; top: 0; bottom: 0; background: var(--ok); }
.player-box { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: 10px; overflow: hidden; }
.player-box iframe, .player-box > div { position: absolute; inset: 0; width: 100%; height: 100%; }
.crumbs { margin: 0 0 12px; font-size: .95rem; }
.crumbs a { color: var(--brand); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.tile-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
a.tile { display: block; color: inherit; text-decoration: none; transition: box-shadow .15s, transform .15s; }
a.tile:hover { box-shadow: 0 4px 14px rgba(0,0,0,.12); transform: translateY(-1px); }
.tile h2 { margin-bottom: 4px; }
.lesson-row { display: grid; grid-template-columns: 1fr auto; gap: 8px 14px; align-items: center; }
.lesson-row .meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; color: var(--muted); font-size: .9rem; }
.lesson-row .btn { margin-top: 0; padding: 8px 16px; }
@media (max-width: 560px) { .lesson-row { grid-template-columns: 1fr; } .lesson-row .btn { text-align: center; } }
.savestate { font-size: .85rem; color: var(--muted); }
.savestate.bad { color: var(--bad); }
.small-muted { color: var(--muted); font-size: .9rem; }

/* ---------- Quiz editor (admin) and quiz pages (student) ---------- */
.optrow { display: flex; gap: 8px; align-items: center; margin-top: 8px; padding: 4px 6px; border-radius: 8px; border: 1px solid transparent; }
.optrow.correct { background: #e8f6ee; border-color: #bfe3cd; }
.optrow .letter { font-weight: 700; width: 1.4em; text-align: center; color: var(--muted); }
.optrow input[type=text] { margin: 0; flex: 1; }
.optrow input[type=radio], .choice input[type=radio] { width: auto; margin: 0; transform: scale(1.3); }
.qcard h2 { font-size: 1.05rem; }
.qcard textarea { margin-bottom: 4px; }
.sticky-bar { position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--line); padding: 10px 16px; display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; z-index: 10; margin: 14px -16px 0; }
.sticky-bar button { margin-top: 0; }
.choice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; margin-top: 8px; border: 2px solid var(--line); border-radius: 10px; cursor: pointer; background: #fff; font-weight: 500; }
.choice:hover { border-color: #9db7d3; }
.choice.sel { border-color: var(--brand); background: #eef4fa; }
.choice.right { border-color: var(--ok); background: #e8f6ee; }
.choice.wrong { border-color: var(--bad); background: #fdecea; }
.choice .tag { margin-left: auto; font-size: .8rem; font-weight: 700; white-space: nowrap; }
.choice input { margin-top: 3px; flex: none; }
.score { text-align: center; }
.score .big { font-size: 2.6rem; font-weight: 800; color: var(--brand); line-height: 1.1; }
.score.good .big { color: var(--ok); }
.explain { margin-top: 10px; padding: 10px 12px; background: #f4f6f9; border-radius: 8px; font-size: .95rem; }
.answered-count { position: sticky; top: 0; background: var(--bg); padding: 8px 0; z-index: 5; font-weight: 600; }

/* ---- Stage 5: reports, dashboard lists, crowded header on phones ---- */
@media (max-width: 560px) {
  .site-header .inner { flex-wrap: wrap; gap: 8px; }
  .site-header .name { flex: 1 1 60%; }
  .site-header .spacer { display: none; }
  .site-header button { padding: 5px 10px; font-size: .85rem; }
}
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; align-items: end; }
.filters label { margin-top: 0; font-size: .85rem; }
.tabs { display: flex; gap: 6px; margin: 4px 0 12px; }
.tabs button { background: #fff; color: var(--brand); border: 1px solid var(--brand); margin-top: 0; padding: 7px 14px; }
.tabs button.on { background: var(--brand); color: #fff; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-top: 12px; }
.summary-line { display: flex; gap: 18px; flex-wrap: wrap; margin: 6px 0 12px; }
.summary-line b { font-size: 1.15rem; }
td.num, th.num { text-align: right; white-space: nowrap; }
.linkbtn { background: none; border: 0; color: var(--brand); text-decoration: underline; padding: 0; margin: 0; cursor: pointer; font: inherit; }
.mini-bar { display: inline-block; vertical-align: middle; width: 70px; height: 8px; background: #e5e9f0; border-radius: 4px; overflow: hidden; margin-right: 6px; }
.mini-bar i { display: block; height: 100%; background: var(--ok); }
