/*
 * VS Code Copilot Chat CSS
 * Extracted from: microsoft/vscode src/vs/workbench/contrib/chat/browser/widget/media/chat.css
 * License: MIT (Microsoft Corporation)
 *
 * This file contains the core chat message styling adapted for standalone use
 * with CSS custom properties replacing VS Code theme variables.
 */

/* ── Theme Variable Fallbacks ──────────────────────────────── */
:root {
  /* Editor */
  --vscode-editor-background: #1e1e1e;
  --vscode-editor-foreground: #cccccc;
  --vscode-editorWidget-background: #252526;
  --vscode-editorWidget-border: #454545;

  /* Input */
  --vscode-input-background: #313131;
  --vscode-input-foreground: #cccccc;
  --vscode-input-border: #3c3c3c;
  --vscode-input-placeholderForeground: #858585;
  --vscode-inputOption-activeBackground: #0078d4;
  --vscode-inputOption-activeBorder: #0078d4;
  --vscode-inputOption-activeForeground: #ffffff;

  /* Focus */
  --vscode-focusBorder: #007acc;

  /* Text */
  --vscode-textLink-foreground: #3794ff;
  --vscode-textLink-activeForeground: #3794ff;
  --vscode-textPreformat-foreground: #d7ba7d;
  --vscode-textPreformat-background: rgba(255, 255, 255, 0.06);
  --vscode-textPreformat-border: rgba(255, 255, 255, 0.08);
  --vscode-textBlockQuote-background: rgba(255, 255, 255, 0.04);
  --vscode-textBlockQuote-border: rgba(255, 255, 255, 0.08);
  --vscode-textCodeBlock-background: rgba(255, 255, 255, 0.04);

  /* Interactive Session */
  --vscode-interactive-session-foreground: #cccccc;
  --vscode-interactive-result-editor-background-color: #1e1e1e;
  --vscode-descriptionForeground: #858585;

  /* Chat specific */
  --vscode-chat-requestBorder: rgba(255, 255, 255, 0.08);
  --vscode-chat-requestBubbleBackground: rgba(90, 93, 94, 0.15);
  --vscode-chat-requestBubbleHoverBackground: rgba(90, 93, 94, 0.25);
  --vscode-chat-avatarBackground: #1f1f1f;
  --vscode-chat-avatarForeground: #cccccc;
  --vscode-chat-list-background: #1e1e1e;
  --vscode-chat-slashCommandBackground: rgba(255, 255, 255, 0.04);
  --vscode-chat-slashCommandForeground: #cccccc;

  /* Font sizes (base 13px) — from VS Code chat.css */
  --vscode-chat-font-size-body-xs: 0.846em;
  --vscode-chat-font-size-body-s: 0.923em;
  --vscode-chat-font-size-body-m: 1em;
  --vscode-chat-font-size-body-l: 1.077em;
  --vscode-chat-font-size-body-xl: 1.231em;
  --vscode-chat-font-size-body-xxl: 1.538em;

  /* Chat font family */
  --vscode-chat-font-family: inherit;

  /* Monospace */
  --monaco-monospace-font: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;

  /* Buttons */
  --vscode-button-background: #0078d4;
  --vscode-button-foreground: #ffffff;
  --vscode-button-hoverBackground: #1a8cff;
  --vscode-button-secondaryBackground: #3c3c3c;
  --vscode-button-secondaryForeground: #cccccc;
  --vscode-button-secondaryHoverBackground: #454545;

  /* Widget */
  --vscode-widget-border: #454545;
  --vscode-list-hoverBackground: rgba(90, 93, 94, 0.31);

  /* Toolbar */
  --vscode-toolbar-hoverBackground: rgba(90, 93, 94, 0.31);

  /* Disabled */
  --vscode-disabledForeground: #858585;

  /* Corner radius */
  --vscode-cornerRadius-small: 4px;
  --vscode-cornerRadius-medium: 6px;
  --vscode-cornerRadius-large: 8px;
  --vscode-cornerRadius-xLarge: 16px;
  --vscode-cornerRadius-circle: 50%;

  /* Error */
  --vscode-errorForeground: #f44747;

  /* Background */
  --vscode-sideBar-background: #252526;
}

