:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --border: #e3e6ee;
  --text: #1c2230;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-weak: #eef0fe;
  --green: #16a34a;
  --orange: #ea8a00;
  --red: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1116;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2a2f3a;
    --text: #e6e8ee;
    --muted: #9aa2b1;
    --accent: #8b8cf9;
    --accent-weak: #23233a;
    --green: #34d399;
    --orange: #fbbf24;
    --red: #f87171;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.55 system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.app { max-width: 960px; margin: 0 auto; padding: 0 16px 48px; }

header {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 0; position: sticky; top: 0; z-index: 10;
  background: var(--bg); border-bottom: 1px solid var(--border); margin-bottom: 20px;
}
.brand { font-weight: 700; font-size: 18px; }
.brand span { vertical-align: middle; }
.spacer { flex: 1; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; }
.tabs button {
  border: 0; background: transparent; color: var(--muted);
  padding: 6px 14px; border-radius: 7px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.settings { position: relative; }
.settings summary { list-style: none; cursor: pointer; font-size: 18px; color: var(--muted); }
.settings summary::-webkit-details-marker { display: none; }
.settings-body {
  position: absolute; right: 0; top: 28px; width: 240px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}
.settings-body small { color: var(--muted); font-weight: 400; }

.view { animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }
.hidden { display: none !important; }

/* Login screen */
.login-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 16px;
}
.login-box {
  width: min(340px, 92vw); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px 24px;
  display: flex; flex-direction: column; gap: 10px;
}
.login-brand { font-size: 22px; font-weight: 700; text-align: center; margin-bottom: 6px; }
.login-box label { font-size: 13px; color: var(--muted); }
.login-box button { margin-top: 6px; }
.login-error { color: var(--red); font-size: 13px; min-height: 16px; }
.muted { color: var(--muted); font-size: 13px; }

input, select, textarea, button {
  font: inherit; color: var(--text);
}
input, select, textarea {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; }
button {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 9px 18px; font-weight: 600; cursor: pointer;
}
button:hover { filter: brightness(1.05); }
button:disabled { opacity: .55; cursor: default; }
.btn-sm { padding: 6px 12px; font-size: 13px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }

