/* ═══════════════════════════════════════════
   Lucid — Bookish Design System
   Warm paper, ink, walnut. No glass, no glow.
   Palette and type matched to the edapt course.
   ═══════════════════════════════════════════ */

/* ─── Design Tokens ─── */
:root {
  /* Espresso backgrounds (dark bookish) */
  --color-bg:             #1A1613;
  --color-bg-warm:        #221D18;
  --color-surface:        #262019;
  --color-surface-warm:   #1F1A15;

  /* Ink — warm paper, inverted */
  --color-text:           #EDE5D8;
  --color-text-secondary: #B6A998;
  --color-text-muted:     #8A7D6D;

  /* Borders */
  --color-border:         #3A322A;
  --color-border-light:   #2C251F;

  /* Accent — warm caramel (walnut, lifted for dark) */
  --color-accent:         #C79A6E;
  --color-accent-hover:   #D8AE82;
  --color-accent-light:   #38291C;
  --color-accent-muted:   #8C6A4C;

  /* Semantic (warm-leaning, dark) */
  --color-success:        #5FB37E;
  --color-success-light:  #1D2A21;
  --color-error:          #D9695A;
  --color-error-light:    #33201D;
  --color-info:           #8FA6BC;
  --color-info-light:     #20262C;

  /* Fonts */
  --font-display: 'Bricolage Grotesque', Georgia, serif;
  --font-body:    'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:    'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  /* Type scale */
  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;

  /* Line heights */
  --leading-tight:  1.2;
  --leading-snug:   1.35;
  --leading-normal: 1.6;

  /* Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Radii */
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   14px;
  --radius-full: 9999px;

  /* Shadows — deep, for dark surfaces */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.30);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.40);
  --shadow-lg: 0 8px 28px rgba(0,0,0,0.55);

  /* Easing + duration */
  --ease-out:        cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast:   150ms;
  --duration-normal: 280ms;

  /* Layout */
  --sidebar-width: 264px;
  --topbar-height: 60px;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: var(--leading-normal);
  height: 100vh;
  overflow: hidden;
}

a { text-decoration: none; color: inherit; }

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  color: inherit;
}

textarea { font-family: inherit; color: inherit; }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: var(--leading-tight);
}

/* ─── App Layout ─── */
.app-layout {
  display: flex;
  height: 100vh;
}

/* ─── Sidebar ─── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: var(--color-surface-warm);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: var(--space-5) var(--space-4);
  transition: transform var(--duration-normal) var(--ease-out);
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-8);
  padding: 0 var(--space-2);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.logo-mark {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  background: var(--color-accent);
  color: var(--color-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.logo-text {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-text);
}

.sidebar-toggle {
  display: none;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
}

/* ─── Sidebar Navigation ─── */
.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
  padding: 0 var(--space-3);
  margin-bottom: var(--space-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  transition: background var(--duration-fast), color var(--duration-fast);
}

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

.nav-item.active {
  background: var(--color-accent-light);
  color: var(--color-accent);
  font-weight: 600;
}

.nav-item svg {
  flex-shrink: 0;
}

/* ─── Focus Card (sidebar footer) ─── */
.focus-card {
  margin-top: auto;
  padding: var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.focus-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}

.focus-card-title {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.focus-card-badge {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--color-accent-light);
  color: var(--color-accent);
}

.focus-card-topic {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-1);
}

.focus-card-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.focus-card-empty {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

/* ─── Main Content ─── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
}

/* ─── Top Bar ─── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 var(--space-8);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  flex-shrink: 0;
}

.mobile-menu-btn {
  display: none;
  padding: var(--space-1);
  color: var(--color-text-secondary);
  border-radius: var(--radius-sm);
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.page-title {
  font-size: var(--text-xl);
  font-weight: 600;
}

.session-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background: var(--color-bg-warm);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-text-muted);
}

.session-badge.connected { color: var(--color-success); border-color: var(--color-success); }
.session-badge.connected .pulse-dot { background: var(--color-success); }

.top-bar-right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-surface);
  flex-shrink: 0;
}

/* ─── Views ─── */
.view {
  flex: 1;
  min-height: 0;
  display: none;
  flex-direction: column;
}

.view.active {
  display: flex;
  animation: fadeIn var(--duration-normal) var(--ease-out);
}

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

/* Scrollable panel used by the data views */
.panel-scroll {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-8);
}

