/* KISS Sorcar VS Code Extension Styles
   Ported from browser_ui.py OUTPUT_CSS + chatbot_ui.py assistant-panel styles
   to produce identical rendering in the VS Code webview sidebar. */

:root {
  font-size: var(--vscode-font-size);

  --bg: var(--vscode-editor-background, #0a0a0c);
  --bg2: var(--vscode-sideBar-background, #1e1e1e);
  --surface: var(--vscode-sideBar-background, #161b22);
  --surface2: var(--vscode-sideBar-background, #1c2128);
  --fg: var(--vscode-editor-foreground, #d4d4d4);
  --dim: var(--vscode-descriptionForeground, #8b949e);
  --accent: var(--vscode-textLink-foreground, #58a6ff);
  --border: var(--vscode-panel-border, #30363d);
  --input-bg: var(--vscode-input-background);
  --green: var(--vscode-terminal-ansiGreen);
  --red: var(--vscode-terminal-ansiRed);
  --yellow: var(--vscode-terminal-ansiYellow);
  --purple: var(--vscode-terminal-ansiMagenta);
  --cyan: var(--vscode-terminal-ansiCyan);

  --fs-xs:  0.636rem;  /* ~8px at 13px */
  --fs-sm:  0.818rem;  /* ~11px at 13px — labels */
  --fs-md:  0.909rem;  /* ~12px at 13px — secondary text */
  --fs-base: 1rem;     /* matches theme font-size — body text */
  --fs-lg:  1.091rem;  /* ~14px at 13px */
  --fs-xl:  1.273rem;  /* ~17px at 13px — headings */
  --fs-2xl: 1.545rem;  /* ~20px at 13px — large headings */
}

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

body {
  font-family: var(--vscode-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
  font-size: var(--fs-base);
  background: var(--bg);
  color: var(--fg);
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ── Header ─────────────────────────────────────────── */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.logo { font-size: var(--fs-base); font-weight: 600; color: var(--accent); }
.version { font-size: inherit; font-weight: 400; opacity: 0.75; }
.status { display: flex; align-items: center; gap: 6px; font-size: var(--fs-base); color: var(--dim); }
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--dim); transition: background 0.2s;
}
.dot.running { background: var(--green); animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }


/* ── Task Panel ──────────────────────────────────────── */
#task-panel {
  flex-shrink: 0;
  max-height: calc(var(--vscode-editor-font-size) * 1.2 * 1.6 * 3 + 12px);
  overflow-y: auto;
  margin: 8px 10px 0;
  padding: 8px 12px;
  border: 2px solid rgba(88,166,255,0.25);
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 4%, transparent);
  font-size: calc(var(--vscode-editor-font-size) * 1.2);
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  display: none;
}
#task-panel.visible { display: block; }

/* ── Output Area ────────────────────────────────────── */
#output {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 14px 12px 12px; scroll-behavior: smooth;
}
#welcome {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 20px 14px; text-align: center;
}
#welcome h2 { font-size: var(--fs-2xl); font-weight: 600; color: var(--fg); margin-bottom: 3px; letter-spacing: -0.3px; }
#welcome p { font-size: var(--fs-base); color: var(--dim); margin-bottom: 14px; }
#suggestions { display: grid; grid-template-columns: 1fr; gap: 5px; width: 100%; }
.suggestion-chip {
  background: color-mix(in srgb, var(--fg) 3%, transparent); border: 1px solid color-mix(in srgb, var(--fg) 8%, transparent);
  border-radius: 8px; padding: 7px 11px; cursor: pointer; text-align: left;
  font-size: var(--fs-base); color: color-mix(in srgb, var(--fg) 79%, transparent); line-height: 1.35; transition: all 0.15s;
}
.suggestion-chip:hover {
  background: color-mix(in srgb, var(--fg) 6%, transparent); border-color: color-mix(in srgb, var(--fg) 15%, transparent); color: var(--fg);
}
.chip-label {
  display: block; font-size: var(--fs-sm); font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--accent); margin-bottom: 2px; opacity: 0.8;
}

/* ── Event items (from OUTPUT_CSS) ──────────────────── */
.ev { margin-bottom: 6px; animation: fadeIn .15s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* Thinking blocks */
.think {
  padding: 8px 12px; margin: 8px 0;
  border: 1px solid rgba(121,192,255,0.12); border-radius: 8px;
  background: color-mix(in srgb, var(--cyan) 4%, transparent); max-height: 200px; overflow-y: auto;
}
.think .lbl {
  font-size: var(--fs-md); font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--cyan); margin-bottom: 4px;
  display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none;
}
.think .lbl .arrow { transition: transform .2s; display: inline-block; }
.think .lbl .arrow.collapsed { transform: rotate(-90deg); }
.think .cnt {
  font-size: var(--fs-md); color: var(--dim); font-style: italic;
  white-space: pre-wrap; word-break: break-word;
}
.think .cnt.hidden { display: none; }

/* Text blocks */
.txt {
  font-size: var(--fs-base); line-height: 1.5; color: color-mix(in srgb, var(--fg) 93%, transparent);
  padding: 4px 10px; white-space: pre-wrap; word-break: break-word;
}
.txt code {
  background: color-mix(in srgb, var(--fg) 8%, transparent); padding: 2px 6px; border-radius: 4px;
  font-family: var(--vscode-editor-font-family, 'Fira Code', monospace); font-size: var(--fs-md);
}
.txt pre {
  background: rgba(0,0,0,0.3); border: 1px solid color-mix(in srgb, var(--fg) 8%, transparent);
  border-radius: 6px; padding: 10px; overflow-x: auto; margin: 6px 0;
}
.txt pre code { background: none; padding: 0; }

/* Tool calls */
.tc {
  border: 1px solid var(--border); border-radius: 8px; margin: 8px 0;
  overflow: hidden; background: var(--surface); transition: box-shadow .2s;
}
.tc:hover { box-shadow: 0 2px 12px rgba(0,0,0,.3); }
.tc-h {
  padding: 7px 10px; background: var(--surface2);
  display: flex; align-items: center; gap: 10px;
  cursor: pointer; user-select: none; flex-wrap: wrap;
}
.tc-h:hover { background: color-mix(in srgb, var(--border) 80%, transparent); }
.tc-h .chv {
  color: var(--dim); transition: transform .2s; font-size: var(--fs-base); flex-shrink: 0;
}
.tc-h .chv.open { transform: rotate(90deg); }
.tn { font-weight: 600; font-size: var(--fs-base); color: var(--accent); }
.tp {
  font-size: var(--fs-base); color: var(--cyan);
  font-family: var(--vscode-editor-font-family, monospace);
  word-break: break-all; min-width: 0;
}
.tp[data-path] { cursor: pointer; text-decoration: underline dotted; }
.tp[data-path]:hover { color: color-mix(in srgb, var(--accent) 82%, transparent); text-decoration: underline solid; }
.td { font-size: var(--fs-md); color: var(--dim); font-style: italic; word-break: break-word; min-width: 0; }
.tc-b {
  padding: 6px 10px; max-height: 200px; overflow-y: auto;
  font-family: var(--vscode-editor-font-family, monospace);
  font-size: var(--fs-md); line-height: 1.5;
}
.tc-b.hide { display: none; }
.tc-b pre { margin: 4px 0; white-space: pre-wrap; word-break: break-word; }

/* Diff rendering */
.diff-old {
  color: var(--red); background: color-mix(in srgb, var(--red) 8%, transparent);
  padding: 1px 6px; display: block; white-space: pre-wrap; word-break: break-word;
}
.diff-new {
  color: var(--green); background: color-mix(in srgb, var(--green) 8%, transparent);
  padding: 1px 6px; display: block; white-space: pre-wrap; word-break: break-word;
}
.diff-ctx {
  color: var(--dim); padding: 1px 6px; display: block; opacity: 0.65;
  white-space: pre-wrap; word-break: break-word;
}
.diff-hl-del { background: color-mix(in srgb, var(--red) 30%, transparent); border-radius: 2px; padding: 0 1px; }
.diff-hl-add { background: color-mix(in srgb, var(--green) 30%, transparent); border-radius: 2px; padding: 0 1px; }
.extra { color: var(--dim); margin: 2px 0; }

/* Tool result */
.tr {
  padding: 5px 10px; margin: 6px 0;
  border: 1px solid var(--border); border-radius: 8px;
  font-family: var(--vscode-editor-font-family, monospace);
  font-size: var(--fs-md); max-height: 150px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word; background: color-mix(in srgb, var(--green) 4%, transparent);
}
.tr.err { background: color-mix(in srgb, var(--red) 4%, transparent); border-color: color-mix(in srgb, var(--red) 20%, transparent); }
.tr .rl {
  font-size: var(--fs-md); font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; margin-bottom: 4px;
}
.tr .rl.ok { color: var(--green); }
.tr .rl.fail { color: var(--red); }

/* Result card */
.rc {
  border: 1px solid var(--green); border-radius: 10px;
  margin: 12px 0; overflow: hidden; background: var(--surface);
}
.rc-h {
  padding: 10px 14px; background: color-mix(in srgb, var(--green) 8%, transparent);
  display: flex; align-items: center; justify-content: space-between;
  flex-direction: column; align-items: flex-start; gap: 6px;
}
.rc-h h3 { color: var(--green); font-size: var(--fs-md); font-weight: 600; margin-bottom: 2px; }
.rs {
  font-size: var(--fs-md); color: var(--dim);
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; width: 100%;
}
.rs b { color: var(--fg); font-weight: 500; display: block; font-size: var(--fs-base); }
.rc-body {
  padding: 10px 14px; font-size: var(--fs-md);
  word-break: break-word; line-height: 1.7;
}
.rc-body.pre { white-space: pre-wrap; }

/* System prompt / prompt */
.system-prompt, .prompt {
  border: 1px solid var(--border); border-radius: 8px; margin: 8px 0;
  overflow: hidden; background: var(--surface);
}
.system-prompt-h, .prompt-h {
  padding: 6px 12px; font-size: var(--fs-md);
  font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
}
.system-prompt-h { background: color-mix(in srgb, var(--purple) 8%, transparent); color: var(--purple); }
.prompt-h { background: color-mix(in srgb, var(--cyan) 8%, transparent); color: var(--cyan); }
.system-prompt-body, .prompt-body {
  padding: 8px 12px; font-size: var(--fs-md); word-break: break-word;
  line-height: 1.6; max-height: 400px; overflow-y: auto;
}

/* System output */
.sys {
  font-size: var(--fs-base); color: var(--dim);
  font-family: var(--vscode-editor-font-family, monospace);
  white-space: pre-wrap; word-break: break-word; padding: 2px 0;
}

/* Bash stream panel */
.bash-panel {
  background: rgba(0,0,0,0.35); border: 1px solid var(--border);
  border-radius: 8px; margin: 2px 0 8px; padding: 8px 10px;
  max-height: 200px; overflow-y: auto;
  font-family: var(--vscode-editor-font-family, monospace);
  font-size: var(--fs-md); line-height: 1.5; color: color-mix(in srgb, var(--fg) 70%, transparent);
  white-space: pre-wrap; word-break: break-word;
}

/* LLM panel (nested agent output) */
.llm-panel {
  border: 1px solid rgba(88,166,255,0.15); border-radius: 8px;
  margin: 6px 0; max-height: 350px; overflow-y: auto;
  padding: 8px 10px; background: color-mix(in srgb, var(--accent) 3%, transparent);
}
.llm-panel .txt { font-size: var(--fs-md); line-height: 1.5; color: color-mix(in srgb, var(--fg) 79%, transparent); }
.llm-panel .think .cnt { font-size: var(--fs-md); }

/* Usage info */
.usage {
  border: 1px solid var(--border); border-radius: 8px; margin: 6px 0;
  padding: 4px 10px; background: var(--surface); font-size: var(--fs-sm);
  color: var(--dim); font-style: italic;
  font-family: var(--vscode-editor-font-family, monospace);
  white-space: pre-wrap; word-break: break-word; overflow-wrap: break-word;
}

/* Spinner (output area) */
.spinner {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 0; color: var(--dim); font-size: var(--fs-base);
  animation: fadeIn .3s ease;
}
.spinner::before {
  content: ''; width: 14px; height: 14px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; flex-shrink: 0; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Wait spinner (input actions) */
#wait-spinner {
  width: 12px; height: 12px;
  border: 2px solid rgba(255,255,255,0.08);
  border-top-color: rgba(255,255,255,0.15);
  border-radius: 50%; flex-shrink: 0;
  transition: opacity 0.2s; opacity: 0;
}
#wait-spinner.active {
  border-color: rgba(255,255,255,0.15);
  border-top-color: rgba(88,166,255,0.7);
  animation: spin .8s linear infinite; opacity: 1;
}

/* Follow-up suggestion bar */
.followup-bar {
  display: flex; flex-direction: column; gap: 4px;
  padding: 8px 12px; margin: 8px 0;
  background: color-mix(in srgb, var(--accent) 5%, transparent); border: 1px solid rgba(88,166,255,0.15);
  border-radius: 8px; cursor: pointer; transition: all 0.15s;
  animation: fadeIn .3s ease;
}
.followup-bar:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent); border-color: rgba(88,166,255,0.25);
}
.fu-label {
  font-size: var(--fs-sm); font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--accent); opacity: 0.8; flex-shrink: 0;
}
.fu-text {
  font-size: var(--fs-base); color: color-mix(in srgb, var(--fg) 79%, transparent);
  white-space: normal; word-break: break-word;
}

