/* ==========================================================================
   SR LEARN X — ACADEMIC INTELLIGENCE & COPILOT STYLESHEET
   Branded with S R Global School Logo Theme: Flame Saffron, Prestige Navy,
   Laurel Emerald, and Globe Royal Blue
   ========================================================================== */

:root {
  /* Core Base Palette */
  --bg-app: #f5f7fc;
  --bg-surface: #ffffff;
  --bg-surface-alt: #f8fafc;
  --bg-sidebar: #060b19; /* Deep Prestige School Navy - matches logo shield */
  --bg-sidebar-panel: rgba(255, 255, 255, 0.05);
  --bg-sidebar-panel-hover: rgba(255, 255, 255, 0.09);
  --border-sidebar: rgba(255, 255, 255, 0.08);

  --ink-primary: #0f172a;
  --ink-secondary: #334155;
  --ink-muted: #64748b;
  --ink-light: #94a3b8;
  --border-light: #e2e8f0;
  --border-subtle: #f1f5f9;

  /* SRGS Emblem Core: Vibrant Saffron / Flame Orange (SR centerpiece & ribbon) */
  --role-primary: #ea580c;
  --role-primary-hover: #c2410c;
  --role-accent: #f59e0b; /* Golden Flame */
  --role-gradient: linear-gradient(135deg, #ea580c 0%, #f97316 50%, #f59e0b 100%);
  --role-glow: rgba(234, 88, 12, 0.22);
  --role-soft-bg: rgba(234, 88, 12, 0.08);
  --role-border-soft: rgba(234, 88, 12, 0.28);

  /* Emblem Secondary Colors */
  --color-globe-blue: #2563eb;
  --color-globe-sky: #38bdf8;
  --color-laurel-green: #16a34a;
  --color-laurel-light: #ecfdf5;

  --user-bubble-bg: #070e20; /* Deep School Navy Bubble */
  --user-bubble-text: #ffffff;

  /* Card and Shadows */
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.09);
  --shadow-xl: 0 20px 40px rgba(15, 23, 42, 0.12);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Outfit', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', Consolas, monospace;
}

/* Teacher Persona Theme Override (Globe Royal Blue & Cyan) */
body[data-role="teacher"] {
  --role-primary: #1d4ed8;
  --role-primary-hover: #1e40af;
  --role-accent: #2563eb;
  --role-gradient: linear-gradient(135deg, #1d4ed8 0%, #2563eb 55%, #38bdf8 100%);
  --role-glow: rgba(29, 78, 216, 0.22);
  --role-soft-bg: rgba(29, 78, 216, 0.08);
  --role-border-soft: rgba(29, 78, 216, 0.28);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--ink-primary);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   LUCIDE ICONS STYLING & UTILITIES
   ========================================================================== */
.lucide {
  stroke-width: 2px;
  stroke: currentColor;
  fill: none;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  transition: stroke 0.15s ease;
}

.lucide-xs { width: 13px; height: 13px; stroke-width: 2.2px; }
.lucide-sm { width: 16px; height: 16px; stroke-width: 2px; }
.lucide-md { width: 18px; height: 18px; stroke-width: 2px; }
.lucide-lg { width: 22px; height: 22px; stroke-width: 2px; }
.lucide-xl { width: 26px; height: 26px; stroke-width: 2px; }

.btn-new-chat svg,
.role-tab svg,
.btn-action-top svg,
.mode-btn svg,
.chip-btn svg,
.msg-btn svg,
.starter-icon svg {
  pointer-events: none;
}

/* ==========================================================================
   APP SHELL LAYOUT
   ========================================================================== */
.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr 340px;
  height: 100vh;
  overflow: hidden;
  position: relative;
  transition: grid-template-columns 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.app-shell.sources-collapsed {
  grid-template-columns: 280px 1fr 0px;
}

.app-shell.sources-collapsed .sources-sidebar {
  opacity: 0;
  pointer-events: none;
  border-left-color: transparent;
}

/* ==========================================================================
   LEFT SIDEBAR: CURRICULUM CONTROLLER & CHAT SESSIONS
   ========================================================================== */
.sidebar {
  background: var(--bg-sidebar);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  height: 100vh;
  border-right: 1px solid var(--border-sidebar);
  position: relative;
  z-index: 20;
}

.sidebar-header {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border-sidebar);
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.brand-logo-container {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: #ffffff;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35), 0 0 0 1.5px rgba(234, 88, 12, 0.4);
  flex-shrink: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.brand-logo-container:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 22px var(--role-glow), 0 0 0 1.5px var(--role-primary);
}

.brand-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.brand-text h1 {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #ffffff;
  line-height: 1.15;
}

.brand-badge {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: rgba(234, 88, 12, 0.16);
  color: #fb923c;
  padding: 3px 8px;
  border-radius: 6px;
  margin-top: 4px;
  border: 1px solid rgba(234, 88, 12, 0.35);
}

body[data-role="teacher"] .brand-badge {
  background: rgba(37, 99, 235, 0.16);
  color: #93c5fd;
  border-color: rgba(37, 99, 235, 0.35);
}

/* New Chat Button */
.btn-new-chat {
  width: 100%;
  height: 42px;
  padding: 0 16px;
  border-radius: 12px;
  background: var(--role-gradient);
  color: #ffffff;
  border: none;
  font-weight: 600;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 4px 16px var(--role-glow), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-new-chat:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
  box-shadow: 0 6px 22px var(--role-glow);
}

/* Sidebar Scrollable Body */
.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Scrollbar Styling */
.sidebar-body::-webkit-scrollbar,
.chat-stream::-webkit-scrollbar,
.sources-content::-webkit-scrollbar {
  width: 6px;
}
.sidebar-body::-webkit-scrollbar-thumb,
.chat-stream::-webkit-scrollbar-thumb,
.sources-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
}
.chat-stream::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.15);
}