.ask-head { margin-bottom: 10px; }
.ask-head select { max-width: 360px; }
.row { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
#question { margin-top: 0; }

.answer {
  margin-top: 20px; background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
}
.answer.ungrounded { border-left-color: var(--orange); }
.answer h1, .answer h2, .answer h3 { margin: .6em 0 .3em; line-height: 1.25; }
.answer p { margin: .5em 0; }
.answer ul, .answer ol { margin: .4em 0; padding-left: 1.4em; }
.answer code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.answer pre { background: var(--surface-2); padding: 12px; border-radius: 8px; overflow-x: auto; }
.answer pre code { background: none; padding: 0; }
.answer a { color: var(--accent); }

.cites, .reminders { margin-top: 16px; padding-top: 12px; border-top: 1px dashed var(--border); }
.cites h4, .reminders h4 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.cite, .reminder { font-size: 14px; margin: 3px 0; }
.reminders { border-top-color: var(--accent); }
.reminder { background: var(--accent-weak); border-radius: 8px; padding: 7px 10px; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; margin-right: 6px; vertical-align: middle; }
.tag.core { background: var(--accent-weak); color: var(--accent); }
.tag.prerequisite { background: #fff2d6; color: #9a6700; }
.tag.policy { background: var(--surface-2); color: var(--muted); }
@media (prefers-color-scheme: dark) { .tag.prerequisite { background: #3a2f12; color: var(--orange); } }
.answer-meta { margin-top: 14px; font-size: 12px; color: var(--muted); }

/* Dashboard */
.dash-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.dash-head label { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.dash-head select { width: auto; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.card .val { font-size: 26px; font-weight: 700; }
.card .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.panel h3 { margin: 0 0 12px; font-size: 15px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }
.chart svg { width: 100%; height: auto; display: block; }

.bar-row { display: grid; grid-template-columns: 130px 1fr auto; align-items: center; gap: 10px; margin: 7px 0; font-size: 14px; }
.bar-track { background: var(--surface-2); border-radius: 6px; height: 20px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: 6px; min-width: 2px; }
.bar-val { color: var(--muted); font-variant-numeric: tabular-nums; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table-wrap { overflow-x: auto; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
td.q { white-space: normal; max-width: 380px; }
.pill { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.dot.ok { background: var(--green); }
.dot.err { background: var(--red); }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }

/* Recent-questions accordions (answer collapsed) */
.rec { border-bottom: 1px solid var(--border); }
.rec > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; padding: 8px 4px; font-size: 13.5px; }
.rec > summary::-webkit-details-marker { display: none; }
.rec > summary::before { content: "▸"; color: var(--muted); font-size: 10px; width: 10px; flex: none; }
.rec[open] > summary::before { content: "▾"; }
.rec > summary:hover { background: var(--surface-2); border-radius: 6px; }
.rec-when, .rec-course, .rec-meta { color: var(--muted); white-space: nowrap; }
.rec-meta { font-variant-numeric: tabular-nums; }
.rec-q { flex: 1; min-width: 40px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-body { padding: 6px 8px 14px 22px; }
.rec-question { margin-bottom: 10px; color: var(--muted); font-size: 13px; }
.rec-question b { color: var(--text); }
.rec-answer { font-size: 14px; }
.rec-answer h1, .rec-answer h2, .rec-answer h3 { font-size: 1.02em; margin: .6em 0 .3em; line-height: 1.25; }
.rec-answer p { margin: .5em 0; }
.rec-answer ul, .rec-answer ol { margin: .4em 0; padding-left: 1.3em; }
.rec-answer code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.rec-answer pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow-x: auto; }
.rec-answer pre code { background: none; padding: 0; }
.rec-answer a { color: var(--accent); }
.rec-cites { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); display: flex; flex-direction: column; gap: 3px; }
.rec-cites-h { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin-bottom: 2px; }
.rec-cite { font-size: 13px; }

/* Teacher */
.teacher-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 720px) { .teacher-grid { grid-template-columns: 1fr; } }
.assign-form { display: grid; gap: 10px; }
.assign-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.assign-form label.full { grid-column: 1 / -1; }
.assign-form label.chk { flex-direction: row; align-items: center; gap: 8px; }
.assign-form label.chk input { width: auto; }
.form-actions { display: flex; align-items: center; gap: 10px; }
.moodle-ping { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.assign { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.assign.sel { background: var(--accent-weak); border-radius: 8px; padding: 10px; }
.assign-title { font-weight: 600; }
.assign .run { margin-top: 2px; }
.assign-actions { display: flex; gap: 6px; align-items: flex-start; flex-wrap: wrap; justify-content: flex-end; }

.fb { border: 1px solid var(--border); border-radius: 10px; margin: 8px 0; background: var(--surface); }
.fb > summary { cursor: pointer; padding: 10px 12px; display: flex; align-items: center; gap: 10px; list-style: none; }
.fb > summary::-webkit-details-marker { display: none; }
.fb-name { font-weight: 600; flex: 1; }
.fb-body { padding: 0 14px 14px; }
.fb-body h5 { margin: 10px 0 4px; font-size: 13px; color: var(--muted); }
.fb-body ul { margin: 4px 0; padding-left: 1.3em; }
.fb-body ul.good li { color: var(--green); }
.fb-body ul.bad li { color: var(--orange); }
.fb-body ul li { color: var(--text); }
.err-text { color: var(--red); }
.fb-meta { margin-top: 10px; font-size: 12px; color: var(--muted); }
.criteria { margin-top: 8px; display: grid; gap: 4px; }
.crit { font-size: 14px; }
.crit .y { color: var(--green); font-weight: 700; }
.crit .n { color: var(--red); font-weight: 700; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: #dcfce7; color: #15803d; }
.badge.err { background: #fee2e2; color: #b91c1c; }
@media (prefers-color-scheme: dark) {
  .badge.ok { background: #16351f; color: var(--green); }
  .badge.err { background: #3a1a1a; color: var(--red); }
}
.grade { font-weight: 700; font-size: 15px; color: var(--accent); }

footer { text-align: center; margin-top: 28px; font-size: 12px; }
