/* ============================================================
   Study Mate Design System — Premium Educational OS
   Color tokens, typography, layout, components
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ─── CSS Variables ───────────────────────────────────────── */
:root {
  /* Backgrounds — faint blue-slate ramp (reads intentional, not flat black) */
  --bg-base:    #0A0B0E;
  --bg-1:       #101218;
  --bg-2:       #161920;
  --bg-3:       #1D212A;
  --bg-4:       #242934;
  --bg-hover:   rgba(255,255,255,0.035);
  --bg-active:  rgba(255,255,255,0.06);

  /* Text */
  --text-primary:   #F4F5F7;
  --text-secondary: #C4C8D0;
  --text-muted:     #8B909B;
  --text-faint:     #565B66;

  /* Accent — restrained cool indigo (Linear/Arc feel, not saturated purple) */
  --accent:       #5B7CFA;
  --accent-2:     #7C9CFF;
  --accent-3:     #56C3F0;
  --accent-hover: #6E8BFF;
  --accent-rgb:   91,124,250;
  --accent-glow:  rgba(91,124,250,0.14);

  /* Semantic */
  --success:  #34C77B;
  --warning:  #E8A33D;
  --danger:   #F0616D;
  --info:     #56C3F0;

  /* Borders */
  --border:       rgba(255,255,255,0.07);
  --border-hover: rgba(255,255,255,0.13);
  --border-focus: rgba(91,124,250,0.55);

  /* Shadows — soft, low-glow (premium = shadows you don't notice) */
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.35);
  --shadow-md:  0 4px 14px rgba(0,0,0,0.4);
  --shadow-lg:  0 12px 34px rgba(0,0,0,0.48);
  --shadow-xl:  0 24px 64px rgba(0,0,0,0.55);
  --glow:       0 0 0 1px rgba(91,124,250,0.14);

  /* Layout */
  --sidebar-width:  240px;
  --topbar-height:  0px;
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  20px;

  /* Spacing scale (8px base) */
  --space-1:   4px;
  --space-2:   8px;
  --space-3:   12px;
  --space-4:   16px;
  --space-5:   20px;
  --space-6:   24px;
  --space-8:   32px;
  --space-10:  40px;
  --space-12:  48px;

  /* Font-size scale */
  --fs-xs:     11px;
  --fs-sm:     12px;
  --fs-13:     13px;
  --fs-base:   14px;
  --fs-15:     15px;
  --fs-md:     16px;
  --fs-lg:     18px;
  --fs-xl:     22px;
  --fs-2xl:    28px;
  --fs-3xl:    34px;
  --lh-tight:    1.2;
  --lh-normal:   1.5;
  --lh-relaxed:  1.65;
  --tracking-tight: -0.02em;
  --tracking-wide:   0.06em;

  /* Motion — easing + durations (the 120fps feel lives here) */
  --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast:  120ms;
  --dur:       180ms;
  --dur-slow:  320ms;
  --transition:      var(--dur) var(--ease-out);
  --transition-slow: var(--dur-slow) var(--ease-out);

  /* Z-index scale */
  --z-nav:      100;
  --z-drawer:   900;
  --z-overlay:  1000;
  --z-cmd:      1200;
  --z-toast:    2000;

  /* Fonts */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
}

/* Light mode override — warm-neutral, crisp hairlines (Notion/Apple feel) */
[data-theme="light"] {
  --bg-base:    #FFFFFF;
  --bg-1:       #FBFBFC;
  --bg-2:       #F5F6F8;
  --bg-3:       #EEEFF3;
  --bg-4:       #E4E6EC;
  --bg-hover:   rgba(15,20,35,0.035);
  --bg-active:  rgba(15,20,35,0.06);
  --text-primary:   #14161C;
  --text-secondary: #3A3F4B;
  --text-muted:     #676D7A;
  --text-faint:     #A0A5B0;
  --accent:       #4361EE;
  --accent-2:     #5B7CFA;
  --accent-3:     #2AA5D8;
  --accent-hover: #3B5BDB;
  --accent-rgb:   67,97,238;
  --accent-glow:    rgba(67,97,238,0.10);
  --border:         rgba(15,20,35,0.09);
  --border-hover:   rgba(15,20,35,0.16);
  --border-focus:   rgba(67,97,238,0.5);
  --shadow-sm:  0 1px 2px rgba(15,20,35,0.06);
  --shadow-md:  0 4px 14px rgba(15,20,35,0.09);
  --shadow-lg:  0 12px 34px rgba(15,20,35,0.12);
  --shadow-xl:  0 24px 64px rgba(15,20,35,0.16);
  --glow:       0 0 0 1px rgba(67,97,238,0.12);
}

/* ─── Reset ───────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ─── Focus: keyboard-only rings (premium = no mouse-click outlines) ── */
:focus { outline: none; }
:focus-visible,
[tabindex]:focus-visible,
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.nav-item:focus-visible,
.cmd-item:focus-visible,
.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ─── Reduced motion: neutralize animation for those who ask ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

html { height: 100%; scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background-color: var(--bg-base);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden;
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11"; /* Inter's refined glyphs */
  transition: background-color var(--transition), color var(--transition);
}

/* ─── App Shell ───────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  height: 100dvh; /* dynamic viewport: excludes mobile URL bar so nothing gets clipped */
  width: 100vw;
  overflow: hidden;
}