/* ── Global Reset ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%; width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
  background: var(--vscode-editor-background);
  color: var(--vscode-interactive-session-foreground);
  overflow: hidden;
}
body { display: flex; flex-direction: column; }

/* ── Interactive Session Container ─────────────────────────── */
.interactive-session {
  display: flex;
  flex-direction: column;
  max-width: 950px;
  height: 100%;
  margin: auto;
  position: relative;
}

/* ── Interactive List ──────────────────────────────────────── */
.interactive-list {
  overflow: hidden;
  position: relative;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Item Container (both request and response) ────────────── */
.interactive-item-container {
  padding: 5px 16px;
  display: flex;
  flex-direction: column;
  color: var(--vscode-interactive-session-foreground);
  cursor: default;
  user-select: text;
  -webkit-user-select: text;
}

/* ── Header ────────────────────────────────────────────────── */
.interactive-item-container .header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  margin-bottom: 8px;
}
.interactive-item-container .header.hidden { display: none; }

.interactive-item-container .header .user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px;
  margin: -2px;
}
.interactive-item-container .header .username {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}
.interactive-item-container .header .avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  outline: 1px solid var(--vscode-chat-requestBorder);
}
.interactive-item-container .header .avatar.codicon-avatar {
  background: var(--vscode-chat-avatarBackground);
}
.interactive-item-container .header .avatar .codicon {
  color: var(--vscode-chat-avatarForeground) !important;
  font-size: 14px;
}

/* ── Value (content area) ──────────────────────────────────── */
.interactive-item-container .value {
  width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}
.interactive-item-container .value > :last-child,
.interactive-item-container .value > :last-child.rendered-markdown > :last-child {
  margin-bottom: 0px;
}

/* ── Rendered Markdown ─────────────────────────────────────── */
.interactive-item-container .value .rendered-markdown {
  line-height: 1.5em;
  font-size: var(--vscode-chat-font-size-body-m);
  font-family: var(--vscode-chat-font-family, inherit);
}
.interactive-item-container .value > .rendered-markdown p {
  margin: 0 0 16px 0;
}
.interactive-item-container .value > .rendered-markdown li > p {
  margin: 0;
}
.interactive-item-container .value .rendered-markdown strong {
  font-weight: 600;
}

/* Headings */
.interactive-item-container .value .rendered-markdown h1 {
  font-size: var(--vscode-chat-font-size-body-xxl);
  font-weight: 600;
  margin: 1.5em 0 0.875em 0;
}
.interactive-item-container .value .rendered-markdown h2 {
  font-size: var(--vscode-chat-font-size-body-xl);
  font-weight: 600;
  margin: 1.5em 0 0.875em 0;
}
.interactive-item-container .value .rendered-markdown h3 {
  font-size: var(--vscode-chat-font-size-body-l);
  font-weight: 600;
  margin: 1.5em 0 0.875em 0;
}

/* Lists */
.interactive-item-container .value .rendered-markdown ul {
  padding-inline-start: 24px;
}
.interactive-item-container .value .rendered-markdown ol {
  padding-inline-start: 28px;
}
.interactive-item-container .value .rendered-markdown li {
  margin: 4px 0;
}

/* Blockquote */
.interactive-item-container .value .rendered-markdown blockquote {
  margin: 0px;
  padding: 0px 16px 0 10px;
  border-left-width: 5px;
  border-left-style: solid;
  border-radius: 2px;
  background: var(--vscode-textBlockQuote-background);
  border-color: var(--vscode-textBlockQuote-border);
}