/* Curriculum Context Box */
.curriculum-card {
  background: var(--bg-sidebar-panel);
  border: 1px solid var(--border-sidebar);
  border-radius: 14px;
  padding: 14px 16px;
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.card-title-sm {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94a3b8;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-group {
  margin-bottom: 11px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  font-size: 11px;
  color: #cbd5e1;
  margin-bottom: 5px;
  font-weight: 600;
}

.custom-select {
  width: 100%;
  background-color: rgba(10, 18, 38, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #f1f5f9;
  padding: 9px 34px 9px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: all 0.2s ease;
}

.custom-select:hover {
  border-color: rgba(255, 255, 255, 0.22);
  background-color: rgba(15, 25, 52, 0.95);
}

.custom-select:focus {
  border-color: var(--role-primary);
  box-shadow: 0 0 0 2px var(--role-glow);
}

.custom-select option {
  background: #0f172a;
  color: #ffffff;
}

/* Mode Switcher Grid */
.modes-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #cbd5e1;
  border-radius: 10px;
  padding: 10px 10px;
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: all 0.18s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-btn:last-child:nth-child(odd) {
  grid-column: span 2;
}

.mode-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.18);
  transform: translateY(-1px);
}

.mode-btn.active {
  background: var(--role-gradient);
  color: #ffffff;
  font-weight: 700;
  border-color: transparent;
  box-shadow: 0 4px 14px var(--role-glow);
}

/* Chat History List */
.history-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-top: 4px;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
  padding-right: 2px;
  max-height: 240px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  color: #94a3b8;
  font-size: 12.5px;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #f1f5f9;
  border-color: rgba(255, 255, 255, 0.12);
  transform: translateX(2px);
}

.history-item.active {
  background: rgba(234, 88, 12, 0.14);
  color: #ffffff;
  font-weight: 600;
  border-color: rgba(234, 88, 12, 0.35);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

body[data-role="teacher"] .history-item.active {
  background: rgba(29, 78, 216, 0.16);
  border-color: rgba(29, 78, 216, 0.35);
}

.history-item-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.history-icon {
  color: #64748b;
  flex-shrink: 0;
  transition: color 0.15s ease;
}

.history-item:hover .history-icon {
  color: #cbd5e1;
}

.history-item.active .history-icon {
  color: var(--role-primary);
}

.history-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
  font-size: 12.5px;
}

