/* ---- Importar mismos estilos del chat premium ---- */
:root {
  --bg-app: #f4f8fc;
  --bg-panel: #ffffff;
  --bg-panel-secondary: #f8fafc;
  --border-color: rgba(0, 145, 234, 0.12);
  --border-color-active: rgba(0, 145, 234, 0.32);
  --text-main: #1e2d3d;
  --text-muted: #5c728a;
  --text-muted-2: #8498ad;
  --accent-color: #0091ea;
  --accent-color-hover: #007bbd;
  --accent-color-bg: rgba(0, 145, 234, 0.05);
  --accent-color-bg-active: rgba(0, 145, 234, 0.12);
  /* Filled call to action (billing). White text needs >= 4.5:1 (U14);
     #008fda gave 3.53:1. Same hue, darker. */
  --cta-bg: #007bbb;
  --cta-bg-hover: #00679c;
  --success-color: #00b0ff;
  --shadow-soft:
    0 12px 36px rgba(0, 145, 234, 0.04), 0 2px 10px rgba(0, 0, 0, 0.01);
  --shadow-premium:
    0 20px 50px rgba(0, 145, 234, 0.06), 0 4px 16px rgba(0, 0, 0, 0.015);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --transition-smooth: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  --sidebar-w: 224px;
  --chat-open-width: clamp(440px, 33vw, 560px);
}

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

html,
body {
  height: 100%;
  overflow: hidden;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family:
    "Plus Jakarta Sans",
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

button,
textarea,
input,
select {
  font-family: inherit;
  cursor: pointer;
}
button:focus-visible,
textarea:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid rgba(0, 145, 234, 0.38);
  outline-offset: 3px;
}

/* Hide mathbox chrome */
.mathbox-loader,
.mathbox-splash,
.mathbox-splash-blue,
.mathbox-overlay,
.mathbox-logo,
.mathbox-progress {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  width: 0 !important;
  height: 0 !important;
}

/* ---- ROOT LAYOUT ---- */
#prisma-root {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---- SIDEBAR ---- */
#global-sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition:
    width 0.3s cubic-bezier(0.16, 1, 0.3, 1),
    min-width 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  z-index: 100;
}
#global-sidebar.collapsed {
  width: 0;
  min-width: 0;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-logo img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
}
.sidebar-logo-text {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 4px;
  flex: 1;
  overflow: hidden;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 160ms ease;
  white-space: nowrap;
  overflow: hidden;
  text-align: left;
  width: 100%;
}
.nav-item svg {
  flex-shrink: 0;
  opacity: 0.6;
}
.nav-item:hover {
  background: var(--bg-panel-secondary);
  color: var(--text-main);
}
.nav-item.active {
  background: var(--accent-color-bg-active);
  color: var(--accent-color);
  border-color: var(--border-color-active);
}
.nav-item.active svg {
  opacity: 1;
}

/* ---- SIDEBAR TOGGLE BUTTON ---- */
#sidebar-toggle {
  position: fixed;
  top: 50%;
  left: var(--sidebar-w);
  transform: translateY(-50%) translateX(-50%);
  width: 22px;
  height: 48px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 0 10px 10px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition:
    left 0.3s cubic-bezier(0.16, 1, 0.3, 1),
    background 150ms ease;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.06);
}
#sidebar-toggle:hover {
  background: var(--accent-color-bg);
}
#sidebar-toggle svg {
  transition: transform 0.3s ease;
  color: var(--text-muted);
}
#sidebar-toggle.collapsed-state {
  left: 0;
}
#sidebar-toggle.collapsed-state svg {
  transform: rotate(180deg);
}

/* ---- MAIN CONTENT AREA ---- */
#main-content {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* ---- VIEWS ---- */
.view {
  display: none;
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.view.active {
  display: flex;
}

/* -"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"-
       VIEW: CHAT IA (full chat_premium layout)
       -"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"- */
#view-chat {
  flex-direction: column;
  height: 100%;
}
.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}
.chat-topbar-brand {
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-topbar-brand h1 {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-main);
}
.chat-topbar-brand span {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  margin-left: 2px;
}