/* ─── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition), min-width var(--transition);
  z-index: var(--z-nav);
}

.sidebar.collapsed {
  width: 64px;
  min-width: 64px;
}

/* Collapsed = icon-only rail: hide every text label cleanly instead of
   letting it get clipped mid-word. */
.sidebar.collapsed .logo-text,
.sidebar.collapsed .logo-badge,
.sidebar.collapsed .nav-group-label,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .streak-label,
.sidebar.collapsed .streak-value,
.sidebar.collapsed .sidebar-profile-info,
.sidebar.collapsed .sidebar-profile-chevron {
  display: none;
}

.sidebar.collapsed .sidebar-logo,
.sidebar.collapsed .nav-item,
.sidebar.collapsed .sidebar-streak,
.sidebar.collapsed .sidebar-profile {
  justify-content: center;
  gap: 0;
  padding-left: 0;
  padding-right: 0;
}

.sidebar.collapsed .nav-group {
  position: relative;
}
/* thin divider between groups so the rail still reads as grouped */
.sidebar.collapsed .nav-group + .nav-group::before {
  content: "";
  display: block;
  height: 1px;
  background: var(--border);
  margin: 4px 14px 6px;
}

/* Logo */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

.logo-mark {
  width: 28px;
  height: 28px;
  min-width: 28px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  color: white;
  letter-spacing: -0.5px;
  box-shadow: 0 2px 8px rgba(var(--accent-rgb),0.4);
}

.logo-text {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.3px;
  color: var(--text-primary);
  white-space: nowrap;
}

.logo-badge {
  font-size: 9px;
  font-weight: 600;
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid rgba(var(--accent-rgb),0.3);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: auto;
  white-space: nowrap;
}

/* Nav groups */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
  scrollbar-width: none;
}
.sidebar-nav::-webkit-scrollbar { display: none; }

.nav-group {
  margin-bottom: 4px;
}

