:root {
  color-scheme: dark;
  --bg-primary: #181818;
  --bg-secondary: #141414;
  --bg-surface: #1e1e1e;
  --bg-input: rgba(228, 228, 228, 0.04);
  --bg-hover: rgba(228, 228, 228, 0.08);
  --bg-user-msg: rgba(228, 228, 228, 0.06);
  --bg-agent-msg: transparent;
  --bg-tool: rgba(228, 228, 228, 0.03);
  --bg-code: rgba(0, 0, 0, 0.25);

  --text-primary: rgba(228, 228, 228, 0.92);
  --text-secondary: rgba(228, 228, 228, 0.70);
  --text-tertiary: rgba(228, 228, 228, 0.48);
  --text-quaternary: rgba(228, 228, 228, 0.32);

  --accent-green: #3fa266;
  --accent-red: #e34671;
  --accent-yellow: #f1b467;
  --accent-blue: #3794ff;
  --accent-purple: #b180d7;
  --accent-link: #81a1c1;

  --border-color: rgba(228, 228, 228, 0.08);

  --radius: 10px;
  --radius-sm: 6px;

  --header-height: 44px;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;

  /* Scrollbars: opaque dark track avoids UA light (white/grey) fallback */
  --scrollbar-track: rgba(0, 0, 0, 0.45);
  --scrollbar-thumb: rgba(228, 228, 228, 0.22);
  --scrollbar-thumb-hover: rgba(228, 228, 228, 0.34);
}

*, *::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-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  margin: 0 auto;
}

/* --- Header --- */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 14px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 10;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.header-right.header-right-hidden {
  display: none;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.connected { background: var(--accent-green); }
.dot.disconnected { background: var(--accent-red); }
.dot.reconnecting { background: var(--accent-yellow); }

#agent-status-icon { font-size: 12px; }

#agent-status-text {
  max-width: min(200px, 45vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#agent-status-text.agent-status-shimmer {
  background: linear-gradient(
    90deg,
    var(--text-secondary) 0%,
    var(--text-primary) 45%,
    var(--text-secondary) 90%
  );
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: statusShimmer 2.2s ease-in-out infinite;
}

@keyframes statusShimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* --- Messages area --- */

#messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  color: var(--text-tertiary);
  gap: 8px;
}

.empty-state code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-surface);
  padding: 3px 7px;
  border-radius: 4px;
  color: var(--accent-blue);
}

.hint { font-size: 12px; }

/* --- Chat element base --- */

.chat-el {
  animation: fadeIn 0.12s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- Human message --- */

.el-human {
  display: flex;
  justify-content: flex-end;
  padding: 2px 0;
}

.human-bubble {
  max-width: 85%;
  padding: 6px 12px;
  background: var(--bg-user-msg);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  word-break: break-word;
}

.quoted-widget {
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent-blue);
  background: rgba(55, 148, 255, 0.08);
}

.quoted-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-quaternary);
  margin-bottom: 4px;
}

.quoted-text {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-secondary);
  white-space: pre-wrap;
  max-height: 120px;
  overflow-y: auto;
}

.mentions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 3px;
}

.mention-badge {
  font-size: 11px;
  padding: 0px 5px;
  border-radius: 3px;
  background: rgba(55, 148, 255, 0.15);
  color: var(--accent-blue);
  font-family: var(--font-mono);
}

