/* ============================================================ */
/* 好友消息 chat.css：从 style.css 拆出的独立样式模块                       */
/* ============================================================ */



/* ========== 好友 / 消息（v3.1.0） ========== */
.friend-list-overlay,
.friend-search-overlay,
.friend-chat-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 900;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 320ms cubic-bezier(.22,1,.36,1), visibility 0s linear 320ms;
  visibility: hidden;
}

.friend-list-overlay.open,
.friend-search-overlay.open,
.friend-chat-overlay.open {
  transform: translateX(0);
  visibility: visible;
  transition: transform 320ms cubic-bezier(.22,1,.36,1), visibility 0s;
}
.friend-list-header {
  display: flex;
  align-items: center;
  padding: 0 8px;
  height: 52px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}

.friend-list-back,
.friend-list-add {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
}

.friend-list-back svg,
.friend-list-add svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.friend-list-title {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: .05em;
}

.friend-list-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.friend-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-tertiary);
  font-size: 13px;
  line-height: 1.7;
}

.friend-section-title {
  padding: 14px 16px 6px;
  font-size: 11px;
  color: var(--text-tertiary);
  letter-spacing: .08em;
}

.friend-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  position: relative;
}

.friend-item:active { background: var(--accent-soft); }

.friend-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  font-size: 16px;
  color: var(--accent);
  font-weight: 500;
}

.friend-item-main { flex: 1; min-width: 0; }

.friend-item-name {
  font-size: 14.5px;
  color: var(--text);
  font-weight: 500;
  margin-bottom: 3px;
}

.friend-item-sub {
  font-size: 12px;
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.friend-item-id {
  font-size: 11px;
  color: var(--text-tertiary);
  font-family: monospace;
}

.friend-item-badge {
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  box-sizing: border-box;
}

.friend-item-actions { display: flex; gap: 8px; align-items: center; }

.friend-action-btn {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}

.friend-action-btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.friend-search-body { flex: 1; padding: 20px; overflow-y: auto; }

.friend-search-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 12px;
  line-height: 1.7;
}

.friend-search-input-row { display: flex; gap: 8px; margin-bottom: 20px; }

.friend-search-input {
  flex: 1;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.friend-search-input:focus { border-color: var(--accent); }

.friend-search-btn {
  padding: 0 18px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}

.friend-search-result { min-height: 80px; }

.friend-search-result .friend-item {
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 14px;
}

.friend-search-empty {
  text-align: center;
  padding: 30px 20px;
  color: var(--text-tertiary);
  font-size: 13px;
}

.friend-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg-row { display: flex; width: 100%; }

.chat-msg-row.me { justify-content: flex-end; }

.chat-msg {
  max-width: 72%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}

.chat-msg.them {
  background: var(--accent-soft);
  color: var(--text);
  border-top-left-radius: 4px;
}

.chat-msg.me {
  background: var(--accent);
  color: #fff;
  border-top-right-radius: 4px;
}

.chat-msg.recalled {
  background: transparent !important;
  color: var(--text-tertiary) !important;
  font-size: 12px;
  padding: 4px 0;
  max-width: 100%;
  text-align: center;
  width: 100%;
}

.friend-chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.friend-chat-input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  max-height: 100px;
  padding: 9px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  resize: none;
  line-height: 1.4;
  box-sizing: border-box;
}

.friend-chat-input:focus { border-color: var(--accent); }

.friend-chat-send {
  padding: 0 18px;
  border-radius: 20px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}

.friend-chat-send:disabled { opacity: .4; cursor: not-allowed; }

.friend-chat-menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 950;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.friend-chat-menu-overlay.open { display: flex; }

