
/* ─── TOKENS ─────────────────────────────────────────── */
:root {
  --navy:    #0b2545;
  --teal:    #1a6b72;
  --teal2:   #24919a;
  --jade:    #2ecc80;
  --amber:   #f0a500;
  --coral:   #e05c5c;
  --sky:     #e8f4f8;
  --paper:   #fafaf8;
  --white:   #ffffff;
  --gray1:   #f4f5f7;
  --gray2:   #e2e5ea;
  --gray3:   #b0b8c1;
  --gray4:   #6b7a8d;
  --gray5:   #374151;
  --text:    #1a2433;
  --shadow:  0 2px 12px rgba(11,37,69,.12);
  --shadow2: 0 8px 32px rgba(11,37,69,.18);
  --r:       10px;
  --r2:      16px;
}

/* ─── RESET ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Outfit', sans-serif;
  background: var(--paper);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.55;
}

/* ─── UTIL ───────────────────────────────────────────── */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-24 { gap: 24px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.w-full { width: 100%; }
.mono { font-family: 'IBM Plex Mono', monospace; font-size: 12px; }

/* ─── BUTTONS ────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px; border-radius: var(--r);
  font-family: 'Outfit', sans-serif; font-weight: 600; font-size: 14px;
  cursor: pointer; border: none; transition: all .15s;
  text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal2); }
.btn-amber { background: var(--amber); color: #fff; }
.btn-amber:hover { background: #d4920a; }
.btn-ghost { background: transparent; color: var(--teal); border: 1.5px solid var(--teal); }
.btn-ghost:hover { background: var(--sky); }
.btn-danger { background: var(--coral); color: #fff; }
.btn-danger:hover { background: #c94444; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 13px 28px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ─── FORM ELEMENTS ──────────────────────────────────── */
input[type=text], input[type=email], input[type=number], select, textarea {
  width: 100%; font-family: 'Outfit', sans-serif; font-size: 14px;
  border: 1.5px solid var(--gray2); border-radius: var(--r);
  padding: 10px 14px; color: var(--text); background: #fff;
  transition: border-color .2s, box-shadow .2s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--teal2); box-shadow: 0 0 0 3px rgba(36,145,154,.15);
}
textarea { resize: vertical; min-height: 120px; }
label { font-weight: 600; font-size: 13px; color: var(--gray4); display: block; margin-bottom: 6px; letter-spacing: .03em; text-transform: uppercase; }
.field { margin-bottom: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ─── BADGE ───────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
}
.badge-teal  { background: #d0f0f2; color: var(--teal); }
.badge-amber { background: #fef3cd; color: #9a6800; }
.badge-jade  { background: #d2f5e3; color: #1a8050; }
.badge-coral { background: #fde8e8; color: #9b2626; }
.badge-navy  { background: #dde4f0; color: var(--navy); }

/* ─── CARD ───────────────────────────────────────────── */
.card {
  background: #fff; border-radius: var(--r2);
  border: 1.5px solid var(--gray2); padding: 24px;
  box-shadow: var(--shadow);
}

/* ─── TOPBAR ─────────────────────────────────────────── */
#topbar {
  background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; height: 58px; position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 16px rgba(0,0,0,.25);
}
.topbar-logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 18px; font-weight: 800; letter-spacing: -.01em; color: #fff;
}
.topbar-logo .logo-icon {
  width: 34px; height: 34px; background: var(--jade); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.topbar-logo .logo-sub { color: var(--jade); font-weight: 400; font-size: 13px; margin-left: 4px; }
#user-info {
  display: flex; align-items: center; gap: 12px; font-size: 13px;
}
#user-info img { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--jade); }
#user-info .user-name { font-weight: 600; }
#user-info .user-email { color: var(--gray3); font-size: 11px; }

/* ─── SETUP/CONFIG MODAL ─────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(11,37,69,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; backdrop-filter: blur(3px);
}
.modal {
  background: #fff; border-radius: var(--r2); padding: 36px;
  width: min(560px, 95vw); box-shadow: var(--shadow2);
  max-height: 90vh; overflow-y: auto;
}
.modal h2 { font-size: 22px; font-weight: 800; color: var(--navy); margin-bottom: 6px; }
.modal .modal-sub { color: var(--gray4); font-size: 14px; margin-bottom: 24px; }
.modal-divider { border: none; border-top: 1.5px solid var(--gray2); margin: 20px 0; }
.modal .step {
  display: flex; gap: 14px; margin-bottom: 14px; align-items: flex-start;
}
.modal .step-num {
  min-width: 26px; height: 26px; background: var(--navy); color: #fff;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0; margin-top: 2px;
}
.modal .step p { font-size: 13.5px; line-height: 1.5; color: var(--gray5); }
.modal .step code { background: var(--gray1); padding: 1px 6px; border-radius: 4px; font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--teal); }

/* ─── SCREENS ────────────────────────────────────────── */
.screen { min-height: calc(100vh - 58px); }

/* ─── LOGIN SCREEN ───────────────────────────────────── */
#screen-login {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, #163d5c 60%, #1a6b72 100%);
  min-height: 100vh; padding: 32px;
}
.login-box {
  background: #fff; border-radius: 20px; padding: 48px 40px;
  width: min(440px, 100%); text-align: center; box-shadow: var(--shadow2);
}
.login-hero {
  width: 72px; height: 72px; background: linear-gradient(135deg, var(--teal), var(--jade));
  border-radius: 18px; display: flex; align-items: center; justify-content: center;
  font-size: 36px; margin: 0 auto 20px;
}
.login-title { font-size: 26px; font-weight: 800; color: var(--navy); }
.login-sub { color: var(--gray4); font-size: 14.5px; margin: 8px 0 28px; line-height: 1.5; }
.login-divider { display: flex; align-items: center; gap: 12px; margin: 20px 0; color: var(--gray3); font-size: 13px; }
.login-divider::before, .login-divider::after { content: ''; flex: 1; height: 1px; background: var(--gray2); }
.login-note { font-size: 12px; color: var(--gray3); margin-top: 20px; }

/* ─── TEACHER DASHBOARD ──────────────────────────────── */
#screen-teacher { display: none; }
.teacher-layout { display: grid; grid-template-columns: 230px 1fr; min-height: calc(100vh - 58px); }
.sidebar {
  background: var(--navy); color: #fff; padding: 20px 0;
  position: sticky; top: 58px; height: calc(100vh - 58px); overflow-y: auto;
}
.sidebar-section { padding: 0 12px; margin-bottom: 24px; }
.sidebar-label { font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--gray3); padding: 0 12px; margin-bottom: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-weight: 500; color: rgba(255,255,255,.7);
  transition: all .15s; margin-bottom: 2px; border: none; background: none;
  width: 100%; text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-item.active { background: var(--teal); color: #fff; }
.nav-item .nav-icon { font-size: 18px; width: 22px; text-align: center; flex-shrink: 0; }
.nav-item .nav-badge { margin-left: auto; background: var(--jade); color: var(--navy); font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 10px; }

.main-content { padding: 28px 32px; max-width: 900px; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }
.page-header { margin-bottom: 24px; }
.page-header h2 { font-size: 22px; font-weight: 800; color: var(--navy); }
.page-header p { color: var(--gray4); font-size: 14px; margin-top: 4px; }

/* ─── PASSAGE INPUT ──────────────────────────────────── */
.upload-zone {
  border: 2.5px dashed var(--gray2); border-radius: var(--r2);
  padding: 28px; text-align: center; cursor: pointer;
  transition: all .2s; background: var(--gray1);
}
.upload-zone:hover { border-color: var(--teal2); background: var(--sky); }
.upload-zone.dragging { border-color: var(--jade); background: #edf9f4; }
.upload-icon { font-size: 36px; margin-bottom: 10px; }
.upload-text { font-size: 14px; color: var(--gray4); }
.upload-text strong { color: var(--teal); }
#pdf-input { display: none; }

.passage-textarea { font-family: 'Lora', serif; font-size: 14.5px; min-height: 300px; line-height: 1.7; }
.word-count { font-size: 12px; color: var(--gray3); margin-top: 6px; text-align: right; }

/* ─── SETTINGS PANEL ─────────────────────────────────── */
.sep-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px;
}
.sep-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px; border-radius: var(--r); border: 1.5px solid var(--gray2);
  cursor: pointer; transition: all .15s; background: #fff;
}
.sep-item:hover { border-color: var(--teal2); background: var(--sky); }
.sep-item.selected { border-color: var(--teal); background: #e8f6f7; }
.sep-item input[type=checkbox] { margin-top: 2px; accent-color: var(--teal); flex-shrink: 0; }
.sep-item-text { font-size: 13px; }
.sep-item-num { font-size: 11px; color: var(--gray3); margin-bottom: 2px; font-family: 'IBM Plex Mono', monospace; }
.sep-item-name { font-weight: 600; color: var(--navy); line-height: 1.3; }

.type-grid { display: flex; gap: 10px; flex-wrap: wrap; }
.type-chip {
  padding: 8px 16px; border-radius: 20px; border: 1.5px solid var(--gray2);
  cursor: pointer; font-size: 13px; font-weight: 500; background: #fff; transition: all .15s;
}
.type-chip:hover { border-color: var(--teal2); }
.type-chip.selected { background: var(--teal); color: #fff; border-color: var(--teal); }

/* ─── GENERATE PANEL ─────────────────────────────────── */
.gen-summary {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px;
}
.gen-stat { text-align: center; padding: 16px; background: var(--gray1); border-radius: var(--r); }
.gen-stat .val { font-size: 24px; font-weight: 800; color: var(--navy); }
.gen-stat .lbl { font-size: 12px; color: var(--gray4); margin-top: 4px; }

.progress-bar-wrap { background: var(--gray2); border-radius: 6px; height: 8px; overflow: hidden; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--teal), var(--jade)); border-radius: 6px; width: 0; transition: width .3s; }

/* ─── QUESTION CARDS ──────────────────────────────────── */
.question-card {
  border: 1.5px solid var(--gray2); border-radius: var(--r2);
  padding: 20px; margin-bottom: 16px; background: #fff; transition: border-color .2s;
}
.question-card:hover { border-color: var(--teal2); }
.q-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.q-num { width: 28px; height: 28px; background: var(--navy); color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; flex-shrink: 0; }
.q-body .q-text { font-size: 15px; font-weight: 600; color: var(--navy); margin-bottom: 12px; }
.q-choices { list-style: none; }
.q-choice { padding: 8px 12px; border-radius: 8px; margin-bottom: 6px; font-size: 14px; border: 1.5px solid var(--gray2); cursor: pointer; transition: all .15s; display: flex; align-items: center; gap: 10px; }
.q-choice:hover { border-color: var(--teal2); background: var(--sky); }
.q-choice.correct { border-color: var(--jade); background: #edf9f4; }
.q-choice.selected { border-color: var(--teal); background: var(--sky); }
.q-choice.wrong { border-color: var(--coral); background: #fef2f2; }
.q-choice .choice-letter { width: 24px; height: 24px; border-radius: 50%; background: var(--gray2); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0; }
.q-choice.correct .choice-letter { background: var(--jade); color: #fff; }
.q-choice.selected .choice-letter { background: var(--teal); color: #fff; }
.q-choice.wrong .choice-letter { background: var(--coral); color: #fff; }

.q-rubric { background: var(--gray1); border-radius: 8px; padding: 12px; margin-top: 10px; font-size: 13px; color: var(--gray5); }
.q-rubric strong { display: block; margin-bottom: 4px; color: var(--navy); }
.q-answer-input { width: 100%; min-height: 90px; font-family: 'Outfit', sans-serif; font-size: 14px; margin-top: 10px; }

.q-actions { display: flex; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--gray2); }
.q-explanation { margin-top: 12px; padding: 12px; background: #fff9e6; border-radius: 8px; border-left: 3px solid var(--amber); font-size: 13px; color: var(--gray5); }

/* ─── QUIZ SCREEN ─────────────────────────────────────── */
#screen-quiz {
  display: none; background: var(--sky);
  min-height: 100vh; padding: 32px 20px;
}
.quiz-container { max-width: 740px; margin: 0 auto; }
.quiz-header { text-align: center; margin-bottom: 32px; }
.quiz-title { font-size: 26px; font-weight: 800; color: var(--navy); }
.quiz-sub { color: var(--gray4); font-size: 14px; margin-top: 6px; }
.quiz-progress { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.quiz-progress-bar { flex: 1; height: 6px; background: var(--gray2); border-radius: 6px; overflow: hidden; }
.quiz-progress-fill { height: 100%; background: var(--teal); border-radius: 6px; transition: width .3s; }
.quiz-progress-text { font-size: 13px; color: var(--gray4); white-space: nowrap; }
.student-name-input {
  max-width: 360px; margin: 0 auto 28px; text-align: center;
}
.student-name-input input { text-align: center; font-size: 16px; }

/* ─── RESULTS SCREEN ─────────────────────────────────── */
.result-score-box {
  text-align: center; padding: 32px; background: linear-gradient(135deg, var(--navy), var(--teal));
  border-radius: var(--r2); color: #fff; margin-bottom: 24px;
}
.result-score-box .score-num { font-size: 64px; font-weight: 800; line-height: 1; }
.result-score-box .score-denom { font-size: 22px; opacity: .7; }
.result-score-box .score-pct { font-size: 18px; margin-top: 8px; color: var(--jade); }

.result-breakdown { display: grid; gap: 14px; }
.result-row {
  display: flex; align-items: flex-start; gap: 14px; padding: 14px;
  border-radius: var(--r); border: 1.5px solid var(--gray2); background: #fff;
}
.result-icon { font-size: 22px; flex-shrink: 0; margin-top: 2px; }
.result-row .q-text { font-size: 14px; font-weight: 600; color: var(--navy); margin-bottom: 6px; }
.result-row .r-detail { font-size: 13px; color: var(--gray4); }
.result-row .r-correct { color: #1a8050; font-weight: 600; }
.result-row .r-wrong { color: #9b2626; font-weight: 600; }

/* ─── SHEETS PANEL ────────────────────────────────────── */
.sheets-status { padding: 14px; border-radius: var(--r); font-size: 14px; margin-bottom: 16px; }
.sheets-status.ok { background: #d2f5e3; color: #1a6640; }
.sheets-status.err { background: #fde8e8; color: #9b2626; }
.sheets-status.info { background: var(--sky); color: var(--teal); }

/* ─── LOADING ─────────────────────────────────────────── */
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--gray2);
  border-top-color: var(--teal); border-radius: 50%;
  animation: spin .8s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay {
  position: fixed; inset: 0; background: rgba(255,255,255,.85);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 150; gap: 16px; font-size: 15px; color: var(--gray4);
}

/* ─── TOAST ───────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 18px; border-radius: var(--r); font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow2); animation: slideIn .25s; max-width: 360px;
  display: flex; align-items: center; gap: 10px;
}
.toast.success { background: var(--jade); color: #fff; }
.toast.error { background: var(--coral); color: #fff; }
.toast.info { background: var(--navy); color: #fff; }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ─── RESPONSIVE ──────────────────────────────────────── */
@media (max-width: 720px) {
  .teacher-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; display: flex; flex-wrap: wrap; padding: 8px; }
  .nav-item { flex-direction: column; padding: 10px; text-align: center; gap: 4px; font-size: 11px; }
  .nav-icon { font-size: 20px; }
  .gen-summary { grid-template-columns: repeat(2,1fr); }
  .field-row { grid-template-columns: 1fr; }
  .main-content { padding: 20px 16px; }
}

/* ─── EDIT MODE ───────────────────────────────────────── */
.edit-input {
  width: 100%; font-family: 'Outfit', sans-serif; font-size: 14px; font-weight: 600;
  border: 1.5px solid var(--teal2); border-radius: 6px; padding: 8px;
  background: #fff; margin-bottom: 8px;
}

/* ─── LIBRARY ─────────────────────────────────────────── */
.lib-item {
  display: flex; align-items: center; gap: 14px;
  padding: 16px; border-radius: var(--r); border: 1.5px solid var(--gray2);
  background: #fff; margin-bottom: 10px; transition: border-color .15s;
}
.lib-item:hover { border-color: var(--teal2); }
.lib-item-icon { font-size: 28px; flex-shrink: 0; }
.lib-item-body { flex: 1; min-width: 0; }
.lib-item-title { font-weight: 700; font-size: 15px; color: var(--navy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-item-meta  { font-size: 12px; color: var(--gray3); margin-top: 3px; }
.lib-item-actions { display: flex; gap: 7px; flex-shrink: 0; }
.drive-status { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 8px 12px; border-radius: 8px; margin-bottom: 16px; }
.drive-status.ok   { background: #d2f5e3; color: #1a6640; }
.drive-status.busy { background: var(--sky); color: var(--teal); }
.drive-status.err  { background: #fde8e8; color: #9b2626; }
.drive-status.idle { background: var(--gray1); color: var(--gray4); }
.accordion-toggle {
  width: 100%; text-align: left; background: none; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; font-family: 'Outfit', sans-serif; font-size: 15px; font-weight: 700;
  color: var(--navy); border-bottom: 1.5px solid var(--gray2);
}
.accordion-body { padding-top: 16px; display: none; }
.accordion-body.open { display: block; }
.chevron { transition: transform .2s; }
.chevron.open { transform: rotate(180deg); }

/* intro banner */
.intro-banner {
  background: linear-gradient(135deg, #0b2545, #1a6b72);
  border-radius: var(--r2); padding: 24px 28px; color: #fff; margin-bottom: 28px;
  display: flex; align-items: center; gap: 24px;
}
.intro-banner .banner-icon { font-size: 48px; flex-shrink: 0; }
.intro-banner h3 { font-size: 18px; font-weight: 800; margin-bottom: 6px; }
.intro-banner p { font-size: 13.5px; color: rgba(255,255,255,.75); line-height: 1.5; }
