/* ================================================================
   Atomontage Chat UI - Design tokens from atomontage.com
   ================================================================ */

:root {
  /* Colors */
  --bg-primary: #121213;
  --bg-secondary: #1a1a1c;
  --bg-tertiary: #202022;
  --bg-elevated: #262628;
  --bg-hover: #2e2e31;
  --bg-input: #202022;

  --accent: #42a2fd;
  --accent-hover: #5bb3ff;
  --accent-dim: rgba(66, 162, 253, 0.15);
  --accent-border: rgba(66, 162, 253, 0.3);

  --text-primary: #fefefe;
  --text-secondary: #9c9c9e;
  --text-tertiary: #737378;
  --text-dim: #555558;

  --border: #2e2e31;
  --border-light: #3a3a3d;

  --danger: #ef4444;
  --danger-hover: #f87171;
  --warning: #f59e0b;
  --success: #22c55e;

  /* Typography */
  --font-body: 'Montserrat', system-ui, -apple-system, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;

  --text-xs: 0.6875rem;
  --text-sm: 0.8125rem;
  --text-base: 0.875rem;
  --text-lg: 1rem;
  --text-xl: 1.125rem;

  /* Spacing */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;

  /* Layout */
  --header-height: 48px;
  --chat-width: 420px;
  --chat-min-width: 300px;
  --chat-max-width: 700px;
  --resize-handle-width: 5px;

  /* Transitions */
  --transition-fast: 120ms ease;
  --transition-base: 200ms ease;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;
}

/* ================================================================
   Reset & base
   ================================================================ */

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ================================================================
   Header
   ================================================================ */

#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 var(--sp-4);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.header-logo-symbol {
  height: 24px;
  width: auto;
}

.header-logo-type {
  height: 20px;
  width: auto;
}

.montage-name {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  margin-left: var(--sp-1);
}

/* Topbar Remix button — visible only when MONTAGE_KIND == "play".
   Sits to the right of the framing/montage name; matches btn-primary
   sizing so the topbar's vertical rhythm doesn't shift when it
   appears. */
.remix-btn-topbar {
  margin-left: var(--sp-3);
}

.header-center {
  display: flex;
  align-items: center;
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

/* Connection status */
.connection-status {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
}

.connection-status.connected .status-dot { background: var(--success); }
.connection-status.reconnecting .status-dot {
  background: var(--warning);
  animation: pulse 1.5s infinite;
}
.connection-status.disconnected .status-dot { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Credits display */
.credits-display {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  padding: var(--sp-1) var(--sp-3);
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
}

.credits-icon {
  color: var(--accent);
  font-size: var(--text-sm);
}

.credits-label {
  color: var(--text-tertiary);
}

/* Connected makers */
.connected-makers {
  display: flex;
  align-items: center;
  gap: -4px;
}

.maker-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 2px solid var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--accent);
  margin-left: -4px;
  cursor: default;
  position: relative;
}

.maker-avatar:first-child { margin-left: 0; }

.maker-avatar[title]:hover::after {
  content: attr(title);
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  white-space: nowrap;
  z-index: 200;
  border: 1px solid var(--border);
}

/* ================================================================
   Buttons
   ================================================================ */

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

.btn-danger:disabled, .btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-sm {
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--text-xs);
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: var(--sp-1);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* ================================================================
   Main layout
   ================================================================ */

#app-main {
  display: flex;
  height: calc(100vh - var(--header-height));
  overflow: hidden;
}

/* ================================================================
   Chat panel
   ================================================================ */

.chat-panel {
  position: relative;
  width: var(--chat-width);
  min-width: var(--chat-min-width);
  max-width: var(--chat-max-width);
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  transition: width var(--transition-base);
  overflow: hidden;
}

.chat-panel.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}

.chat-title {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.session-size {
  font-size: var(--text-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: color 0.6s ease;
  color: #4ade80;
}

.clear-context-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-dim);
  font-size: 11px;
  font-family: var(--font-body);
  cursor: pointer;
  padding: 2px 10px;
  border-radius: 12px;
  transition: all var(--transition-fast);
}

.clear-context-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.35);
  color: var(--text-secondary);
}

/* ================================================================
   Queue status
   ================================================================ */

