:root {
  --bg: #f1f4f7;
  --bg-strong: #e8eef4;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-strong: #eef2f6;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #0f766e;
  --accent-strong: #0b5d56;
  --accent-soft: rgba(15, 118, 110, 0.12);
  --danger: #dc2626;
  --warning: #b45309;
  --success: #15803d;
  --shadow-sm: 0 6px 18px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 18px 45px rgba(15, 23, 42, 0.12);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --sidebar-width: 260px;
  --transition: 180ms ease;
  --font-sans: "IBM Plex Sans", "Space Grotesk", "Helvetica Neue", sans-serif;
  --font-mono: "IBM Plex Mono", "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

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

html,
body {
  height: 100%;
}

body.app-body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text);
  background-color: var(--bg);
  line-height: 1.5;
}

body.app-body.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
  background:
    radial-gradient(circle at top, rgba(15, 118, 110, 0.16), transparent 55%),
    var(--bg);
}

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

a:hover {
  color: var(--accent-strong);
}

img {
  max-width: 100%;
  display: block;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
  z-index: 35;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: rgba(248, 250, 252, 0.98);
  border-right: 1px solid var(--border);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  z-index: 40;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-title {
  font-weight: 600;
  font-size: 16px;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 2px;
}

.sidebar-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  padding-left: 6px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}

.nav-link:hover {
  background: var(--surface-soft);
}

.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  box-shadow: inset 0 0 0 1px rgba(15, 118, 110, 0.18);
}

.nav-icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
}

.nav-icon svg {
  width: 18px;
  height: 18px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.sidebar-meta {
  font-size: 12px;
  color: var(--muted);
}

.app-main {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

body.editor-fullscreen .sidebar,
body.editor-fullscreen .sidebar-backdrop,
body.editor-fullscreen .topbar,
body.editor-fullscreen .page-header {
  display: none;
}

body.editor-fullscreen .app-main {
  margin-left: 0;
}

body.editor-fullscreen .main-content {
  padding: 0;
}

body.editor-fullscreen .content-inner {
  max-width: none;
  padding: 0;
}

body.curriculum-chat-page .sidebar,
body.curriculum-chat-page .sidebar-backdrop {
  display: none;
}

body.curriculum-chat-page .app-main {
  margin-left: 0;
}

body.curriculum-chat-page .topbar {
  padding-left: 24px;
}

body.curriculum-chat-page .sidebar-toggle {
  display: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: 64px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.topbar-title .title {
  font-size: 18px;
  font-weight: 600;
}

.topbar-title .subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-link {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid transparent;
  transition: border var(--transition), color var(--transition);
}

.topbar-link:hover {
  border-color: var(--border);
  color: var(--text);
}

.topbar-chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: #0f172a;
  color: #fff;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.topbar-user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-size: 12px;
}

.topbar-user-name {
  font-weight: 600;
}

.topbar-user-role {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.sidebar-toggle {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
}

.sidebar-toggle span {
  width: 16px;
  height: 2px;
  border-radius: 999px;
  background: var(--text);
}

.main-content {
  flex: 1;
}

.content-inner {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 28px 48px;
  animation: page-fade 0.4s ease;
}

.content-wide {
  max-width: 1400px;
}

.content-narrow {
  max-width: 940px;
}

.content-inner[dir="rtl"] {
  text-align: right;
}

.content-inner[dir="rtl"] input,
.content-inner[dir="rtl"] select,
.content-inner[dir="rtl"] textarea {
  direction: rtl;
}

.content-inner[dir="rtl"] th,
.content-inner[dir="rtl"] td {
  text-align: right;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.page-header h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.02em;
}

.page-header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.page-header-actions {
  display: flex;
  gap: 10px;
}

.eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.card,
.panel,
.box,
.form-box,
.book-box,
.storyboard-card,
.story-card,
.scene-card,
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.auth-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-md);
}

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

.auth-mark {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: var(--shadow-sm);
}

.auth-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.auth-brand-title {
  font-weight: 600;
  font-size: 16px;
}

.auth-brand-subtitle {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin-top: 2px;
}

.auth-title {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 6px;
}

.auth-subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 16px;
}

.auth-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}

.auth-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.auth-footer {
  margin-top: 16px;
  font-size: 12px;
  color: var(--muted);
}

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

.container {
  max-width: 1200px;
  margin: 0 auto;
}

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

