:root {
  color-scheme: dark;
  --bg: #070809;
  --surface: #0e1011;
  --surface-2: #131616;
  --surface-3: #18201f;
  --text: #e8ede8;
  --muted: #9ea9a3;
  --muted-2: #6e7a75;
  --border: rgba(255, 255, 255, 0.12);
  --border-strong: color-mix(in srgb, var(--accent) 34%, transparent);
  --accent: #57dbc2;
  --accent-soft: #2eb8a6;
  --accent-text: #070809;
  --danger: #f24f42;
  --ok: #57dbc2;
  --user-bubble: #1c4740;
  --assistant-bubble: #131616;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04), 0 18px 44px rgba(0, 0, 0, 0.34);
  --radius-panel: 8px;
  --radius-control: 8px;
  --radius-chip: 8px;
  --app-height: 100dvh;
  --composer-height: 84px;
  --keyboard-inset: 0px;
  --keyboard-action-gutter: 54px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --sidebar-width: 360px;
}

@supports (height: 100svh) {
  :root { --app-height: 100svh; }
}

html {
  height: var(--app-height);
  min-height: var(--app-height);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  height: var(--app-height);
  min-height: var(--app-height);
  overflow-x: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea { font: inherit; }
button { cursor: pointer; }
button, input, textarea, article, section, aside, div { min-width: 0; }

.login-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.login-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  padding: 18px;
  display: grid;
  gap: 12px;
  box-shadow: var(--shadow);
}

.login-brand { margin-bottom: 8px; }
.login-brand strong {
  color: var(--text);
  font-size: 32px;
  line-height: 1.05;
  letter-spacing: -0.02em;
}
.login-brand span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}
.login-card label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.login-card input {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-control);
  padding: 13px;
  font-size: 16px;
}
.login-card button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  border-radius: var(--radius-control);
  padding: 12px;
  font-weight: 650;
}
.login-error { margin: 0; color: var(--danger); }

.app-shell {
  min-height: var(--app-height);
  height: var(--app-height);
  max-height: var(--app-height);
  background: var(--bg);
  display: grid;
  grid-template-columns: minmax(250px, var(--sidebar-width)) 8px minmax(0, 1fr);
  gap: 8px;
  padding: 14px;
  overflow: hidden;
}

@media (min-width: 821px) {
  body.sidebar-collapsed .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  body.sidebar-collapsed .sidebar {
    display: none;
  }

  body.sidebar-collapsed .sidebar-resizer {
    display: none;
  }
}

.sidebar,
.chat-shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
}

.sidebar {
  padding: 14px;
  max-height: calc(var(--app-height) - 28px);
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.sidebar-resizer {
  min-height: 0;
  border-radius: var(--radius-chip);
  cursor: col-resize;
  position: relative;
  touch-action: none;
}

.sidebar-resizer::before {
  content: "";
  position: absolute;
  inset: 14px 3px;
  border-left: 1px solid var(--border);
  border-right: 1px solid transparent;
}

.sidebar-resizer:hover::before,
.sidebar-resizer:focus-visible::before,
body.sidebar-resizing .sidebar-resizer::before {
  border-left-color: var(--text);
}

.sidebar-resizer:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

body.sidebar-resizing {
  cursor: col-resize;
  user-select: none;
}

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

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-chip);
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}

.brand strong {
  display: block;
  font-size: 14px;
  line-height: 1.2;
}

.brand span,
.eyebrow,
.system-card small,
.system-card p,
.sidebar-note p {
  color: var(--muted);
}

.brand span {
  display: block;
  font-size: 12px;
}

.system-card,
.sidebar-note,
.history-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 12px;
  background: var(--surface-2);
}

.mode-tabs {
  display: flex;
  width: 100%;
  gap: 5px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface-2);
}

.mode-tab,
.text-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: var(--radius-chip);
  padding: 10px 11px;
  text-align: left;
}

.mode-tab {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  min-height: 30px;
  padding: 5px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 650;
  font-size: 11px;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

.mode-tab span {
  pointer-events: none;
  min-width: 0;
  max-width: 100%;
}

.mode-tab:hover {
  background: var(--surface-3);
  color: var(--text);
}

.mode-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.mode-tab.active {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: none;
}

.mobile-status-drawer {
  display: contents;
}

.mobile-status-heading {
  display: none;
}

.mobile-push-button {
  display: none;
}

.mobile-push-button[hidden] {
  display: none;
}

#settings-reregister-push-button {
  display: none;
}

.history-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
  min-width: 0;
}

.history-card.collapsed {
  padding: 0;
  border-color: transparent;
  background: transparent;
}

.history-card.collapsed .history-heading {
  margin-bottom: 0;
  display: block;
}

.history-card.collapsed .history-heading strong,
.history-card.collapsed .heading-actions button:not([id^="toggle-"]) {
  display: none;
}

.history-card.collapsed .heading-actions,
.history-card.collapsed .text-button {
  width: 100%;
}

.history-card.collapsed .heading-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-content: stretch;
}

.history-card.collapsed .text-button {
  padding: 6px 8px;
  text-align: center;
}

.heading-actions {
  display: inline-flex;
  align-items: stretch;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
  flex: 0 1 auto;
  max-width: 100%;
  min-width: 0;
}

.collapsible-content[hidden],
.history-list[hidden] {
  display: none !important;
}

.history-heading strong {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-card .history-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.history-card .heading-actions {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
}

.history-card .heading-actions .text-button {
  padding: 3px 9px;
  font-size: 11px;
  min-height: 24px;
  line-height: 1;
}

.history-card .text-button {
  width: 100%;
}

.history-search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  margin: 8px 0;
}

.history-search input {
  min-height: 30px;
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-control);
  padding: 5px 8px;
  font-size: 12px;
}

.history-search .text-button {
  width: auto;
  min-width: 58px;
}

.text-button {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 8px;
  font-size: 12px;
  background: var(--surface-2);
  border-color: var(--border);
  white-space: nowrap;
  max-width: 100%;
}

.history-list,
.limits-list {
  max-height: 260px;
  overflow-y: auto;
  overflow-x: hidden;
  display: grid;
  gap: 7px;
  min-width: 0;
}

.history-panel {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.history-panel #history-list {
  flex: 1 1 auto;
  max-height: none;
  min-height: 0;
  align-content: start;
}

.limits-list {
  max-height: 220px;
}

.history-row {
  position: relative;
  display: block;
  min-width: 0;
}

.history-item,
.limit-item {
  width: 100%;
  min-width: 0;
  position: relative;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-chip);
  padding: 6px 8px;
  text-align: left;
}

.session-actions {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 2;
}

.history-row:hover .session-actions,
.history-row:focus-within .session-actions {
  opacity: 1;
  pointer-events: auto;
}

.session-action-button,
.history-delete-button {
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  background: color-mix(in srgb, var(--surface-2) 96%, transparent);
  color: var(--muted-2);
  font-size: 12px;
  line-height: 1;
  padding: 4px 8px;
  white-space: nowrap;
  backdrop-filter: blur(4px);
}
.session-action-button.assign { width: 26px; padding: 4px 0; display: grid; place-items: center; }
.session-action-button.assign .ui-icon { width: 14px; height: 14px; }
.session-action-button.pin { width: 26px; padding: 4px 0; display: grid; place-items: center; }
.session-action-button.pin .ui-icon { width: 14px; height: 14px; }
.session-action-button.pin.pinned { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.session-pin-mark {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  color: var(--accent);
}
.session-pin-mark .ui-icon { width: 12px; height: 12px; stroke-width: 2; fill: color-mix(in srgb, var(--accent) 35%, transparent); }
/* Touch devices have no hover: keep the row actions reachable. */
@media (hover: none) {
  .session-actions { opacity: 1; pointer-events: auto; }
}

.session-action-button.danger,
.history-delete-button.danger {
  border-color: color-mix(in srgb, var(--danger) 38%, var(--border));
  background: color-mix(in srgb, var(--surface-2) 88%, var(--danger));
  color: var(--danger);
}

.session-action-button:disabled,
.history-delete-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.session-action-button:not(:disabled):hover,
.history-delete-button:not(:disabled):hover {
  background: color-mix(in srgb, var(--surface-2) 78%, var(--border-strong));
}

.session-action-button.danger:not(:disabled):hover,
.history-delete-button.danger:not(:disabled):hover {
  background: color-mix(in srgb, var(--surface-2) 78%, var(--danger));
}

.history-item.archive {
  border-style: dashed;
  border-color: var(--border-strong);
}

.limit-item {
  display: grid;
  gap: 3px;
  border-color: color-mix(in srgb, var(--accent) 28%, transparent);
  background: color-mix(in srgb, var(--surface-2) 86%, var(--accent-soft));
}

.limit-item.exhausted {
  border-color: rgba(242, 79, 66, 0.36);
  background: color-mix(in srgb, var(--surface-2) 88%, var(--danger));
}

.history-item strong,
.history-item span,
.history-item small,
.limit-item strong,
.limit-item span,
.limit-item small {
  display: block;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-title-wrap {
  display: flex !important;
  align-items: center;
  gap: 6px;
}
.history-title-wrap strong { flex: 1 1 auto; }

.history-item strong,
.limit-item strong { font-size: 12.5px; }
.history-item span,
.history-item small,
.limit-item span,
.limit-item small,
.empty-history,
.limits-note { color: var(--muted-2); font-size: 11.5px; }
.history-item.same-mode { border-color: var(--border-strong); }
.history-item.pinned {
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent), 0 0 12px color-mix(in srgb, var(--accent) 8%, transparent);
}
.history-item.active-session {
  border: 2px solid color-mix(in srgb, var(--accent) 85%, transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent), inset 0 0 0 1px color-mix(in srgb, var(--accent) 12%, transparent);
  background: color-mix(in srgb, var(--surface-2) 88%, var(--accent-soft));
}
.history-item.running-session small:last-child,
.brain-session-run { color: var(--accent); }

.history-item.running-session {
  border-color: color-mix(in srgb, var(--accent) 70%, transparent) !important;
  background: color-mix(in srgb, var(--surface-2) 84%, var(--accent-soft)) !important;
}

.history-item.running-session::after {
  content: '';
  position: absolute;
  left: 0;
  top: 3px;
  bottom: 3px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
  animation: session-pulse 1.2s ease-in-out infinite;
}

@keyframes session-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.75); }
}

.history-snippet { color: var(--muted); line-height: 1.3; }
.history-item mark { background: color-mix(in srgb, var(--accent) 30%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.brain-sessions-card[hidden] { display: none !important; }
.limits-note { display: block; margin-top: 8px; line-height: 1.35; }

.health-connect-card .history-heading {
  margin-bottom: 6px;
}

.health-connect-card .heading-actions {
  grid-template-columns: minmax(0, 1fr);
}

.health-connect-card .limits-note {
  display: block;
}

.system-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 650;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--ok);
}

.status-dot.warn { background: var(--danger); }

