/* ── Messages container ────────────────────────────────────────────────────── */

.copilot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

/* ── Message bubbles ───────────────────────────────────────────────────────── */

.copilot-msg {
  padding: 0.6rem 0.9rem;
  border-radius: 0.75rem;
  font-size: 0.85rem;
  line-height: 1.55;
  max-width: 88%;
}

.copilot-msg.assistant {
  background: var(--msg-assistant-bg);
  color: var(--msg-assistant-text);
  align-self: flex-start;
  border-bottom-left-radius: 0.2rem;
}

.copilot-msg.user {
  background: var(--msg-user-bg);
  color: var(--msg-user-text);
  align-self: flex-end;
  border-bottom-right-radius: 0.2rem;
}

.copilot-msg.error {
  background: #fef2f2;
  color: #991b1b;
  align-self: flex-start;
  border-bottom-left-radius: 0.2rem;
  font-size: 0.82rem;
}

@media (prefers-color-scheme: dark) {
  .copilot-msg.error {
    background: #2d1515;
    color: #fca5a5;
  }
}

.copilot-msg.info {
  background: #f0f9ff;
  color: #0369a1;
  align-self: flex-start;
  border-bottom-left-radius: 0.2rem;
  font-size: 0.80rem;
}

@media (prefers-color-scheme: dark) {
  .copilot-msg.info {
    background: #0c1e2d;
    color: #7dd3fc;
  }
}

.copilot-msg--failed {
  opacity: 0.6;
}

.copilot-failed-badge {
  color: #dc2626;
  font-size: 0.75rem;
  margin-right: 0.35rem;
  flex-shrink: 0;
}

.copilot-thinking {
  opacity: 0.65;
}

