/**
 * AI 对话可复用视觉（消息气泡 / 输入卡 / 发送钮）
 * 供顶栏助手与打印设计器侧栏共用。
 * 设计器根节点加 .ai-chat-embed 使用浅色工作区主题。
 */
.ai-chat-embed {
  --bg-primary: #f9fafb;
  --bg-secondary: #ffffff;
  --bg-input: #ffffff;
  --bg-hover: #f0f0f0;
  --bg-code: #f9fafb;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #6b7280;
  --text-dim: #9ca3af;
  --border-color: #e5e7eb;
  --border-active: #3b82f6;
  --accent-primary: #2563eb;
  --accent-success: #16a34a;
  --accent-warning: #d97706;
  --accent-error: #dc2626;
  --accent-purple: #7c3aed;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  box-sizing: border-box;
}
.ai-chat-embed *,
.ai-chat-embed *::before,
.ai-chat-embed *::after {
  box-sizing: border-box;
}

.ai-chat-embed .chat-window {
  flex: 1;
  overflow-y: auto;
  position: relative;
  scroll-behavior: smooth;
  min-height: 0;
  background: var(--bg-primary);
}
.ai-chat-embed .messages-container {
  padding: 0;
  max-width: none;
  margin: 0;
}
.ai-chat-embed .message-wrapper {
  padding: 8px 12px;
  max-width: none;
  margin: 0;
}
.ai-chat-embed .message-bubble {
  display: flex;
  gap: 10px;
  padding: 4px 0;
  border-bottom: 1px solid transparent;
}
.ai-chat-embed .message-wrapper + .message-wrapper .message-bubble {
  border-top: 1px solid var(--border-color);
}
.ai-chat-embed .message-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 600;
}
.ai-chat-embed .message-avatar.user {
  background: #e5e7eb;
  color: var(--text-primary);
}
.ai-chat-embed .message-avatar.assistant {
  background: linear-gradient(135deg, var(--accent-primary), #7c3aed);
  color: #fff;
}
.ai-chat-embed .message-content {
  flex: 1;
  min-width: 0;
}
.ai-chat-embed .message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.ai-chat-embed .message-role {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}
.ai-chat-embed .message-time {
  font-size: 11px;
  color: var(--text-muted);
}
.ai-chat-embed .message-body {
  position: relative;
}
.ai-chat-embed .message-text {
  color: var(--text-primary);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
}
.ai-chat-embed .message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.ai-chat-embed .message-attachments img {
  max-width: 120px;
  max-height: 80px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  object-fit: cover;
}

.ai-chat-embed .loading-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px 8px;
  color: var(--text-muted);
  font-size: 13px;
  user-select: none;
}
.ai-chat-embed .dot {
  width: 6px;
  height: 6px;
  background: var(--accent-primary);
  border-radius: 50%;
  animation: aiChatBounce 1.4s infinite ease-in-out both;
  display: inline-block;
}
.ai-chat-embed .dot:nth-child(2) { animation-delay: -0.32s; }
.ai-chat-embed .dot:nth-child(3) { animation-delay: -0.16s; }
@keyframes aiChatBounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

.ai-chat-embed .chat-input-area {
  padding: 8px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-primary);
  flex-shrink: 0;
}
.ai-chat-embed .input-container {
  max-width: none;
  margin: 0;
  position: relative;
}
.ai-chat-embed .input-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: visible;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}
.ai-chat-embed .input-card:focus-within {
  border-color: var(--border-active);
  box-shadow: 0 0 0 1px var(--border-active);
}
.ai-chat-embed .input-textarea-wrap {
  padding: 4px 12px 0;
}
.ai-chat-embed .chat-textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  line-height: 1.55;
  resize: none;
  padding: 2px 0;
  max-height: 140px;
  min-height: 32px;
}
.ai-chat-embed .chat-textarea::placeholder {
  color: var(--text-muted);
}
.ai-chat-embed .input-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 8px 8px;
  gap: 6px;
}
.ai-chat-embed .input-bottom-left {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  min-width: 0;
}
.ai-chat-embed .input-tool-btn {
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  line-height: 1.2;
}
.ai-chat-embed .input-tool-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.ai-chat-embed .input-tool-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.ai-chat-embed .send-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-primary);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}
.ai-chat-embed .send-btn:hover:not(.disabled) {
  filter: brightness(0.95);
  transform: translateY(-1px);
}
.ai-chat-embed .send-btn.disabled {
  background: var(--bg-hover);
  color: var(--text-muted);
  cursor: not-allowed;
  transform: none;
}
.ai-chat-embed .send-btn.is-stop {
  background: var(--accent-error);
  color: #fff;
  cursor: pointer;
}
.ai-chat-embed .send-btn.is-stop:hover {
  filter: brightness(0.95);
  transform: translateY(-1px);
}
.ai-chat-embed .send-btn.is-stop.disabled {
  background: var(--accent-error);
  color: #fff;
  cursor: pointer;
  opacity: 0.95;
}
.ai-chat-embed .attach-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 6px;
}
.ai-chat-embed .attach-preview-item {
  position: relative;
  width: 56px;
  height: 56px;
}
.ai-chat-embed .attach-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}
.ai-chat-embed .attach-preview-item button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: #dc2626;
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}