.history-delete-btn {
  background: none;
  border: none;
  color: #64748b;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: all 0.15s;
}

.history-item:hover .history-delete-btn {
  opacity: 1;
}

.history-delete-btn:hover {
  color: #f43f5e;
  background: rgba(244, 63, 94, 0.15);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border-sidebar);
  background: rgba(0, 0, 0, 0.25);
  font-size: 11.5px;
  color: #64748b;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-footer-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  color: #94a3b8;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 8px #22c55e;
  display: inline-block;
}

.btn-icon-subtle {
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: all 0.2s;
}

.btn-icon-subtle:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  transform: rotate(30deg);
}

/* ==========================================================================
   MAIN WORKSPACE AREA
   ========================================================================== */
.main-workspace {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  background: var(--bg-app);
  overflow: hidden;
}

/* Top Navigation Bar */
.topbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
  padding: 12px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Role Segmented Switcher */
.role-switcher {
  display: flex;
  background: #f1f5f9;
  padding: 3px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-light);
}

.role-tab {
  padding: 7px 18px;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-secondary);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  gap: 6px;
}

.role-tab.active {
  background: var(--bg-surface);
  color: var(--role-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

body[data-role="teacher"] .role-tab.active {
  color: var(--role-primary);
}

.curriculum-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff7ed;
  color: #c2410c;
  border: 1px solid #fed7aa;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: var(--radius-full);
}

body[data-role="teacher"] .curriculum-pill {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-action-top {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  background: var(--bg-surface);
  color: var(--ink-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-action-top:hover {
  background: #f8fafc;
  color: var(--ink-primary);
  border-color: #cbd5e1;
}

/* ==========================================================================
   CHAT CONVERSATION STREAM
   ========================================================================== */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px 140px;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
}

/* Welcome Hero Screen */
.welcome-hero {
  max-width: 820px;
  margin: 40px auto;
  text-align: center;
  animation: fadeIn 0.4s ease-out;
}

.hero-logo-badge {
  width: 68px;
  height: 68px;
  border-radius: 20px;
  background: #ffffff;
  padding: 6px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08), 0 0 0 1px rgba(234, 88, 12, 0.15);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.hero-logo-badge:hover {
  transform: scale(1.06) rotate(1deg);
  box-shadow: 0 12px 30px var(--role-glow), 0 0 0 1.5px var(--role-primary);
}

.hero-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.hero-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff7ed;
  color: #ea580c;
  border: 1px solid #fed7aa;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 16px;
  border-radius: var(--radius-full);
  margin-bottom: 16px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

body[data-role="teacher"] .hero-pill {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.welcome-hero h2 {
  font-family: var(--font-display);
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink-primary);
  margin-bottom: 12px;
}

.welcome-hero p {
  font-size: 17px;
  color: var(--ink-secondary);
  max-width: 620px;
  margin: 0 auto 36px;
}

/* Quick Starter Cards */
.starter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  text-align: left;
}

.starter-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.starter-card:hover {
  transform: translateY(-2px);
  border-color: var(--role-primary);
  box-shadow: var(--shadow-md);
}

.starter-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.starter-card h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-primary);
  margin-bottom: 4px;
}

.starter-card p {
  font-size: 12.5px;
  color: var(--ink-muted);
  line-height: 1.4;
  margin: 0;
}