/* Ghost text overlay */
#ghost-overlay {
  position: absolute; top: 0; left: 0; right: 0;
  pointer-events: none; white-space: pre-wrap; word-break: break-word;
  font-family: inherit; font-size: var(--fs-base); line-height: 1.5;
  color: transparent; padding: 2px 18px 2px 2px; min-height: 4.5em;
}
#ghost-overlay .ghost-text {
  color: color-mix(in srgb, var(--fg) 50%, transparent);
}

/* Clear button */
#clear-btn {
  background: none; border: none;
  color: color-mix(in srgb, var(--fg) 50%, transparent); cursor: pointer;
  padding: 4px; transition: color 0.15s;
  display: flex; align-items: center;
}
#clear-btn:hover { color: color-mix(in srgb, var(--fg) 66%, transparent); }

/* Disabled state for textarea while agent is running or merge is active */
#task-input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Drag-over visual feedback */
#input-container.drag-over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

/* ── Input Area ─────────────────────────────────────── */
#input-area {
  flex-shrink: 0; padding: 0 12px 12px; padding-top: 10px;
  border-top: 1px solid var(--border); background: var(--bg2);
  position: relative;
}
#file-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
#file-chips:empty { display: none; margin-bottom: 0; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: color-mix(in srgb, var(--accent) 10%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
  border-radius: 6px; padding: 4px 10px; font-size: var(--fs-base); color: color-mix(in srgb, var(--accent) 91%, transparent);
}
.file-chip img { width: 20px; height: 20px; border-radius: 4px; object-fit: cover; }
.file-chip .fc-rm {
  cursor: pointer; color: color-mix(in srgb, var(--fg) 50%, transparent); margin-left: 4px; transition: color 0.15s;
}
.file-chip .fc-rm:hover { color: var(--red); }