.human-text {
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* --- Assistant message --- */

.el-assistant {
  display: flex;
  justify-content: flex-start;
  padding: 2px 0;
}

.assistant-bubble {
  max-width: 95%;
  padding: 6px 10px;
  word-break: break-word;
  overflow: visible;
  max-height: none;
}

.assistant-content {
  font-size: 13px;
  line-height: 1.6;
  overflow: visible;
  max-height: none;
}

/* Streamdown / markdown may still use horizontal scroll regions inside prose */
.assistant-bubble .ui-scroll-area,
.assistant-bubble .ui-scroll-area__viewport,
.assistant-bubble .ui-scroll-area__content {
  max-height: none !important;
  height: auto !important;
}

.assistant-bubble .ui-scroll-area__viewport,
.assistant-bubble .ui-scroll-area__content {
  overflow-y: visible !important;
}

.assistant-bubble .ui-scroll-area[data-direction="horizontal"] .ui-scroll-area__viewport,
.assistant-bubble .ui-scroll-area[data-direction="horizontal"] .ui-scroll-area__content {
  overflow-x: auto !important;
  overflow-y: visible !important;
}

.el-tool .tool-diff-host {
  margin-top: 10px;
}

.assistant-bubble .native-code-block {
  margin-top: 8px;
}

.assistant-bubble .overflow-auto,
.assistant-bubble .overflow-y-auto,
.assistant-bubble .overflow-scroll {
  max-height: none !important;
  overflow-y: visible !important;
}

.assistant-content.markdown-body p { margin-bottom: 6px; }
.assistant-content.markdown-body p:last-child { margin-bottom: 0; }
.assistant-content.markdown-body ol,
.assistant-content.markdown-body ul { padding-left: 18px; margin-bottom: 6px; }
.assistant-content.markdown-body li { margin-bottom: 2px; }
.assistant-content.markdown-body pre {
  margin: 6px 0;
  padding: 8px 10px;
  overflow: auto;
  background: var(--bg-code);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  -webkit-overflow-scrolling: touch;
}
.assistant-content.markdown-body code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: rgba(228, 228, 228, 0.06);
  padding: 1px 4px;
  border-radius: 3px;
}
.assistant-content.markdown-body pre code {
  display: block;
  padding: 0;
  border-radius: 0;
  background: none;
  color: var(--shiki-foreground);
  white-space: pre;
  line-height: 1.5;
}
.assistant-content.markdown-body pre code span {
  color: inherit;
}
.assistant-content.markdown-body pre code .line,
.assistant-content.markdown-body pre code [data-line] {
  display: block;
}
.assistant-content.markdown-body strong,
.assistant-content.markdown-body .font-semibold { font-weight: 600; }
.assistant-content.markdown-body a {
  color: var(--accent-link);
  text-decoration: none;
}

/* Shiki vars if Streamdown embeds inline code blocks in markdown HTML */
.assistant-content.markdown-body {
  --shiki-foreground: rgba(228, 228, 228, 0.92);
  --shiki-token-comment: #7f848e;
  --shiki-token-keyword: #c678dd;
  --shiki-token-type: #e5c07b;
  --shiki-token-function: #61afef;
  --shiki-token-string: #98c379;
  --shiki-token-punctuation: rgba(228, 228, 228, 0.72);
  --shiki-token-constant: #d19a66;
  --shiki-token-parameter: #abb2bf;
  --shiki-token-deleted: #e06c75;
  --shiki-token-inserted: #98c379;
}

/* --- Code blocks (native renderer) --- */

.code-block {
  --cb-font: 12px;
  --cb-lh: 1.45;
  --cb-lines: 7;
  margin: 6px 0 4px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-code);
  border: 1px solid var(--border-color);
}

.code-block-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px 2px 8px;
  min-height: 40px;
  box-sizing: border-box;
  background: rgba(228, 228, 228, 0.03);
  border-bottom: 1px solid var(--border-color);
}

.code-block-toolbar--actions-only {
  justify-content: flex-end;
  padding-right: 2px;
}

.code-block-header {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-tertiary);
  padding: 2px 0;
}

.code-block-fullscreen-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-width: 44px;
  min-height: 44px;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.code-block-fullscreen-btn:active {
  background: rgba(228, 228, 228, 0.1);
  color: var(--text-primary);
}

/* Scroll viewport: at most ~7 lines of code, then vertical scroll */
.code-block-viewport {
  max-height: calc(var(--cb-font) * var(--cb-lh) * var(--cb-lines) + 12px);
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Code block scrollbars: dark track + themed thumb (WebKit + Firefox) */
.code-block-viewport,
.code-block-fs-scroll {
  color-scheme: dark;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.code-block-viewport::-webkit-scrollbar,
.code-block-fs-scroll::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.code-block-viewport::-webkit-scrollbar-button,
.code-block-fs-scroll::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}

.code-block-viewport::-webkit-scrollbar-track,
.code-block-fs-scroll::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: 3px;
}

.code-block-viewport::-webkit-scrollbar-thumb,
.code-block-fs-scroll::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border-radius: 3px;
}

.code-block-viewport::-webkit-scrollbar-thumb:hover,
.code-block-fs-scroll::-webkit-scrollbar-thumb:hover {
  background-color: var(--scrollbar-thumb-hover);
}