/* Chat Messages */
.message-list {
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.message-wrapper {
  display: flex;
  gap: 14px;
  animation: messageSlideIn 0.25s ease-out forwards;
}

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

/* User Message */
.message-wrapper.user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.message-wrapper.user .message-avatar {
  background: #1e293b;
  color: #ffffff;
}

.message-wrapper.assistant .message-avatar {
  background: #ffffff;
  border: 1.5px solid var(--border-light);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  padding: 4px;
}

.avatar-logo-img {
  width: 26px;
  height: 26px;
  object-fit: contain;
}

.message-bubble {
  max-width: 82%;
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  position: relative;
}

.message-wrapper.user .message-bubble {
  background: var(--user-bubble-bg);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.message-wrapper.assistant .message-bubble {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  color: var(--ink-primary);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
  width: 100%;
}

/* Assistant Message Header Meta (Clean & Minimal) */
.bubble-meta-clean {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.meta-brand-tag {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--role-primary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.meta-verified-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: #15803d;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  padding: 2px 9px;
  border-radius: var(--radius-full);
}

/* Bubble Content Typography & Formatting */
.bubble-content {
  font-size: 15px;
  line-height: 1.68;
  color: var(--ink-primary);
}

.bubble-content h3 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  margin: 14px 0 8px;
  color: var(--ink-primary);
}

.bubble-content h4 {
  font-size: 16px;
  font-weight: 700;
  margin: 14px 0 6px;
  color: var(--ink-secondary);
}

.bubble-content p {
  margin-bottom: 12px;
}

.bubble-content hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 16px 0;
}

.bubble-content ul, .bubble-content ol {
  margin: 8px 0 14px 22px;
}

.bubble-content li {
  margin-bottom: 5px;
}

.bubble-content blockquote {
  border-left: 4px solid var(--role-primary);
  background: #f8fafc;
  padding: 10px 16px;
  margin: 12px 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-style: italic;
  color: var(--ink-secondary);
}

/* Tables inside messages */
.bubble-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 13.5px;
  background: #ffffff;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.bubble-content th, .bubble-content td {
  padding: 10px 14px;
  border: 1px solid var(--border-light);
  text-align: left;
}

.bubble-content th {
  background: #f1f5f9;
  font-weight: 600;
  color: var(--ink-primary);
}

/* Code & Pre */
.bubble-content pre {
  background: #0f172a;
  color: #f8fafc;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 12px 0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}

.bubble-content code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  color: #0f172a;
}

.bubble-content pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

/* KaTeX Math Formatting */
.katex-display {
  margin: 12px 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px 0;
}

/* Interactive Details / Dropdown */
.bubble-content details {
  background: #f8fafc;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin: 10px 0;
  cursor: pointer;
}

.bubble-content summary {
  font-weight: 600;
  color: var(--role-primary);
  outline: none;
}

.bubble-content details[open] {
  background: #f0fdf4;
  border-color: #86efac;
}

/* Key Points Pills */
.key-points-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.key-point-pill {
  font-size: 11.5px;
  font-weight: 500;
  background: #f1f5f9;
  color: var(--ink-secondary);
  padding: 4px 10px;
  border-radius: var(--radius-full);
}

/* Quick Action Suggestion Chips */
.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border-light);
}

.chip-btn {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: var(--radius-full);
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  color: #c2410c;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip-btn:hover {
  background: var(--role-gradient);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 3px 10px var(--role-glow);
}

body[data-role="teacher"] .chip-btn {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1d4ed8;
}

body[data-role="teacher"] .chip-btn:hover {
  background: var(--role-gradient);
  border-color: transparent;
  color: #ffffff;
}