.unit-box {
  background: var(--surface-soft);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 12px 0 8px 18px;
}

.lesson-box {
  background: #fff;
  border-left: 3px solid #22c55e;
  border-radius: 8px;
  padding: 8px 10px;
  margin: 8px 0 6px 36px;
}

.form-box {
  margin-bottom: 20px;
}

.tile {
  display: block;
  transition: transform var(--transition), box-shadow var(--transition);
}

.tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.grid,
.card-grid,
.storyboard-grid,
.cards,
.scene-grid {
  display: grid;
  gap: 16px;
}

.grid {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card-grid {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.storyboard-grid {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.scene-grid {
  grid-template-columns: 1fr;
}

.cards {
  grid-template-columns: 1fr;
}

.nav-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 18px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
}

.nav-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.nav-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.nav-card-title {
  font-weight: 600;
  font-size: 15px;
}

.nav-card-desc {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

.stat-card {
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.12), rgba(15, 23, 42, 0.02));
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}

.stat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stat-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.stat-value {
  font-size: 26px;
  font-weight: 600;
  margin-top: 6px;
}

.stat-meta {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

.section-divider {
  margin: 30px 0 32px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(15, 23, 42, 0.12), transparent);
}

.answer,
.sources {
  margin-top: 16px;
  padding: 14px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.icon {
  width: 18px;
  height: 18px;
  vertical-align: middle;
}

h2,
h3,
h4 {
  margin: 0 0 12px;
}

h1 {
  font-size: 24px;
  margin: 0 0 12px;
}

p {
  margin: 0 0 12px;
}

label {
  display: block;
  margin-top: 12px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: var(--font-sans);
  background: #fff;
}

input[type="checkbox"] {
  width: auto;
  margin: 0 6px 0 0;
  padding: 0;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

.output-area {
  min-height: 320px;
  font-family: var(--font-mono);
}

.scene-editor {
  min-height: 120px;
  background: #fff;
}

.scene-output {
  margin-bottom: 16px;
}

.scene-fallback {
  background: #fff;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

pre,
code {
  font-family: var(--font-mono);
}

pre {
  white-space: pre-wrap;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.btn,
.submit-btn,
.add-btn,
.btn-secondary,
.prompt-btn,
.edit-btn,
.convert-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 10px;
  margin-top: 10px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
  text-decoration: none;
}

.submit-btn {
  width: 100%;
}

.btn:hover,
.submit-btn:hover,
.add-btn:hover,
.convert-btn:hover {
  transform: translateY(-1px);
  background: var(--accent-strong);
  box-shadow: var(--shadow-sm);
}

.btn.secondary,
.btn-secondary,
.prompt-btn {
  background: var(--surface-soft);
  color: var(--text);
  border-color: var(--border);
}

.btn.secondary:hover,
.btn-secondary:hover,
.prompt-btn:hover {
  background: var(--surface-strong);
}

.btn.inline {
  width: auto;
  padding: 8px 12px;
  font-size: 12px;
}

.btn-danger,
.danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: #b91c1c;
}

.edit-btn {
  background: #0f172a;
}

.edit-btn:hover {
  background: #111827;
}

.badge,
.pill,
.tag,
.story-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--surface-strong);
  color: var(--text);
}

.pill {
  background: rgba(15, 118, 110, 0.12);
  color: var(--accent-strong);
}

.story-tag {
  background: rgba(30, 64, 175, 0.12);
  color: #1e3a8a;
}

.alert,
.message {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  margin-bottom: 14px;
}

.alert-success,
.message.success,
.success {
  background: rgba(22, 163, 74, 0.12);
  border-color: rgba(22, 163, 74, 0.25);
  color: #166534;
}

.alert-error,
.message.error,
.error {
  background: rgba(220, 38, 38, 0.12);
  border-color: rgba(220, 38, 38, 0.25);
  color: #991b1b;
}

.danger-zone {
  border: 1px dashed rgba(220, 38, 38, 0.45);
  background: rgba(220, 38, 38, 0.08);
}

.hint,
.meta,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.row-actions,
.action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.section {
  margin-top: 20px;
}

.pill-list {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.lesson-entries {
  display: grid;
  gap: 12px;
}

.progress-list {
  margin: 10px 0 0;
  padding-left: 18px;
}

.progress-shell {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  transition: width 0.4s ease;
}

.progress-bar.is-running {
  background-size: 200% 100%;
  animation: progress-sheen 1.2s linear infinite;
}

.progress-status {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.progress-list li {
  margin: 4px 0;
  font-size: 13px;
}

.progress-list li.ok {
  color: var(--success);
}

.progress-list li.error {
  color: var(--danger);
}

.progress-list li.processing {
  color: var(--muted);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin: 10px 0 14px;
}

.permission-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  font-size: 13px;
  margin-top: 0;
  font-weight: 500;
}

.user-card {
  margin-top: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: 14px;
}

th {
  color: var(--muted);
  font-weight: 600;
  background: var(--surface-soft);
}

details {
  border-radius: var(--radius-md);
}

summary {
  list-style: none;
}

summary::-webkit-details-marker {
  display: none;
}

.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.lesson-text {
  white-space: pre-wrap;
  overflow: auto;
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  flex: 1;
}

.pdf-frame {
  border: none;
  width: 100%;
  min-height: 60vh;
}

.scene-table th,
.scene-table td {
  border: 1px solid var(--border);
  padding: 8px;
  text-align: left;
}

.scene-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.scene-table th {
  background: var(--surface-soft);
}

.scene-image {
  width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  object-fit: contain;
}

.scene-image-placeholder {
  width: 100%;
  min-height: 180px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: var(--surface-soft);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  padding: 12px;
  text-align: center;
}

.storyboard-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.story-title,
.scene-title {
  font-weight: 600;
}

.story-meta,
.scene-status,
.scene-fields,
.asset-note {
  font-size: 12px;
  color: var(--muted);
}

.scene-fields div {
  margin-top: 6px;
}

.scene-body {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 2fr;
  gap: 16px;
  align-items: start;
}

.scene-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.scene-summary {
  font-size: 13px;
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
}

.storyboard-rendered {
  margin-top: 10px;
  background: var(--surface-soft);
  border-radius: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  direction: rtl;
  text-align: right;
}

.storyboard-rendered .scene-table th,
.storyboard-rendered .scene-table td {
  text-align: right;
}

.story-card summary {
  cursor: pointer;
  font-weight: 600;
}

.editor-area {
  min-height: 320px;
  direction: rtl;
  text-align: right;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

.modal {
  width: min(900px, 96vw);
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  padding: 18px;
}

.modal textarea {
  min-height: 240px;
}

.modal pre {
  max-height: 60vh;
  overflow: auto;
}

.modal-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.disabled {
  opacity: 0.6;
  pointer-events: none;
}

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

.card-grid > *,
.grid > *,
.cards > *,
.storyboard-grid > *,
.scene-grid > * {
  animation: card-rise 0.35s ease both;
}

.card-grid > *:nth-child(1),
.grid > *:nth-child(1),
.cards > *:nth-child(1),
.storyboard-grid > *:nth-child(1),
.scene-grid > *:nth-child(1) {
  animation-delay: 0.05s;
}

.card-grid > *:nth-child(2),
.grid > *:nth-child(2),
.cards > *:nth-child(2),
.storyboard-grid > *:nth-child(2),
.scene-grid > *:nth-child(2) {
  animation-delay: 0.1s;
}

.card-grid > *:nth-child(3),
.grid > *:nth-child(3),
.cards > *:nth-child(3),
.storyboard-grid > *:nth-child(3),
.scene-grid > *:nth-child(3) {
  animation-delay: 0.15s;
}

@keyframes card-rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes progress-sheen {
  0% {
    background-position: 0% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

@media (max-width: 980px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform var(--transition);
  }

  .app-main {
    margin-left: 0;
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .scene-body {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .content-inner {
    padding: 22px 18px 40px;
  }

  .topbar {
    padding: 0 16px;
  }
}

.page-header-tight {
  margin-bottom: 16px;
}

.content-chat {
  max-width: none;
  padding-bottom: 28px;
}

.chat-migration-card {
  max-width: 780px;
}

.chat-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  min-height: calc(100vh - 170px);
}

.chat-conversations,
.chat-stage {
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
}

.chat-conversations {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-conversations-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.08), rgba(15, 23, 42, 0.02)),
    var(--surface);
}

.chat-conversations-head h2,
.chat-stage-head h2 {
  margin: 0;
}

.chat-new-button {
  margin-top: 0;
  white-space: nowrap;
}

.chat-conversation-list {
  flex: 1;
  overflow: auto;
  padding: 10px;
}

.chat-empty-list {
  padding: 16px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 13px;
}

.chat-conversation-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 14px 12px;
  margin: 0;
  border: 1px solid transparent;
  border-radius: 16px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}

.chat-conversation-item + .chat-conversation-item {
  margin-top: 6px;
}

.chat-conversation-item:hover {
  background: var(--surface-soft);
  border-color: var(--border);
  transform: translateY(-1px);
}

.chat-conversation-item.is-active {
  background: rgba(15, 118, 110, 0.1);
  border-color: rgba(15, 118, 110, 0.22);
}

.chat-conversation-title {
  font-size: 14px;
  font-weight: 600;
}

.chat-conversation-preview,
.chat-conversation-time {
  color: var(--muted);
  font-size: 12px;
}

.chat-stage {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.chat-stage-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--border);
  background:
    radial-gradient(circle at top right, rgba(15, 118, 110, 0.12), transparent 45%),
    var(--surface);
}

.chat-stage-eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin-bottom: 6px;
}