#input-container {
  background: var(--input-bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; transition: border-color 0.2s;
}
#input-container:focus-within { border-color: rgba(88,166,255,0.4); }
#input-wrap { display: flex; align-items: flex-start; gap: 4px; }
#input-text-wrap { flex: 1; min-width: 0; position: relative; }
#task-input {
  width: 100%; background: transparent; border: none; color: var(--fg);
  font-family: inherit; font-size: var(--fs-base); line-height: 1.5;
  resize: none; outline: none; min-height: 4.5em; max-height: 200px;
  padding: 2px 18px 2px 2px;
}
#task-input::placeholder { color: color-mix(in srgb, var(--fg) 50%, transparent); }

/* Input clear (X) button */
#input-clear-btn {
  position: absolute; top: 4px; right: 4px; z-index: 10;
  background: none; border: none; color: color-mix(in srgb, var(--fg) 50%, transparent);
  font-size: var(--fs-md); line-height: 1; cursor: pointer;
  width: 11px; height: 11px; border-radius: 3px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s;
}
#input-clear-btn:hover { color: color-mix(in srgb, var(--fg) 74%, transparent); background: color-mix(in srgb, var(--fg) 8%, transparent); }

#input-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

#send-btn {
  background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); border: none;
  border-radius: 50%; width: 28px; height: 28px; cursor: pointer;
  transition: all 0.2s; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
