/* 对话助手容器 */
.chat-assistant-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 140px);
  background: white;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

/* 头部 */
.chat-assistant-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px;
  border-bottom: 1px solid #e5e7eb;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.chat-assistant-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  color: white;
}

.chat-assistant-subtitle {
  font-size: 14px;
  margin: 4px 0 0 0;
  opacity: 0.9;
}

.chat-assistant-controls {
  display: flex;
  align-items: center;
}

/* 消息区域 */
.chat-assistant-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: #f9fafb;
}

/* 空状态 */
.chat-assistant-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: #6b7280;
}

.chat-assistant-empty svg {
  margin-bottom: 16px;
}

.chat-assistant-empty h3 {
  font-size: 18px;
  font-weight: 600;
  color: #111827;
  margin: 0 0 8px 0;
}

.chat-assistant-empty p {
  font-size: 14px;
  margin: 0 0 16px 0;
}

.chat-assistant-empty ul {
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: left;
}

.chat-assistant-empty li {
  padding: 8px 16px;
  margin: 4px 0;
  background: white;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  font-size: 13px;
  color: #4b5563;
}

/* 消息 */
.chat-message {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-message.user {
  flex-direction: row-reverse;
}

.chat-message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-message.user .chat-message-avatar {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.chat-message.assistant .chat-message-avatar {
  background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
  color: white;
}

.chat-message-content {
  flex: 1;
  max-width: 80%;
}

.chat-message.user .chat-message-content {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.chat-message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
}

.chat-message.user .chat-message-header {
  flex-direction: row-reverse;
}

.chat-message-role {
  font-weight: 600;
  color: #111827;
}

.chat-message-time {
  color: #9ca3af;
  font-size: 12px;
}

.chat-message-text {
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.6;
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.chat-message.user .chat-message-text {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-message.assistant .chat-message-text {
  background: white;
  color: #111827;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}

.chat-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: currentColor;
  margin-left: 2px;
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* 工具调用 */
.chat-tool-calls {
  margin-bottom: 12px;
}

.chat-tool-call {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
}

.chat-tool-call.calling {
  border-color: #3b82f6;
  background: #eff6ff;
}

.chat-tool-call.success {
  border-color: #10b981;
  background: #f0fdf4;
}

.chat-tool-call.error {
  border-color: #ef4444;
  background: #fef2f2;
}

.chat-tool-call-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 13px;
}

.chat-tool-call-icon {
  font-size: 16px;
}

.chat-tool-call-title {
  color: #111827;
}

.chat-tool-call-body {
  font-size: 13px;
}

.chat-tool-call-explanation {
  color: #6b7280;
  margin-bottom: 8px;
}

.chat-tool-call-sql {
  background: #1f2937;
  color: #10b981;
  padding: 12px;
  border-radius: 6px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  overflow-x: auto;
  margin: 8px 0;
}

.chat-tool-call-result {
  color: #059669;
  font-weight: 500;
  padding: 8px 12px;
  background: #d1fae5;
  border-radius: 6px;
  margin-top: 8px;
}

.chat-tool-call-error {
  color: #dc2626;
  font-weight: 500;
  padding: 8px 12px;
  background: #fee2e2;
  border-radius: 6px;
  margin-top: 8px;
}

/* 图表显示 */
.chat-charts {
  margin-bottom: 12px;
}

.chat-chart {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
}

.chat-chart.generating {
  border-color: #8b5cf6;
  background: #f5f3ff;
}

.chat-chart.success {
  border-color: #10b981;
  background: #f0fdf4;
}

.chat-chart.error {
  border-color: #ef4444;
  background: #fef2f2;
}

.chat-chart-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-weight: 600;
  font-size: 14px;
}

.chat-chart-icon {
  font-size: 20px;
}

.chat-chart-title {
  color: #111827;
}

.chat-chart-explanation {
  color: #6b7280;
  font-size: 13px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: #f9fafb;
  border-radius: 6px;
}

.chat-chart-container {
  background: white;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chat-chart-error {
  color: #dc2626;
  font-weight: 500;
  padding: 12px;
  background: #fee2e2;
  border-radius: 6px;
  text-align: center;
}

/* 输入区域 */
.chat-assistant-input {
  padding: 20px 24px;
  border-top: 1px solid #e5e7eb;
  background: white;
}

.chat-input-wrapper {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  transition: border-color 0.2s;
}

.chat-input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-input:disabled {
  background: #f9fafb;
  cursor: not-allowed;
}

.chat-send-button {
  height: 48px;
  padding: 0 24px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-send-button:hover:not(:disabled) {
  background: linear-gradient(135deg, #5568d3 0%, #6a3f8f 100%);
}

.chat-input-hint {
  margin-top: 8px;
  font-size: 12px;
  color: #9ca3af;
  text-align: right;
}

/* 滚动条样式 */
.chat-assistant-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-assistant-messages::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.chat-assistant-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

.chat-assistant-messages::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* ===== Markdown 渲染样式 ===== */

/* 段落 */
.chat-message-text p {
  margin: 0 0 8px 0;
  line-height: 1.7;
}
.chat-message-text p:last-child {
  margin-bottom: 0;
}

/* 标题 */
.chat-message-text h1,
.chat-message-text h2,
.chat-message-text h3,
.chat-message-text h4 {
  margin: 12px 0 6px 0;
  font-weight: 600;
  line-height: 1.4;
}
.chat-message-text h1 { font-size: 18px; }
.chat-message-text h2 { font-size: 16px; }
.chat-message-text h3 { font-size: 14px; }

/* 列表 */
.chat-message-text ul,
.chat-message-text ol {
  margin: 6px 0;
  padding-left: 20px;
}
.chat-message-text li {
  margin: 3px 0;
  line-height: 1.6;
}

/* 行内代码 */
.md-inline-code {
  background: rgba(99, 102, 241, 0.1);
  color: #6366f1;
  padding: 1px 6px;
  border-radius: 4px;
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 0.88em;
}

/* 代码块 */
.md-code-block {
  background: #1e1e2e;
  color: #cdd6f4;
  border-radius: 8px;
  padding: 12px 16px;
  margin: 8px 0;
  overflow-x: auto;
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
}
.md-code-block code {
  background: none;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

/* 表格 */
.md-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}
.md-table th,
.md-table td {
  border: 1px solid #e5e7eb;
  padding: 6px 12px;
  text-align: left;
}
.md-table th {
  background: #f3f4f6;
  font-weight: 600;
  color: #374151;
}
.md-table tr:nth-child(even) td {
  background: #f9fafb;
}

/* 引用块 */
.chat-message-text blockquote {
  border-left: 3px solid #6366f1;
  margin: 8px 0;
  padding: 4px 12px;
  color: #6b7280;
  background: #f5f3ff;
  border-radius: 0 6px 6px 0;
}

/* 分割线 */
.chat-message-text hr {
  border: none;
  border-top: 1px solid #e5e7eb;
  margin: 12px 0;
}

/* 加粗 / 斜体 */
.chat-message-text strong { font-weight: 600; color: #111827; }
.chat-message-text em { font-style: italic; color: #4b5563; }

/* 链接 */
.chat-message-text a {
  color: #6366f1;
  text-decoration: none;
}
.chat-message-text a:hover {
  text-decoration: underline;
}
