:root {
  --bg: #f2f3f5;
  --bg-soft: #ffffff;
  --bg-raise: #f7f8fa;
  --line: #e5e8ed;
  --text: #1f2329;
  --text-dim: #8a919f;
  --accent: #12b7f5;
  --accent-hover: #08a8e6;
  --accent-soft: #e5f7ff;
  --danger: #f25555;
  --radius: 16px;
  --shadow: 0 10px 32px rgba(31, 35, 41, .09);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 12px;
  cursor: pointer;
  transition: transform .14s ease, background .14s ease, border-color .14s ease, color .14s ease, box-shadow .14s ease;
}
button:hover { border-color: #cfd5dd; background: #f1f3f6; }
button:active { transform: scale(.97); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.icon { padding: 4px 10px; font-size: 20px; line-height: 1.1; background: none; border: none; }
button.danger { border-color: #ffdada; color: var(--danger); background: #fff8f8; }
button.link { background: none; border: none; color: var(--text-dim); }

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }

.hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
.screen { height: 100dvh; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.screen.center { align-items: center; justify-content: center; padding: 24px; }

/* ---------- 登录 / 设置 ---------- */
.card {
  width: min(380px, 100%);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
}
.card h1 { font-size: 20px; margin: 0; }
.hint { color: var(--text-dim); font-size: 13px; margin: 0; }
.error { color: var(--danger); font-size: 13px; margin: 0; min-height: 18px; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 8px rgba(31, 35, 41, .04);
  z-index: 10;
}
.topbar .title { font-weight: 600; letter-spacing: .02em; font-size: 17px; }
.topbar .actions { display: flex; gap: 8px; }
.topbar .actions button { padding: 5px 10px; font-size: 13px; }
.session-search-wrap { display: flex; align-items: center; gap: 6px; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--line); }
.session-search-wrap input { padding: 7px 10px; background: #f3f5f7; border-color: transparent; }
.session-search-wrap button { width: 26px; height: 26px; padding: 0; border: none; background: transparent; color: var(--text-dim); font-size: 18px; }
.session-search-results { max-height: 38dvh; overflow-y: auto; padding: 6px 12px 10px; background: #fff; border-bottom: 1px solid var(--line); }
.session-search-results > p { margin: 4px 0; color: var(--text-dim); font-size: 13px; }
.chat-head {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  cursor: pointer;
}
.chat-head span { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 头像 ---------- */
.avatar {
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-raise);
  border: 1px solid rgba(0, 0, 0, .05);
}
.avatar.small { width: 30px; height: 30px; }
.avatar.big { width: 64px; height: 64px; }

/* ---------- 会话列表 ---------- */
.session-list { flex: 1; overflow-y: auto; background: #fff; }
.session-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background .16s ease, transform .16s ease;
}
.session-row:hover, .session-row:active { background: #f7fbfd; }
.session-row:active { transform: scale(.992); }
.session-row .avatar-fallback {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 600;
  background: linear-gradient(145deg, #6bd4fb, #12b7f5);
  color: #fff;
  flex: 0 0 auto;
}
.session-row img.avatar { width: 48px; height: 48px; flex: 0 0 auto; }
.session-main { flex: 1; min-width: 0; }
.session-main .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-main .preview { color: var(--text-dim); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: 0 0 auto; }
.session-side .time { color: var(--text-dim); font-size: 12px; }
.session-side .more { background: none; border: none; color: var(--text-dim); font-size: 18px; padding: 0 6px; }
.session-pinned { color: #7b8794; font-size: 11px; }
.session-unread { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 10px; color: #fff; background: #f05d5e; font-size: 11px; line-height: 18px; text-align: center; }
.session-search-result { width: 100%; display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border: none; border-radius: 8px; background: transparent; text-align: left; }
.session-search-result:hover { background: #f2f5f7; }
.session-search-result strong { font-size: 13px; font-weight: 600; }
.session-search-result span { overflow: hidden; color: var(--text-dim); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--text-dim); }

/* ---------- 消息区 ---------- */
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: #f2f3f5;
  -webkit-overflow-scrolling: touch;
}
.archive-page-button {
  align-self: center;
  padding: 7px 14px;
  border: 1px solid #d6e8f1;
  border-radius: 999px;
  background: #fff;
  color: #4785a1;
  font-size: 12px;
}
.msg { display: flex; flex-direction: column; max-width: 82%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot { align-self: flex-start; align-items: flex-start; }
.bubble {
  position: relative;
  padding: 10px 14px;
  border-radius: 8px;
  background: #fff;
  border: none;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(31, 35, 41, .05);
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .bubble { background: var(--accent); color: #fff; }
.msg.bot .bubble::before,
.msg.user .bubble::before {
  content: "";
  position: absolute;
  top: 12px;
  width: 0;
  height: 0;
  border: 6px solid transparent;
}
.msg.bot .bubble::before { left: -11px; border-right-color: #fff; }
.msg.user .bubble::before { right: -11px; border-left-color: var(--accent); }
.bubble img { max-width: 100%; border-radius: 10px; display: block; margin: 4px 0; }
.bubble video { max-width: 100%; max-height: 65dvh; border-radius: 10px; display: block; margin: 4px 0; }

#view-chat.archive-read-only .composer,
#view-chat.archive-read-only .composer-resizer,
#view-chat.archive-read-only .quote-bar { display: none; }
#view-chat.archive-read-only .scroll-bottom { bottom: 24px; }
.bubble .quote {
  border-left: 3px solid rgba(18, 183, 245, .65);
  padding-left: 8px;
  margin-bottom: 6px;
  color: var(--text-dim);
  font-size: 13px;
}
.msg.user .bubble .quote { border-left-color: rgba(255, 255, 255, .72); color: rgba(255, 255, 255, .8); }
.msg .meta { font-size: 11px; color: var(--text-dim); margin-top: 4px; padding: 0 4px; }
.msg.error .bubble { border-color: var(--danger); color: var(--danger); }

/* 消息行 + 头像 */
.msg-row { display: flex; align-items: flex-start; gap: 11px; max-width: 100%; }
.msg-row.user { flex-direction: row-reverse; }
.msg-row.msg-enter { animation: message-enter .22s cubic-bezier(.2, .8, .2, 1) both; }
.msg-row.msg-leave { pointer-events: none; animation: message-leave .16s ease both; }
.msg-row .msg { align-self: auto; max-width: min(78%, 560px); }
.msg-avatar {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  font-size: 15px;
  font-weight: 600;
}
.avatar-fallback {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #6bd4fb, #12b7f5);
  color: #fff;
  border: 1px solid rgba(0, 0, 0, .04);
}
.typing { display: inline-flex; gap: 3px; padding: 4px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-dim); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25 } 30% { opacity: 1 } }
@keyframes message-enter { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes message-leave { to { opacity: 0; transform: translateX(10px) scale(.98); max-height: 0; margin-block: -8px; } }

/* ---------- 引用 / 待发附件 ---------- */
.quote-bar {
  margin: 0 14px 6px;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  background: #eef9fe;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--text-dim);
}
.quote-bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-bar button { border: none; background: none; color: var(--text-dim); font-size: 18px; padding: 0 4px; }
.pending { padding: 0 14px 8px; background: #fff; }
.pending-items { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; }
.pending .chip { position: relative; flex: 0 0 auto; }
.pending .chip img { width: 62px; height: 62px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.pending .chip .chip-delete {
  position: absolute; top: -6px; right: -6px;
  padding: 0; width: 20px; height: 20px; line-height: 18px;
  border-radius: 50%; font-size: 13px; background: var(--bg-raise);
}
.chip-order { position: absolute; right: 3px; bottom: 3px; display: flex; overflow: hidden; border: 1px solid rgba(31, 35, 41, .15); border-radius: 6px; background: rgba(255, 255, 255, .88); }
.pending .chip .chip-move { position: static; width: 16px; height: 16px; padding: 0; border: none; border-radius: 0; background: transparent; color: #3f4854; font-size: 15px; line-height: 14px; }
.pending .chip .chip-move:disabled { opacity: .25; }
.pending-editor { display: flex; align-items: center; gap: 8px; min-width: 0; }
.compress-toggle { flex: 0 0 auto; display: flex; align-items: center; gap: 4px; color: var(--text-dim); font-size: 12px; white-space: nowrap; }
.compress-toggle input { width: auto; margin: 0; }
.pending-editor input[type="text"] { min-width: 0; padding: 6px 9px; font-size: 13px; }
.upload-status { flex: 0 0 auto; max-width: 30%; overflow: hidden; color: #6d7785; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.transfer-feedback { padding: 7px 14px 8px; background: #fff; border-top: 1px solid #eef0f2; }
.transfer-feedback { opacity: 0; transform: translateY(6px); transition: opacity .18s ease, transform .18s ease; }
.transfer-feedback.is-open { opacity: 1; transform: translateY(0); }
.transfer-copy { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 5px; color: #697482; font-size: 12px; }
.transfer-copy span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.transfer-copy span:last-child { color: #12aeea; font-variant-numeric: tabular-nums; }
.transfer-track { width: 100%; height: 4px; overflow: hidden; border-radius: 99px; background: #e8edf1; }
.transfer-fill { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #33c4f5, #1599ea); transition: width .16s linear; }
.transfer-feedback.error .transfer-copy span:last-child { color: var(--danger); }
.transfer-feedback.error .transfer-fill { background: #f06a6a; }

/* ---------- 输入区 ---------- */
.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
  background: rgba(255, 255, 255, .98);
  border-top: 1px solid var(--line);
}
.composer textarea { resize: none; max-height: 132px; border-radius: 10px; background: #f4f5f7; border-color: transparent; }
.composer textarea:focus { background: #fff; border-color: #b6e7fa; box-shadow: 0 0 0 3px rgba(18, 183, 245, .1); }

/* ---------- 表情面板 ---------- */
.sticker-panel {
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
  max-height: 46dvh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .18s ease, transform .22s cubic-bezier(.2, .8, .2, 1);
}
.sticker-panel.is-open { opacity: 1; transform: translateY(0); }
.tabs { display: flex; gap: 8px; align-items: center; }
.tabs button { font-size: 13px; padding: 5px 10px; }
.tabs button:not(.active):not(.link) { color: var(--text-dim); background: none; }
.tabs button.active { color: #079ed8; background: var(--accent-soft); border-color: #b7e9fb; }
.tags { display: flex; gap: 6px; overflow-x: auto; }
.tags button { font-size: 12px; padding: 3px 9px; color: var(--text-dim); background: none; }
.tags button.active { color: var(--text); background: var(--bg-raise); }
.sticker-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px;
  overflow-y: auto;
}
.sticker-list img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.sticker-list img:active { border-color: var(--accent); }

/* ---------- 弹窗 ---------- */
.dialog {
  position: fixed;
  inset: 0;
  background: rgba(31, 35, 41, .35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 40;
  opacity: 0;
  transition: opacity .18s ease;
}
.dialog.is-open { opacity: 1; }
.dialog-card {
  width: min(400px, 100%);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
  transform: translateY(10px) scale(.985);
  transition: transform .2s cubic-bezier(.2, .8, .2, 1);
}
.dialog.is-open .dialog-card { transform: translateY(0) scale(1); }
.dialog-card h2 { margin: 0; font-size: 17px; }
.dialog-row { display: flex; align-items: center; gap: 14px; }
.dialog-avatar-actions { display: flex; flex-direction: column; gap: 8px; }
.dialog-avatar-actions button { padding: 5px 10px; font-size: 13px; }
.dialog-label { color: var(--text-dim); font-size: 13px; }
.dialog-card textarea { min-height: 112px; resize: vertical; line-height: 1.45; }
.dialog-hint { margin: -5px 0 0; color: var(--text-dim); font-size: 12px; line-height: 1.45; }
.dialog-check { display: flex; align-items: center; gap: 7px; color: var(--text-dim); font-size: 14px; }
.dialog-check input { width: auto; margin: 0; }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.dialog-actions .spacer { flex: 1; }
.dialog-actions button { padding: 7px 12px; }

/* ---------- 图库选择 ---------- */
.gallery-picker { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(31, 35, 41, .34); opacity: 0; transition: opacity .18s ease; }
.gallery-picker.is-open { opacity: 1; }
.gallery-picker-card { width: min(440px, 100%); max-height: min(560px, 84dvh); overflow: hidden; border-radius: 14px; background: #fff; box-shadow: var(--shadow); transform: translateY(14px) scale(.985); transition: transform .22s cubic-bezier(.2, .8, .2, 1); }
.gallery-picker.is-open .gallery-picker-card { transform: translateY(0) scale(1); }
.gallery-picker-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 16px 18px 12px; border-bottom: 1px solid var(--line); }
.gallery-picker-head h2 { margin: 0; font-size: 17px; }
.gallery-picker-head p { margin: 3px 0 0; color: var(--text-dim); font-size: 12px; }
.gallery-picker-head button { font-size: 20px; }
.gallery-picker-list { max-height: min(440px, 64dvh); overflow-y: auto; padding: 8px; }
.gallery-loading { padding: 18px 10px; margin: 0; color: var(--text-dim); text-align: center; }
.gallery-choice { width: 100%; display: flex; flex-direction: column; gap: 3px; margin: 2px 0; padding: 12px; border: none; background: transparent; text-align: left; border-radius: 9px; }
.gallery-choice:hover { background: #f1f8fc; }
.gallery-choice strong { font-size: 15px; }
.gallery-choice span { color: var(--text-dim); font-size: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translate(-50%, 10px);
  opacity: 0;
  color: #fff;
  background: rgba(31, 35, 41, .9);
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  z-index: 50;
  transition: opacity .16s ease, transform .18s cubic-bezier(.2, .8, .2, 1);
}
.toast.is-open { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 滚动到底部 ---------- */
#view-chat { position: relative; min-height: 0; --quote-bar-offset: 0px; }
#view-chat.has-quote { --quote-bar-offset: 52px; }
.chat-pane { position: relative; min-width: 0; min-height: 0; overflow: hidden; flex: 1; display: flex; flex-direction: column; }
.desktop-sidebar { display: none; }
.composer-resizer { display: none; }
.scroll-bottom {
  position: absolute;
  right: 14px;
  bottom: calc(env(safe-area-inset-bottom) + 84px + var(--quote-bar-offset));
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  color: #079ed8;
  background: #fff;
  border: 1px solid #d9eef6;
  box-shadow: 0 6px 20px rgba(31, 35, 41, .12);
  z-index: 20;
  transition: bottom .18s ease;
}

/* ---------- 消息操作菜单 ---------- */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(31, 35, 41, .35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
  opacity: 0;
  transition: opacity .18s ease;
}
.sheet.is-open { opacity: 1; }
.sheet-card {
  width: min(440px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 10px 10px calc(env(safe-area-inset-bottom) + 10px);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transform: translateY(104%);
  transition: transform .24s cubic-bezier(.2, .8, .2, 1);
}
.sheet.is-open .sheet-card { transform: translateY(0); }
.sheet-card button {
  text-align: left;
  padding: 13px 14px;
  border-radius: 12px;
  background: none;
  border: none;
  font-size: 15px;
}
.sheet-card button:hover, .sheet-card button:active { background: #f4f6f8; }
.sheet-card button.danger { color: var(--danger); }
.sheet-card button.link { text-align: center; color: var(--text-dim); font-size: 14px; }

/* ---------- 大图预览 ---------- */
.viewer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .94);
  z-index: 70;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transition: opacity .18s ease;
}
.viewer.is-open { opacity: 1; }
.viewer-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: calc(env(safe-area-inset-top) + 10px) 84px 8px 12px;
}
.viewer-bar span { flex: 1; text-align: center; color: var(--text-dim); font-size: 13px; }
.viewer-top-action,
#viewer-close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 8px);
  z-index: 2;
  width: 32px;
  height: 32px;
  padding: 0;
  color: rgba(255, 255, 255, .92);
  background: transparent;
  border: 0;
  border-radius: 0;
  font-size: 22px;
  font-weight: 300;
  line-height: 32px;
  text-align: center;
  box-shadow: none;
}
.viewer-top-action { right: 44px; }
#viewer-close { right: 8px; }
.viewer-top-action:hover,
.viewer-top-action:active,
#viewer-close:hover,
#viewer-close:active { background: transparent; border: 0; color: #fff; }
.viewer-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}
.viewer-stage img {
  max-width: 100%;
  max-height: 100%;
  transition: transform .18s ease-out, opacity .16s ease-out;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.viewer-stage img.viewer-dragging { transition: none; }
.viewer-stage img.viewer-slide-out-left { transform: translateX(-34vw) scale(.98) !important; opacity: 0 !important; }
.viewer-stage img.viewer-slide-out-right { transform: translateX(34vw) scale(.98) !important; opacity: 0 !important; }
.viewer-stage img.viewer-slide-in-left { transform: translateX(-34vw) scale(.98) !important; opacity: 0 !important; transition: none; }
.viewer-stage img.viewer-slide-in-right { transform: translateX(34vw) scale(.98) !important; opacity: 0 !important; transition: none; }
.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, .08);
  border-color: rgba(255, 255, 255, .14);
  font-size: 22px;
  padding: 4px 12px;
}
.viewer-nav.prev { left: 10px; }
.viewer-nav.next { right: 10px; }
.viewer-hint {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 10px);
}

/* 大图长按操作：遮罩点空白处收起，白框从底部滑入。 */
.viewer-actions {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  background: rgba(0, 0, 0, 0);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, background .2s ease;
}
.viewer-actions.open {
  background: rgba(0, 0, 0, .16);
  opacity: 1;
  pointer-events: auto;
}
.viewer-actions-card {
  width: 100%;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 12px);
  background: #fff;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 28px rgba(0, 0, 0, .16);
  transform: translateY(100%);
  transition: transform .24s cubic-bezier(.2, .8, .2, 1);
}
.viewer-actions.open .viewer-actions-card { transform: translateY(0); }
.viewer-actions-card button {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  color: #1f2329;
  background: transparent;
  border: 0;
  border-radius: 10px;
  font-size: 16px;
  text-align: center;
}
.viewer-actions-card button:active { background: #f2f4f6; }

/* 定位后高亮 */
.msg.flash .bubble { box-shadow: 0 0 0 3px rgba(18, 183, 245, .35); }
.msg-row.search-hit .bubble { animation: search-hit 1.8s ease-out; }
@keyframes search-hit { 0%, 35% { box-shadow: 0 0 0 4px rgba(18, 183, 245, .46); } 100% { box-shadow: none; } }
.retry-btn { margin-top: 6px; font-size: 13px; padding: 4px 10px; }

/* ---------- QQ 风格细节与响应式 ---------- */
#view-list, #view-chat { background: var(--bg); }
#view-list .topbar { min-height: 60px; }
#view-chat .topbar { min-height: 58px; }
#btn-back { color: #505967; font-size: 30px; font-weight: 300; }
#btn-edit { color: #505967; font-size: 24px; letter-spacing: 2px; }
#btn-sticker, #btn-image { color: #525b68; font-size: 24px; }
#btn-send { min-width: 66px; border-radius: 8px; }
.chat-head { justify-content: center; }
.chat-head span { font-size: 16px; }
.chat-head .avatar { width: 32px; height: 32px; }
.msg .meta { color: #a1a7b2; }
.msg.user .meta { text-align: right; }
.msg.error .bubble { background: #fff0f0; color: var(--danger); }
.msg.error .bubble::before { border-left-color: #fff0f0; border-right-color: #fff0f0; }
.pending { background: #fff; padding-top: 8px; }
.session-main .name { color: #222832; font-size: 16px; }
.session-main .preview { margin-top: 2px; color: #9299a5; }
.session-side .time { color: #a4aab4; }

@media (min-width: 900px) {
  /* 桌面端：QQ风双栏聊天（左侧会话栏 + 右侧聊天区） */
  #view-chat { flex-direction: row; background: #f5f6f7; }
  #view-list { max-width: 760px; margin: 0 auto; box-shadow: var(--shadow); }
  #view-list > .topbar,
  #view-list > .session-search-wrap,
  #view-list > .session-search-results,
  #view-list > .session-list,
  #view-list > .empty { width: 100%; align-self: center; }

  .desktop-sidebar {
    display: flex;
    width: 270px;
    flex: 0 0 270px;
    flex-direction: column;
    background: #f5f6f7;
    border-right: 1px solid #e7e8eb;
  }
  .desktop-account {
    display: flex;
    align-items: center;
    height: 54px;
    min-height: 54px;
    gap: 10px;
    padding: 0 16px;
    background: #ebedf0;
    border-bottom: 1px solid #e2e4e8;
  }
  .desktop-self-avatar {
    display: flex;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    padding: 0;
    overflow: hidden;
    color: #fff;
    background: linear-gradient(145deg, #6bd4fb, #12b7f5);
    border: none;
    border-radius: 50%;
  }
  .desktop-self-avatar .avatar { width: 34px; height: 34px; border: 0; }
  .desktop-account-name { display: flex; min-width: 0; flex: 1; flex-direction: column; line-height: 1.25; }
  .desktop-account-name strong { overflow: hidden; font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
  .desktop-account-name span { color: #8a919f; font-size: 11px; }
  .desktop-add {
    width: 28px;
    height: 28px;
    padding: 0;
    color: #747b86;
    background: #fff;
    border: 1px solid #e4e5e7;
    border-radius: 6px;
    font-size: 20px;
    font-weight: 300;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }
  .desktop-add:hover { background: #f0f2f5; border-color: #cfd5dd; }
  .desktop-session-search-wrap { padding: 9px 12px 5px; background: #f5f6f7; }
  .desktop-session-search-wrap input { padding: 6px 9px; border: none; border-radius: 6px; background: #e9ebee; font-size: 12px; }
  .desktop-session-list { flex: 1; overflow-y: auto; padding: 6px 8px 10px; }
  .desktop-session-list .session-row {
    gap: 10px;
    margin: 1px 0;
    padding: 9px 8px;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    transition: background .12s ease;
  }
  .desktop-session-list .session-row:hover { background: #eaecef; }
  .desktop-session-list .session-row.active { background: #dfe2e6; }
  .desktop-session-list .session-row img.avatar,
  .desktop-session-list .session-row .avatar-fallback { width: 40px; height: 40px; border-radius: 8px; }
  .desktop-session-list .session-main .name { font-size: 14px; font-weight: 500; color: #1f2329; }
  .desktop-session-list .session-main .preview { font-size: 12px; color: #8a919f; margin-top: 2px; }
  .desktop-session-list .session-side { gap: 0; align-self: stretch; }
  .desktop-session-list .session-side .time { padding-top: 1px; font-size: 11px; color: #a4aab4; }
  .desktop-session-list .session-side .more { display: none; }
  .desktop-search-label { padding: 10px 8px 4px; color: #8a919f; font-size: 12px; }
  .desktop-session-list .session-search-result { padding: 8px; }

  .chat-pane { background: #f5f6f7; }
  #view-chat .topbar {
    height: 54px;
    min-height: 54px;
    padding: 0 24px;
    background: #fcfcfd;
    border-bottom: 1px solid #e7e8eb;
    box-shadow: none;
  }
  #view-chat #btn-back { display: none; }
  #view-chat .chat-head { justify-content: flex-start; gap: 10px; }
  #view-chat .chat-head span { font-size: 16px; font-weight: 600; color: #1f2329; }
  #view-chat .chat-head .avatar { width: 32px; height: 32px; border-radius: 50%; }
  #view-chat #btn-edit { color: #6f7680; font-size: 18px; padding: 4px 8px; border-radius: 6px; }
  #view-chat #btn-edit:hover { background: #eaecef; }

  #view-chat .messages { padding: 20px 32px 14px; background: #f5f6f7; }
  #view-chat .msg-row .msg { max-width: min(72%, 650px); }
  #view-chat .msg-row { gap: 10px; }
  #view-chat .msg-avatar { width: 36px; height: 36px; border-radius: 6px; }
  #view-chat .bubble { padding: 9px 13px; border-radius: 8px; font-size: 14.5px; line-height: 1.55; box-shadow: 0 1px 2px rgba(31, 35, 41, .04); }
  #view-chat .msg.user .bubble { background: #c9ecff; color: #1f2b32; }
  #view-chat .msg.user .bubble::before { border-left-color: #c9ecff; }
  #view-chat .msg.bot .bubble { background: #fff; }
  #view-chat .msg .meta { margin-top: 4px; font-size: 11px; color: #a4aab4; }
  #view-chat .scroll-bottom { bottom: calc(var(--desktop-composer-height, 140px) + 24px + var(--quote-bar-offset)); }

#view-chat .composer-resizer {
    position: relative;
    display: block;
    height: 4px;
    flex: 0 0 4px;
    cursor: ns-resize;
    background: #fff;
    touch-action: none;
    z-index: 2;
  }
  #view-chat .composer-resizer::after {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 1px;
    content: "";
    background: #e7e8eb;
    transition: background .15s ease, height .15s ease;
  }
  #view-chat .composer-resizer:hover::after,
  #view-chat.resizing .composer-resizer::after {
    height: 2px;
    background: #12b7f5;
  }
  #view-chat.resizing { user-select: none; cursor: ns-resize; }

  #view-chat .composer {
    position: relative;
    height: var(--desktop-composer-height, 140px);
    min-height: 72px;
    max-height: 460px;
    flex: 0 0 var(--desktop-composer-height, 140px);
    align-items: flex-end;
    gap: 10px;
    padding: 34px 20px 8px;
    background: #fff;
    border-top: none;
  }
  #view-chat .composer textarea {
    height: calc(var(--desktop-composer-height, 140px) - 42px) !important;
    min-height: 28px;
    max-height: none;
    padding: 0;
    font-size: 14.5px;
    line-height: 1.55;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }
  #view-chat .composer textarea:focus { background: transparent; border: none; box-shadow: none; }
  #view-chat .composer #btn-sticker,
  #view-chat .composer #btn-image,
  #view-chat .composer #btn-gallery {
    position: absolute;
    top: 6px;
    height: 26px;
    width: 26px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #606670;
    font-size: 19px;
    line-height: 1;
    border-radius: 5px;
    border: none;
    background: none;
    cursor: pointer;
    transition: color .12s, background .12s;
  }
  #view-chat .composer #btn-sticker:hover,
  #view-chat .composer #btn-image:hover,
  #view-chat .composer #btn-gallery:hover {
    color: #12b7f5;
    background: #f0f3f6;
  }
  #view-chat .composer #btn-sticker { left: 18px; }
  #view-chat .composer #btn-image { left: 50px; }
  #view-chat .composer #btn-gallery { left: 82px; font-size: 13px; font-weight: 600; }
  #view-chat .composer #btn-send {
    min-width: 80px;
    height: 30px;
    padding: 0 16px;
    font-size: 13.5px;
    font-weight: 500;
    border-radius: 6px;
    margin-bottom: 0;
    align-self: flex-end;
  }
  #view-chat .pending { padding: 8px 20px; background: #fff; }
  #view-chat .transfer-feedback { padding: 7px 20px 8px; }
  #view-chat .quote-bar { margin: 0 20px 6px; }
  #view-chat .sticker-panel { position: absolute; right: 0; bottom: 0; left: 0; z-index: 15; box-shadow: 0 -12px 28px rgba(31, 35, 41, .1); }
}

@media (max-width: 899px) {
  #view-chat {
    position: fixed;
    inset: 0;
    z-index: 30;
    box-shadow: -10px 0 28px rgba(31, 35, 41, .12);
    transform: translateX(0);
    transition: transform .21s cubic-bezier(.2, .8, .2, 1), box-shadow .21s ease;
  }
  #view-chat.page-enter-right,
  #view-chat.page-leave-right {
    transform: translateX(100%);
    box-shadow: none;
  }
}

@media (max-width: 560px) {
  .topbar { padding-left: 8px; padding-right: 8px; }
  .topbar .actions { gap: 4px; }
  .topbar .actions button { padding: 5px 7px; }
  #btn-new-session { font-size: 0; }
  #btn-new-session::after { content: "＋"; font-size: 21px; line-height: 1; }
  .messages { padding: 18px 12px 10px; gap: 17px; }
  .msg-row { gap: 9px; }
  .msg-row .msg { max-width: calc(100vw - 88px); }
  .msg-avatar { width: 38px; height: 38px; }
  .bubble { padding: 9px 12px; font-size: 15px; line-height: 1.55; }
  .composer { gap: 5px; padding-left: 7px; padding-right: 7px; }
  .composer button.icon { padding: 5px 6px; }
  #btn-send { min-width: 56px; padding-left: 10px; padding-right: 10px; }
  .pending-editor { flex-wrap: wrap; }
  .pending-editor input[type="text"] { flex: 1 1 180px; }
  .upload-status { max-width: 100%; }
  .transfer-feedback { padding-left: 12px; padding-right: 12px; }
}

.gallery-link { color: #526850; font-size: 13px; text-decoration: none; padding: 7px 9px; border-radius: 7px; }
.gallery-link:hover { background: #edf1e9; }
.desktop-gallery-link { display: flex; justify-content: space-between; color: #61705e; padding: 9px 15px 12px; font-size: 12px; text-decoration: none; }
.desktop-gallery-link:hover { background: #e7ece3; }