#send-btn svg { width: 12px; height: 12px; }
#send-btn:hover { background: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--fg); box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 20%, transparent); }
#send-btn:disabled { opacity: 0.3; cursor: not-allowed; box-shadow: none; }

#stop-btn {
  background: color-mix(in srgb, var(--red) 10%, transparent); color: var(--red);
  border: 1px solid color-mix(in srgb, var(--red) 15%, transparent); border-radius: 50%;
  width: 28px; height: 28px; cursor: pointer; transition: all 0.2s; display: none;
  align-items: center; justify-content: center; flex-shrink: 0;
}
#stop-btn svg { width: 11px; height: 11px; }
#stop-btn:hover { background: color-mix(in srgb, var(--red) 20%, transparent); box-shadow: 0 0 12px color-mix(in srgb, var(--red) 15%, transparent); }

/* Input Footer */
#input-footer {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 5px; padding-top: 5px; border-top: 1px solid color-mix(in srgb, var(--fg) 5%, transparent);
}

/* Model Picker */
#model-picker { position: relative; display: flex; align-items: center; gap: 4px; min-width: 0; overflow: visible; }
#model-btn {
  display: flex; align-items: center; gap: 6px;
  background: color-mix(in srgb, var(--fg) 3%, transparent); border: 1px solid color-mix(in srgb, var(--fg) 10%, transparent);
  border-radius: 6px; padding: 4px 8px; font-size: var(--fs-base); font-family: inherit;
  color: color-mix(in srgb, var(--fg) 58%, transparent); cursor: pointer; transition: border-color 0.2s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px;
  outline: none;
}
#model-btn:hover { border-color: color-mix(in srgb, var(--fg) 20%, transparent); color: color-mix(in srgb, var(--fg) 74%, transparent); }
#model-btn svg { flex-shrink: 0; opacity: 0.55; }
#upload-btn {
  background: color-mix(in srgb, var(--fg) 3%, transparent); color: color-mix(in srgb, var(--fg) 58%, transparent);
  border: 1px solid color-mix(in srgb, var(--fg) 8%, transparent); border-radius: 6px;
  padding: 4px 6px; cursor: pointer; flex-shrink: 0;
  transition: color 0.15s, border-color 0.2s;
  display: flex; align-items: center; justify-content: center;
}
#upload-btn:hover { color: color-mix(in srgb, var(--fg) 70%, transparent); border-color: color-mix(in srgb, var(--fg) 16%, transparent); background: color-mix(in srgb, var(--fg) 5%, transparent); }
#upload-btn svg { width: 11px; height: 11px; }
#history-btn, #run-prompt-btn {
  background: none; border: none;
  color: color-mix(in srgb, var(--fg) 50%, transparent); cursor: pointer;
  padding: 4px; transition: color 0.15s, opacity 0.15s;
  display: flex; align-items: center;
}
#history-btn:hover { color: color-mix(in srgb, var(--fg) 66%, transparent); }
#history-btn:disabled, #clear-btn:disabled { opacity: 0.3; cursor: not-allowed; }
#run-prompt-btn:not(:disabled) { color: color-mix(in srgb, var(--green) 72%, transparent); }
#run-prompt-btn:not(:disabled):hover { color: color-mix(in srgb, var(--green) 91%, transparent); }
#run-prompt-btn:disabled { opacity: 0.15; cursor: not-allowed; }
#model-dropdown {
  position: absolute; bottom: 100%; left: 0; min-width: 280px; max-width: 380px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  max-height: 320px; display: none; flex-direction: column;
  z-index: 100; box-shadow: 0 -6px 28px rgba(0,0,0,0.5); margin-bottom: 4px;
  overflow: hidden;
}
#model-dropdown.open { display: flex; }
#model-search {
  width: 100%; background: transparent; border: none;
  border-bottom: 1px solid rgba(255,255,255,0.06); color: var(--fg);
  font-size: var(--fs-base); padding: 8px 12px; outline: none; font-family: inherit;
}
#model-search::placeholder { color: color-mix(in srgb, var(--fg) 50%, transparent); }
#model-list { overflow-y: auto; flex: 1; }
.model-item {
  padding: 5px 10px; font-size: var(--fs-base); color: color-mix(in srgb, var(--fg) 66%, transparent);
  cursor: pointer; display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid rgba(255,255,255,0.02); transition: background 0.08s;
}
.model-item:hover, .model-item.sel { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.model-item.active { color: var(--accent); font-weight: 500; }
.model-cost { font-size: var(--fs-sm); color: color-mix(in srgb, var(--fg) 50%, transparent); flex-shrink: 0; margin-left: 12px; }
.model-group-hdr {
  padding: 4px 10px 3px; font-size: var(--fs-sm); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: color-mix(in srgb, var(--fg) 50%, transparent);
  background: var(--bg2);
  border-bottom: 1px solid rgba(255,255,255,0.04);
  position: sticky; top: 0; z-index: 1;
}

/* Autocomplete */
@keyframes acSlideUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
#autocomplete {
  position: absolute; bottom: 100%; left: 0; right: 0;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  max-height: 300px; overflow-y: auto; display: none;
  z-index: 50; box-shadow: 0 -8px 32px rgba(0,0,0,0.45), 0 0 0 1px color-mix(in srgb, var(--fg) 4%, transparent);
  margin-bottom: 4px; animation: acSlideUp 0.15s ease;
}
.ac-section {
  padding: 2px 12px 1px; font-size: var(--fs-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: color-mix(in srgb, var(--fg) 50%, transparent);
  background: var(--bg2);
  border-bottom: 1px solid rgba(255,255,255,0.035);
  position: sticky; top: 0; z-index: 1;
}
.ac-item {
  padding: 2px 12px; font-size: var(--fs-sm); cursor: pointer;
  display: flex; align-items: center; gap: 4px;
  border-bottom: 1px solid rgba(255,255,255,0.02);
  border-left: 2px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.ac-item.sel {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-left-color: var(--accent);
}
.ac-icon {
  flex-shrink: 0; width: 14px; height: 14px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 3px;
  background: color-mix(in srgb, var(--fg) 4%, transparent);
  color: color-mix(in srgb, var(--fg) 50%, transparent); font-size: var(--fs-base);
}
.ac-icon svg {
  width: 10px; height: 10px; stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.ac-item.sel .ac-icon {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
}
.ac-text {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--vscode-editor-font-family, 'SF Mono', 'Fira Code', monospace);
  font-size: var(--fs-sm); color: color-mix(in srgb, var(--fg) 62%, transparent); min-width: 0;
  letter-spacing: -0.01em;
}
.ac-item.sel .ac-text { color: color-mix(in srgb, var(--fg) 87%, transparent); }
.ac-dir { color: color-mix(in srgb, var(--fg) 50%, transparent); }
.ac-fname { color: color-mix(in srgb, var(--fg) 74%, transparent); }
.ac-item.sel .ac-dir { color: color-mix(in srgb, var(--fg) 53%, transparent); }
.ac-item.sel .ac-fname { color: color-mix(in srgb, var(--fg) 96%, transparent); }
.ac-hl { color: var(--accent); font-weight: 600; }
.ac-hint {
  font-size: var(--fs-xs); color: color-mix(in srgb, var(--fg) 50%, transparent);
  background: color-mix(in srgb, var(--fg) 4%, transparent);
  border: 1px solid rgba(255,255,255,0.05);
  padding: 1px 5px; border-radius: 4px; margin-left: auto;
  flex-shrink: 0;
  font-family: var(--vscode-editor-font-family, 'SF Mono', 'Fira Code', monospace);
}
.ac-item.sel .ac-hint {
  color: color-mix(in srgb, var(--accent) 54%, transparent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  border-color: rgba(88,166,255,0.12);
}
.ac-footer {
  padding: 2px 12px; font-size: var(--fs-xs); color: color-mix(in srgb, var(--fg) 50%, transparent);
  border-top: 1px solid rgba(255,255,255,0.04);
  display: flex; gap: 14px;
  background: var(--bg2);
  position: sticky; bottom: 0;
}
.ac-footer kbd {
  background: color-mix(in srgb, var(--fg) 5%, transparent); color: color-mix(in srgb, var(--fg) 50%, transparent);
  padding: 1px 5px; border-radius: 3px; font-size: var(--fs-xs);
  font-family: var(--vscode-editor-font-family, 'SF Mono', 'Fira Code', monospace);
  border: 1px solid rgba(255,255,255,0.04);
}

/* ── Sidebar ────────────────────────────────────────── */
#sidebar {
  position: fixed; right: 0; top: 0; bottom: 0; width: 420px;
  background: var(--bg2); border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform 0.25s ease;
  z-index: 200; padding: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
#sidebar.open { transform: translateX(0); }
#sidebar-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 199; opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
#sidebar-overlay.open { opacity: 1; pointer-events: auto; }
#sidebar-close {
  position: absolute; top: 12px; right: 12px; background: none; border: none;
  color: color-mix(in srgb, var(--fg) 50%, transparent); font-size: var(--fs-2xl); cursor: pointer; padding: 4px 8px; border-radius: 4px;
}
#sidebar-close:hover { color: color-mix(in srgb, var(--fg) 83%, transparent); background: color-mix(in srgb, var(--fg) 8%, transparent); }
.sidebar-section {
  margin-top: 24px;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
#history-list {
  overflow-y: auto;
  flex: 1;
}
.sidebar-loading {
  text-align: center;
  padding: 12px;
  color: var(--dim);
  font-size: var(--fs-md);
}
.sidebar-hdr {
  font-size: var(--fs-md); font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: color-mix(in srgb, var(--fg) 50%, transparent); margin-bottom: 10px;
}
#history-search {
  width: 100%; background: color-mix(in srgb, var(--fg) 5%, transparent); border: 1px solid var(--border);
  border-radius: 6px; color: var(--fg); font-size: var(--fs-base); padding: 6px 10px;
  outline: none; margin-bottom: 10px;
}
#history-search:focus { border-color: var(--accent); }
.sidebar-item {
  padding: 7px 10px; background: color-mix(in srgb, var(--fg) 3%, transparent);
  border: 1px solid color-mix(in srgb, var(--fg) 5%, transparent); border-radius: 8px;
  margin-bottom: 4px; cursor: pointer; font-size: var(--fs-base);
  color: #000 !important; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; transition: all 0.15s;
}
.sidebar-item:hover {
  background: color-mix(in srgb, var(--fg) 6%, transparent); border-color: color-mix(in srgb, var(--fg) 10%, transparent); color: var(--fg);
}
.sidebar-empty { font-size: var(--fs-base); color: color-mix(in srgb, var(--fg) 50%, transparent); padding: 8px 0; }

/* ── Ask User Modal ─────────────────────────────────── */
#ask-user-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center; z-index: 300;
}
.modal-content {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px; width: 90%; max-width: 400px;
}
.modal-title { font-size: var(--fs-xl); font-weight: 600; color: var(--fg); margin-bottom: 12px; }
#ask-user-question { font-size: var(--fs-lg); color: color-mix(in srgb, var(--fg) 83%, transparent); margin-bottom: 12px; line-height: 1.5; }
#ask-user-input {
  width: 100%; background: color-mix(in srgb, var(--fg) 5%, transparent); border: 1px solid var(--border);
  border-radius: 6px; color: var(--fg); font-size: var(--fs-lg); padding: 10px;
  resize: none; outline: none; min-height: 80px; margin-bottom: 12px;
}
#ask-user-input:focus { border-color: var(--accent); }
#ask-user-submit {
  background: var(--accent); border: none; border-radius: 6px; color: var(--vscode-button-foreground);
  font-size: var(--fs-lg); font-weight: 500; padding: 8px 16px; cursor: pointer; transition: opacity 0.15s;
}
#ask-user-submit:hover { opacity: 0.9; }