/* Table */
.interactive-item-container .value .rendered-markdown table {
  text-align: left;
  border-radius: var(--vscode-cornerRadius-medium);
  overflow: hidden;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--vscode-chat-requestBorder);
  margin: 8px 0;
  width: 100%;
  display: table;
}
.interactive-item-container .value .rendered-markdown table td,
.interactive-item-container .value .rendered-markdown table th {
  border: 1px solid var(--vscode-chat-requestBorder);
  border-top: none;
  border-left: none;
  padding: 4px 6px;
}
.interactive-item-container .value .rendered-markdown table th {
  white-space: normal;
  overflow-wrap: break-word;
}
.interactive-item-container .value .rendered-markdown table td:last-child,
.interactive-item-container .value .rendered-markdown table th:last-child {
  border-right: none;
}
.interactive-item-container .value .rendered-markdown table tbody tr:last-child td {
  border-bottom: none;
}

/* Links */
.interactive-item-container .value .rendered-markdown a,
.interactive-item-container .value .rendered-markdown a code {
  color: var(--vscode-textLink-foreground);
}
.interactive-item-container .value .rendered-markdown a {
  user-select: text;
  text-decoration: none;
}
.interactive-item-container .value .rendered-markdown a:hover,
.interactive-item-container .value .rendered-markdown a:active {
  color: var(--vscode-textLink-activeForeground);
}

/* HR */
.interactive-item-container .value .rendered-markdown hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  margin: 12px 0;
}

/* Images */
.interactive-item-container .value .rendered-markdown img {
  max-width: 100%;
}

/* Inline code */
.interactive-item-container .value .rendered-markdown code:not(pre code),
.interactive-item-container code {
  font-family: var(--monaco-monospace-font);
  font-size: var(--vscode-chat-font-size-body-xs);
  color: var(--vscode-textPreformat-foreground);
  background-color: var(--vscode-textPreformat-background);
  padding: 1px 3px;
  border-radius: 4px;
  border: 1px solid var(--vscode-textPreformat-border);
  white-space: pre-wrap;
}

/* ── Request (user bubble, right-aligned) ──────────────────── */
.interactive-item-container.interactive-request {
  align-items: flex-end;
}
.interactive-item-container.interactive-request .value {
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-end !important;
}
.interactive-item-container.interactive-request .value .rendered-markdown {
  background-color: var(--vscode-chat-requestBubbleBackground);
  border-radius: var(--vscode-cornerRadius-xLarge);
  padding: 8px 12px;
  max-width: 90%;
  margin-left: auto;
  width: fit-content;
  margin-bottom: 5px;
  position: relative;
}
.interactive-item-container.interactive-request .value .rendered-markdown:hover {
  background-color: var(--vscode-chat-requestBubbleHoverBackground);
}
.interactive-item-container.interactive-request .value .rendered-markdown > :first-child {
  margin-top: 0px;
}
.interactive-item-container.interactive-request .value .rendered-markdown > :last-child {
  margin-bottom: 0px;
}
.interactive-item-container.interactive-request .value > .rendered-markdown p {
  width: fit-content;
}

/* ── Response ──────────────────────────────────────────────── */
.interactive-item-container.interactive-response {
  align-items: flex-start;
}

/* ── Code Blocks ───────────────────────────────────────────── */
.interactive-result-code-block {
  margin: 8px 0;
  border-radius: var(--vscode-cornerRadius-medium);
  border: 1px solid var(--vscode-editorWidget-border);
  overflow: hidden;
}
.interactive-result-code-block .interactive-result-code-block-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  background: var(--vscode-editorWidget-background);
  border-bottom: 1px solid var(--vscode-editorWidget-border);
  font-size: var(--vscode-chat-font-size-body-s);
  color: var(--vscode-descriptionForeground);
}
.interactive-result-code-block .interactive-result-editor {
  padding: 0;
}
.interactive-result-code-block pre {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--vscode-editor-background);
}
.interactive-result-code-block code {
  font-family: var(--monaco-monospace-font);
  font-size: var(--vscode-chat-font-size-body-s);
  line-height: 1.5;
  color: var(--vscode-editor-foreground);
  background: transparent;
  border: none;
  padding: 0;
  white-space: pre;
}

