/* 多会话 / 附件 / 语音 / 回到底部 —— 叠在 chat.css 之上。 */

.chat-layout {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 28px;
  display: flex;
  gap: 18px;
  box-sizing: border-box;
}

.chat-layout.drag-over { outline: 2px dashed var(--ink); outline-offset: -8px; }

.chat-shell {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  max-width: none;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ── 会话列表 ──────────────────────────────────────────────────────── */
.threads {
  width: 236px;
  flex: none;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 18px 0;
  border-right: 1px solid var(--line-soft);
  box-sizing: border-box;
}

.threads-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px 10px;
}

.threads-title { font-size: 12px; font-weight: 600; letter-spacing: 1px; }

.threads-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 2px; }

.thread-group {
  padding: 12px 8px 5px;
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--faint);
}

.thread-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}

.thread-item:hover { background: var(--surface-2); }

.thread-item.on {
  background: var(--surface);
  border-color: var(--line);
}

.thread-item.on::before {
  content: "";
  position: absolute;
  left: 0;
  top: 11px;
  bottom: 11px;
  width: 2px;
  border-radius: 2px;
  background: var(--black);
}

.thread-main { flex: 1; min-width: 0; }

.thread-name {
  font-size: 12px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-time {
  margin-top: 1px;
  font-size: 9px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.thread-ops { display: none; gap: 3px; flex: none; }
.thread-item:hover .thread-ops { display: flex; }

.thread-op {
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
  font-size: 9px;
}

.thread-op:hover { color: var(--ink); }
.thread-op.danger:hover { color: var(--danger); border-color: #e2b2ac; }

.thread-rename {
  width: 100%;
  height: 24px;
  padding: 0 4px;
  border: 1px solid var(--ink);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  outline: none;
}

.threads-foot {
  padding: 10px 4px 0;
  border-top: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.thread-foot-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  padding: 4px 2px;
}

.thread-foot-btn:hover { color: var(--ink); }
.thread-foot-btn.close { display: none; }

.threads-mask {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 9, .42);
  display: none;
  z-index: 55;
}

.threads-mask.open { display: block; }

.thread-toggle { display: none; }

/* ── 回到底部 ──────────────────────────────────────────────────────── */
.scroll-bottom {
  position: absolute;
  left: 50%;
  bottom: 154px;
  transform: translateX(-50%);
  height: 28px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 10px;
  box-shadow: var(--shadow);
  z-index: 12;
}

.scroll-bottom:hover { color: var(--ink); }

/* ── 附件 ──────────────────────────────────────────────────────────── */
.attach-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 0 7px;
}

.attach-tray:empty { display: none; }

.attach-item {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 190px;
  height: 36px;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  font-size: 10px;
}

.attach-thumb { width: 28px; height: 28px; border-radius: 4px; object-fit: cover; flex: none; }
.attach-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.attach-x { border: 0; background: transparent; color: var(--faint); font-size: 12px; padding: 0 1px; }
.attach-x:hover { color: var(--danger); }

.composer-main { flex: 1; min-width: 0; }

.composer-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 1px 0;
}

.tool-btn {
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 10px;
}

.tool-btn:hover { background: var(--surface-2); color: var(--ink); }
.tool-btn.rec { background: var(--black); border-color: var(--black); color: #fff; }

.tool-note { margin-left: auto; font-size: 9px; color: var(--faint); }

/* ── 语音条 ────────────────────────────────────────────────────────── */
.voice-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  font-size: 11px;
}

.voice-pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--black);
  animation: vp 1s infinite;
}

@keyframes vp { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

.voice-time { font-variant-numeric: tabular-nums; color: var(--ink); }
.voice-tip { color: var(--muted); }
.voice-cancel {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
}
.voice-cancel:hover { color: var(--danger); }

/* ── 消息附件 / 操作 ───────────────────────────────────────────────── */
.msg-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
  justify-content: flex-end;
}

.msg-img {
  width: 126px;
  height: 94px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .18);
  cursor: zoom-in;
}

