/* ============================================================================
   Chat: messages, markdown, composer, chain-of-thought, file cards.
   ========================================================================== */

.chat-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 2rem 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ---------- Empty state ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin: auto;
  padding: 4rem 1rem 3rem;
  max-width: 480px;
  gap: 0.35rem;
}
.empty-state h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text-primary);
}
.empty-state p {
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.55;
}

/* ---------- Messages ---------- */
.message {
  display: flex;
  flex-direction: column;
  max-width: var(--content-width);
  margin: 0 auto;
  width: 100%;
  position: relative;
}

.message.user { align-items: flex-end; }
.message.user .message-content {
  background: var(--bg-surface);
  border-radius: var(--radius);
  padding: 0.65rem 0.9rem;
  max-width: 85%;
  font-size: 13.5px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-primary);
}

.message.assistant .message-content {
  padding: 0.25rem 0;
  font-size: 13.5px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.message-content.error-content {
  color: var(--danger);
  border-left: 2px solid var(--danger);
  padding-left: 0.75rem;
}

/* ---------- Attachments in user messages ---------- */
.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.22rem 0.55rem;
  background: var(--bg-hover);
  border-radius: 9999px;
  font-size: 11.5px;
  color: var(--text-muted);
  transition: color .12s;
}
.file-chip:hover { color: var(--text-primary); }

/* ---------- Markdown body ---------- */
.md-stream > * + * { margin-top: 0.7rem; }
.md-stream p { margin: 0; }

.md-stream h1, .md-stream h2, .md-stream h3, .md-stream h4 {
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.005em;
  color: var(--text-primary);
}
.md-stream h1 { font-size: 1.22rem; }
.md-stream h2 { font-size: 1.1rem; }
.md-stream h3 { font-size: 1rem; }
.md-stream h4 { font-size: 0.94rem; }

.md-stream ul, .md-stream ol { padding-left: 1.4rem; }
.md-stream li + li { margin-top: 0.22rem; }
.md-stream li::marker { color: var(--text-faint); }

.md-stream a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color .12s;
}
.md-stream a:hover { border-bottom-color: var(--accent); }

.md-stream code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--bg-surface);
  padding: 0.12em 0.35em;
  border-radius: 4px;
}

.md-stream pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.55;
}
.md-stream pre code {
  background: transparent;
  padding: 0;
  color: #d4d2cc;
  font-size: inherit;
}

.md-stream blockquote {
  border-left: 2px solid var(--border-strong);
  padding-left: 0.85rem;
  color: var(--text-muted);
}

.md-stream table { border-collapse: collapse; font-size: 12.5px; }
.md-stream th, .md-stream td {
  border: 1px solid var(--border);
  padding: 0.3rem 0.6rem;
}
.md-stream th { background: var(--bg-surface); }

.md-stream hr { border: none; border-top: 1px solid var(--border); }

/* ---------- Message actions ---------- */
.msg-actions {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.5rem;
  opacity: 0;
  transition: opacity .12s;
}
.message:hover .msg-actions,
.message:focus-within .msg-actions { opacity: 1; }
.message.user .msg-actions { justify-content: flex-end; }

/* ---------- Edit mode ---------- */
.edit-ta {
  width: 100%;
  min-height: 44px;
  padding: 0.6rem 0.75rem;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13.5px;
  line-height: 1.5;
  resize: vertical;
  outline: none;
  font-family: inherit;
}
.edit-ta:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
  margin-top: 0.55rem;
}

/* ---------- Composer ---------- */
.composer {
  flex-shrink: 0;
  padding: 0.75rem 1.5rem 1rem;
}

.attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding-bottom: 0.5rem;
  max-width: var(--content-width);
  margin: 0 auto;
}
.attachment-preview:empty { display: none; }

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.26rem 0.5rem 0.26rem 0.7rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 9999px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.attachment-chip > span:first-child {
  cursor: pointer;
  transition: color .12s;
}
.attachment-chip > span:first-child:hover { color: var(--text-primary); }

.attachment-remove {
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  border-radius: 9999px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  transition: background .12s, color .12s;
}
.attachment-remove:hover { background: var(--bg-hover); color: var(--text-primary); }

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0.5rem 0.5rem 0.5rem 0.4rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: border-color .15s, box-shadow .15s;
}
.composer-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.attach-btn.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  line-height: 0;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  flex-shrink: 0;
  transition: background .12s, color .12s;
}
.attach-btn.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.attach-btn.icon-btn .icon { margin: 0; }