.chat-stage-meta {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  padding-top: 6px;
}

.chat-flash {
  margin: 14px 22px 0;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  font-size: 13px;
}

.chat-flash.is-error {
  border-color: rgba(220, 38, 38, 0.24);
  background: rgba(220, 38, 38, 0.08);
  color: #991b1b;
}

.chat-flash.is-success {
  border-color: rgba(21, 128, 61, 0.24);
  background: rgba(21, 128, 61, 0.08);
  color: #166534;
}

.chat-thread {
  overflow: auto;
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background:
    radial-gradient(circle at top, rgba(15, 118, 110, 0.05), transparent 35%),
    linear-gradient(180deg, rgba(248, 250, 252, 0.8), rgba(255, 255, 255, 0.95));
}

.chat-empty-thread {
  margin: auto;
  max-width: 520px;
  text-align: center;
  padding: 36px 28px;
  border: 1px dashed var(--border);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.72);
}

.chat-empty-thread h3 {
  margin: 0 0 10px;
}

.chat-empty-thread p {
  margin: 0;
  color: var(--muted);
}

.chat-empty-icon {
  width: 58px;
  height: 58px;
  margin: 0 auto 16px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent-strong);
  background: rgba(15, 118, 110, 0.12);
  border: 1px solid rgba(15, 118, 110, 0.18);
}