.queue-status {
  padding: var(--sp-2) var(--sp-4);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  flex-shrink: 0;
}

.queue-depth {
  color: var(--text-tertiary);
}

.queue-position {
  color: var(--accent);
  font-weight: 500;
}

.queue-paused {
  color: var(--warning);
  font-weight: 500;
  padding: var(--sp-1) 0;
}

/* ================================================================
   Owner controls
   ================================================================ */

.owner-controls {
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.owner-controls-header {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--sp-2);
}

.owner-controls-row {
  display: flex;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}

.queued-prompts-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  max-height: 120px;
  overflow-y: auto;
}

.queued-prompt-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-1) var(--sp-2);
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.queued-prompt-item .prompt-preview {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: var(--sp-2);
}

.queued-prompt-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px 4px;
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.queued-prompt-delete:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* ================================================================
   Messages
   ================================================================ */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}
.messages::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* User message */
.message {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  max-width: 100%;
}

.message-user {
  align-items: flex-end;
}

.message-user .message-bubble {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-md) var(--radius-md) var(--radius-sm) var(--radius-md);
  padding: var(--sp-2) var(--sp-3);
  max-width: 85%;
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: var(--text-lg);
}

/* Remote user message (another maker's prompt in broadcast mode) */
.message-remote-user {
  align-items: flex-start;
}

.remote-user-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-bottom: 2px;
  padding-left: var(--sp-1);
}

.message-remote-user .message-bubble {
  background: var(--bg-tertiary, #2a2a3e);
  color: var(--text-primary);
  border-radius: var(--radius-md) var(--radius-md) var(--radius-md) var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  max-width: 85%;
  word-wrap: break-word;
  white-space: pre-wrap;
  border-left: 3px solid var(--accent);
  font-size: var(--text-lg);
}

/* Assistant message */
.message-assistant {
  align-items: flex-start;
}

.message-assistant .message-bubble {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-radius: var(--radius-md) var(--radius-md) var(--radius-md) var(--radius-sm);
  padding: var(--sp-3);
  max-width: 95%;
  word-wrap: break-word;
  white-space: pre-wrap;
  border: 1px solid var(--border);
  font-size: var(--text-lg);
}

.message-meta {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-xs);
  color: var(--text-dim);
  padding: 0 var(--sp-1);
}

.message-cost {
  display: none;
  color: var(--text-tertiary);
}

.message:hover .message-cost {
  display: inline;
}

/* Undo button */
.undo-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 2px var(--sp-2);
  font-size: var(--text-xs);
  font-family: var(--font-body);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.undo-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-light);
  background: var(--bg-hover);
}

/* Status messages */
.message-status {
  align-items: center;
}

.message-status .message-bubble {
  background: transparent;
  color: var(--text-tertiary);
  font-size: var(--text-sm);
  padding: var(--sp-1) var(--sp-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-full);
}

.message-status .message-bubble.error {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.3);
}

.message-status .message-bubble.expandable {
  cursor: pointer;
  transition: background var(--transition-fast);
}

.message-status .message-bubble.expandable:hover {
  background: var(--bg-tertiary);
}

.message-status .message-bubble.expandable.expanded {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-style: solid;
  margin-bottom: 0;
}

.status-detail-expanded {
  background: #1a1a2e;
  border: 1px solid var(--border-light);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  max-width: 400px;
  text-align: left;
}

.status-detail-row {
  margin-bottom: var(--sp-1);
  word-break: break-word;
}

.status-detail-row strong {
  color: var(--text-primary);
}

.status-detail-row .tool-detail-content {
  margin-top: var(--sp-1);
  max-height: 150px;
}

/* Streaming indicator */
.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* ================================================================
   Agent action emoji bar
   ================================================================ */

.tool-emoji-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: var(--accent-dim);
  border-radius: var(--radius-sm);
  margin: var(--sp-1) 0;
  max-width: 100%;
}

.tool-emoji {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  width: 20px;
  height: 20px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform var(--transition-fast), background var(--transition-fast);
}

