/* ============================================================
   AI 对话模块
   ============================================================ */

.chat { height: 100%; display: flex; position: relative; overflow: hidden; }

/* ---- 会话侧栏 ---- */
.chat-side {
  width: var(--sidebar-w); flex: none;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line-strong);
  box-shadow: var(--divider-shadow);
  border-top: none; border-bottom: none; border-left: none;
  border-radius: 0;
  transition: margin-left var(--t-mid) var(--ease);
}
.chat.side-collapsed .chat-side { margin-left: calc(var(--sidebar-w) * -1); }
.cs-head { display: flex; gap: var(--sp-2); padding: var(--sp-4); }
.cs-new { flex: 1; }
.cs-search { padding: 0 var(--sp-4) var(--sp-3); }
.cs-list { flex: 1; overflow-y: auto; padding: 0 var(--sp-3) var(--sp-4); }

.cs-newgroup {
  display: flex; align-items: center; gap: var(--sp-2);
  width: 100%; padding: 8px 10px; margin-bottom: var(--sp-2);
  border-radius: var(--r-sm); color: var(--tx-3); font-size: var(--fs-sm);
  border: 1px dashed var(--line-2);
  transition: all var(--t-fast);
}
.cs-newgroup:hover { color: var(--neon-cyan); border-color: var(--line-glow); }

.cs-group { margin-bottom: 2px; }
.cs-group-head { display: flex; align-items: center; gap: 2px; padding: 2px 0; }
.cs-group-toggle {
  display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0;
  padding: 7px 8px; border-radius: var(--r-sm);
  color: var(--tx-2); font-size: var(--fs-sm); font-weight: 600;
  transition: background var(--t-fast);
}
.cs-group-toggle:hover { background: var(--bg-3); }
.cs-chev { display: inline-flex; transition: transform var(--t-fast) var(--ease); color: var(--tx-3); }
.cs-group-toggle.collapsed .cs-chev { transform: rotate(0deg); }
.cs-chev { transform: rotate(90deg); }
.cs-g-ic { display: inline-flex; color: var(--neon-violet); }
.cs-count { font-size: var(--fs-xs); color: var(--tx-3); background: var(--bg-3); padding: 1px 7px; border-radius: var(--r-full); }
.cs-group-more { width: 28px; height: 28px; opacity: 0; }
.cs-group-head:hover .cs-group-more { opacity: 1; }
.cs-group-items { padding-left: 10px; }
.cs-empty-mini { color: var(--tx-3); font-size: var(--fs-xs); padding: 6px 10px; }
.cs-sec-title { color: var(--tx-3); font-size: var(--fs-xs); padding: 10px 10px 6px; letter-spacing: 1px; }
.cs-empty { color: var(--tx-3); font-size: var(--fs-sm); text-align: center; padding: 30px 10px; }

.cs-item {
  position: relative;
  display: flex; align-items: center; gap: 4px;
  padding: 9px 8px 9px 10px; border-radius: var(--r-sm);
  cursor: pointer; transition: background var(--t-fast);
  border: 1px solid transparent;
}
.cs-item:hover { background: var(--bg-3); }
.cs-item.active {
  background: var(--grad-brand-soft);
  border-color: var(--line-2);
}
.cs-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cs-item-title { font-size: var(--fs-sm); color: var(--tx-1); }
.cs-item-time { font-size: var(--fs-xs); color: var(--tx-3); }
.cs-pin { color: var(--neon-cyan); display: inline-flex; }
.cs-item-more { width: 26px; height: 26px; opacity: 0; flex: none; }
.cs-item:hover .cs-item-more, .cs-item.active .cs-item-more { opacity: 1; }

/* 侧栏收起后的展开按钮 */
.cs-expand {
  position: absolute; left: 12px; top: 12px; z-index: 5;
  display: none; box-shadow: var(--shadow-1);
}
.chat.side-collapsed .cs-expand { display: inline-flex; }