/* Message Actions Toolbar */
.message-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.msg-btn {
  background: transparent;
  border: none;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.msg-btn:hover {
  background: #f1f5f9;
  color: var(--ink-primary);
}

.msg-btn.active {
  color: var(--role-primary);
  background: var(--role-glow);
}

/* Typing / Generating Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  max-width: 480px;
  animation: fadeIn 0.2s ease;
}

.dots {
  display: flex;
  gap: 4px;
}

.dot {
  width: 8px;
  height: 8px;
  background: var(--role-primary);
  border-radius: 50%;
  animation: pulseDot 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes pulseDot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.1); opacity: 1; }
}

.typing-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-secondary);
}

/* ==========================================================================
   FLOATING BOTTOM INPUT AREA
   ========================================================================== */
.input-dock {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 32px 24px;
  background: linear-gradient(180deg, rgba(244, 247, 252, 0) 0%, rgba(244, 247, 252, 0.95) 30%, #f4f7fc 100%);
  z-index: 15;
}

.input-box {
  max-width: 900px;
  margin: 0 auto;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: 10px 16px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-box:focus-within {
  border-color: var(--role-primary);
  box-shadow: 0 12px 35px var(--role-glow);
}

.input-top-indicators {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--ink-muted);
}

.indicator-chip {
  background: #f1f5f9;
  color: var(--ink-secondary);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-weight: 600;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.chat-input {
  flex: 1;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink-primary);
  background: transparent;
  resize: none;
  max-height: 160px;
  min-height: 24px;
  padding: 4px 0;
}

.input-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-voice {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #f1f5f9;
  color: var(--ink-secondary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-voice:hover {
  background: #e2e8f0;
  color: var(--ink-primary);
}

.btn-voice.listening {
  background: #fee2e2;
  color: #ef4444;
  animation: pulseVoice 1.2s infinite;
}

@keyframes pulseVoice {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  70% { transform: scale(1.08); box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.btn-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--role-gradient);
  color: #ffffff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px var(--role-glow);
}

.btn-send:hover {
  transform: scale(1.06);
  filter: brightness(1.1);
}

.btn-send:disabled {
  background: #cbd5e1;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

.input-disclaimer {
  text-align: center;
  font-size: 11.5px;
  color: var(--ink-light);
  margin-top: 8px;
}

/* ==========================================================================
   RIGHT SLIDING DRAWER: VERIFIED CURRICULUM SOURCES
   ========================================================================== */
.sources-drawer {
  position: fixed;
  top: 0;
  right: -380px;
  width: 380px;
  height: 100vh;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-light);
  box-shadow: var(--shadow-xl);
  z-index: 30;
  display: flex;
  flex-direction: column;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sources-drawer.open {
  right: 0;
}

.drawer-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-header h3 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: var(--ink-primary);
}

.drawer-close {
  background: transparent;
  border: none;
  font-size: 20px;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 4px;
}

.sources-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.source-card {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 14px;
  text-decoration: none;
  color: inherit;
  transition: all 0.2s ease;
  background: var(--bg-surface);
  display: block;
}

.source-card:hover {
  border-color: var(--role-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.source-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.source-title {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--ink-primary);
}

.source-trust {
  font-size: 11px;
  font-weight: 700;
  background: #f0fdf4;
  color: #16a34a;
  padding: 2px 7px;
  border-radius: var(--radius-full);
}

.source-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  background: #eff6ff;
  color: #1d4ed8;
  padding: 2px 6px;
  border-radius: 4px;
  margin-bottom: 6px;
}

.source-snippet {
  font-size: 12px;
  color: var(--ink-muted);
  line-height: 1.45;
}

/* ==========================================================================
   SETTINGS MODAL
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 90%;
  max-width: 520px;
  overflow: hidden;
  animation: modalScale 0.25s ease-out;
}

@keyframes modalScale {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
}

.modal-body {
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  outline: none;
}

.modal-input:focus {
  border-color: var(--role-primary);
}

.modal-footer {
  padding: 14px 24px;
  background: #f8fafc;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-secondary {
  padding: 8px 16px;
  background: transparent;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  padding: 8px 18px;
  background: var(--role-gradient);
  border: none;
  border-radius: var(--radius-md);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* ==========================================================================
   RIGHT SIDEBAR: VERIFIED SOURCES & CURRICULUM CITATIONS (MATCHING IMAGE 2)
   ========================================================================== */
.sources-sidebar {
  background: #ffffff;
  border-left: 1px solid var(--border-light);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 15;
  transition: opacity 0.2s ease, border-color 0.2s ease;
  box-shadow: -2px 0 10px rgba(15, 23, 42, 0.02);
}

.sources-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  background: #ffffff;
  flex-shrink: 0;
}

.sources-header-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sources-eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--role-primary);
}

body[data-role="teacher"] .sources-eyebrow {
  color: var(--role-primary);
}

.sources-title-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 2px;
}

.sources-title-row h3 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  color: var(--ink-primary);
  margin: 0;
}

.sources-count-badge {
  font-size: 11px;
  font-weight: 700;
  background: #f1f5f9;
  color: #475569;
  padding: 1px 7px;
  border-radius: var(--radius-full);
}

.sources-subtitle {
  font-size: 11.5px;
  color: var(--ink-muted);
  margin-top: 2px;
}