.panel-inner {
  max-width: 860px;
  margin: 0 auto;
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}

/* ─── Focus Bar ─── */
.focus-bar {
  position: relative;
  flex-shrink: 0;
  padding: var(--space-3) var(--space-8);
  border-bottom: 1px solid var(--color-border-light);
  background: var(--color-bg);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.focus-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  transition: all var(--duration-fast);
}

.focus-chip:hover {
  border-color: var(--color-accent-muted);
  color: var(--color-accent);
}

.focus-chip.has-focus {
  background: var(--color-accent-light);
  border-color: var(--color-accent-muted);
  color: var(--color-accent);
}

.focus-chip-caret {
  transition: transform var(--duration-fast);
}

.focus-chip[aria-expanded="true"] .focus-chip-caret {
  transform: rotate(180deg);
}

.focus-dropdown {
  position: absolute;
  top: calc(100% - var(--space-2));
  left: var(--space-8);
  z-index: 40;
  width: 360px;
  max-width: calc(100% - var(--space-12));
  max-height: 420px;
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2);
  animation: dropdownIn 180ms var(--ease-out);
}

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

.focus-group-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  padding: var(--space-3) var(--space-3) var(--space-1);
}

.focus-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--color-text);
  transition: background var(--duration-fast);
}

.focus-option:hover { background: var(--color-bg-warm); }

.focus-option.selected {
  background: var(--color-accent-light);
  color: var(--color-accent);
  font-weight: 600;
}

.focus-dropdown-empty {
  padding: var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-align: center;
}

/* ─── Chat Area ─── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-8);
  display: flex;
  flex-direction: column;
}

/* ─── Welcome Hero ─── */
.welcome-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  padding: var(--space-10) var(--space-5);
}

.welcome-mark {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  background: var(--color-accent);
  color: var(--color-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.8rem;
  margin-bottom: var(--space-5);
  box-shadow: var(--shadow-md);
}

.welcome-title {
  font-size: var(--text-3xl);
  font-weight: 700;
  margin-bottom: var(--space-3);
  color: var(--color-text);
}

.welcome-sub {
  font-size: var(--text-base);
  color: var(--color-text-secondary);
  max-width: 460px;
  line-height: var(--leading-normal);
  margin-bottom: var(--space-8);
}

.quick-actions {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  justify-content: center;
}

.quick-action-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-5);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  transition: all var(--duration-fast);
}

.quick-action-btn:hover {
  border-color: var(--color-accent-muted);
  color: var(--color-accent);
  box-shadow: var(--shadow-sm);
}

