/* =============================================================
   File: style.css
   StudyTool — Application Styles
   ============================================================= */

/* ----- CSS Custom Properties ----- */
:root {
  --primary:       #228be6;
  --primary-dark:  #1971c2;
  --primary-light: #e7f5ff;
  --success:       #40c057;
  --danger:        #fa5252;
  --warning:       #fd7e14;
  --text:          #1a1a2e;
  --text-muted:    #6c757d;
  --bg:            #f8f9fa;
  --surface:       #ffffff;
  --border:        #dee2e6;
  --radius:        12px;
  --shadow:        0 2px 12px rgba(0,0,0,0.07);
  --shadow-lg:     0 8px 32px rgba(0,0,0,0.12);
  --transition:    0.18s ease;
}

/* ----- Reset ----- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ----- Preloader ----- */
.preloader {
  position: fixed;
  inset: 0;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}
.preloader.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ----- Spinner Ring ----- */
.spinner-ring {
  width: 48px; height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner-ring.sm { width: 20px; height: 20px; border-width: 3px; }
.spinner-ring.xs { width: 14px; height: 14px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- Page fade-in ----- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0);   }
}
.page { animation: fadeIn 0.28s ease; }

/* ----- App Layout ----- */
#root { min-height: 100vh; }
.page {
  max-width: 920px;
  margin: 0 auto;
  padding: 1.25rem 1rem;
}

/* ----- App Header / Navigation ----- */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: var(--shadow);
}
.app-logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.02em;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.app-nav { display: flex; gap: 0.2rem; align-items: center; }
.nav-btn {
  background: none;
  border: none;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.nav-btn:hover  { background: var(--primary-light); color: var(--primary); }
.nav-btn.active { background: var(--primary-light); color: var(--primary); }
.nav-btn.danger-nav:hover { background: #fff5f5; color: var(--danger); }

/* Hamburger (mobile) */
.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  flex-direction: column;
  gap: 5px;
}
.hamburger span {
  display: block;
  width: 22px; height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: var(--transition);
}
.mobile-menu {
  display: none;
  position: fixed;
  top: 60px; left: 0; right: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  flex-direction: column;
  gap: 0.35rem;
  z-index: 199;
  box-shadow: var(--shadow);
}
.mobile-menu.open { display: flex; }

@media (max-width: 640px) {
  .hamburger { display: flex; }
  .app-nav    { display: none; }
}

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.15rem;
  border: 1.5px solid transparent;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.4;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary);  color: #fff; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-success { background: var(--success);  color: #fff; border-color: var(--success); }
.btn-success:hover:not(:disabled) { background: #2f9e44; border-color: #2f9e44; }
.btn-danger  { background: var(--danger);   color: #fff; border-color: var(--danger);  }
.btn-danger:hover:not(:disabled)  { background: #e03131; border-color: #e03131; }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.btn-ghost   { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); }
.btn-sm { padding: 0.38rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.8rem 1.6rem;  font-size: 1rem; }
.btn-full { width: 100%; justify-content: center; }

/* Per-button spinner */
.btn-spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
  flex-shrink: 0;
}
.btn-outline .btn-spinner,
.btn-ghost .btn-spinner {
  border-color: rgba(0,0,0,0.15);
  border-top-color: var(--primary);
}
.btn.loading .btn-spinner { display: block; }
.btn.loading .btn-text    { opacity: 0.75;  }

/* ----- Cards ----- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

/* ----- Forms ----- */
.form-group { margin-bottom: 1rem; }
.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form-input {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  font-family: inherit;
}
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(34,139,230,0.12); }
.form-input.error { border-color: var(--danger); }
select.form-input { cursor: pointer; }
textarea.form-input { resize: vertical; min-height: 90px; }
.form-error { color: var(--danger); font-size: 0.8rem; margin-top: 0.3rem; }
.form-hint  { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.3rem; }
.form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }

/* ----- Auth Page ----- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eef7ff 0%, #f8f9fa 48%, #fff7ed 100%);
  padding: 2rem 1rem;
}
.auth-shell {
  width: min(100%, 1040px);
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(360px, 430px);
  gap: 2rem;
  align-items: center;
}
.auth-info {
  padding: 1rem 0;
}
.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--primary);
  font-weight: 800;
  font-size: 1.05rem;
  margin-bottom: 1.1rem;
}
.auth-info h1 {
  max-width: 620px;
  font-size: 2.35rem;
  line-height: 1.15;
  letter-spacing: 0;
  margin-bottom: 1rem;
}
.auth-info p {
  max-width: 590px;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.75;
}
.auth-feature-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
  margin-top: 1.4rem;
}
.auth-feature {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  min-width: 0;
  padding: 0.85rem 0;
  border-top: 1px solid rgba(222, 226, 230, 0.9);
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.5;
}
.auth-feature i {
  width: 1.1rem;
  color: var(--primary);
  margin-top: 0.15rem;
  flex-shrink: 0;
}
.auth-panel {
  min-width: 0;
  width: 100%;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem;
  width: 100%;
  max-width: 430px;
  box-shadow: var(--shadow-lg);
}
.auth-logo { text-align: center; margin-bottom: 2rem; }
.auth-logo h1,
.auth-logo h2 { font-size: 2rem; color: var(--primary); margin-bottom: 0.25rem; letter-spacing: 0; }
.auth-logo p  { color: var(--text-muted); font-size: 0.9rem; }

.auth-tabs {
  display: flex;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 1.5rem;
}
.auth-tab {
  flex: 1;
  padding: 0.6rem;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: all var(--transition);
}
.auth-tab.active { background: var(--primary); color: #fff; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  font-size: 0.78rem;
  margin: 0.9rem 0 1rem;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  height: 1px;
  background: var(--border);
  flex: 1;
}
.google-auth-btn {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}
.google-auth-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.auth-legal {
  color: var(--text-muted);
  font-size: 0.78rem;
  display: flex;
  gap: 0.45rem;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin: 1rem 0 0;
  width: 100%;
  max-width: 430px;
  min-width: 0;
  text-align: center;
}
.auth-legal a { white-space: nowrap; }

.auth-error {
  background: #fff5f5;
  border: 1px solid #ffc9c9;
  border-radius: 8px;
  padding: 0.75rem;
  color: var(--danger);
  font-size: 0.85rem;
  margin-bottom: 1rem;
  display: none;
}
.auth-error.show { display: block; }

@media (max-width: 860px) {
  .auth-shell {
    grid-template-columns: 1fr;
    gap: 1.5rem;
    align-items: stretch;
  }
  .auth-info {
    text-align: center;
    padding: 0;
  }
  .auth-brand,
  .auth-info h1,
  .auth-info p,
  .auth-card,
  .auth-legal {
    margin-left: auto;
    margin-right: auto;
  }
  .auth-info h1 { font-size: 1.85rem; }
}
@media (max-width: 560px) {
  .auth-page {
    align-items: flex-start;
    padding: 1rem;
  }
  .auth-feature-grid { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .auth-card { padding: 1.5rem; }
  .auth-info h1 { font-size: 1.55rem; }
}

/* ----- Modal ----- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  animation: fadeIn 0.2s ease;
}
.modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 2rem;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
  max-height: 92vh;
  overflow-y: auto;
  animation: slideUp 0.22s ease;
}
@keyframes slideUp {
  from { transform: translateY(18px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.modal-title { font-size: 1.15rem; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  transition: background var(--transition);
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}
@media (max-width: 480px) {
  .modal { padding: 1.25rem; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; justify-content: center; }
}

/* ----- Toast ----- */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  z-index: 8000;
  max-width: 340px;
}
.toast {
  background: #1a1a2e;
  color: #fff;
  padding: 0.75rem 1.1rem;
  border-radius: 10px;
  font-size: 0.875rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: slideInRight 0.3s ease;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger);  }