.nav-group-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 8px 16px 4px;
  white-space: nowrap;
  overflow: hidden;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin: 1px 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition), transform var(--transition), opacity var(--transition);
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-decoration: none;
  border: 1px solid transparent;
  user-select: none;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.nav-item.active {
  position: relative;
  background: var(--accent-glow);
  color: var(--text-primary);
  font-weight: 600;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.nav-item.active .nav-icon {
  opacity: 1;
  color: var(--accent);
}

.nav-icon {
  width: 18px;
  height: 18px;
  min-width: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  font-size: 16px;
}

.nav-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-badge {
  font-size: 10px;
  font-weight: 700;
  background: var(--accent);
  color: white;
  border-radius: 10px;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-streak {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: rgba(251,191,36,0.08);
  border: 1px solid rgba(251,191,36,0.15);
  white-space: nowrap;
  overflow: hidden;
}

.streak-icon { font-size: 16px; }
.streak-label { font-size: 12px; color: var(--text-muted); }
.streak-value { font-size: 13px; font-weight: 700; color: #F59E0B; margin-left: auto; }

/* AI credits meter in the sidebar footer */
.sidebar-credits {
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: var(--accent-glow);
  border: 1px solid rgba(var(--accent-rgb), 0.2);
}
.credits-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.credits-icon { font-size: 12px; color: var(--accent); }
.credits-label { font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.04em; }
.credits-remaining { font-size: 11px; color: var(--text-muted); margin-left: auto; white-space: nowrap; }
.credits-bar { height: 4px; border-radius: 999px; background: var(--bg-3); overflow: hidden; }
.credits-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width var(--transition-slow);
}
.credits-fill.warning { background: var(--warning); }
.credits-fill.danger { background: var(--danger); }

/* Profile card in the sidebar footer */
.sidebar-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition);
  overflow: hidden;
}
.sidebar-profile:hover {
  background: var(--bg-hover);
  border-color: var(--border);
}
.sidebar-profile-avatar {
  width: 30px;
  height: 30px;
  min-width: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: white;
  overflow: hidden;
}
.sidebar-profile-info { flex: 1; overflow: hidden; }
.sidebar-profile-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-profile-email {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-profile-chevron {
  font-size: 18px;
  color: var(--text-faint);
  line-height: 1;
}

/* ─── Main Content ────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-5);
  height: 54px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-1) 82%, transparent);
  backdrop-filter: blur(12px) saturate(1.1);
  -webkit-backdrop-filter: blur(12px) saturate(1.1);
  z-index: var(--z-nav);
}

.topbar-title {
  font-size: var(--fs-base);
  font-weight: 600;
  letter-spacing: var(--tracking-tight);
  color: var(--text-primary);
  flex: 1;
}

.topbar-search-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 7px var(--space-3);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition), background-color var(--transition);
  font-size: var(--fs-13);
  color: var(--text-muted);
  min-width: 240px;
}

.topbar-search-trigger:hover {
  border-color: var(--border-hover);
  background: var(--bg-3);
  color: var(--text-secondary);
}

.search-kbd {
  margin-left: auto;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition), transform var(--transition), opacity var(--transition);
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ─── Page / Panel system ─────────────────────────────────── */
.panel-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.panel {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.panel.active {
  display: flex;
  animation: panelIn var(--dur-slow) var(--ease-out);
}

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

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-8) var(--space-8);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.panel-body::-webkit-scrollbar { width: 5px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* Panel header */
.panel-header {
  padding: 0 0 var(--space-8);
}

.panel-title {
  font-size: var(--fs-2xl);
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
  line-height: var(--lh-tight);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.panel-subtitle {
  font-size: var(--fs-13);
  color: var(--text-muted);
  line-height: var(--lh-normal);
}

/* ─── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.card:hover {
  border-color: var(--border-hover);
}

.card-sm {
  padding: 14px 16px;
  border-radius: var(--radius-md);
}

.card-glass {
  background: color-mix(in srgb, var(--bg-2) 70%, transparent);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border: 1px solid var(--border);
}

/* ─── Stat cards ──────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  transition: border-color var(--transition);
}

.stat-card:hover { border-color: var(--border-hover); }

.stat-icon {
  font-size: 22px;
  margin-bottom: 10px;
  display: block;
}

.stat-value {
  font-size: var(--fs-2xl);
  font-weight: 800;
  letter-spacing: var(--tracking-tight);
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: var(--space-1);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-change {
  font-size: 11px;
  font-weight: 600;
  margin-top: 6px;
}

.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* ─── Grid layouts ────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }

/* ─── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--fs-13);
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition), transform var(--transition), opacity var(--transition);
  font-family: var(--font-sans);
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 2px 14px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-3);
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--bg-4);
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-danger {
  background: rgba(239,68,68,0.1);
  color: var(--danger);
  border-color: rgba(239,68,68,0.2);
}
.btn-danger:hover {
  background: rgba(239,68,68,0.2);
}

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ─── Inputs ──────────────────────────────────────────────── */
.input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 13px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color var(--transition);
}

.input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input::placeholder { color: var(--text-faint); }

.input-group {
  display: flex;
  gap: 8px;
}

.input-group .input { flex: 1; }

textarea.input {
  resize: vertical;
  min-height: 80px;
}

.select {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 13px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

/* ─── Tags / Badges ───────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-accent { background: var(--accent-glow); color: var(--accent); border: 1px solid rgba(var(--accent-rgb),0.3); }
.badge-success { background: rgba(34,197,94,0.1); color: var(--success); border: 1px solid rgba(34,197,94,0.2); }
.badge-warning { background: rgba(245,158,11,0.1); color: var(--warning); border: 1px solid rgba(245,158,11,0.2); }
.badge-danger  { background: rgba(239,68,68,0.1);  color: var(--danger);  border: 1px solid rgba(239,68,68,0.2); }
.badge-info    { background: rgba(62,166,255,0.1);  color: var(--info);    border: 1px solid rgba(62,166,255,0.2); }
.badge-muted   { background: var(--bg-3); color: var(--text-muted); border: 1px solid var(--border); }

/* ─── Chat Interface ──────────────────────────────────────── */
.chat-shell {
  display: flex;
  height: 100%;
  overflow: hidden;
}

/* Conversation history rail */
.chat-history {
  width: 260px;
  min-width: 260px;
  border-right: 1px solid var(--border);
  background: var(--bg-1);
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  gap: 6px;
  overflow: hidden;
  transition: width var(--transition), min-width var(--transition), padding var(--transition);
}
.chat-history-top {
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-history-collapse {
  width: 34px;
  min-width: 34px;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-muted);
  font-size: 15px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.chat-history-collapse:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Collapsed rail: fully hidden, its content removed from flow. The floating
   "☰ Chats" toggle in the chat area brings it back. */
.chat-shell.history-collapsed .chat-history {
  width: 0;
  min-width: 0;
  padding-left: 0;
  padding-right: 0;
  border-right: none;
  overflow: hidden;
}
.chat-shell.history-collapsed .chat-history > * { display: none; }
.chat-shell.history-collapsed .chat-history-toggle { display: inline-flex; }
.chat-new-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-primary);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.chat-new-btn:hover { background: var(--bg-hover); border-color: var(--border-focus); }

.chat-history-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 10px 8px 4px;
}
.chat-history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.chat-history-list::-webkit-scrollbar { width: 4px; }
.chat-history-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.chat-history-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: 12px 8px;
  text-align: center;
}

.chat-conv {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-secondary);
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition);
}
.chat-conv:hover { background: var(--bg-hover); }
.chat-conv.active {
  background: var(--accent-glow);
  border-color: rgba(var(--accent-rgb),0.25);
  color: var(--text-primary);
}
.chat-conv-title {
  flex: 1;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-conv-actions {
  display: none;
  gap: 2px;
}
.chat-conv:hover .chat-conv-actions,
.chat-conv.active .chat-conv-actions { display: flex; }
.chat-conv-btn {
  width: 22px;
  height: 22px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
}
.chat-conv-btn:hover { background: var(--border); color: var(--text-primary); }
.chat-conv-btn.danger:hover { background: rgba(239,68,68,0.15); color: var(--danger, #ef4444); }

.chat-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* Floating button to reveal the conversation rail (when collapsed on desktop,
   or as a drawer trigger on mobile). */
.chat-history-toggle {
  display: none;
  align-self: flex-start;
  margin: 8px 0 0 12px;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.chat-history-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Chat topbar: mobile "Chats" toggle (left) + course focus switcher (right) */
.chat-topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 8px 16px 0;
}
.chat-topbar .chat-history-toggle { margin: 0; }
.chat-focus {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}
.chat-focus-label {
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--text-faint);
}
.chat-focus-select {
  font-size: var(--fs-sm);
  padding: 5px 10px;
  max-width: 220px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* ChatGPT-style: each message occupies a centered reading column, no avatars. */
.msg-row {
  display: flex;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  animation: msgIn 0.2s ease;
}

/* Assistant answers span the column as plain text; user prompts sit right. */
.msg-row.user { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }

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

.msg-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.msg-row.assistant .msg-content { width: 100%; }
.msg-row.user .msg-content { max-width: 85%; }

.msg-bubble {
  padding: 4px 2px;
  line-height: 1.7;
  font-size: 15px;
}

/* User prompt keeps a subtle accent bubble aligned to the right. */
.msg-row.user .msg-bubble {
  background: var(--accent);
  color: white;
  padding: 11px 15px;
  border-radius: var(--radius-lg);
  border-bottom-right-radius: 4px;
}

/* Assistant is plain, borderless, full-width prose (like ChatGPT). */
.msg-row.assistant .msg-bubble {
  background: none;
  border: none;
  color: var(--text-primary);
  padding: 4px 2px;
}

/* Markdown in chat */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
  margin: 12px 0 6px;
  font-weight: 700;
}
.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { padding-left: 18px; margin-bottom: 8px; }
.msg-bubble li { margin-bottom: 3px; }
.msg-bubble code {
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.msg-bubble pre {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  overflow-x: auto;
  margin: 10px 0;
}
.msg-bubble pre code { background: none; padding: 0; }
.msg-bubble strong { font-weight: 700; }

/* GFM tables (comparison answers) */
.md-table-wrap {
  overflow-x: auto;
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.md-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
.md-table th, .md-table td {
  border: 1px solid var(--border);
  padding: 7px 11px;
  text-align: left;
  vertical-align: top;
}
.md-table thead th {
  background: var(--bg-2);
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}
.md-table tbody tr:nth-child(even) { background: rgba(255,255,255,0.02); }

/* Typewriter caret shown while an assistant reply is being revealed */
.msg-bubble.typing-caret::after {
  content: '▋';
  display: inline-block;
  margin-left: 1px;
  color: var(--accent);
  animation: caretBlink 1s steps(1) infinite;
}
@keyframes caretBlink { 50% { opacity: 0; } }

/* Message actions (TTS speaker button) */
.msg-actions {
  display: flex;
  gap: 8px;
  margin-top: 2px;
}
.tts-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text-muted);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.tts-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}
.tts-btn.playing {
  color: var(--accent);
  border-color: var(--accent);
}
.tts-btn.loading {
  opacity: .7;
  cursor: default;
}
.tts-btn .tts-icon { font-size: 13px; line-height: 1; }

/* 👍/👎 answer-quality feedback buttons */
.fb-btn {
  border: 1px solid transparent;
  background: none;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 13px;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity var(--transition), background-color var(--transition), border-color var(--transition);
}
.fb-btn:hover { opacity: 1; background: var(--bg-2); }
.fb-btn.active { opacity: 1; }
.fb-btn.fb-up.active { background: rgba(52,199,123,0.14); border-color: rgba(52,199,123,0.4); }
.fb-btn.fb-down.active { background: rgba(240,97,109,0.14); border-color: rgba(240,97,109,0.4); }

/* ─── "Teach me until I understand" — understanding check ─────── */
.understand-check {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-3);
  padding: 10px var(--space-4);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  animation: ucIn var(--dur-slow) var(--ease-out);
}
@keyframes ucIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.uc-prompt {
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--text-secondary);
}
.uc-chips { display: inline-flex; gap: var(--space-2); flex-wrap: wrap; }
.uc-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  font-size: var(--fs-sm);
  font-weight: 600;
  font-family: inherit;
  color: var(--text-secondary);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
}
.uc-chip:hover { transform: translateY(-1px); border-color: var(--border-hover); color: var(--text-primary); }
.uc-chip:active { transform: scale(0.97); }
.uc-chip.uc-yes:hover  { border-color: var(--success); color: var(--success); }
.uc-chip.uc-kind:hover { border-color: var(--warning); color: var(--warning); }
.uc-chip.uc-no:hover   { border-color: var(--accent);  color: var(--accent); }
.understand-check.uc-done {
  justify-content: flex-start;
  background: rgba(52,199,123,0.08);
  border-color: rgba(52,199,123,0.25);
}
.uc-locked { font-size: var(--fs-13); font-weight: 600; color: var(--success); }

