:root {
  --bg: #0e0d0c;
  --bg-elev: #171513;
  --bg-card: #1c1a17;
  --border: #2c2823;
  --gold: #cda45e;
  --gold-bright: #e6c17a;
  --cream: #f3ecdd;
  --text: #f3ecdd;
  --text-dim: #a89f8f;
  --text-faint: #6f675b;
  --green: #6fae7b;
  --red: #d5726b;
  --amber: #e0b054;
  --blue: #7aa7c9;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 30px rgba(0,0,0,.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--gold); }

#app { min-height: 100%; display: flex; flex-direction: column; }

/* ---------- Layout shell ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #151311, #100f0d);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .02em; }
.brand .logo {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--gold-bright), #8a6a2f);
  display: flex; align-items: center; justify-content: center;
  color: #1a1408; font-weight: 800; font-size: 14px;
}
.brand small { display: block; color: var(--text-dim); font-weight: 400; font-size: 11px; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--bg-elev); color: var(--text); display: flex; align-items: center;
  justify-content: center; cursor: pointer; position: relative; font-size: 16px;
}
.icon-btn:hover { border-color: var(--gold); }
.badge-dot {
  position: absolute; top: -2px; right: -2px; background: var(--red); color: #fff;
  font-size: 10px; min-width: 16px; height: 16px; border-radius: 8px; display: flex;
  align-items: center; justify-content: center; padding: 0 3px; font-weight: 700;
}

.layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 220px; flex-shrink: 0; border-right: 1px solid var(--border);
  background: var(--bg-elev); padding: 14px 10px; overflow-y: auto;
}
.sidebar a {
  display: block; padding: 10px 12px; border-radius: var(--radius-sm); color: var(--text-dim);
  text-decoration: none; font-size: 14px; margin-bottom: 2px; font-weight: 500;
}
.sidebar a:hover { background: var(--bg-card); color: var(--text); }
.sidebar a.active { background: rgba(205,164,94,.15); color: var(--gold-bright); }
.sidebar .section-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); padding: 14px 12px 4px; }

.main { flex: 1; min-width: 0; padding: 18px; overflow-y: auto; }
.main-inner { max-width: 1080px; margin: 0 auto; }

.bottom-nav {
  display: none; position: sticky; bottom: 0; z-index: 20; background: var(--bg-elev);
  border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  justify-content: space-around;
}
.bottom-nav a { flex: 1; text-align: center; color: var(--text-dim); text-decoration: none; font-size: 10.5px; padding: 6px 2px; border-radius: 10px; }
.bottom-nav a.active { color: var(--gold-bright); }
.bottom-nav .bn-ic { display: block; font-size: 18px; margin-bottom: 2px; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .bottom-nav { display: flex; }
  .main { padding: 14px 14px 90px; }
}

/* ---------- Typography / basics ---------- */
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; margin: 0 0 6px; letter-spacing: .01em; }
h1 { font-size: 26px; color: var(--cream); }
h2 { font-size: 19px; color: var(--cream); }
h3 { font-size: 15px; color: var(--gold-bright); }
p { color: var(--text-dim); line-height: 1.5; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.eyebrow { color: var(--gold); text-transform: uppercase; font-size: 11px; letter-spacing: .12em; font-weight: 700; margin-bottom: 4px; }

/* ---------- Cards / grid ---------- */
.card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.card-flush { padding: 0; overflow: hidden; }
.grid { display: grid; gap: 14px; }
.grid.cols-1 { grid-template-columns: 1fr; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 700px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 460px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }

.stat { text-align: left; }
.stat .num { font-size: 30px; font-weight: 800; color: var(--gold-bright); font-family: Georgia, serif; }
.stat .lbl { color: var(--text-dim); font-size: 12.5px; margin-top: 2px; }

/* ---------- Forms ---------- */
label { display: block; font-size: 12.5px; color: var(--text-dim); margin: 10px 0 5px; font-weight: 600; }
input, select, textarea {
  width: 100%; background: var(--bg-elev); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14.5px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); }