.msg-file {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 220px;
  padding: 6px 8px;
  border-radius: 7px;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-size: 10px;
}

.msg-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.msg-actions {
  display: flex;
  gap: 5px;
  margin-top: 5px;
  opacity: 0;
  transition: opacity .12s ease;
}

.msg:hover .msg-actions,
.msg:focus-within .msg-actions { opacity: 1; }

.msg-act {
  height: 23px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 10px;
}

.msg-act:hover { color: var(--ink); background: var(--surface-2); }

@media (max-width: 1100px) {
  .thread-toggle { display: inline-flex; }

  .threads {
    position: fixed;
    left: 232px;
    top: 0;
    bottom: 0;
    width: 280px;
    z-index: 60;
    background: var(--surface);
    padding: 14px 16px;
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow);
    transform: translateX(-110%);
    transition: transform .2s ease;
  }

  .threads.open { transform: none; }
  .threads .close { display: inline-block; }
  .thread-ops { display: flex; }
  .thread-op { padding: 0 4px; }
  .chat-layout { padding: 0 20px; }
}

@media (max-width: 900px) {
  .threads { left: 0; width: min(86vw, 320px); }
  .chat-layout { padding: 0 14px; }
  .scroll-bottom { bottom: 186px; }
  .msg-actions { opacity: 1; }
  .tool-note { display: none; }
}

.send-btn.stop { background: var(--danger); }
.tool-btn:disabled { opacity: .4; cursor: not-allowed; }
#voiceBtn { touch-action: none; user-select: none; }

/* 用户消息按内容宽度右对齐；否则 flex:1 的 msg-body 会把气泡拉到整行左侧，
   图片又被 justify-content:flex-end 推到最右，气泡和附件像是两条消息。 */
.msg.user .msg-body {
  flex: 0 1 auto;
  max-width: min(82%, 640px);
}
.msg.user .bubble { max-width: 100%; }

/* 会话搜索 */
.threads-search {
  width: 100%;
  height: 30px;
  margin: 0 0 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  color: var(--ink);
  font-size: 11px;
  outline: none;
  box-sizing: border-box;
}
.threads-search:focus { border-color: var(--ink); }
.threads-search::placeholder { color: var(--faint); }
.threads-foot { flex-wrap: wrap; }
.thread-foot-btn { flex: none; }

/* 手机键盘 */
body.kb-up .chat-main { height: calc(100dvh - var(--kb, 0px)); }
body.kb-up .mobile-nav { display: none; }
body.kb-up .chat-head { display: none; }

/* Markdown（只给猫导的回复） */
.bubble strong { font-weight: 600; }
.bubble code {
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--surface-2);
  font-size: .94em;
}
.bubble pre {
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  overflow-x: auto;
  font-size: 11px;
  line-height: 1.55;
}
.bubble pre code { padding: 0; background: transparent; }
.bubble a { color: var(--ink); border-bottom: 1px solid var(--line); }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 20px; }
.bubble li { margin: 2px 0; }
.md-gap { height: 6px; }

/* 录音附件 */
.msg-audio { width: 220px; height: 32px; }

/* 会话搜索为空 */
.thread-empty { padding: 26px 8px; text-align: center; font-size: 11px; color: var(--muted); }

/* 引用条 */
.quote-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 7px 11px;
  border-left: 3px solid var(--ink);
  border-radius: 4px 7px 7px 4px;
  background: var(--surface);
  font-size: 11px;
  color: var(--muted);
}
.quote-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-close { border: 0; background: transparent; color: var(--muted); font-size: 14px; }
.quote-close:hover { color: var(--danger); }

/* 语音确认弹层 */
.voice-preview-text {
  width: 100%;
  min-height: 96px;
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
  box-sizing: border-box;
  outline: none;
}
.voice-preview-text:focus { border-color: var(--ink); }
.voice-preview-audio { width: 100%; margin-top: 12px; }

/* 对话字号偏好（我的页可切） */
html[data-chat-font="s"] .bubble { font-size: 12px; }
html[data-chat-font="l"] .bubble { font-size: 15px; line-height: 1.8; }