/* Mode selector (Chat Libre / Demo Guiada) */
.mode-selector {
  display: flex;
  align-items: center;
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  padding: 3px;
  border-radius: 99px;
  gap: 2px;
}
.mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 99px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-smooth);
}
.mode-btn:hover:not(.active) {
  color: var(--text-main);
}
.mode-btn.active {
  background: var(--bg-panel);
  color: var(--accent-color);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Status badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 99px;
  background: var(--bg-panel-secondary);
  border: 1px solid var(--border-color);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffab40;
  box-shadow: 0 0 10px #ffab40;
  transition: var(--transition-smooth);
}
.status-dot.active {
  background: var(--success-color);
  box-shadow: 0 0 10px var(--success-color);
}
.status-dot.pending {
  background: #f59e0b;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.65);
}
.status-dot.error {
  background: #ef4444;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.5);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 99px;
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-smooth);
}
.btn-secondary:hover {
  color: var(--accent-color);
  border-color: var(--border-color-active);
}

/* Workspace (chat + whiteboard) */
.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Chat container - fills full width by default, shrinks in board-mode */
.chat-container {
  flex: 0 0 100%;
  max-width: 100%;
  min-width: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  background: var(--bg-panel);
  height: 100%;
  min-height: 0;
  overflow: hidden;
  z-index: 10;
  transition:
    flex-basis 0.5s cubic-bezier(0.16, 1, 0.3, 1),
    max-width 0.5s cubic-bezier(0.16, 1, 0.3, 1),
    border-right 0.3s ease;
  will-change: flex-basis, max-width;
}
body.board-mode .chat-container {
  flex-basis: var(--chat-open-width);
  max-width: var(--chat-open-width);
  min-width: min(420px, 48vw);
  border-right: 1px solid var(--border-color);
}

.thread-area {
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  max-width: 840px;
  margin: 0 auto;
  transition: max-width 0.4s ease;
}
body.board-mode .thread-area {
  max-width: 100%;
  padding: 16px;
}
.thread-area::-webkit-scrollbar {
  width: 6px;
}
.thread-area::-webkit-scrollbar-thumb {
  background: rgba(0, 145, 234, 0.15);
  border-radius: 99px;
}
.chat-empty {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  margin: auto;
  padding: 16px;
}
body.board-mode .chat-empty {
  display: none !important;
}
.chat-empty h2 {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 12px;
  color: var(--text-main);
}
.chat-empty p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.6;
}

.quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.quick-card {
  padding: 14px;
  border-radius: var(--radius-md);
  text-align: left;
  border: 1px solid var(--border-color);
  background: var(--bg-panel-secondary);
  cursor: pointer;
  transition: var(--transition-smooth);
}
.quick-card:hover {
  border-color: var(--border-color-active);
  background: var(--accent-color-bg);
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
}
.quick-card strong {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 4px;
}
.quick-card span {
  font-size: 11px;
  color: var(--text-muted);
}

/* Messages */
.message {
  display: flex;
  gap: 12px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border-color);
  min-width: 0;
}
.message:last-child {
  border-bottom: none;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  flex-shrink: 0;
  border: 1px solid var(--border-color);
}
.message.assistant .avatar {
  background: var(--accent-color-bg);
  color: var(--accent-color);
  border-color: var(--border-color-active);
}
.message.user .avatar {
  background: var(--bg-panel-secondary);
  color: var(--text-main);
}
.bubble {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.5;
  width: 100%;
  min-width: 0;
}
.bubble,
.bubble * {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.message.assistant .bubble {
  background: var(--bg-panel-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-top-left-radius: 4px;
}
.message.assistant.sequence-step .bubble {
  background: linear-gradient(
    180deg,
    rgba(0, 145, 234, 0.05),
    rgba(255, 255, 255, 0.96)
  );
  border-color: rgba(0, 145, 234, 0.18);
}
.message.lesson-step-message {
  scroll-margin-top: 16px;
}
.message.lesson-step-message .bubble {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lesson-step-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.lesson-step-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(0, 145, 234, 0.18);
  background: rgba(0, 145, 234, 0.08);
  color: var(--accent-color);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.lesson-step-caption {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}
.lesson-step-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.lesson-step-fragment {
  min-width: 0;
}
.lesson-step-fragment-divider {
  height: 1px;
  background: linear-gradient(
    90deg,
    rgba(0, 145, 234, 0.12),
    rgba(0, 145, 234, 0.02)
  );
}
.message.lesson-step-active .bubble {
  border-color: rgba(0, 145, 234, 0.42);
  box-shadow:
    0 0 0 1px rgba(0, 145, 234, 0.08),
    0 12px 32px rgba(15, 23, 42, 0.08);
}
.message.lesson-step-active .lesson-step-badge {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: #fff;
}
.message.user .bubble {
  background: var(--accent-color-bg-active);
  color: var(--text-main);
  border-top-right-radius: 4px;
  width: auto;
}
.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(80, 130, 170, 0.18);
}
.message-attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(100%, 280px);
  padding: 7px 10px 7px 7px;
  border: 1px solid var(--border-color-active);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--text-main);
}
.message-attachment-type {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 28px;
  flex: 0 0 auto;
  border-radius: 7px;
  background: var(--accent-color);
  color: #fff;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.04em;
}
.message-attachment-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 750;
}
.message.message-send-failed .bubble {
  border-color: rgba(220, 38, 38, 0.3);
}
.bubble p {
  margin-bottom: 8px;
}
.bubble p:last-child {
  margin-bottom: 0;
}
.math {
  font-family: "Cambria Math", Georgia, serif;
  font-style: italic;
  color: var(--accent-color);
  padding: 0 2px;
}
.math-block {
  display: block;
  margin: 12px 0;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  font-family: "Cambria Math", Georgia, serif;
  font-size: 1.05em;
  text-align: center;
  overflow-x: auto;
}
.bubble .katex {
  font-size: 1.02em;
}
.bubble .katex-display {
  margin: 0.85rem 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
}
.bubble .katex-display > .katex {
  display: inline-block;
  max-width: 100%;
}
.thinking {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}
.thinking span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-color);
  opacity: 0.4;
  animation: blink 1.2s infinite;
}
.thinking span:nth-child(2) {
  animation-delay: 0.2s;
}
.thinking span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.4;
  }
  40% {
    opacity: 1;
  }
}