.ai-chat-embed .code-block-wrap {
  position: relative;
  margin: 8px 0;
}
.ai-chat-embed pre {
  background: var(--bg-code) !important;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 12px;
}
.ai-chat-embed code {
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
  font-size: 12px;
}

.ai-chat-embed .print-ai-apply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid var(--border-color);
  background: #eff6ff;
  flex-shrink: 0;
}
.ai-chat-embed .print-ai-apply-bar[hidden] {
  display: none !important;
}
.ai-chat-embed .print-ai-apply-btn {
  border: none;
  background: var(--accent-primary);
  color: #fff;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.ai-chat-embed .print-ai-apply-btn:hover {
  filter: brightness(0.95);
}
.ai-chat-embed .print-ai-apply-hint {
  font-size: 12px;
  color: var(--text-secondary);
  flex: 1;
  min-width: 0;
}

/* 工具调用：对齐参考对话窗的折叠行 */
.ai-chat-embed .tool-call-group {
  margin: 10px 0;
  border-left: 2px solid var(--accent-purple, #cba6f7);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: rgba(203, 166, 247, 0.04);
  overflow: hidden;
}
.ai-chat-embed .reasoning-block {
  margin: 0;
  border: none;
  background: transparent;
  color: var(--text-secondary);
}
.ai-chat-embed .reasoning-block summary {
  list-style: none;
}
.ai-chat-embed .reasoning-block summary::-webkit-details-marker {
  display: none;
}
.ai-chat-embed .reasoning-block[open] > summary .tool-call-chevron {
  transform: rotate(90deg);
}
.ai-chat-embed .reasoning-body {
  display: none;
  padding: 0 12px 10px 28px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow: auto;
  line-height: 1.5;
  font-size: 12px;
  color: var(--text-secondary);
}
.ai-chat-embed .reasoning-block[open] .reasoning-body {
  display: block;
}
.ai-chat-embed .tool-call-item {
  border-bottom: 1px solid rgba(203, 166, 247, 0.1);
}
.ai-chat-embed .tool-call-item:last-child {
  border-bottom: none;
}
.ai-chat-embed .tool-call-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 12px;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}
.ai-chat-embed .tool-call-header:hover {
  background: rgba(203, 166, 247, 0.08);
}
.ai-chat-embed .tool-call-chevron {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}
.ai-chat-embed .tool-call-chevron.expanded {
  transform: rotate(90deg);
}
.ai-chat-embed .tool-call-icon {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 12px;
}
.ai-chat-embed .tool-call-icon.calling {
  background: rgba(137, 180, 250, 0.15);
  color: var(--accent-primary);
}
.ai-chat-embed .tool-call-icon.done {
  display: none;
}
.ai-chat-embed .tool-call-icon.stopped {
  background: rgba(250, 179, 135, 0.15);
  color: var(--accent-warning, #f0a050);
}
.ai-chat-embed .tool-call-icon.error {
  background: rgba(243, 139, 168, 0.15);
  color: var(--accent-error);
}
.ai-chat-embed .tool-call-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-chat-embed .tool-call-status {
  font-size: 11px;
  margin-left: auto;
  padding: 2px 8px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}
.ai-chat-embed .tool-call-status.calling {
  background: rgba(137, 180, 250, 0.12);
  color: var(--accent-primary);
}
.ai-chat-embed .tool-call-status.done {
  display: none;
}
.ai-chat-embed .tool-call-status.stopped {
  background: rgba(250, 179, 135, 0.12);
  color: var(--accent-warning, #f0a050);
}
.ai-chat-embed .tool-call-status.error {
  background: rgba(243, 139, 168, 0.12);
  color: var(--accent-error);
}
.ai-chat-embed .tool-call-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.ai-chat-embed .tool-call-status.calling .tool-call-status-dot {
  animation: toolCallDotPulse 1.5s ease-in-out infinite;
}
@keyframes toolCallDotPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.ai-chat-embed .tool-call-body {
  padding: 0 12px 10px 40px;
  display: none;
}
.ai-chat-embed .tool-call-body.visible {
  display: block;
}
.ai-chat-embed .tool-call-section {
  margin-bottom: 8px;
}
.ai-chat-embed .tool-call-section:last-child {
  margin-bottom: 0;
}
.ai-chat-embed .tool-call-args,
.ai-chat-embed .tool-call-result {
  background: var(--bg-code);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 200px;
  overflow-y: auto;
}
.ai-chat-embed .tool-call-args {
  max-height: 120px;
}
.ai-chat-embed .tool-call-result.success {
  border-color: rgba(166, 227, 161, 0.3);
}
.ai-chat-embed .tool-call-result.error {
  border-color: rgba(243, 139, 168, 0.3);
}
.ai-chat-embed .tool-call-args-label,
.ai-chat-embed .tool-call-result-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.ai-chat-embed .tool-call-args-label svg,
.ai-chat-embed .tool-call-result-label svg {
  width: 12px;
  height: 12px;
}

