/* ============================================================================
   Classroom Chatbot — Design System
   Responsive-first, dark/light theming, custom accent (blue), smooth motion.
   Mirrors the visual language Rishvanth prefers (Horizon-tab / laundry-tracker):
   glassmorphism surfaces, soft shadows, spring-y transitions, and layouts that
   adapt to any screen (mobile / tablet / laptop / desktop).
   ============================================================================ */

:root {
  /* Accent — blue */
  --accent: #1d5fd0;
  --accent-soft: rgba(29, 95, 208, 0.14);
  --accent-hover: #164aa8;

  /* PSU base */
  --psu-blue: #1d417d;

  /* Light theme */
  --bg: #f4f6fb;
  --bg-gradient: radial-gradient(1200px 600px at 15% -10%, rgba(29, 65, 125, 0.12), transparent 60%),
                 radial-gradient(1000px 500px at 110% 10%, rgba(29, 95, 208, 0.08), transparent 55%),
                 var(--bg);
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --surface-3: #e8ebf3;
  --border: rgba(20, 30, 60, 0.10);
  --text: #16213b;
  --text-muted: #5d6785;
  --shadow: 0 10px 34px rgba(22, 33, 59, 0.10);
  --shadow-sm: 0 4px 14px rgba(22, 33, 59, 0.07);
  --user-bubble: var(--psu-blue);
  --user-bubble-text: #ffffff;
  --bot-bubble: #eef1f7;
  --bot-bubble-text: #1c2540;

  /* Radii / motion */
  --r-lg: 22px;
  --r-md: 14px;
  --r-sm: 10px;
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0e1320;
  --bg-gradient: radial-gradient(1200px 600px at 15% -10%, rgba(29, 65, 125, 0.30), transparent 60%),
                 radial-gradient(1000px 500px at 110% 10%, rgba(29, 95, 208, 0.14), transparent 55%),
                 var(--bg);
  --surface: #161c2e;
  --surface-2: #1d2439;
  --surface-3: #232b44;
  --border: rgba(190, 205, 240, 0.12);
  --text: #edf1fc;
  --text-muted: #9aa4c2;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 5px 18px rgba(0, 0, 0, 0.4);
  --user-bubble: var(--accent);
  --user-bubble-text: #ffffff;
  --bot-bubble: rgba(255, 255, 255, 0.06);
  --bot-bubble-text: #e6ebf8;

  color-scheme: dark;
}

/* ---------------- Reset / base ---------------- */
* { box-sizing: border-box; }

html {
  margin: 0;
  padding: 0;
  background: var(--bg);
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-gradient);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  transition: background 0.4s ease, color 0.3s ease;
  overflow-x: hidden;
}

/* Themed scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }

a { color: var(--accent); text-decoration: none; }

/* ---------------- Shared components ---------------- */
.btn {
  font: inherit;
  border: none;
  border-radius: var(--r-md);
  padding: 0.7rem 1.15rem;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.18s var(--ease-spring), box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
.btn:active { transform: scale(0.96); }
.btn:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 20px rgba(29, 95, 208, 0.28);
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 10px 26px rgba(29, 95, 208, 0.36); }

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
}
.btn-ghost:hover { background: var(--surface-3); }

.btn-icon {
  background: transparent;
  color: var(--text-muted);
  width: 40px; height: 40px;
  padding: 0; border-radius: 12px;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }

/* Inputs */
.input {
  font: inherit;
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: var(--r-md);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.input::placeholder { color: var(--text-muted); }

/* Card surface */
.surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}

