/* ════════════════════════════════════════════════════════════════
   AI 对话页样式 (v1.511) — 深色主题，独立于画板 chat.css
   ════════════════════════════════════════════════════════════════ */
/* 让 AI 对话页占满整个内容区，不受 .page 默认 24px padding 影响 */
#page-chat.active {
  display: flex;
  padding: 0;
}

.chat-page {
  flex: 1;
  display: flex;
  min-width: 0;
  background: #0f1117;
  color: #e4e4e7;
  overflow: hidden;
}

/* ─── 左侧会话栏 ─── */
.chat-sidebar {
  width: 280px;
  min-width: 280px;
  flex-shrink: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #15171f;
  border-right: 1px solid #262a36;
  padding: 12px 10px;
  box-sizing: border-box;
  gap: 10px;
}
.chat-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-sidebar-title { font-size: 15px; font-weight: 600; color: #f4f4f5; }
.chat-new-btn {
  background: #8b5cf6; color: #fff; border: none; border-radius: 8px;
  width: 100%; padding: 9px 12px; font-size: 13px; cursor: pointer; font-weight: 600;
}
.chat-new-btn:hover { background: #7c3aed; }
.chat-batch-enter {
  background: transparent; color: #a1a1aa; border: 1px solid #2a2e3a;
  border-radius: 8px; padding: 5px 10px; font-size: 12px; cursor: pointer;
}
.chat-batch-enter:hover { color: #e4e4e7; border-color: #3a3f4d; }
.chat-batch-bar {
  display: flex; align-items: center; gap: 8px; font-size: 12px; color: #a1a1aa;
  background: #1c1f29; border: 1px solid #2a2e3a; border-radius: 8px; padding: 6px 8px;
}
.chat-batch-all { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.chat-batch-del {
  background: #ef4444; color: #fff; border: none; border-radius: 6px;
  padding: 4px 8px; font-size: 12px; cursor: pointer; margin-left: auto;
}
.chat-batch-cancel { background: transparent; color: #a1a1aa; border: 1px solid #2a2e3a; border-radius: 6px; padding: 4px 8px; font-size: 12px; cursor: pointer; }
.chat-conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin-top: 2px; }
.chat-conv-item {
  position: relative; padding: 10px 10px; border-radius: 8px; cursor: pointer;
  background: transparent; border: 1px solid transparent; transition: background .15s;
}
.chat-conv-item:hover { background: #1c1f29; }
.chat-conv-item.active { background: #211d33; border-color: #3a2f5c; }
.chat-conv-title { font-size: 13px; color: #e4e4e7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 18px; }
.chat-conv-time { font-size: 11px; color: #6b7280; margin-top: 3px; }
.chat-conv-item input[type=checkbox] { position: absolute; top: 12px; left: 10px; }
.chat-conv-item.batch .chat-conv-title { padding-left: 22px; }
/* 🔧 v1.931: 批量模式选中态（点行/复选框/全选都同步） */
.chat-conv-item.batch.selected { background: #211d33; border-color: #6d28d9; }
.chat-conv-item.batch.selected .chat-conv-title { color: #c4b5fd; }
.chat-conv-item.batch.selected input[type=checkbox] { accent-color: #8b5cf6; }
.chat-conv-del {
  position: absolute; top: 8px; right: 8px; width: 18px; height: 18px; line-height: 16px;
  text-align: center; border-radius: 5px; color: #6b7280; cursor: pointer; font-size: 13px;
  opacity: .55; background: #15171f; transition: opacity .15s, color .15s, background .15s;
}
.chat-conv-item:hover .chat-conv-del { opacity: 1; }
.chat-conv-del:hover { color: #ef4444; background: #2a0f0f; }
.chat-conv-rename {
  position: absolute; top: 8px; right: 28px; font-size: 11px; color: #6b7280; cursor: pointer;
  opacity: 0;
}
.chat-conv-item:hover .chat-conv-rename { opacity: 1; }

/* ─── 右侧主区 ─── */
.chat-main { flex: 1; display: flex; flex-direction: column; height: 100%; min-width: 0; overflow-y: auto; }
.chat-topbar {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 16px;
  border-bottom: 1px solid #262a36; background: #12141c; flex-shrink: 0;
}
.chat-current-title { font-size: 14px; font-weight: 500; color: #e4e4e7; }
.chat-credits { font-size: 12px; color: #8b5cf6; font-weight: 600; }

.chat-controls-row {
  display: flex; align-items: center; gap: 10px;
  margin-top: 10px; padding-top: 10px; border-top: 1px solid #262a36;
}
.chat-model-sel {
  background: #1c1f29; color: #e4e4e7; border: 1px solid #2a2e3a; border-radius: 8px;
  padding: 7px 10px; font-size: 13px; min-width: 180px; max-width: 260px; cursor: pointer;
}
/* 🔧 v1.939: 模型下拉改用 enhanceModelSelect（自定义下拉）后，约束其在控制栏内的宽度与高度，
   避免 .mp-btn width:100% 在 flex 行里被拉伸撑破 .chat-controls-row 布局 */
.chat-controls-row .mp-wrap { min-width: 180px; max-width: 260px; }
.chat-controls-row .mp-btn { height: 34px; padding: 0 10px; font-size: 13px; }
.chat-controls-row .mp-ico { width: 18px; height: 18px; }
.chat-ws { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #a1a1aa; cursor: pointer; user-select: none; }
.chat-ws input { cursor: pointer; }
.chat-ws-hint { font-size: 11px; color: #6b7280; white-space: nowrap; }
.chat-ws input:disabled { cursor: not-allowed; }

.chat-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 16px; }
.chat-empty { margin: auto; text-align: center; color: #6b7280; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.chat-empty-icon { font-size: 40px; color: #8b5cf6; }
.chat-empty-text { font-size: 16px; color: #a1a1aa; }
.chat-empty-hint { font-size: 12px; max-width: 320px; }

.chat-msg { display: flex; flex-direction: column; gap: 6px; max-width: 880px; width: 100%; margin: 0 auto; }
.chat-msg.assistant { align-items: flex-start; }
.chat-msg.user { align-items: flex-end; }
/* 🔧 v1.551: 头像 + 模型名放在气泡上方（chat-avatar 后方） */
.chat-msg-header { display: flex; align-items: center; gap: 8px; }
.chat-msg.user .chat-msg-header { flex-direction: row-reverse; }
.chat-avatar { width: 32px; height: 32px; min-width: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; }
.chat-msg.user .chat-avatar { background: #8b5cf6; color: #fff; }
.chat-msg.assistant .chat-avatar { background: #1c1f29; color: #c4b5fd; border: 1px solid #2a2e3a; }
.chat-msg-name { font-size: 12px; color: #a78bfa; font-weight: 600; white-space: nowrap; }
.chat-msg-content { display: flex; flex-direction: column; max-width: calc(100% - 42px); }
.chat-msg.assistant .chat-msg-content { align-items: flex-start; }
.chat-msg.user .chat-msg-content { align-items: flex-end; }
.chat-bubble {
  position: relative;
  background: #1c1f29; border: 1px solid #262a36; border-radius: 12px; padding: 12px 14px;
  font-size: 14px; line-height: 1.6; color: #e4e4e7; white-space: pre-wrap; word-break: break-word;
}
/* 🔧 v1.547: 带复制按钮的气泡，右侧/顶部预留空间避免文字压住按钮 */
.chat-bubble.has-copy { padding-right: 56px; padding-top: 8px; }
.chat-msg.user .chat-bubble { background: #2a2350; border-color: #3a2f5c; }
.chat-bubble img { max-width: 320px; max-height: 320px; border-radius: 8px; margin-top: 8px; display: block; cursor: pointer; }
.chat-bubble.streaming::after { content: '▋'; color: #8b5cf6; animation: chatBlink 1s steps(2) infinite; }
@keyframes chatBlink { 0%,50% { opacity: 1; } 50.01%,100% { opacity: 0; } }
.chat-msg-images { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chat-msg-images img { width: 160px; height: 160px; object-fit: cover; border-radius: 8px; cursor: pointer; border: 1px solid #2a2e3a; }
/* 🔧 v1.545: 消息元信息放到 bubble 外部下方；AI 依次为模型名、时间、删除；用户右对齐时间和删除；时间 hover 显示 */
.chat-msg-footer { display: flex; align-items: center; gap: 8px; font-size: 11px; color: #6b7280; margin-top: 4px; padding: 0 4px; opacity: 0.7; transition: opacity .2s; }
.chat-msg:hover .chat-msg-footer { opacity: 1; }
.chat-msg.user .chat-msg-footer { justify-content: flex-end; }
.chat-msg-model { color: #a78bfa; font-weight: 500; }
.chat-msg-time { opacity: 0; transition: opacity .2s; }
.chat-msg:hover .chat-msg-time { opacity: 1; }
/* 🔧 v1.546: 删除按钮默认隐藏，hover 消息时显示；v1.547 改为带框胶囊 */
.chat-msg-del { cursor: pointer; font-size: 12px; color: #9aa0ad; padding: 2px 8px; border-radius: 6px; line-height: 1.4; border: 1px solid #2a2e3a; background: #1c1f29; opacity: 0; transition: opacity .2s, color .15s, background .15s, border-color .15s; }
.chat-msg:hover .chat-msg-del { opacity: 1; }
.chat-msg-del:hover { color: #ef4444; background: #2a0f0f; border-color: #ef4444; }
.chat-msg-body { white-space: pre-wrap; word-break: break-word; }

/* 🔧 新增右上角「复制」按钮（v1.547） */
.chat-copy-btn { position:absolute; top:8px; right:8px; border:none; padding:3px 9px; border-radius:6px; background:#2a2e3a; color:#9aa0ad; font-size:12px; line-height:1.4; cursor:pointer; opacity:.8; transition:background .15s,color .15s,opacity .15s; }
.chat-copy-btn:hover { background:#3a4258; color:#e4e4e7; opacity:1; }
.chat-copy-btn:focus-visible { outline:2px solid #8b5cf6; outline-offset:-2px; }

/* 🔧 v1.533: 画板 agent 过程文本（深度思考/分析/优化/进度），浅色主题友好 */
.chat-step-text { font-size: 12px; line-height: 1.6; color: #8a8f99; margin: 3px 0; padding-left: 8px; border-left: 2px solid #d8dce6; white-space: pre-wrap; word-break: break-word; }
.chat-step-progress { color: #6b7280; font-style: italic; border-left-color: #e0c36b; }
/* 🔧 v1.546: 自定义确认弹窗 */
.chat-confirm-overlay { position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,.65); display: none; align-items: center; justify-content: center; }
.chat-confirm-box { background: #1c1f29; border: 1px solid #2a2e3a; border-radius: 12px; padding: 22px 26px; min-width: 280px; max-width: 90vw; box-shadow: 0 12px 40px rgba(0,0,0,.4); text-align: center; }
.chat-confirm-box p { margin: 0 0 20px; font-size: 14px; color: #e4e4e7; line-height: 1.6; }
.chat-confirm-btns { display: flex; justify-content: center; gap: 12px; }
.chat-confirm-btns button { border: none; border-radius: 8px; padding: 8px 20px; font-size: 13px; font-weight: 500; cursor: pointer; transition: background .15s; }
.chat-confirm-cancel { background: #2a2e3a; color: #a1a1aa; }
.chat-confirm-cancel:hover { background: #363b4a; color: #e4e4e7; }
.chat-confirm-ok { background: #8b5cf6; color: #fff; }
.chat-confirm-ok:hover { background: #7c3aed; }

/* 🔧 v1.755: 反问选项可点击按钮 —— 渲染在问题气泡下方，点一下即自动回复 */
.chat-quick-opts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; padding: 0 4px; }
.chat-quick-opt {
  background: #211d33; color: #c4b5fd; border: 1px solid #3a2f5c; border-radius: 10px;
  padding: 8px 14px; font-size: 13px; font-weight: 500; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.chat-quick-opt:hover { background: #2c2547; border-color: #8b5cf6; transform: translateY(-1px); }
.chat-quick-opt:active { transform: translateY(0); }
.chat-quick-opt:disabled { opacity: .45; cursor: default; transform: none; }
.chat-quick-opt:disabled:hover { background: #211d33; border-color: #3a2f5c; }

/* 🔧 v1.544: 思考过程折叠块（与正文分离，默认收起） */
.chat-thinking { margin: 4px 0 8px; border: 1px solid #2a2e3a; border-radius: 8px; background: #0f1117; overflow: hidden; }
.chat-thinking > summary { cursor: pointer; user-select: none; padding: 6px 10px; font-size: 12px; color: #8b5cf6; font-weight: 500; list-style: none; }
.chat-thinking > summary::-webkit-details-marker { display: none; }
.chat-thinking > summary::before { content: '▸ '; }
.chat-thinking[open] > summary::before { content: '▾ '; }
.chat-thinking-body { padding: 0 10px 10px 10px; font-size: 12.5px; line-height: 1.7; color: #9aa0ad; white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow-y: auto; }
/* 🔧 v1.544: 文件下载卡片（模型下发的 zip/pdf 等链接） */
.chat-msg-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chat-file-chip { display: inline-flex; align-items: center; gap: 4px; max-width: 240px; padding: 5px 10px; border-radius: 7px; background: #1c2030; border: 1px solid #2a2e3a; color: #93c5fd; font-size: 12px; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-file-chip:hover { background: #232838; border-color: #3a4358; color: #bfdbfe; }

/* ─── 输入区 ─── */
.chat-input-area { border-top: 1px solid #262a36; background: #12141c; padding: 12px 16px; flex-shrink: 0; }
.chat-input-area.drag-over { background: #1a1330; outline: 2px dashed #8b5cf6; outline-offset: -6px; }
.chat-refs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; max-height: 140px; overflow-y: auto; }
.chat-refs:empty { display: none; }   /* 🔧 v1.944: 无附件时完全不占位（此前空容器仍占 padding+margin 共 16px，把输入框顶出一大段空隙） */
.chat-ref-thumb { position: relative; width: 56px; height: 56px; border-radius: 8px; overflow: hidden; border: 1px solid #2a2e3a; }
.chat-ref-thumb img { width: 100%; height: 100%; object-fit: cover; }
.chat-ref-thumb .rm { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.6); color: #fff; border: none; border-radius: 50%; width: 16px; height: 16px; font-size: 11px; cursor: pointer; line-height: 14px; }
.chat-input-row { display: flex; align-items: flex-end; gap: 10px; }
.chat-input {
  flex: 1; resize: none; background: #1c1f29; color: #e4e4e7; border: 1px solid #2a2e3a;
  border-radius: 10px; padding: 10px 12px; font-size: 14px; font-family: inherit; line-height: 1.5;
  min-height: 44px; max-height: 55vh; outline: none;   /* 🔧 v1.942: 高度由顶部拖拽手柄调节 */
}
/* 🔧 v1.943: 输入框顶部拖拽手柄（上下拖动调整输入框高度，双击恢复默认）
   热区加大到 12px 并提 z-index，避免被上方 .chat-refs 盖住导致拖不动 */
.chat-input-resizer {
  height: 12px; margin: -8px 0 2px; cursor: ns-resize; user-select: none;
  display: flex; align-items: center; justify-content: center; touch-action: none;
  position: relative; z-index: 3;
}
.chat-input-resizer::before {
  content: ''; width: 48px; height: 3px; border-radius: 2px; background: #333a4a; transition: background .15s;
}
.chat-input-resizer:hover::before, .chat-input-resizer.active::before { background: #8b5cf6; }
.chat-input:focus { border-color: #8b5cf6; }
.chat-send {
  background: #8b5cf6; color: #fff; border: none; border-radius: 10px; height: 40px; padding: 0 18px;
  font-size: 14px; font-weight: 600; cursor: pointer; flex: none;
}
.chat-send:hover { background: #7c3aed; }
.chat-send:disabled { background: #3a2f5c; color: #a78bfa; cursor: default; }
.chat-attach {
  background: #1c1f29; color: #a1a1aa; border: 1px solid #2a2e3a; border-radius: 8px;
  width: 32px; height: 32px; font-size: 16px; cursor: pointer; flex: none;
  display: flex; align-items: center; justify-content: center;
}
.chat-attach:hover { color: #e4e4e7; border-color: #3a3f4d; }

/* ─── 附件：文档缩略 / 拖拽排序 ─── */
.chat-ref-thumb.file { background: #1c1f29; display: flex; align-items: center; justify-content: center; padding: 4px; }
.chat-ref-file { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; height: 100%; gap: 2px; overflow: hidden; }
.chat-ref-ic { font-size: 18px; line-height: 1; }
.chat-ref-nm { font-size: 8px; line-height: 1.1; color: #c4b5fd; text-align: center; max-width: 100%; word-break: break-all; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chat-ref-thumb { cursor: grab; touch-action: none; }
.chat-ref-thumb:active { cursor: grabbing; }
.chat-ref-clone { cursor: grabbing; }

@media (max-width: 720px) {
  .chat-sidebar { width: 200px; min-width: 200px; }
  .chat-bubble img { max-width: 220px; max-height: 220px; }
}

/* v1.747+: 矮窗口自适应——压缩输入区间距，避免底部被裁 */
@media (max-height: 560px) {
  .chat-input-area { padding: 8px 12px; }
  .chat-input { padding: 8px 10px; max-height: 96px; }
  .chat-controls-row { margin-top: 6px; padding-top: 6px; }
  .chat-refs { max-height: 84px; }
  .chat-messages { padding: 12px 12px; }
}