/* Composer */
.composer-panel {
  border-top: 1px solid var(--border-color);
  background: var(--bg-panel);
  padding: 16px 20px;
  flex-shrink: 0;
  min-width: 0;
}
.demo-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-panel-secondary);
  border: 1px solid var(--border-color);
  margin-bottom: 12px;
  min-width: 0;
}
.sequence-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: linear-gradient(
    135deg,
    rgba(0, 145, 234, 0.06),
    rgba(0, 176, 255, 0.04)
  );
  border: 1px solid var(--border-color-active);
  margin-bottom: 12px;
  min-width: 0;
}
.sequence-bar-info {
  flex: 1;
  min-width: 0;
}
.sequence-bar-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.sequence-bar-title-row h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sequence-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sequence-bar-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  margin-left: auto;
}
.demo-bar-info {
  flex: 1;
  min-width: 0;
}
.demo-bar-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.demo-bar-title-row h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.demo-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-color);
  background: var(--accent-color-bg);
  padding: 2px 8px;
  border-radius: 99px;
  white-space: nowrap;
}
.demo-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.demo-bar-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}
.btn-primary-demo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 99px;
  border: 0;
  background: var(--accent-color);
  color: white;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary-demo svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}
.btn-primary-demo:hover {
  background: var(--accent-color-hover);
}
.btn-secondary-demo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 99px;
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-muted);
  cursor: pointer;
}
.btn-secondary-demo svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}
.input-wrapper {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  min-width: 0;
}
.input-wrapper textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  background: var(--bg-panel-secondary);
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.5;
  max-height: 140px;
  overflow-y: auto;
  outline: none;
  transition: var(--transition-smooth);
  min-width: 0;
}
.input-wrapper textarea:focus {
  border-color: var(--border-color-active);
  background: var(--bg-panel);
}
.composer-mode-toggle {
  height: 42px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: #fff;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  transition: var(--transition-smooth);
  white-space: nowrap;
}
.composer-mode-toggle svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}
.composer-mode-toggle:hover {
  border-color: var(--border-color-active);
  color: var(--accent-color);
  background: var(--accent-color-bg);
}
.composer-mode-toggle.active {
  border-color: rgba(0, 145, 234, 0.42);
  background: var(--accent-color);
  color: #fff;
  box-shadow: 0 8px 20px rgba(0, 145, 234, 0.18);
}
.btn-send {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  border: 0;
  background: var(--accent-color);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: background 150ms ease;
}
.btn-send:hover {
  background: var(--accent-color-hover);
}
.btn-send svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}
.composer-suggestions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.attachment-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 0;
  margin-top: 8px;
}
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--border-color-active);
  border-radius: 999px;
  background: var(--accent-color-bg);
  color: var(--text-main);
  font-size: 11px;
  font-weight: 700;
}
.attachment-chip span {
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attachment-chip button {
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-weight: 800;
}
.attachment-chip button:hover {
  background: rgba(0, 145, 234, 0.16);
}
.history-drawer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  justify-content: flex-end;
  pointer-events: none;
}
.history-drawer.open {
  pointer-events: auto;
}
.history-backdrop {
  position: absolute;
  inset: 0;
  opacity: 0;
  background: rgba(18, 35, 52, 0.24);
  transition: opacity 180ms ease;
}
.history-drawer.open .history-backdrop {
  opacity: 1;
}
.history-panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(420px, 100vw);
  height: 100%;
  padding: 22px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border-color);
  box-shadow: -18px 0 40px rgba(24, 55, 85, 0.12);
  transform: translateX(100%);
  transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1);
}
.history-drawer.open .history-panel {
  transform: translateX(0);
}
.history-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.history-panel-header h2 {
  font-size: 19px;
  letter-spacing: -0.02em;
}
.history-panel-header.compact {
  margin-bottom: 10px;
}
.history-panel-header.compact .btn-secondary {
  padding: 5px 9px;
  font-size: 11px;
}
.history-note {
  margin: 10px 0 16px;
  color: var(--text-muted);
  font-size: 13px;
}
.history-list,
.document-library {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}
.history-list {
  max-height: 48%;
  padding-right: 2px;
}
.history-documents {
  margin-top: 18px;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.document-library {
  max-height: 230px;
}
.document-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: stretch;
}
.document-delete {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-panel);
  color: #9f2740;
  padding: 0 10px;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.document-delete:hover {
  border-color: #c44a61;
  background: #fff4f6;
}
.history-item,
.document-item {
  width: 100%;
  padding: 11px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-panel-secondary);
  color: var(--text-main);
  text-align: left;
}
.history-item:hover,
.document-item:hover {
  border-color: var(--border-color-active);
  background: var(--accent-color-bg);
}
.history-item.active {
  border-color: var(--accent-color);
  background: var(--accent-color-bg);
  box-shadow: inset 3px 0 0 var(--accent-color);
}
.history-item strong,
.document-item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.history-item small,
.document-item small {
  display: block;
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 11px;
}
.history-empty {
  padding: 14px 4px;
  color: var(--text-muted);
  font-size: 13px;
}

