/* Cursor 风格聊天渲染：层次清晰、分区着色、段落分明 */

.chat-messages {
  padding: 14px 16px;
  gap: 18px;
}

.chat-turn {
  padding: 0;
  border-bottom: none;
}

.chat-turn.user {
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(236, 72, 153, 0.07);
  border: 1px solid rgba(236, 72, 153, 0.18);
}

.chat-turn.assistant {
  padding: 2px 4px 8px;
  background: transparent;
}

.chat-turn.notice {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.06);
  border: 1px solid rgba(59, 130, 246, 0.15);
}

.chat-turn.notice .chat-turn-label {
  color: var(--text-muted, #94a3b8);
}

.chat-turn-head {
  margin-bottom: 10px;
}

.chat-turn-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.chat-turn.user .chat-turn-label {
  color: color-mix(in srgb, var(--primary) 75%, #fff);
}

.chat-turn.assistant .chat-turn-label {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.chat-turn-body {
  font-size: 14px;
  line-height: 1.72;
  color: color-mix(in srgb, var(--text) 94%, #fff);
  word-break: break-word;
  letter-spacing: 0.01em;
}

.chat-turn.user .chat-turn-body {
  font-size: 14px;
  color: #f9fafb;
}

.chat-turn.streaming .chat-turn-body::after {
  content: '▍';
  display: inline-block;
  margin-left: 2px;
  color: var(--accent);
  animation: chat-cursor-blink 1s step-end infinite;
}

@keyframes chat-cursor-blink {
  50% { opacity: 0; }
}

.chat-system-note {
  font-size: 12px;
  color: var(--text-muted);
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}

/* —— Markdown 正文 —— */

.chat-md > *:first-child {
  margin-top: 0;
}

.chat-md p {
  margin: 0 0 12px;
  color: color-mix(in srgb, var(--text) 92%, #cbd5e1);
}

.chat-md p:last-child {
  margin-bottom: 0;
}

.chat-md-strong {
  color: #f8fafc;
  font-weight: 650;
}

.chat-md-em {
  color: color-mix(in srgb, var(--accent) 35%, #e5e7eb);
  font-style: italic;
}

.chat-md-h1,
.chat-md-h2,
.chat-md-h3 {
  margin: 18px 0 10px;
  line-height: 1.35;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.chat-md-h1:first-child,
.chat-md-h2:first-child,
.chat-md-h3:first-child {
  margin-top: 0;
}

.chat-md-h1 {
  font-size: 20px;
  color: #ffffff;
}

.chat-md-h2 {
  font-size: 17px;
  color: #f3f4f6;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-md-h3 {
  font-size: 13px;
  color: color-mix(in srgb, var(--accent) 55%, #e5e7eb);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.chat-md-exec-title {
  margin-top: 22px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: color-mix(in srgb, var(--accent) 70%, #fff);
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid rgba(139, 92, 246, 0.22);
  display: inline-block;
}

.chat-md-list {
  margin: 0 0 14px;
  padding-left: 1.35em;
}

.chat-md-list li {
  margin: 6px 0;
  padding-left: 2px;
  color: color-mix(in srgb, var(--text) 88%, #cbd5e1);
}

.chat-md-list li::marker {
  color: color-mix(in srgb, var(--accent) 65%, #fff);
}

.chat-md-exec-list {
  list-style: none;
  margin: 10px 0 16px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.chat-md-exec-list li {
  margin: 0;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-md-exec-list li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.chat-md-exec-list li:first-child {
  padding-top: 0;
}

.chat-li-status {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  list-style: none;
  margin-left: 0;
  padding-left: 0;
}

.chat-li-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.chat-li-text {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  line-height: 1.55;
}

.chat-li-ok .chat-li-icon {
  color: #6ee7b7;
  background: rgba(52, 211, 153, 0.15);
}

.chat-li-ok .chat-li-text {
  color: #d1fae5;
}

.chat-li-err .chat-li-icon {
  color: #fca5a5;
  background: rgba(248, 113, 113, 0.15);
}

.chat-li-err .chat-li-text {
  color: #fecaca;
}

.chat-li-warn .chat-li-icon {
  color: #fcd34d;
  background: rgba(251, 191, 36, 0.15);
}

.chat-li-warn .chat-li-text {
  color: #fde68a;
}

.chat-md-quote {
  margin: 12px 0;
  padding: 10px 12px;
  border-left: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 0 10px 10px 0;
  font-size: 13px;
}

.chat-md-hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin: 16px 0;
}

.chat-md-callout {
  margin: 14px 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.6;
}

.chat-md-callout p {
  margin: 0;
}

.chat-md-callout-result {
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.28);
  color: #d1fae5;
}

.chat-md-callout-result .chat-md-strong {
  color: #6ee7b7;
}

.chat-md-callout-warn {
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.28);
  color: #fde68a;
}

.chat-md-inline-code,
.chat-code code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.chat-md-inline-code {
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(139, 92, 246, 0.14);
  border: 1px solid rgba(139, 92, 246, 0.25);
  color: #e9d5ff;
}

.chat-md-link {
  color: color-mix(in srgb, var(--accent) 75%, #fff);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-md-link:hover {
  color: #fff;
}

.chat-code-wrap {
  margin: 14px 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  overflow: hidden;
  background: #0b0f17;
}

.chat-code-wrap.is-partial {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}

.chat-code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
}

.chat-code-lang {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: color-mix(in srgb, var(--accent) 60%, #fff);
  text-transform: lowercase;
}

.chat-code {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  white-space: pre;
  line-height: 1.55;
}

.chat-code code {
  color: #e5e7eb;
}

.chat-tool-card,
.chat-file-card {
  margin: 12px 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.chat-tool-card[data-status="running"],
.chat-file-card[data-status="running"] {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.chat-tool-head,
.chat-file-head {
  width: 100%;
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  text-align: left;
  background: rgba(255, 255, 255, 0.04);
  border: none;
  color: var(--text);
  cursor: pointer;
}

.chat-tool-head:hover,
.chat-file-head:hover {
  background: rgba(255, 255, 255, 0.06);
}

.chat-tool-icon,
.chat-file-icon {
  font-size: 13px;
  opacity: 0.85;
}

.chat-tool-name,
.chat-file-name {
  font-size: 12px;
  font-weight: 700;
  color: color-mix(in srgb, var(--accent) 80%, #fff);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.chat-tool-summary,
.chat-file-meta {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-tool-state,
.chat-file-state {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.chat-tool-card[data-status="done"] .chat-tool-state,
.chat-file-card[data-status="done"] .chat-file-state {
  color: var(--ok);
}

.chat-tool-card[data-status="running"] .chat-tool-state,
.chat-file-card[data-status="running"] .chat-file-state {
  color: #fbbf24;
}

.chat-tool-chevron {
  color: var(--text-muted);
  transition: transform 0.16s ease;
}

.chat-tool-card.is-open .chat-tool-chevron,
.chat-file-card.is-open .chat-tool-chevron {
  transform: rotate(90deg);
}

.chat-tool-body,
.chat-file-body {
  border-top: 1px solid var(--border);
}

.chat-tool-body .chat-code,
.chat-file-body .chat-code {
  max-height: 280px;
}

.chat-generated-image {
  margin: 12px 0 0;
}

.chat-generated-image img {
  display: block;
  width: min(100%, 320px);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.chat-empty {
  padding: 24px 16px;
  color: var(--text-muted);
  font-size: 13px;
}

.chat-thinking {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(139, 92, 246, 0.12);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--text-muted);
  font-size: 12px;
}

.chat-thinking-label {
  color: color-mix(in srgb, var(--accent) 80%, #fff);
  font-weight: 600;
}

.chat-thinking-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}

.chat-thinking-dots i {
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  animation: chat-thinking-bounce 1.2s ease-in-out infinite;
}

.chat-thinking-dots i:nth-child(2) { animation-delay: 0.15s; }
.chat-thinking-dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-thinking-bounce {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.chat-md-h3 + .chat-md-list,
.chat-turn-body h3 + ul {
  margin-top: 8px;
}
