/* ============================================================
   EduHoc Design System — app.css
   Production build (adapted from .ui reference)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* === TOKENS === */
:root {
  /* Brand — overridden per-tenant via _tenant_css.php */
  --primary: #2563EB;

  --blue-50:#EFF6FF; --blue-100:#DBEAFE; --blue-200:#BFDBFE;
  --blue-300:#93C5FD; --blue-400:#60A5FA;
  --blue-500:#3B82F6; --blue-600:#2563EB; --blue-700:#1D4ED8;

  --gray-50:#F9FAFB; --gray-100:#F3F4F6; --gray-200:#E5E7EB;
  --gray-300:#D1D5DB; --gray-400:#9CA3AF; --gray-500:#6B7280;
  --gray-600:#4B5563; --gray-700:#374151; --gray-800:#1F2937; --gray-900:#111827;

  --green-50:#F0FDF4; --green-100:#DCFCE7; --green-500:#22C55E;
  --green-600:#16A34A; --green-700:#15803D;
  --red-50:#FEF2F2; --red-100:#FEE2E2; --red-500:#EF4444; --red-600:#DC2626;
  --yellow-50:#FFFBEB; --yellow-100:#FEF3C7; --yellow-500:#F59E0B; --yellow-600:#D97706;
  --orange-50:#FFF7ED; --orange-100:#FFEDD5; --orange-500:#F97316; --orange-600:#EA580C;
  --purple-50:#FAF5FF; --purple-100:#F3E8FF; --purple-500:#A855F7; --purple-600:#9333EA;
  --purple-700:#7C3AED;
  --teal-50:#F0FDFA; --teal-100:#CCFBF1; --teal-500:#14B8A6; --teal-600:#0D9488;

  /* Surfaces + status tones (light). Dark values are under html[data-theme='dark']. */
  --surface: #FFFFFF;
  --tone-blue-bg: var(--blue-100);     --tone-blue-fg: var(--blue-700);
  --tone-green-bg: var(--green-100);   --tone-green-fg: var(--green-700);
  --tone-red-bg: var(--red-100);       --tone-red-fg: var(--red-600);
  --tone-yellow-bg: var(--yellow-100); --tone-yellow-fg: #92400E;
  --tone-orange-bg: var(--orange-100); --tone-orange-fg: #C2410C;
  --tone-purple-bg: var(--purple-100); --tone-purple-fg: var(--purple-700);
  --tone-teal-bg: var(--teal-100);     --tone-teal-fg: #0F766E;
  --tone-gray-bg: var(--gray-100);     --tone-gray-fg: var(--gray-600);
  --text-success: var(--green-600); --text-danger: var(--red-500); --text-warning: var(--yellow-600); --text-info: var(--blue-600);

  /* Sidebar role accent — set inline per role in authenticated.php */
  --sidebar-accent-text: var(--blue-600);
  --sidebar-accent-bg:   var(--blue-50);

  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --radius-sm: 4px; --radius: 6px; --radius-md: 8px; --radius-lg: 12px;
  --radius-xl: 16px; --radius-2xl: 20px; --radius-full: 9999px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow:    0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
  --shadow-xl: 0 20px 25px rgba(0,0,0,.1), 0 10px 10px rgba(0,0,0,.04);
}

html[data-theme='dark'] {
  color-scheme: dark;
  --surface: #111827;
  --tone-blue-bg: rgba(59, 130, 246, .18);   --tone-blue-fg: #93C5FD;
  --tone-green-bg: rgba(34, 197, 94, .16);   --tone-green-fg: #86EFAC;
  --tone-red-bg: rgba(239, 68, 68, .18);     --tone-red-fg: #FCA5A5;
  --tone-yellow-bg: rgba(245, 158, 11, .18); --tone-yellow-fg: #FCD34D;
  --tone-orange-bg: rgba(249, 115, 22, .18); --tone-orange-fg: #FDBA74;
  --tone-purple-bg: rgba(168, 85, 247, .20); --tone-purple-fg: #D8B4FE;
  --tone-teal-bg: rgba(20, 184, 166, .18);   --tone-teal-fg: #5EEAD4;
  --tone-gray-bg: rgba(148, 163, 184, .16);  --tone-gray-fg: #CBD5E1;
  --text-success: #4ADE80; --text-danger: #F87171; --text-warning: #FBBF24; --text-info: #60A5FA;
  --blue-50:#0F172A; --blue-100:#172554; --blue-200:#1E3A8A;
  --gray-50:#0B1220; --gray-100:#111827; --gray-200:#1F2937;
  --gray-300:#334155; --gray-400:#64748B; --gray-500:#94A3B8;
  --gray-600:#CBD5E1; --gray-700:#E2E8F0; --gray-800:#F1F5F9; --gray-900:#F8FAFC;
  --green-50:#052E1C; --green-100:#14532D;
  --red-50:#3A1010; --red-100:#450A0A;
  --yellow-50:#3A2B05; --yellow-100:#422006;
  --orange-50:#3B1707; --orange-100:#431407;
  --purple-50:#2E1065; --purple-100:#3B0764;
  --teal-50:#042F2E; --teal-100:#134E4A;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.45);
  --shadow:    0 1px 3px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.35);
  --shadow-md: 0 4px 6px rgba(0,0,0,.45), 0 2px 4px rgba(0,0,0,.35);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.45), 0 4px 6px rgba(0,0,0,.35);
  --shadow-xl: 0 20px 25px rgba(0,0,0,.5), 0 10px 10px rgba(0,0,0,.4);
}

