/* ⚠️ `[hidden]` 的 UA 样式 `display:none` 会被我们自己的 `.reply-bar{display:flex}`
   覆盖（同优先级，作者样式表赢过 UA 样式表）。这条一定要放在所有 display 规则之前，
   并且带 !important —— 否则回复栏和表情面板会永远显示着。
   这是本轮改动里唯一一处"看起来能用、其实一直露在外面"的坑。 */
[hidden] { display: none !important; }

/* 秘密基地 —— 样式。
   手机优先：小米/安卓上要像原生 App，所以去掉点击高亮、锁住缩放、用安全区变量。 */

:root {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --bg-soft: #1e222b;
  --line: #262b36;
  --text: #e8eaf0;
  --text-dim: #9aa3b2;
  --text-faint: #626b7b;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.14);
  --mine: #3d6ef5;
  --mine-text: #ffffff;
  --theirs: #232833;
  --danger: #e5534b;
  --ok: #3fb950;
  /*
   * 安全区。
   *
   * env(safe-area-inset-*) 只有 iOS Safari 和部分 Chrome 会填 ——
   * 安卓 WebView **恒为 0**。所以安卓壳会把导航栏高度算好，
   * 以 CSS 变量的形式注入（--safe-bottom-inset），这里优先用它。
   *
   * 顺序很重要：先写 var(...)，再写 env(...) 兜底，
   * 这样两边都能用，不会互相覆盖。
   */
  --safe-top: var(--safe-top-inset, env(safe-area-inset-top, 0px));
  --safe-bottom: var(--safe-bottom-inset, env(safe-area-inset-bottom, 0px));
  --keyboard: var(--keyboard-inset, 0px);
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  /* 100% 是旧写法，100dvh 会跟着"视口真实可见高度"变（键盘弹出时也是）。
     两行都写：不认 dvh 的老 WebView 用 100%，认的用 dvh。 */
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior: none;
}

body {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#root { height: 100%; height: 100dvh; }

button, input, textarea {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  outline: none;
}

button { cursor: pointer; }

/* ── 通用：视图切换 ───────────────────────────────────────────────────── */
.view { display: none; height: 100%; flex-direction: column; }
.view.active { display: flex; }

/* ── 登录 ─────────────────────────────────────────────────────────────── */
#login {
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 24px);
  background:
    radial-gradient(circle at 30% 18%, rgba(91, 140, 255, 0.18), transparent 42%),
    radial-gradient(circle at 76% 82%, rgba(140, 91, 255, 0.13), transparent 45%),
    var(--bg);
}

.login-box { width: 100%; max-width: 360px; }

.login-logo {
  text-align: center;
  font-size: 30px;
  font-weight: 650;
  letter-spacing: 6px;
  margin-bottom: 6px;
  background: linear-gradient(120deg, #7fa4ff, #b28dff 60%, #6fd3ff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.login-sub {
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
  margin-bottom: 34px;
  letter-spacing: 1px;
}

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 7px;
  letter-spacing: 0.5px;
}

.field input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  transition: border-color 0.15s, background 0.15s;
  font-size: 16px;
}

.field input:focus {
  border-color: var(--accent);
  background: var(--bg-soft);
}

/* 口令下面那行说明：比普通 hint 大一点，因为这句话很重要 */
.pass-hint {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 8px;
  line-height: 1.5;
}

.btn-primary {
  width: 100%;
  padding: 15px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 16px;
  margin-top: 8px;
  transition: opacity 0.15s, transform 0.1s;
}
.btn-primary:active { transform: scale(0.985); opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; }