.friend-chat-menu {
  background: var(--bg);
  width: 100%;
  max-width: 460px;
  border-radius: 14px 14px 0 0;
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.friend-chat-menu-btn {
  padding: 15px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}

.friend-chat-menu-btn:last-child { border-bottom: none; }

.friend-chat-menu-btn.danger { color: var(--danger); }

.friend-chat-menu-btn.cancel {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 6px;
  border-radius: 0 0 14px 14px;
}


/* 修复 v3.1.0：好友页顶部状态栏遮挡 */
.friend-list-overlay .friend-list-header,
.friend-search-overlay .friend-list-header,
.friend-chat-overlay .friend-list-header {
  padding-top: env(safe-area-inset-top);
  height: calc(52px + env(safe-area-inset-top));
  box-sizing: border-box;
}

.friend-search-body {
  padding-top: 12px;
}


/* ============ v3.1.1 好友功能补充 ============ */

/* 顶部状态栏安全区：跟 App 内部 --safe-top 一致 */
.friend-list-overlay .friend-list-header,
.friend-search-overlay .friend-list-header,
.friend-chat-overlay .friend-list-header {
  padding-top: var(--safe-top, 0px);
  height: calc(52px + var(--safe-top, 0px));
  box-sizing: border-box;
}


/* 聊天页底部输入区安全区 */
.friend-chat-input-row {
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}


/* 好友头像容器：包住头像渲染输出，固定 40px 圆形 */
.friend-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.friend-avatar > div,
.friend-avatar > svg {
  width: 100% !important;
  height: 100% !important;
  display: block;
}


/* 聊天行：对方消息带头像 */
.chat-msg-row {
  display: flex;
  width: 100%;
  align-items: flex-start;
  gap: 8px;
}

.chat-msg-row.me { justify-content: flex-end; }

.chat-msg-row.them { justify-content: flex-start; }

.chat-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  margin-top: 2px;
}

.chat-msg-avatar > div,
.chat-msg-avatar > svg {
  width: 100% !important;
  height: 100% !important;
  display: block;
}


/* 消息状态：发送中 / 失败 */
.chat-msg.sending { opacity: 0.55; }

.chat-msg.failed {
  background: #E15A4A !important;
  color: #fff !important;
}


/* 漂浮 toast：屏幕正中，2 秒 */
.friend-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.92);
  background: rgba(30, 26, 22, 0.92);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.5;
  max-width: 78%;
  text-align: center;
  z-index: 99999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  font-family: inherit;
}

.friend-toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}


/* ============ v3.1.2 聊天页增强 ============ */

/* 时间分隔条 */
.chat-time-divider {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-tertiary);
  padding: 10px 0 6px;
  letter-spacing: .04em;
  user-select: none;
  -webkit-user-select: none;
}


/* 消息状态条（自己消息左侧） */
.chat-msg-status {
  width: 16px;
  height: 16px;
  margin-right: 6px;
  align-self: center;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  box-sizing: border-box;
}

.chat-msg-status.sending {
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: chatSpin 0.8s linear infinite;
}

.chat-msg-status.failed {
  background: #E15A4A;
  border-radius: 50%;
}


/* 气泡小尾巴 */
.chat-msg {
  position: relative;
}

.chat-msg.me::after {
  content: '';
  position: absolute;
  right: -4px;
  top: 10px;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 5px solid var(--accent);
}

.chat-msg.them::after {
  content: '';
  position: absolute;
  left: -4px;
  top: 10px;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-right: 5px solid var(--accent-soft);
}

.chat-msg.recalled::after { display: none; }


/* v3.1.6：引用小圆点已按用户要求删除 */

/* 跳转时短暂高亮 */
.chat-msg-row.quote-jump-hl {
  animation: quoteJumpHl 1.5s ease-out;
}


/* 引用条可点击手感 */
.chat-msg-quote { cursor: pointer; }


/* 跳到底部按钮 */
.friend-chat-jump-btn {
  position: absolute;
  right: 16px;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(0,0,0,.12);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 6;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .15s ease;
  padding: 0;
}

.friend-chat-jump-btn.show {
  opacity: 1;
  pointer-events: auto;
}

.friend-chat-jump-btn:active {
  transform: scale(.94);
}

.friend-chat-jump-btn svg {
  width: 20px;
  height: 20px;
  stroke: var(--accent);
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.friend-chat-jump-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  box-sizing: border-box;
}


/* 长按消息菜单：贴气泡上方横排（微信风格） */
.chat-msg-menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 951;
  background: transparent;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
}

.chat-msg-menu-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.chat-msg-menu {
  position: fixed;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  background: rgba(30, 26, 22, 0.92);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.28);
  white-space: nowrap;
}

.chat-msg-menu-btn {
  padding: 10px 16px;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  border-right: 1px solid rgba(255, 255, 255, 0.12);
  white-space: nowrap;
}

