/* ===== 对话主窗口与滚动容器 ===== */
.chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 18px 16px 24px;
  scroll-behavior: smooth;
}

/* ===== 欢迎首页空状态卡片 ===== */
.empty {
  margin: 18px auto 0;
  max-width: 760px;
  padding: 18px;
  border-radius: var(--radius);
  border: 1px dashed var(--border);
  color: var(--text-muted);
  background: var(--card-bg-soft);
}

.empty .empty-inner {
  max-width: 980px;
  margin: 0 auto;
}

.empty .empty-title {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.2;
  margin: 0 0 14px 0;
}

.empty .empty-title-accent {
  font-weight: 900;
}

.empty .empty-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.empty .empty-card {
  text-align: left;
  border-radius: 14px;
  padding: 12px 12px 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(6px);
}

.empty .empty-card-h {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  margin-bottom: 8px;
}

.empty .empty-card-h span:last-child {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.2px;
}

.empty .empty-card:nth-child(3) .empty-card-h span:last-child {
  font-weight: 600;
  letter-spacing: 0.3px;
}

.empty .empty-ico {
  font-size: 18px;
  line-height: 1;
}

.empty .empty-card-b {
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.empty .empty-foot {
  margin-top: 12px;
  font-size: 12px;
  opacity: 0.75;
}

@media (max-width: 900px) {
  .empty .empty-grid {
    grid-template-columns: 1fr;
  }

  .empty .empty-title {
    font-size: 20px;
  }
}

/* ===== 消息基础样式 ===== */
.msg {
  display: flex;
  max-width: 100%;
  margin: 0 0 14px;
  gap: 0;
}

.avatar {
  display: none;
}

.bubble {
  flex: 1;
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
  padding: 12px 14px;
  background: var(--card-bg-soft);
  position: relative;
}

.meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 6px;
}

.role {
  display: none;
}