/* Citation box */
.citation-block {
  background: rgba(62,166,255,0.06);
  border: 1px solid rgba(62,166,255,0.15);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 12px;
}

.citation-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--info);
  margin-bottom: 6px;
}

.citation-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.citation-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--info);
  flex-shrink: 0;
}

/* Figure cards in chat */
.figure-strip {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.fig-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  width: 200px;
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition);
  flex-shrink: 0;
}

.fig-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.fig-card img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  background: var(--bg-3);
  display: block;
}

.fig-card-footer {
  padding: 8px 10px;
}

.fig-card-id {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-mono);
}

.fig-card-caption {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 13px 17px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.2s ease infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* Chat input area */
.chat-input-area {
  padding: 12px 24px 14px;
  background: transparent;
}

.chat-input-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 8px 8px 8px 8px;
  transition: border-color var(--transition), box-shadow var(--transition);
  max-width: 720px;
  margin: 0 auto;
  box-shadow: 0 2px 14px rgba(0,0,0,0.18);
}

.chat-input-box:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow), 0 2px 14px rgba(0,0,0,0.22);
}

/* "+" attachments/tools button (ChatGPT-style) */
.chat-add-btn {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 50%;
  border: none;
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-size: 22px;
  line-height: 1;
  font-weight: 400;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
  padding-bottom: 2px;
}
.chat-add-btn:hover { background: var(--border); color: var(--text-primary); }
.chat-add-btn.active { background: var(--accent-glow); color: var(--accent); }