.chat-msg-menu-btn:last-of-type {
  border-right: none;
}

.chat-msg-menu-btn:active {
  background: rgba(255, 255, 255, 0.08);
}

.chat-msg-menu-btn.danger {
  color: #FF8070;
}

.chat-msg-menu-arrow {
  position: absolute;
  width: 0;
  height: 0;
  transform: translateX(-50%);
}

.chat-msg-menu-arrow.bottom {
  bottom: -6px;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid rgba(30, 26, 22, 0.92);
}

.chat-msg-menu-arrow.top {
  top: -6px;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid rgba(30, 26, 22, 0.92);
}


/* 自己消息带头像后的间距 */
.chat-msg-row.me .chat-msg-avatar {
  margin-left: 8px;
  margin-right: 0;
}

.chat-msg-row.them .chat-msg-avatar {
  margin-right: 8px;
  margin-left: 0;
}


.chat-msg-row.them .chat-msg-avatar {
  margin-right: 8px;
  margin-left: 0;
}

/* ============ v3.1.2 C+D 组：已读 + 引用 ============ */
/* ============ v3.1.2 C+D 组：已读 + 引用 ============ */
.chat-msg-status.read {
  color: var(--accent);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: -.02em;
  width: auto;
  padding: 0 2px;
  background: transparent;
}

.chat-msg-quote {
  padding: 4px 8px;
  margin-bottom: 4px;
  border-left: 2px solid currentColor;
  opacity: .75;
  font-size: 12px;
  line-height: 1.4;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.06);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  box-sizing: border-box;
}

.chat-msg.me .chat-msg-quote {
  background: rgba(255, 255, 255, 0.18);
}

.chat-msg-body {
  white-space: pre-wrap;
  word-break: break-word;
}

.friend-chat-reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--input-bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.friend-chat-reply-bar[hidden] { display: none; }

.friend-chat-reply-body {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.friend-chat-reply-name {
  color: var(--accent);
  font-weight: 500;
  margin-right: 4px;
}

.friend-chat-reply-text {
  color: var(--text-secondary);
}

.friend-chat-reply-cancel {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.friend-chat-reply-cancel:active { background: var(--border); color: var(--danger); }

/* ============ v3.1.4 聊天输入框 + 表情菜单 ============ */

/* 输入框：右侧三个按钮并排 */
.friend-chat-input-row {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  align-items: flex-end;
}


.friend-chat-input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  max-height: 100px;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  resize: none;
  line-height: 1.4;
  box-sizing: border-box;
}


.friend-chat-input:focus { border-color: var(--accent); }


/* 图标按钮：笑脸 / 加号 */
.friend-chat-icon-btn {
  position: relative;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  transition: color .15s ease,
              background .15s ease,
              transform .35s cubic-bezier(.34,1.3,.64,1);
}

/* v3.1.6：给图标 svg 显式声明 stroke / fill。
   否则 <line> 没有 stroke 就看不见（加号变空），
   <circle> 会吃浏览器默认的黑色 fill（笑脸变黑圆）。 */
.friend-chat-icon-btn svg {
  width: 20px;
  height: 20px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}


/* v3.1.6：猫耳相关代码已彻底移除，不再需要 */
/* 发送按钮 */
.friend-chat-send {
  padding: 0 18px;
  height: 40px;
  border-radius: 20px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  flex-shrink: 0;
  transition: opacity .2s ease;
}


.friend-chat-send:disabled {
  opacity: .35;
  cursor: not-allowed;
}


/* v3.1.6：+ / 发送 用 max-width + opacity + scale 做过渡（A 方案） */
.friend-chat-input-row #friendChatPlus {
  display: flex;
  max-width: 40px;
  opacity: 1;
  transform: scale(1);
  overflow: hidden;
  transition: max-width .22s cubic-bezier(.22,1,.36,1),
              opacity .22s ease,
              transform .22s cubic-bezier(.22,1,.36,1);
}

.friend-chat-input-row.mode-text #friendChatPlus {
  max-width: 0;
  opacity: 0;
  transform: scale(0.5);
  pointer-events: none;
}


/* 新增：专门对付 #friendChatPlus 的旋转，用 !important 压过上面的 scale */
.friend-chat-input-row #friendChatPlus.rotating {
  transform: scale(1) rotate(405deg) !important;
}