/* === RESET === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; overflow-x: hidden; }
body { font-family: var(--font); color: var(--gray-800); background: var(--gray-50); line-height: 1.5; overflow-x: hidden; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: var(--font); -webkit-tap-highlight-color: transparent; }
img { max-width: 100%; display: block; }
ul, ol { list-style: none; }
input, select, textarea { font-family: var(--font); -webkit-tap-highlight-color: transparent; }
/* Prevent iOS Safari zoom on input focus (font-size < 16px triggers zoom) */
@media (max-width: 768px) {
  input, select, textarea { font-size: max(16px, 1em); }
}

/* ============================================================
   APP SHELL
   ============================================================ */

.app { display: flex; min-height: 100vh; }

/* --- Sidebar --- */
.sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--gray-200);
  position: fixed; top: 0; left: 0; bottom: 0;
  overflow-y: auto; z-index: 100;
  display: flex; flex-direction: column;
  transition: transform .25s ease, width .2s ease;
  scrollbar-width: thin; scrollbar-color: var(--gray-200) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 4px; }

.sidebar-logo {
  height: 64px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 20px;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}
.sidebar-logo-text {
  font-size: 18px; font-weight: 800; color: var(--primary);
  white-space: nowrap; letter-spacing: -.5px; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-logo-badge {
  font-size: 10px; font-weight: 700; background: var(--primary); color: white;
  padding: 2px 6px; border-radius: var(--radius-full); flex-shrink: 0;
}
.sidebar-nav { flex: 1; padding: 12px 10px; }
.sidebar-section { margin-bottom: 20px; }
.sidebar-section-label {
  font-size: 11px; font-weight: 600; color: var(--gray-400);
  text-transform: uppercase; letter-spacing: .06em;
  padding: 0 10px; margin-bottom: 4px; display: block;
}
.sidebar-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-md);
  color: var(--gray-600); font-size: 14px; font-weight: 500;
  transition: background .12s, color .12s;
  margin-bottom: 1px; cursor: pointer;
  border: none; background: none; width: 100%; text-align: left;
}
.sidebar-item:hover { background: var(--gray-100); color: var(--gray-900); }
.sidebar-item.active {
  background: var(--sidebar-accent-bg);
  color: var(--sidebar-accent-text);
  font-weight: 600;
}
.sidebar-item .icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.sidebar-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-item .count {
  margin-left: auto; font-size: 11px; font-weight: 700;
  background: var(--red-500); color: white;
  padding: 1px 6px; border-radius: var(--radius-full); min-width: 18px; text-align: center; flex-shrink: 0;
}
.sidebar-footer {
  padding: 14px 12px; border-top: 1px solid var(--gray-200); flex-shrink: 0;
}
.sidebar-user {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px;
  border-radius: var(--radius-md); cursor: pointer; transition: background .12s;
}
.sidebar-user:hover { background: var(--gray-100); }
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: 13px; font-weight: 600; color: var(--gray-900);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-role { font-size: 11px; color: var(--gray-500); }

/* Sidebar backdrop (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 99;
}
.sidebar-overlay.active { display: block; }

/* --- Header --- */
.header {
  height: 64px;
  background: var(--surface);
  border-bottom: 1px solid var(--gray-200);
  position: fixed; top: 0; left: 240px; right: 0;
  z-index: 200;
  display: flex; align-items: center; padding: 0 20px; gap: 12px;
}
.header-toggle {
  display: none;
  width: 36px; height: 36px;
  border: none; background: none;
  font-size: 20px; color: var(--gray-500);
  border-radius: var(--radius-md);
  align-items: center; justify-content: center;
}
.header-toggle:hover { background: var(--gray-100); }
.header-search { flex: 1; max-width: 400px; position: relative; }
.header-search input {
  width: 100%; height: 36px;
  padding: 0 16px 0 36px;
  border: 1px solid var(--gray-200); border-radius: var(--radius-full);
  font-size: 14px; color: var(--gray-700); background: var(--gray-50); outline: none;
  transition: border-color .15s, background .15s;
}
.header-search input:focus {
  border-color: var(--blue-500); background: var(--surface);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.header-search input::placeholder { color: var(--gray-400); }
.header-search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--gray-400); font-size: 14px; pointer-events: none;
}
.header-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--radius-full); border: none;
  background: transparent; display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--gray-500); position: relative; cursor: pointer;
  transition: background .15s;
}
.icon-btn:hover { background: var(--gray-100); }
.theme-toggle .theme-icon-sun { display: inline; }
.theme-toggle .theme-icon-moon { display: none; }
html[data-theme='dark'] .theme-toggle .theme-icon-sun { display: none; }
html[data-theme='dark'] .theme-toggle .theme-icon-moon { display: inline; }
.badge-dot {
  position: absolute; top: 5px; right: 5px;
  width: 8px; height: 8px;
  background: var(--red-500); border-radius: var(--radius-full); border: 2px solid white;
}
html[data-theme='dark'] .badge-dot { border-color: var(--gray-100); }
.user-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: var(--radius-full); cursor: pointer;
  transition: background .15s; border: none; background: none;
  font-family: var(--font);
}
.user-pill:hover { background: var(--gray-100); }
.user-name { font-size: 14px; font-weight: 500; color: var(--gray-700); }
.user-caret { color: var(--gray-400); font-size: 12px; }