/* ─── Chat Messages ─── */
.messages {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

.message {
  display: flex;
  gap: var(--space-3);
  animation: messageIn var(--duration-normal) var(--ease-out);
}

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

.message.user {
  flex-direction: row-reverse;
}

/* The avatar pops in with a little spring */
.message-avatar {
  animation: avatarPop 360ms var(--ease-out) backwards;
}

@keyframes avatarPop {
  0%   { opacity: 0; transform: scale(0.4); }
  70%  { transform: scale(1.08); }
  100% { opacity: 1; transform: scale(1); }
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.message.assistant .message-avatar {
  background: var(--color-accent);
  color: var(--color-surface);
}

.message.user .message-avatar {
  background: var(--color-bg-warm);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.message-bubble {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  max-width: 600px;
  transform-origin: top left;
  animation: bubbleExpand 340ms var(--ease-out) backwards;
}

/* Bubble expands out from the avatar corner */
@keyframes bubbleExpand {
  0%   { opacity: 0; transform: scale(0.85) translateY(4px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.message.assistant .message-bubble {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-top-left-radius: var(--radius-sm);
}

.message.user .message-bubble {
  background: var(--color-accent-light);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-top-right-radius: var(--radius-sm);
  transform-origin: top right;
}

/* Rendered markdown inside assistant bubbles */
.message-bubble p {
  margin: 0 0 0.6em;
}
.message-bubble p:last-child {
  margin-bottom: 0;
}
.message-bubble strong {
  font-weight: 600;
}
.message-bubble em {
  font-style: italic;
}
.message-bubble code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--color-bg-warm);
  border: 1px solid var(--color-border-light);
  padding: 1px 5px;
  border-radius: 4px;
}
.message-bubble ul {
  margin: 0.3em 0 0.6em;
  padding-left: 1.2em;
}
.message-bubble li {
  margin: 0.2em 0;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: var(--space-2) 2px;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-text-muted);
  animation: typing-bounce 1.4s ease-in-out infinite;
}

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

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

.typing-bubble {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.typing-label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-style: italic;
}

/* ─── Input Area ─── */
.input-area {
  padding: var(--space-4) var(--space-8) var(--space-5);
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
  flex-shrink: 0;
}

.input-container {
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
  max-width: 760px;
  margin: 0 auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-2) var(--space-3);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.input-container:focus-within {
  border-color: var(--color-accent-muted);
  box-shadow: 0 0 0 3px var(--color-accent-light);
}

.message-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: var(--text-base);
  line-height: 1.5;
  padding: var(--space-2) var(--space-1);
  resize: none;
  max-height: 120px;
  color: var(--color-text);
}

.message-input::placeholder { color: var(--color-text-muted); }
.message-input:disabled { opacity: 0.5; cursor: not-allowed; }

.send-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--color-accent);
  color: var(--color-surface);
  transition: all var(--duration-fast);
  flex-shrink: 0;
  opacity: 0.4;
}

.send-btn:not(:disabled) { opacity: 1; }
.send-btn:not(:disabled):hover { background: var(--color-accent-hover); }
.send-btn:disabled { cursor: not-allowed; }

.input-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-align: center;
  margin-top: var(--space-2);
}

/* ─── Citations ─── */
.citations {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border-light);
}

.citation-tag {
  display: inline-flex;
  align-items: center;
  font-size: var(--text-xs);
  font-weight: 500;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
  border: 1px solid var(--color-border);
  transition: transform var(--duration-fast), box-shadow var(--duration-fast);
  animation: citationPop 300ms var(--ease-out) backwards;
}

.citation-tag:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

@keyframes citationPop {
  0%   { opacity: 0; transform: scale(0.7); }
  100% { opacity: 1; transform: scale(1); }
}

.citation-tag.curriculum {
  background: var(--color-accent-light);
  color: var(--color-accent);
}

.citation-tag.subject {
  background: var(--color-info-light);
  color: var(--color-info);
}

/* ─── Error Messages ─── */
.message.system-error {
  align-self: center;
  max-width: 560px;
}

.error-bubble {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  background: var(--color-error-light) !important;
  border: 1px solid var(--color-error) !important;
  color: var(--color-error) !important;
  font-size: var(--text-sm);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
}

/* ─── Panel headings (shared by data views) ─── */
.panel-heading {
  margin-bottom: var(--space-2);
}

.panel-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-text);
}

.panel-sub {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-8);
}

.panel-error {
  padding: var(--space-4) var(--space-5);
  background: var(--color-error-light);
  border: 1px solid var(--color-error);
  border-radius: var(--radius-md);
  color: var(--color-error);
  font-size: var(--text-sm);
}

/* ─── Curriculum View ─── */
.cur-strand {
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-accent);
  margin: var(--space-8) 0 var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.cur-strand:first-of-type { margin-top: 0; }

.cur-element {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-3);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast), transform var(--duration-fast);
}