.tool-emoji-img {
  width: 14px;
  height: 14px;
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.tool-emoji:hover {
  background: rgba(66, 162, 253, 0.25);
  transform: scale(1.1);
}

.tool-emoji:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.tool-emoji.selected {
  background: rgba(66, 162, 253, 0.35);
  transform: scale(1.1);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.tool-emoji.in-progress {
  animation: tool-emoji-pulse 1.1s ease-in-out infinite;
}

.tool-emoji.has-screenshot::after {
  content: "\1F4F7";
  position: absolute;
  font-size: 10px;
}

@keyframes tool-emoji-pulse {
  0%, 100% {
    filter: drop-shadow(0 0 0 rgba(66, 162, 253, 0));
    transform: scale(1);
  }
  50% {
    filter: drop-shadow(0 0 6px rgba(66, 162, 253, 0.9));
    transform: scale(1.08);
  }
}

/* ================================================================
   Hover popup (anchored to emoji, same visuals as detail view)
   ================================================================ */

.tool-hover-popup {
  position: fixed;
  z-index: 10000;
  max-width: min(420px, calc(100vw - 32px));
  pointer-events: none;
  opacity: 0;
  display: none;
  padding: 5px 9px;
  background: #1a1a2e;
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.55);
}

.tool-hover-popup.visible {
  display: block;
  opacity: 1;
}

/* ================================================================
   Expanded tool detail (dark blue box with header + code)
   ================================================================ */

.tool-detail-expanded {
  background: #1a1a2e;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--sp-2) var(--sp-3);
  margin: var(--sp-1) 0 var(--sp-2);
  max-width: 100%;
}

.tool-detail-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding-bottom: var(--sp-2);
  margin-bottom: var(--sp-2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-weight: 700;
  font-size: var(--text-md, 15px);
  color: var(--accent);
}

.tool-detail-emoji {
  width: 14px;
  height: 14px;
  display: inline-block;
  flex: 0 0 auto;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.tool-detail-title {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-detail-filepath {
  font-family: "JetBrains Mono", "Fira Code", "SF Mono", "Consolas", monospace;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: var(--sp-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-detail-section-label {
  font-weight: 700;
  font-size: var(--text-sm);
  color: var(--accent);
  margin: var(--sp-2) 0 var(--sp-1);
}

/* Keep legacy class name used by status-detail-row diagnostics */
.tool-detail-content {
  font-family: "JetBrains Mono", "Fira Code", "SF Mono", "Consolas", monospace;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: pre;
  line-height: 1.5;
  margin: 0;
  max-height: 300px;
  overflow: auto;
}

/* ================================================================
   Code block inside expanded detail (monospace, line numbers, copy)
   ================================================================ */

.tool-code-block {
  position: relative;
  background: #0f1021;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  max-width: 100%;
  font-family: "JetBrains Mono", "Fira Code", "SF Mono", "Consolas", monospace;
  font-size: 11px;
  line-height: 1.5;
}

.tool-code-scroll {
  max-height: 360px;
  overflow: auto;
  border-radius: inherit;
}

.tool-code-plain {
  margin: 0;
  padding: 10px 16px;
  white-space: pre;
  color: var(--text-primary);
}

/* Single-line content wraps so it's fully visible without horizontal scroll. */
.tool-code-plain.wrap {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* Thin custom scrollbar inside code blocks */
.tool-code-scroll::-webkit-scrollbar {
  height: 8px;
  width: 8px;
}

.tool-code-scroll::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.03);
}

.tool-code-scroll::-webkit-scrollbar-thumb {
  background: rgba(66, 162, 253, 0.35);
  border-radius: 4px;
}

.tool-code-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(66, 162, 253, 0.55);
}

.tool-code-scroll {
  scrollbar-color: rgba(66, 162, 253, 0.45) rgba(255, 255, 255, 0.03);
  scrollbar-width: thin;
}

/* Lua syntax highlighting tokens */
.tool-code-block .tok-kw {
  color: #c678dd;
  font-weight: 600;
}
.tool-code-block .tok-str {
  color: #98c379;
}
.tool-code-block .tok-com {
  color: #6b7380;
  font-style: italic;
}
.tool-code-block .tok-num {
  color: #d19a66;
}

/* Screenshot inside tool detail */
.tool-detail-expanded .screenshot-thumbnail {
  display: block;
  margin-top: var(--sp-2);
}

/* ================================================================
   Screenshot thumbnails
   ================================================================ */

.screenshot-thumbnail {
  display: inline-block;
  max-width: 200px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.screenshot-thumbnail:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

/* Screenshot placeholder (broken image fallback) */
.screenshot-placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 200px;
  height: 120px;
  background: var(--bg-tertiary);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--text-dim);
  font-size: var(--text-xs);
}

/* Load earlier messages button */
.load-earlier-btn {
  align-self: center;
  margin-bottom: var(--sp-3);
}

/* ================================================================
   Screenshot lightbox
   ================================================================ */

.screenshot-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  animation: lightbox-fade-in 0.2s ease;
}

@keyframes lightbox-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.screenshot-lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  cursor: zoom-in;
  transition: transform 0.3s ease;
}