.code-block-viewport::-webkit-scrollbar-corner,
.code-block-fs-scroll::-webkit-scrollbar-corner {
  background: var(--scrollbar-track);
}

.code-block pre {
  margin: 0;
  padding: 6px 8px;
  overflow-x: visible;
  font-family: var(--font-mono);
  font-size: var(--cb-font);
  line-height: var(--cb-lh);
  color: var(--text-primary);
  white-space: pre;
}

.code-block code { background: none; padding: 0; }

/* Line-level diff (structured diffLines from server) */
.code-block-diff-plain {
  margin: 0;
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: var(--cb-font);
  line-height: var(--cb-lh);
  background: var(--bg-code);
}

.code-block-diff-plain--raw pre {
  margin: 0;
  white-space: pre;
  color: var(--text-primary);
}

/* Full-screen code reader (mobile: safe areas, large close target) */
.code-block-fs-overlay {
  position: fixed;
  inset: 0;
  z-index: 10050;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  box-sizing: border-box;
}

.code-block-fs-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
}

.code-block-fs-panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: min(960px, 100%);
  max-height: 100%;
  margin: auto;
  background: var(--bg-code);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.code-block-fs-panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  padding: 10px 10px 10px 14px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(228, 228, 228, 0.04);
}

.code-block-fs-title {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-block-fs-close {
  flex-shrink: 0;
  min-width: 48px;
  min-height: 48px;
  padding: 12px;
  border: none;
  border-radius: 10px;
  font-size: 22px;
  line-height: 1;
  color: var(--text-secondary);
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.code-block-fs-close:active {
  background: rgba(228, 228, 228, 0.1);
  color: var(--text-primary);
}

.code-block-fs-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.code-block-fs-scroll .code-block-diff-plain {
  max-width: none;
}

.code-block-fs-scroll .code-block-diff-line {
  margin-left: 0;
  margin-right: 0;
}

.code-block-diff-line {
  white-space: pre;
  padding: 1px 6px 1px 8px;
  margin: 0 -6px;
  border-radius: 2px;
}

.code-block-diff-line--ctx {
  color: var(--text-primary);
}

.code-block-diff-line--add {
  background: rgba(63, 185, 80, 0.22);
  color: rgba(230, 245, 233, 0.98);
  border-left: 3px solid rgba(63, 185, 80, 0.95);
  padding-left: 10px;
}

.code-block-diff-line--rem {
  background: rgba(248, 81, 73, 0.2);
  color: rgba(255, 232, 230, 0.98);
  border-left: 3px solid rgba(248, 81, 73, 0.9);
  padding-left: 10px;
}

.code-block-diff-line--meta,
.code-block-diff-line--hunk {
  color: var(--text-tertiary);
  background: rgba(228, 228, 228, 0.05);
  font-size: 11px;
}

/* --- Tool call line --- */

.el-tool { padding: 1px 0; }

.tool-line {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tool-line.completed .tool-icon { color: var(--text-tertiary); }
.tool-line.loading .tool-icon { color: var(--accent-yellow); }

.tool-actions-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 8px 2px;
}

.tool-icon {
  flex-shrink: 0;
  font-size: 12px;
  width: 14px;
  text-align: center;
}

.tool-action {
  font-weight: 500;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.tool-details {
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-file-info {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
  font-size: 11px;
}

.tool-filename {
  color: var(--text-secondary);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-additions { color: var(--accent-green); }
.tool-deletions { color: var(--accent-red); }

.tool-summary {
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Thought block --- */

.el-thought { padding: 0 0; }

.thought-line.thought-line-summary {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.thought-line.thought-line-step {
  margin-left: 8px;
  padding-left: 8px;
  border-left: 2px solid rgba(55, 148, 255, 0.35);
  color: var(--text-tertiary);
  font-size: 12px;
}

.thought-line {
  padding: 1px 8px;
  font-size: 12px;
  color: var(--text-quaternary);
}

/* --- Plan block --- */

.el-plan { padding: 2px 0; }

.plan-card {
  padding: 8px 10px;
  background: rgba(228, 228, 228, 0.03);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.plan-label {
  font-size: 10px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plan-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.plan-description {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.plan-todo-list {
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 0;
}

.plan-todo-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.3;
}

.plan-todo-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 3px;
}

.plan-todo-pending { background: var(--text-tertiary); }
.plan-todo-completed { background: var(--accent-green); }
.plan-todo-in_progress { background: var(--accent-blue); }

.plan-todo-text {
  flex: 1;
  min-width: 0;
}

.plan-progress {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 16px;
}

.plan-progress-track {
  flex: 1;
  height: 3px;
  background: var(--border-color);
  border-radius: 2px;
  overflow: hidden;
}

.plan-progress-bar {
  height: 100%;
  background: var(--accent-green);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.plan-progress-text {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.plan-actions-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 4px;
}

.plan-btn {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.plan-btn-build {
  background: var(--accent-blue);
  color: #fff;
}

.plan-btn-view {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.plan-model-badge {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-left: auto;
}

.plan-card-widget {
  background: var(--bg-surface);
  border-color: color-mix(in srgb, var(--border-color) 80%, var(--accent-blue));
  gap: 6px;
}

.plan-widget-header {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.plan-widget-icon {
  font-size: 12px;
  opacity: 0.85;
  flex-shrink: 0;
}

.plan-widget-filename {
  font-size: 11px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plan-description.markdown-body {
  font-size: 12px;
  line-height: 1.45;
  max-height: 160px;
  overflow-y: auto;
}

.plan-description.markdown-body p { margin-bottom: 6px; }
.plan-description.markdown-body p:last-child { margin-bottom: 0; }

.plan-todos-more {
  font-size: 11px;
  color: var(--text-quaternary);
  padding: 2px 0 0 14px;
}

.plan-actions-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: nowrap;
  padding-top: 6px;
  margin-top: 2px;
  border-top: 1px solid var(--border-color);
}

.plan-actions-left,
.plan-actions-center,
.plan-actions-right {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.plan-actions-center {
  flex: 1;
  justify-content: center;
  overflow: hidden;
}

.plan-model-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 3px 8px;
  border-radius: 14px;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
}

.plan-model-pill-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.plan-model-pill-chev {
  flex-shrink: 0;
  opacity: 0.7;
  font-size: 10px;
}

.plan-model-badge-inline {
  font-size: 11px;
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plan-card-modal {
  background: transparent;
  border: none;
  padding: 0;
}

.plan-card-modal .plan-description.markdown-body,
.plan-card-modal .plan-todo-list {
  max-height: none;
}

.plan-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.66);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 12px;
}

.plan-modal-overlay.hidden { display: none; }

.plan-modal {
  width: 100%;
  max-width: 720px;
  max-height: min(82vh, 720px);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.plan-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.plan-modal-heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.plan-modal-label {
  font-size: 11px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plan-modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.plan-modal-close {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 26px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
}

.plan-modal-body {
  overflow-y: auto;
  padding: 16px;
}

/* --- Composer queue strip --- */

.composer-queue-bar {
  flex-shrink: 0;
  padding: 6px 12px 8px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.composer-queue-bar.hidden { display: none; }

.composer-queue-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.composer-queue-chevron {
  font-size: 10px;
  color: var(--text-quaternary);
}

.composer-queue-label {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer-queue-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 72px;
  overflow-y: auto;
}

.composer-queue-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
}

.composer-queue-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid var(--text-tertiary);
  flex-shrink: 0;
  margin-top: 4px;
  opacity: 0.5;
}

.composer-queue-text {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* --- Standalone todo list card --- */

.el-todo-list { padding: 2px 0; }

.todo-list-card {
  padding: 8px 10px;
  background: rgba(228, 228, 228, 0.03);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.todo-list-card-title {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.todo-list-card-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.todo-list-card-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.35;
}

.todo-list-card-icon {
  flex-shrink: 0;
  font-size: 12px;
  line-height: 1.35;
}

.todo-list-card-text {
  flex: 1;
  min-width: 0;
}

/* --- Run command --- */

.el-run-command { padding: 2px 0; }

.run-card {
  padding: 8px 10px;
  background: rgba(228, 228, 228, 0.03);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.run-header {
  font-size: 12px;
}

.run-description {
  color: var(--text-secondary);
  font-weight: 500;
}

.run-candidates {
  color: var(--text-tertiary);
}

.run-command-block {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-primary);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 200px;
  overflow-y: auto;
}

.run-prompt {
  color: var(--accent-green);
  user-select: none;
}

.run-actions-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.run-btn {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.run-btn-run {
  background: var(--accent-green);
  color: #fff;
}

.run-btn-skip {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.run-btn-allow {
  background: var(--accent-blue);
  color: #fff;
}

/* --- Loading indicator --- */

.el-loading { padding: 2px 0; }

.loading-dots {
  display: flex;
  gap: 3px;
  padding: 2px 8px;
}

.dot-anim {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-quaternary);
  animation: dotBounce 1.4s ease-in-out infinite;
}

.dot-anim:nth-child(2) { animation-delay: 0.16s; }
.dot-anim:nth-child(3) { animation-delay: 0.32s; }

@keyframes dotBounce {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* --- Approval Bar --- */

.approval-bar {
  padding: 10px 14px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 10;
}

.approval-bar.hidden { display: none; }

.approval-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-align: center;
}

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

/* --- Questionnaire Bar --- */

.questionnaire-bar {
  padding: 10px 14px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  max-height: 55vh;
}

.questionnaire-bar.hidden { display: none; }

.questionnaire-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.questionnaire-icon { font-size: 14px; }

.questionnaire-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.questionnaire-stepper {
  font-size: 11px;
  color: var(--text-secondary);
  margin-left: auto;
}

#questionnaire-questions {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  min-height: 0;
  flex: 1;
}

.questionnaire-question {
  margin-bottom: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary, rgba(255,255,255,0.04));
}

.questionnaire-question-active {
  border-left: 2px solid var(--accent-blue);
}

.questionnaire-question-label {
  display: flex;
  gap: 4px;
  font-size: 13px;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.questionnaire-question-number {
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.questionnaire-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.questionnaire-option {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.4;
  text-align: left;
  width: 100%;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.questionnaire-option:active { transform: scale(0.97); }
.questionnaire-option:hover { border-color: var(--accent-blue); }
.questionnaire-option-selected {
  border-color: var(--accent-blue);
  background: rgba(55, 148, 255, 0.15);
}

.questionnaire-option-letter {
  font-weight: 600;
  color: var(--accent-blue);
}

.questionnaire-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
  flex-shrink: 0;
}

.btn-q-skip {
  flex: 1;
  height: 40px;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-q-continue {
  flex: 1;
  height: 40px;
  background: var(--accent-blue);
  color: #fff;
}

.btn-q-continue:disabled { opacity: 0.35; }
.btn-q-skip:hover:not(:disabled) { border-color: var(--text-secondary); }
.btn-q-continue:hover:not(:disabled) { opacity: 0.85; }

/* --- Buttons --- */

.btn {
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-approve {
  flex: 1;
  height: 48px;
  background: var(--accent-green);
  color: #fff;
}

.btn-reject {
  flex: 1;
  height: 48px;
  background: var(--accent-red);
  color: #fff;
}

.btn-approve:hover:not(:disabled), .btn-reject:hover:not(:disabled) { opacity: 0.85; }

/* --- Input Bar --- */

#input-bar {
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 10;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 4px 4px 4px 12px;
  border: 1px solid var(--border-color);
  transition: border-color 0.2s;
}

.input-wrapper:focus-within { border-color: rgba(228, 228, 228, 0.16); }

#message-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  max-height: 120px;
  padding: 6px 0;
}

#message-input::placeholder { color: var(--text-quaternary); }
#message-input:disabled { opacity: 0.4; }

.btn-send {
  width: 36px;
  height: 36px;
  min-width: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-link);
  color: #fff;
  border-radius: 50%;
  padding: 0;
}

.btn-send:disabled { background: var(--text-quaternary); }

/* --- Toast --- */

#toast-container {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.toast {
  background: var(--bg-surface);
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.2s ease-out;
  white-space: nowrap;
}

.toast.error { border-left: 2px solid var(--accent-red); }
.toast.success { border-left: 2px solid var(--accent-green); }

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

/* --- Scrollbar (#messages) --- */

#messages {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

#messages::-webkit-scrollbar {
  width: 6px;
}

#messages::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}

#messages::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: 3px;
}

#messages::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border-radius: 3px;
}

#messages::-webkit-scrollbar-thumb:hover {
  background-color: var(--scrollbar-thumb-hover);
}

/* --- Window Bar --- */

.window-bar {
  display: flex;
  align-items: center;
  height: 32px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 10;
  padding: 0 4px;
}

.window-bar.hidden { display: none; }

.window-list {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  overflow-y: hidden;
  flex: 1;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding: 3px 0;
}

.window-list::-webkit-scrollbar { display: none; }

.window-item {
  flex-shrink: 0;
  padding: 3px 10px;
  font-size: 10px;
  border-radius: 4px;
  background: transparent;
  color: var(--text-quaternary);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font-sans);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.window-item:active { transform: scale(0.97); }
.window-item.active {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-color);
  font-weight: 500;
}

/* --- Tab Bar --- */

.tab-bar {
  display: flex;
  align-items: center;
  height: 36px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 10;
  padding: 0 4px;
  gap: 2px;
}

.tab-bar.hidden { display: none; }

.tab-list {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  overflow-y: hidden;
  flex: 1;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding: 4px 0;
}

.tab-list::-webkit-scrollbar { display: none; }

.tab-item {
  flex-shrink: 0;
  padding: 4px 10px;
  font-size: 11px;
  border-radius: 4px;
  background: transparent;
  color: var(--text-tertiary);
  border: none;
  cursor: pointer;
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font-sans);
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.tab-item:active { transform: scale(0.97); }
.tab-item.active {
  background: var(--bg-hover);
  color: var(--text-primary);
  font-weight: 500;
}

.tab-item .tab-status {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

.tab-status.running { background: var(--accent-yellow); }
.tab-status.completed { background: var(--accent-green); }
.tab-status.error { background: var(--accent-red); }

.tab-new-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 16px;
  font-weight: 400;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.tab-new-btn:active { background: var(--bg-hover); }

/* --- Mode/Model Pills --- */

.mode-model-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.pill {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: 11px;
  font-family: var(--font-sans);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s;
}

.pill:active { background: var(--bg-hover); }

.pill-icon {
  font-size: 12px;
  line-height: 1;
  opacity: 0.7;
}

.pill-chevron {
  font-size: 8px;
  opacity: 0.5;
  line-height: 1;
}

/* --- Bottom Sheet --- */

.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
}

.sheet-overlay.hidden { display: none; }

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg-surface);
  border-top-left-radius: 14px;
  border-top-right-radius: 14px;
  padding: 12px 0;
  z-index: 210;
  max-height: 60vh;
  overflow-y: auto;
  animation: sheetSlideUp 0.2s ease-out;
}

.bottom-sheet.hidden { display: none; }

@keyframes sheetSlideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 4px 16px 10px;
  border-bottom: 1px solid var(--border-color);
}

.sheet-list {
  display: flex;
  flex-direction: column;
  padding: 6px 0;
}

.sheet-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border: none;
  background: none;
  width: 100%;
  font-family: var(--font-sans);
  text-align: left;
}

.sheet-item:active { background: var(--bg-hover); }

.sheet-item.selected {
  color: var(--accent-blue);
  font-weight: 500;
}

.sheet-item-icon {
  width: 20px;
  text-align: center;
  font-size: 14px;
  opacity: 0.7;
}

.sheet-item-check {
  font-size: 14px;
  color: var(--accent-blue);
}

.sheet-item-label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.sheet-item-tag {
  font-size: 10px;
  opacity: 0.5;
}

.sheet-item-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
}

.sheet-item-badge {
  font-size: 12px;
  opacity: 0.5;
  line-height: 1;
}

.sheet-loading, .sheet-empty {
  padding: 24px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
  opacity: 0.7;
}

.sheet-divider {
  height: 1px;
  background: var(--border-color);
  margin: 4px 16px;
}

.sheet-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--text-primary);
}

.toggle-switch {
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: var(--bg-hover);
  border: none;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  padding: 0;
}

.toggle-switch.on {
  background: var(--accent-green);
}

.toggle-knob {
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
}

.toggle-switch.on .toggle-knob {
  transform: translateX(16px);
}

/* --- Desktop --- */

@media (min-width: 768px) {
  #messages {
    padding-left: max(16px, calc((100% - 800px) / 2));
    padding-right: max(16px, calc((100% - 800px) / 2));
  }
  .human-bubble { max-width: 75%; }
  .btn-approve, .btn-reject { height: 44px; }
  .approval-bar,
  .questionnaire-bar,
  #input-bar {
    padding-left: max(14px, calc((100% - 800px) / 2));
    padding-right: max(14px, calc((100% - 800px) / 2));
  }
}