.chat-message {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.chat-message-user {
  justify-content: flex-end;
}

.chat-avatar {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.chat-avatar-assistant {
  color: var(--accent-strong);
  background: rgba(15, 118, 110, 0.12);
  border: 1px solid rgba(15, 118, 110, 0.18);
}

.chat-avatar-user {
  color: #fff;
  background: linear-gradient(135deg, #0f172a, #1f2937);
  border: 1px solid rgba(15, 23, 42, 0.22);
}

.chat-bubble {
  max-width: min(860px, 82%);
  border-radius: 20px;
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}

.chat-bubble-user {
  background: linear-gradient(135deg, #0f766e, #0f5f86);
  color: #fff;
  border-bottom-right-radius: 8px;
}

.chat-bubble-assistant {
  background: #fff;
  border: 1px solid var(--border);
  border-bottom-left-radius: 8px;
}

.chat-message-text {
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
}

.chat-scope-badge {
  margin-top: 12px;
  display: inline-flex;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 11px;
  line-height: 1.3;
}

.chat-message-time,
.chat-answer-time {
  color: var(--muted);
  font-size: 11px;
}

.chat-message-time {
  margin-top: 10px;
  color: rgba(255, 255, 255, 0.75);
}

.chat-answer-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}

.chat-answer-icon {
  display: inline-flex;
  width: 30px;
  height: 30px;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(15, 23, 42, 0.08);
}

.chat-answer-icon svg {
  width: 18px;
  height: 18px;
}

.chat-answer-label {
  font-size: 13px;
  font-weight: 700;
}

.chat-answer-time {
  margin-left: auto;
}

.answer-type-textbook .chat-bubble-assistant {
  border-left: 4px solid #2563eb;
  background: linear-gradient(180deg, rgba(239, 246, 255, 0.88), #ffffff 45%);
}

.answer-type-textbook .chat-answer-icon,
.answer-type-textbook .chat-answer-label {
  color: #1d4ed8;
}

.answer-type-curriculum .chat-bubble-assistant {
  border-left: 4px solid #0f766e;
  background: linear-gradient(180deg, rgba(240, 253, 250, 0.92), #ffffff 45%);
}

.answer-type-curriculum .chat-answer-icon,
.answer-type-curriculum .chat-answer-label {
  color: #0f766e;
}

.answer-type-tool .chat-bubble-assistant {
  border-left: 4px solid #b45309;
  background: linear-gradient(180deg, rgba(255, 251, 235, 0.92), #ffffff 45%);
}

.answer-type-tool .chat-answer-icon,
.answer-type-tool .chat-answer-label {
  color: #b45309;
}

.answer-type-out_of_scope .chat-bubble-assistant {
  border-left: 4px solid #dc2626;
  background: linear-gradient(180deg, rgba(254, 242, 242, 0.92), #ffffff 45%);
}

.answer-type-out_of_scope .chat-answer-icon,
.answer-type-out_of_scope .chat-answer-label {
  color: #b91c1c;
}

.chat-evidence {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(15, 23, 42, 0.08);
}

.chat-evidence-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 10px;
}

.chat-evidence-item {
  padding: 12px 13px;
  border-radius: 14px;
  border: 1px solid rgba(37, 99, 235, 0.14);
  background: rgba(255, 255, 255, 0.76);
}

.chat-evidence-item + .chat-evidence-item {
  margin-top: 10px;
}

.chat-evidence-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.chat-evidence-meta {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

.chat-evidence-excerpt {
  margin-top: 8px;
  font-size: 12px;
  color: #334155;
  line-height: 1.6;
}

.chat-composer {
  padding: 18px 22px 20px;
  border-top: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(248, 250, 252, 0.96), rgba(255, 255, 255, 0.98));
}

.chat-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.chat-filter {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.chat-filter span {
  display: block;
  margin-bottom: 6px;
}

.chat-filter select {
  margin-top: 0;
  padding: 9px 10px;
  font-size: 13px;
}

.chat-input-wrap textarea {
  min-height: 112px;
  margin-top: 0;
  border-radius: 16px;
  resize: vertical;
  padding: 14px 15px;
}

.chat-composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 14px;
}

.chat-composer-note {
  color: var(--muted);
  font-size: 12px;
}

.chat-send-button {
  margin-top: 0;
  min-width: 116px;
}

@media (max-width: 1180px) {
  .chat-shell {
    grid-template-columns: 1fr;
  }

  .chat-conversations {
    min-height: 240px;
    max-height: 320px;
  }
}

@media (max-width: 860px) {
  .chat-stage-head,
  .chat-conversations-head,
  .chat-thread,
  .chat-composer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .chat-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chat-composer-foot {
    flex-direction: column;
    align-items: stretch;
  }

  .chat-bubble {
    max-width: 100%;
  }
}

@media (max-width: 560px) {
  .chat-filters {
    grid-template-columns: 1fr;
  }

  .chat-message {
    gap: 10px;
  }

  .chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 12px;
  }

  .chat-bubble {
    padding: 14px;
  }

  .chat-stage-meta {
    white-space: normal;
  }
}

/* Curriculum Chat layout refresh */
.content-chat {
  max-width: none;
  padding: 0;
  height: calc(100vh - 64px);
}

.chat-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 0;
  height: 100%;
  min-height: 100%;
}

.chat-conversations,
.chat-stage {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.chat-conversations {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 18px 12px 14px;
  border-right: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.38);
}

.chat-sidebar-brand {
  padding: 6px 8px 18px;
}

.chat-sidebar-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.chat-sidebar-subtitle {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.chat-new-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  transition: background var(--transition), transform var(--transition), border-color var(--transition);
}

.chat-new-button:hover {
  transform: translateY(-1px);
  background: #fff;
  border-color: rgba(15, 23, 42, 0.14);
}

.chat-new-plus {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.1);
  color: var(--accent-strong);
  font-size: 18px;
  line-height: 1;
}

.chat-sidebar-label {
  padding: 0 8px 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.chat-conversation-list {
  flex: 1;
  overflow: auto;
  padding: 0 2px;
}

.chat-empty-list {
  padding: 12px 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
}

.chat-conversation-item {
  width: 100%;
  display: block;
  padding: 12px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  transition: background var(--transition), transform var(--transition);
}

.chat-conversation-item + .chat-conversation-item {
  margin-top: 4px;
}

.chat-conversation-item:hover {
  background: rgba(255, 255, 255, 0.55);
  transform: translateY(-1px);
}

.chat-conversation-item.is-active {
  background: rgba(15, 118, 110, 0.1);
}

.chat-conversation-preview,
.chat-conversation-time {
  display: none;
}

.chat-conversation-title {
  display: block;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
}

.chat-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.chat-stage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 24px 34px 0;
  border: 0;
  background: transparent;
}

.chat-stage-head h2 {
  font-size: 28px;
  letter-spacing: -0.03em;
}

.chat-stage-head-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-scope-button,
.chat-preview-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--accent-strong);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), border-color var(--transition);
}