/* ── Tool Invocation ───────────────────────────────────────── */
.interactive-item-container .value > .chat-tool-invocation-part {
  margin: 4px 0;
}
.interactive-item-container .value > .chat-tool-invocation-part .rendered-markdown p {
  margin: 0 0 6px 0;
}
.interactive-item-container .value > .chat-tool-invocation-part .tool-input-output-part {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}
.interactive-item-container .value > .chat-tool-invocation-part .tool-input-output-part .rendered-markdown p {
  margin: inherit;
}
.interactive-item-container .value > .chat-tool-invocation-part .tool-input-output-part .expando {
  display: flex;
  align-items: center;
  cursor: pointer;
}
.interactive-item-container .value > .chat-tool-invocation-part .tool-input-output-part .input-output {
  display: none;
  padding: 6px 0;
  flex-basis: 100%;
  width: 100%;
}
.interactive-item-container .value > .chat-tool-invocation-part .tool-input-output-part.expanded .input-output {
  display: inherit;
}
.interactive-item-container .value > .chat-tool-invocation-part .tool-output-part {
  border: 1px solid var(--vscode-widget-border);
  border-radius: var(--vscode-cornerRadius-medium);
  background: var(--vscode-editor-background);
  margin: 4px 0;
  overflow: hidden;
}
.interactive-item-container .value > .chat-tool-invocation-part .tool-output-part .output-title {
  padding: 8px 12px;
  background: var(--vscode-editorWidget-background);
  border-bottom: 1px solid var(--vscode-widget-border);
  font-size: var(--vscode-chat-font-size-body-m);
}
.interactive-item-container .value > .chat-tool-invocation-part:not(:last-child) {
  margin-bottom: 14px;
}

/* ── Progress Container ────────────────────────────────────── */
.interactive-item-container .progress-container {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 0 14px 0;
  font-size: var(--vscode-chat-font-size-body-m);
  padding-top: 2px;
}
.interactive-item-container .progress-container .codicon {
  color: var(--vscode-editorWidget-border) !important;
  margin: 0 .2em;
}
.interactive-item-container .progress-container .rendered-markdown.progress-step {
  white-space: normal;
}
.interactive-item-container .progress-container .rendered-markdown.progress-step > p {
  color: var(--vscode-descriptionForeground);
  font-size: var(--vscode-chat-font-size-body-s);
  margin: 0;
}

/* Animated ellipsis */
@keyframes ellipsis {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
  100% { content: ''; }
}
.show-detail-progress .chat-animated-ellipsis,
.interactive-item-container:not(.show-detail-progress) .chat-animated-ellipsis {
  display: none;
}
.show-detail-progress > p:last-child::after {
  content: '';
  display: inline-block;
  width: 2em;
  animation: ellipsis steps(4, end) 1s infinite;
}

/* ── Chat Input Container ──────────────────────────────────── */
.chat-input-container {
  box-sizing: border-box;
  cursor: text;
  background-color: var(--vscode-input-background);
  border: 1px solid var(--vscode-input-border, transparent);
  border-radius: var(--vscode-cornerRadius-xLarge);
  padding: 10px 14px;
  width: 100%;
  position: relative;
  transition: border-color 0.15s;
  color: var(--vscode-input-foreground);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  max-height: 120px;
  outline: none;
}
.chat-input-container:focus {
  border-color: var(--vscode-focusBorder);
}
.chat-input-container::placeholder {
  color: var(--vscode-input-placeholderForeground);
}