.cur-element:hover {
  border-color: var(--color-accent-muted);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.cur-element.is-focus {
  border-color: var(--color-accent);
  background: var(--color-accent-light);
}

.cur-element-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.cur-element-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
}

.cur-element-action {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-accent);
  white-space: nowrap;
  opacity: 0;
  transition: opacity var(--duration-fast);
}

.cur-element:hover .cur-element-action { opacity: 1; }
.cur-element.is-focus .cur-element-action { opacity: 1; }

.cur-subelements {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.cur-subelement {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  background: var(--color-bg-warm);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-full);
  padding: 3px 10px;
}

/* ─── Stat cards (Progress) ─── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.stat-value {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--color-accent);
  line-height: 1.1;
}

.stat-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-top: var(--space-2);
}

/* ─── Cards / sections ─── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-6);
}

.card-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--space-4);
}

.empty-note {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  padding: var(--space-4) 0;
  text-align: center;
}

/* ─── Trend chart ─── */
.trend-svg {
  width: 100%;
  height: 180px;
  overflow: visible;
}

.trend-line {
  fill: none;
  stroke: var(--color-accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.trend-area { fill: var(--color-accent-light); opacity: 0.6; }
.trend-dot  { fill: var(--color-surface); stroke: var(--color-accent); stroke-width: 2.5; }
.trend-label { font-size: 11px; fill: var(--color-text-secondary); font-family: var(--font-mono); }
.trend-axis  { font-size: 11px; fill: var(--color-text-muted); }
.trend-grid  { stroke: var(--color-border-light); stroke-width: 1; }

/* ─── Misconception list ─── */
.mis-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--color-border-light);
}

.mis-item:last-child { border-bottom: none; }

.mis-label {
  font-weight: 600;
  color: var(--color-text);
  font-size: var(--text-base);
}

.mis-desc {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-top: 2px;
}

.mis-count {
  flex-shrink: 0;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-accent);
  background: var(--color-accent-light);
  border-radius: var(--radius-full);
  padding: 3px 10px;
  white-space: nowrap;
}

/* ─── Mastery list ─── */
.mastery-item {
  display: grid;
  grid-template-columns: 1fr 140px 96px;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--color-border-light);
}

.mastery-item:last-child { border-bottom: none; }

.mastery-id {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-text);
}

.mastery-bar {
  height: 8px;
  background: var(--color-bg-warm);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.mastery-bar-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: var(--radius-full);
  transition: width var(--duration-slow, 500ms) var(--ease-out);
}

.mastery-meta {
  text-align: right;
  font-size: var(--text-sm);
}

.mastery-score { font-weight: 700; color: var(--color-accent); }
.mastery-attempts { font-size: var(--text-xs); color: var(--color-text-muted); }

@media (max-width: 768px) {
  .stat-row { grid-template-columns: 1fr; }
  .mastery-item { grid-template-columns: 1fr 80px; }
  .mastery-bar { display: none; }
}

/* ─── Placeholder (views not yet wired) ─── */
.view-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  color: var(--color-text-muted);
  gap: var(--space-2);
  padding: var(--space-12);
}

.view-placeholder h3 {
  font-size: var(--text-xl);
  color: var(--color-text-secondary);
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    z-index: 100;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu-btn { display: flex; }
  .chat-area, .panel-scroll { padding: var(--space-5) var(--space-4); }
  .top-bar { padding: 0 var(--space-4); }
  .input-area { padding: var(--space-3) var(--space-4) var(--space-4); }
  .quick-actions { flex-direction: column; align-items: center; }
  .welcome-title { font-size: var(--text-2xl); }
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(44,42,40,0.4);
  z-index: 99;
}

.sidebar-overlay.active { display: block; }

::selection {
  background: var(--color-accent-light);
  color: var(--color-text);
}

/* ─── Collapsible Context Block (V2-A) ─── */

.context-block {
  margin: 0 0 var(--space-3) 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-warm);
  overflow: hidden;
}