.billing-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.billing-notice {
  min-height: 20px;
  padding: 0 2px;
  color: var(--text-muted);
  font-size: 13px;
}

.billing-notice.error {
  color: #b42318;
}

.billing-card {
  display: grid;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--border-color);
  border-radius: 18px;
  background:
    linear-gradient(145deg, rgba(0, 145, 234, 0.08), transparent 58%), #fff;
}

.billing-card h3,
.billing-card p {
  margin: 0;
}

.billing-kicker {
  display: block;
  margin-bottom: 5px;
  color: var(--accent-color);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.billing-usage {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.billing-usage strong {
  color: var(--text-main);
  font-size: 34px;
  line-height: 1;
}

.billing-usage span,
.billing-period,
.billing-product p {
  color: var(--text-muted);
  font-size: 13px;
}

.billing-meter {
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: #e8f1f7;
}

.billing-meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #008bd2, #37b5dd);
  transition: width 240ms ease;
}

.billing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.billing-primary {
  border: 1px solid var(--cta-bg);
  border-radius: 10px;
  padding: 9px 14px;
  background: var(--cta-bg);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.billing-primary:hover:not(:disabled) {
  border-color: var(--cta-bg-hover);
  background: var(--cta-bg-hover);
}

.billing-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

@media (max-width: 720px) {
  .billing-card {
    padding: 16px;
  }

  .billing-actions {
    flex-direction: column;
  }

  .billing-actions button {
    width: 100%;
  }
}
@media (max-width: 700px) {
  .composer-mode-toggle .mode-label {
    display: none;
  }
  .composer-mode-toggle {
    width: 42px;
    padding: 0;
  }
  .history-panel {
    width: 100%;
  }
}
.suggestion-chip {
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 99px;
  border: 1px solid var(--border-color);
  background: var(--bg-panel-secondary);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition-smooth);
}
.suggestion-chip:hover {
  border-color: var(--border-color-active);
  color: var(--accent-color);
}

/* Whiteboard: hidden by default, revealed by body.board-mode */
.whiteboard-container {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  grid-template-rows: 56px 1fr 36px;
  background: var(--bg-app);
  border-left: 1px solid var(--border-color);
  opacity: 0;
  transform: translateX(60px) scale(0.99);
  pointer-events: none;
  transition:
    opacity 0.3s ease,
    transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  height: 100%;
  min-height: 0;
  overflow: hidden;
  will-change: transform, opacity;
}
body.board-mode .whiteboard-container {
  opacity: 1;
  transform: translateX(0) scale(1);
  pointer-events: auto;
}
.board-header {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 56px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-panel);
}
body.ai-busy #btnSend {
  display: none;
}
body:not(.ai-busy) #btnCancelAI {
  display: none;
}
#btnCancelAI {
  background: #fff;
  color: #b42318;
  border: 1px solid rgba(180, 35, 24, 0.22);
  font-weight: 800;
}
#btnCancelAI:hover {
  background: rgba(180, 35, 24, 0.06);
  border-color: rgba(180, 35, 24, 0.34);
}
.board-meta {
  min-width: 0;
  overflow: hidden;
}
.board-meta h2 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.board-meta p {
  display: none;
}
.board-steps {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  justify-content: flex-end;
  min-width: max-content;
}
.btn-step {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition-smooth);
}
.btn-step:hover:not(:disabled) {
  border-color: var(--border-color-active);
  color: var(--accent-color);
}
.btn-step:disabled {
  opacity: 0.4;
  cursor: default;
}
.step-indicator {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0 8px;
  white-space: nowrap;
  min-width: 72px;
  text-align: center;
}
.lesson-speed-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 4px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--bg-panel-secondary);
}
.lesson-speed-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted-2);
}
.lesson-speed-select {
  border: 0;
  background: transparent;
  color: var(--text-main);
  font-size: 12px;
  font-weight: 700;
  outline: none;
  cursor: pointer;
  min-width: 108px;
}
.board-canvas-area {
  flex: 1;
  position: relative;
  overflow: hidden;
}
#pizarraApp {
  position: absolute;
  inset: 0;
  z-index: 1;
}
.board-loader {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg-panel-secondary);
}
.board-loader h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-muted);
}
.board-loader p {
  font-size: 13px;
  color: var(--text-muted-2);
  max-width: 280px;
  text-align: center;
}
.board-toolbar {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  cursor: pointer;
  color: var(--text-muted);
  transition: var(--transition-smooth);
}
.toolbar-btn:hover {
  border-color: var(--border-color-active);
  color: var(--accent-color);
}
.toolbar-btn.active {
  background: var(--accent-color-bg-active);
  border-color: var(--border-color-active);
  color: var(--accent-color);
}
.toolbar-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}
.viewport-panel {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  max-width: 380px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
}
.viewport-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  margin-right: 4px;
}
.viewport-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 99px;
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition-smooth);
}
.viewport-pill.active {
  background: var(--accent-color-bg-active);
  color: var(--accent-color);
  border-color: var(--border-color-active);
}
.viewport-pill:not(.active):hover {
  border-color: var(--border-color-active);
}
.viewport-custom {
  display: flex;
  align-items: center;
  gap: 4px;
}
.viewport-custom input {
  width: 52px;
  padding: 3px 6px;
  font-size: 11px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  color: var(--text-main);
  outline: none;
}
.viewport-custom span {
  font-size: 11px;
  color: var(--text-muted);
}
.viewport-apply {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 99px;
  border: 0;
  background: var(--accent-color);
  color: white;
  cursor: pointer;
}
.viewport-hint {
  font-size: 10px;
  color: var(--text-muted-2);
  width: 100%;
}
select#viewportQuality {
  font-size: 11px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 3px 6px;
  background: var(--bg-panel);
  color: var(--text-main);
  outline: none;
}
.visual-spec {
  display: none !important;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
}
.spec-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.spec-item strong {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-color);
}
.spec-item span {
  font-size: 11px;
  color: var(--text-main);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.board-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 36px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-color);
  font-size: 11px;
  color: var(--text-muted);
}
.log-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--accent-color);
}
/* -"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"-
       VIEW: LESSON VIEWER
       -"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"- */