/* 登录页的"当前地址"提示 */
.addr-hint {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.addr-title { font-size: 11.5px; color: var(--text-faint); margin-bottom: 9px; letter-spacing: 0.5px; }

.addr-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  margin-bottom: 7px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.addr-row:active { background: var(--bg-soft); }
.addr-row.best { border-color: rgba(63, 185, 80, 0.4); }
.addr-label { font-size: 10.5px; color: var(--text-faint); }
.addr-row.best .addr-label { color: #5fc77a; }
.addr-url {
  font-size: 11.5px;
  color: var(--text-dim);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.addr-empty { font-size: 12px; color: var(--text-faint); }

/* 记住我 */
.remember {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 4px 0 16px;
  font-size: 13.5px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.remember input {
  appearance: none;
  -webkit-appearance: none;
  width: 19px;
  height: 19px;
  border-radius: 6px;
  border: 1.5px solid var(--line);
  background: var(--bg-elev);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
  position: relative;
  margin: 0;
}
.remember input:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.remember input:checked::after {
  content: '✓';
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  line-height: 1;
}
.remember-hint { color: var(--text-faint); font-size: 12px; margin-left: auto; }

.login-error {
  margin-top: 14px;
  padding: 11px 14px;
  border-radius: 10px;
  background: rgba(229, 83, 75, 0.12);
  border: 1px solid rgba(229, 83, 75, 0.3);
  color: #ff9d97;
  font-size: 13px;
  display: none;
}
.login-error.show { display: block; }

/* ── 会话列表 ─────────────────────────────────────────────────────────── */
#list { background: var(--bg); }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(var(--safe-top) + 10px) 16px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 17, 21, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

.topbar h1 {
  font-size: 19px;
  font-weight: 620;
  margin: 0;
  flex: 1;
  letter-spacing: 1px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.icon-btn:active { background: var(--bg-soft); color: var(--text); }

.conn-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
  transition: background 0.3s;
}
.conn-dot.on { background: var(--ok); box-shadow: 0 0 8px rgba(63, 185, 80, 0.6); }
.conn-dot.off { background: var(--danger); }

.conv-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.conv-item {
  display: flex;
  gap: 13px;
  padding: 13px 16px;
  cursor: pointer;
  transition: background 0.12s;
  border-bottom: 1px solid rgba(38, 43, 54, 0.5);
}
.conv-item:active { background: var(--bg-elev); }

.avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2d3444, #1c212b);
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-dim);
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.bot { background: linear-gradient(135deg, #35507c, #2a3a5c); color: #a8c0f0; }

.conv-body { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 3px; }

.conv-row { display: flex; align-items: baseline; gap: 8px; }

.conv-name {
  font-weight: 560;
  font-size: 15.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.conv-time { font-size: 11.5px; color: var(--text-faint); flex-shrink: 0; }

.conv-tag {
  font-size: 10.5px;
  color: var(--text-faint);
  background: var(--bg-soft);
  padding: 1px 6px;
  border-radius: 6px;
  flex-shrink: 0;
}

.conv-preview {
  font-size: 13.5px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-preview.unread { color: var(--text-dim); }

.badge {
  min-width: 19px; height: 19px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  display: grid;
  place-items: center;
  padding: 0 6px;
  flex-shrink: 0;
}

.empty-state {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--text-faint);
  font-size: 14px;
  text-align: center;
  padding: 40px;
  line-height: 1.9;
}

/* ── 聊天 ─────────────────────────────────────────────────────────────── */
#chat { background: var(--bg); }

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--safe-top) + 8px) 12px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 17, 21, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  flex-shrink: 0;
  z-index: 10;
}

.chat-head .title { flex: 1; min-width: 0; }
.chat-head .title .n { font-size: 16.5px; font-weight: 600; display: block; }
.chat-head .title .s { font-size: 11.5px; color: var(--text-faint); display: block; margin-top: 1px; }

/* 消息区：倒序滚动容器 —— 手机上加载历史最稳的做法。
   column-reverse 让"贴底"变成自然状态，新消息进来不用手动 scrollTop。 */
.msg-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column-reverse;
  padding: 12px 14px;
  gap: 3px;
  overscroll-behavior: contain;
}

.msg-row {
  display: flex;
  gap: 9px;
  margin: 7px 0;
  animation: fadeUp 0.18s ease-out;
  max-width: 100%;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg-row.mine { flex-direction: row-reverse; }
.msg-row.grouped { margin-top: 1px; }

.msg-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--bg-soft);
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  flex-shrink: 0;
  align-self: flex-end;
  overflow: hidden;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg-row.grouped .msg-avatar { visibility: hidden; }

.msg-col { display: flex; flex-direction: column; gap: 3px; max-width: min(78%, 520px); min-width: 0; }
.msg-row.mine .msg-col { align-items: flex-end; }

.msg-sender {
  font-size: 11.5px;
  color: var(--text-faint);
  padding: 0 4px;
}

.bubble {
  padding: 9px 13px;
  border-radius: var(--radius);
  background: var(--theirs);
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.52;
  max-width: 100%;
}
.msg-row.mine .bubble { background: var(--mine); color: var(--mine-text); }

.bubble.tail-tl { border-top-left-radius: 6px; }
.bubble.tail-tr { border-top-right-radius: 6px; }

/* 图片 */
.bubble.img {
  padding: 3px;
  background: var(--bg-soft);
  overflow: hidden;
  line-height: 0;
}
.msg-row.mine .bubble.img { background: rgba(61, 110, 245, 0.35); }
.bubble.img img {
  display: block;
  max-width: 100%;
  max-height: 46vh;
  border-radius: 13px;
  cursor: zoom-in;
  object-fit: cover;
}
.bubble.img .cap {
  font-size: 14px;
  line-height: 1.45;
  padding: 7px 10px 5px;
  white-space: pre-wrap;
}

/* 语音 */
.bubble.voice {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 128px;
  cursor: pointer;
  padding: 11px 14px;
}
.voice-bars { display: flex; align-items: center; gap: 2.5px; height: 17px; }
.voice-bars i {
  width: 2.5px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.62;
  height: 6px;
}
.bubble.voice.playing .voice-bars i { animation: vbar 0.9s ease-in-out infinite; }
.bubble.voice.playing .voice-bars i:nth-child(2) { animation-delay: 0.1s; }
.bubble.voice.playing .voice-bars i:nth-child(3) { animation-delay: 0.2s; }
.bubble.voice.playing .voice-bars i:nth-child(4) { animation-delay: 0.3s; }
.bubble.voice.playing .voice-bars i:nth-child(5) { animation-delay: 0.4s; }
@keyframes vbar { 0%,100% { height: 5px; } 50% { height: 16px; } }
.voice-dur { font-size: 12.5px; opacity: 0.8; font-variant-numeric: tabular-nums; }
.voice-transcript {
  font-size: 12.5px;
  color: var(--text-faint);
  padding: 2px 4px 0;
  line-height: 1.45;
  max-width: 100%;
  overflow-wrap: anywhere;
}

/* 文件 */
.bubble.file { display: flex; align-items: center; gap: 10px; }
.file-meta { font-size: 13px; color: var(--text-dim); line-height: 1.35; }

/* 系统消息 */
.sys-msg {
  align-self: center;
  font-size: 12px;
  color: var(--text-faint);
  padding: 5px 12px;
  border-radius: 10px;
  background: rgba(30, 34, 43, 0.6);
  margin: 8px 0;
  max-width: 80%;
  text-align: center;
}

.msg-time {
  font-size: 10.5px;
  color: var(--text-faint);
  padding: 0 5px;
  font-variant-numeric: tabular-nums;
}

.day-divider {
  align-self: center;
  font-size: 11.5px;
  color: var(--text-faint);
  padding: 7px 0;
  margin: 6px 0;
}

/* ── 输入区 ───────────────────────────────────────────────────────────── */
.composer {
  border-top: 1px solid var(--line);
  background: var(--bg-elev);
  /*
   * 输入区：底下要给两样东西留位置
   *   --safe-bottom  系统导航栏高度（安卓壳注入；iOS 走 env 兜底）
   *   --keyboard     软键盘高度（安卓壳注入，键盘收起时是 0）
   *
   * 用 max() 而不是相加：键盘弹起来的时候已经罩住导航栏了，
   * 两个加起来会多出一条空白缝。max() 在 Android 7+ 的 WebView 都支持。
   */
  padding: 9px 12px calc(9px + max(var(--safe-bottom), var(--keyboard)));
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 9px;
}

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

.composer textarea {
  width: 100%;
  resize: none;
  padding: 10px 14px;
  border-radius: 20px;
  background: var(--bg-soft);
  border: 1px solid transparent;
  max-height: 132px;
  min-height: 40px;
  line-height: 1.45;
  font-size: 15.5px;
  transition: border-color 0.15s;
  display: block;
}
.composer textarea:focus { border-color: rgba(91, 140, 255, 0.45); }

.send-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: transform 0.1s, opacity 0.15s;
}
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled { opacity: 0.4; }

.composer .circle {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--text-dim);
  background: var(--bg-soft);
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.composer .circle:active { background: #2a2f3b; color: var(--text); }

/* 录音态 */
.rec-state {
  flex: 1;
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 20px;
  background: var(--bg-soft);
}
.rec-state.on { display: flex; }
.rec-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--danger);
  animation: recpulse 1.1s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes recpulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.35; transform: scale(0.82); } }