/* ── Markdown content rendering (shared via .md-body on system-prompt-body, prompt-body, rc-body) ── */
.md-body p { margin: 4px 0; }
.md-body :is(h1,h2,h3,h4,h5,h6) { margin: 8px 0 4px; font-weight: 600; color: var(--fg); }
.md-body h1 { font-size: var(--fs-xl); }
.md-body h2 { font-size: var(--fs-lg); }
.md-body h3 { font-size: var(--fs-base); }
.md-body :is(ul,ol) { margin: 4px 0; padding-left: 20px; }
.md-body li { margin: 2px 0; }
.md-body code {
  background: color-mix(in srgb, var(--fg) 8%, transparent); padding: 1px 4px; border-radius: 3px;
  font-family: var(--vscode-editor-font-family, 'Fira Code', monospace); font-size: var(--fs-md);
}
.md-body pre {
  background: rgba(0,0,0,0.3); border: 1px solid color-mix(in srgb, var(--fg) 8%, transparent);
  border-radius: 6px; padding: 8px 10px; overflow-x: auto; margin: 6px 0;
}
.md-body pre code { background: none; padding: 0; font-size: var(--fs-md); }
.md-body blockquote {
  border-left: 3px solid var(--accent); padding: 4px 10px; margin: 6px 0; color: var(--dim); font-style: italic;
}
.md-body a { color: var(--accent); text-decoration: underline; }
.md-body strong { font-weight: 600; color: var(--fg); }
.md-body em { font-style: italic; }
.md-body hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
.md-body table { border-collapse: collapse; margin: 6px 0; width: 100%; }
.md-body :is(th,td) {
  border: 1px solid var(--border); padding: 4px 8px; font-size: var(--fs-md);
}
.md-body th {
  background: color-mix(in srgb, var(--fg) 4%, transparent); font-weight: 600;
}

