/* ============================================================
   im-chat.css —— 统一聊天界面（微信风格，咨询师/倾听师端 + 用户端共用）
   设计原则：克制、大气、留白充足；底栏输入框占主导，次要功能收进「⊕ / ⋯」菜单
   ============================================================ */

/* ---------- 顶部对象栏（对方头像 + 名称 + 状态 + 更多） ---------- */
.im-bar {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--c-surface); border-bottom: 1px solid rgba(15,23,42,.07);
  flex-shrink: 0; min-height: 56px;
}
.im-back {
  flex: 0 0 auto; width: 32px; height: 34px; border: none; background: transparent;
  font-size: 28px; line-height: 1; color: var(--n-800); cursor: pointer; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; margin-left: -4px;
}
.im-back:active { background: var(--n-100); }
.im-peer { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.im-peer-avatar {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; overflow: hidden;
  background: #eceff5; display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.im-peer-avatar img { width: 100%; height: 100%; object-fit: cover; }
.im-peer-info { min-width: 0; }
.im-peer-name { font-size: 15px; font-weight: 700; color: var(--n-800); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.im-peer-sub { font-size: 12px; color: var(--n-400); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.im-timer {
  flex: 0 0 auto; display: flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  color: var(--s-amber-700); background: var(--s-amber-100); padding: 4px 10px; border-radius: 999px;
}
.im-timer .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--s-amber-500); animation: imPulse 1.4s infinite; }
@keyframes imPulse { 0%,100%{opacity:1} 50%{opacity:.35} }
.im-more {
  flex: 0 0 auto; width: 34px; height: 34px; border: none; background: transparent; border-radius: 8px;
  font-size: 22px; line-height: 1; color: var(--n-800); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.im-more:active { background: var(--n-100); }
.im-call-btn {
  flex: 0 0 auto; width: 36px; height: 36px; border: none; background: transparent; border-radius: 50%;
  font-size: 19px; line-height: 1; color: var(--n-800); cursor: pointer; display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent; transition: background .12s, transform .12s;
}
.im-call-btn:active { background: var(--n-100); transform: scale(.92); }
.im-call-btn.video { color: #5b4bd6; }
.im-call-btn.ai { background: linear-gradient(135deg, var(--brand-1), #6d5efc); color: var(--c-surface); box-shadow: 0 2px 8px rgba(16, 185, 129, .32); }
.im-more-menu {
  position: absolute; top: 54px; right: 10px; z-index: 30; min-width: 176px;
  background: var(--c-surface); border: 1px solid rgba(15,23,42,.08); border-radius: 14px; padding: 6px;
  box-shadow: 0 12px 32px rgba(15,23,42,.16); display: flex; flex-direction: column; gap: 2px;
  animation: imMenuIn .14s ease-out;
}
.im-more-menu[hidden] { display: none; }
@keyframes imMenuIn { from{opacity:0; transform: translateY(-6px)} to{opacity:1; transform:none} }
.im-mi {
  text-align: left; padding: 10px 12px; border: none; background: transparent; border-radius: 10px;
  font-size: 14px; color: var(--n-800); cursor: pointer; display: flex; align-items: center; gap: 8px;
}
.im-mi:hover { background: #f3f1ff; }
.im-mi.danger { color: var(--s-amber-700); }
.im-mi.ok { color: var(--s-green-700); }

/* ---------- 消息区 ---------- */
.im-box { flex: 1; overflow-y: auto; padding: 14px 12px 18px; display: flex; flex-direction: column; gap: 2px; background: #eef1f5; }
.im-day { align-self: center; font-size: 11px; color: var(--n-400); background: rgba(148,163,184,.22); padding: 3px 12px; border-radius: 999px; margin: 12px 0 8px; }
.im-row { max-width: 78%; margin-bottom: 14px; display: flex; gap: 8px; align-items: flex-start; }
.im-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.im-row.peer { align-self: flex-start; flex-direction: row; }
.im-avatar { flex: 0 0 auto; width: 38px; height: 38px; border-radius: 8px; overflow: hidden; background: #e3e7ef; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.im-avatar img { width: 100%; height: 100%; object-fit: cover; }
.im-body { display: flex; flex-direction: column; min-width: 0; max-width: 100%; }
.im-row.mine .im-body { align-items: flex-end; }
.im-bubble {
  position: relative; padding: 10px 13px; border-radius: 12px; font-size: 15px; line-height: 1.6;
  word-break: break-word; white-space: pre-wrap; box-shadow: 0 1px 1px rgba(15,23,42,.05);
}
.im-bubble.in { background: var(--c-surface); color: var(--n-800); border-top-left-radius: 3px; }
.im-bubble.in::before {
  content: ''; position: absolute; left: -5px; top: 13px; width: 0; height: 0;
  border: 6px solid transparent; border-right-color: var(--c-surface); border-left: 0; margin-top: -6px;
}
.im-bubble.out { background: linear-gradient(135deg, var(--brand-1), #6d5efc); color: var(--c-surface); border-top-right-radius: 3px; }
.im-bubble.out::before {
  content: ''; position: absolute; right: -5px; top: 13px; width: 0; height: 0;
  border: 6px solid transparent; border-left-color: #6d5efc; border-right: 0; margin-top: -6px;
}
.im-bubble.revoked { font-style: italic; color: var(--n-400); background: #e9edf3; box-shadow: none; }
.im-bubble.revoked::before { display: none; }
.im-img { max-width: 200px; border-radius: 10px; display: block; overflow: hidden; }
.im-img img { width: 100%; border-radius: 10px; display: block; }
.im-time { font-size: 10px; color: #9aa5b5; margin-top: 4px; padding: 0 2px; }
.im-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.im-revoke { font-size: 11px; color: #9aa5b5; text-decoration: underline; background: none; border: none; padding: 0; cursor: pointer; }
.im-sys { align-self: center; max-width: 90%; font-size: 11.5px; color: #7c8798; background: rgba(148,163,184,.18); padding: 6px 12px; border-radius: 10px; line-height: 1.6; text-align: center; margin: 8px 0; }
.im-call {
  align-self: center; max-width: 82%; display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-radius: 999px; background: rgba(148,163,184,.2); color: var(--n-600);
  font-size: 13px; cursor: pointer; margin: 6px 0; width: fit-content;
}
.im-call.mine { background: rgba(16,185,129,.18); color: #5b4bd6; }
.im-call.missed { color: var(--s-red-600); }
.im-call .mc-ico { font-size: 16px; }

/* ---------- 输入栏（⊕更多 / 输入框 / 表情 / 语音 / 发送） ---------- */
.im-input {
  position: relative; display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  flex-shrink: 0; background: var(--c-surface); border-top: 1px solid rgba(15,23,42,.07);
}
.im-voice-toggle {
  order: 1; width: 38px; height: 38px; border-radius: 50%; background: transparent; border: none; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 21px; cursor: pointer; padding: 0; color: var(--n-800);
  transition: background .12s; -webkit-tap-highlight-color: transparent;
}
.im-voice-toggle:active { background: var(--n-100); }
.im-voice-toggle.active { color: #5b4bd6; }
.im-more-btn {
  order: 4; width: 38px; height: 38px; border-radius: 50%; background: transparent; font-size: 24px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; border: none; cursor: pointer; padding: 0; color: #5b4bd6;
  transition: background .12s, transform .12s; -webkit-tap-highlight-color: transparent;
}
.im-more-btn:active { transform: scale(.92); background: #e9e7fb; }
.im-field {
  order: 2; flex: 1; min-width: 0; height: 46px; padding: 0 16px; border: 1px solid rgba(15,23,42,.12); border-radius: 23px;
  font-size: 16px; outline: none; background: #f7f8fa; font-family: inherit;
}
.im-field:focus { border-color: var(--brand-1); background: var(--c-surface); }
.im-input .ce-btn { order: 3; } /* 表情按钮由 chat-extras 注入，排在输入框之后 */
.im-voice-hold {
  order: 2; flex: 1; min-width: 0; height: 46px; border-radius: 23px; border: 1px solid rgba(15,23,42,.12);
  background: var(--n-100); font-size: 15px; color: var(--n-800); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px;
  -webkit-tap-highlight-color: transparent;
}
.im-voice-hold:active { background: #e9e7fb; }
.im-voice-hold[hidden] { display: none; }
.im-send {
  order: 5; padding: 0 18px; height: 38px; border: none; border-radius: 19px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--brand-1), #6d5efc); color: var(--c-surface); font-size: 14px; font-weight: 700;
}
.im-send:hover { opacity: .92; }
.im-send:disabled { opacity: .5; cursor: not-allowed; }
.im-send[hidden] { display: none; }

/* 移动端聊天输入区安全区（iPhone 全面屏：Home Indicator 不遮挡输入框与「⊕」菜单） */
@media (max-width: 899px) {
  .im-input { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .im-plus-menu { bottom: calc(56px + env(safe-area-inset-bottom)); }
}
.im-plus-menu {
  position: absolute; bottom: 56px; right: 8px; z-index: 20; min-width: 152px;
  background: var(--c-surface); border: 1px solid rgba(15,23,42,.08); border-radius: 14px; padding: 6px;
  box-shadow: 0 12px 32px rgba(15,23,42,.16); display: flex; flex-direction: column; gap: 2px;
  animation: imMenuIn .14s ease-out;
}
.im-plus-menu[hidden] { display: none; }
.im-pi { text-align: left; padding: 10px 12px; border: none; background: transparent; border-radius: 10px; font-size: 14px; color: var(--n-800); cursor: pointer; display: flex; align-items: center; gap: 8px; }
.im-pi:hover { background: #f3f1ff; }

/* ---------- 快捷语（横向小标签，可选） ---------- */
.im-quick { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px; flex-shrink: 0; background: var(--c-surface); border-top: 1px solid rgba(15,23,42,.05); }
.im-quick::-webkit-scrollbar { display: none; }
.im-quick button { flex-shrink: 0; border: 1px solid rgba(15,23,42,.1); background: #f7f8fa; color: #4b5563; font-size: 12.5px; padding: 7px 13px; border-radius: 999px; cursor: pointer; white-space: nowrap; font-family: inherit; }
.im-quick button:active { background: #ece9fb; }

/* ---------- 安全提示 ---------- */
.im-tip { margin: 8px 12px 0; font-size: 12px; color: var(--n-400); text-align: center; line-height: 1.6; background: #f7f8fa; border: 1px dashed rgba(15,23,42,.12); border-radius: 10px; padding: 8px 10px; }

/* ============================================================
   用户端：进入聊天后，弹窗转为「单页聊天界面」
   —— 隐藏咨询师详情/评价/套餐，聊天区 flex 占满，仅消息列表滚动
   ============================================================ */
.modal-mask:has(.chat-card.chat-active) { padding: 0; }
.modal-card.chat-card.chat-active {
  width: 100%; max-width: 680px; height: 100vh; max-height: 100vh;
  border-radius: 0; padding: 0; overflow: hidden; display: flex; flex-direction: column;
}
.chat-card.chat-active .consultant-info,
.chat-card.chat-active .ci-actions,
.chat-card.chat-active .consultant-reviews,
.chat-card.chat-active .consultant-packages,
.chat-card.chat-active .consult-start-area { display: none !important; }
.chat-card.chat-active .modal-head {
  flex-shrink: 0; justify-content: flex-end; padding: 12px 14px; margin-bottom: 0;
  border-bottom: 1px solid rgba(15,23,42,.07);
}
.chat-card.chat-active .modal-head h2 { display: none; }
.chat-card.chat-active .chat-area { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-card.chat-active .im-box { flex: 1; min-height: 0; }

/* ============================================================
   微信式聊天增强：撤回态 / 已读标记 / 长按菜单 / 正在输入
   ============================================================ */
.im-revoked { font-size: 12px; color: #98a2b3; padding: 2px 4px; line-height: 1.5; }
.im-read { font-style: normal; margin-left: 6px; color: #7c8aa5; }
.im-ctx-menu {
  position: fixed; z-index: 9999; min-width: 132px; background: var(--c-surface); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(15,23,42,.2); padding: 6px; display: none; -webkit-user-select: none; user-select: none;
}
.im-ctx-menu.show { display: block; animation: imCtxIn .12s ease; }
.im-ctx-menu button {
  display: flex; align-items: center; gap: 8px; width: 100%; border: none; background: transparent;
  padding: 10px 12px; font-size: 14px; color: var(--n-800); border-radius: 8px; cursor: pointer; text-align: left;
}
.im-ctx-menu button:hover, .im-ctx-menu button:active { background: #f2f4f8; }
.im-ctx-menu button.danger { color: var(--brand-rose); }
@keyframes imCtxIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.im-typing {
  display: none; align-items: center; gap: 6px; padding: 4px 16px; font-size: 12px; color: var(--n-400);
}
.im-typing.show { display: flex; }
.im-typing .dots { display: inline-flex; gap: 3px; }
.im-typing .dots i { width: 5px; height: 5px; border-radius: 50%; background: #b6bfd0; animation: imTyping 1.2s infinite ease-in-out; }
.im-typing .dots i:nth-child(2) { animation-delay: .2s; }
.im-typing .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes imTyping { 0%,60%,100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* ============================================================
   微信式增强：引用回复 / 新消息提示 / 历史翻页 / 图片灯箱
   咨询师 & 倾听师工作台、用户端聊天共用（两端视觉保持一致）
   ============================================================ */

/* 引用回复：气泡上方挂一条被引用摘要 */
.im-quote {
  max-width: 100%; margin-bottom: 4px; padding: 6px 10px; border-radius: 8px;
  background: rgba(15, 23, 42, .05); border-left: 2px solid #b6bfd0;
  font-size: 12px; line-height: 1.5; color: #6b7488;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.im-quote.mine { background: rgba(16, 185, 129, .08); border-left-color: var(--brand-4); color: #6d5fa8; }

/* 「↓ 新消息」浮动提示：用户正在翻历史时不打断他的滚动位置 */
.im-new-pill {
  position: absolute; right: 14px; bottom: 76px; z-index: 40;
  display: none; align-items: center; gap: 4px;
  padding: 7px 14px; border: none; border-radius: 999px;
  background: var(--v-600); color: var(--c-surface); font-size: 12.5px; font-weight: 700; font-family: inherit;
  box-shadow: 0 6px 18px rgba(16, 185, 129, .32); cursor: pointer;
}
.im-new-pill.show { display: inline-flex; animation: imPillIn .18s ease; }
.im-new-pill:active { transform: scale(.95); }
@keyframes imPillIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* 向上翻历史消息的加载态 */
.im-older-loading { padding: 10px 0 14px; text-align: center; font-size: 12px; color: var(--n-400); }

/* 图片灯箱：点图片放大，点任意处关闭 */
.im-preview {
  position: fixed; inset: 0; z-index: 10000; display: none;
  align-items: center; justify-content: center; background: rgba(15, 23, 42, .92);
  cursor: zoom-out; -webkit-tap-highlight-color: transparent;
}
.im-preview.show { display: flex; animation: imPrevIn .16s ease; }
.im-preview img { max-width: 92vw; max-height: 88vh; object-fit: contain; border-radius: 8px; }
@keyframes imPrevIn { from { opacity: 0; } to { opacity: 1; } }