.system-card p,
.sidebar-note p {
  margin: 10px 0 4px;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.system-card small {
  display: block;
  font-size: 12px;
  line-height: 1.45;
}

.sidebar-note strong {
  display: block;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chat-shell {
  min-width: 0;
  height: calc(var(--app-height) - 28px);
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  position: relative;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-header {
  grid-row: 1;
  min-height: 64px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: wrap;
}

.live-activity {
  grid-row: 2;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, max-content));
  gap: 8px;
  max-height: 96px;
  overflow: auto;
  align-content: start;
  overscroll-behavior: contain;
  flex: 0 0 auto;
}

.live-activity[hidden] { display: none; }

.activity-item {
  flex: 0 0 auto;
  max-width: min(320px, 82vw);
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  background: var(--surface-2);
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.activity-item strong { margin-right: 6px; }
.activity-item span { color: var(--muted); }

.eyebrow {
  margin: 0 0 2px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.ui-icon {
  width: 1em;
  height: 1em;
  display: inline-block;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.secondary-button {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-chip);
  padding: 8px 11px;
}

.learn-topic-actions .secondary-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.header-overflow {
  position: relative;
  flex: 0 0 auto;
}

.header-overflow-toggle {
  min-width: 38px;
  font-size: 18px;
  line-height: 1;
  padding-inline: 10px;
}

.header-overflow-toggle.active {
  border-color: var(--border-strong);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.header-overflow-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 60;
  min-width: 168px;
  display: grid;
  gap: 2px;
  padding: 6px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface-2);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

.header-overflow-menu[hidden] { display: none; }

.header-overflow-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
}

.header-overflow-item .ui-icon { width: 14px; height: 14px; }

.header-overflow-item:hover,
.header-overflow-item:focus-visible {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  outline: none;
}

.sidebar-toggle-button {
  min-width: 112px;
  text-align: center;
}

.secondary-button:focus-visible,
.text-button:focus-visible,
.talk-button:focus-visible,
.attach-button:focus-visible,
.queue-chip:focus-visible,
.text-form textarea:focus-visible,
.text-form button:focus-visible,
.approval-button:focus-visible,
.history-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.chat-workspace {
  grid-row: 3;
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 10px;
}
.messages-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  display: flex;
}
.messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  contain: layout paint style;
  overscroll-behavior: contain;
  overflow-anchor: none;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: auto;
}

.typing-indicator {
  position: absolute;
  left: 18px;
  bottom: calc(var(--composer-height) + 10px);
  z-index: 35;
  max-width: calc(100% - 36px);
  margin: 0;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  background: var(--surface-2);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2);
  pointer-events: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.typing-indicator[hidden] { display: none; }

/* Prevent last message being covered by the floating typing indicator */
.messages:has(~ .typing-indicator:not([hidden])),
.chat-workspace:has(~ .typing-indicator:not([hidden])) .messages {
  padding-bottom: 52px;
}

.typing-indicator span {
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--muted);
  animation: typing-pulse 1s infinite ease-in-out;
}

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

@keyframes typing-pulse {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

.message {
  position: relative;
  max-width: min(700px, 90%);
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 11px 13px;
  background: var(--assistant-bubble);
  overflow-wrap: anywhere;
}

.message.user {
  align-self: flex-end;
  max-width: min(600px, 80%);
  background: var(--user-bubble);
  border-color: color-mix(in srgb, var(--accent) 25%, transparent);
}

.message.assistant {
  align-self: stretch;
  width: 100%;
  max-width: 100%;
}

.message-regenerate-wrap {
  align-self: stretch;
  display: flex;
  justify-content: flex-end;
  margin: -4px 2px 8px 0;
}

.message-regenerate-button,
.message-compare-button,
.message-edit-button {
  border: 0;
  background: transparent;
  color: var(--text-muted, var(--muted));
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
  transition: color 140ms ease, opacity 140ms ease, background-color 140ms ease;
}

.message-edit-button .ui-icon { width: 14px; height: 14px; }

.message-regenerate-button,
.message-compare-button {
  padding: 5px 8px;
  border-radius: 999px;
}

.message-regenerate-button:hover,
.message-regenerate-button:focus-visible,
.message-compare-button:hover,
.message-compare-button:focus-visible,
.message-edit-button:hover,
.message-edit-button:focus-visible {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  outline: none;
}

.message-regenerate-button:disabled,
.message-compare-button:disabled,
.message-edit-button:disabled { opacity: 0.5; cursor: not-allowed; }

.message-edit-button {
  position: absolute;
  top: 7px;
  right: 8px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  opacity: 0;
}

.message.user:hover .message-edit-button,
.message.user:focus-within .message-edit-button { opacity: 1; }

.message.user.editing { cursor: default; }

.message.user.editing .message-body,
.message.user.editing .message-edit-button { display: none; }

.message-edit-form {
  display: grid;
  gap: 8px;
}

.message-edit-textarea {
  width: 100%;
  min-height: 80px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 12px;
  line-height: 1.45;
  font: inherit;
}

.message-edit-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 36%, transparent);
}

.message-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.message-edit-actions button {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  padding: 5px 10px;
  cursor: pointer;
  font-size: 0.82rem;
}

.message-edit-actions button:hover,
.message-edit-actions button:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  color: var(--accent);
  outline: none;
}

.msg-interrupted-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 0.78rem;
  color: var(--text-muted, #888);
  text-align: center;
  padding: 6px 12px;
  margin: 4px auto;
  max-width: 480px;
  background: transparent;
  border: none;
  font-style: italic;
}

.msg-interrupted-notice .ui-icon { width: 15px; height: 15px; color: var(--danger); }

.message.user.msg-queued {
  color: color-mix(in srgb, var(--text) 74%, var(--muted));
  background: color-mix(in srgb, var(--user-bubble) 68%, var(--surface-2));
  border-color: color-mix(in srgb, var(--muted) 38%, var(--border));
  opacity: 0.88;
}

.message.user.msg-queued .message-body {
  font-style: italic;
}

.message.user .queued-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: fit-content;
  margin-top: 7px;
  padding: 2px 7px;
  border: 1px solid color-mix(in srgb, var(--muted) 36%, transparent);
  border-radius: 999px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface-2) 72%, transparent);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: lowercase;
}

.message.app-prompt-card.routable {
  cursor: pointer;
  border-color: color-mix(in srgb, var(--accent) 42%, var(--border));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 15%, transparent);
}

.message.app-prompt-card.routable:hover,
.message.app-prompt-card.routable:focus-visible {
  background: color-mix(in srgb, var(--assistant-bubble) 84%, var(--accent));
  outline: none;
}

.message .route-hint {
  display: block;
  margin-top: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 650;
}

/* Where a server-written user turn came from (scheduled check-in, retried
   step): a quiet label above the text, never raw meta. Workspace reports
   are their own collapsed card (panes.css). */
.message .message-origin-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  max-width: 100%;
  margin: 0 0 6px;
  padding: 2px 9px 2px 7px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 26%, transparent);
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 650;
  line-height: 1.5;
}

.message .message-origin-chip .ui-icon {
  width: 13px;
  height: 13px;
  flex: none;
  color: var(--accent);
}

@media (forced-colors: active) {
  .message .message-origin-chip { border-color: CanvasText; }
}

.message.archive-match {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  background: color-mix(in srgb, var(--assistant-bubble) 78%, var(--accent));
}