.toast.warning { background: var(--warning); }
@keyframes slideInRight {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ----- Page Header ----- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.page-title {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

/* ----- Stats Grid ----- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  text-align: center;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-lg); }
.stat-icon  { font-size: 1.6rem; margin-bottom: 0.4rem; }
.stat-value { font-size: 1.9rem; font-weight: 700; color: var(--primary); line-height: 1.1; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.3rem; }

/* ----- Tab Bar ----- */
.tab-bar {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1.5rem;
  gap: 0.15rem;
  overflow-x: auto;
}
.tab-item {
  padding: 0.55rem 1rem;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition);
}
.tab-item.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-item:hover  { color: var(--primary); }

/* ----- Quiz ----- */
.quiz-container { max-width: 720px; margin: 0 auto; }
.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.quiz-progress-text { color: var(--text-muted); font-size: 0.875rem; }

.timer {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 1rem;
  font-weight: 700;
  padding: 0.38rem 0.85rem;
  border-radius: 8px;
  background: var(--primary-light);
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  transition: background var(--transition), color var(--transition);
}
.timer.warn   { background: #fff3bf; color: #e67700; }
.timer.danger { background: #fff5f5; color: var(--danger); animation: pulse 1s ease infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

.progress-bar-outer {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-bottom: 1.25rem;
  overflow: hidden;
}
.progress-bar-inner {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.question-card { margin-bottom: 1.25rem; }
.question-number { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.6rem; }
.question-text   { font-size: 1.05rem; line-height: 1.75; margin-bottom: 1.25rem; }

.options-list { display: flex; flex-direction: column; gap: 0.65rem; }
.option-btn {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  background: var(--surface);
  font-size: 0.95rem;
  text-align: left;
  width: 100%;
  transition: all var(--transition);
  font-family: inherit;
}
.option-btn:hover    { border-color: var(--primary); background: var(--primary-light); }
.option-btn.selected { border-color: var(--primary); background: var(--primary-light); }
.option-btn.correct  { border-color: var(--success); background: #ebfbee; }
.option-btn.wrong    { border-color: var(--danger);  background: #fff5f5; }
.option-btn[disabled]{ cursor: default; }

.option-label {
  min-width: 28px; height: 28px;
  background: var(--bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  flex-shrink: 0;
  transition: all var(--transition);
}
.option-btn.selected .option-label { background: var(--primary); color: #fff; }
.option-btn.correct  .option-label { background: var(--success); color: #fff; }
.option-btn.wrong    .option-label { background: var(--danger);  color: #fff; }

.question-image,
.question-image-preview img {
  display: block;
  width: min(100%, 620px);
  max-height: 360px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  margin: 0.75rem 0 1rem;
}

.quiz-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

/* Quiz Results */
.quiz-results { text-align: center; }
.score-circle {
  width: 150px; height: 150px;
  border-radius: 50%;
  border: 8px solid var(--primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.25rem;
}
.score-pct      { font-size: 2.2rem; font-weight: 800; color: var(--primary); line-height: 1; }
.score-fraction { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.25rem; }
.result-grade   { font-size: 1.25rem; font-weight: 700; margin-bottom: 0.4rem; }

/* ----- History ----- */
.history-list { display: flex; flex-direction: column; gap: 0.7rem; }
.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  transition: box-shadow var(--transition);
}
.history-item:hover { box-shadow: var(--shadow); }
.history-item.reviewable { cursor: pointer; }
.history-item.reviewable:focus {
  outline: 3px solid rgba(34,139,230,0.18);
  outline-offset: 2px;
}
.history-badge {
  padding: 0.22rem 0.6rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.result-grade {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
.badge-completed { background: #ebfbee; color: #2f9e44; }
.badge-paused    { background: #fff3bf; color: #e67700; }
.badge-progress  { background: #e7f5ff; color: #1971c2; }
.badge-expired   { background: #fff5f5; color: #e03131; }
.history-info    { flex: 1; min-width: 0; }
.history-title   { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-meta    { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.15rem; }
.history-score   { font-size: 1.1rem; font-weight: 700; color: var(--primary); flex-shrink: 0; }
.history-actions { display: flex; gap: 0.45rem; flex-shrink: 0; }

/* ----- Admin ----- */
.admin-section { margin-bottom: 2rem; }
.admin-section-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 1rem;
}
.question-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.65rem;
  transition: border-color var(--transition), box-shadow var(--transition), opacity var(--transition);
}
.question-item.dragging {
  opacity: 0.55;
  box-shadow: var(--shadow-lg);
}
.question-item.drag-over {
  border-color: var(--primary);
}
.question-item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.question-item-text    { flex: 1; font-size: 0.95rem; line-height: 1.65; min-width: 0; }
.question-item-text p,
.question-item-text div { margin: 0; }
.question-item-text ul,
.question-item-text ol {
  margin: 0.15rem 0;
  padding-left: 1.1rem;
}
.question-item-text li {
  margin: 0.05rem 0;
  padding-left: 0.1rem;
}
.question-item-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.question-select { display: flex; align-items: flex-start; padding-top: 0.25rem; }
.question-preview-thumb {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-top: 0.4rem;
}
.drag-handle {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: grab;
  padding: 0.2rem 0.1rem;
  line-height: 1;
  font-size: 1rem;
}
.drag-handle:active { cursor: grabbing; }
.drag-handle:hover { color: var(--primary); }
.question-filter-select {
  width: min(100%, 260px);
}
.editor-toolbar {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.rich-editor,
.question-live-preview {
  width: 100%;
  min-height: 130px;
  padding: 0.75rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  line-height: 1.65;
  outline: none;
}
.rich-editor:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(34,139,230,0.12);
}
.rich-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
}
.rich-editor ul,
.rich-editor ol,
.question-live-preview ul,
.question-live-preview ol,
.question-text ul,
.question-text ol,
.explanation-text ul,
.explanation-text ol {
  padding-left: 1.35rem;
  margin: 0.35rem 0;
}
.rich-editor mark,
.rich-editor span[style*="background-color"],
.question-live-preview mark,
.question-live-preview span[style*="background-color"],
.question-text mark,
.question-text span[style*="background-color"],
.question-item-text mark,
.question-item-text span[style*="background-color"],
.explanation-text mark,
.explanation-text span[style*="background-color"] {
  background: #fff3bf;
  border-radius: 3px;
  padding: 0 0.12rem;
}
.explanation-text {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
  margin-top: 0.45rem;
}
.question-image-preview:empty {
  display: none;
}
.file-upload-control {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.file-upload-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.file-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.6rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), color var(--transition), box-shadow var(--transition);
}
.file-upload-btn:hover,
.file-upload-input:focus + .file-upload-btn {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  box-shadow: 0 0 0 3px rgba(34,139,230,0.1);
}
.file-upload-name {
  color: var(--text-muted);
  font-size: 0.85rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.question-check,
.bulk-select-all input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--primary);
}
.bulk-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 0.8rem;
}
.bulk-select-all {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  font-weight: 600;
}
.history-export-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.history-export-controls .form-input {
  width: min(100%, 280px);
}
.table-wrap {
  overflow-x: auto;
  width: 100%;
}
.session-table {
  min-width: 980px;
}
.chart-panel {
  width: 100%;
}
.score-chart {
  width: 100%;
  min-height: 220px;
  margin-top: 0.75rem;
}
.score-chart svg {
  display: block;
  width: 100%;
  height: 220px;
}
.chart-axis {
  stroke: var(--border);
  stroke-width: 1.5;
}
.chart-area {
  fill: rgba(34, 139, 230, 0.14);
}
.chart-line {
  fill: none;
  stroke: var(--primary);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chart-point {
  fill: var(--surface);
  stroke: var(--primary);
  stroke-width: 2.5;
}
.chart-label {
  fill: var(--text-muted);
  font-size: 0.7rem;
}

/* ----- Empty State ----- */
.empty-state {
  text-align: center;
  padding: 3.5rem 1rem;
  color: var(--text-muted);
}
.empty-state-icon  { font-size: 3rem; margin-bottom: 0.75rem; }
.empty-state-title { font-size: 1.1rem; font-weight: 600; color: var(--text); margin-bottom: 0.4rem; }

/* ----- Quiz Setup ----- */
.quiz-setup { max-width: 480px; margin: 0 auto; }

/* ----- Divider ----- */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

/* ----- Responsive ----- */
@media (max-width: 640px) {
  .page { padding: 0.75rem; }
  .card { padding: 1rem; }
  .quiz-nav { flex-direction: column; }
  .quiz-nav .btn { width: 100%; justify-content: center; }
  .quiz-header { flex-direction: column; align-items: flex-start; }
  .page-header { flex-direction: column; align-items: flex-start; }
  #toast-container { left: 0.75rem; right: 0.75rem; max-width: none; }
}

/* ----- KaTeX Overrides ----- */
.katex { font-size: 1em !important; }
.katex-display { overflow-x: auto; margin: 0.5em 0 !important; }

/* ----- Input with inline validation icon ----- */
.input-wrap { position: relative; }
.input-wrap .form-input { padding-right: 2.5rem; }
.input-valid-icon {
  position: absolute;
  right: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  color: var(--success);
  opacity: 0;
  transition: opacity 0.22s ease;
  pointer-events: none;
}
.input-valid-icon.show { opacity: 1; }

/* ----- Password Policy Checklist ----- */
.pwd-policy {
  list-style: none;
  margin: 0.55rem 0 0.5rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
}
.pwd-policy li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: color 0.22s ease;
  user-select: none;
}
.pwd-policy li .pi {                /* policy icon */
  width: 14px;
  text-align: center;
  font-size: 0.78rem;
  color: #ced4da;
  transition: color 0.22s ease, transform 0.18s ease;
  flex-shrink: 0;
}
.pwd-policy li.met        { color: var(--success); }
.pwd-policy li.met .pi    { color: var(--success); transform: scale(1.15); }

/* ----- Confirm-password match hint ----- */
.pwd-match-hint {
  font-size: 0.8rem;
  margin-top: 0.3rem;
  display: none;
  align-items: center;
  gap: 0.4rem;
}
.pwd-match-hint.show     { display: flex; }
.pwd-match-hint.ok       { color: var(--success); }
.pwd-match-hint.bad      { color: var(--danger);  }

/* ----- Utility ----- */
.text-muted   { color: var(--text-muted); }
.text-center  { text-align: center; }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.gap-1 { gap: 0.5rem; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.w-full { width: 100%; }

/* ----- Table ----- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.data-table th {
  text-align: left;
  padding: 0.7rem 0.75rem;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.data-table td {
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg); }

/* ----- Role Badge ----- */
.role-badge {
  display: inline-block;
  padding: 0.18rem 0.55rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.role-admin   { background: var(--primary-light); color: var(--primary); }
.role-student { background: var(--bg);            color: var(--text-muted); }

/* ----- Invite note ----- */
.info-box {
  background: var(--primary-light);
  border: 1px solid #a5d8ff;
  border-radius: 8px;
  padding: 0.85rem 1rem;
  font-size: 0.85rem;
  color: var(--primary-dark);
  margin-bottom: 1.25rem;
}

/* ----- Legal Pages ----- */
.legal-page {
  min-height: 100vh;
  background: var(--bg);
  padding: 2rem 1rem;
}
.legal-document {
  max-width: 820px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
}
.legal-document h1 {
  color: var(--primary);
  margin-bottom: 0.35rem;
}
.legal-document h2 {
  font-size: 1.05rem;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}
.legal-document p,
.legal-document li {
  color: var(--text-muted);
  line-height: 1.7;
}
.legal-document ul { padding-left: 1.2rem; }
.legal-nav {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