.friend-chat-input-row #friendChatSend {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 0;
  padding-left: 0;
  padding-right: 0;
  opacity: 0;
  transform: scale(0.5);
  pointer-events: none;
  overflow: hidden;
  white-space: nowrap;
  transition: max-width .22s cubic-bezier(.22,1,.36,1),
              padding .22s cubic-bezier(.22,1,.36,1),
              opacity .22s ease,
              transform .22s cubic-bezier(.22,1,.36,1);
}

.friend-chat-input-row.mode-text #friendChatSend {
  max-width: 100px;
  padding-left: 18px;
  padding-right: 18px;
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}


/* 表情 / 加号面板 */
.friend-chat-panel {
  flex-shrink: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  height: 0;
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
  transition: height .22s cubic-bezier(.22,1,.36,1);
}


.friend-chat-panel.open {
  height: 250px;
  overflow-y: auto;
}


/* 表情网格 3×4 */
.friend-chat-sticker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px 16px;
}


.friend-chat-sticker {
  aspect-ratio: 1;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  transition: background .12s ease;
}


.friend-chat-sticker:active {
  background: var(--list-hover);
}


.friend-chat-sticker img {
  width: 80%;
  height: 80%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}


/* ============ v3.1.4 撤回消息样式 ============ */

/* 撤回后：气泡消失，头像留在原地 */
.chat-msg-row .chat-msg.is-recalled {
  display: none !important;
}


/* 撤回后：状态条（已读/发送中）也不显示 */
.chat-msg-row:has(.chat-msg.is-recalled) .chat-msg-status {
  display: none !important;
}

/* 表情消息：没有气泡背景 */
.chat-msg.chat-msg-sticker {
  background: transparent !important;
  padding: 0 !important;
  border-radius: 0 !important;
  max-width: 40%;
}


.chat-msg.chat-msg-sticker::after {
  display: none;
}


.chat-msg.chat-msg-sticker .chat-sticker-img {
  width: 100%;
  max-width: 160px;
  height: auto;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}


.chat-msg.chat-msg-sticker .chat-msg-quote {
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.06);
}

/* ============ v3.1.4 消息页 / 通讯录 ============ */

/* 通讯录搜索框 */
.friend-contacts-search {
  display: flex;
  gap: 8px;
  padding: 10px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.friend-contacts-search .friend-search-input {
  flex: 1;
}


/* 折叠区标题 */
.friend-section-collapsible {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.friend-section-arrow {
  width: 14px;
  height: 14px;
  stroke: var(--text-tertiary);
  stroke-width: 1.6;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform .3s;
}

.friend-section-collapsible.open .friend-section-arrow {
  transform: rotate(180deg);
}

.friend-section-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .35s cubic-bezier(.22,1,.36,1);
  overflow: hidden;
}

.friend-section-body.open {
  grid-template-rows: 1fr;
}

.friend-section-body > .friend-section-inner {
  overflow: hidden;
  min-height: 0;
}


/* 字母分组头 */
.friend-letter-header {
  padding: 12px 16px 4px;
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: .06em;
  background: var(--bg);
}


/* 消息页空态 */
.friend-empty {
  padding: 60px 20px;
  text-align: center;
  font-size: 13px;
  color: var(--text-tertiary);
  line-height: 1.7;
}

/* ============ v3.1.5 图片 / 文件消息 ============ */

/* + 号面板里的入口 */
.friend-chat-plus-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  padding: 14px 4px;
  cursor: pointer;
  font-family: inherit;
  border-radius: 10px;
  transition: background .15s ease;
}

.friend-chat-plus-item:active:not(:disabled) {
  background: var(--list-hover);
}


/* 图片消息气泡：去掉背景和边框 */
.chat-msg.chat-msg-image-bubble {
  background: transparent !important;
  padding: 0 !important;
  border-radius: 10px !important;
  max-width: 62%;
  overflow: hidden;
}

.chat-msg.chat-msg-image-bubble::after {
  display: none;
}

.chat-msg-image {
  display: block;
  max-width: 100%;
  width: 200px;
  height: auto;
  max-height: 240px;
  border-radius: 10px;
  background: var(--input-bg);
  cursor: pointer;
  object-fit: cover;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}