.screenshot-lightbox.zoomed img {
  transform: scale(2);
  cursor: zoom-out;
}

/* ================================================================
   Typing indicator (in-chat "AI is thinking" bubble)
   ================================================================ */

.typing-indicator {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0;
  max-width: 95%;
}

.typing-indicator-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  opacity: 0.7;
  flex-shrink: 0;
}

.typing-dots {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

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

.thinking-text {
  font-size: var(--text-sm);
  color: var(--text-dim);
  margin-top: 2px;
  padding-left: 0;
  animation: thinking-fade-in 0.3s ease;
}

@keyframes thinking-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.typing-stop-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  line-height: 1;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  padding: 0;
  opacity: 1;
}

.typing-stop-btn:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.typing-stop-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* Queue position indicator under user message */
.queue-position-indicator {
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
  padding: 2px var(--sp-1) 0;
  align-self: flex-end;
}

/* Queue action buttons (edit/delete) on queued user messages */
.queue-actions {
  display: flex;
  gap: 4px;
  align-self: flex-end;
  padding-top: 2px;
}

.queue-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 5px;
  font-size: 14px;
  line-height: 1;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  opacity: 0.6;
  transition: all var(--transition-fast);
}

.queue-action-btn:hover {
  opacity: 1;
}

.queue-action-edit:hover {
  color: var(--accent);
  background: rgba(99, 102, 241, 0.1);
}

.queue-action-delete:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* Cancelled queued message */
.message-cancelled .message-bubble {
  opacity: 0.5;
  text-decoration: line-through;
}

/* ================================================================
   Code blocks (collapsible)
   ================================================================ */

.code-block-wrapper {
  margin: var(--sp-2) 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg-tertiary);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast);
}

.code-block-header:hover {
  background: var(--bg-hover);
}

.code-block-header .toggle-icon {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  transition: transform var(--transition-base);
}

.code-block-header .toggle-icon.expanded {
  transform: rotate(90deg);
}

.code-block-header .file-name {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.code-block-content {
  display: none;
  background: var(--bg-primary);
  overflow-x: auto;
}

.code-block-content.expanded {
  display: block;
}

.code-block-content pre {
  margin: 0;
  padding: var(--sp-3);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.6;
  color: var(--text-secondary);
  white-space: pre;
}

/* ================================================================
   Chat input
   ================================================================ */

.chat-input-area {
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
  flex-shrink: 0;
}

/* Play-mode CTA: shares .chat-input-area for outer padding +
   border-top, plus .input-wrapper for the rounded box look —
   visually a chat input that's "disabled, would be here if you
   could write." The text + Remix button sit inside the box
   where the textarea + send-btn would normally be.
   `:focus-within` accent stays inert because no inputs are inside. */
.play-remix-cta-wrapper {
  /* Reset .input-wrapper's flex-end alignment — text + button
     center-align reads as a CTA, not a prompt-in-progress. */
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  /* "Not interactable" hint — slightly subdued vs the live input
     box. Keeps the same border + background so the framing of
     the panel reads identical across kinds. */
  cursor: default;
  /* Match the textarea's vertical room so the panel's bottom
     edge doesn't shift when toggling kinds — input-wrapper's
     own padding leaves enough height for the line + button. */
  padding: var(--sp-2) var(--sp-3);
}

.play-remix-cta-text {
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: var(--text-lg);
  line-height: 1.5;
  /* Same vertical padding as .prompt-input so the text baseline
     sits where the user would expect to type. */
  padding: var(--sp-1) 0;
}

.play-remix-cta-btn {
  /* Match send-btn's footprint (32px square) so the button
     visually anchors to the same spot the send button does in
     make mode. */
  height: 32px;
  padding: 0 var(--sp-3);
  font-size: var(--text-sm);
  font-weight: 500;
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast);
  padding: var(--sp-2);
  gap: var(--sp-2);
}