.chat-textarea {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font-sans);
  outline: none;
  resize: none;
  max-height: 160px;
  min-height: 24px;
  line-height: 1.5;
  padding: 5px 4px;
}

.chat-textarea::placeholder { color: var(--text-faint); }

.chat-send-btn {
  width: 34px;
  height: 34px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), box-shadow var(--transition), opacity var(--transition);
  flex-shrink: 0;
}

.chat-send-btn:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 12px rgba(var(--accent-rgb),0.4);
}

.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-input-foot {
  max-width: 720px;
  margin: 8px auto 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-faint);
}

.chat-hints {
  display: flex;
  gap: 8px;
  margin: 0 auto 10px;
  max-width: 760px;
  flex-wrap: wrap;
}

.chat-hint-chip {
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  background: var(--bg-1);
  transition: background-color var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition), transform var(--transition), opacity var(--transition);
}

.chat-hint-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

/* ─── Curriculum Explorer ─────────────────────────────────── */
.explorer-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
}

.explorer-tree {
  width: 300px;
  min-width: 300px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.explorer-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
}

.tree-book {
  margin-bottom: 16px;
}

.tree-book-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: background var(--transition);
}

.tree-book-header:hover { background: var(--bg-hover); }

.tree-chapter {
  margin: 2px 0 2px 8px;
}

.tree-chapter-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  transition: background-color var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition), transform var(--transition), opacity var(--transition);
}

.tree-chapter-header:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.tree-chapter-header.active {
  background: var(--accent-glow);
  color: var(--text-primary);
  border: 1px solid rgba(var(--accent-rgb),0.2);
}

.tree-arrow {
  font-size: 10px;
  transition: transform var(--transition);
  color: var(--text-faint);
}

.tree-chapter.open .tree-arrow { transform: rotate(90deg); }

.tree-sections { display: none; margin-left: 16px; }
.tree-chapter.open .tree-sections { display: block; }

.tree-section {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-faint);
  transition: background-color var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition), transform var(--transition), opacity var(--transition);
}

.tree-section:hover {
  background: var(--bg-hover);
  color: var(--text-muted);
}

.tree-section.active {
  color: var(--accent);
  font-weight: 500;
}

.tree-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}

.tree-section.active .tree-dot { background: var(--accent); }

/* ─── Visual Atlas / Figure Grid ──────────────────────────── */
.atlas-filters {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.figure-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.atlas-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition), transform var(--transition), opacity var(--transition);
}

.atlas-card:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.atlas-card img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  background: var(--bg-3);
  display: block;
}

.atlas-card-body {
  padding: 12px 14px;
}

.atlas-card-id {
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}

.atlas-card-caption {
  font-size: 12px;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.atlas-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

/* ─── Flashcards ──────────────────────────────────────────── */
.flashcard-deck {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.flashcard {
  perspective: 1000px;
  height: 170px;
  cursor: pointer;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform var(--dur-slow) var(--ease-out);
  will-change: transform;
}

.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }

.flashcard-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  text-align: center;
}

.flashcard-front {
  background: var(--bg-2);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
}

.flashcard-back {
  background: linear-gradient(135deg, rgba(var(--accent-rgb),0.12), rgba(var(--accent-rgb),0.08));
  border-color: rgba(var(--accent-rgb),0.2);
  color: var(--accent);
  transform: rotateY(180deg);
  font-size: 13px;
  line-height: 1.55;
}

.flashcard-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
  opacity: 0.5;
  margin-bottom: 8px;
}

/* ─── Quiz / MCQ ──────────────────────────────────────────── */
.quiz-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
}

.quiz-q-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.quiz-question {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 18px;
  line-height: 1.5;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.quiz-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-1);
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition), transform var(--transition), opacity var(--transition);
  font-size: 14px;
  color: var(--text-secondary);
  text-align: left;
}

.quiz-option:hover:not([disabled]) {
  border-color: var(--border-hover);
  background: var(--bg-hover);
  color: var(--text-primary);
}

.quiz-option.correct {
  background: rgba(34,197,94,0.08);
  border-color: rgba(34,197,94,0.3);
  color: var(--success);
}

.quiz-option.wrong {
  background: rgba(239,68,68,0.08);
  border-color: rgba(239,68,68,0.3);
  color: var(--danger);
}

.quiz-option-key {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  background: var(--bg-2);
}