/* ---------------- Floating app header (shared across pages) ---------------- */
.app-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.3rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.app-header .logo { width: 46px; height: 46px; border-radius: 12px; object-fit: cover; }
.app-header .titles { flex: 1; min-width: 0; }
.app-header .titles h1 { font-size: 1.1rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-header .titles .sub { font-size: 0.8rem; color: var(--text-muted); display: flex; align-items: center; gap: 0.4rem; margin-top: 0.1rem; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; display: inline-block; flex-shrink: 0; }
.header-actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.head-group { display: flex; align-items: center; gap: 0.5rem; }
.head-divider { width: 1px; height: 24px; background: var(--border); margin: 0 0.35rem; }
.head-btn { display: inline-flex; align-items: center; gap: 0.45rem; white-space: nowrap; padding: 0.5rem 0.8rem; }
.head-btn svg { flex-shrink: 0; }
.head-btn-label { line-height: 1; }
.head-btn.danger:hover { color: #ef4444; border-color: rgba(239, 68, 68, 0.4); background: rgba(239, 68, 68, 0.08); }
.head-btn.icon-only { padding: 0.5rem 0.6rem; }
.theme-toggle-btn .ico-light { display: none; }
html[data-theme="dark"] .theme-toggle-btn .ico-dark { display: none; }
html[data-theme="dark"] .theme-toggle-btn .ico-light { display: block; }
@media (max-width: 640px) { .head-btn-label { display: none; } }

/* ---------------- Page shell + floating panels (shared) ---------------- */
.page {
  max-width: 1160px;
  margin: 0 auto;
  padding: clamp(0.75rem, 2vw, 1.4rem);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.page-main { display: flex; flex-direction: column; gap: 1rem; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 0.88rem; font-weight: 700; letter-spacing: 0.02em; }
.panel-head .panel-sub { font-size: 0.72rem; color: var(--text-muted); font-weight: 400; }
.panel-body { padding: 1.3rem 1.4rem; }
.panel-body.flat { padding: 0; }

/* ---------------- Tabs (course + view, shared) ---------------- */
.tab-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.tab {
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.15s var(--ease-spring);
}
.tab:hover { border-color: var(--accent); transform: translateY(-1px); }
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tab .cnt { font-size: 0.72rem; font-weight: 700; background: rgba(255,255,255,0.25); color: inherit; border-radius: 999px; padding: 0.08rem 0.42rem; margin-left: 0.35rem; }

/* ---------------- Expandable terms (accordion) ---------------- */
.terms-list { max-height: 46dvh; overflow-y: auto; padding-right: 0.2rem; }
.terms-intro { margin: 0 0 0.7rem; font-size: 0.92rem; color: var(--text-muted); }
.terms-sec {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  margin: 0 0 0.55rem;
  overflow: hidden;
}
.terms-sec summary {
  list-style: none;
  cursor: pointer;
  padding: 0.7rem 0.9rem;
  font-weight: 600;
  font-size: 0.86rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  user-select: none;
}
.terms-sec summary::-webkit-details-marker { display: none; }
.terms-sec summary::after { content: "+"; font-size: 1.05rem; color: var(--text-muted); font-weight: 500; line-height: 1; transition: transform 0.15s ease; }
.terms-sec[open] summary::after { content: "\2212"; }
.terms-sec .terms-body { padding: 0 0.9rem 0.8rem; font-size: 0.84rem; line-height: 1.55; color: var(--text-muted); }
.terms-sec .terms-body p { margin: 0 0 0.5rem; }
.terms-sec .terms-body p:last-child { margin-bottom: 0; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.8rem 1.2rem;
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  font-size: 0.95rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  z-index: 200;
  transition: transform 0.3s var(--ease-spring), opacity 0.3s ease;
  max-width: min(90vw, 420px);
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { border-left: 4px solid #22c55e; }
.toast.error { border-left: 4px solid #ef4444; }

/* ---------------- Keyframe helpers ---------------- */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  0% { opacity: 0; transform: scale(0.92); }
  100% { opacity: 1; transform: scale(1); }
}
.anim-fade-up { animation: fadeUp 0.4s var(--ease-spring) both; }
.anim-pop { animation: popIn 0.3s var(--ease-spring) both; }

/* ---------------- Modal / consent (shared by auth + chat pages) ---------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 14, 26, 0.55);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center; justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal-overlay.open .modal-panel { animation: popIn 0.28s var(--ease-spring) both; }
.modal-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  width: 100%;
  max-height: min(86dvh, 720px);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 1.15rem; letter-spacing: -0.01em; }
.modal-body { padding: 1.4rem; overflow-y: auto; }

/* Consent gate (terms of service) */
.consent-gate { z-index: 200; }
.consent-gate .modal-panel { animation: popIn 0.3s var(--ease-spring) both; }
.consent-body { padding: 1.2rem 1.4rem 1.4rem; }
.consent-lead { margin: 0 0 0.8rem; font-size: 0.92rem; }
.consent-scroll {
  max-height: 40dvh; overflow-y: auto; padding: 0.9rem 1rem;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-2); font-size: 0.88rem; line-height: 1.55;
}
.consent-scroll p { margin: 0 0 0.7rem; }
.consent-scroll p:last-child { margin-bottom: 0; }
.consent-check {
  display: flex; gap: 0.6rem; align-items: flex-start;
  margin: 1rem 0 1.1rem; font-size: 0.88rem; line-height: 1.45; cursor: pointer;
}
.consent-check input { margin-top: 0.15rem; accent-color: var(--accent); width: 17px; height: 17px; flex-shrink: 0; }
.consent-course-pill {
  font-size: 0.75rem; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); border-radius: 999px; padding: 0.3rem 0.7rem;
}
.btn-block { width: 100%; }

/* ---------------- Responsive utility ---------------- */
.hide-mobile { }
.show-mobile { display: none !important; }

@media (max-width: 640px) {
  .hide-mobile { display: none !important; }
  .show-mobile { display: flex !important; }
}

/* ---------------- Code blocks (Prism) ---------------- */
/* Always-dark code surface (the ChatGPT / Slack / GitHub pattern) with a
   token palette tuned for that surface. Scoped to chat bubbles so it never
   leaks into other pages. */
.msg-bubble pre[class*="language-"],
.msg-bubble pre {
  background: #0d1424;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  padding: 0.9rem 1.05rem;
  margin: 0.6rem 0;
  overflow-x: auto;
  color: #e6edf3;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.8rem;
  line-height: 1.6;
}
.msg-bubble pre code[class*="language-"] {
  color: #e6edf3;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-shadow: none;
}
.msg-bubble :not(pre) > code {
  background: rgba(29, 95, 208, 0.14);
  color: inherit;
  padding: 0.14em 0.42em;
  border-radius: 6px;
  font-size: 0.85em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Token palette (dark surface) */
.msg-bubble .token.comment, .msg-bubble .token.prolog, .msg-bubble .token.doctype, .msg-bubble .token.cdata { color: #6b7a90; }
.msg-bubble .token.punctuation { color: #9aa8bd; }
.msg-bubble .token.tag, .msg-bubble .token.boolean, .msg-bubble .token.number, .msg-bubble .token.constant, .msg-bubble .token.symbol, .msg-bubble .token.deleted { color: #7dd3fc; }
.msg-bubble .token.selector, .msg-bubble .token.attr-name, .msg-bubble .token.string, .msg-bubble .token.char, .msg-bubble .token.builtin, .msg-bubble .token.inserted { color: #86efac; }
.msg-bubble .token.operator, .msg-bubble .token.entity, .msg-bubble .token.url { color: #d3dce8; }
.msg-bubble .token.atrule, .msg-bubble .token.attr-value, .msg-bubble .token.keyword { color: #c4b5fd; }
.msg-bubble .token.function, .msg-bubble .token.class-name { color: #93c5fd; }
.msg-bubble .token.regex, .msg-bubble .token.important, .msg-bubble .token.variable { color: #f9a8d4; }