/* --- Main content area --- */
.main {
  margin-left: 240px;
  margin-top: 64px;
  padding: 24px;
  min-height: calc(100vh - 64px);
  flex: 1; min-width: 0;
}

/* --- Mobile bottom nav (student only, shown on mobile) --- */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 56px; background: var(--surface);
  border-top: 1px solid var(--gray-200);
  z-index: 150;
  justify-content: space-around; align-items: center;
}
.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  padding: 6px 0; cursor: pointer;
  border: none; background: none; font-family: var(--font);
  color: var(--gray-400); font-size: 11px; font-weight: 500;
  text-decoration: none; transition: color .15s;
}
.bottom-nav-item .icon { font-size: 20px; line-height: 1; }
.bottom-nav-item.active { color: var(--sidebar-accent-text, var(--blue-600)); }

/* === BREADCRUMB === */
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--gray-400); margin-bottom: 20px; }
.breadcrumb a { color: var(--gray-500); }
.breadcrumb a:hover { color: var(--blue-600); text-decoration: underline; }
.breadcrumb-sep { color: var(--gray-300); }
.breadcrumb .current { color: var(--gray-700); font-weight: 500; }

.page-header { margin-bottom: 24px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 700; color: var(--gray-900); margin-bottom: 4px; }
.page-subtitle { font-size: 14px; color: var(--gray-500); }

.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-title { font-size: 15px; font-weight: 600; color: var(--gray-900); }

/* ============================================================
   EXAM SHELL
   ============================================================ */
.exam-shell { display: flex; flex-direction: column; min-height: 100vh; background: var(--gray-50); }
.exam-topbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 24px; height: 60px;
  background: var(--surface); border-bottom: 2px solid var(--gray-200);
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.exam-topbar-left  { display: flex; align-items: center; gap: 14px; min-width: 0; flex: 1; }
.exam-topbar-center { text-align: center; flex-shrink: 0; }
.exam-topbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.exam-back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 500; color: var(--gray-500);
  text-decoration: none; padding: 6px 12px;
  border: 1px solid var(--gray-200); border-radius: var(--radius-md);
  white-space: nowrap; transition: all .15s;
}
.exam-back-btn:hover { background: var(--gray-100); color: var(--gray-700); }
.exam-timer {
  font-size: 30px; font-weight: 800; letter-spacing: .03em;
  font-variant-numeric: tabular-nums; color: var(--gray-900); line-height: 1;
}
.exam-timer.warn   { color: var(--orange-500); }
.exam-timer.danger { color: var(--red-600); animation: timer-pulse 1s ease-in-out infinite; }
@keyframes timer-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
.exam-body { flex: 1; padding: 24px; overflow-y: auto; }
.exam-content-grid {
  display: grid; grid-template-columns: 1fr 288px; gap: 20px;
  max-width: 1100px; margin: 0 auto;
}

/* ============================================================
   AUTH LAYOUT
   ============================================================ */