.message .role {
  margin-bottom: 5px;
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.message p,
.message .message-body {
  margin: 0;
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Markdown rendered content inside assistant messages */
.message .message-body p {
  margin: 0 0 0.6em;
  white-space: normal;
}
.message .message-body p:last-child { margin-bottom: 0; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.artifact-preview-btn { margin: 6px 0 10px; border: 1px solid var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--surface-2)); color: var(--text); border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 700; }
.queue-chip-tray {
  grid-column: 1 / -1;
  min-width: 0;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 2px 6px;
}
.queue-chip-tray[hidden] { display:none; }
.queue-chip {
  appearance: none;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-2) 92%, white 3%);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
  max-width: min(360px, 86vw);
  overflow: hidden;
  text-overflow: ellipsis;
}
.queue-chip { display: inline-flex; align-items: center; gap: 6px; }
.queue-chip .ui-icon,
.queued-badge .ui-icon { width: 13px; height: 13px; }
.context-chip { border-color: var(--border); background: var(--surface-2); color: var(--text); }
.slash-menu { position:absolute; left:96px; bottom:78px; z-index:80; display:grid; gap:4px; min-width:220px; padding:8px; border:1px solid var(--border); border-radius:14px; background:var(--surface); box-shadow:var(--shadow); }
.slash-menu[hidden] { display:none; }
.slash-menu button,.command-item { width:100%; text-align:left; border:1px solid transparent; border-radius:10px; padding:11px 12px; background:transparent; color:var(--text); }
.slash-menu button:hover,.command-item:hover { background:var(--surface-2); border-color: var(--border); }
.command-palette-modal { background: var(--surface); border: 1px solid var(--border); }
.command-palette-input { width:100%; border:1px solid var(--border); border-radius:12px; padding:11px 12px; background:var(--surface-2); color:var(--text); }
.cost-date-input { width:100%; border:1px solid var(--border); border-radius:10px; padding:7px 8px; background:var(--surface-2); color:var(--text); font-size:0.82rem; }
.command-palette-results { display:grid; gap:5px; margin-top:10px; max-height:52vh; overflow:auto; }
.template-list { display: grid; gap: 7px; }
.template-item {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface-2);
  color: var(--text);
  padding: 11px 12px;
  text-align: left;
  display: grid;
  gap: 4px;
}
.template-item:hover,
.template-item:focus-visible {
  border-color: var(--border-strong);
  background: var(--surface-3);
}
.template-item strong,
.template-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.template-item span {
  color: var(--muted);
  font-size: 12px;
}
.inline-chart { display:block; width:100%; max-width:680px; height:240px; border:1px solid var(--border); border-radius:12px; background:#0b0f14; cursor: crosshair; }
.markdown-render-fallback { white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9rem; line-height: 1.45; color: var(--text); }
.markdown-table-wrap {
  margin: 0.7em 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface-2);
  overflow: hidden;
}
.markdown-table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}
.markdown-table-copy,
.diff-copy-button {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
}
.markdown-table-copy:hover,
.markdown-table-copy:focus-visible,
.diff-copy-button:hover,
.diff-copy-button:focus-visible {
  border-color: var(--border-strong);
  color: var(--accent);
  outline: none;
}
.message .message-body .markdown-table-scroll {
  overflow-x: auto;
  max-width: 100%;
}
.sortable-table-heading {
  cursor: pointer;
  user-select: none;
}
.sortable-table-heading::after {
  content: "↕";
  display: inline-block;
  margin-left: 6px;
  color: var(--muted-2);
  font-size: 0.8em;
}
.sortable-table-heading[data-sort-dir="asc"]::after { content: "↑"; color: var(--accent); }
.sortable-table-heading[data-sort-dir="desc"]::after { content: "↓"; color: var(--accent); }
.diff-view { position: relative; margin:.5rem 0; border:1px solid var(--border); border-radius:12px; background:var(--surface-2); }
.diff-view summary { cursor:pointer; padding:8px 10px; font-weight:700; }
.diff-view pre { margin:0; }
.diff-copy-button {
  position: absolute;
  top: 6px;
  right: 8px;
}
.diff-add { display:block; color:#86efac; background:rgba(34,197,94,.12); }
.diff-remove { display:block; color:#fca5a5; background:rgba(239,68,68,.12); }
.diff-line { display:block; color:var(--muted); }
.answer-compare { display: grid; gap: 10px; }
.answer-compare-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.answer-compare-table-wrap {
  max-height: min(62vh, 620px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
}
.answer-compare-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
}
.answer-compare-table th,
.answer-compare-table td {
  border-bottom: 1px solid var(--border);
  padding: 7px 8px;
  vertical-align: top;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.answer-compare-table th:first-child,
.answer-compare-table td:first-child {
  width: 48px;
  color: var(--muted-2);
  text-align: right;
}
.answer-compare-table tr.changed td {
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}
.virtual-collapsed { content-visibility:auto; overflow:hidden; opacity:.35; }
.cost-meter-card {
  display: grid;
  gap: 0;
  background: color-mix(in srgb, var(--surface-2) 88%, white 2%);
  border-color: var(--border);
}
.cost-meter-card .cost-meter-heading {
  align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 0;
}
.cost-meter-card .cost-meter-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  width: auto;
}
.cost-meter-card .cost-meter-actions .text-button {
  width: auto;
}
.cost-meter-toggle {
  min-width: 28px;
  min-height: 24px;
  padding: 2px 7px;
  color: var(--muted);
  background: transparent;
  border-color: transparent;
  line-height: 1;
}
.cost-meter-toggle:hover,
.cost-meter-toggle:focus-visible {
  color: var(--text);
  background: var(--surface-3);
  border-color: var(--border);
}
.cost-meter-content {
  display: grid;
  grid-template-rows: 1fr;
  opacity: 1;
  transition: grid-template-rows 200ms ease, opacity 160ms ease;
}
.cost-meter-content > .cost-meter-inner {
  overflow: hidden;
  min-height: 0;
  display: grid;
  gap: 9px;
  padding-top: 9px;
}
.cost-meter-card.cost-meter-hidden .cost-meter-content {
  grid-template-rows: 0fr;
  opacity: 0;
}
.cost-meter-card.cost-meter-hidden #refresh-cost-button {
  display: none;
}
.cost-date-range {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.cost-date-range label {
  display: grid;
  gap: 4px;
  color: var(--muted-2);
  font-size: 0.8rem;
  line-height: 1.25;
}
.cost-meter {
  font-size: 0.8rem;
  color: var(--muted);
  display: grid;
  gap: 6px;
  margin-top: 0;
}
.cost-meter strong {
  color: var(--text);
  font-size: clamp(0.95rem, 1vw, 1.05rem);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
}
.cost-meter small { color: var(--muted-2); font-size: 0.78rem; line-height: 1.3; }
.cost-meter-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 7px;
  line-height: 1.35;
}
.cost-meter-row span:last-child { color: var(--text); text-align: right; }
.cost-meter-row-estimate span:last-child { color: var(--muted-2); font-style: italic; }
.cost-meter-note { color: var(--text); font-size: 0.72rem; line-height: 1.3; margin: 0; opacity: 0.7; }
.cost-meter-error { color: var(--danger); margin: 0; font-size: 0.82rem; }
.cost-date-input {
  min-height: 32px;
}
.cost-meter-card.cost-meter-hidden {
  gap: 0;
  padding: 7px 12px;
}
.cost-meter-card.cost-meter-hidden .cost-meter-heading strong {
  font-size: 0.78rem;
}
.scroll-bottom-button { position: absolute; right: 18px; bottom: 18px; z-index: 40; width: 42px; height: 42px; border-radius: 999px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text); box-shadow: var(--shadow); font-size: 22px; font-weight: 900; opacity: 0; transform: scale(.88); transition: opacity .16s ease, transform .16s ease; }
.scroll-bottom-button.visible:not([hidden]) { opacity: 1; transform: scale(1); }
.artifacts-panel { width: 0; min-width: 0; overflow: hidden; border: 0 solid var(--border); background: var(--surface); border-radius: var(--radius-panel); box-shadow: var(--shadow); transform: translateX(24px); opacity: 0; transition: opacity .16s ease, transform .42s var(--ease-spring, cubic-bezier(.22, 1, .36, 1)); }
.artifacts-panel.open { width: 40%; min-width: 320px; border-width: 1px; opacity: 1; transform: translateX(0); margin-left: 12px; }
.artifacts-panel.open.trip-studio { width: min(68%, 1120px); min-width: 560px; background: color-mix(in srgb, var(--surface) 88%, #d4c4a8); }
.artifact-open-button { margin-top: 10px; min-height: 44px; padding: 8px 14px; border: 1px solid var(--accent); border-radius: 999px; background: var(--accent); color: var(--accent-text); font-size: 12px; font-weight: 800; cursor: pointer; }
.artifact-open-button:hover { filter: brightness(1.06); }
.artifact-open-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.artifacts-header { height: 44px; padding: 0 12px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.artifacts-header strong { font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; }
.artifacts-header .text-button { width: auto; min-width: 44px; min-height: 44px; padding: 4px 8px; }
.artifacts-panel iframe { width: 100%; height: calc(100% - 44px); border: 0; background: white; }
.message .message-body h1,
.message .message-body h2,
.message .message-body h3,
.message .message-body h4 {
  margin: 0.8em 0 0.3em;
  font-size: 1em;
  font-weight: 700;
  line-height: 1.3;
}
.message .message-body h1:first-child,
.message .message-body h2:first-child,
.message .message-body h3:first-child { margin-top: 0; }
.message .message-body ul,
.message .message-body ol {
  margin: 0.4em 0;
  padding-left: 1.4em;
}
.message .message-body li { margin: 0.2em 0; }
.message .message-body .task-list-item {
  list-style: none;
  margin-left: -1.35em;
  display: flex;
  align-items: flex-start;
  gap: 0.45em;
}
.message .message-body .task-list-item input[type="checkbox"] {
  margin: 0.2em 0 0;
  accent-color: var(--accent);
}
.message .message-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.8em 0;
}
.message .message-body .markdown-table-scroll {
  max-width: 100%;
  overflow-x: auto;
  margin: 0.75em 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface-2);
}
.message .message-body table {
  width: 100%;
  min-width: min(520px, 100%);
  border-collapse: collapse;
  font-size: 0.94em;
  line-height: 1.45;
}
.message .message-body th,
.message .message-body td {
  padding: 0.55em 0.7em;
  text-align: left;
  vertical-align: top;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  min-width: 7em;
}
.message .message-body th:last-child,
.message .message-body td:last-child { border-right: none; }
.message .message-body tr:last-child td { border-bottom: none; }
.message .message-body th {
  color: var(--accent);
  font-weight: 700;
  background: color-mix(in srgb, var(--surface-2) 78%, var(--accent));
}
.message .message-body a { color: var(--accent); }
.message .message-body code {
  background: var(--surface-3);
  border-radius: 4px;
  padding: 0.12em 0.38em;
  font-size: 0.88em;
  font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}
.message .message-body pre {
  position: relative;
  background: transparent;
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  margin: 0.65em 0;
  border: none;
}
.message .message-body pre code {
  display: block;
  background: #22272e;
  border-radius: 8px;
  padding: 0.9em 1em 0.9em;
  font-size: 0.82em;
  line-height: 1.58;
  overflow-x: auto;
  font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}
.message .message-body pre.has-badge code { padding-top: 2.4em; }
.message .message-body code.hljs { background: #22272e !important; }
.code-lang-badge {
  position: absolute;
  top: 8px;
  left: 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #768390;
  pointer-events: none;
  font-family: inherit;
  z-index: 1;
}
.code-copy-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: #768390;
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: color 120ms, background 120ms, border-color 120ms;
  line-height: 1.6;
  z-index: 1;
}
.code-copy-btn:hover { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.code-copy-btn.copied { color: var(--accent); border-color: var(--border-strong); background: transparent; }
.message .message-body pre.code-collapsed code { max-height: 34em; overflow: hidden; }
.message .message-body pre.code-collapsed::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4.5em;
  pointer-events: none;
  background: #22272e;
  opacity: 0.92;
}
.code-expand-btn {
  position: absolute;
  right: 0.45rem;
  bottom: 0.45rem;
  z-index: 3;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
}
.code-expand-btn:hover { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.katex { word-break: break-word; }
.mermaid-block {
  margin: 0.65em 0;
  padding: 14px 12px 10px;
  background: #22272e;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  text-align: center;
  overflow-x: auto;
}
.mermaid-block svg { max-width: 100%; height: auto; }
.mermaid-block.mermaid-error {
  text-align: left;
  background: rgba(255,107,107,0.06);
  border-color: rgba(255,107,107,0.28);
}
.mermaid-block.mermaid-error pre {
  margin: 0;
  color: #ff8c8c;
  font-size: 0.82em;
  background: transparent;
  border-radius: 0;
  overflow-x: auto;
}
.message .message-body blockquote {
  margin: 0.4em 0;
  padding: 0.65em 0.8em;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface-2);
  color: var(--muted);
}
/* Plain text messages keep pre-wrap */
.message p { white-space: pre-wrap; }

.message pre,
.message code {
  max-width: 100%;
}

.message pre {
  overflow-x: auto;
}

.message figure {
  max-width: 100%;
  margin: 10px 0;
}

.message :is(img, svg, canvas, video, iframe, figure) {
  max-width: 100%;
  height: auto;
}

.message :is(svg, canvas, video, iframe) {
  max-height: min(360px, 55vh);
}

.message small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.approval-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.approval-button {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-chip);
  padding: 8px 11px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text);
}

.approval-button.allow {
  border-color: rgba(22, 121, 76, 0.35);
  color: var(--ok);
}

.approval-button.quadrant-action {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text);
}

.quadrant-action .ui-icon { width: 13px; height: 13px; color: var(--muted); }
.quadrant-swatch {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 50%;
  background: var(--quadrant-color, var(--muted));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--quadrant-color, var(--muted)) 55%, transparent);
}
.quadrant-action[data-quadrant="red"] { --quadrant-color: #e85d5d; }
.quadrant-action[data-quadrant="yellow"] { --quadrant-color: #e6b84f; }
.quadrant-action[data-quadrant="blue"] { --quadrant-color: #5793d6; }
.quadrant-action[data-quadrant="green"] { --quadrant-color: #57b98b; }

.approval-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.composer {
  grid-row: 4;
  padding: 14px;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 96%, white 2%);
  display: grid;
  grid-template-columns: minmax(132px, 172px) auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  position: relative;
  overflow: visible;
}

.talk-button,
.attach-button,
.text-form button {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-control);
  font-weight: 650;
}

.talk-button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  touch-action: none;
}

.composer-actions {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

.attach-button {
  width: 46px;
  min-width: 46px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
  padding: 0;
}

.composer-action-button {
  flex: 0 0 auto;
}

.talk-button.recording {
  background: var(--danger);
  border-color: var(--danger);
}

.text-form #send-button {
  min-width: 88px;
  min-height: 48px;
  padding: 0 22px;
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 750;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.text-form .stop-button {
  min-width: 88px;
  min-height: 48px;
  padding: 0 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-color: rgba(242, 79, 66, 0.55);
  background: color-mix(in srgb, var(--danger) 20%, var(--surface-2));
  color: var(--text);
}

.text-form .stop-button[hidden] { display: none; }

.talk-button:disabled,
.attach-button:disabled,
.text-form button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.attachment-tray {
  grid-column: 1 / -1;
  min-width: 0;
}

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.attachment-item {
  display: inline-flex;
  align-items: stretch;
  min-width: 0;
}

.attachment-chip {
  min-width: 0;
  max-width: min(260px, 100%);
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  padding: 5px 9px 5px 5px;
}

.attachment-chip img {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface-3);
  flex: 0 0 auto;
}

.attachment-video-thumb {
  position: relative;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-3);
  flex: 0 0 auto;
  display: block;
}