.chat-input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.35rem;
  background: transparent;
  border: none;
  outline: none;
  font-size: 13.5px;
  line-height: 1.5;
  resize: none;
  max-height: 220px;
}
.chat-input::placeholder { color: var(--text-faint); }
.chat-input:disabled { opacity: 0.6; cursor: not-allowed; }

.send-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #0b0b0b;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: background .12s, transform .06s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.96); }
.send-btn.stopping { background: var(--danger); }

/* ---------- Composer footer: hint left, model right ---------- */
.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  max-width: var(--content-width);
  margin: 0.55rem auto 0;
  padding: 0 0.25rem;
}

.ai-notice {
  order: 1;
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quick-model {
  order: 2;
  appearance: none;
  padding: 0.28rem 1.6rem 0.28rem 0.7rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 9999px;
  color: var(--text-muted);
  font-size: 11.5px;
  cursor: pointer;
  max-width: 260px;
  text-overflow: ellipsis;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 12px) 50%, calc(100% - 8px) 50%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  transition: color .12s, border-color .12s;
}
.quick-model:hover { color: var(--text-primary); border-color: var(--border-strong); }
.quick-model option { background: var(--bg-surface); color: var(--text-primary); }

/* ---------- Chain of thought ---------- */
.cot { margin-bottom: 0.9rem; contain: content; }

.cot-summary {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  padding: 0.28rem 0.6rem 0.28rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 9999px;
  color: var(--text-muted);
  font-size: 11.5px;
  user-select: none;
  list-style: none;
  transition: background .12s, color .12s;
}
.cot-summary::-webkit-details-marker { display: none; }
.cot-summary:hover { background: var(--bg-surface); color: var(--text-primary); }

.cot-chevron {
  width: 12px;
  height: 12px;
  transition: transform .15s;
}
.cot[open] .cot-chevron { transform: rotate(90deg); }

.cot-body {
  margin-top: 0.5rem;
  padding: 0.65rem 0.75rem;
  border-left: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  contain: content;
}

.cot-reasoning {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  max-height: 260px;
  overflow-y: auto;
  font-family: var(--font-mono);
}
.cot-reasoning:empty { display: none; }

.cot-steps {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.cot-steps:empty { display: none; }

.cot-step {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--text-muted);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 11.5px;
  width: fit-content;
  max-width: 100%;
  font-family: var(--font-mono);
}
.cot-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.cot-step.running .cot-dot {
  animation: mc-pulse 1s ease-in-out infinite;
}
@keyframes mc-pulse {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 1; }
}
.cot-step.done  { color: var(--text-muted); }
.cot-step.error { color: var(--danger); border-color: var(--danger); }
.cot-step-name  { color: var(--text-primary); font-weight: 500; }
.cot-step-args {
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 340px;
}

/* ---------- File cards (attached to assistant messages) ---------- */
.file-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.file-card {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.7rem 0.45rem 0.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  max-width: 100%;
  transition: background .12s, border-color .12s;
}
.file-card:hover { background: var(--bg-hover); border-color: var(--border-strong); }

.file-card-badge {
  width: 26px;
  height: 26px;
  background: var(--accent);
  color: #0b0b0b;
  border-radius: 5px;
  display: grid;
  place-items: center;
  font-size: 9px;
  font-weight: 700;
  flex-shrink: 0;
}

.file-card-body {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  min-width: 0;
}
.file-card-path {
  font-size: 12.5px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 320px;
}
.file-card-meta {
  font-size: 10.5px;
  color: var(--text-muted);
}

/* ---------- speed-highlight skin ---------- */
.md-stream pre code[class*="shj-lang-"],
.side-code[class*="shj-lang-"] {
  background: transparent !important;
  padding: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  font-size: inherit !important;
  line-height: inherit !important;
  margin: 0 !important;
  max-width: none !important;
  color: #d4d2cc !important;
  text-shadow: none !important;
  font-family: var(--font-mono) !important;
}
.md-stream pre code[class*="shj-lang-"] > div,
.side-code[class*="shj-lang-"] > div { display: block; }
.md-stream pre code[class*="shj-lang-"] .shj-numbers,
.side-code[class*="shj-lang-"] .shj-numbers { display: none; }