.chat-msg-image-bubble .chat-msg-quote {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-secondary);
  margin: 0 0 4px 0;
}


/* 文件消息 */
.chat-msg.chat-msg-file-bubble {
  background: var(--input-bg) !important;
  padding: 10px 14px !important;
  border-radius: 12px !important;
  max-width: 78%;
}

.chat-msg.chat-msg-file-bubble::after {
  display: none;
}

.chat-msg-file {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.chat-msg-file > svg {
  width: 32px;
  height: 32px;
  stroke: var(--accent);
  stroke-width: 1.6;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.chat-msg-file-info {
  min-width: 0;
  flex: 1;
}

.chat-msg-file-name {
  font-size: 13.5px;
  color: var(--text);
  font-weight: 500;
  word-break: break-all;
  line-height: 1.4;
}

.chat-msg-file-size {
  font-size: 11.5px;
  color: var(--text-tertiary);
  margin-top: 2px;
}


/* 大图查看器 */
.chat-image-viewer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  padding: 20px;
  box-sizing: border-box;
}

.chat-image-viewer.open {
  opacity: 1;
  pointer-events: auto;
}

.chat-image-viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

/* ============ v3.1.6 最终修复：加号与笑脸统一旋转 ============ */

/* 1. 必须给图标按钮显式加上初始 transform: rotate(0deg)，否则某些浏览器不会触发过渡动画 */
.friend-chat-icon-btn {
  transform: rotate(0deg);
  transition: transform .35s cubic-bezier(.34,1.3,.64,1);
}


/* 2. 统一的旋转类，加号和笑脸加上这个类都会旋转 405 度（即转一圈停在 45 度角，正好把 + 变成 ×） */
.friend-chat-icon-btn.rotating {
  transform: rotate(405deg);
}

/* 最终修复：针对 #friendChatPlus 强制合并 scale 与旋转，穿透 ID 选择器的权重覆盖 */
.friend-chat-input-row #friendChatPlus.rotating {
  transform: scale(1) rotate(405deg) !important;
}

/* ============ 终极修复：输入框高度严格对齐 ============ */
.friend-chat-input {
  /* 千万不要用 height: 40px !important，否则 JS 无法撑高输入框 */
  height: auto; 
  min-height: 40px !important;
  max-height: 100px !important;
  padding: 9px 14px !important;
  line-height: 20px !important; /* 9 + 20 + 9 + 2(边框) = 40px */
  box-sizing: border-box !important;
  resize: none !important;
}

/* ============ v3.1.7 宠物赠送 ============ */

/* 卡片气泡：去掉默认气泡背景 */
.chat-msg.chat-msg-pet-gift-bubble {
  background: transparent !important;
  padding: 0 !important;
  border-radius: 14px !important;
  max-width: 72%;
  overflow: visible;
}

.chat-msg.chat-msg-pet-gift-bubble::after {
  display: none;
}

.chat-msg.chat-msg-pet-gift-bubble .chat-msg-quote {
  margin-bottom: 6px;
}

/* ============ v3.1.8 双人聊天统计 ·「你我」 ============ */
.chat-stats-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 970;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
}

.chat-stats-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.chat-stats-panel {
  width: 100%;
  max-width: 460px;
  max-height: 86vh;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform .28s cubic-bezier(.22,1,.36,1);
}

.chat-stats-overlay.open .chat-stats-panel {
  transform: translateY(0);
}

.chat-stats-panel::before {
  content: '';
  display: block;
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 0 auto 12px;
  flex-shrink: 0;
}

.chat-stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--divider);
}

.chat-stats-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: .04em;
}

.chat-stats-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-stats-close:active { background: var(--list-hover); }

.chat-stats-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-top: 16px;
}

.chat-stats-loading, .chat-stats-empty, .chat-stats-error {
  text-align: center;
  padding: 40px 20px;
  font-size: 13.5px;
  color: var(--text-tertiary);
}

.chat-stats-section {
  margin-bottom: 24px;
}

.chat-stats-section-title {
  font-size: 11.5px;
  color: var(--text-tertiary);
  letter-spacing: .08em;
  margin-bottom: 12px;
}


/* 话痨比例条 */
.chat-stats-vs-wrap {
  display: flex;
  height: 28px;
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 8px;
}

.chat-stats-vs-me {
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #fff;
  transition: width .4s ease;
}