/* ---- 移到分组弹窗列表 ---- */
.move-group-list { display: flex; flex-direction: column; gap: 6px; }
.move-group-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--r-md);
  border: 1px solid var(--line-1); color: var(--tx-1); font-size: var(--fs-sm);
  transition: all var(--t-fast);
}
.move-group-item:hover { border-color: var(--line-glow); background: var(--bg-3); }
.move-group-item.current { border-color: var(--line-glow); background: var(--grad-brand-soft); }
.move-group-item .i:last-child { margin-left: auto; color: var(--neon-green); }

/* ---- 消息主区 ---- */
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-topbar {
  display: none; align-items: center; gap: var(--sp-3);
  padding: 10px var(--sp-4); border-bottom: 1px solid var(--line-1);
}
.chat-topbar-title { font-size: var(--fs-sm); color: var(--tx-2); }
.chat-scroll { flex: 1; overflow-y: auto; padding: var(--sp-5) var(--sp-5) var(--sp-3); }
.chat-msgs { max-width: var(--composer-max); margin: 0 auto; display: flex; flex-direction: column; gap: var(--sp-5); }
.chat-loading { display: flex; justify-content: center; padding: 60px 0; }

/* ---- 欢迎空态 ---- */
.chat-welcome { text-align: center; padding: 6vh 0 4vh; animation: fadeUp 0.6s var(--ease); }
.cw-orb {
  width: 84px; height: 84px; margin: 0 auto 22px;
  border-radius: 26px; display: flex; align-items: center; justify-content: center;
  background: var(--grad-brand); color: var(--tx-on-neon);
  box-shadow: var(--glow-brand);
  animation: pulseGlow 3.4s ease-in-out infinite;
}
.cw-orb .i { width: 40px; height: 40px; }
.chat-welcome h2 { font-size: var(--fs-2xl); margin-bottom: 8px; }
.cw-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-3); max-width: 560px; margin: 26px auto 0; }
.cw-card {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 14px 16px; border-radius: var(--r-lg);
  background: var(--bg-glass); border: 1px solid var(--line-1);
  color: var(--tx-2); font-size: var(--fs-sm);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: all var(--t-fast) var(--ease);
}
.cw-card:hover { border-color: var(--line-glow); color: var(--tx-1); transform: translateY(-2px); box-shadow: var(--glow-cyan); }
.cw-ic { display: inline-flex; color: var(--neon-cyan); flex: none; }

/* ---- 消息气泡 ---- */
.msg-row { display: flex; gap: var(--sp-3); align-items: flex-start; animation: fadeUp 0.35s var(--ease); }
.msg-row.user { flex-direction: row-reverse; }
.msg-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-sm); font-weight: 700;
  overflow: hidden;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.user-avatar { background: var(--grad-brand); color: var(--tx-on-neon); }
.ai-avatar { background: var(--grad-brand-soft); border: 1px solid var(--line-2); color: var(--neon-cyan); box-shadow: var(--glow-cyan); }

.msg-bubble {
  position: relative; max-width: 78%; min-width: 0;
  padding: 12px 16px; border-radius: var(--r-lg);
  background: var(--bg-glass); border: 1px solid var(--line-1);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  line-height: 1.75; font-size: var(--fs-md);
  overflow-wrap: break-word;
}
.msg-row.user .msg-bubble {
  background: linear-gradient(135deg, rgba(0, 229, 255, 0.14), rgba(139, 92, 246, 0.18));
  border-color: var(--line-2);
  border-bottom-right-radius: var(--r-sm);
}
.msg-row.ai .msg-bubble { border-bottom-left-radius: var(--r-sm); }