.chat-preview-button:hover {
  transform: translateY(-1px);
  background: #fff;
  border-color: rgba(15, 23, 42, 0.18);
}

.chat-scope-button svg,
.chat-preview-button svg {
  width: 18px;
  height: 18px;
}

.chat-stage-meta {
  display: flex;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}

.chat-stage-meta-date:empty {
  display: none;
}

.chat-empty-state .chat-stage-head {
  min-height: 64px;
  padding: 18px 34px 0;
}

.chat-empty-state .chat-stage-head h2 {
  display: none;
}

.chat-flash {
  max-width: 920px;
  width: calc(100% - 68px);
  margin: 0 auto 14px;
  border-radius: 16px;
}

.chat-thread {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 18px 34px 190px;
  background: transparent;
}

.chat-empty-thread {
  max-width: 760px;
  min-height: calc(100vh - 260px);
  margin: 0 auto;
  padding: 0 18px 40px;
  border: 0;
  border-radius: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.chat-empty-mark {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  margin-bottom: 18px;
  background: rgba(15, 118, 110, 0.1);
  color: var(--accent-strong);
  font-size: 24px;
  line-height: 1;
}

.chat-empty-thread h3 {
  margin: 0 0 10px;
  font-size: clamp(34px, 5vw, 60px);
  font-weight: 500;
  letter-spacing: -0.04em;
  line-height: 1.05;
}

.chat-empty-thread p {
  max-width: 620px;
  margin: 0;
  font-size: 15px;
  color: var(--muted);
}

.chat-message {
  width: min(980px, 100%);
  margin: 0 auto;
}

.chat-message + .chat-message {
  margin-top: 18px;
}

.chat-message-user {
  display: flex;
  justify-content: flex-end;
}

.chat-message-assistant {
  display: block;
}

.chat-avatar {
  display: none;
}

.chat-bubble {
  max-width: none;
  box-shadow: none;
}

.chat-bubble-user {
  max-width: min(340px, 78%);
  padding: 14px 18px;
  border-radius: 18px;
  background: rgba(15, 118, 110, 0.08);
  color: var(--text);
  border: 1px solid rgba(15, 118, 110, 0.12);
}

.chat-bubble-assistant {
  width: 100%;
  padding: 18px 22px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(15, 23, 42, 0.08);
}

.chat-message-media {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

.chat-message-image-link {
  display: block;
}

.chat-message-image {
  display: block;
  width: min(320px, 100%);
  max-height: 280px;
  object-fit: cover;
  border-radius: 16px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.9);
}

.chat-message-assistant.chat-message-rtl .chat-message-text {
  direction: rtl;
  text-align: right;
}

.chat-message-assistant.chat-message-rtl .chat-answer-head {
  direction: ltr;
}

.chat-message-text {
  font-size: 15px;
  line-height: 1.9;
}

.chat-math-fraction {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  vertical-align: middle;
  margin: 0 0.18em;
  min-width: 1.8em;
  text-align: center;
  unicode-bidi: isolate;
}

.chat-math-inline {
  display: inline-block;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
}

.chat-math-inline-tex,
.chat-inline-ltr {
  display: inline-block;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
}

.chat-math-display {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: center;
  margin: 0.45rem 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.chat-math-display mjx-container[jax="CHTML"] {
  margin: 0 auto !important;
}

.chat-math-inline-tex mjx-container[jax="CHTML"],
.chat-inline-ltr mjx-container[jax="CHTML"] {
  margin: 0 !important;
}

.chat-math-arabic-token {
  direction: rtl;
  unicode-bidi: plaintext;
}

.chat-math-display-fallback,
.chat-math-inline-fallback {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: center;
}

.chat-math-arabic-text {
  display: inline-block;
  direction: rtl;
  unicode-bidi: plaintext;
  text-align: right;
}

.chat-math-case-brace {
  display: inline-block;
  padding: 0 0.12em;
}

.chat-math-num,
.chat-math-den {
  display: block;
  padding: 0 0.12em;
  line-height: 1.2;
}

.chat-math-num {
  padding-bottom: 0.08em;
  border-bottom: 1px solid currentColor;
}

.chat-math-den {
  padding-top: 0.08em;
}

.chat-scope-badge {
  margin-top: 10px;
  background: rgba(15, 23, 42, 0.06);
  border: 1px solid rgba(15, 23, 42, 0.08);
  color: var(--muted);
}

.chat-message-time {
  color: var(--muted);
}

.chat-answer-head {
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 12px;
}

.chat-answer-icon {
  width: 28px;
  height: 28px;
}

.chat-answer-icon svg {
  width: 16px;
  height: 16px;
}

.chat-answer-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.chat-answer-time {
  margin-left: auto;
}

.chat-evidence {
  margin-top: 18px;
  padding-top: 16px;
}

.chat-evidence-title {
  margin-bottom: 12px;
}

.chat-evidence-item {
  border-radius: 16px;
}

.chat-composer {
  position: sticky;
  bottom: 0;
  padding: 0 24px 22px;
  border: 0;
  background: linear-gradient(180deg, rgba(241, 244, 247, 0), rgba(241, 244, 247, 0.96) 32%, rgba(241, 244, 247, 1) 100%);
}

.chat-composer-shell {
  position: relative;
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 18px 18px 14px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
}

.chat-input-wrap textarea {
  min-height: 72px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  resize: none;
  font-size: 17px;
  line-height: 1.6;
  box-shadow: none;
}

.chat-input-wrap textarea:focus {
  outline: none;
  box-shadow: none;
}

.chat-is-sending .chat-composer-shell > :not(.chat-compose-loading) {
  opacity: 0.28;
  pointer-events: none;
}

.chat-attachment-strip {
  margin-top: 14px;
}

.chat-attachment-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 18px;
  background: rgba(248, 250, 252, 0.92);
}

.chat-attachment-thumb {
  width: 62px;
  height: 62px;
  border-radius: 14px;
  object-fit: cover;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: #fff;
}

.chat-attachment-copy {
  min-width: 0;
  flex: 1;
}

.chat-attachment-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}