/* ── Merge Toolbar (shown in input area) ───────────── */
.merge-toolbar-card {
  background: var(--input-bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 10px; animation: fadeIn 0.2s ease;
  overflow: hidden; min-width: 0;
}
.merge-toolbar-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px; min-width: 0;
}
.merge-toolbar-title {
  font-size: var(--fs-sm); font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--accent); opacity: 0.8;
}
.merge-toolbar-hint {
  font-size: var(--fs-xs); color: var(--dim); opacity: 0.7;
}
.merge-toolbar-actions {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.merge-toolbar-row {
  display: flex; align-items: center; gap: 2px; width: 100%; min-width: 0;
}
.merge-btn {
  font-size: var(--fs-sm); font-family: inherit; border: none; border-radius: 6px;
  padding: 4px 6px; cursor: pointer; transition: all 0.15s;
  white-space: nowrap; font-weight: 500;
  display: inline-flex; align-items: center; background: none;
  justify-content: center; flex: 1 1 0;
}
.merge-btn.merge-accept {
  background: color-mix(in srgb, var(--green) 12%, transparent); color: var(--green);
}
.merge-btn.merge-accept:hover { background: color-mix(in srgb, var(--green) 22%, transparent); }
.merge-btn.merge-reject {
  background: color-mix(in srgb, var(--red) 10%, transparent); color: var(--red);
}
.merge-btn.merge-reject:hover { background: color-mix(in srgb, var(--red) 18%, transparent); }
.merge-btn.merge-nav {
  color: var(--dim); padding: 4px 6px;
}
.merge-btn.merge-nav:hover { background: color-mix(in srgb, var(--fg) 8%, transparent); color: var(--fg); }
.merge-info {
  border: 1px solid rgba(210,153,34,0.2); border-radius: 8px;
  padding: 10px 14px; margin: 8px 0;
  background: color-mix(in srgb, var(--yellow) 4%, transparent);
}

/* ── Syntax highlighting overrides ───────────────────── */
code { font-family: var(--vscode-editor-font-family, 'SF Mono', 'Fira Code', monospace); }
.hljs { background: var(--surface2) !important; border-radius: 6px; padding: 10px !important; }

/* ── Custom tooltips (native title doesn't work in VS Code webviews) ── */
#custom-tooltip {
  position: fixed; z-index: 10000; background: var(--bg2); color: var(--fg);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px;
  font-size: var(--fs-sm); line-height: 1.4; white-space: pre-wrap;
  word-break: break-word; max-width: 350px; pointer-events: none;
  opacity: 0; transition: opacity 0.15s; box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
#custom-tooltip.visible { opacity: 1; }

/* ── Scrollbar ──────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--dim); }