.rec-time { font-variant-numeric: tabular-nums; font-size: 15px; color: var(--text); }
.rec-hint { font-size: 12.5px; color: var(--text-faint); flex: 1; text-align: right; }

/* 上传进度条 */
.upload-bar {
  height: 2px;
  background: var(--line);
  position: relative;
  overflow: hidden;
  display: none;
}
.upload-bar.on { display: block; }
.upload-bar i {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 30%;
  background: var(--accent);
  animation: slide 1.1s ease-in-out infinite;
}
@keyframes slide { 0% { left: -30%; } 100% { left: 100%; } }

/* ── 头像（设置面板里那块） ───────────────────────────────────────────── */
.avatar-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.avatar-big {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
  /* 背景不写死：没有头像时由 JS 按 id 算一个颜色内联进来。
     写死渐变会把内联那个盖掉，表现就是"字有颜色、底色永远是深灰"。 */
  background: var(--bg-soft);
  display: grid;
  place-items: center;
  font-size: 26px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  transition: opacity 0.15s;
}
.avatar-big span {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  /* 颜色由 JS 按 id 算出来给（内联），背景也跟着走 */
}
.avatar-big:active { opacity: 0.8; }
.avatar-big.busy { opacity: 0.5; }
.avatar-big img { width: 100%; height: 100%; object-fit: cover; display: block; }