.input-wrapper:focus-within {
  border-color: var(--accent-border);
}

.prompt-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-lg);
  resize: none;
  padding: var(--sp-1) var(--sp-2);
  max-height: 120px;
  line-height: 1.5;
}

.prompt-input::placeholder {
  color: var(--text-dim);
}

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled {
  background: var(--bg-elevated);
  color: var(--text-dim);
  cursor: not-allowed;
}

.input-hint {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding-top: var(--sp-1);
  font-size: var(--text-xs);
  color: var(--text-dim);
}

.input-hint .separator { color: var(--border); }

/* Attachment chips */
.attachment-chips {
  display: none;
  flex-wrap: wrap;
  gap: var(--sp-1);
  padding: 0 var(--sp-1) var(--sp-2);
}
.attachment-chips.has-items {
  display: flex;
}
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-2);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  max-width: 200px;
}
.attachment-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attachment-chip-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
  border-radius: 2px;
}
.attachment-chip-remove:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.15);
}

/* Attach button (paperclip) */
.attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.attach-btn:hover {
  color: var(--accent);
  background: var(--accent-dim);
}

/* Drop zone overlay */
.drop-zone-overlay {
  position: absolute;
  inset: 0;
  background: rgba(66, 162, 253, 0.08);
  border: 2px dashed var(--accent);
  border-radius: var(--radius-md);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.drop-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  color: var(--accent);
  font-size: var(--text-base);
  font-weight: 500;
}

/* Upload status in chat */
.upload-status {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  padding: var(--sp-2) var(--sp-3);
  font-style: italic;
}

/* ================================================================
   Resize handle
   ================================================================ */

.resize-handle {
  width: var(--resize-handle-width);
  cursor: col-resize;
  background: transparent;
  position: relative;
  flex-shrink: 0;
  z-index: 50;
  transition: background var(--transition-fast);
}

.resize-handle:hover,
.resize-handle.active {
  background: var(--accent);
}

/* ================================================================
   Expand chat button
   ================================================================ */

.expand-chat-btn {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 50;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: var(--sp-3) var(--sp-1);
  display: flex;
  align-items: center;
  transition: all var(--transition-fast);
}

.expand-chat-btn:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

/* ================================================================
   WASM panel
   ================================================================ */

.wasm-panel {
  flex: 1;
  background: #0a0a0b;
  position: relative;
  overflow: hidden;
}

/* WASM client iframe - fills the entire right panel */
.wasm-iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  display: none;
  z-index: 1;
}

/* ================================================================
   WASM overlays (loading, error, placeholder)
   ================================================================ */

.wasm-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0a0b;
  z-index: 10;
  transition: opacity var(--transition-base);
}

.wasm-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  text-align: center;
  padding: var(--sp-4);
}

/* --- Loading state --- */

.wasm-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--bg-elevated);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.wasm-loading-text {
  font-size: var(--text-lg);
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.wasm-loading-sub {
  font-size: var(--text-xs);
  color: var(--text-dim);
}

/* --- Error state --- */

.wasm-error-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.12);
  color: var(--danger);
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wasm-error-text {
  font-size: var(--text-lg);
  font-weight: 500;
  color: var(--text-primary);
}

.wasm-error-detail {
  font-size: var(--text-xs);
  color: var(--text-dim);
  max-width: 320px;
  word-break: break-word;
}

#wasm-retry-btn {
  margin-top: var(--sp-2);
}

/* --- Placeholder state (no VM connection info) --- */

.wasm-placeholder-overlay .wasm-logo {
  font-weight: 700;
  font-size: 2rem;
  letter-spacing: 0.2em;
  color: var(--text-tertiary);
  opacity: 0.4;
}