.sources-close-btn {
  color: var(--ink-muted);
  background: transparent;
  border: none;
  padding: 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.sources-close-btn:hover {
  background: #f1f5f9;
  color: var(--ink-primary);
}

.sources-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
}

/* Custom Scrollbar for Sources List */
.sources-list::-webkit-scrollbar {
  width: 5px;
}
.sources-list::-webkit-scrollbar-track {
  background: #fafafa;
}
.sources-list::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}
.sources-list::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Individual Source Item - Exact Match to User Screenshot Image 2 */
.source-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid #f1f5f9;
  text-decoration: none;
  background: #ffffff;
  transition: background-color 0.15s ease;
  cursor: pointer;
}

.source-item:hover {
  background-color: #f8fafc;
}

.source-item:active {
  background-color: #f1f5f9;
}

.source-item-info {
  flex: 1;
  min-width: 0;
}

.source-item-title {
  font-size: 13.5px;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.35;
  margin-bottom: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
}

.source-item:hover .source-item-title {
  color: var(--role-primary);
}

body[data-role="teacher"] .source-item:hover .source-item-title {
  color: var(--role-primary);
}

.source-item-type {
  font-size: 11.5px;
  color: #64748b;
  font-weight: 400;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Green Trust Score Pill - Exactly as in Image 2 */
.source-item-pill {
  flex-shrink: 0;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #059669;
  font-size: 12.5px;
  font-weight: 700;
  padding: 2.5px 8px;
  border-radius: 6px;
  min-width: 28px;
  text-align: center;
}

.source-item-pill.high {
  background: #ecfdf5;
  border-color: #6ee7b7;
  color: #047857;
}

/* Empty State */
.sources-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 50px 24px;
  color: var(--ink-muted);
}

.sources-empty i, .sources-empty svg {
  margin-bottom: 12px;
  opacity: 0.35;
  color: #0284c7;
}

.sources-empty p {
  font-size: 13px;
  line-height: 1.5;
}

/* ==========================================================================
   PRINT / PDF EXPORT STYLESHEET
   ========================================================================== */
@media print {
  .sidebar, .topbar, .input-dock, .sources-sidebar, .message-actions, .suggestion-chips, .btn-action-top {
    display: none !important;
  }
  .app-shell {
    display: block !important;
    height: auto !important;
  }
  .main-workspace {
    height: auto !important;
    overflow: visible !important;
    background: #ffffff !important;
  }
  .chat-container {
    padding: 0 !important;
    overflow: visible !important;
  }
  .message-wrapper.user {
    display: none !important;
  }
  .message-bubble {
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    max-width: 100% !important;
  }
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 12pt !important;
  }
}

/* ==========================================================================
   RESPONSIVE MEDIA QUERIES
   ========================================================================== */
@media (max-width: 1200px) {
  .app-shell {
    grid-template-columns: 280px 1fr;
  }
  .app-shell.sources-collapsed {
    grid-template-columns: 280px 1fr;
  }
  .sources-sidebar {
    position: fixed;
    right: -360px;
    top: 0;
    bottom: 0;
    width: 340px;
    box-shadow: var(--shadow-xl);
    z-index: 50;
    transition: right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .sources-sidebar.open {
    right: 0;
    opacity: 1;
    pointer-events: auto;
  }
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    left: -280px;
    width: 280px;
    transition: left 0.3s ease;
    z-index: 40;
  }
  .sidebar.open {
    left: 0;
  }
  .chat-container {
    padding: 16px 16px 140px;
  }
  .input-dock {
    padding: 12px 16px 20px;
  }
  .starter-grid {
    grid-template-columns: 1fr;
  }
}

/* Math Fallback & Clean Formula Display */
.math-fallback-block {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px 16px;
  margin: 12px 0;
  color: #0f172a;
  font-size: 14.5px;
  line-height: 1.6;
  text-align: center;
  overflow-x: auto;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.math-fallback-inline {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  background: #f1f5f9;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 13.5px;
  color: #0f172a;
}

.bubble-content .katex-display {
  margin: 14px 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px 0;
}