.time {
  display: none !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

.message-time,
.chat-time,
.timestamp {
  display: none !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* 用户与 AI 消息气泡对齐 */
.msg.user {
  justify-content: flex-end;
}

.msg.bot {
  justify-content: flex-start;
  max-width: none !important;
  width: 100% !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
}

.msg.user .bubble {
  background: var(--user-bg);
  border: 1px solid var(--border-soft);
  flex: 0 1 auto !important;
  width: fit-content !important;
  max-width: 70% !important;
  margin-left: auto;
  font-size: 16px;
  line-height: 1.6;
}

.msg.bot .bubble {
  background: var(--bot-bg);
  border: 1px solid var(--border-soft);
  flex: 1 1 auto !important;
  width: 100% !important;
  max-width: none !important;
}

.error .bubble {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
}

.user-message {
  display: inline-block;
  max-width: 70%;
  width: fit-content;
  margin-left: auto;
}

/* 用户发送图片显示尺寸 */
.user-image-preview {
  display: block;
  max-width: 220px;
  max-height: 220px;
  width: auto;
  height: auto;
  border-radius: 10px;
  margin-bottom: 8px;
  object-fit: contain;
}

.user-images-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.user-images-row .user-image-preview {
  max-width: 120px;
  max-height: 120px;
  margin-bottom: 0;
}

/* ===== Markdown：浅色背景适配 ===== */
.markdown-body {
  background: transparent !important;
  color: var(--text-main) !important;
  padding: 0 !important;
  margin: 0 !important;
  font-size: 16px;
  line-height: 1.65;
  text-indent: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.25rem;
  margin-left: 0;
}

.markdown-body pre {
  background: #f6f8fa !important;
  border: 1px solid var(--border) !important;
  border-radius: 10px !important;
  padding: 12px !important;
  overflow: auto !important;
}

.markdown-body code {
  background: #f3f4f6 !important;
  border-radius: 6px !important;
  padding: 0.15em 0.35em !important;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.markdown-body blockquote {
  border-left: 4px solid #d1d5db !important;
  background: #f9fafb !important;
  color: #4b5563 !important;
  border-radius: 8px !important;
  padding: 8px 12px !important;
}

.markdown-body a {
  color: #2563eb !important;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.markdown-body h1 {
  font-size: 22px !important;
}

.markdown-body h2 {
  font-size: 20px !important;
}

.markdown-body h3 {
  font-size: 18px !important;
}

/* ===== Markdown 表格横向滚动 ===== */
.markdown-body .table-scroll {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 8px 0;
}

.markdown-body .table-scroll table {
  width: max-content;
  min-width: 100%;
  table-layout: auto;
}

.markdown-body th,
.markdown-body td {
  white-space: nowrap;
  vertical-align: top;
}

.markdown-body img,
.markdown-body video {
  max-width: 100%;
  height: auto;
}

/* ===== Token 统计 ===== */
.token-usage {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

/* ===== 滚动提示与浮动火箭 ===== */
.scroll-tip {
  position: sticky;
  bottom: 12px;
  width: fit-content;
  max-width: 92%;
  margin: 0 auto 10px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.2;
  color: #ffffff;
  background: rgba(17, 24, 39, 0.86);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  z-index: 5;
  cursor: pointer;
  user-select: none;
  text-align: center;
}

.scroll-arrow-btn {
  position: fixed;
  right: 16px;
  bottom: 96px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .15);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.scroll-arrow-btn svg {
  width: 22px;
  height: 22px;
}

/* ===== AI 生成图片及弹窗 ===== */
.ai-generated-image {
  display: block;
  width: 80%;
  max-width: 520px;
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  user-select: none;
}

.ai-generated-tip {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.image-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  padding: 20px;
}

.image-modal.open {
  display: flex;
}

.image-modal-content {
  max-width: min(1100px, 96vw);
  max-height: 90vh;
  border-radius: 12px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}

.image-modal-toolbar {
  position: fixed;
  top: 18px;
  right: 20px;
  display: flex;
  gap: 10px;
  z-index: 100000;
}

.image-modal-btn {
  height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  background: rgba(17, 24, 39, 0.6);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
}

/* ===== 思考过程与动画 ===== */
.thinking {
  color: rgba(107, 114, 128, 1);
}

.thinking-dots {
  display: inline-block;
  width: 3ch;
  white-space: nowrap;
  vertical-align: middle;
  position: relative;
  top: 0.12em;
}

.thinking-dots::after {
  content: "...";
  display: inline-block;
  width: 0;
  overflow: hidden;
  white-space: nowrap;
  animation: thinking-dots 1.2s steps(4, end) infinite;
}

@keyframes thinking-dots {
  0% { width: 0; }
  100% { width: 3ch; }
}

.thinking-block {
  margin-bottom: 12px;
  border: 1px solid rgba(139, 92, 246, 0.18);
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.04) 0%, rgba(59, 130, 246, 0.04) 100%);
  overflow: hidden;
  transition: border-color 0.2s ease;
}

.thinking-block:hover {
  border-color: rgba(139, 92, 246, 0.30);
}

.thinking-block summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  font-weight: 600;
  color: #7c3aed;
  list-style: none;
  outline: none;
  transition: background 0.15s ease;
}

.thinking-block summary::-webkit-details-marker {
  display: none;
}

.thinking-block summary::before {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid #7c3aed;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.thinking-block[open] summary::before {
  transform: rotate(90deg);
}

.thinking-block summary:hover {
  background: rgba(139, 92, 246, 0.06);
}

.thinking-block .thinking-icon {
  font-size: 15px;
  line-height: 1;
}

.thinking-block .thinking-label {
  flex: 1;
}

.thinking-block .thinking-status {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: auto;
}

.thinking-block .thinking-content {
  padding: 0 14px 12px;
  font-size: 13px;
  line-height: 1.6;
  color: #6b7280;
  border-top: 1px solid rgba(139, 92, 246, 0.10);
  max-height: 400px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.thinking-block .thinking-content::-webkit-scrollbar {
  width: 4px;
}

.thinking-block .thinking-content::-webkit-scrollbar-thumb {
  background: rgba(139, 92, 246, 0.25);
  border-radius: 2px;
}

.thinking-block.is-thinking summary .thinking-label::after {
  content: '';
  display: inline-block;
  width: 3ch;
  overflow: hidden;
  white-space: nowrap;
  animation: thinking-dots 1.2s steps(4, end) infinite;
  vertical-align: bottom;
}

/* 响应式适配 */
@media (max-width: 768px) {
  .user-message {
    max-width: 92%;
  }
}

@media (max-width: 640px) {
  .chat-scroll {
    padding: 14px 10px 18px;
  }

  .msg {
    gap: 10px;
  }

  .bubble {
    padding: 8px 10px;
  }

  .msg.user .bubble,
  .msg.bot .bubble {
    max-width: 92% !important;
  }

  .msg.bot,
  .msg.bot .bubble {
    width: auto !important;
  }

  .msg.user .bubble {
    font-size: 15px;
    line-height: 1.65;
  }

  .user-image-preview {
    max-width: 160px;
    max-height: 160px;
  }

  .markdown-body p,
  .markdown-body ul,
  .markdown-body ol,
  .markdown-body blockquote {
    margin-left: 0;
    padding-left: 0;
  }

  .markdown-body ul,
  .markdown-body ol {
    padding-left: 1.0rem;
  }

  .markdown-body blockquote {
    padding-left: 0.8rem;
  }

  .markdown-body pre {
    padding: 10px !important;
    font-size: 13px !important;
  }

  .markdown-body code {
    font-size: 13px !important;
  }

  .markdown-body {
    font-size: 15px;
    line-height: 1.7;
  }

  .thinking-block .thinking-content {
    font-size: 12px;
    max-height: 300px;
  }
}