.wasm-placeholder-overlay .wasm-subtitle {
  font-size: var(--text-sm);
  color: var(--text-dim);
  letter-spacing: 0.1em;
}

.wasm-placeholder-overlay .wasm-hint {
  font-size: var(--text-xs);
  color: var(--text-dim);
  opacity: 0.5;
  margin-top: var(--sp-4);
}

/* ================================================================
   Kill dialog
   ================================================================ */

.kill-dialog {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  max-width: 380px;
  width: 90%;
}

.kill-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.dialog-content {
  padding: var(--sp-6);
}

.dialog-content h3 {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--sp-2);
}

.dialog-content p {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  margin-bottom: var(--sp-4);
}

.dialog-option {
  margin-bottom: var(--sp-4);
}

.dialog-option label {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
}

.dialog-option input[type="checkbox"] {
  accent-color: var(--accent);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
}

/* ================================================================
   Scrollbar for queued prompts list
   ================================================================ */

.queued-prompts-list::-webkit-scrollbar { width: 3px; }
.queued-prompts-list::-webkit-scrollbar-track { background: transparent; }
.queued-prompts-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ================================================================
   Inline file previews in chat messages
   ================================================================ */

.file-preview {
  margin-top: var(--sp-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  max-width: 280px;
}

.file-preview-image {
  display: block;
  max-width: 200px;
  max-height: 200px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  object-fit: contain;
  background: var(--bg-secondary);
}

.file-preview-audio {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-2);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.file-preview-audio .file-preview-label {
  font-size: var(--text-xs);
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-preview-audio audio {
  width: 100%;
  height: 32px;
}

.file-preview-text {
  padding: var(--sp-2);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono, monospace);
  font-size: var(--text-xs);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-secondary);
  max-height: 120px;
  overflow: hidden;
  position: relative;
}

.file-preview-text .file-preview-label {
  display: block;
  font-family: var(--font-sans, sans-serif);
  font-size: var(--text-xs);
  color: var(--text-dim);
  margin-bottom: var(--sp-1);
  font-style: italic;
}

.file-preview-text .preview-expand-hint {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 32px;
  background: linear-gradient(transparent, var(--bg-secondary));
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: var(--sp-1);
  font-size: var(--text-xs);
  color: var(--accent);
}

/* Missing-file placeholder.
   Rendered by montage.js::renderMissingPlaceholder when
   /api/uploads/<filename> 404s — usually because the file was above
   the archive size cap and /tmp/uploads/ was wiped on a restart.
   Resets the tier-specific styles (image dimensions / audio padding
   / text mono-formatting) and shows just an emoji + filename chip
   so chat history reads as "this WAS a thing" instead of a broken
   image or empty audio bar. */
.file-preview.file-preview-missing {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-2);
  max-width: 280px;
  background: var(--bg-secondary);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  cursor: default;
  color: var(--text-dim);
  font-size: var(--text-xs);
  font-family: var(--font-sans, sans-serif);
  font-style: normal;
  /* Override the 120px max-height + overflow:hidden the text branch
     applies via .file-preview-text — we want the chip to size to
     content. Same rationale for white-space: nowrap. */
  max-height: none;
  overflow: visible;
  white-space: nowrap;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.file-preview-missing .file-preview-missing-emoji {
  font-size: 1.4em;
  line-height: 1;
  flex-shrink: 0;
}

.file-preview-missing .file-preview-missing-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* ================================================================
   Lightbox overlay
   ================================================================ */

.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
}

.lightbox-close {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 32px;
  cursor: pointer;
  z-index: 10001;
  line-height: 1;
  padding: var(--sp-1);
  transition: color var(--transition-fast);
}

.lightbox-close:hover {
  color: var(--text-primary);
}

.lightbox-content {
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-content img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.lightbox-content pre {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  color: var(--text-primary);
  font-family: var(--font-mono, monospace);
  font-size: var(--text-sm);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 80vw;
  max-height: 85vh;
  overflow: auto;
}

.lightbox-content .lightbox-audio {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  min-width: 300px;
}

.lightbox-content .lightbox-audio .lightbox-audio-name {
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.lightbox-content .lightbox-audio audio {
  width: 100%;
}
