/* ============================================================
   BUTTONS — Polished with depth
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  background: var(--primary);
  color: white;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  transition: all var(--transition);
  min-height: 40px;
  border: 1px solid transparent;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  letter-spacing: -0.01em;
}

.btn:hover {
  background: var(--primary-hover);
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 6px 16px var(--primary-glow);
}

.btn:active { transform: translateY(0) scale(0.98); box-shadow: none; }
.btn-secondary { background: var(--bg-elev); color: var(--text); border-color: var(--border); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--bg-soft); border-color: var(--border-hover); box-shadow: var(--shadow); }
.btn-success { background: var(--success); }
.btn-success:hover { box-shadow: 0 4px 12px rgba(22, 163, 74, 0.2); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { box-shadow: 0 4px 12px rgba(220, 38, 38, 0.2); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); box-shadow: none; }
.btn-ghost:hover { background: var(--bg-soft); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; min-height: 30px; }
.btn-lg { padding: 14px 28px; font-size: 1rem; min-height: 48px; border-radius: var(--radius); }
.btn-icon { padding: 8px; min-width: 36px; min-height: 36px; border-radius: 8px; }
.btn[disabled],
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

/* ============================================================
   CARDS — Elevated with clean depth
   ============================================================ */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  transition: all var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.card-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 8px; }
.card-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 12px; }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.9rem; }

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: border var(--transition);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--primary);
  outline: none;
}

.form-textarea { resize: vertical; min-height: 80px; font-family: inherit; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.form-help { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

/* Toggle switch */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; gap: 12px; }

.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border);
  border-radius: 24px;
  transition: var(--transition);
}

.toggle-slider:before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: var(--transition);
}

.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider:before { transform: translateX(20px); }

/* ============================================================
   NAV TABS
   ============================================================ */
.nav-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
  overflow-x: auto;
  padding: 5px;
  background: var(--bg-soft);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.82rem;
  white-space: nowrap;
  transition: all var(--transition);
  border: none;
}
.nav-tab svg { flex-shrink: 0; }

.nav-tab:hover { color: var(--text); background: var(--primary-soft); }
.nav-tab.active { color: #fff; background: var(--primary); box-shadow: 0 4px 12px var(--primary-glow); }

/* ============================================================
   BADGES & STATUS
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--bg-soft);
  letter-spacing: 0.02em;
  border: 1px solid var(--border);
}

.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-info { background: var(--primary-soft); color: var(--primary); }

.difficulty-easy { background: var(--success-soft); color: var(--success); }
.difficulty-medium { background: var(--warning-soft); color: var(--warning); }
.difficulty-hard { background: var(--danger-soft); color: var(--danger); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 30, 0.55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 200ms ease;
}

.modal-lg { max-width: 900px; }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-title { font-size: 1.3rem; font-weight: 700; }
.modal-close { font-size: 1.4rem; color: var(--text-muted); padding: 4px 10px; border-radius: 6px; }
.modal-close:hover { background: var(--bg-soft); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }

/* ============================================================
   TABLES
   ============================================================ */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { background: var(--bg-soft); font-weight: 700; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-soft); }

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-stack {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 320px;
}

.toast {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  animation: slideIn 250ms ease;
  font-size: 0.9rem;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ============================================================
   STAT BOXES
   ============================================================ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin: 20px 0;
}

.stat {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 16px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.stat::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--grad);
}

.stat:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-4px) scale(1.02);
}

/* ============================================================
   USER AVATAR (initials circle)
   ============================================================ */
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
  color: white;
  flex-shrink: 0;
  text-transform: uppercase;
}

.avatar-sm { width: 26px; height: 26px; font-size: 0.65rem; }
.avatar-lg { width: 44px; height: 44px; font-size: 1rem; }

/* ============================================================
   BREADCRUMBS
   ============================================================ */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.breadcrumb-item {
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s;
}

.breadcrumb-item:hover { color: var(--text); }
.breadcrumb-sep { opacity: 0.4; }
.breadcrumb-current { color: var(--text); font-weight: 600; }

.stat-value { font-size: 1.8rem; font-weight: 900; color: var(--primary); letter-spacing: -0.03em; }
.stat-label { font-size: 0.72rem; color: var(--text-muted); margin-top: 6px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }

/* ============================================================
   CHARTS
   ============================================================ */
.chart-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.chart-card h3 { font-size: 1rem; margin-bottom: 10px; }
.chart-canvas-wrap { position: relative; height: 280px; }

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.login-screen {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  max-width: 420px;
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px;
  box-shadow: var(--shadow-lg);
}

.login-card h1 { font-size: 1.6rem; margin-bottom: 6px; }
.login-card p { color: var(--text-muted); margin-bottom: 24px; }

/* ============================================================
   PROGRESS BAR
   ============================================================ */
.progress-bar {
  height: 8px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
  margin: 12px 0;
}

.progress-fill {
  height: 100%;
  background: var(--grad);
  transition: width var(--transition);
}

/* ============================================================
   ADMIN
   ============================================================ */