.chat-attachment-note {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.chat-attachment-remove {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.08);
  color: var(--text);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 16px;
}

.chat-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.chat-icon-button-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.chat-attach-button {
  position: relative;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), border-color var(--transition);
}

.chat-attach-button:hover {
  transform: translateY(-1px);
  background: #fff;
  border-color: rgba(15, 23, 42, 0.18);
}

.chat-attach-button svg,
.chat-scope-button svg,
.chat-send-button svg {
  width: 19px;
  height: 19px;
}

.chat-scope-button {
  position: relative;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 999px;
  background: rgba(229, 243, 244, 0.92);
  color: var(--accent-strong);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), border-color var(--transition);
}

.chat-scope-button:hover {
  transform: translateY(-1px);
  background: rgba(219, 238, 239, 1);
  border-color: rgba(15, 118, 110, 0.2);
}

.chat-send-button {
  position: relative;
  flex: 0 0 auto;
  width: 46px;
  min-width: 46px;
  height: 46px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  border-radius: 999px;
}

.chat-send-button.is-loading {
  opacity: 0.72;
}

.chat-toolbar-scope-label {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0 12px;
  font-size: 11px;
  line-height: 1.5;
  font-style: italic;
  color: rgba(15, 23, 42, 0.58);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-compose-loading {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(2px);
}

.chat-compose-loading[hidden] {
  display: none !important;
}

.chat-compose-loading-book {
  width: 52px;
  height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: rgba(15, 118, 110, 0.1);
  color: var(--accent-strong);
  transform-style: preserve-3d;
  animation: chat-book-flip 1.1s ease-in-out infinite;
}

.chat-compose-loading-book svg {
  width: 24px;
  height: 24px;
}

.chat-compose-loading-text {
  font-size: 13px;
  font-weight: 600;
  color: rgba(15, 23, 42, 0.72);
}

@keyframes chat-book-flip {
  0% {
    transform: perspective(320px) rotateY(0deg);
  }
  50% {
    transform: perspective(320px) rotateY(-180deg);
  }
  100% {
    transform: perspective(320px) rotateY(-360deg);
  }
}

.chat-scope-panel,
.chat-preview-panel {
  width: 520px;
  max-width: 46vw;
  height: 100%;
  display: flex;
  flex-direction: column;
  border-left: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.56);
  box-shadow: -18px 0 40px rgba(15, 23, 42, 0.08);
}