.chat-stats-vs-friend {
  background: var(--input-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-secondary);
  transition: width .4s ease;
}

.chat-stats-vs-me .vs-val, .chat-stats-vs-friend .vs-val { font-weight: 600; font-size: 13px; }

.chat-stats-vs-sub {
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
}

.chat-stats-vs-sub strong { color: var(--accent); }


/* 类型分布条形图 */
.chat-stats-bars {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-stats-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-stats-bar-label { width: 36px; font-size: 12.5px; color: var(--text); flex-shrink: 0; }

.chat-stats-bar-track { flex: 1; height: 6px; border-radius: 3px; background: var(--divider); overflow: hidden; }

.chat-stats-bar-fill { height: 100%; border-radius: 3px; }

.chat-stats-bar-count { width: 32px; text-align: right; font-size: 12px; color: var(--text-tertiary); flex-shrink: 0; }


/* ============ v3.1.8 聊天统计 · 更新按钮与底部 ============ */
.chat-stats-header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-stats-refresh-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: color .15s ease;
}

.chat-stats-refresh-btn:active {
  background: var(--list-hover);
  color: var(--accent);
}

.chat-stats-refresh-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chat-stats-refresh-btn.rotating svg {
  animation: chatStatsSpin 0.8s linear infinite;
}

.chat-stats-footer {
  text-align: center;
  font-size: 11px;
  color: var(--text-tertiary);
  padding: 16px 0 8px;
  border-top: 1px dashed var(--divider);
  margin-top: 20px;
  letter-spacing: 0.02em;
}

/* ============ v3.1.8 你我 · 丰富版 UI ============ */
.chat-stats-hero {
  padding: 10px 0 24px;
  text-align: center;
}

.chat-stats-hero-row {
  display: flex;
  justify-content: space-around;
}

.chat-stats-hero-item .num {
  font-size: 38px;
  font-weight: 300;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 8px;
}

.chat-stats-hero-item .label {
  font-size: 12px;
  color: var(--text-tertiary);
}


/* 第一句话 */
.chat-stats-first-msgs {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-stats-first-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-stats-first-row.them { align-items: flex-start; }

.chat-stats-first-row.me { align-items: flex-end; }

.chat-stats-first-row .bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  max-width: 82%;
  word-break: break-word;
}

.chat-stats-first-row.them .bubble {
  background: var(--accent-soft);
  color: var(--text);
  border-top-left-radius: 4px;
}

.chat-stats-first-row.me .bubble {
  background: var(--accent);
  color: #fff;
  border-top-right-radius: 4px;
}

.chat-stats-first-row .time {
  font-size: 10px;
  color: var(--text-tertiary);
}


/* 字数对比 */
.chat-stats-words {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-tertiary);
  padding-bottom: 4px;
  margin-top: 8px;
}

.chat-stats-words strong {
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
}


/* 高光时刻小方块 */
.chat-stats-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.chat-stats-fact {
  background: var(--input-bg);
  padding: 14px;
  border-radius: 12px;
  text-align: center;
}

.chat-stats-fact .num {
  font-size: 24px;
  font-weight: 500;
  color: var(--accent);
  line-height: 1.1;
  margin-bottom: 6px;
}

.chat-stats-fact .lbl {
  font-size: 11px;
  color: var(--text-tertiary);
}


/* 最爱表情 */
.chat-stats-top-stickers {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.chat-stats-sticker-img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 8px;
  background: var(--input-bg);
  padding: 4px;
}


/* 月度趋势 */
.chat-stats-months {
  display: flex;
  align-items: flex-end;
  height: 100px;
  gap: 4px;
  padding-top: 10px;
}

.chat-stats-month-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 100%;
}

.chat-stats-month-bar {
  width: 100%;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: height .4s ease;
}

.chat-stats-month-label {
  font-size: 9px;
  color: var(--text-tertiary);
  margin-top: 6px;
  white-space: nowrap;
}

/* 品味交集与宠物羁绊的标签 */
.chat-stats-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-stats-tag {
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 12px;
}

.friend-chat-menu-overlay.open .share-trace-picker {
  transform: translateY(0);
}


/* ========== 聊天里的足迹卡片 ========== */
.chat-msg.chat-msg-trace-bubble {
  background: transparent !important;
  padding: 0 !important;
  border-radius: 0 !important;
  max-width: 75%;
  overflow: visible;
}