.msg-tools {
  position: absolute; top: -14px; right: 12px;
  display: none; gap: 2px; padding: 2px;
  background: var(--bg-glass-strong); border: 1px solid var(--line-2);
  border-radius: var(--r-sm); box-shadow: var(--shadow-1);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.msg-bubble:hover .msg-tools { display: flex; }
.msg-tools .btn-icon { width: 26px; height: 26px; }
.msg-tools .i { width: 14px; height: 14px; }

.msg-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; color: var(--tx-3); font-size: var(--fs-xs); }
.msg-error { color: var(--danger); font-size: var(--fs-sm); margin-top: 6px; }

/* 任务2：AI 等待首包思考动画（打字点 + 呼吸文案） */
.ai-thinking { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.ai-thinking-text {
  font-size: var(--fs-sm); color: var(--tx-3);
  animation: aiThinkPulse 1.6s ease-in-out infinite;
}
@keyframes aiThinkPulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }

/* 任务4：生成失败气泡（仅通用提示，不暴露上游原因） */
.msg-failed {
  display: flex; align-items: center; gap: 8px;
  color: var(--danger); font-size: var(--fs-sm);
}
.msg-failed .i { flex: none; }

/* 加密思考完成标记（思考内容不可见但确实思考过） */
.msg-reason-encrypted {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
  padding: 7px 12px; border: 1px solid var(--line-1); border-radius: var(--r-md);
  background: rgba(139, 92, 246, 0.06);
  color: var(--neon-violet); font-size: var(--fs-sm); font-weight: 600;
}
.reason-pending { color: var(--tx-3); animation: aiThinkPulse 1.6s ease-in-out infinite; }

/* 思考块 */
.msg-reason {
  margin-bottom: 10px; border: 1px solid var(--line-1);
  border-radius: var(--r-md); background: rgba(139, 92, 246, 0.06);
}
.msg-reason summary {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; cursor: pointer; user-select: none;
  color: var(--neon-violet); font-size: var(--fs-sm); font-weight: 600;
  list-style: none;
}
.msg-reason summary::-webkit-details-marker { display: none; }
.reason-body { padding: 0 12px 10px; color: var(--tx-3); font-size: var(--fs-sm); border-top: 1px dashed var(--line-1); padding-top: 8px; }

/* 附件展示 */
.msg-attach { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.msg-attach-img { max-width: 220px; max-height: 180px; border-radius: var(--r-md); border: 1px solid var(--line-1); object-fit: cover; }
.msg-attach-file {
  display: inline-flex; align-items: center; gap: 8px; max-width: 240px;
  padding: 8px 12px; border-radius: var(--r-md);
  background: var(--bg-3); border: 1px solid var(--line-1);
  font-size: var(--fs-sm); color: var(--tx-1);
  transition: border-color var(--t-fast);
}
.msg-attach-file:hover { border-color: var(--line-glow); }

/* ---- markdown 渲染样式 ---- */
.md p, .md .md-p { margin: 0 0 10px; }
.md > :last-child, .md .md-p:last-child { margin-bottom: 0; }
.md-h { margin: 14px 0 8px; line-height: 1.4; }
.md-h1 { font-size: 1.45em; } .md-h2 { font-size: 1.3em; } .md-h3 { font-size: 1.15em; } .md-h4 { font-size: 1.05em; }
.md-h:first-child { margin-top: 0; }
.md-hr { margin: 14px 0; }
.md-list { margin: 8px 0 10px; padding-left: 22px; display: flex; flex-direction: column; gap: 4px; }
ul.md-list { list-style: disc; }
ol.md-list { list-style: decimal; }
.md-task { list-style: none; margin-left: -22px; display: flex; align-items: flex-start; gap: 8px; }
.md-task input { margin-top: 5px; accent-color: var(--neon-cyan); }
.md-task.done span { color: var(--tx-3); text-decoration: line-through; }
.md-quote {
  margin: 10px 0; padding: 8px 14px;
  border-left: 3px solid var(--neon-violet);
  background: rgba(139, 92, 246, 0.08); border-radius: 0 var(--r-md) var(--r-md) 0;
  color: var(--tx-2);
}
.md-quote p { margin: 4px 0; }
.md-inline-code {
  font-family: var(--font-mono); font-size: 0.88em;
  background: rgba(0, 229, 255, 0.1); border: 1px solid var(--line-1);
  padding: 1px 6px; border-radius: 6px; color: var(--neon-cyan);
}
.md-code { margin: 10px 0; border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--line-1); background: var(--bg-1); }
.md-code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px; background: var(--bg-3); border-bottom: 1px solid var(--line-1);
}
.md-code-lang { font-size: var(--fs-xs); color: var(--tx-3); font-family: var(--font-mono); letter-spacing: 1px; }
.md-code-copy {
  font-size: var(--fs-xs); color: var(--tx-2); padding: 2px 10px;
  border-radius: var(--r-sm); border: 1px solid var(--line-1);
  transition: all var(--t-fast);
}
.md-code-copy:hover { color: var(--neon-cyan); border-color: var(--line-glow); }
.md-code pre { padding: 12px 14px; overflow-x: auto; }
.md-code code { font-family: var(--font-mono); font-size: var(--fs-sm); line-height: 1.65; color: var(--tx-1); }
.md-link { color: var(--neon-cyan); text-decoration: underline; text-underline-offset: 3px; }
.md-link:hover { color: var(--neon-magenta); }
.md-img { max-width: min(420px, 100%); border-radius: var(--r-md); margin: 8px 0; border: 1px solid var(--line-1); }
.md-table-wrap { overflow-x: auto; margin: 10px 0; }
.md-table { border-collapse: collapse; min-width: 50%; font-size: var(--fs-sm); }
.md-table th, .md-table td { border: 1px solid var(--line-2); padding: 7px 12px; text-align: left; }
.md-table th { background: var(--bg-3); color: var(--tx-1); font-weight: 600; }
.md-table tr:nth-child(even) td { background: rgba(120, 140, 255, 0.03); }