/* ── Status Bar ────────────────────────────────────────────── */
.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--vscode-editor-background);
  border-bottom: 1px solid var(--vscode-editorWidget-border);
  font-size: var(--vscode-chat-font-size-body-s);
  flex-shrink: 0;
}
.status-bar .status-icon {
  font-size: 10px;
}
.status-bar .status-icon.disconnected { color: var(--vscode-descriptionForeground); }
.status-bar .status-icon.connecting { color: #cca700; animation: pulse 1s infinite; }
.status-bar .status-icon.connected { color: #4ec9b0; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Mode selector */
.mode-selector {
  display: flex;
  gap: 2px;
  background: var(--vscode-editorWidget-background);
  border-radius: var(--vscode-cornerRadius-small);
  padding: 2px;
  margin-left: auto;
}
.mode-btn {
  background: none;
  border: none;
  color: var(--vscode-descriptionForeground);
  font-size: var(--vscode-chat-font-size-body-xs);
  padding: 3px 10px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
}
.mode-btn.active {
  background: var(--vscode-button-background);
  color: var(--vscode-button-foreground);
}

/* ── Confirmation Dialog ───────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.overlay.hidden { display: none; }
.confirm-dialog {
  background: var(--vscode-editorWidget-background);
  border: 1px solid var(--vscode-editorWidget-border);
  border-radius: var(--vscode-cornerRadius-large);
  padding: 16px;
  max-width: 400px;
  width: 100%;
}
.confirm-title {
  font-size: var(--vscode-chat-font-size-body-l);
  font-weight: 600;
  color: var(--vscode-editor-foreground);
  margin-bottom: 10px;
}
.confirm-message {
  font-size: var(--vscode-chat-font-size-body-m);
  color: var(--vscode-editor-foreground);
  line-height: 1.5;
  margin-bottom: 14px;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  font-family: var(--monaco-monospace-font);
  background: var(--vscode-editor-background);
  padding: 10px;
  border-radius: var(--vscode-cornerRadius-small);
}
.confirm-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--vscode-cornerRadius-small);
  font-size: var(--vscode-chat-font-size-body-m);
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-primary {
  background: var(--vscode-button-background);
  color: var(--vscode-button-foreground);
}
.btn-primary:hover { background: var(--vscode-button-hoverBackground); }
.btn-secondary {
  background: var(--vscode-button-secondaryBackground);
  color: var(--vscode-button-secondaryForeground);
  border: 1px solid var(--vscode-editorWidget-border);
}
.btn-secondary:hover { background: var(--vscode-button-secondaryHoverBackground); }

/* ── Input Area ────────────────────────────────────────────── */
.input-area {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 10px 12px 4px;
  background: transparent;
  margin: 0 12px;
  flex-shrink: 0;
}
.attach-btn, .send-btn {
  background: none;
  border: none;
  cursor: pointer;
  border-radius: var(--vscode-cornerRadius-small);
  color: var(--vscode-descriptionForeground);
  transition: all 0.15s;
  flex-shrink: 0;
  padding: 8px;
  font-size: 18px;
}
.send-btn {
  background: var(--vscode-button-background);
  color: var(--vscode-button-foreground);
  border-radius: var(--vscode-cornerRadius-circle);
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  padding: 5px;
}
.send-btn:hover { background: var(--vscode-button-hoverBackground); }
.send-btn:disabled { opacity: 0.4; cursor: default; }
.attach-btn:hover {
  background: var(--vscode-toolbar-hoverBackground);
  color: var(--vscode-editor-foreground);
}

/* ── System Message ────────────────────────────────────────── */
.system-msg {
  text-align: center;
  color: var(--vscode-descriptionForeground);
  font-size: var(--vscode-chat-font-size-body-s);
  padding: 8px 16px;
  margin: 4px 0;
}

/* ── Copy Button ───────────────────────────────────────────── */
.copy-btn {
  background: none;
  border: 1px solid var(--vscode-editorWidget-border);
  color: var(--vscode-descriptionForeground);
  font-size: var(--vscode-chat-font-size-body-xs);
  padding: 2px 8px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
}
.copy-btn:hover {
  background: var(--vscode-toolbar-hoverBackground);
  color: var(--vscode-editor-foreground);
}
.copy-btn.copied {
  color: #4ec9b0;
  border-color: #4ec9b0;
}

/* ── Language Label ────────────────────────────────────────── */
.code-block-lang {
  font-family: var(--monaco-monospace-font);
  font-size: var(--vscode-chat-font-size-body-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (min-width: 768px) {
  .interactive-session { padding: 0 24px; }
  .overlay { align-items: center; }
}
