/* 萌包子对话页 —— 布局/交互照搬 python3 AI 助手，配色品牌蓝（--primary #3b82f6） */

/* ===== 整体 ===== */
.chat-view {
  height: calc(100vh - 140px);  /* navbar 61 + footer 78 + 余量：页面不滚动，消息区内部滚动 */
  display: flex;
  flex-direction: column;
  background: var(--surface-2, #f1f5f9);
}

/* ===== 顶部栏 ===== */
.chat-topbar { flex-shrink: 0; background: var(--surface, #fff); border-bottom: 1px solid var(--border, #e2e8f0); }
.chat-topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; padding: 0 20px; }
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; border: 2px solid #fff; box-shadow: var(--shadow-sm, 0 2px 8px rgba(15, 23, 42, 0.08)); flex-shrink: 0; }
.topbar-title { font-size: 15px; font-weight: 700; color: var(--text, #1e293b); line-height: 1.3; }
.topbar-sub { font-size: 12px; color: var(--text-muted, #94a3b8); }
.topbar-right { display: flex; align-items: center; }
.chat-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 4px 12px; background: var(--primary-bg, #eff6ff); color: var(--primary-dark, #2563eb); border-radius: 999px; }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success, #10b981); animation: badge-pulse 2s infinite; }
@keyframes badge-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.35); } 50% { box-shadow: 0 0 0 4px rgba(16, 185, 129, 0); } }

/* ===== 主体 ===== */
.chat-body { display: flex; flex: 1; min-height: 0; position: relative; }

/* ===== 侧边栏（可折叠） ===== */
.sidebar-wrap { width: 260px; flex-shrink: 0; transition: width 0.25s; overflow: hidden; }
.sidebar-wrap.closed { width: 0; }
.sidebar { width: 260px; background: var(--surface, #fff); border-right: 1px solid var(--border, #e2e8f0); display: flex; flex-direction: column; height: 100%; }
.sidebar-toggle-btn {
  position: absolute; left: 258px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 56px; background: var(--surface-2, #f1f5f9);
  border: 1px solid var(--border-strong, #cbd5e1); border-left: none;
  border-radius: 0 6px 6px 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted, #94a3b8); z-index: 10; transition: left 0.25s; font-size: 15px;
}
.sidebar-toggle-btn:hover { color: var(--primary, #3b82f6); background: var(--border, #e2e8f0); }
.sidebar-wrap.closed + .sidebar-toggle-btn { left: 0; }
.sidebar-toggle-btn span { pointer-events: none; line-height: 1; }
.sidebar-header { padding: 14px 16px; border-bottom: 1px solid var(--border, #e2e8f0); display: flex; justify-content: space-between; align-items: center; }
.sidebar-title { font-size: 14px; font-weight: 700; color: var(--text, #1e293b); }
#new-chat-btn { font-size: 12px; background: var(--primary, #3b82f6); color: #fff; padding: 6px 12px; border: none; border-radius: 8px; cursor: pointer; display: flex; align-items: center; gap: 4px; transition: var(--transition-fast, all 0.15s ease); }
#new-chat-btn:hover { background: var(--primary-dark, #2563eb); }
.sidebar-list { flex: 1; overflow-y: auto; padding: 8px; }
.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-thumb { background: var(--border-strong, #cbd5e1); border-radius: 4px; }
.conv-loading { text-align: center; color: var(--text-muted, #94a3b8); font-size: 12px; padding: 28px 0; }
.conv-item { padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--text-secondary, #475569); margin-bottom: 2px; display: flex; justify-content: space-between; align-items: center; transition: background 0.15s; }
.conv-item:hover { background: var(--surface-2, #f1f5f9); }
.conv-item.active { background: var(--primary-light, #dbeafe); color: var(--primary-dark, #2563eb); font-weight: 500; }
.conv-item .conv-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.conv-item .conv-del { opacity: 0; width: 22px; height: 22px; border-radius: 4px; border: none; background: transparent; color: var(--text-muted, #94a3b8); cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 14px; }
.conv-item:hover .conv-del { opacity: 1; }
.conv-item .conv-del:hover { background: var(--danger, #ef4444); color: #fff; }

/* ===== 聊天区 ===== */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-messages { flex: 1; overflow-y: auto; scroll-behavior: smooth; padding: 20px; }
.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-strong, #cbd5e1); border-radius: 10px; }
.chat-box { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }

/* ===== 欢迎屏 ===== */
.welcome-head { text-align: center; margin: 24px 0 18px; }
.welcome-avatar { width: 64px; height: 64px; border-radius: 18px; object-fit: cover; margin: 0 auto 14px; box-shadow: var(--shadow-blue, 0 4px 20px rgba(59, 130, 246, 0.22)); border: 3px solid #fff; }
.welcome-head h2 { font-size: 20px; font-weight: 700; color: var(--text, #1e293b); margin: 0 0 4px; }
.welcome-head p { font-size: 13px; color: var(--text-muted, #94a3b8); margin: 0; }

/* 弹幕（快捷问题滚动） */
.danmaku-wrapper { overflow: hidden; height: 176px; position: relative; width: 100%; }
.danmaku-lane { position: absolute; display: flex; height: 36px; align-items: center; left: 0; }
.danmaku-lane:nth-child(1) { top: 4px; }
.danmaku-lane:nth-child(2) { top: 48px; }
.danmaku-lane:nth-child(3) { top: 92px; }
.danmaku-lane:nth-child(4) { top: 136px; }
.danmaku-chip { display: inline-flex; align-items: center; padding: 4px 14px; margin: 0 6px; border-radius: 16px; background: #fff; border: 1px solid var(--border, #e2e8f0); font-size: 12.5px; color: var(--text-secondary, #475569); cursor: pointer; white-space: nowrap; flex-shrink: 0; transition: var(--transition-fast, all 0.15s ease); }
.danmaku-chip:hover { background: var(--primary-bg, #eff6ff); border-color: var(--primary, #3b82f6); color: var(--primary-dark, #2563eb); }

/* ===== 消息 ===== */
.msg-anim { animation: fadeUp 0.3s ease-out; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.msg-row { display: flex; }
.msg-row.user { justify-content: flex-end; }
.msg-ai-wrap { display: flex; gap: 10px; max-width: 92%; min-width: 0; }
.msg-user-wrap { display: flex; flex-direction: column; align-items: flex-end; max-width: 92%; }
.msg-user-inner { display: flex; align-items: flex-start; gap: 8px; min-width: 0; }
.msg-avatar-bot { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; margin-top: 2px; border: 1.5px solid #fff; box-shadow: var(--shadow-xs, 0 1px 2px rgba(15, 23, 42, 0.06)); }
.msg-avatar-user { width: 32px; height: 32px; border-radius: 50%; background: var(--primary, #3b82f6); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; flex-shrink: 0; margin-top: 2px; }
.msg-bubble-ai { background: var(--surface, #fff); border-radius: 14px 14px 14px 4px; padding: 12px 16px; box-shadow: var(--shadow-xs, 0 1px 2px rgba(15, 23, 42, 0.04)); border: 1px solid var(--border, #e2e8f0); min-width: 0; }
.msg-bubble-user { background: var(--primary-gradient, linear-gradient(135deg, #3b82f6, #6366f1)); color: #fff; border-radius: 14px 14px 4px 14px; padding: 10px 16px; box-shadow: var(--shadow-blue, 0 4px 20px rgba(59, 130, 246, 0.18)); }
.msg-content { font-size: 14px; line-height: 1.7; color: var(--text, #1e293b); overflow-wrap: anywhere; word-break: break-word; }
.msg-bubble-ai .msg-content { overflow-x: auto; }  /* 超宽 md 元素（宽表格/长代码）在内容区横向滚动，不突出气泡（python3 同款） */
.msg-bubble-user .msg-content { color: #fff; white-space: pre-wrap; }
.msg-sources { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.src-tag { font-size: 12px; padding: 2px 9px; background: var(--primary-bg, #eff6ff); color: var(--primary-dark, #2563eb); border-radius: 999px; }
.msg-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: var(--text-muted, #94a3b8);
  margin-top: 4px;
  opacity: 0;
  transition: opacity 0.2s ease;
}
/* 用户消息 meta 对齐气泡右下角（右边缘贴气泡右边缘，与 AI 左下角对称）；右移补偿头像宽度 32+8 */
.msg-user-wrap .msg-meta { margin-right: 40px; }
.msg-row:hover .msg-meta { opacity: 1; }
.msg-copy { cursor: pointer; }
.msg-copy:hover { color: var(--primary, #3b82f6); }

/* typing 三点 */
@keyframes dotPulse { 0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }
.typing-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--primary, #3b82f6); animation: dotPulse 1.4s infinite ease-in-out both; }
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0s; }

/* ===== 代码块 ===== */
.code-block { background: #1a1a2e; border-radius: 10px; margin: 10px 0; overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.06); }
.code-header { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; background: rgba(255, 255, 255, 0.04); border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.code-lang { font-size: 11px; color: #8b8ba7; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.copy-btn { font-size: 11px; color: #8b8ba7; cursor: pointer; background: none; border: none; display: flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 4px; transition: all 0.2s; }
.copy-btn:hover { background: rgba(255, 255, 255, 0.08); color: #e0e0e0; }
.code-block pre { padding: 14px 16px; margin: 0; overflow-x: auto; font-size: 13px; line-height: 1.6; color: #e2e8f0; white-space: pre !important; }
.code-block code { font-family: 'Fira Code', 'Consolas', monospace; color: #e2e8f0; white-space: pre !important; }

/* ===== Markdown 渲染 ===== */
.msg-bubble-ai h1, .msg-bubble-ai h2, .msg-bubble-ai h3, .msg-bubble-ai h4, .msg-bubble-ai h5 { font-weight: 700; color: var(--text, #1e293b); margin: 10px 0 4px; }
.msg-bubble-ai h1 { font-size: 17px; }
.msg-bubble-ai h2 { font-size: 16px; }
.msg-bubble-ai h3 { font-size: 15px; }
.msg-bubble-ai h4 { font-size: 14.5px; }
.msg-bubble-ai h5 { font-size: 14px; }
.msg-bubble-ai p { margin: 4px 0; }
.msg-bubble-ai ul, .msg-bubble-ai ol { margin: 4px 0 4px 20px; padding: 0; }
.msg-bubble-ai li { margin: 2px 0; }
.msg-bubble-ai blockquote { border-left: 4px solid var(--primary, #3b82f6); padding: 6px 12px; margin: 8px 0; color: var(--text-secondary, #475569); background: var(--primary-bg, #eff6ff); border-radius: 0 8px 8px 0; }
.msg-bubble-ai table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
.msg-bubble-ai th, .msg-bubble-ai td { border: 1px solid var(--border, #e2e8f0); padding: 6px 10px; text-align: left; }
.msg-bubble-ai th { background: var(--surface-2, #f1f5f9); font-weight: 600; }
.msg-bubble-ai a { color: var(--primary-dark, #2563eb); text-decoration: underline; word-break: break-all; }
.msg-bubble-ai code:not(.hljs) { background: var(--surface-2, #f1f5f9); padding: 1px 5px; border-radius: 4px; font-family: var(--font-mono); font-size: 12.5px; border: 1px solid var(--border, #e2e8f0); color: var(--primary-dark, #2563eb); }
.msg-bubble-ai strong { font-weight: 600; }

/* ===== 输入区 ===== */
.chat-input-wrap { flex-shrink: 0; background: var(--surface, #fff); border-top: 1px solid var(--border, #e2e8f0); padding: 12px 20px; }
.chat-input-inner { max-width: 860px; margin: 0 auto; display: flex; align-items: flex-end; gap: 10px; }
#chat-input { flex: 1; padding: 12px 16px; border: none; border-radius: 12px; background: var(--surface-2, #f1f5f9); outline: none; resize: none; font-size: 14px; line-height: 22px; min-height: 48px; max-height: 120px; color: var(--text, #1e293b); font-family: inherit; transition: var(--transition, all 0.25s cubic-bezier(0.4, 0, 0.2, 1)); }
#chat-input::placeholder { color: var(--text-muted, #94a3b8); }
#chat-input:focus { background: #fff; box-shadow: 0 0 0 3px var(--primary-glow, rgba(59, 130, 246, 0.15)); }
#send-btn { height: 48px; padding: 0 20px; border-radius: 12px; background: var(--primary-gradient, linear-gradient(135deg, #3b82f6, #6366f1)); color: #fff; border: none; cursor: pointer; font-size: 14px; font-weight: 500; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: var(--transition, all 0.25s cubic-bezier(0.4, 0, 0.2, 1)); }
#send-btn:hover { box-shadow: var(--shadow-blue, 0 4px 20px rgba(59, 130, 246, 0.18)); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

/* ===== 未登录提示（仿输入框的登录引导条） ===== */
.login-hint { flex: 1; padding: 0; cursor: pointer; }
.login-box {
  max-width: 860px; margin: 0 auto; min-height: 48px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 0 16px; border-radius: 12px;
  background: var(--surface-2, #f1f5f9);
  transition: var(--transition, all 0.25s cubic-bezier(0.4, 0, 0.2, 1));
}
.login-box:hover { background: #fff; box-shadow: 0 0 0 3px var(--primary-glow, rgba(59, 130, 246, 0.15)); }
.login-box-text { font-size: 14px; color: var(--text-muted, #94a3b8); flex: 1; display: flex; align-items: center; }
.login-box-btn {
  height: 36px; padding: 0 18px; border-radius: 10px;
  background: var(--primary-gradient, linear-gradient(135deg, #3b82f6, #6366f1));
  color: #fff; font-size: 14px; font-weight: 500;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: var(--transition, all 0.25s cubic-bezier(0.4, 0, 0.2, 1));
}
.login-box:hover .login-box-btn { box-shadow: var(--shadow-blue, 0 4px 20px rgba(59, 130, 246, 0.18)); }

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .chat-topbar-inner { padding: 0 12px; }
  .sidebar-wrap { width: 220px; }
  .sidebar { width: 220px; }
  .sidebar-toggle-btn { left: 218px; }
  .chat-messages { padding: 14px; }
  .msg-ai-wrap, .msg-user-wrap { max-width: 96%; }
}