/* ---- Composer ---- */
.chat-composer-wrap { flex: none; padding: var(--sp-3) var(--sp-5) var(--sp-5); }
.composer {
  max-width: var(--composer-max); margin: 0 auto;
  border-radius: var(--r-xl); padding: 12px 14px 10px;
  background: var(--bg-glass-strong);
  box-shadow: var(--shadow-2);
  display: flex; flex-direction: column; gap: 8px;
}
.composer:focus-within { border-color: var(--line-glow); box-shadow: var(--shadow-2), 0 0 0 3px rgba(0, 229, 255, 0.08); }
.composer-input {
  width: 100%; border: none; background: transparent; resize: none;
  max-height: 180px; font-size: var(--fs-md); line-height: 1.7; color: var(--tx-1);
}
.composer-input:focus { outline: none; }
.composer-input::placeholder { color: var(--tx-3); }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.cb-left { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.composer-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: var(--r-full);
  background: var(--bg-3); border: 1px solid var(--line-1);
  font-size: var(--fs-xs); color: var(--tx-2); font-weight: 600;
  transition: all var(--t-fast);
}
.composer-chip:hover { border-color: var(--line-glow); color: var(--tx-1); }
.composer-switch { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.composer-switch .cs-label { font-size: var(--fs-xs); color: var(--tx-2); user-select: none; }
.composer-switch .switch { width: 32px; height: 18px; }
.composer-switch .switch .sw-track::after { width: 12px; height: 12px; }
.composer-switch .switch input:checked + .sw-track::after { transform: translateX(14px); }
.composer-switch.cap-off { opacity: 0.45; cursor: not-allowed; }
.composer-switch.cap-off .switch input { cursor: not-allowed; }

.send-btn {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--grad-brand); color: var(--tx-on-neon);
  box-shadow: var(--glow-brand);
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast);
}
.send-btn:hover { transform: scale(1.06); box-shadow: 0 6px 30px rgba(79, 124, 255, 0.55); }
.send-btn.is-stop { background: linear-gradient(135deg, #ff5d73, #f471b5); box-shadow: 0 0 20px rgba(255, 93, 115, 0.4); }

/* 附件 chips */
.composer-attach { display: flex; flex-wrap: wrap; gap: 8px; }
.attach-chip {
  display: flex; align-items: center; gap: 8px; max-width: 260px;
  padding: 6px 8px; border-radius: var(--r-md);
  background: var(--bg-3); border: 1px solid var(--line-1);
}
.attach-thumb { width: 34px; height: 34px; border-radius: var(--r-sm); object-fit: cover; }
.attach-ic { display: inline-flex; color: var(--neon-cyan); }
.attach-name { font-size: var(--fs-xs); color: var(--tx-2); }
.attach-x { width: 22px; height: 22px; }

/* 模型菜单 */
.model-menu { min-width: 260px; max-width: 320px; padding: 6px; }
.model-group { padding: 2px 0; }
.model-group + .model-group { border-top: 1px solid var(--line-1); margin-top: 4px; padding-top: 6px; }
.model-group-title { font-size: var(--fs-xs); color: var(--tx-3); font-weight: 600; letter-spacing: .08em; padding: 4px 12px 6px; }
.model-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; border-radius: var(--r-sm); text-align: left;
  transition: background var(--t-fast);
}
.model-item:hover { background: var(--bg-3); }
.model-item.active { background: var(--grad-brand-soft); }
.model-item.locked { opacity: 0.72; }
.model-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.model-name { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); font-weight: 600; }
.model-crown { color: var(--neon-gold); display: inline-flex; }
.model-lock { color: var(--tx-3); display: inline-flex; }
.model-desc { font-size: var(--fs-xs); color: var(--tx-3); }
.model-check { color: var(--neon-cyan); display: inline-flex; }
.model-price { flex: none; font-size: var(--fs-xs); color: var(--neon-gold); opacity: 0.9; }
.model-price.free { color: var(--neon-green); }
.model-demo { flex: none; font-size: var(--fs-xs); color: var(--tx-3); border: 1px solid var(--line-2); border-radius: 4px; padding: 0 4px; line-height: 1.6; }