.auth-shell { min-height: 100vh; display: flex; }
.auth-left {
  width: 40%; background: linear-gradient(135deg, var(--blue-700), var(--blue-600));
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px; color: white;
}
.auth-left h1 { font-size: 28px; font-weight: 800; margin-bottom: 12px; text-align: center; }
.auth-left p  { font-size: 16px; opacity: .85; text-align: center; line-height: 1.6; }
.auth-right { flex: 1; display: flex; align-items: center; justify-content: center; padding: 48px; background: var(--surface); }
.auth-form  { width: 100%; max-width: 380px; }
.auth-logo  { font-size: 24px; font-weight: 800; color: var(--blue-600); margin-bottom: 32px; text-align: center; }
.auth-stat  { display: flex; gap: 32px; margin-top: 32px; }
.auth-stat-item { text-align: center; }
.auth-stat-item .n { font-size: 24px; font-weight: 800; }
.auth-stat-item .l { font-size: 12px; opacity: .7; margin-top: 2px; }
.centered-auth {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--gray-50); padding: 24px;
}
.auth-card {
  background: var(--surface); border: 1px solid var(--gray-200);
  border-radius: var(--radius-2xl); padding: 40px;
  width: 100%; max-width: 520px; box-shadow: var(--shadow-lg);
}
.auth-card-logo { text-align: center; margin-bottom: 28px; }
.auth-card-logo span { font-size: 22px; font-weight: 800; color: var(--primary); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 16px; height: 36px; font-size: 14px; font-weight: 500;
  border-radius: var(--radius-md); border: 1px solid transparent;
  transition: all .15s; white-space: nowrap; cursor: pointer; font-family: var(--font);
}
.btn-sm  { height: 30px; padding: 0 12px; font-size: 13px; border-radius: var(--radius); }
.btn-lg  { height: 44px; padding: 0 24px; font-size: 15px; border-radius: var(--radius-lg); }
.btn-xl  { height: 52px; padding: 0 32px; font-size: 16px; font-weight: 600; border-radius: var(--radius-lg); }
.btn-full { width: 100%; }
.btn-primary   { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { filter: brightness(.92); }
.btn-secondary { background: var(--surface); color: var(--gray-700); border-color: var(--gray-300); }
.btn-secondary:hover { background: var(--gray-50); border-color: var(--gray-400); }
.btn-ghost  { background: transparent; color: var(--gray-600); border-color: transparent; }
.btn-ghost:hover { background: var(--gray-100); color: var(--gray-800); }
.btn-danger { background: var(--red-500); color: white; border-color: var(--red-500); }
.btn-danger:hover { background: var(--red-600); }
.btn-success { background: var(--green-600); color: white; border-color: var(--green-600); }
.btn-success:hover { background: var(--green-700); }
.btn:disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 16px; }
.label { display: block; font-size: 13px; font-weight: 500; color: var(--gray-700); margin-bottom: 5px; }
.label .req { color: var(--red-500); margin-left: 2px; }
.hint { font-size: 12px; color: var(--gray-400); margin-top: 4px; }
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--gray-300); border-radius: var(--radius-md);
  font-size: 14px; color: var(--gray-800); outline: none;
  transition: border-color .15s, box-shadow .15s; background: var(--surface);
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.input::placeholder { color: var(--gray-400); }
.textarea { height: auto; padding: 8px 12px; resize: vertical; }
.select {
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2'%3E%3Cpolyline points='6,9 12,15 18,9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 32px;
}
.input-with-icon { position: relative; }
.input-with-icon .input { padding-left: 36px; }
.input-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--gray-400); font-size: 15px; }
.input-group { display: flex; gap: 8px; }
.input-group .input { flex: 1; }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--blue-600); flex-shrink: 0; }
.check-item, .radio-item { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--gray-700); cursor: pointer; padding: 4px 0; }

/* ============================================================
   CARDS
   ============================================================ */
.card { background: var(--surface); border: 1px solid var(--gray-200); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-sm); }
.card-sm { padding: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 600; color: var(--gray-900); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--gray-200); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-sm); }
.stat-icon  { font-size: 28px; margin-bottom: 12px; }
.stat-value { font-size: 28px; font-weight: 800; color: var(--gray-900); line-height: 1; margin-bottom: 4px; }
.stat-label { font-size: 12px; font-weight: 500; color: var(--gray-500); text-transform: uppercase; letter-spacing: .04em; }
.stat-change { font-size: 12px; margin-top: 8px; display: flex; align-items: center; gap: 4px; }
.stat-change.up { color: var(--green-600); } .stat-change.down { color: var(--red-500); }
.course-card { background: var(--surface); border: 1px solid var(--gray-200); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); transition: box-shadow .2s, transform .2s; cursor: pointer; }
.course-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.course-thumb { height: 140px; display: flex; align-items: center; justify-content: center; font-size: 48px; position: relative; overflow: hidden; }
.course-body { padding: 16px; }
.course-title { font-size: 14px; font-weight: 600; color: var(--gray-900); margin-bottom: 6px; line-height: 1.4; }
.course-meta { font-size: 12px; color: var(--gray-500); margin-bottom: 12px; }
.course-price { font-size: 16px; font-weight: 700; color: var(--blue-600); }

/* ============================================================
   BADGES
   ============================================================ */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--radius-full); font-size: 12px; font-weight: 500; }