.attachment-video-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Play glyph marks the chip as a clip even before the poster frame decodes. */
.attachment-video-thumb::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-42%, -50%);
  border-style: solid;
  border-width: 5px 0 5px 8px;
  border-color: transparent transparent transparent rgba(255, 255, 255, 0.92);
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.55));
}

.attachment-details {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.attachment-details strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.attachment-details small {
  color: var(--muted);
  font-size: 11px;
}

.attachment-remove {
  width: 28px;
  border: 1px solid var(--border);
  border-left: 0;
  border-radius: 0 var(--radius-control) var(--radius-control) 0;
  background: var(--surface-3);
  color: var(--muted);
  font-weight: 700;
}

.mic-icon {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
}

.text-form {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
}

.text-form textarea {
  appearance: none;
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  background: #101312 !important;
  color: var(--text) !important;
  -webkit-text-fill-color: var(--text);
  border-radius: var(--radius-control);
  padding: 9px 14px;
  outline: none;
  font-size: 16px;
  line-height: 1.5;
  min-height: calc(1.5em + 18px);
  max-height: calc(3em + 18px);
  overflow-y: auto;
  resize: none;
}

.text-form textarea::placeholder {
  color: var(--muted);
  opacity: 1;
}

.text-form textarea:focus { border-color: var(--accent); }
.text-form button { padding: 0 15px; }

.tts-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tts-panel[hidden] { display: none !important; }

.tts-bottom-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: start;
}

.tts-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  background: var(--surface-2);
  padding: 14px;
  display: grid;
  gap: 12px;
  min-width: 0;
}

/* Direction switch: voice-over (text→speech) vs transcription (speech→text).
   Segmented rather than underlined so it reads as a different level of choice
   than the URL/Paste/PDF source tabs inside the voice-over form. */
.tts-mode-switch {
  display: inline-flex;
  align-self: start;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
}

.tts-mode-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 120ms, background 120ms;
}

.tts-mode-tab:hover { color: var(--text); }
.tts-mode-tab.active { background: var(--accent); color: var(--accent-text); }

.tts-mode-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.tts-mode-panel[hidden] { display: none !important; }

.transcribe-controls { grid-template-columns: minmax(0, 1fr) auto; }

.transcribe-audio {
  width: 100%;
  height: 34px;
  border-radius: var(--radius-control);
}

.transcribe-text {
  min-height: 240px;
  font-size: 14px;
  line-height: 1.55;
}

.transcribe-text:disabled { opacity: 0.6; cursor: default; }

.transcribe-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tts-src-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
}

.tts-src-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color 120ms, border-color 120ms;
}

.tts-src-tab:hover { color: var(--text); }
.tts-src-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tts-pdf-drop,
.tts-audio-drop {
  display: flex !important;
  align-items: center;
  justify-content: center;
  gap: 0 !important;
  min-height: 72px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-control);
  cursor: pointer;
  transition: border-color 140ms, background 140ms;
}

.tts-pdf-drop:hover,
.tts-audio-drop:hover { border-color: var(--accent); background: var(--surface-3); }
.tts-pdf-drop.has-file,
.tts-audio-drop.has-file { border-color: var(--border-strong); border-style: solid; }

.tts-pdf-placeholder {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
  pointer-events: none;
}

.tts-card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.tts-card h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.tts-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.tts-card input[type="url"],
.tts-card textarea,
.tts-card select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text);
  padding: 10px 11px;
  font: inherit;
  font-size: 14px;
  outline: none;
}

.tts-card textarea { resize: vertical; line-height: 1.45; }
.tts-card input:focus, .tts-card textarea:focus, .tts-card select:focus { border-color: var(--accent); }

.tts-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: end;
}

.tts-local-connection {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.tts-local-connection button { min-height: 44px; padding: 8px 12px; }
.tts-local-connection small { flex: 1 1 240px; min-width: 0; line-height: 1.45; overflow-wrap: anywhere; }

.tts-check {
  display: flex !important;
  grid-template-columns: none !important;
  align-items: center;
  gap: 7px !important;
  min-height: 40px;
  white-space: nowrap;
}

.tts-controls button {
  min-height: 40px;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  padding: 0 14px;
}

.tts-chip {
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--accent);
  background: var(--surface-3);
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 700;
}

.tts-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: tts-spin 900ms linear infinite;
}

@keyframes tts-spin { to { transform: rotate(360deg); } }

.tts-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
}

.tts-play-btn {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 140ms;
}

.tts-play-btn:disabled { opacity: 0.35; cursor: default; }

.tts-progress-wrap {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 4px;
}

.tts-seek {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
  height: 4px;
}

.tts-time-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.tts-speed-pills { display: flex; gap: 3px; }
.tts-speed-pill {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 4px;
  padding: 2px 5px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: color 100ms, background 100ms, border-color 100ms;
  line-height: 1.4;
}
.tts-speed-pill:hover { color: var(--text); border-color: var(--border-strong); }
.tts-speed-pill.active { background: var(--accent); color: var(--accent-text); border-color: transparent; }

.tts-muted,
.tts-card small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.tts-library {
  display: grid;
  gap: 8px;
  max-height: min(460px, 48vh);
  overflow-y: auto;
}

.tts-library-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface);
  padding: 8px;
}

.tts-library-item.active { border-color: var(--border-strong); background: var(--surface-3); }
.tts-library-item.error { border-color: rgba(255, 107, 107, 0.45); }

.tts-library-main {
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  display: grid;
  gap: 3px;
  padding: 0;
}