/* 遮罩（移动端抽屉）：需高于顶栏(49)与移动端底栏(50) */
.chat-backdrop {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(3, 5, 16, 0.55); backdrop-filter: blur(4px);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 0.32s var(--ease), visibility 0s linear 0.32s;
}

/* ---- 响应式 ---- */
@media (max-width: 1024px) {
  .chat-side {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 56;
    transform: translateX(calc(-105% + var(--drag-x, 0px)));
    transition: transform 0.32s var(--ease);
    will-change: transform;
    border: none; border-right: 1px solid var(--line-strong);
    background: var(--bg-glass-strong);
  }
  .chat.side-open .chat-side { transform: translateX(var(--drag-x, 0px)); }
  .chat.side-open .chat-backdrop { opacity: 1; visibility: visible; transition-delay: 0s; pointer-events: auto; }
  .chat.dragging .chat-side, .chat.dragging .chat-backdrop { transition: none; }
  .chat.side-collapsed .chat-side { margin-left: 0; }
  .cs-collapse, .cs-expand { display: none !important; }
  .chat-topbar { display: flex; }
}
@media (max-width: 768px) {
  .chat-scroll { padding: var(--sp-4) var(--sp-3) var(--sp-2); }
  .chat-composer-wrap { padding: var(--sp-2) var(--sp-3) var(--sp-3); }
  .msg-bubble { max-width: 88%; }
  .cw-grid { grid-template-columns: 1fr; }
  /* 手机端保留「深度思考 / 联网搜索」文字：收紧间距与字号，允许整体换行防溢出 */
  .cb-left { gap: var(--sp-2); row-gap: var(--sp-2); }
  .composer-switch { gap: 5px; }
  .composer-switch .cs-label { display: inline; font-size: 11px; white-space: nowrap; }
}