.badge-blue   { background: var(--tone-blue-bg);   color: var(--tone-blue-fg); }
.badge-green  { background: var(--tone-green-bg);  color: var(--tone-green-fg); }
.badge-red    { background: var(--tone-red-bg);    color: var(--tone-red-fg); }
.badge-yellow { background: var(--tone-yellow-bg); color: var(--tone-yellow-fg); }
.badge-gray   { background: var(--tone-gray-bg);   color: var(--tone-gray-fg); }
.badge-purple { background: var(--tone-purple-bg); color: var(--tone-purple-fg); }
.badge-orange { background: var(--tone-orange-bg); color: var(--tone-orange-fg); }
.badge-teal   { background: var(--tone-teal-bg);   color: var(--tone-teal-fg); }

/* ============================================================
   PROGRESS
   ============================================================ */
.progress    { height: 8px; background: var(--gray-200); border-radius: var(--radius-full); overflow: hidden; }
.progress-sm { height: 5px; } .progress-lg { height: 12px; }
.progress-bar { height: 100%; background: var(--blue-600); border-radius: var(--radius-full); transition: width .4s; }
.progress-bar.green  { background: var(--green-500); }
.progress-bar.yellow { background: var(--yellow-500); }
.progress-bar.red    { background: var(--red-500); }
.progress-row { margin-bottom: 12px; }
.progress-label { display: flex; justify-content: space-between; font-size: 13px; color: var(--gray-600); margin-bottom: 6px; }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap { border: 1px solid var(--gray-200); border-radius: var(--radius-lg); overflow: hidden; background: var(--surface); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-toolbar { padding: 14px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border-bottom: 1px solid var(--gray-200); background: var(--gray-50); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { background: var(--gray-50); padding: 12px 16px; text-align: left; font-size: 12px; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--gray-200); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--gray-100); color: var(--gray-700); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--gray-50); }
.td-actions { display: flex; gap: 4px; align-items: center; }

/* ============================================================
   TABS
   ============================================================ */
.tabs { display: flex; border-bottom: 1px solid var(--gray-200); margin-bottom: 20px; gap: 0; overflow-x: auto; }
.tab { padding: 10px 16px; font-size: 14px; font-weight: 500; color: var(--gray-500); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; transition: all .15s; margin-bottom: -1px; background: none; border-top: none; border-left: none; border-right: none; font-family: var(--font); }
.tab:hover { color: var(--gray-700); }
.tab.active { color: var(--blue-600); border-bottom-color: var(--blue-600); font-weight: 600; }
.tab-panel { display: none; } .tab-panel.active { display: block; }
.pill-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.pill-tab { padding: 6px 14px; border-radius: var(--radius-full); border: 1px solid var(--gray-300); font-size: 13px; font-weight: 500; color: var(--gray-600); cursor: pointer; transition: all .1s; background: var(--surface); font-family: var(--font); }
.pill-tab:hover { border-color: var(--blue-300); color: var(--blue-600); }
.pill-tab.active { background: var(--blue-600); color: white; border-color: var(--blue-600); }

/* ============================================================
   AVATAR
   ============================================================ */
.av { border-radius: var(--radius-full); display: flex; align-items: center; justify-content: center; font-weight: 700; color: white; flex-shrink: 0; font-size: 14px; }
.av-sm { width: 28px; height: 28px; font-size: 11px; }
.av-md { width: 36px; height: 36px; font-size: 13px; }
.av-lg { width: 48px; height: 48px; font-size: 16px; }
.av-xl { width: 72px; height: 72px; font-size: 24px; }
.av-a { background: linear-gradient(135deg, var(--blue-500), var(--blue-700)); }
.av-b { background: linear-gradient(135deg, var(--green-500), var(--teal-600)); }
.av-c { background: linear-gradient(135deg, var(--purple-500), var(--purple-700)); }
.av-d { background: linear-gradient(135deg, var(--orange-500), var(--red-500)); }
.av-e { background: linear-gradient(135deg, var(--yellow-500), var(--orange-500)); }

/* ============================================================
   ALERTS
   ============================================================ */
.alert { display: flex; gap: 12px; padding: 12px 16px; border-radius: var(--radius-md); font-size: 14px; border: 1px solid; }
.alert-info    { background: var(--blue-50);   border-color: var(--blue-200);   color: var(--blue-700); }
.alert-success { background: var(--green-50);  border-color: var(--green-100);  color: var(--green-700); }
.alert-warning { background: var(--yellow-50); border-color: var(--yellow-100); color: var(--yellow-600); }
.alert-danger  { background: var(--red-50);    border-color: var(--red-100);    color: var(--red-600); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 300; display: none; align-items: center; justify-content: center; padding: 16px; -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius-xl); max-width: 500px; width: 100%; box-shadow: var(--shadow-xl); -webkit-animation: modalIn .2s; animation: modalIn .2s; }
@-webkit-keyframes modalIn { from { opacity: 0; transform: scale(.95) translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes modalIn { from { opacity: 0; transform: scale(.95) translateY(-10px); } to { opacity: 1; transform: none; } }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; justify-content: space-between; }
.modal-title  { font-size: 17px; font-weight: 700; color: var(--gray-900); }
.modal-close  { width: 32px; height: 32px; border: none; background: none; font-size: 18px; cursor: pointer; border-radius: var(--radius); color: var(--gray-400); }
.modal-close:hover { background: var(--gray-100); color: var(--gray-700); }
.modal-body   { padding: 20px 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: 10px; }

/* ============================================================
   DROPDOWN
   ============================================================ */
.dropdown { position: relative; display: inline-flex; }
.dropdown-menu { position: absolute; top: calc(100% + 6px); right: 0; min-width: 200px; background: var(--surface); border: 1px solid var(--gray-200); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); z-index: 250; padding: 6px; display: none; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; font-size: 14px; color: var(--gray-700); border-radius: var(--radius); cursor: pointer; transition: background .1s; }
.dropdown-item:hover { background: var(--gray-100); }
.dropdown-divider { height: 1px; background: var(--gray-200); margin: 6px 0; }