.copilot-token-count {
  margin-top: 0.3rem;
  font-size: 0.7rem;
  color: var(--placeholder-color);
  opacity: 0.6;
  font-style: normal;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

/* ── Tool call blocks ──────────────────────────────────────────────────────── */

.copilot-tool {
  font-size: 0.78rem;
}

/* Pending approval needs to stand out */
.copilot-tool--pending {
  border: 1px solid var(--toolbar-border);
  border-radius: 0.4rem;
  border-left: 3px solid #f59e0b;
}

.copilot-tool-header {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
  padding: 0.15rem 0.25rem;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  font-size: 0.78rem;
  color: var(--placeholder-color);
  transition: color 0.12s;
}

.copilot-tool--pending .copilot-tool-header {
  padding: 0.4rem 0.6rem;
}

.copilot-tool-header:hover {
  color: inherit;
}

.copilot-tool-status {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  font-size: 0.7rem;
}

.copilot-tool-name {
  font-weight: 400;
  font-family: var(--bs-font-monospace);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.copilot-tool-name code {
  font-family: inherit;
  font-size: inherit;
  background: rgba(0,0,0,0.06);
  border-radius: 0.2rem;
  padding: 0 0.25em;
}

@media (prefers-color-scheme: dark) {
  .copilot-tool-name code {
    background: rgba(255,255,255,0.08);
  }
}

/* A file path that opens the file viewer. Reads as a code chip but acts as a link. */
.copilot-tool-name .copilot-tool-path,
.copilot-tool-path {
  font-family: var(--bs-font-monospace);
  font-size: inherit;
  color: #6366f1;
  cursor: pointer;
  border-radius: 0.2rem;
  padding: 0 0.25em;
  background: rgba(99,102,241,0.10);
  text-decoration: none;
}

.copilot-tool-path:hover {
  text-decoration: underline;
  background: rgba(99,102,241,0.18);
}

.copilot-tool-body {
  border-top: 1px solid var(--toolbar-border);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.copilot-tool-section {
  display: flex;
  flex-direction: column;
  padding: 0.4rem 0.6rem;
}

.copilot-tool-section + .copilot-tool-section {
  border-top: 1px solid var(--toolbar-border);
}

.copilot-tool-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.25rem;
  color: var(--placeholder-color);
}

.copilot-tool-label--done  { color: #16a34a; }
.copilot-tool-label--error { color: #dc2626; }

.copilot-tool-pre {
  font-size: 0.72rem;
  font-family: var(--bs-font-monospace);
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
  padding: 0.35rem 0.5rem;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 0.25rem;
  max-height: 200px;
  overflow-y: auto;
}

@media (prefers-color-scheme: dark) {
  .copilot-tool-pre {
    background: rgba(255, 255, 255, 0.04);
  }
}

.copilot-tool-pre--error { color: #dc2626; }

/* Structured (`result_type === 'json'`) results: keep JSON readable (don't break
   mid-token) and flag the typed payload with a left accent. */
.copilot-tool-pre--json {
  word-break: normal;
  overflow-x: auto;
  border-left: 2px solid var(--bs-info, #0dcaf0);
}

/* ── Markdown rendering ────────────────────────────────────────────────────── */

.copilot-markdown { max-width: 100%; }

.copilot-markdown > *:first-child { margin-top: 0; }
.copilot-markdown > *:last-child  { margin-bottom: 0; }

.copilot-markdown h1,
.copilot-markdown h2,
.copilot-markdown h3,
.copilot-markdown h4 {
  font-size: 0.9rem;
  font-weight: 700;
  margin: 0.75rem 0 0.3rem;
  line-height: 1.3;
}

.copilot-markdown p  { margin: 0.4rem 0; }

.copilot-markdown ul,
.copilot-markdown ol {
  margin: 0.4rem 0;
  padding-left: 1.4rem;
}

.copilot-markdown li { margin: 0.15rem 0; }

.copilot-markdown code {
  font-family: var(--bs-font-monospace);
  font-size: 0.78rem;
  background: rgba(0, 0, 0, 0.08);
  padding: 0.1em 0.35em;
  border-radius: 0.25rem;
}

@media (prefers-color-scheme: dark) {
  .copilot-markdown code { background: rgba(255, 255, 255, 0.1); }
}

.copilot-markdown pre {
  background: rgba(0, 0, 0, 0.06);
  border-radius: 0.4rem;
  padding: 0.65rem 0.85rem;
  overflow-x: auto;
  margin: 0.5rem 0;
  font-size: 0.78rem;
}

@media (prefers-color-scheme: dark) {
  .copilot-markdown pre { background: rgba(255, 255, 255, 0.06); }
}

.copilot-markdown pre code { background: none; padding: 0; font-size: inherit; }

.copilot-markdown blockquote {
  border-left: 3px solid #6366f1;
  margin: 0.5rem 0;
  padding: 0.3rem 0.75rem;
  color: var(--placeholder-color);
  font-style: italic;
}

.copilot-markdown hr {
  border: none;
  border-top: 1px solid var(--toolbar-border);
  margin: 0.6rem 0;
}

.copilot-markdown a    { color: #6366f1; text-decoration: underline; }
.copilot-markdown strong { font-weight: 700; }
.copilot-markdown em     { font-style: italic; }

/* Keep wide content inside the bubble so it never stretches the message list
   (which would let the whole page pan sideways). Images shrink to the bubble
   width; tables become their own horizontal scroll box. Code blocks (`pre`)
   already scroll within themselves (overflow-x: auto above). */
.copilot-markdown img {
  max-width: 100%;
  height: auto;
  border-radius: 0.4rem;
}

.copilot-markdown table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

/* ── Approval panel ────────────────────────────────────────────────────────── */

.copilot-approval {
  border: 1px solid var(--toolbar-border);
  border-radius: 0.5rem;
  font-size: 0.82rem;
}

.copilot-approval--approved { border-color: #16a34a; }
.copilot-approval--rejected { border-color: #dc2626; }

.copilot-approval-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  background: var(--msg-assistant-bg);
  font-size: 0.8rem;
  flex-wrap: wrap;
}

.copilot-approval-path {
  font-family: var(--bs-font-monospace);
  font-size: 0.75rem;
  color: #6366f1;
}

.copilot-approval-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--toolbar-border);
}

.copilot-approval-btns {
  display: flex;
  gap: 0.4rem;
}

.copilot-reject-note {
  font-size: 0.8rem;
  resize: none;
}

.copilot-clarification-title {
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text-primary, #1e293b);
}

.copilot-clarification-question {
  font-size: 0.82rem;
  color: var(--text-secondary, #475569);
}

.copilot-clarification-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.copilot-chip {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.copilot-clarification-input-row {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
}

/* ── Diff view ─────────────────────────────────────────────────────────────── */

.copilot-diff {
  font-family: var(--bs-font-monospace);
  font-size: 0.72rem;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
  max-height: 320px;
  overflow-y: auto;
  margin: 0;
  padding: 0.5rem 0;
  background: transparent;
  border-top: 1px solid var(--toolbar-border);
}

.diff-added {
  display: block;
  background: rgba(22, 163, 74, 0.12);
  color: #15803d;
  padding: 0 0.75rem;
}

.diff-removed {
  display: block;
  background: rgba(220, 38, 38, 0.1);
  color: #b91c1c;
  padding: 0 0.75rem;
  text-decoration: line-through;
  opacity: 0.85;
}

.diff-unchanged {
  display: block;
  padding: 0 0.75rem;
  color: var(--placeholder-color);
}

.diff-ellipsis {
  display: block;
  padding: 0.1rem 0.75rem;
  color: var(--placeholder-color);
  font-style: italic;
  background: rgba(0, 0, 0, 0.03);
  text-align: center;
}

@media (prefers-color-scheme: dark) {
  .diff-added    { color: #4ade80; }
  .diff-removed  { color: #f87171; }
  .diff-ellipsis { background: rgba(255, 255, 255, 0.03); }
}

/* ── Agent trace ───────────────────────────────────────────────────────────── */

.copilot-agent,
.copilot-agent-end {
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: 0.5rem;
  font-size: 0.78rem;
  overflow: clip;
  margin-left: calc(var(--agent-depth, 0) * 1rem);
}

.copilot-agent-header {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.65rem;
  background: rgba(99, 102, 241, 0.12);
  color: var(--msg-assistant-text);
}

.copilot-agent-header i {
  font-size: 0.85rem;
  flex-shrink: 0;
  color: #6366f1;
}

.copilot-agent-header strong {
  color: #6366f1;
  font-weight: 600;
}

.copilot-agent-badge {
  margin-left: auto;
  font-size: 0.67rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1rem 0.4rem;
  border-radius: 0.25rem;
}

.copilot-agent-badge.running {
  background: rgba(234, 179, 8, 0.15);
  color: #b45309;
}

.copilot-agent-badge.done {
  background: rgba(22, 163, 74, 0.12);
  color: #15803d;
}

.copilot-agent-preview {
  font-size: 0.75rem;
  font-family: var(--bs-font-monospace);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  padding: 0.45rem 0.65rem;
  color: var(--placeholder-color);
  border-top: 1px solid rgba(99, 102, 241, 0.15);
  max-height: 120px;
  overflow-y: auto;
  background: rgba(99, 102, 241, 0.05);
}

.copilot-agent-preview--result {
  color: var(--msg-assistant-text);
  opacity: 0.8;
}

@media (prefers-color-scheme: dark) {
  .copilot-agent-badge.running { background: rgba(234, 179, 8, 0.2);  color: #fbbf24; }
  .copilot-agent-badge.done    { background: rgba(22, 163, 74, 0.18); color: #4ade80; }
  .copilot-agent-header        { background: rgba(99, 102, 241, 0.1); }
}

/* ── Attachment chips (composer pending + sent user bubble) ──────────────────── */

.attach-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.4rem 0.5rem;
}

/* Inside a user bubble the chips sit below the text with a little top spacing. */
.copilot-msg.user .attach-chips {
  padding: 0.4rem 0 0;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 100%;
  padding: 0.2rem 0.45rem;
  border: 1px solid var(--toolbar-border);
  border-radius: 0.5rem;
  background: var(--msg-assistant-bg);
  font-size: 0.75rem;
  line-height: 1.2;
}

.attach-chip--clickable { cursor: pointer; }
.attach-chip--clickable:hover { border-color: #6366f1; }
.attach-chip--uploading { opacity: 0.7; }

.attach-chip .bi { font-size: 0.85rem; flex-shrink: 0; }

.attach-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 12rem;
}

.attach-chip-size {
  color: var(--placeholder-color);
  flex-shrink: 0;
}

.attach-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  padding: 0;
  border: none;
  border-radius: 0.3rem;
  background: transparent;
  color: var(--placeholder-color);
  cursor: pointer;
  flex-shrink: 0;
}

.attach-chip-remove:hover { background: var(--sidebar-hover); color: #dc2626; }