textarea { resize: vertical; min-height: 70px; }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field-row > * { flex: 1; min-width: 140px; }
.checkline { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.checkline input { width: auto; }
.checkline label { margin: 0; }
.hint { color: var(--text-faint); font-size: 12px; margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: linear-gradient(135deg, var(--gold-bright), #a9803c); color: #1a1408;
  border: none; padding: 10px 16px; border-radius: var(--radius-sm); font-weight: 700;
  font-size: 14px; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { border-color: var(--gold); color: var(--gold-bright); }
.btn.danger { background: var(--red); color: #fff; }
.btn.sm { padding: 6px 11px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- Table / list ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-faint); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
tr:hover td { background: rgba(255,255,255,.02); }
.table-wrap { overflow-x: auto; }

.list-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: rgba(255,255,255,.02); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: rgba(205,164,94,.18); color: var(--gold-bright);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.list-row .meta { flex: 1; min-width: 0; }
.list-row .meta .name { font-weight: 600; }
.list-row .meta .sub { color: var(--text-dim); font-size: 12.5px; }

/* ---------- Badges/pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
}
.pill-gold { background: rgba(205,164,94,.18); color: var(--gold-bright); }
.pill-green { background: rgba(111,174,123,.18); color: var(--green); }
.pill-red { background: rgba(213,114,107,.18); color: var(--red); }
.pill-amber { background: rgba(224,176,84,.18); color: var(--amber); }
.pill-blue { background: rgba(122,167,201,.18); color: var(--blue); }
.pill-gray { background: rgba(255,255,255,.08); color: var(--text-dim); }

/* ---------- Auth screens ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(circle at 50% 0%, #1c1810, var(--bg) 60%);
}
.auth-card { width: 100%; max-width: 380px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px 24px; box-shadow: var(--shadow); }
.auth-logo { text-align: center; margin-bottom: 6px; }
.auth-logo .logo { width: 52px; height: 52px; border-radius: 14px; margin: 0 auto 10px; }
.auth-title { text-align: center; margin-bottom: 22px; }
.auth-title h1 { font-size: 22px; }
.auth-title p { font-size: 13px; margin: 4px 0 0; }
.auth-switch { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-dim); }
.auth-switch a { cursor: pointer; }

/* ---------- Notifications panel ---------- */
.notif-panel {
  position: fixed; top: 62px; right: 12px; width: 340px; max-width: 92vw; max-height: 70vh; overflow-y: auto;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 40;
}
.notif-item { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.notif-item:last-child { border-bottom: none; }
.notif-item .t { font-weight: 700; font-size: 13.5px; }
.notif-item .b { color: var(--text-dim); font-size: 12.5px; margin-top: 2px; }
.notif-item .meta { color: var(--text-faint); font-size: 11px; margin-top: 4px; }
.notif-item.unread { background: rgba(205,164,94,.06); }

/* ---------- Overlay / modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center;
  justify-content: center; padding: 16px; z-index: 50;
}
.modal {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal.small { max-width: 380px; }
.modal.wide { max-width: 960px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- PDF markup editor ---------- */
.markup-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px; padding: 8px 0 14px;
  border-bottom: 1px solid var(--border); margin-bottom: 10px;
}
.tool-group { display: flex; align-items: center; gap: 6px; }
.tool-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-elev);
  font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.tool-btn.active { border-color: var(--gold); background: rgba(205,164,94,.14); }
.color-swatch {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0;
}
.color-swatch.active { border-color: var(--gold-bright); }
.markup-canvas-wrap {
  position: relative; width: 100%; max-width: 880px; margin: 0 auto; background: #fff; border-radius: 8px;
  overflow: hidden; touch-action: none;
}
.markup-canvas-wrap canvas { display: block; width: 100%; }
#draw-canvas { position: absolute; top: 0; left: 0; cursor: crosshair; }
.markup-text-box {
  position: absolute; min-width: 60px; max-width: 220px; background: rgba(255,244,180,.92); color: #1a1a1a;
  border: 1px solid #c9a95e; border-radius: 4px; padding: 3px 6px; font-size: 12px; line-height: 1.3;
  cursor: move; outline: none;
}
.markup-pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 10px; }

/* ---------- Toasts ---------- */
#toast-host { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-elev); border: 1px solid var(--gold); color: var(--text); padding: 10px 16px;
  border-radius: 10px; font-size: 13.5px; opacity: 0; transform: translateY(8px); transition: all .25s; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { border-color: var(--red); }
.toast-success { border-color: var(--green); }

/* ---------- Calendar ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { text-align: center; font-size: 11px; color: var(--text-faint); text-transform: uppercase; padding-bottom: 4px; }
.cal-cell {
  min-height: 64px; border: 1px solid var(--border); border-radius: 8px; padding: 5px; font-size: 11px;
  background: var(--bg-elev); cursor: pointer;
}
.cal-cell.today { border-color: var(--gold); }
.cal-cell .d { color: var(--text-dim); font-weight: 700; margin-bottom: 3px; }
.cal-cell .ev { display: block; border-radius: 5px; padding: 1px 4px; margin-bottom: 2px; font-size: 10px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-cell.other-month { opacity: .35; }
@media (max-width: 700px) { .cal-cell { min-height: 44px; font-size: 10px; } }

.empty-state { text-align: center; padding: 40px 16px; color: var(--text-faint); }
.empty-state .big { font-size: 34px; margin-bottom: 8px; }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { background: var(--bg-elev); border: 1px solid var(--border); color: var(--text-dim); padding: 7px 13px;
  border-radius: 999px; font-size: 13px; cursor: pointer; font-weight: 600; }
.tabs button.active { background: rgba(205,164,94,.16); border-color: var(--gold); color: var(--gold-bright); }

.copy-box { background: var(--bg-elev); border: 1px dashed var(--border); border-radius: 8px; padding: 10px; font-family: monospace;
  white-space: pre-wrap; font-size: 12.5px; color: var(--text-dim); }

.loading { display: flex; align-items: center; justify-content: center; padding: 60px; color: var(--text-dim); }

/* ---------- Reports ---------- */
.report-print { margin-top: 14px; }
.report-header { margin-bottom: 14px; }
.report-header h2 { margin: 0 0 4px; }
.report-print h3 { margin: 18px 0 8px; font-size: 15px; color: var(--gold-bright); }
.report-print table { width: 100%; }

/* ---------- Print (used by the Reports page's "Print this report") ---------- */
@media print {
  .no-print, .topbar, .sidebar, .bottom-nav, #toast-host { display: none !important; }
  .layout, .main, .main-inner { display: block !important; padding: 0 !important; margin: 0 !important; max-width: 100% !important; }
  body { background: #fff !important; }
  .report-print, .report-print .card, .report-print.card {
    background: #fff !important; color: #111 !important; border: none !important; box-shadow: none !important; padding: 0 !important;
  }
  .report-print * { color: #111 !important; }
  .report-print .grid { display: grid !important; grid-template-columns: repeat(4, 1fr) !important; gap: 10px !important; }
  .report-print .stat { border: 1px solid #ccc !important; border-radius: 6px; padding: 10px !important; background: #fafafa !important; }
  .report-print table, .report-print th, .report-print td { border: 1px solid #ccc !important; }
  .report-print th, .report-print td { padding: 5px 7px !important; font-size: 12px; }
  .report-print .pill { border: 1px solid #999 !important; background: #f0f0f0 !important; color: #111 !important; }
}

/* ---------- AI chat widget ---------- */
.ai-chat-launcher {
  position: fixed; right: 18px; bottom: 22px; z-index: 45;
  width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--gold); color: var(--bg); font-size: 22px; cursor: pointer; box-shadow: var(--shadow);
}
.ai-chat-launcher:hover { background: var(--gold-bright); }
.ai-chat-panel {
  position: fixed; right: 18px; bottom: 84px; z-index: 45; width: 340px; max-width: calc(100vw - 32px);
  height: 440px; max-height: 70vh; display: flex; flex-direction: column;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.ai-chat-header {
  display: flex; align-items: center; justify-content: space-between; padding: 12px 14px;
  border-bottom: 1px solid var(--border); font-weight: 700;
}
.ai-chat-thread { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.ai-chat-bubble {
  max-width: 85%; padding: 8px 11px; border-radius: 12px; font-size: 13.5px; line-height: 1.4; white-space: pre-wrap;
}
.ai-chat-bubble.assistant { align-self: flex-start; background: var(--bg-elev); border: 1px solid var(--border); }
.ai-chat-bubble.user { align-self: flex-end; background: rgba(205,164,94,.18); color: var(--gold-bright); }
.ai-chat-bubble.loading { opacity: .6; }
.ai-chat-input-row { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.ai-chat-input-row input {
  flex: 1; padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg-elev); color: var(--text); font-size: 13.5px; font-family: inherit;
}
.ai-chat-input-row .btn { padding: 8px 14px; }

@media (max-width: 860px) {
  .ai-chat-launcher { bottom: 78px; }
  .ai-chat-panel { bottom: 140px; }
}

/* Marking table: keep every control usable instead of squashing it -
   the table scrolls sideways on narrow screens. */
.grading-table { min-width: 1180px; }
.grading-table select[data-f="status"] { min-width: 120px; }
.grading-table input[data-f="score"] { min-width: 80px; }
.grading-table input[data-f="feedback"] { min-width: 200px; }
.grading-scroll-hint { display: none; }
@media (max-width: 1000px) { .grading-scroll-hint { display: block; } }

/* Feedback can be a multi-line AI mistakes report - keep its line breaks. */
.feedback-text { white-space: pre-line; min-width: 220px; max-width: 460px; font-size: 13px; line-height: 1.45; }
.grading-table textarea[data-f="feedback"] { min-width: 280px; font-size: 13px; }

/* The marking window uses almost the full screen width. */
.modal.wide:has(.grading-table) { max-width: min(1500px, 96vw); width: 96vw; }

.greeting-sub { margin: 4px 0 0; color: var(--text-dim); font-size: 14.5px; }

/* Recently due / Tracker */
.rd-school { margin-bottom: 22px; }
.rd-school h2 { font-size: 18px; margin: 0 0 10px; }
.rd-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.rd-card { cursor: pointer; margin: 0; transition: transform .12s ease, border-color .12s ease; }
.rd-card:hover, .rd-card:focus { transform: translateY(-2px); border-color: var(--gold, #c9a54c); outline: none; }
.rd-top { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 10px; }
.rd-icon { font-size: 22px; line-height: 1; }
.rd-title { font-weight: 700; }
.rd-bar { height: 6px; border-radius: 99px; background: rgba(255,255,255,.08); overflow: hidden; margin: 6px 0 10px; }
.rd-bar span { display: block; height: 100%; background: var(--green, #6fae7b); }
.rd-counts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; text-align: center; }
.rd-counts strong { display: block; font-size: 20px; }
.rd-counts span { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.rd-counts .bad strong { color: var(--red); }
.rd-counts .warn strong { color: var(--amber); }
.tracker-list ol.names { margin: 0; padding-left: 22px; max-height: 320px; overflow: auto; }
.tracker-list ol.names li { padding: 3px 0; }
.tracker-list.bad h3 { color: var(--red); }
.tracker-totals .num { font-size: 26px; font-weight: 700; color: var(--gold-bright, #e6c36a); }
.tracker-totals .num small { font-size: 14px; color: var(--text-dim); }
.grid.cols-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 700px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } }
.rd-counts span { font-size: 10px; letter-spacing: 0; line-height: 1.25; display: block; }

/* Course registration (sign-in screen) */
.register-cta { margin-top: 18px; padding: 14px; border: 1px dashed var(--gold); border-radius: 12px; text-align: center; display: grid; gap: 10px; }
.reg-subjects { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 4px; }
.reg-choice { display: block; margin: 0; cursor: pointer; }
.reg-choice input { position: absolute; opacity: 0; pointer-events: none; }
.reg-choice span { display: block; text-align: center; padding: 12px 6px; border: 1px solid var(--border); border-radius: 10px; font-weight: 600; font-size: 14px; }
.reg-choice input:checked + span { border-color: var(--gold); background: rgba(205,164,94,.15); color: var(--gold-bright); }
.reg-choice input:focus-visible + span { outline: 2px solid var(--gold); }
.hp-field { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }

/* New registrations (admin) */
.reg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.reg-card { margin: 0; display: grid; gap: 8px; }
.reg-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.reg-contacts { display: grid; gap: 4px; font-size: 13.5px; }
.reg-notes { margin: 0; padding: 8px 10px; background: rgba(255,255,255,.04); border-radius: 8px; font-size: 13.5px; white-space: pre-line; }
.reg-actions { margin-top: 4px; }
.nav-count { display: inline-block; min-width: 18px; padding: 1px 6px; border-radius: 99px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; text-align: center; margin-left: 4px; }