.chat-msg.chat-msg-trace-bubble::after { display: none; }

.tsd-header { display: flex; gap: 12px; margin-bottom: 16px; }

.tsd-avatar { width: 44px; height: 44px; border-radius: 50%; overflow: hidden; flex-shrink: 0; background: var(--accent-soft); }

.tsd-avatar img, .tsd-avatar svg { width: 100%; height: 100%; display: block; }

.tsd-info { flex: 1; }

.tsd-name { font-size: 15px; font-weight: 600; color: var(--text); }

.tsd-time { font-size: 12px; color: var(--text-tertiary); margin-top: 4px; }

.tsd-text { font-size: 15px; color: var(--text); line-height: 1.7; white-space: pre-wrap; margin-bottom: 12px; }

.tsd-images { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 12px; }

.tsd-img-item { aspect-ratio: 1; border-radius: 6px; overflow: hidden; background: var(--divider); cursor: pointer; }

.tsd-img-item img { width: 100%; height: 100%; object-fit: cover; display: block; }

.tsd-anchor { font-size: 13px; color: var(--accent); padding: 8px 12px; background: var(--accent-soft); border-radius: 8px; display: inline-block; cursor: pointer; margin-bottom: 24px; }

.tsd-divider { height: 1px; background: var(--divider); margin: 16px 0; }

.tsd-comment-list { display: flex; flex-direction: column; gap: 16px; }

.tsd-comment-item { display: flex; gap: 10px; }

.tsd-comment-avatar { width: 32px; height: 32px; border-radius: 50%; overflow: hidden; flex-shrink: 0; }

.tsd-comment-main { flex: 1; }

.tsd-comment-name { font-size: 13px; font-weight: 500; color: var(--accent); margin-bottom: 4px; }

.tsd-comment-text { font-size: 14px; color: var(--text); line-height: 1.5; word-break: break-word; }

.tsd-comment-replies { margin-top: 10px; background: var(--input-bg); padding: 8px 12px; border-radius: 8px; display: flex; flex-direction: column; gap: 8px; }

/* ===== v3.1.11 修复：详情页高度与评论样式 ===== */
/* 压缩顶部导航高度，适配刘海屏状态栏 */
.trace-share-detail-overlay .friend-list-header {
  height: calc(44px + var(--safe-top, 0px)) !important;
  padding-top: var(--safe-top, 0px) !important;
  box-sizing: border-box !important;
}

/* 强制标题居中 */
.trace-share-detail-overlay .friend-list-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: auto;
}

/* 去掉二级评论的竖线 */
.tsd-comment-children {
  margin-left: 48px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

/* ===== 抖音风格展开收起按钮 v2 ===== */
.tsd-comment-reply-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  margin-left: 48px;
  margin-top: 2px;
  margin-bottom: 8px;
  cursor: pointer;
  user-select: none;
}

.tsd-comment-reply-toggle .toggle-line {
  width: 16px;
  height: 1px;
  display: inline-block;
}

.tsd-comment-reply-toggle .toggle-arrow {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-block;
  margin-left: -2px;
}

/* 高度动画依赖 grid，绝对不会出现高度算错的问题 */
.tsd-comment-replies-collapse {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.tsd-comment-replies-collapse.open {
  grid-template-rows: 1fr;
}

.tsd-comment-replies-collapse > div {
  overflow: hidden;
  min-height: 0;
}
/* ===== 动态头像翻转补丁：放开父容器裁切，让 scale(1.35) 不被裁掉 =====
   .trace-comment-avatar 自己画的是圆形 SVG，父容器不需要再裁圆。
   父容器 overflow: hidden 会把放大到 1.35 倍的头像边缘切掉，
   看起来就像“只变了一下、没有放大”。 */
.friend-avatar,
.chat-msg-avatar,
.tsd-avatar,
.tsd-comment-avatar,
.plaza-feed-avatar,
.rank-avatar{
  overflow: visible;
}

/* 如果担心静态头像的方形内容露出来，可以只对含动态头像的容器放开：
   但 :has 在部分老 WebView 不支持，所以这里直接全部放开。
   静态头像本身也是圆形 SVG，放开后视觉不变。 */