.avatar-big-edit {
  position: absolute;
  inset: auto 0 0 0;
  height: 24px;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.15s;
}
.avatar-big:hover .avatar-big-edit,
.avatar-big:active .avatar-big-edit { opacity: 1; }

.avatar-side { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.avatar-side .hint { margin-top: 0; }

/* 两个按钮并排，各自占一半；只有一个时也占一半，不会撑成一条大横条。 */
.avatar-btns { display: flex; gap: 8px; }
.avatar-btns > * { flex: 1; min-width: 0; }
.avatar-side .btn-ghost { padding: 9px 10px; font-size: 13.5px; white-space: nowrap; }

/* ── 图片查看器 ───────────────────────────────────────────────────────── */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.95);
  display: none;
  place-items: center;
  z-index: 100;
  padding: 20px;
}
.lightbox.on { display: grid; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ── 设置面板 ─────────────────────────────────────────────────────────── */
.settings {
  width: min(92vw, 400px);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.settings h2 { font-size: 17px; margin: 0 0 18px; font-weight: 620; }
.settings .field { margin-bottom: 15px; }
.settings .field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 11px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  font-size: 15px;
}
.settings .field input:focus { border-color: var(--accent); }
.settings .hint { font-size: 12px; color: var(--text-faint); margin-top: 7px; line-height: 1.55; }
.settings .row { display: flex; gap: 10px; margin-top: 12px; }
.settings .row > * { flex: 1; }
.btn-ghost {
  padding: 12px;
  border-radius: 11px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14.5px;
  transition: background 0.15s;
}
.btn-ghost:active { background: #2a2f3b; }
.btn-ghost.danger { color: #ff9d97; border-color: rgba(229, 83, 75, 0.3); }
.settings .btn-primary { margin-top: 0; padding: 12px; font-size: 15px; }

/* ── 新会话选择器 ─────────────────────────────────────────────────────── */
.pick-list { display: flex; flex-direction: column; gap: 6px; }

.pick-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.pick-row.on { border-color: var(--accent); background: var(--accent-soft); }
.pick-name { flex: 1; font-size: 15px; }
.pick-check {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 13px;
  color: transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.pick-row.on .pick-check { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Toast ────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 84px);
  transform: translateX(-50%) translateY(10px);
  background: rgba(45, 52, 66, 0.97);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 13.5px;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  max-width: 84vw;
  text-align: center;
  backdrop-filter: blur(8px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── 桌面适配 ─────────────────────────────────────────────────────────── */
/* 宽屏：左列表右聊天，两个视图同时在场。 */
@media (min-width: 860px) {
  #root { display: grid; grid-template-columns: 340px 1fr; height: 100%; min-height: 0; }
  #login { grid-column: 1 / -1; }

  /* grid 的子项默认 min-height:auto —— 会被内容撑开，导致列表整块滚出屏幕外
     （真机上表现为"左栏一片空白、只有一条竖线"）。这里锁死高度并把滚动交给内部列表。 */
  #list, #chat { min-height: 0; height: 100%; overflow: hidden; }

  #list { border-right: 1px solid var(--line); }
  #list.active, body.desktop #list { display: flex; }
  #chat.active, body.desktop #chat { display: flex; }
  body.desktop #login { display: none; }
  body.desktop .back-btn { display: none; }
  .msg-col { max-width: min(70%, 560px); }
}

.back-btn { display: grid; }

/* 滚动条（桌面） */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2b313d; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3a4250; }

/* 减少动效 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
/* ══════════════════════════════════════════════════════════════════════════
   IM 增强：长按菜单 / 引用回复 / 撤回 / 搜索 / 表情贴纸 / 在线状态
   ══════════════════════════════════════════════════════════════════════════ */

/* ── 底部弹出菜单 ─────────────────────────────────────────────────────── */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(6, 8, 12, 0.55);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0 0 calc(var(--safe-bottom) + 8px);
  animation: fadeIn 0.14s ease;
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
.sheet {
  width: 100%; max-width: 460px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  margin: 0 10px;
  animation: sheetUp 0.18s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes sheetUp { from { transform: translateY(18px); opacity: 0.6 } to { transform: none; opacity: 1 } }
.sheet-title { padding: 14px 18px 6px; font-size: 12.5px; color: var(--text-faint); }
.sheet-item {
  display: block; width: 100%;
  padding: 15px 18px;
  background: none; border: 0; border-top: 1px solid var(--line);
  color: var(--text); font-size: 15.5px; text-align: left;
  font-family: inherit;
}
.sheet-item:active { background: var(--bg-soft); }
.sheet-item.danger { color: var(--danger); }
.sheet-cancel { color: var(--text-dim); }
.sheet > .sheet-item:first-child { border-top: 0; }

/* ── 引用回复 ─────────────────────────────────────────────────────────── */
.quote {
  display: flex; flex-direction: column; gap: 1px;
  max-width: 100%;
  padding: 6px 10px;
  margin-bottom: 3px;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: rgba(91, 140, 255, 0.08);
  cursor: pointer;
}
.quote-name { font-size: 11.5px; color: var(--accent); font-weight: 600; }
.quote-text { font-size: 12.5px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-row.mine .quote { background: rgba(255, 255, 255, 0.07); border-left-color: rgba(255, 255, 255, 0.5); }
.msg-row.mine .quote-name { color: rgba(255, 255, 255, 0.85); }
.msg-row.mine .quote-text { color: rgba(255, 255, 255, 0.65); }

/* 引用跳转的高亮闪烁 */
.msg-row.flash { animation: flashRow 1.2s ease; border-radius: 12px; }
@keyframes flashRow {
  0%, 100% { background: transparent }
  20%, 60% { background: rgba(91, 140, 255, 0.14) }
}

/* ── 撤回 ─────────────────────────────────────────────────────────────── */
.bubble.revoked {
  background: transparent !important;
  border: 1px dashed var(--line);
  color: var(--text-faint) !important;
  font-size: 12.5px;
  padding: 6px 12px;
}

/* ── 贴纸消息 ─────────────────────────────────────────────────────────── */
.sticker {
  font-size: 56px; line-height: 1.1;
  padding: 2px 4px;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.35));
  user-select: none;
}

/* ── 回复栏 ───────────────────────────────────────────────────────────── */
.chat-footer { display: flex; flex-direction: column; }
.reply-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
}
.reply-bar-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; border-left: 3px solid var(--accent); padding-left: 9px; }
.reply-bar-name { font-size: 11.5px; color: var(--accent); font-weight: 600; }
.reply-bar-text { font-size: 12.5px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-bar-close {
  width: 26px; height: 26px; flex-shrink: 0;
  border-radius: 50%; border: 0;
  background: var(--bg-soft); color: var(--text-dim);
  font-size: 16px; line-height: 1;
}

/* ── 表情 / 贴纸面板 ──────────────────────────────────────────────────── */
.emoji-panel {
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
  max-height: 42vh;
  display: flex; flex-direction: column;
}
.panel-tabs { display: flex; gap: 4px; padding: 8px 12px 0; }
.panel-tab {
  padding: 6px 14px; border-radius: 9px 9px 0 0;
  border: 0; background: none;
  color: var(--text-faint); font-size: 13px; font-family: inherit;
}
.panel-tab.active { background: var(--bg-soft); color: var(--text); }
.panel-body { overflow-y: auto; padding: 6px 12px 12px; }
.emoji-group-name { font-size: 11px; color: var(--text-faint); margin: 8px 0 4px; letter-spacing: 0.4px; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 2px; }
.emoji-cell {
  aspect-ratio: 1; border: 0; background: none;
  font-size: 23px; line-height: 1;
  border-radius: 9px; padding: 0;
}
.emoji-cell:active { background: var(--bg-soft); }

.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; }
.sticker-cell {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 4px;
  background: var(--bg-soft); border: 0; border-radius: 13px;
  color: var(--text-dim); font-family: inherit;
}
.sticker-cell:active { background: var(--line); }
.sticker-glyph { font-size: 30px; line-height: 1.1; }
.sticker-label { font-size: 10.5px; }

.circle.active { background: var(--accent-soft); color: var(--accent); }

/* ── 在线状态 ─────────────────────────────────────────────────────────── */
.avatar { position: relative; }
.presence-dot {
  position: absolute; right: -1px; bottom: -1px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--ok);
  border: 2px solid var(--bg);
  box-shadow: 0 0 6px rgba(63, 185, 80, 0.5);
}
.chat-head .title .s.typing { color: var(--accent); }

/* ── 置顶 ─────────────────────────────────────────────────────────────── */
.conv-item.pinned { background: rgba(91, 140, 255, 0.045); }
.pin-mark { font-size: 10px; margin-right: 3px; opacity: 0.85; }
.conv-preview.typing { color: var(--accent); }

/* ── 搜索 ─────────────────────────────────────────────────────────────── */
.search-wrap {
  position: fixed; inset: 0; z-index: 92;
  background: var(--bg);
  display: flex; flex-direction: column;
  padding-top: var(--safe-top);
  animation: fadeIn 0.14s ease;
}
.search-head {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.search-input {
  flex: 1;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 9px 13px;
  color: var(--text); font-size: 15px; font-family: inherit;
  outline: none;
}
.search-input:focus { border-color: var(--accent); }
.search-results { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.search-hint { padding: 28px 18px; text-align: center; color: var(--text-faint); font-size: 13px; }
.search-row { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.search-row:active { background: var(--bg-elev); }
.search-row-top { display: flex; align-items: baseline; gap: 7px; margin-bottom: 3px; }
.search-row-name { font-size: 13px; font-weight: 600; color: var(--text); }
.search-row-conv { font-size: 11px; color: var(--text-faint); }
.search-row-time { font-size: 11px; color: var(--text-faint); margin-left: auto; }
.search-row-text { font-size: 13.5px; color: var(--text-dim); line-height: 1.45; word-break: break-word; }
.search-row-text mark { background: rgba(91, 140, 255, 0.32); color: var(--text); border-radius: 3px; padding: 0 1px; }

/* ── 录音电平 ─────────────────────────────────────────────────────────── */
.rec-state.on { --level: 0; }
.rec-state.on .rec-dot {
  transform: scale(calc(1 + var(--level, 0) * 0.9));
  opacity: calc(0.55 + var(--level, 0) * 0.45);
  transition: transform 60ms linear, opacity 60ms linear;
  box-shadow: 0 0 calc(4px + var(--level, 0) * 14px) rgba(229, 83, 75, 0.7);
}

/* ══════════════════════════════════════════════════════════════════════════
   头像裁剪：拖动选位置、滑块/滚轮/双指缩放
   ══════════════════════════════════════════════════════════════════════════ */
.crop-wrap {
  /* 必须高于 .lightbox（设置面板用，z-index:100），否则裁剪器会藏在面板后面；
     低于 .toast（200），提示才看得见。 */
  position: fixed; inset: 0; z-index: 150;
  background: #0b0d11;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px;
  padding: calc(var(--safe-top) + 18px) 16px calc(var(--safe-bottom) + 18px);
  animation: fadeIn 0.15s ease;
}
.crop-title { font-size: 17px; font-weight: 600; }
.crop-hint { font-size: 12.5px; color: var(--text-faint); margin-top: -8px; }

.crop-stage {
  display: grid; place-items: center;
  flex-shrink: 0;
  /* touch-action:none 是关键：不然手机上拖图片会变成滚动页面 */
  touch-action: none;
  cursor: grab;
  -webkit-user-select: none; user-select: none;
}
.crop-stage.dragging { cursor: grabbing; }

.crop-frame {
  position: relative;
  overflow: hidden;
  border-radius: 50%;
  background: #000;
  /* 圆环 + 四周压暗：框内亮、框外暗，一眼看出取的是什么范围 */
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.16),
    0 0 0 3px rgba(0, 0, 0, 0.5),
    0 12px 40px rgba(0, 0, 0, 0.6);
}
.crop-img {
  position: absolute; left: 0; top: 0;
  /* 页面里可能给 img 设了 max-width:100%，这里必须放开，否则图片会被缩小 */
  max-width: none; max-height: none;
  -webkit-user-drag: none;
  user-select: none;
  will-change: transform;
}

.crop-zoom-row {
  display: flex; align-items: center; gap: 10px;
  width: min(320px, 82vw);
  color: var(--text-faint); font-size: 15px;
}
.crop-zoom {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 4px; border-radius: 2px;
  background: #2a303c;
  outline: none;
}
.crop-zoom::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0b0d11;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
}
.crop-zoom::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); border: 2px solid #0b0d11;
}
.crop-zoom-icon { opacity: 0.7; }

.crop-actions {
  display: flex; gap: 10px;
  width: min(320px, 82vw);
  margin-top: 4px;
}
.crop-actions button { flex: 1; }