.chat-scope-panel {
  width: 420px;
  max-width: 36vw;
}

.chat-preview-panel[hidden],
.chat-scope-panel[hidden],
.chat-preview-button[hidden] {
  display: none !important;
}

.chat-scope-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
}

.chat-scope-note {
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.chat-scope-fields {
  display: grid;
  gap: 14px;
}

.chat-scope-field {
  display: grid;
  gap: 8px;
}

.chat-scope-field span {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.chat-scope-field select {
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 10px 14px;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.88);
  font-size: 14px;
  box-shadow: none;
}

.chat-scope-field select:focus {
  outline: none;
  border-color: rgba(15, 118, 110, 0.34);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1);
}

.chat-shell.chat-scope-open .chat-scope-button,
.chat-shell.chat-preview-open .chat-preview-button {
  background: rgba(15, 118, 110, 0.12);
  border-color: rgba(15, 118, 110, 0.22);
  color: var(--accent-strong);
}

.chat-preview-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}

.chat-preview-kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.chat-preview-title {
  margin-top: 6px;
  font-size: 16px;
  font-weight: 600;
}

.chat-preview-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.06);
  color: var(--text);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.chat-preview-body {
  flex: 1;
  min-height: 0;
  padding: 14px;
}

.chat-preview-frame {
  width: 100%;
  height: 100%;
  min-height: 100%;
  border: 0;
  border-radius: 22px;
  background: #fff;
}