/* ============================================================
   MISC COMPONENTS
   ============================================================ */
.divider { display: flex; align-items: center; gap: 12px; color: var(--gray-400); font-size: 13px; margin: 16px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--gray-200); }
.empty-state { text-align: center; padding: 48px 24px; color: var(--gray-400); }
.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--gray-600); margin-bottom: 8px; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: var(--radius-full); font-size: 12px; font-weight: 500; background: var(--gray-100); color: var(--gray-600); border: 1px solid var(--gray-200); }
.panel-layout { display: grid; grid-template-columns: 280px 1fr; gap: 20px; align-items: start; }
.sticky-panel { position: sticky; top: calc(64px + 24px); max-height: calc(100vh - 64px - 48px); overflow-y: auto; }

/* Gradients */
.grad-blue   { background: linear-gradient(135deg, #2563EB, #7C3AED); }
.grad-green  { background: linear-gradient(135deg, #059669, #0EA5E9); }
.grad-orange { background: linear-gradient(135deg, #EA580C, #EAB308); }
.grad-pink   { background: linear-gradient(135deg, #DB2777, #9333EA); }
.grad-teal   { background: linear-gradient(135deg, #0D9488, #2563EB); }

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.f{display:flex}.fc{flex-direction:column}.fi{align-items:center}
.fb{justify-content:space-between}.fe{justify-content:flex-end}.fw{flex-wrap:wrap}
.f1{flex:1}.g1{gap:4px}.g2{gap:8px}.g3{gap:12px}.g4{gap:16px}.g6{gap:24px}
.mb1{margin-bottom:4px}.mb2{margin-bottom:8px}.mb3{margin-bottom:12px}
.mb4{margin-bottom:16px}.mb5{margin-bottom:20px}.mb6{margin-bottom:24px}
.mt1{margin-top:4px}.mt2{margin-top:8px}.mt3{margin-top:12px}.mt4{margin-top:16px}.mt6{margin-top:24px}
.ml-auto{margin-left:auto}.mr-auto{margin-right:auto}
.w100{width:100%}.text-c{text-align:center}.text-r{text-align:right}
.fw4{font-weight:400}.fw5{font-weight:500}.fw6{font-weight:600}.fw7{font-weight:700}.fw8{font-weight:800}
.fs11{font-size:11px}.fs12{font-size:12px}.fs13{font-size:13px}.fs14{font-size:14px}
.fs15{font-size:15px}.fs16{font-size:16px}.fs18{font-size:18px}.fs22{font-size:22px}.fs28{font-size:28px}
.c400{color:var(--gray-400)}.c500{color:var(--gray-500)}.c600{color:var(--gray-600)}
.c700{color:var(--gray-700)}.c900{color:var(--gray-900)}
.cblue{color:var(--text-info)}.cgreen{color:var(--text-success)}.cred{color:var(--text-danger)}
.truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.rounded{border-radius:var(--radius)}.rounded-lg{border-radius:var(--radius-lg)}.rounded-full{border-radius:var(--radius-full)}
.shadow{box-shadow:var(--shadow)}.shadow-md{box-shadow:var(--shadow-md)}
.border{border:1px solid var(--gray-200)}.border-t{border-top:1px solid var(--gray-200)}.border-b{border-bottom:1px solid var(--gray-200)}
.p2{padding:8px}.p3{padding:12px}.p4{padding:16px}.p5{padding:20px}
.bg-white{background:white}.bg-gray50{background:var(--gray-50)}.bg-blue50{background:var(--blue-50)}
.relative{position:relative}.overflow-h{overflow:hidden}
.cursor{cursor:pointer}.shrink0{flex-shrink:0}

/* ============================================================
   COMPONENT PARTIALS — C2
   ============================================================ */

/* --- Spinner (used by btn-loading in button.php partial) --- */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 14px; height: 14px;
  border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; display: inline-block;
  animation: spin .6s linear infinite;
}
.btn-loading { opacity: .7; pointer-events: none; }

/* --- Input error state (used by input.php partial) --- */
.input.error, .select.error, .textarea.error {
  border-color: var(--red-500);
  box-shadow: 0 0 0 3px rgba(239,68,68,.1);
}
.error-msg { font-size: 12px; color: var(--red-500); margin-top: 4px; }

/* --- Modal size variants (used by modal.php partial) --- */
.modal-sm { max-width: 360px; }
.modal-lg { max-width: 700px; }
.modal-xl { max-width: 900px; }

/* --- Sortable table header (used by table.php partial) --- */
.sort-link {
  color: inherit; text-decoration: none;
  display: inline-flex; align-items: center; gap: 4px;
  white-space: nowrap;
}
.sort-link:hover { color: var(--blue-600); }
.sort-active { color: var(--blue-600) !important; }
.sort-icon { font-size: 10px; color: var(--gray-400); line-height: 1; }
.sort-active .sort-icon { color: var(--blue-600); }

/* --- Table footer / pagination wrapper (used by table.php partial) --- */
.table-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--gray-200);
  display: flex; align-items: center; justify-content: flex-end;
  background: var(--gray-50);
  gap: 8px;
}

/* ============================================================
   C5 — UI STATES: SKELETON, TOAST, EMPTY STATE
   ============================================================ */

/* --- Skeleton shimmer --- */
@keyframes shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position:  400px 0; }
}
.skel {
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 37%, var(--gray-100) 63%);
  background-size: 400px 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius);
  display: block;
}
.skel-text   { height: 14px; border-radius: var(--radius-sm); }
.skel-circle { border-radius: var(--radius-full); }

.skel-card { background: var(--surface); border: 1px solid var(--gray-200); border-radius: var(--radius-lg); padding: 20px; overflow: hidden; }
.skel-card .skel-thumb { height: 140px; margin: -20px -20px 16px; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }

.skel-row td { padding: 12px 16px; }

.skel-list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--gray-100); }
.skel-list-item:last-child { border-bottom: none; }

/* --- Empty state extended --- */
.empty-state p  { font-size: 14px; color: var(--gray-500); margin-bottom: 20px; line-height: 1.6; }
.empty-state .btn { margin-top: 4px; }
.empty-state-compact { padding: 28px 16px; }
.empty-state-compact .icon { font-size: 32px; }
.empty-state-compact h3 { font-size: 14px; }

/* --- Toast container --- */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 400;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--surface); box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--gray-300);
  font-size: 14px;
  min-width: 280px; max-width: 380px;
  pointer-events: all;
  animation: toastIn .25s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: none; }
}
.toast.out { animation: toastOut .2s ease forwards; }
@keyframes toastOut {
  to { opacity: 0; transform: translateX(16px); }
}
.toast-success { border-left-color: var(--green-500); }
.toast-error   { border-left-color: var(--red-500); }
.toast-warning { border-left-color: var(--yellow-500); }
.toast-info    { border-left-color: var(--blue-500); }
.toast-icon  { font-size: 17px; line-height: 1; flex-shrink: 0; margin-top: 1px; }
.toast-body  { flex: 1; color: var(--gray-700); line-height: 1.45; }
.toast-close {
  background: none; border: none; cursor: pointer;
  color: var(--gray-400); font-size: 14px; line-height: 1;
  padding: 0; flex-shrink: 0; margin-top: 2px;
}
.toast-close:hover { color: var(--gray-600); }