#view-viewer {
  flex-direction: row;
}

/* Viewer sidebar - lesson list */
.viewer-sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  overflow: hidden;
}
.viewer-sidebar-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}
.viewer-sidebar-header .section-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted-2);
  margin-bottom: 10px;
  display: block;
}
.filter-bar {
  display: flex;
  gap: 6px;
}
.filter-btn {
  flex: 1;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  background: var(--bg-panel);
  cursor: pointer;
  transition: all 130ms ease;
}
.filter-btn:hover {
  color: var(--text-main);
  border-color: var(--border-color-active);
}
.filter-btn.active {
  color: var(--accent-color);
  border-color: var(--border-color-active);
  background: var(--accent-color-bg-active);
}
.lesson-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.lesson-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  width: 100%;
  cursor: pointer;
  transition: all 130ms ease;
}
.lesson-item:hover {
  background: var(--bg-panel-secondary);
  border-color: var(--border-color);
}
.lesson-item.active {
  background: var(--accent-color-bg);
  border-color: var(--border-color-active);
}
.lesson-subject-tag {
  display: inline-block;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 999px;
  width: fit-content;
  background: var(--accent-color-bg-active);
  color: var(--accent-color);
  border: 1px solid var(--border-color-active);
}
.lesson-subject-tag.physics {
  background: rgba(225, 29, 72, 0.07);
  color: #e11d48;
  border-color: rgba(225, 29, 72, 0.22);
}
.lesson-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.3;
}
.lesson-item-level {
  font-size: 11px;
  color: var(--text-muted-2);
}