.chat-filters,
.chat-filter,
.chat-composer-foot,
.chat-composer-note,
.chat-stage-eyebrow,
.chat-empty-icon {
  display: none;
}

.chat-shell.chat-scope-open {
  grid-template-columns: 280px minmax(0, 1fr) 420px;
}

.chat-shell.chat-preview-open {
  grid-template-columns: minmax(0, 1fr) 520px;
}

.chat-shell.chat-preview-open .chat-conversations {
  display: none;
}

@media (max-width: 980px) {
  .chat-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100vh - 64px);
  }

  .chat-conversations {
    border-right: 0;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    max-height: 230px;
  }

  .chat-shell.chat-scope-open {
    grid-template-columns: 1fr;
  }

  .chat-shell.chat-preview-open {
    grid-template-columns: 1fr;
  }

  .chat-scope-panel,
  .chat-preview-panel {
    position: fixed;
    top: 64px;
    right: 0;
    z-index: 45;
    width: min(100vw, 560px);
    max-width: 100vw;
    height: calc(100vh - 64px);
    background: rgba(255, 255, 255, 0.96);
  }

  .chat-scope-panel {
    width: min(100vw, 420px);
    max-width: 100vw;
  }

  .chat-stage-head {
    padding: 20px 22px 0;
  }

  .chat-thread {
    padding: 18px 22px 190px;
  }

  .chat-flash {
    width: calc(100% - 44px);
  }
}

@media (max-width: 760px) {
  .content-chat {
    height: auto;
    min-height: calc(100vh - 64px);
  }

  .chat-empty-thread {
    min-height: 320px;
  }

  .chat-empty-thread h3 {
    font-size: 36px;
  }

  .chat-composer {
    padding: 0 14px 16px;
  }

  .chat-composer-shell {
    padding: 14px 14px 12px;
    border-radius: 22px;
  }

  .chat-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .chat-toolbar-actions {
    width: auto;
  }

  .chat-send-button {
    width: 46px;
  }

  .chat-attach-button {
    flex: 0 0 auto;
  }

  .chat-toolbar {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .chat-toolbar-scope-label {
    order: 3;
    width: 100%;
    padding: 2px 0 0;
    text-align: left;
    white-space: normal;
  }

  .chat-preview-panel {
    top: 0;
    height: 100vh;
  }

  .chat-scope-panel {
    top: 0;
    height: 100vh;
  }
}

@media (max-width: 520px) {
  .chat-stage-head,
  .chat-thread {
    padding-left: 14px;
    padding-right: 14px;
  }

  .chat-flash {
    width: calc(100% - 28px);
  }

  .chat-bubble-user {
    max-width: 88%;
  }

  .chat-toolbar-actions {
    justify-content: flex-start;
  }

  .chat-toolbar-scope-label {
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