@media (max-width: 480px) {
  .toast-container { bottom: 72px; right: 12px; left: 12px; }
  .toast { min-width: 0; max-width: 100%; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  .panel-layout { grid-template-columns: 1fr; }
  .exam-content-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  /* Sidebar becomes drawer */
  .sidebar { transform: translateX(-240px); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-xl); }

  /* Header spans full width */
  .header { left: 0; }
  .header-toggle { display: flex; }
  .user-name { display: none; }
  .header-search { max-width: 180px; }

  /* Main no longer offset */
  .main { margin-left: 0; width: 100%; }

  /* Student mobile: add bottom padding so content isn't hidden behind bottom nav */
  .main.has-bottom-nav { padding-bottom: calc(56px + 16px); }

  /* Show bottom nav */
  .bottom-nav { display: flex; }

  /* Auth: hide decorative left panel */
  .auth-left { display: none; }
  .auth-right { padding: 24px; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .page-header { flex-direction: column; align-items: stretch; }

  /* ── Touch targets ≥ 44px ───────────────────────────────── */
  .btn       { min-height: 44px; }
  .btn-lg,
  .btn-xl    { min-height: 44px; }
  .icon-btn  { width: 44px; height: 44px; }
  .modal-close { width: 44px; height: 44px; }
  .input, .select { height: 44px; }
  .textarea  { min-height: 44px; }
  .sidebar-item  { min-height: 44px; }
  .tab           { min-height: 44px; padding: 0 16px; display: inline-flex; align-items: center; }
  .dropdown-item { min-height: 44px; }
  .bottom-nav-item { min-height: 44px; }
  /* Checkbox/radio tap area via parent padding */
  .check-item,
  .radio-item { padding: 10px 0; }

  /* Prevent dropdown from overflowing viewport edge */
  .dropdown-menu { max-width: calc(100vw - 24px); }
}

.guest-theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 260;
  border: 1px solid var(--gray-200);
  background: var(--surface);
}
html[data-theme='dark'] .guest-theme-toggle {
  background: var(--gray-100);
  border-color: var(--gray-300);
}