.quiz-explanation {
  margin-top: 14px;
  padding: 12px 16px;
  background: rgba(var(--accent-rgb),0.06);
  border: 1px solid rgba(var(--accent-rgb),0.15);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.55;
  display: none;
}

.quiz-score-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
}

/* ─── Notes ───────────────────────────────────────────────── */
.notes-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
}

.notes-list {
  width: 280px;
  min-width: 280px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.notes-list-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.note-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}

.note-item:hover { background: var(--bg-hover); }
.note-item.active { background: var(--accent-glow); }

.note-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-item-preview {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-item-meta {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 4px;
}

.notes-editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.notes-editor-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.notes-editor-body {
  flex: 1;
  padding: 20px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.note-title-input {
  font-size: 20px;
  font-weight: 700;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  outline: none;
  width: 100%;
  letter-spacing: -0.3px;
}

.note-content-input {
  flex: 1;
  font-size: 14px;
  line-height: 1.7;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  outline: none;
  resize: none;
  width: 100%;
}

/* ─── Progress bars ───────────────────────────────────────── */
.progress-bar {
  height: 6px;
  background: var(--bg-3);
  border-radius: 6px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.6s ease;
}

.progress-fill.success { background: linear-gradient(90deg, var(--success), #16a34a); }
.progress-fill.warning { background: linear-gradient(90deg, var(--warning), #d97706); }
.progress-fill.danger  { background: linear-gradient(90deg, var(--danger), #dc2626); }

/* Radial progress */
.radial-progress {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.radial-progress svg { transform: rotate(-90deg); }

.radial-progress .rp-bg { fill: none; stroke: var(--bg-3); }
.radial-progress .rp-fill {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.8s ease;
}

.radial-label {
  position: absolute;
  text-align: center;
}

/* ─── Analytics charts ────────────────────────────────────── */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 100px;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.bar-fill {
  width: 100%;
  background: linear-gradient(to top, var(--accent), var(--accent-2));
  border-radius: 4px 4px 0 0;
  transition: height 0.6s ease;
  min-height: 4px;
}

.bar-label {
  font-size: 10px;
  color: var(--text-faint);
}

/* ─── Study Planner ───────────────────────────────────────── */
.planner-day {
  display: flex;
  gap: 14px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.planner-day:last-child { border-bottom: none; }

.planner-day-num {
  width: 40px;
  min-width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  background: var(--bg-3);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.planner-day-num.high {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: rgba(var(--accent-rgb),0.3);
}

.planner-day-content { flex: 1; }

.planner-day-topics {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.planner-day-activities {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.planner-day-activities li {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.planner-day-activities li::before {
  content: '';
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}

.planner-time-tag {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 10px;
  background: var(--bg-3);
  color: var(--text-faint);
  white-space: nowrap;
  align-self: flex-start;
  margin-top: 4px;
}

/* ─── Study planner form ──────────────────────────────────── */
.plan-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.plan-activities {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.plan-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  transition: border-color var(--transition), background var(--transition);
}
.plan-chip:hover { border-color: var(--border-focus); }
.plan-chip:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--text-primary);
}
.plan-chip input { accent-color: var(--accent); margin: 0; }

/* Plan result summary chips + per-day date */
.planner-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.planner-summary-chip {
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.planner-day-date {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}

/* ─── Lightbox / Modal ────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6,8,12,0.72);
  backdrop-filter: blur(10px) saturate(1.1);
  -webkit-backdrop-filter: blur(10px) saturate(1.1);
  animation: overlayIn var(--dur) var(--ease-out);
}

@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay.hidden { display: none; }

.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  max-width: 90vw;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalIn var(--dur-slow) var(--ease-out);
  will-change: transform, opacity;
}

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

.modal-header {
  display: flex;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  flex: 1;
}

.modal-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition), transform var(--transition), opacity var(--transition);
}

.modal-close:hover { background: var(--bg-4); color: var(--text-primary); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
}

/* Lightbox */
.lightbox-img {
  max-width: 80vw;
  max-height: 75vh;
  object-fit: contain;
  border-radius: var(--radius-lg);
  display: block;
}

/* ─── Command Palette ─────────────────────────────────────── */
.cmd-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-cmd);
  background: rgba(6,8,12,0.6);
  backdrop-filter: blur(8px) saturate(1.1);
  -webkit-backdrop-filter: blur(8px) saturate(1.1);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 16vh;
  animation: overlayIn var(--dur) var(--ease-out);
}

.cmd-overlay.hidden { display: none; }

.cmd-palette {
  width: 620px;
  max-width: 94vw;
  background: color-mix(in srgb, var(--bg-2) 88%, transparent);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: cmdIn var(--dur) var(--ease-out);
  will-change: transform, opacity;
}

@keyframes cmdIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.cmd-input-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.cmd-search-icon { font-size: var(--fs-lg); color: var(--text-muted); }

.cmd-input {
  flex: 1;
  background: none;
  border: none;
  font-size: var(--fs-md);
  color: var(--text-primary);
  outline: none;
  font-family: var(--font-sans);
}

.cmd-input::placeholder { color: var(--text-faint); }

.cmd-results {
  max-height: 380px;
  overflow-y: auto;
  padding: var(--space-2);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.cmd-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition);
}

.cmd-item.selected {
  background: var(--accent-glow);
}
.cmd-item.selected::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.cmd-item:hover { background: var(--bg-hover); }

.cmd-item-icon { font-size: var(--fs-md); width: 24px; text-align: center; color: var(--text-secondary); }
.cmd-item-label { font-size: var(--fs-base); font-weight: 500; flex: 1; }
.cmd-item-sub { font-size: var(--fs-sm); color: var(--text-muted); }
.cmd-item-kbd {
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
}

.cmd-section-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  padding: var(--space-3) var(--space-3) var(--space-1);
}

.cmd-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 16px;
  font-size: 11px;
  color: var(--text-faint);
}

.cmd-footer kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 4px;
}

/* ─── Keyboard shortcuts cheat-sheet ──────────────────────── */
.kbd {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 600;
  min-width: 20px;
  text-align: center;
  color: var(--text-secondary);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  padding: 2px 6px;
}

.shortcut-list { display: flex; flex-direction: column; }
.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}
.shortcut-row:last-child { border-bottom: none; }
.shortcut-desc { font-size: var(--fs-13); color: var(--text-secondary); }
.shortcut-keys { display: inline-flex; align-items: center; gap: 5px; }
.shortcut-then { font-size: var(--fs-xs); color: var(--text-faint); }

/* ─── Settings ────────────────────────────────────────────── */
.settings-section {
  margin-bottom: 28px;
}

.settings-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: 12px;
}

.settings-row {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 2px;
  gap: 14px;
}

.settings-row:first-child { border-radius: var(--radius-md) var(--radius-md) var(--radius-sm) var(--radius-sm); }
.settings-row:last-child  { border-radius: var(--radius-sm) var(--radius-sm) var(--radius-md) var(--radius-md); }
.settings-row:only-child  { border-radius: var(--radius-md); }

.settings-row-icon { font-size: 18px; width: 24px; text-align: center; }
.settings-row-info { flex: 1; }
.settings-row-label { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.settings-row-desc  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Toggle switch */
.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

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

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-4);
  border-radius: 22px;
  cursor: pointer;
  transition: background var(--transition);
  border: 1px solid var(--border);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  top: 2px;
  left: 2px;
  transition: transform var(--transition);
}

.toggle input:checked + .toggle-slider { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ─── Empty states ────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
  gap: 12px;
}

.empty-icon { font-size: 40px; opacity: 0.4; }
.empty-title { font-size: 16px; font-weight: 600; color: var(--text-secondary); }
.empty-desc  { font-size: 13px; color: var(--text-muted); max-width: 300px; line-height: 1.5; }

/* ─── Skeleton loading ────────────────────────────────────── */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--bg-2);
  border-radius: var(--radius-sm);
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg,
    transparent 0%,
    var(--bg-hover) 45%,
    var(--bg-active) 50%,
    var(--bg-hover) 55%,
    transparent 100%);
  animation: shimmer 1.4s var(--ease-in-out) infinite;
  will-change: transform;
}

@keyframes shimmer {
  100% { transform: translateX(100%); }
}

/* Composable skeleton primitives (used by JS skeleton() helper) */
.sk-stack { display: flex; flex-direction: column; gap: var(--space-3); }
.sk-line { height: 12px; border-radius: var(--radius-sm); }
.sk-line.sk-lg { height: 18px; }
.sk-line.w-40 { width: 40%; }
.sk-line.w-60 { width: 60%; }
.sk-line.w-80 { width: 80%; }
.sk-card { height: 96px; border-radius: var(--radius-lg); }
.sk-tile { height: 200px; border-radius: var(--radius-lg); }

/* ─── Dividers ────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* ─── Tooltip ─────────────────────────────────────────────── */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-4);
  color: var(--text-primary);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition);
  border: 1px solid var(--border);
  z-index: 200;
}