/* Stage (3D canvas area) */
.viewer-stage-area {
  flex: 1;
  position: relative;
  background: #f8f6f1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.viewer-topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-panel);
  flex-shrink: 0;
}
.viewer-topnav-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}
.stage-inner {
  flex: 1;
  position: relative;
  min-height: 0;
  overflow: hidden;
}
#app {
  position: absolute;
  inset: 0;
  z-index: 1;
}
.stage-label {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 10;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
}
.eyebrow {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-color);
}
.stage-label h2 {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-main);
}
.step-strip {
  position: absolute;
  bottom: 16px;
  left: 16px;
  right: 16px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
}
.step-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.step-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-color);
}
.step-num {
  font-size: 11px;
  font-weight: 800;
  color: var(--accent-color);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
#stepText {
  flex: 1;
  font-size: 13px;
  color: var(--text-main);
  line-height: 1.4;
}
.step-right {
  display: flex;
  gap: 4px;
}
.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-muted);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 120ms ease;
  cursor: pointer;
}
.icon-btn:hover {
  color: var(--accent-color);
  border-color: var(--border-color-active);
  background: var(--accent-color-bg);
}

/* Inspector (right panel of viewer) */
.inspector-panel {
  width: 320px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-left: 1px solid var(--border-color);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.inspector-topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 48px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}
.inspector-topnav-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}
.insp-tabs {
  display: flex;
  gap: 4px;
}
.insp-tab {
  font-size: 12px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 130ms ease;
}
.insp-tab.active {
  background: var(--accent-color-bg-active);
  color: var(--accent-color);
}
.insp-panel {
  display: none;
  padding: 16px;
}
.insp-panel.active {
  display: block;
}
.insp-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted-2);
  display: block;
  margin-bottom: 4px;
  margin-top: 14px;
}
.insp-label:first-child {
  margin-top: 0;
}
.lesson-text {
  font-size: 13px;
  color: var(--text-main);
  line-height: 1.5;
}
.insp-formula {
  font-family: "Cambria Math", Georgia, serif;
  font-size: 14px;
  color: var(--accent-color);
  background: var(--bg-panel-secondary);
  border: 1px solid var(--border-color);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  display: block;
}
.note-list {
  padding-left: 16px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}
.note-list li {
  margin-bottom: 4px;
}
.status-pill {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 99px;
}
.status-pill.reviewed {
  background: rgba(0, 176, 255, 0.1);
  color: #0070ad;
}
.status-pill.draft {
  background: rgba(245, 158, 11, 0.12);
  color: #92400e;
}
.meta-level {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 8px;
}
.meta-row {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}
.field-select,
.field-input {
  display: block;
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-panel-secondary);
  color: var(--text-main);
  outline: none;
  margin-top: 4px;
  transition: border-color 150ms ease;
}
.field-select:focus,
.field-input:focus {
  border-color: var(--border-color-active);
}
.field-textarea {
  display: block;
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-panel-secondary);
  color: var(--text-main);
  outline: none;
  margin-top: 4px;
  resize: vertical;
  min-height: 70px;
  transition: border-color 150ms ease;
}
.field-textarea:focus {
  border-color: var(--border-color-active);
}
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--accent-color);
  color: white;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 12px;
  transition: background 150ms ease;
}
.btn-primary:hover {
  background: var(--accent-color-hover);
}
.output-pre {
  font-size: 11px;
  font-family: "Fira Code", "Consolas", monospace;
  color: var(--text-main);
  background: var(--bg-panel-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
  margin-top: 6px;
}
.output-pre.sm {
  max-height: 100px;
}
.nav-chips {
  display: flex;
  gap: 8px;
  align-items: center;
}
.nav-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 99px;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}
.nav-chip#mathboxChip {
  background: rgba(0, 145, 234, 0.07);
  color: var(--accent-color);
  border-color: var(--border-color-active);
}
.nav-chip#giacChip {
  background: rgba(0, 145, 234, 0.04);
  color: var(--accent-color);
  border-color: var(--border-color-active);
}
.viewer-topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-panel);
  flex-shrink: 0;
}
.viewer-topnav-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}