.tts-library-main strong,
.tts-library-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tts-library-main span { color: var(--muted); font-size: 12px; }
.tts-library-actions { display: flex; gap: 5px; align-items: center; }
.text-button.danger { color: #ff8c8c; border-color: rgba(255, 140, 140, 0.35); }

@media (max-width: 920px) {
  .tts-bottom-row { grid-template-columns: 1fr; }
  .tts-controls { grid-template-columns: 1fr; }
  .tts-library { max-height: none; }
}

@media (max-width: 820px) {
  .tts-panel {
    padding: 12px max(12px, var(--safe-right)) max(16px, var(--safe-bottom)) max(12px, var(--safe-left));
    overflow: visible;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #070809;
    --surface: #0e1011;
    --surface-2: #131616;
    --surface-3: #18201f;
    --text: #e8ede8;
    --muted: #9ea9a3;
    --muted-2: #6e7a75;
    --border: rgba(255, 255, 255, 0.12);
    --border-strong: color-mix(in srgb, var(--accent) 34%, transparent);
    --accent: #57dbc2;
    --accent-soft: #2eb8a6;
    --accent-text: #070809;
    --shadow: none;
  }

  .message.user { background: var(--user-bubble); }
}

@media (max-width: 820px) {
  html,
  body {
    height: auto;
    min-height: var(--app-height);
    overflow-x: hidden;
    overflow-y: auto;
    position: static;
    width: 100%;
  }

  .app-shell {
    padding: 0;
    height: auto;
    min-height: var(--app-height);
    max-height: none;
    display: block;
    overflow: visible;
    background: var(--surface);
  }

  .sidebar-resizer {
    display: none;
  }

  .sidebar {
    display: block;
    max-height: none;
    overflow: visible;
    border: 0;
    border-radius: 0;
    border-bottom: 1px solid var(--border);
    padding: max(8px, var(--safe-top)) max(10px, var(--safe-right)) 8px max(10px, var(--safe-left));
    background: var(--surface);
    z-index: 30;
  }

  .brand,
  .system-card,
  .sidebar-note,
  .sidebar .history-card:not(.limits-card):not(.history-panel):not(.health-connect-card):not(.brain-sessions-card) { display: none; }

  .mobile-status-drawer {
    display: block;
    margin-top: 7px;
    padding: 7px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    background: var(--surface-2);
  }

  .mobile-status-heading {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px;
    margin-bottom: 0;
  }

  .mobile-push-button:not([hidden]) {
    display: block;
    width: 100%;
    margin-top: 7px;
  }

  #settings-reregister-push-button:not([hidden]) {
    display: inline-block;
  }

  .mobile-status-heading .heading-actions {
    flex-wrap: nowrap;
    gap: 4px;
  }

  .mobile-status-heading strong {
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-status-drawer.collapsed .limits-card,
  .mobile-status-drawer.collapsed .history-panel,
  .mobile-status-drawer.collapsed .brain-sessions-card {
    display: none;
  }

  .limits-card,
  .history-panel,
  .brain-sessions-card {
    display: block;
    margin-top: 7px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .limits-card .history-heading,
  .history-panel .history-heading,
  .health-connect-card .history-heading,
  .brain-sessions-card .history-heading {
    margin-bottom: 5px;
  }

  .limits-card .heading-actions,
  .history-panel .heading-actions,
  .brain-sessions-card .heading-actions {
    display: none;
  }

  .limits-card .history-heading strong {
    font-size: 11px;
  }

  .history-panel .history-heading strong {
    font-size: 12px;
  }

  .mobile-status-heading .text-button,
  .limits-card .text-button,
  .history-panel .text-button,
  .health-connect-card .text-button {
    min-height: 28px;
    padding: 3px 6px;
    font-size: 11px;
  }

  .health-connect-card .limits-note {
    font-size: 10.5px;
  }

  .history-panel .history-list {
    max-height: 96px;
  }

  .mode-tabs {
    display: flex;
    width: 100%;
    gap: 4px;
    padding: 3px;
    border-radius: var(--radius-control);
    background: var(--surface-2);
  }

  .mode-tab {
    justify-content: center;
    text-align: center;
    padding: 5px 1px;
    min-height: 28px;
    font-size: clamp(8.2px, 2.55vw, 10.5px);
    border-radius: var(--radius-control);
    white-space: nowrap;
  }

  .mode-tab::after { display: none; }

  .history-card {
    margin-top: 8px;
  }

  .history-list,
  .limits-list {
    max-height: 104px;
    grid-template-columns: 1fr;
  }

  .limits-list {
    max-height: 72px;
  }

  .limit-item {
    padding: 6px 8px;
  }

  .limit-item strong,
  .limit-item span,
  .limit-item small {
    font-size: 10.5px;
  }

  .limits-note {
    display: none;
  }

  .chat-shell {
    min-height: calc(var(--app-height) - 48px);
    height: auto;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    overflow: visible;
  }

  .chat-header {
    display: none;
  }

  .notify-quick { display: inline-flex; }

  .live-activity {
    display: none !important;
  }

  .activity-item {
    max-width: min(300px, 78vw);
  }

  .messages {
    min-height: calc(var(--app-height) - 160px);
    overflow: visible;
    padding: 14px max(12px, var(--safe-right)) max(16px, var(--safe-bottom)) max(12px, var(--safe-left));
    overscroll-behavior: auto;
    -webkit-overflow-scrolling: touch;
    scroll-padding-bottom: calc(var(--composer-height) + 20px + var(--safe-bottom));
  }

  .message {
    max-width: 94%;
    border-radius: var(--radius-panel);
    padding: 12px 13px;
  }

  .typing-indicator {
    left: max(12px, var(--safe-left));
    right: auto;
    bottom: calc(var(--composer-height) + 8px + var(--safe-bottom));
    max-width: calc(100% - 24px);
  }

  .composer {
    grid-template-columns: 46px auto minmax(0, 1fr);
    align-items: center;
    gap: 7px;
    padding: 10px max(10px, var(--safe-right)) max(10px, var(--safe-bottom)) max(10px, var(--safe-left));
    position: sticky;
    left: auto;
    right: auto;
    bottom: 0;
    z-index: 40;
    border-top: 1px solid var(--border);
    box-shadow: 0 -10px 32px rgba(20, 20, 20, 0.08);
  }

  .composer-actions {
    gap: 4px;
  }

  .talk-button {
    width: 46px;
    min-width: 46px;
    height: 46px;
    min-height: 46px;
    padding: 0;
    border-radius: var(--radius-control);
    font-size: 0;
  }

  .attach-button {
    width: 36px;
    min-width: 36px;
    height: 46px;
    min-height: 46px;
    border-radius: var(--radius-control);
    font-size: 18px;
  }

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

  .talk-button .mic-icon {
    width: 10px;
    height: 10px;
  }

  .text-form {
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 5px;
  }

  .text-form textarea {
    min-height: 44px;
    padding-inline: 12px;
    background: var(--surface-2) !important;
    color: var(--text) !important;
  }

  .text-form textarea {
    height: 46px;
  }

  .text-form button {
    height: 46px;
    padding-inline: 12px;
    border-radius: var(--radius-control);
    font-size: 13px;
    white-space: nowrap;
    position: static;
    z-index: auto;
  }

  .text-form #send-button {
    min-width: 76px;
    padding-inline: 18px;
  }

  body.keyboard-open .sidebar {
    padding-top: max(6px, var(--safe-top));
    padding-bottom: 6px;
  }

  body.keyboard-open .mode-tab {
    min-height: 34px;
    padding-block: 7px;
  }

  body.keyboard-open .chat-header {
    min-height: 46px;
    padding-block: 7px;
  }

  body.keyboard-open .chat-header .eyebrow {
    display: none;
  }

  body.keyboard-open .composer {
    padding-bottom: 4px;
  }

  body.ios.keyboard-open .composer {
    padding-right: calc(max(10px, var(--safe-right)) + var(--keyboard-action-gutter));
  }
}

@media (display-mode: standalone) and (max-width: 820px) {
  .sidebar {
    padding-top: max(12px, var(--safe-top));
  }
}

@media (prefers-reduced-motion: reduce) {
  /* Collapses everything to an instant change (relied on by the skills store
     and ML Lab notebook tests). Overlays that fade rather than snap opt back
     in explicitly in fluid.css, where a short opacity cross-fade is kept. */
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}


/* Minimal production polish: flat surfaces, sharp controls, no horizontal history overflow. */
.sidebar,
.chat-shell,
.history-card,
.system-card,
.sidebar-note,
.message,
.login-card {
  background-clip: padding-box;
}

.history-panel,
.limits-card {
  max-width: 100%;
}

.history-panel .history-heading,
.limits-card .history-heading {
  min-width: 0;
}

.history-item {
  overflow: hidden;
}

.history-item strong {
  letter-spacing: -0.01em;
}

.history-item span,
.history-item small {
  line-height: 1.35;
}

.text-button,
.secondary-button,
.talk-button,
.attach-button,
.queue-chip,
.text-form button,
.text-form textarea,
.mode-tab {
  box-shadow: none;
}

.mode-tab.active {
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.message,
.history-item,
.limit-item,
.notification-item {
  box-shadow: none;
}

.session-loading-state {
  align-self: stretch;
  margin: auto;
  width: min(320px, 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  background: color-mix(in srgb, var(--surface-2) 82%, transparent);
  color: var(--muted);
  padding: 13px 14px;
  text-align: center;
  font-size: 13px;
}

.session-loading-state.is-error {
  display: grid;
  gap: 10px;
  color: var(--text);
  border-color: color-mix(in srgb, var(--danger, #e5484d) 45%, var(--border));
}

.session-load-retry {
  justify-self: center;
  min-height: 32px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: color-mix(in srgb, var(--surface-2) 86%, transparent);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.session-load-retry:disabled { opacity: 0.6; cursor: default; }

.message-window-control {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 4px auto 10px;
  color: var(--muted-2);
  font-size: 12px;
}

.message-window-expand {
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: color-mix(in srgb, var(--surface-2) 86%, transparent);
  color: var(--muted);
  padding: 6px 10px;
  font-weight: 600;
}

.message-window-expand:hover,
.message-window-expand:focus-visible {
  border-color: var(--border-strong);
  color: var(--text);
}


/* iOS mobile shell: DVoice charcoal, compact, fixed app viewport.
   Standalone PWAs keep the page itself locked; only the message pane scrolls. */
@media (max-width: 820px) {
  :root {
    color-scheme: dark;
    --bg: #070809;
    --surface: #0e1011;
    --surface-2: #131616;
    --surface-3: #18201f;
    --text: #e8ede8;
    --muted: #9ea9a3;
    --muted-2: #6e7a75;
    --border: rgba(255, 255, 255, 0.12);
    --border-strong: color-mix(in srgb, var(--accent) 34%, transparent);
    --accent: #57dbc2;
    --accent-soft: #2eb8a6;
    --accent-text: #070809;
    --shadow: none;
  }

  html,
  body,
  .app-shell {
    background: var(--bg);
  }
}

@media (display-mode: standalone) and (max-width: 820px) {
  html,
  body,
  .app-shell {
    background: #070809 !important;
  }

  html,
  body {
    height: var(--app-height);
    min-height: var(--app-height);
    overflow: hidden;
    position: fixed;
    inset: 0;
  }

  .app-shell {
    height: var(--app-height);
    min-height: 0;
    max-height: var(--app-height);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .sidebar {
    flex: 0 0 auto;
    max-height: 36vh;
    overflow: hidden;
  }

  .chat-shell {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    overflow: hidden;
  }

  .chat-workspace {
    flex: 1 1 auto;
    min-height: 0;
  }

  .messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

/* ── Emotions / RULER card ─────────────────────────────── */

:root {
  --em-cyan: #00c8e0;
  --em-negative: #ff4d4d;
  --em-positive: #22c55e;
  --em-mixed: #f59e0b;
  --em-card-bg: #0d0d10;
}

.ruler-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0;
}

@keyframes em-reveal {
  to { opacity: 1; transform: translateY(0); }
}

.em-rsec {
  margin-bottom: 9px;
  opacity: 0;
  transform: translateY(8px);
  animation: em-reveal 0.26s ease forwards;
}

.em-rsec:nth-child(1) { animation-delay: 0.04s; }
.em-rsec:nth-child(2) { animation-delay: 0.10s; }
.em-rsec:nth-child(3) { animation-delay: 0.16s; }
.em-rsec:nth-child(4) { animation-delay: 0.22s; }
.em-rsec:nth-child(5) { animation-delay: 0.28s; }
.em-rsec:nth-child(6) { animation-delay: 0.34s; }
.em-rsec:nth-child(7) { animation-delay: 0.40s; }

.em-sec-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}

.em-cyan { color: var(--em-cyan); }

.em-muted-card {
  background: var(--em-card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
}

.em-label-card {
  background: var(--em-card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 12px 13px;
  margin-bottom: 6px;
}

.em-label-card:last-child { margin-bottom: 0; }

.em-label-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
}

.em-label-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
  line-height: 1.2;
}

.em-valence-badge {
  font-size: 7px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 2px 5px;
  border-radius: 2px;
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 1px;
}

.em-valence-badge.negative { background: rgba(255,77,77,0.1); color: var(--em-negative); border: 1px solid rgba(255,77,77,0.22); }
.em-valence-badge.positive { background: rgba(34,197,94,0.08); color: var(--em-positive); border: 1px solid rgba(34,197,94,0.2); }
.em-valence-badge.mixed    { background: rgba(245,158,11,0.09); color: var(--em-mixed);    border: 1px solid rgba(245,158,11,0.22); }

.em-label-desc {
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
  margin-bottom: 10px;
}

.em-intensity-row { display: flex; align-items: center; gap: 9px; }

.em-intensity-track {
  flex: 1;
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
}

.em-intensity-fill {
  height: 100%;
  border-radius: 3px;
  width: 0;
  transition: width 0.72s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.em-intensity-fill.negative { background: var(--em-negative); }
.em-intensity-fill.positive { background: var(--em-positive); }
.em-intensity-fill.mixed    { background: var(--em-mixed); }

.em-intensity-val {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
  min-width: 26px;
  text-align: right;
  flex-shrink: 0;
}

.em-express-card {
  background: var(--em-card-bg);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius-control);
  padding: 14px 14px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
}

.em-strategy-card {
  background: var(--em-card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 11px 13px;
  margin-bottom: 6px;
}

.em-strategy-card:last-child { margin-bottom: 0; }

.em-strategy-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  line-height: 1.35;
}

.em-strategy-rationale {
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}

.em-synthesis-card {
  background: var(--em-card-bg);
  border: 1px solid var(--border);
  border-top: 2px solid var(--em-cyan);
  border-radius: var(--radius-control);
  padding: 14px 15px 13px;
  font-size: 13px;
  line-height: 1.75;
  color: var(--text);
}

/* ── RULER preview card (voice PWA) ────────────────────── */

.ruler-preview {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.ruler-preview-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ruler-preview-recognize {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}

.ruler-open-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--em-cyan);
  border-radius: var(--radius-control);
  color: var(--em-cyan);
  background: transparent;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background 140ms;
}

.ruler-open-btn:hover { background: rgba(0,200,224,0.07); }

/* Debate / Sparring Room cards (amber accent to match the gym brand) */
.debate-controls { display: flex; flex-direction: column; gap: 10px; width: 100%; margin-top: 10px; }
.debate-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.debate-chip {
  border: 1px solid rgba(243,179,78,0.4); background: rgba(243,179,78,0.08); color: #f3b34e;
  border-radius: 999px; padding: 6px 12px; font-size: 12px; font-weight: 600; cursor: pointer;
  -webkit-appearance: none; appearance: none;
}
.debate-chip:active { background: rgba(243,179,78,0.18); }
.debate-end {
  align-self: flex-start; border: 1px solid rgba(243,179,78,0.4); background: transparent; color: #f3b34e;
  border-radius: var(--radius-control); padding: 9px 16px; font-size: 13px; font-weight: 600; cursor: pointer;
  -webkit-appearance: none; appearance: none;
}
.debate-end.ready { background: #f3b34e; color: #1a1407; border-color: #f3b34e; }
.debate-score-card { display: flex; flex-direction: column; gap: 10px; width: 100%; margin-top: 10px; }
.dsc-head { display: flex; align-items: baseline; gap: 12px; }
.dsc-score { font-size: 26px; font-weight: 700; color: var(--text, #fff); font-variant-numeric: tabular-nums; }
.dsc-score small { font-size: 13px; color: var(--muted); font-weight: 500; }
.dsc-primary { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: #ff7a7a; }
.dsc-summary { margin: 0; font-size: 13px; line-height: 1.6; color: var(--muted); }
.dsc-open {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid #f3b34e; border-radius: var(--radius-control); color: #1a1407; background: #f3b34e;
  padding: 11px 16px; font-size: 14px; font-weight: 700; text-decoration: none; white-space: nowrap;
  min-height: 44px; /* iOS tap target */
}
.dsc-open:active { opacity: 0.85; }

/* ===================================================================== */
/* Theme switcher (poached from Odysseus theme system): data-theme on     */
/* <body> overrides the :root design tokens. Default (no attr / midnight)  */
/* keeps the existing palette.                                             */
/* ===================================================================== */
.theme-select {
  margin-left: auto;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  padding: 3px 6px;
  cursor: pointer;
}
.theme-select:hover { color: var(--text); }

body[data-theme="onedark"] {
  --bg: #282c34; --surface: #21252b; --surface-2: #2c313a; --surface-3: #353b45;
  --text: #abb2bf; --muted: #828997; --muted-2: #5c6370;
  --border: rgba(171,178,191,0.16); --border-strong: rgba(97,175,239,0.5);
  --accent: #61afef; --accent-soft: #528bce; --accent-text: #1b1f27;
  --user-bubble: #2f3b4c; --assistant-bubble: #2c313a; --ok: #98c379; --danger: #e06c75;
}
body[data-theme="slate"] {
  --bg: #0f1419; --surface: #171c23; --surface-2: #1d242d; --surface-3: #283039;
  --text: #e6edf3; --muted: #9aa7b2; --muted-2: #6b7785;
  --border: rgba(230,237,243,0.12); --border-strong: rgba(125,170,255,0.4);
  --accent: #7aa2f7; --accent-soft: #5d83d6; --accent-text: #0f1419;
  --user-bubble: #25304a; --assistant-bubble: #1d242d;
}
body[data-theme="paper"] {
  color-scheme: light;
  --bg: #f6f5f1; --surface: #ffffff; --surface-2: #f0eee8; --surface-3: #e7e4dc;
  --text: #1f1d1a; --muted: #5f5b54; --muted-2: #8a857c;
  --border: rgba(0,0,0,0.12); --border-strong: rgba(34,139,120,0.45);
  --accent: #1f8f7d; --accent-soft: #17776a; --accent-text: #ffffff;
  --user-bubble: #d7ede7; --assistant-bubble: #ffffff; --shadow: 0 1px 0 rgba(0,0,0,0.04), 0 14px 36px rgba(0,0,0,0.12);
}
/* ── Accent colour palette (overrides accent tokens only; surfaces/bg unchanged) ── */
body[data-accent="gold"]   { --accent:#b8cc52; --accent-soft:#9fb33f; --accent-text:#1a1a00; --user-bubble:#2a2a00; --ok:#b8cc52; }
body[data-accent="rose"]   { --accent:#e87aa0; --accent-soft:#c95a80; --accent-text:#070809; --user-bubble:#2a1020; --ok:#e87aa0; }
body[data-accent="ice"]    { --accent:#5cb8d4; --accent-soft:#3a9ab8; --accent-text:#070809; --user-bubble:#0e2530; --ok:#5cb8d4; }
body[data-accent="cobalt"] { --accent:#6f90c8; --accent-soft:#5574b0; --accent-text:#070809; --user-bubble:#161e34; --ok:#6f90c8; }
body[data-accent="amber"]  { --accent:#d6864a; --accent-soft:#b86428; --accent-text:#1a0c00; --user-bubble:#2a1400; --ok:#d6864a; }
body[data-accent="sage"]   { --accent:#58c08a; --accent-soft:#38a070; --accent-text:#070809; --user-bubble:#0a2018; --ok:#58c08a; }

/* Accent swatches */
.accent-swatch-row { display:flex; gap:8px; flex-wrap:wrap; align-items:center; }
.accent-swatch {
  width:26px; height:26px; border-radius:50%; border:2.5px solid transparent;
  cursor:pointer; padding:0; flex-shrink:0;
  transition: border-color .13s, transform .1s, box-shadow .13s;
  outline:none;
  box-shadow: 0 0 0 1.5px var(--border);
}
.accent-swatch:hover { transform:scale(1.18); }
.accent-swatch.swatch-active { border-color:var(--text); box-shadow:0 0 0 1.5px var(--text); }

/* ===================================================================== */
/* Brain mode: Odysseus-style live thinking / tool-thread / report UI    */
/* Adopts Inter (UI) + Fira Code (mono/agent) and a One-Dark-ish accent  */
/* on top of the existing layout. Scoped to the brain components so the  */
/* rest of the app is untouched.                                         */
/* ===================================================================== */
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
code, pre, .mono, .agent-thread, .thinking-content-inner {
  font-family: 'Fira Code', ui-monospace, 'SFMono-Regular', Menlo, monospace;
}

/* --- Collapsible "thinking" section ---------------------------------- */
.thinking-section {
  margin: 6px 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  background: color-mix(in srgb, var(--surface-2) 88%, var(--accent) 12%);
  overflow: hidden;
}
.thinking-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 11px; cursor: pointer; user-select: none;
  font-size: 12.5px; color: var(--muted);
}
.thinking-header:hover { color: var(--text); }
.thinking-header-left { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.thinking-icon { color: var(--accent); flex-shrink: 0; }
.thinking-toggle { transition: transform 0.18s ease; opacity: 0.6; }
.thinking-toggle.expanded { transform: rotate(90deg); }
.thinking-content { max-height: 0; overflow: hidden; transition: max-height 0.2s ease; }
.thinking-content.expanded { max-height: 1400px; overflow: auto; }
.thinking-content-inner {
  padding: 4px 13px 12px; font-size: 12.5px; line-height: 1.5;
  color: var(--muted); white-space: pre-wrap; word-break: break-word;
}
/* animated "thinking…" dots while the model is reasoning */
.thinking-dots::after {
  content: ''; animation: brain-dots 1.4s steps(4, end) infinite;
}
@keyframes brain-dots {
  0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; }
  75% { content: '...'; } 100% { content: ''; }
}

/* --- Agent thread (tool / phase / source sub-elements) --------------- */
.agent-thread { margin: 6px 0 4px; display: flex; flex-direction: column; gap: 4px; }
.agent-thread-node {
  display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: var(--radius-chip);
  background: var(--surface-2); font-size: 12px; overflow: hidden;
}
.agent-thread-header {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer;
}
.agent-thread-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex-shrink: 0;
}
.agent-thread-event-icon { display: grid; place-items: center; color: var(--muted-2); flex: 0 0 15px; }
.agent-thread-event-icon .ui-icon { width: 15px; height: 15px; }
.agent-thread-node.running .agent-thread-dot { animation: brain-pulse 1s ease-in-out infinite; }
.agent-thread-node.failed .agent-thread-dot { background: var(--danger); }
.agent-thread-node.gpt5-progress { border-color: color-mix(in srgb, var(--accent) 24%, transparent); background: color-mix(in srgb, var(--accent) 5.5%, transparent); }
.agent-thread-node.gpt5-progress.completed .agent-thread-dot { background: var(--ok); }
@keyframes brain-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }
.agent-thread-tool { color: var(--text); font-weight: 600; }
.agent-thread-node.gpt5-progress .agent-thread-tool { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.agent-thread-node.gpt5-thread,
.agent-thread-node.brain-run-thread { gap: 0; }
.gpt5-thread-summary,
.brain-run-thread-summary { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; border: 0; background: transparent; color: inherit; cursor: pointer; font: inherit; text-align: left; }
.brain-run-thread-summary { padding: 8px 10px; background: color-mix(in srgb, var(--accent) 7%, transparent); }
.gpt5-thread-title { flex: 1; color: var(--text); font-weight: 650; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.brain-run-thread-title { flex: 1; color: var(--text); font-weight: 760; letter-spacing: 0.01em; }
.gpt5-thread-rows,
.brain-run-thread-rows { display: none; flex-direction: column; gap: 4px; padding: 0 6px 7px; }
.agent-thread-node.gpt5-thread.expanded > .gpt5-thread-rows { display: flex; }
.agent-thread-node.brain-run-thread.expanded > .brain-run-thread-rows { display: flex; }
.agent-thread-node.gpt5-thread.expanded > .gpt5-thread-summary .agent-thread-chevron,
.agent-thread-node.brain-run-thread.expanded > .brain-run-thread-summary .agent-thread-chevron { transform: rotate(90deg); }
.gpt5-thread-rows .agent-thread-node { background: color-mix(in srgb, var(--accent) 4%, var(--surface-2)); }
.brain-run-thread-rows > .agent-thread-node { background: color-mix(in srgb, var(--accent) 3%, var(--surface-2)); }
.agent-thread-status { color: var(--muted-2); margin-left: auto; }
.agent-thread-chevron { opacity: 0.45; transition: transform 0.18s ease; }
.agent-thread-node.expanded > .agent-thread-header > .agent-thread-chevron { transform: rotate(90deg); }
.agent-thread-content {
  max-height: 0; overflow: hidden; transition: max-height 0.2s ease;
  padding: 0 10px; color: var(--muted); white-space: pre-wrap; word-break: break-word;
}
.agent-thread-node.expanded > .agent-thread-content { max-height: 360px; overflow: auto; padding: 0 10px 9px; }
/* User message injected mid-run */
.agent-thread-node.user-inject { border-color: color-mix(in srgb, #4caf8a 28%, transparent); background: color-mix(in srgb, #1c4740 70%, transparent); }
.agent-thread-node.user-inject .agent-thread-dot { background: #4caf8a; }
.agent-thread-node.user-inject .agent-thread-tool { color: #8fd9b8; }
.agent-thread-node.user-inject .agent-thread-chevron { display: none; }
.agent-thread-node.user-inject > .agent-thread-content { max-height: none; padding: 0 10px 9px; color: var(--text); }
.live-run-status {
  margin: 6px 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12.5px;
}
/* --- Streaming body + typewriter caret -------------------------------- */
.stream-content { white-space: normal; }
.stream-caret {
  display: inline-block; width: 7px; height: 1.05em; margin-left: 1px;
  background: var(--accent); vertical-align: text-bottom;
  animation: brain-caret 1s steps(2, start) infinite;
}
@keyframes brain-caret { 0%,100% { opacity: 1; } 50% { opacity: 0; } }
.message.live-stream { border-color: var(--border-strong); }
.brain-elapsed { opacity: 0.65; font-variant-numeric: tabular-nums; }

/* --- Source cards ----------------------------------------------------- */
.source-cards { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.source-card-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 280px;
  padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: 12px;
  cursor: pointer; text-decoration: none;
}
.source-card-chip:hover { color: var(--text); border-color: var(--border-strong); }
.source-card-chip .sc-host { display: grid; place-items: center; color: var(--accent); flex-shrink: 0; }
.source-card-chip .sc-host .ui-icon { width: 13px; height: 13px; }
.source-card-chip .sc-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Modal (source detail / full report) ------------------------------ */
.app-modal-overlay {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.6); padding: 20px;
}
.app-modal-overlay[hidden] { display: none; }
.app-modal {
  width: min(760px, 100%); max-height: 84vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-panel); box-shadow: var(--shadow); overflow: hidden;
}
.app-modal-header {
  display: flex; align-items: center; gap: 10px; padding: 13px 16px;
  border-bottom: 1px solid var(--border); font-weight: 600;
}
.app-modal-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.app-modal-close {
  display: grid; place-items: center;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  border-radius: var(--radius-control); width: 32px; height: 32px; cursor: pointer; font-size: 16px;
}
.app-modal-close .ui-icon { width: 15px; height: 15px; }
.app-modal-close:hover { color: var(--text); }
.app-modal-body { padding: 16px; overflow: auto; line-height: 1.6; }
.app-modal-body a { color: var(--accent); }

/* --- Run console ------------------------------------------------------ */
.run-console-overlay {
  position: fixed; inset: 0; z-index: 68;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.62); padding: 18px;
}
.run-console-overlay[hidden] { display: none; }
.run-console {
  width: min(1180px, 100%); height: min(86vh, 100%);
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-panel); box-shadow: var(--shadow);
}
.run-console-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.run-console-header > div:first-child { min-width: 0; display: grid; gap: 2px; }
.run-console-eyebrow {
  color: var(--muted-2); font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
}
.run-console-header strong { color: var(--text); font-size: 15px; }
.run-console-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.run-console-meta {
  padding: 8px 16px; border-bottom: 1px solid var(--border);
  color: var(--muted-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.run-console-grid {
  flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(260px, 0.35fr) minmax(0, 1fr);
}
.run-console-list {
  min-width: 0; min-height: 0; overflow: auto;
  border-right: 1px solid var(--border); background: var(--surface-2);
  padding: 10px; display: flex; flex-direction: column; gap: 8px;
}
.run-console-run {
  width: 100%; min-height: 0; padding: 8px 12px;
  display: flex; flex-direction: column; gap: 5px; text-align: left;
  border: 1px solid var(--border); border-radius: var(--radius-control);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.run-console-run:hover,
.run-console-run.selected { border-color: var(--border-strong); background: rgba(255,255,255,0.05); }
.run-console-run.selected { box-shadow: inset 3px 0 0 var(--accent); }
.run-console-run-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.run-console-run-top strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.run-console-run-line,
.run-console-run-stamp {
  color: var(--muted-2); font-size: 11.5px; line-height: 1.35;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.run-status-pill {
  flex-shrink: 0; padding: 2px 7px; border: 1px solid var(--border);
  border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 10.5px;
}
.run-status-pill.running,
.run-status-pill.queued,
.run-status-pill.waiting_approval { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.run-status-pill.completed { color: #7dd3a8; border-color: rgba(125, 211, 168, 0.42); }
.run-status-pill.failed,
.run-status-pill.interrupted,
.run-status-pill.cancelled { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.run-console-detail {
  min-width: 0; min-height: 0; overflow: auto; padding: 14px 16px 18px;
  display: flex; flex-direction: column; gap: 12px;
}
.run-console-detail h3 {
  margin: 2px 0 -4px; color: var(--muted-2); font-size: 11px; letter-spacing: 0.07em; text-transform: uppercase;
}
.run-console-summary,
.run-console-usage {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px;
}
.run-console-summary > div,
.run-console-usage > div {
  min-width: 0; border: 1px solid var(--border); border-radius: var(--radius-control);
  background: var(--surface-2); padding: 9px 10px;
}
.run-console-summary span,
.run-console-usage span {
  display: block; color: var(--muted-2); font-size: 11px; letter-spacing: 0.07em; text-transform: uppercase;
}
.run-console-summary strong,
.run-console-usage strong {
  display: block; margin-top: 3px; color: var(--text); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.run-console-note,
.run-console-error,
.run-console-empty {
  border: 1px solid var(--border); border-radius: var(--radius-control);
  background: var(--surface-2); color: var(--muted); padding: 10px 12px; font-size: 12.5px; line-height: 1.45;
}
.run-console-error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.run-console-empty { min-height: 88px; display: flex; align-items: center; justify-content: center; text-align: center; }
.run-console-empty.compact { min-height: 44px; }
.run-console-events { display: flex; flex-direction: column; gap: 8px; }
.run-console-event {
  border: 1px solid var(--border); border-radius: var(--radius-control);
  background: var(--surface-2); overflow: hidden; font-size: 12px;
}
.run-console-event summary {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; cursor: pointer;
}
.run-console-event summary strong {
  flex: 1 1 auto; color: var(--text); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.run-console-event summary span {
  flex: 0 1 auto; min-width: 0; margin-left: auto; color: var(--muted-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.run-console-event pre {
  margin: 0; max-height: 260px; overflow: auto; padding: 0 10px 10px;
  color: var(--muted); white-space: pre-wrap; word-break: break-word;
}
.retry-tool-button { margin: 0 10px 10px; }

.artifact-gallery,
.template-list,
.version-list,
.flowboard-panel {
  display: grid;
  gap: 10px;
}

.artifact-gallery-item,
.template-item,
.flowboard-event {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface-2) 82%, transparent);
}

.artifact-gallery-item,
.template-item {
  width: 100%;
  display: grid;
  gap: 5px;
  text-align: left;
  padding: 10px 12px;
  color: var(--text);
}

.template-item.selected,
.artifact-gallery-item:hover,
.template-item:hover {
  border-color: var(--border-strong);
  background: rgba(255,255,255,0.06);
}

.artifact-gallery-item span,
.template-item span,
.flowboard-event span,
.flowboard-event small {
  color: var(--muted);
  font-size: 12px;
}

.artifact-gallery-preview {
  max-height: 46vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 12px;
}

.artifact-gallery-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface-2) 82%, transparent);
  overflow: hidden;
}

.artifact-gallery-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.artifact-gallery-card-head strong {
  font-size: 13px;
  color: var(--text);
}

.artifact-gallery-stage {
  padding: 12px;
  max-height: 52vh;
  overflow: auto;
}

.artifact-gallery-frame {
  width: 100%;
  min-height: 280px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.artifact-gallery-open {
  margin-top: 8px;
}


.version-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface-2) 82%, transparent);
  padding: 10px 12px;
  display: grid;
  gap: 8px;
}

.version-item.is-current {
  border-color: var(--border-strong);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.version-item-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.version-item-head span { color: var(--muted); font-size: 12px; }

.version-item-body {
  max-height: 30vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}

.version-item-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.message-versions-button {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius-chip);
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.message-versions-button:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.persona-row {
  display: grid;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface-2) 82%, transparent);
  padding: 8px;
}

.persona-row.selected {
  border-color: var(--border-strong);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.persona-row .persona-select {
  border: 0;
  background: transparent;
  padding: 4px 4px;
}

.persona-row .persona-select:hover { background: transparent; }

.persona-row-actions,
.persona-create-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.persona-create-actions { margin-top: 10px; }


.flowboard-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.flowboard-event {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
}

.modal-form {
  display: grid;
  gap: 12px;
}

.modal-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.modal-form input,
.modal-form select,
.modal-form textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 9px 10px;
}

/* Toasts, the status line and the composer error: styles-redesign.css (feedback layer). */

@media (max-width: 420px) {
  .composer {
    grid-template-columns: 46px minmax(0, auto) minmax(104px, 1fr);
    gap: 6px;
  }

  .composer-actions {
    gap: 3px;
  }

  .attach-button {
    width: 34px;
    min-width: 34px;
  }

  .ocr-action {
    min-width: 34px;
    padding-inline: 5px;
    font-size: 9.5px;
  }

  .text-form {
    gap: 4px;
  }

  .text-form textarea {
    padding-inline: 10px;
  }

  .text-form button {
    padding-inline: 7px;
  }
}

@media (max-width: 820px) {
  .run-console-overlay { padding: 0; align-items: stretch; }
  .run-console { width: 100%; height: 100%; border-radius: 0; }
  .run-console-grid { grid-template-columns: 1fr; overflow: auto; }
  .run-console-list { max-height: 34vh; border-right: 0; border-bottom: 1px solid var(--border); }
  .run-console-detail { overflow: visible; }
  .run-console-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ── Animated backgrounds (lifted from Odysseus theme.js canvas patterns) ── */
:root { --bg-effect-intensity: 1.28; --bg-effect-size: 1.06; }

/* When an effect is active, lift the app above the fixed canvas (z-index:0)
   and let it show behind the conversation column. The sidebar and composer
   keep their solid surfaces for readability. */
body.has-bg-effect .app-shell {
  position: relative;
  z-index: 1;
  background: transparent !important;
}
body.has-bg-effect .chat-shell,
body.has-bg-effect .messages,
body.has-bg-effect .live-activity { background: transparent !important; }
body.has-bg-effect .message { background: color-mix(in srgb, var(--assistant-bubble) 82%, transparent) !important; }
body.has-bg-effect .message.user { background: color-mix(in srgb, var(--user-bubble) 82%, transparent) !important; }
body.has-bg-effect .message.live-stream { background: color-mix(in srgb, var(--assistant-bubble) 72%, transparent) !important; }

/* Smooth theme/background transitions */
/* Theme transitions — only on shell surfaces and interactive controls, not every message bubble */
.app-shell, .sidebar, .chat-shell, .composer, .mode-tab, .theme-select {
  transition: background-color 0.35s ease, color 0.35s ease, border-color 0.35s ease;
}

/* Per-message paint isolation — prevents a single bubble's resize from
   triggering full-column layout recalculation */
.message {
  contain: layout paint style;
}

/* GPU-promote animated elements so they paint on their own compositor layer */
.stream-caret,
.thinking-dots::after,
.agent-thread-dot,
.tts-spinner {
  will-change: transform;
}

/* Promote live-stream bubble to its own stacking context cheaply */
.message.live-stream {
  isolation: isolate;
}

/* ── Documents editor (poached from Odysseus Documents) ─────────────────── */
.docs-overlay {
  position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.6); padding: 18px;
}
.docs-overlay[hidden] { display: none; }
.docs-modal {
  width: min(1100px, 100%); height: min(88vh, 100%); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-panel);
  box-shadow: var(--shadow); overflow: hidden;
}
.docs-header { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.docs-tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; min-width: 0; }
.docs-tab { display: inline-flex; align-items: center; gap: 4px; padding: 5px 8px 5px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--muted); white-space: nowrap; cursor: pointer; }
.docs-tab.active { color: var(--text); border-color: var(--border-strong); background: var(--surface-3); }
.docs-tab-name { font-size: 12.5px; }
.docs-tab-close { border: none; background: transparent; color: var(--muted-2); cursor: pointer; font-size: 14px; line-height: 1; padding: 0 2px; }
.docs-tab-close:hover { color: var(--danger); }
.docs-header-actions { display: flex; align-items: center; gap: 6px; }
.docs-btn { border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); border-radius: 8px; padding: 6px 10px; font-size: 12.5px; cursor: pointer; }
.docs-btn:hover { color: var(--text); }
.docs-btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.docs-mode { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.docs-mode button { border: none; background: var(--surface-2); color: var(--muted); padding: 6px 9px; font-size: 12px; cursor: pointer; }
.docs-mode button.active { background: var(--surface-3); color: var(--text); }
.docs-close { border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); border-radius: 8px; width: 32px; height: 32px; font-size: 16px; cursor: pointer; }
.docs-close:hover { color: var(--text); }
.docs-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; }
.docs-body[data-mode="edit"] { grid-template-columns: 1fr; }
.docs-body[data-mode="edit"] .doc-preview { display: none; }
.docs-body[data-mode="preview"] { grid-template-columns: 1fr; }
.docs-body[data-mode="preview"] .doc-editor { display: none; }
.doc-editor {
  border: none; border-right: 1px solid var(--border); resize: none; padding: 16px;
  background: var(--bg); color: var(--text); font-family: 'Fira Code', ui-monospace, monospace;
  font-size: 13px; line-height: 1.6; outline: none;
}
.doc-preview { padding: 16px; overflow: auto; line-height: 1.65; color: var(--text); }
.doc-preview a { color: var(--accent); }
.doc-preview pre, .doc-preview code { font-family: 'Fira Code', ui-monospace, monospace; }
.docs-ai { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-top: 1px solid var(--border); }
.doc-ai-input { flex: 1; padding: 8px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); font-size: 13px; }
.doc-ai-status { font-size: 12px; color: var(--muted); min-width: 60px; }
@media (max-width: 768px) {
  .docs-body, .docs-body[data-mode="split"] { grid-template-columns: 1fr; }
  .docs-body[data-mode="split"] .doc-preview { display: none; }
}

/* ── Settings modal ─────────────────────────────────────────────────────── */
.settings-modal { width: min(760px, 100%); }
.settings-modal-body { display: flex; flex-direction: column; gap: 24px; padding: 20px; }
.settings-section { display: flex; flex-direction: column; gap: 10px; }
.settings-section-title { font-size: 11px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); margin: 0; }
.settings-section-desc { font-size: 13px; color: var(--muted); margin: 0; line-height: 1.4; }
.settings-section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.settings-row { display: flex; align-items: center; gap: 12px; }
.settings-row-between { justify-content: space-between; }
.settings-key-row .settings-input { min-width: 0; }
.settings-key-row .secondary-button { flex: 0 0 auto; }
@media (max-width: 640px) {
  .settings-key-row { align-items: stretch; flex-direction: column; }
  .settings-key-row .secondary-button { width: 100%; }
}
.settings-label { font-size: 13px; color: var(--text); min-width: 120px; }
.settings-select,
.settings-input,
.codex-pkce-panel textarea { flex: 1; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: var(--radius-control); padding: 6px 10px; font-size: 13px; }
.settings-select { cursor: pointer; }
.settings-select:focus,
.settings-input:focus,
.codex-pkce-panel textarea:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.settings-health-status { font-size: 13px; color: var(--muted); }
/* Vinted helper: a compact extension of Settings, not a second modal. */
.vmodels-section p, .omodels-section p { margin: 0; line-height: 1.5; }
.vmodels-actions { flex-wrap: wrap; gap: 8px; }
.vmodels-section .secondary-button, .omodels-section .secondary-button { min-height: 44px; white-space: normal; text-align: center; }
.vmodels-section [hidden], .omodels-section [hidden] { display: none !important; }
.vmodels-section a.secondary-button, .omodels-section a.secondary-button { display: inline-flex; align-items: center; text-decoration: none; }
:is(#vmodels-status, #omodels-status)[data-state="connected"] { color: var(--text); font-weight: 600; }
:is(#vmodels-status, #omodels-status)[data-state="connected"]::before { content: '✓ '; color: var(--accent); }
#vmodels-action-status:empty, #omodels-action-status:empty { display: none; }
/* Separate action feedback from measured bridge health; no motion required. */
:is(.vmodels-section, .omodels-section) .secondary-button:active {
  background: var(--accent); color: var(--accent-text, var(--bg)); border-color: var(--accent);
}
:is(.vmodels-section, .omodels-section) .secondary-button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 3px;
}
:is(.vmodels-section, .omodels-section) .secondary-button[aria-busy="true"] {
  border-color: var(--accent); background: var(--surface-2); color: var(--text); cursor: progress;
}
:is(#vmodels-action-status, #omodels-action-status):not(:empty) {
  border-left: 3px solid var(--accent); padding: 8px 12px; color: var(--text); background: var(--surface-2);
}

.vmodels-setup { font-size: 13px; min-width: 0; }
.vmodels-setup summary { cursor: pointer; min-height: 44px; display: list-item; align-content: center; }
.vmodels-setup summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.vmodels-setup ol { padding-left: 20px; line-height: 1.6; }
.vmodels-setup pre, .omodels-command { white-space: pre-wrap; overflow-wrap: anywhere; padding: 12px; background: var(--surface-2, var(--surface)); border: 1px solid var(--border); border-radius: 8px; }
.vmodels-setup > p { margin-top: 12px; }
.vmodels-setup > button { margin-bottom: 4px; }
.codex-accounts-list { display: grid; gap: 8px; }
.codex-account-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; align-items: center; border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--surface-2); padding: 10px 12px; }
.codex-account-main { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.codex-account-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.codex-account-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; color: var(--muted); font-size: 12px; min-width: 0; }
.codex-account-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.codex-account-actions { display: flex; align-items: center; gap: 6px; }
.codex-badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 3px 8px; font-size: 11px; font-weight: 700; }
.codex-badge .ui-icon { width: 12px; height: 12px; }
.codex-badge--good { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent); }
.codex-badge--bad { color: #ffb0b0; background: rgba(255, 107, 107, 0.12); border: 1px solid rgba(255, 107, 107, 0.28); }
.codex-pkce-panel { display: grid; gap: 10px; border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--surface-2); padding: 12px; }
.codex-pkce-row { display: flex; gap: 8px; align-items: center; }
.codex-auth-instructions { display: grid; gap: 8px; }
.codex-auth-instructions p { margin: 0; color: var(--muted); font-size: 13px; }
.codex-auth-instructions a { color: var(--accent); overflow-wrap: anywhere; font-size: 12px; }
.codex-pkce-actions { display: flex; gap: 8px; align-items: center; }
.codex-error { color: #ff9b9b !important; }
.codex-success { color: var(--accent) !important; }
@media (max-width: 820px) {
  .artifacts-panel.open { position: fixed; inset: 10px; z-index: 80; width: auto; min-width: 0; }
  .artifacts-panel.open.trip-studio { width: auto; min-width: 0; }
  .chat-workspace { position: relative; }
}

@media (max-width: 640px) {
  .settings-section-heading,
  .codex-pkce-row { flex-direction: column; align-items: stretch; }
  .codex-account-row { grid-template-columns: 1fr; }
}

/* Model cards */
.model-cards { display: flex; flex-direction: column; gap: 8px; }
.model-card { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-control); cursor: pointer; transition: border-color .15s, background .15s; }
.model-card input[type="radio"] { margin-top: 3px; accent-color: var(--accent); cursor: pointer; }
.model-card-body { display: flex; flex-direction: column; gap: 3px; }
.model-card-body strong { font-size: 14px; font-weight: 600; color: var(--text); }
.model-card-body span { font-size: 12px; color: var(--muted); line-height: 1.4; }
.model-card:hover { border-color: var(--accent); background: var(--surface-2); }
.model-card--active { border-color: var(--accent) !important; background: var(--surface-2); }
.model-card--active .model-card-body strong { color: var(--accent); }

/* Engine chooser */
.engine-summary { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--surface-2); color: var(--text); cursor: pointer; transition: border-color .15s; }
.engine-summary:hover { border-color: var(--accent); }
.engine-summary-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.engine-summary-body strong { font-size: 14px; font-weight: 600; }
.engine-summary-body span { font-size: 12px; color: var(--muted); }
.engine-summary-cta { font-size: 12px; color: var(--accent); font-weight: 600; white-space: nowrap; }

/* Sit above the settings modal (same base z-index) when both briefly coexist. */
#engine-modal { z-index: 120; }
.engine-modal { width: min(540px, 100%); max-height: 88dvh; }
.engine-modal-body { display: flex; flex-direction: column; gap: 18px; padding: 20px; overflow: auto; }
.engine-modal-body > .settings-section-desc { margin: 0; }
.engine-cards { display: flex; flex-direction: column; gap: 8px; }
.engine-card { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 13px 15px; border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--surface); color: var(--text); cursor: pointer; transition: border-color .15s, background .15s; }
.engine-card:hover { border-color: var(--accent); background: var(--surface-2); }
.engine-card--active { border-color: var(--accent) !important; background: color-mix(in srgb, var(--accent) 10%, var(--surface-2)); }
.engine-card-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.engine-card-body strong { font-size: 14px; font-weight: 600; color: var(--text); }
.engine-card--active .engine-card-body strong { color: var(--accent); }
.engine-card-body span { font-size: 12px; color: var(--muted); line-height: 1.4; }
.engine-card-tag { align-self: center; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--accent-text); background: var(--accent); padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.engine-card-check { width: 18px; flex: 0 0 18px; text-align: center; color: var(--accent); font-weight: 700; opacity: 0; }
.engine-card-check .ui-icon { width: 16px; height: 16px; }
.engine-card--active .engine-card-check { opacity: 1; }
.engine-effort-row { gap: 12px; flex-wrap: wrap; }
/* .settings-row's display:flex beat the hidden attribute: a single-effort
   engine showed a one-option dial. */
.engine-effort-row[hidden] { display: none; }
/* The Local model dropdown can hold long, arbitrary Ollama tags — let it shrink
   and let the native control truncate rather than overflow the modal. */
.engine-effort-row .settings-select { flex: 1 1 200px; min-width: 0; max-width: 100%; min-height: 44px; }
.engine-local-refresh { flex: 0 0 auto; min-height: 44px; white-space: nowrap; }
.engine-local-status { font-size: 12px; color: var(--muted); margin: 0; line-height: 1.4; overflow-wrap: anywhere; }
.engine-local-status[data-state="connected"] { color: var(--ok); }
.engine-local-status[data-state="offline"] { color: var(--danger); }
.engine-effort-hint { font-size: 12px; color: var(--muted); margin: -8px 0 0; line-height: 1.4; overflow-wrap: anywhere; }
.engine-modal-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 2px; }
.template-badge { display: inline-block; margin-top: 3px; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--accent-text); background: var(--accent); padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.primary-button { border: 0; background: var(--accent); color: var(--accent-text); border-radius: var(--radius-chip); padding: 9px 16px; font-weight: 600; cursor: pointer; transition: background .15s; }
.primary-button:hover { background: var(--accent-soft); }

/* Learn this topic → Intelligence Learning Base + TTS folders */
.learn-topic-actions { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 7px; }
.learn-topic-button { font-size: 12.5px; }
.learn-topic-modal { display: flex; flex-direction: column; gap: 12px; }
.learn-topic-label { font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase; color: #8a9a96; }
.learn-topic-input {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid rgba(87,219,194,0.28); background: #0e1011; color: #e8efed; font-size: 16px;
}
.learn-topic-input:focus { outline: none; border-color: #57dbc2; }
.learn-topic-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #c3cdca; }
.learn-topic-note { margin: 0; font-size: 12.5px; line-height: 1.45; color: #8a9a96; }
.learn-topic-status { font-size: 13px; color: #8a9a96; }
.learn-topic-status.error { color: #ff8a8a; }
.tts-folder-header {
  margin: 16px 0 6px; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: #57dbc2;
}
.tts-folder-header:first-child { margin-top: 0; }

/* Generated images (Unfiltered engine's Venice variants) arrive as markdown
   images in the assistant bubble; keep them inside the column. */
.message .message-body img {
  display: block;
  max-width: min(100%, 420px);
  max-height: 360px;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  margin: 8px 0;
  cursor: zoom-in;
}

/* Tap a chat image to see it full size; tap again or Esc closes. */
.image-lightbox {
  position: fixed; inset: 0; z-index: 10000;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(0, 0, 0, .82);
  cursor: zoom-out;
}
.image-lightbox[hidden] { display: none; }
.image-lightbox img {
  max-width: 100%; max-height: 100%;
  object-fit: contain; border-radius: 8px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, .5);
}
.md-preview { border: 1px solid var(--border-strong, rgba(255,255,255,0.12)); border-radius: 8px; padding: 10px 14px; margin: 6px 0; }
.md-preview[hidden], pre[hidden] { display: none; }