[data-tooltip]:hover::after { opacity: 1; }

/* ─── Scrollbar global ────────────────────────────────────── */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

/* ─── Utility classes ─────────────────────────────────────── */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
.loading { opacity: 0.5; pointer-events: none; }

/* ─── Responsive ──────────────────────────────────────────── */

/* Tablet / iPad (portrait & smaller laptops) */
@media (max-width: 1024px) {
  :root { --sidebar-width: 210px; }
  .chat-messages { padding: 18px 18px; }
  .msg-row { max-width: 100%; }
  .chat-input-area { padding: 12px 16px 16px; }
}

@media (max-width: 900px) {
  :root { --sidebar-width: 200px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .explorer-tree { width: 240px; min-width: 240px; }
}

/* Phones & small tablets — sidebar becomes a slide-in drawer */
@media (max-width: 768px) {
  /* Off-canvas sidebar drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100dvh;
    width: 260px;
    min-width: 260px;
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
    padding-top: env(safe-area-inset-top, 0);
  }
  .sidebar.open { transform: translateX(0); }
  /* Ignore the desktop "collapsed" state on mobile */
  .sidebar.collapsed { width: 260px; min-width: 260px; }

  /* Dim backdrop shown when the drawer is open */
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
  }
  .sidebar-backdrop.show { opacity: 1; pointer-events: auto; }

  .main { width: 100%; }

  /* Keep the topbar clear of the notch and give the hamburger room */
  .topbar {
    padding: 0 12px;
    padding-top: env(safe-area-inset-top, 0);
    height: calc(52px + env(safe-area-inset-top, 0px));
    gap: 8px;
  }
  /* The desktop search box is too wide for phones — hide it, keep the ⌘K palette
     reachable via the search icon if needed later */
  .topbar-search-trigger { display: none; }
  .topbar-title { font-size: 13px; }

  .panel-body { padding: 16px; }
  .chat-messages { padding: 14px 12px; gap: 8px; }
  .msg-row.user .msg-content { max-width: 90%; }

  /* Chat history becomes a slide-in drawer over the messages */
  .chat-history {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
  }
  .chat-history.open { transform: translateX(0); }
  .chat-shell { position: relative; }
  .chat-history-toggle { display: flex !important; }

  /* Stack explorer / notes two-pane layouts vertically */
  .explorer-layout, .notes-layout {
    flex-direction: column;
  }
  .explorer-tree, .notes-list {
    width: 100%;
    min-width: 0;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  /* Chat input respects the home-indicator safe area */
  .chat-input-area {
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 640px) {
  .panel-body { padding: 14px; }
  .atlas-filters { flex-wrap: wrap; }
}

/* Prevent iOS from zooming when focusing inputs (font < 16px triggers zoom) */
@media (max-width: 768px) {
  .chat-textarea, .input, .select, .cmd-input {
    font-size: 16px;
  }
}

/* ─── Authentication Overlay (Glassmorphism & Transition) ─── */
.auth-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(8, 10, 14, 0.7);
  backdrop-filter: blur(18px) saturate(1.1);
  -webkit-backdrop-filter: blur(18px) saturate(1.1);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: var(--z-toast);
  transition: opacity var(--transition-slow);
}
.auth-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.auth-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 420px;
  padding: 36px;
  box-shadow: var(--shadow-xl), var(--glow);
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.auth-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.auth-header .logo-mark {
  background: var(--accent);
  color: white;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 20px;
  font-weight: 800;
  box-shadow: var(--glow);
}
.auth-header h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 8px;
}
.auth-header p {
  font-size: 14px;
  color: var(--text-muted);
}
.auth-tabs {
  display: flex;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
}
.auth-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background-color var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition), transform var(--transition), opacity var(--transition);
}
.auth-tab.active {
  background: var(--bg-3);
  color: var(--text-primary);
}