.admin-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.q-edit-card {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.q-edit-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.notif-badge {
  position: absolute; top: 2px; right: 2px;
  background: var(--danger); color: white;
  font-size: 0.6rem; font-weight: 700;
  width: 16px; height: 16px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}

/* Preview-as-student banner */
.preview-banner {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  flex-wrap: wrap;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white; padding: 10px 16px; border-radius: var(--radius);
  margin-bottom: 16px; font-size: 0.88rem; font-weight: 600;
}
.preview-banner .btn { background: rgba(255,255,255,0.2); color: white; border: 1px solid rgba(255,255,255,0.4); }
.preview-banner .btn:hover { background: rgba(255,255,255,0.3); }

/* ============================================================
   PUBLIC QUIZ LIBRARY
   ============================================================ */
.library-header { margin-bottom: 20px; }
.library-header h2 { font-size: 1.5rem; font-weight: 800; margin-bottom: 4px; }

.library-filters {
  display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.library-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.library-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}

.library-card-header {
  display: flex; gap: 6px; margin-bottom: 10px;
}

.library-card-title {
  font-size: 1rem; font-weight: 700; margin-bottom: 6px;
  color: var(--text);
}

.library-card-desc {
  font-size: 0.82rem; color: var(--text-muted); line-height: 1.4;
  margin-bottom: 12px;
}

.library-card-meta {
  display: flex; gap: 12px; flex-wrap: wrap;
  font-size: 0.75rem; color: var(--text-muted); margin-bottom: 12px;
}
.library-card-meta span {
  display: inline-flex; align-items: center; gap: 4px;
}

.library-card-footer {
  display: flex; justify-content: space-between; align-items: center;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.library-card-author {
  font-size: 0.75rem; color: var(--text-muted);
}

.library-pagination {
  display: flex; gap: 6px; justify-content: center; flex-wrap: wrap;
}

/* ============================================================
   ONBOARDING WIZARD
   ============================================================ */
#onboarding-overlay {
  position: fixed; inset: 0; z-index: 99999;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.onboarding-card {
  background: var(--bg-elev); border-radius: 20px;
  padding: 36px; max-width: 520px; width: 100%;
  box-shadow: 0 24px 80px rgba(0,0,0,0.3);
}
.onboarding-header { text-align: center; margin-bottom: 24px; }
.onboarding-header h2 { font-size: 1.3rem; font-weight: 800; margin: 12px 0 4px; }
.onboarding-header p { font-size: 0.9rem; }
.onboarding-options { display: flex; flex-direction: column; gap: 10px; }
.onboarding-option {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: 12px;
  border: 1.5px solid var(--border); background: var(--bg);
  text-align: left; cursor: pointer; transition: all 0.2s ease;
  width: 100%;
}
.onboarding-option:hover {
  border-color: var(--primary); background: var(--primary-soft);
  transform: translateX(4px);
}
.onboarding-option-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--primary-soft); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.onboarding-option:hover .onboarding-option-icon {
  background: var(--primary); color: white;
}
.onboarding-option-text { flex: 1; }
.onboarding-option-text strong { display: block; font-size: 0.9rem; margin-bottom: 2px; }
.onboarding-option-text span { font-size: 0.78rem; color: var(--text-muted); line-height: 1.4; }
.onboarding-footer { margin-top: 20px; text-align: center; }
.onboarding-tip {
  display: flex; align-items: center; gap: 6px; justify-content: center;
  margin-top: 12px; font-size: 0.75rem; color: var(--text-muted);
}

/* ============================================================
   LEGAL PAGES
   ============================================================ */
.legal-page {
  max-width: 800px;
  margin: 0 auto;
  line-height: 1.8;
  color: var(--text);
}
.legal-page h1 { font-size: 1.8rem; font-weight: 800; margin-bottom: 8px; }
.legal-page h2 { font-size: 1.2rem; font-weight: 700; margin-top: 32px; margin-bottom: 8px; color: var(--text); }
.legal-page h3 { font-size: 1rem; font-weight: 600; margin-top: 16px; margin-bottom: 6px; }
.legal-page p { margin-bottom: 12px; color: var(--text-muted); font-size: 0.9rem; }
.legal-page ul { margin: 8px 0 16px 24px; color: var(--text-muted); font-size: 0.9rem; }
.legal-page li { margin-bottom: 6px; }
.legal-updated { font-size: 0.8rem; color: var(--text-muted); opacity: 0.7; margin-bottom: 24px; }

/* ============================================================
   Mobile Responsive
   ============================================================ */

/* ─── Tablet (768px) ─── */
@media (max-width: 768px) {
  .nav-tabs {
    padding: 3px;
    gap: 4px;
  }

  .nav-tab {
    padding: 7px 12px;
    font-size: 0.75rem;
  }

  .modal {
    padding: 20px;
    max-width: calc(100% - 24px);
  }

  .modal-lg {
    max-width: calc(100% - 24px);
  }

  th, td {
    padding: 8px 10px;
    font-size: 0.82rem;
  }

  .login-card {
    padding: 24px;
    max-width: 100%;
  }

  .btn-lg {
    padding: 12px 20px;
    font-size: 0.9rem;
  }

  .stat {
    padding: 16px 12px;
  }

  .stat-value {
    font-size: 1.4rem;
  }

  .chart-canvas-wrap {
    height: 220px;
  }

  .toast-stack {
    right: 12px;
    left: 12px;
    max-width: none;
  }

  .admin-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .modal-actions {
    flex-direction: column;
  }
}

/* ─── Phone (480px) ─── */
@media (max-width: 480px) {
  .nav-tabs {
    gap: 2px;
  }

  .nav-tab {
    padding: 6px 10px;
    font-size: 0.7rem;
  }

  .nav-tab svg {
    width: 14px;
    height: 14px;
  }

  .btn {
    padding: 9px 14px;
    font-size: 0.82rem;
  }

  .stat-value {
    font-size: 1.2rem;
  }

  .stat-label {
    font-size: 0.65rem;
  }

  .card {
    padding: 16px;
    border-radius: 12px;
  }

  .chart-canvas-wrap {
    height: 180px;
  }

  table {
    font-size: 0.78rem;
  }

  th, td {
    padding: 6px 8px;
  }
}