.context-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  font-family: var(--font-body);
  user-select: none;
  gap: var(--space-2);
}

.context-block-header:hover {
  color: var(--color-text);
  background: var(--color-accent-light);
}

.context-block-label {
  flex: 1;
}

.context-block-arrow {
  font-size: var(--text-xs);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.context-block.open .context-block-arrow {
  transform: rotate(90deg);
}

.context-block-body {
  display: none;
  padding: var(--space-2) var(--space-3) var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text);
  border-top: 1px solid var(--color-border-light);
  line-height: 1.6;
}

.context-block.open .context-block-body {
  display: block;
}

/* ─── Mode Picker (V2-B) ─── */

.mode-picker {
  margin-top: var(--space-5);
  text-align: left;
}

.mode-picker-label {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin: 0 0 var(--space-3) 0;
  font-family: var(--font-body);
}

.mode-options {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  justify-content: center;
}

.mode-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  cursor: pointer;
  font-family: var(--font-body);
  text-align: left;
  min-width: 120px;
  flex: 1;
  transition: border-color var(--duration-fast) ease, background var(--duration-fast) ease;
}

.mode-option:hover {
  border-color: var(--color-accent-muted);
  background: var(--color-accent-light);
}

.mode-option.selected {
  border-color: var(--color-accent);
  background: var(--color-accent-light);
}

.mode-option-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  display: block;
  margin-bottom: var(--space-1);
}

.mode-option-desc {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  display: block;
  line-height: 1.4;
}

/* ─── Mode Chip (V2-B mid-session switcher) ─── */

.mode-chip-wrapper {
  position: relative;
  display: inline-flex;
}

.mode-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  font-family: var(--font-body);
  cursor: pointer;
  transition: border-color var(--duration-fast) ease;
  white-space: nowrap;
}

.mode-chip:hover {
  border-color: var(--color-accent-muted);
  color: var(--color-text);
}

.mode-chip-caret {
  opacity: 0.5;
  flex-shrink: 0;
}

.mode-chip-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 200;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  min-width: 180px;
  overflow: hidden;
}

.mode-chip-option {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: none;
  background: none;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--color-text);
  text-align: left;
  cursor: pointer;
}

.mode-chip-option:hover {
  background: var(--color-accent-light);
}

.mode-chip-option.active {
  font-weight: 600;
  color: var(--color-accent);
}

/* ─── Year Chip (mirrors Mode Chip) ─── */
.year-chip-wrapper {
  position: relative;
  display: inline-flex;
}

.year-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  font-family: var(--font-body);
  cursor: pointer;
  transition: border-color var(--duration-fast) ease;
}

.year-chip:hover {
  border-color: var(--color-accent-muted);
  color: var(--color-accent);
}

.year-chip-caret {
  transition: transform var(--duration-fast) ease;
}

.year-chip[aria-expanded='true'] .year-chip-caret {
  transform: rotate(180deg);
}

.year-chip-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 200;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  min-width: 120px;
  overflow: hidden;
}

.year-chip-option {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: none;
  background: none;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--color-text);
  text-align: left;
  cursor: pointer;
}

.year-chip-option:hover {
  background: var(--color-accent-light);
}

.year-chip-option.active {
  font-weight: 600;
  color: var(--color-accent);
}

/* ─── Question Me button (right-aligned in the focus bar) ─── */
.question-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--color-accent-muted);
  border-radius: 999px;
  background: var(--color-accent-light);
  color: var(--color-accent);
  font-size: var(--text-xs);
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: background var(--duration-fast) ease, border-color var(--duration-fast) ease;
}

.question-btn:hover {
  background: var(--color-accent);
  color: var(--color-surface);
  border-color: var(--color-accent);
}

/* Phase 56: worked-example diagram bubble. The SVG scales to the bubble width. */
.diagram-bubble {
  padding: 0.5rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
}
.diagram-bubble svg {
  display: block;
  max-width: 100%;
  height: auto;
}