html[data-theme='dark'] .sidebar,
html[data-theme='dark'] .header,
html[data-theme='dark'] .bottom-nav,
html[data-theme='dark'] .exam-topbar,
html[data-theme='dark'] .auth-right,
html[data-theme='dark'] .auth-card,
html[data-theme='dark'] .card,
html[data-theme='dark'] .stat-card,
html[data-theme='dark'] .course-card,
html[data-theme='dark'] .table-wrap,
html[data-theme='dark'] .modal,
html[data-theme='dark'] .dropdown-menu,
html[data-theme='dark'] .skel-card,
html[data-theme='dark'] .toast,
html[data-theme='dark'] .table-toolbar,
html[data-theme='dark'] th,
html[data-theme='dark'] .auth-card {
  background: var(--gray-100);
  border-color: var(--gray-300);
}

html[data-theme='dark'] .btn-secondary {
  background: var(--gray-100);
  border-color: var(--gray-300);
  color: var(--gray-700);
}

html[data-theme='dark'] .sidebar-item:hover,
html[data-theme='dark'] .sidebar-user:hover,
html[data-theme='dark'] .header-toggle:hover,
html[data-theme='dark'] .icon-btn:hover,
html[data-theme='dark'] .user-pill:hover,
html[data-theme='dark'] .dropdown-item:hover,
html[data-theme='dark'] .btn-secondary:hover,
html[data-theme='dark'] .btn-ghost:hover,
html[data-theme='dark'] tbody tr:hover td,
html[data-theme='dark'] .modal-close:hover,
html[data-theme='dark'] .exam-back-btn:hover {
  background: var(--gray-200);
}

html[data-theme='dark'] .header-search input,
html[data-theme='dark'] .input,
html[data-theme='dark'] .select,
html[data-theme='dark'] .textarea,
html[data-theme='dark'] .pill-tab,
html[data-theme='dark'] .tag {
  background: var(--gray-200);
  border-color: var(--gray-300);
  color: var(--gray-700);
}

html[data-theme='dark'] .header-search input:focus,
html[data-theme='dark'] .input:focus,
html[data-theme='dark'] .select:focus,
html[data-theme='dark'] .textarea:focus {
  background: var(--gray-100);
}

html[data-theme='dark'] .modal-close,
html[data-theme='dark'] .dropdown-item,
html[data-theme='dark'] .user-name,
html[data-theme='dark'] td,
html[data-theme='dark'] .toast-body,
html[data-theme='dark'] .course-meta,
html[data-theme='dark'] .page-subtitle,
html[data-theme='dark'] .sidebar-user-role,
html[data-theme='dark'] .header-search-icon,
html[data-theme='dark'] .header-search input::placeholder,
html[data-theme='dark'] .input::placeholder {
  color: var(--gray-500);
}

html[data-theme='dark'] .auth-left {
  background: linear-gradient(135deg, #1E293B, #0F172A);
}

@media (max-width: 480px) {
  .main { padding: 16px; }
  .auth-card { padding: 28px 24px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  /* Hide search bar — too cramped; replaced by dedicated search page */
  .header-search { display: none; }
  /* Full-bleed table on narrow screens */
  .table-wrap { border-left: none; border-right: none; border-radius: 0; margin: 0 -16px; }
}

/* 320px — very narrow (iPhone SE 1st gen, small Android) */
@media (max-width: 359px) {
  .main { padding: 12px; }
  .auth-card { padding: 24px 16px; }
  .stat-grid { grid-template-columns: 1fr; }
  .modal { border-radius: var(--radius-lg); }
  .modal-body, .modal-header, .modal-footer { padding-left: 16px; padding-right: 16px; }
}

/* ============================================================
   C6 — RESPONSIVE QA NOTES
   Breakpoints verified in code: 320px / 375px / 480px / 768px / 1024px / 1440px+
   No horizontal scroll: overflow-x hidden on html+body; table-wrap scrollable
   Touch targets ≥ 44px: btn, icon-btn, modal-close, input, select, sidebar-item, tab, dropdown-item
   Cross-browser: -webkit-tap-highlight-color, -webkit-backdrop-filter, -webkit-animation,
     -moz-osx-font-smoothing, iOS zoom prevention (font-size ≥ 16px on inputs)
   Manual verification required: Chrome 120+, Firefox 120+, Safari 17+ (iOS 17)
   ============================================================ */