/* -"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"-
       VIEWS: STUDIO & INTEGRATION
       -"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"--"- */
#view-studio,
#view-integration {
  flex-direction: column;
  background: var(--bg-app);
  overflow-y: auto;
}
.content-view-header {
  padding: 40px 48px 32px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-panel);
  flex-shrink: 0;
}
.content-view-header h2 {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 6px;
}
.content-view-header p {
  font-size: 15px;
  color: var(--text-muted);
}
.content-view-body {
  padding: 32px 48px;
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
}
.content-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  flex: 1;
  min-width: 320px;
}
.content-card h3 {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 16px;
}

@media (max-width: 1680px) {
  :root {
    --sidebar-w: 204px;
    --chat-open-width: clamp(410px, 36vw, 520px);
  }
  .thread-area {
    padding: 18px;
  }
  body.board-mode .thread-area {
    padding: 18px 18px 14px;
  }
  body.board-mode .composer-panel {
    padding: 14px 16px;
  }
  body.board-mode .sequence-bar,
  body.board-mode .demo-bar {
    flex-wrap: wrap;
    align-items: flex-start;
  }
  body.board-mode .sequence-bar-actions,
  body.board-mode .demo-bar-actions {
    width: 100%;
    justify-content: flex-end;
  }
  body.board-mode .sequence-preview,
  body.board-mode .demo-preview {
    white-space: normal;
    overflow: visible;
    text-overflow: initial;
    line-height: 1.35;
  }
  .lesson-speed-wrap {
    order: -1;
  }
}

@media (max-width: 1420px) {
  :root {
    --sidebar-w: 84px;
    --chat-open-width: clamp(390px, 41vw, 470px);
  }
  body.board-mode .chat-container {
    min-width: 390px;
  }
  .sidebar-logo {
    justify-content: center;
    padding-inline: 12px;
  }
  .sidebar-logo-text,
  .nav-item {
    font-size: 0;
  }
  .nav-item {
    justify-content: center;
    gap: 0;
    padding-inline: 0;
  }
  .nav-item svg {
    opacity: 1;
  }
  #sidebar-toggle {
    left: var(--sidebar-w);
  }
}
.thinking-box {
  margin: 8px 12px;
  border-left: 3px solid var(--accent-color);
  padding: 10px 14px;
  background: var(--bg-panel-secondary);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-muted);
  transition: var(--transition-smooth);
}
.thinking-box.collapsed .thinking-content {
  display: none;
}
.thinking-box.collapsed {
  cursor: pointer;
  padding: 6px 14px;
}
.thinking-box.collapsed:hover {
  background: var(--accent-color-bg);
}
.thinking-header {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted-2);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.thinking-box.collapsed .thinking-header {
  margin-bottom: 0;
}
.thinking-content {
  line-height: 1.5;
  white-space: pre-wrap;
  font-family: monospace;
  opacity: 0.8;
}

.pilot-auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(248, 252, 255, 0.92);
  backdrop-filter: blur(10px);
}
.pilot-auth-overlay.visible {
  display: flex;
}
.pilot-auth-card {
  width: min(440px, 100%);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(15, 43, 70, 0.16);
  padding: 28px;
}
.pilot-auth-card h2 {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 900;
  color: var(--text-main);
}
.pilot-auth-card p {
  margin: 0 0 18px;
  color: var(--text-muted);
  line-height: 1.5;
}
.pilot-auth-card label {
  display: block;
  font-size: 12px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  margin: 12px 0 6px;
}
.pilot-auth-card input {
  width: 100%;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 13px 14px;
  font-size: 15px;
  outline: none;
}
.pilot-auth-card input:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 4px rgba(0, 145, 234, 0.12);
}
.pilot-auth-card button {
  width: 100%;
  margin-top: 18px;
  border: none;
  border-radius: 14px;
  padding: 13px 16px;
  background: var(--accent-color);
  color: white;
  font-weight: 900;
  cursor: pointer;
}
.pilot-auth-hint {
  margin: 12px 0 0;
  color: #31516f;
  font-size: 13px;
}
.pilot-auth-hint:empty {
  display: none;
}
.pilot-auth-error {
  min-height: 20px;
  margin-top: 12px;
  color: #c62828;
  font-size: 13px;
}
.pilot-notice {
  margin-top: 16px;
  padding: 12px;
  border-radius: 14px;
  background: #eef8ff;
  color: #31516f;
  font-size: 13px;
  line-height: 1.45;
}
.btn-cancel-ai {
  display: none;
  min-height: 42px;
  border: 1px solid #ffc5c5;
  background: #fff5f5;
  color: #b42318;
  border-radius: 18px;
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
}
body.ai-busy .btn-cancel-ai {
  display: inline-flex;
  align-items: center;
}
body.ai-busy .btn-send {
  opacity: 0.55;
  pointer-events: none;
}