/* Sign in with Google */
.google-signin-wrap {
  margin-top: var(--space-4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}
.google-signin-btn {
  display: flex;
  justify-content: center;
  min-height: 40px;
  width: 100%;
}
.auth-divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  color: var(--text-faint);
  font-size: var(--fs-sm);
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Onboarding — pick your year */
.onboarding-years {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin: var(--space-2) 0 var(--space-5);
}
.onboarding-year-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px var(--space-4);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-size: var(--fs-15);
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition), transform var(--transition);
}
.onboarding-year-opt:hover { border-color: var(--border-hover); transform: translateY(-1px); }
.onboarding-year-opt.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.onboarding-year-opt .oy-check {
  opacity: 0;
  color: var(--accent);
  font-weight: 800;
  transition: opacity var(--transition);
}
.onboarding-year-opt.selected .oy-check { opacity: 1; }

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.auth-form.hidden {
  display: none;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-group input {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: var(--text-primary);
  font-size: 14px;
  transition: border var(--transition);
}
.form-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.auth-error-message {
  font-size: 13px;
  color: var(--danger);
  min-height: 18px;
}
.auth-info-message {
  font-size: 13px;
  color: var(--success);
  min-height: 0;
  line-height: 1.5;
}
.auth-link {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
}
.auth-link:hover { text-decoration: underline; }
.auth-submit-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition);
}
.auth-submit-btn:hover {
  background: var(--accent-hover);
}

/* ─── Topbar avatar button ─────────────────────────────────────── */
.topbar-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
  border: none;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
}
.topbar-avatar:hover {
  transform: scale(1.06);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ─── Profile modal ────────────────────────────────────────────── */
.profile-card {
  position: relative;
  max-width: 460px;
  gap: 20px;
}
.profile-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--bg-hover);
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.profile-close:hover { background: var(--border); color: var(--text-primary); }

.profile-hero {
  display: flex;
  align-items: center;
  gap: 16px;
}
.profile-hero-avatar {
  width: 56px;
  height: 56px;
  min-width: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: white;
  box-shadow: 0 4px 14px rgba(var(--accent-rgb),0.4);
}
.profile-hero-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}
.profile-hero-email {
  font-size: 13px;
  color: var(--text-muted);
}

.profile-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.avatar-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.avatar-opt {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-2);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: border-color var(--transition), transform var(--transition);
}
.avatar-opt:hover { transform: translateY(-2px); }
.avatar-opt.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.profile-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  flex-wrap: wrap;
}

/* ─── Transient toast (errors / info) ─────────────────────────── */
.app-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  max-width: 460px;
  width: max-content;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 13.5px;
  line-height: 1.45;
  box-shadow: var(--shadow-lg);
  z-index: var(--z-toast);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
  text-align: center;
}
.app-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.app-toast.error {
  border-color: rgba(239,68,68,0.5);
  background: linear-gradient(180deg, rgba(239,68,68,0.14), var(--bg-2));
}
.app-toast.success { border-color: rgba(34,197,94,0.5); }