@media (max-width: 980px) {
  :root {
    --sidebar-w: 0px;
    --chat-open-width: min(420px, 100vw);
  }
  #global-sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    width: 224px;
    min-width: 224px;
    box-shadow: 14px 0 40px rgba(15, 23, 42, 0.08);
  }
  #global-sidebar.collapsed {
    width: 0;
    min-width: 0;
  }
  body.board-mode .workspace {
    flex-direction: column;
  }
  body.board-mode .chat-container {
    flex: 0 0 42%;
    max-width: 100%;
    min-width: 0;
    border-right: 0;
    border-bottom: 1px solid var(--border-color);
  }
  .whiteboard-container {
    min-height: 0;
  }
  .board-header {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 76px;
    align-items: start;
    padding-block: 10px;
  }
  .board-steps {
    justify-content: flex-start;
    overflow-x: auto;
    max-width: 100%;
    padding-bottom: 2px;
  }
  .viewport-panel {
    left: 12px;
    right: 12px;
    bottom: 44px;
    width: auto;
    max-width: none;
  }
  .composer-suggestions {
    overflow-x: auto;
    padding-bottom: 2px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* Phase 3 accessibility and responsive hardening */
.thread-area[aria-busy="true"] {
  cursor: progress;
}
.message.streaming-message .bubble::after {
  content: "";
  display: inline-block;
  width: 0.48em;
  height: 1em;
  margin-left: 0.2em;
  vertical-align: -0.12em;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.45;
  animation: prisma-stream-caret 0.9s steps(1, end) infinite;
}
.message.stream-complete .bubble::after {
  display: none;
}
@keyframes prisma-stream-caret {
  50% {
    opacity: 0;
  }
}

button,
[role="button"],
input,
textarea,
select {
  touch-action: manipulation;
}

@media (max-width: 680px) {
  .chat-topbar {
    min-height: 98px;
    height: auto;
    padding: 7px 10px;
    gap: 6px;
    flex-wrap: wrap;
    align-content: center;
  }
  .chat-topbar-brand {
    display: none;
  }
  .mode-selector {
    order: 1;
  }
  .topbar-actions {
    display: contents;
  }
  .topbar-actions .btn-secondary,
  .topbar-actions .status-badge {
    padding: 6px 8px;
    font-size: 11px;
  }
  .status-badge {
    gap: 5px;
  }
  #statusLabel {
    max-width: 68px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .workspace {
    min-width: 0;
  }
  .chat-container {
    flex-basis: 100%;
    width: 100%;
  }
  body.board-mode .chat-container {
    flex: 0 0 min(48vh, 430px);
  }
  body.board-mode .whiteboard-container {
    min-height: 48vh;
  }
  .input-wrapper {
    gap: 6px;
    align-items: flex-end;
  }
  .input-wrapper textarea {
    min-width: 0;
  }
  .composer-mode-toggle .mode-label {
    display: none;
  }
  .composer-mode-toggle,
  .btn-send,
  .btn-cancel-ai,
  .btn-step,
  .icon-btn {
    min-width: 44px;
    min-height: 44px;
  }
  .btn-cancel-ai {
    padding-inline: 10px;
  }
  .board-header {
    padding-inline: 10px;
  }
  .board-steps {
    scroll-snap-type: x proximity;
  }
  .board-steps > * {
    scroll-snap-align: start;
  }
  .viewport-panel {
    max-height: min(48vh, 360px);
    overflow: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .message.streaming-message .bubble::after {
    animation: none !important;
    opacity: 0.35;
  }
}

/* Accessibility gate: component rules may remove native outlines, but never the
   keyboard-visible focus indicator. Kept last and important intentionally. */
button:focus-visible,
textarea:focus-visible,
input:focus-visible,
select:focus-visible,
a[href]:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid rgba(0, 114, 178, 0.82) !important;
  outline-offset: 3px !important;
}
