/* ===== 全局变量与重置 ===== */
:root {
  --wx-green: #07C160;
  --wx-green-dark: #06AD56;
  --wx-green-light: #95EC69;
  --bg-primary: #F5F5F5;
  --bg-secondary: #FFFFFF;
  --bg-hover: #EAEAEA;
  --bg-active: #D6D6D6;
  --bg-nav: #2E2E2E;
  --bg-sidebar: #EDEDED;
  --text-primary: #191919;
  --text-secondary: #888888;
  --text-tertiary: #B2B2B2;
  --border-color: #E5E5E5;
  --bubble-self: #95EC69;
  --bubble-other: #FFFFFF;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.18);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --nav-width: 60px;
  --sidebar-width: 300px;
  --transition: 0.2s ease;
  --overlay-bg: rgba(0,0,0,0.5);
  --msg-system-bg: rgba(0,0,0,0.04);
  --search-highlight: #FFE066;
  --recalled-color: #B2B2B2;
}

/* 深色模式 */
[data-theme="dark"] {
  --bg-primary: #1A1A1A;
  --bg-secondary: #2A2A2A;
  --bg-hover: #3A3A3A;
  --bg-active: #404040;
  --bg-nav: #1A1A1A;
  --bg-sidebar: #222222;
  --text-primary: #E8E8E8;
  --text-secondary: #999999;
  --text-tertiary: #666666;
  --border-color: #3A3A3A;
  --bubble-self: #07C160;
  --bubble-other: #333333;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.5);
  --overlay-bg: rgba(0,0,0,0.7);
  --msg-system-bg: rgba(255,255,255,0.06);
  --search-highlight: #FFD700;
  --recalled-color: #666666;
}

[data-theme="dark"] .msg-row.self .msg-bubble { color: #fff; }
[data-theme="dark"] .login-box { background: var(--bg-secondary); }
[data-theme="dark"] #nicknameInput { background: var(--bg-primary); color: var(--text-primary); }
[data-theme="dark"] .chat-list::-webkit-scrollbar-thumb,
[data-theme="dark"] .messages::-webkit-scrollbar-thumb,
[data-theme="dark"] .emoji-panel::-webkit-scrollbar-thumb { background: #444; }

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button, .chat-item, .nav-item, .tool-btn, input, textarea, .msg-bubble, .mobile-back {
  touch-action: manipulation;
  -webkit-touch-callout: none;
}
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-primary);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease, color 0.3s ease;
}
button { border: none; background: none; cursor: pointer; font-family: inherit; color: inherit; }
input, textarea { font-family: inherit; outline: none; border: none; }
svg { width: 22px; height: 22px; }

/* ===== 登录页 ===== */
.login-page {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #07C160 0%, #06AD56 50%, #05984C 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.login-box {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  width: 380px;
  max-width: 90vw;
  box-shadow: var(--shadow-md);
  text-align: center;
  animation: loginIn 0.4s ease;
}
@keyframes loginIn {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.login-logo {
  width: 72px;
  height: 72px;
  margin: 0 auto 20px;
  background: var(--wx-green);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.login-logo svg { width: 40px; height: 40px; }
.login-box h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-primary);
}
.login-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 28px;
}
#loginForm {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#nicknameInput {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 15px;
  transition: border-color var(--transition);
  background: var(--bg-primary);
  color: var(--text-primary);
}
#nicknameInput:focus {
  border-color: var(--wx-green);
  background: var(--bg-secondary);
}
#loginBtn {
  width: 100%;
  padding: 14px;
  background: var(--wx-green);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius-md);
  transition: all var(--transition);
}
#loginBtn:hover:not(:disabled) { background: var(--wx-green-dark); }
#loginBtn:disabled { opacity: 0.6; cursor: not-allowed; }
.login-error {
  color: #FA5151;
  font-size: 13px;
  margin-top: 12px;
  min-height: 18px;
}
.login-tips {
  margin-top: 24px;
  font-size: 12px;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* ===== 应用容器 ===== */
.app { display: flex; height: 100%; width: 100%; }

/* ===== 左侧导航栏 ===== */
.nav-bar {
  width: var(--nav-width);
  background: var(--bg-nav);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0;
  flex-shrink: 0;
}
.nav-avatar {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 30px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color var(--transition);
}
.nav-avatar:hover { border-color: var(--wx-green); }
.nav-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.nav-items { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.nav-item {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: #9A9A9A;
  position: relative;
  transition: all var(--transition);
}
.nav-item:hover { color: #FFFFFF; background: rgba(255,255,255,0.08); }
.nav-item.active { color: var(--wx-green); }
.nav-badge {
  position: absolute; top: 2px; right: 2px;
  min-width: 16px; height: 16px; padding: 0 4px;
  background: #FA5151; color: #FFFFFF; font-size: 10px;
  border-radius: 8px; display: flex; align-items: center; justify-content: center; font-weight: 500;
}
.nav-bottom { display: flex; flex-direction: column; align-items: center; gap: 8px; }

/* ===== 会话/用户列表面板 ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid var(--border-color);
  overflow: hidden;
}
.sidebar-header { padding: 12px 14px; flex-shrink: 0; }
.search-box {
  display: flex; align-items: center;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 6px 10px; gap: 6px;
}
.search-box svg { width: 16px; height: 16px; color: var(--text-tertiary); flex-shrink: 0; }
.search-box input { flex: 1; font-size: 13px; background: transparent; color: var(--text-primary); min-width: 0; }
.search-box input::placeholder { color: var(--text-tertiary); }

/* 群聊入口 */
.group-chat-item { border-bottom: 1px solid var(--border-color); }
.group-avatar {
  background: var(--wx-green);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.group-avatar svg { width: 24px; height: 24px; }
.online-section-title {
  padding: 10px 14px 6px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  flex-shrink: 0;
}

/* 用户/聊天列表 */
.chat-list { flex: 1; overflow-y: auto; overflow-x: hidden; }
.chat-list::-webkit-scrollbar { width: 6px; }
.chat-list::-webkit-scrollbar-thumb { background: #C9C9C9; border-radius: 3px; }
.chat-list::-webkit-scrollbar-track { background: transparent; }
.chat-item {
  display: flex; align-items: center;
  padding: 12px 14px;
  cursor: pointer;
  transition: background var(--transition);
  position: relative; gap: 12px;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-active); }
.chat-avatar {
  width: 42px; height: 42px;
  border-radius: var(--radius-sm);
  overflow: hidden; flex-shrink: 0; position: relative; background: #DDD;
}
.chat-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-item-content { flex: 1; min-width: 0; }
.chat-item-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.chat-item-name {
  font-size: 14px; font-weight: 500; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px;
}
.chat-item-time { font-size: 11px; color: var(--text-tertiary); flex-shrink: 0; margin-left: 8px; }
.chat-item-bottom { display: flex; align-items: center; justify-content: space-between; }
.chat-item-msg {
  font-size: 12px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0;
}
.chat-item-badge {
  min-width: 18px; height: 18px; padding: 0 5px;
  background: #FA5151; color: #fff; font-size: 11px;
  border-radius: 9px; display: flex; align-items: center; justify-content: center;
  margin-left: 8px; flex-shrink: 0; font-weight: 500;
}

/* 在线状态点 */
.user-online-dot {
  position: absolute; bottom: 0; right: 0;
  width: 12px; height: 12px;
  background: var(--wx-green);
  border: 2px solid var(--bg-sidebar);
  border-radius: 50%;
}

/* ===== 聊天主区域 ===== */
.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--bg-primary); min-width: 0; min-height: 0; position: relative; }
.chat-window { display: flex; flex-direction: column; height: 100%; }

/* ===== 可拖拽分隔条（始终可见、带抓手） ===== */
.resizer {
  flex-shrink: 0;
  position: relative;
  z-index: 30;
  transition: background 0.15s ease;
}
.resizer-x {
  width: 9px;
  cursor: col-resize;
  background: transparent;
}
.resizer-y {
  height: 9px;
  cursor: row-resize;
  background: transparent;
}
/* 居中抓手线 */
.resizer-x::before {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 2px; height: 26px;
  border-radius: 1px;
  background: var(--text-tertiary);
  opacity: 0.55;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.resizer-y::before {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 26px; height: 2px;
  border-radius: 1px;
  background: var(--text-tertiary);
  opacity: 0.55;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.resizer-x:hover,
.resizer-x.active {
  background: var(--wx-green);
}
.resizer-y:hover,
.resizer-y.active {
  background: var(--wx-green);
}
.resizer-x:hover::before,
.resizer-x.active::before,
.resizer-y:hover::before,
.resizer-y.active::before {
  background: #fff;
  opacity: 1;
}
body.resizing-x,
body.resizing-x * { cursor: col-resize !important; }
body.resizing-y,
body.resizing-y * { cursor: row-resize !important; }
body.resizing {
  user-select: none;
  -webkit-user-select: none;
}
.resizer-x { touch-action: none; }
.resizer-y { touch-action: none; }

.chat-header {
  height: 56px; padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}
/* 移动端返回按钮（桌面隐藏） */
.mobile-back {
  display: none;
  width: 36px; height: 36px;
  margin-right: 4px;
  align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: all var(--transition);
  flex-shrink: 0;
}
.mobile-back:hover { background: var(--bg-hover); color: var(--text-primary); }
.mobile-back svg { width: 22px; height: 22px; }
.chat-info { display: flex; align-items: baseline; gap: 10px; }
.chat-info h2 { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.chat-status { font-size: 12px; color: var(--wx-green); }
.chat-status.offline { color: var(--text-tertiary); }
.chat-actions { display: flex; align-items: center; gap: 4px; }
.chat-actions button {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); color: var(--text-secondary); transition: all var(--transition);
}
.chat-actions button:hover { background: var(--bg-hover); color: var(--text-primary); }
.chat-actions svg { width: 20px; height: 20px; }

/* 消息搜索栏 */
.msg-search-bar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 10px 20px;
  flex-shrink: 0;
  animation: slideDown 0.2s ease;
}
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.msg-search-input-wrap {
  display: flex; align-items: center;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  padding: 6px 10px; gap: 8px;
}
.msg-search-input-wrap svg { width: 16px; height: 16px; color: var(--text-tertiary); flex-shrink: 0; }
.msg-search-input-wrap input { flex: 1; font-size: 13px; background: transparent; color: var(--text-primary); }
.msg-search-input-wrap input::placeholder { color: var(--text-tertiary); }
.msg-search-input-wrap button { width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; color: var(--text-tertiary); border-radius: 4px; }
.msg-search-input-wrap button:hover { background: var(--bg-hover); color: var(--text-primary); }
.msg-search-input-wrap button svg { width: 16px; height: 16px; }
.msg-search-result {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  min-height: 16px;
}
.msg-search-result .result-item {
  padding: 6px 10px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.msg-search-result .result-item:hover { background: var(--bg-hover); }
.msg-search-result .result-item .result-sender { color: var(--wx-green); font-weight: 500; margin-right: 6px; }
.msg-search-result .result-item .result-time { color: var(--text-tertiary); float: right; }

/* 消息区域 */
.messages {
  flex: 1; overflow-y: auto;
  padding: 20px;
  display: flex; flex-direction: column; gap: 16px;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: #C9C9C9; border-radius: 3px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.msg-time { text-align: center; font-size: 11px; color: var(--text-tertiary); margin: 4px 0; }

/* 系统消息 */
.msg-system {
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
  padding: 4px 12px;
  background: var(--msg-system-bg);
  border-radius: var(--radius-sm);
  align-self: center;
  max-width: 80%;
}

/* 消息行 */
.msg-row { display: flex; gap: 10px; max-width: 70%; animation: msgIn 0.25s ease; position: relative; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.msg-row.self { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar { width: 36px; height: 36px; border-radius: var(--radius-sm); overflow: hidden; flex-shrink: 0; background: #DDD; }
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.msg-body { display: flex; flex-direction: column; min-width: 0; }
.msg-row.self .msg-body { align-items: flex-end; }
.msg-sender { font-size: 11px; color: var(--text-tertiary); margin-bottom: 4px; padding: 0 4px; }
.msg-bubble {
  position: relative;
  padding: 9px 13px;
  border-radius: var(--radius-md);
  font-size: 14px; line-height: 1.5;
  word-break: break-word; white-space: pre-wrap;
  max-width: 100%;
  box-shadow: var(--shadow-sm);
  cursor: default;
}
.msg-row.other .msg-bubble { background: var(--bubble-other); color: var(--text-primary); border-top-left-radius: 2px; }
.msg-row.other .msg-bubble::before {
  content: ''; position: absolute; left: -6px; top: 10px;
  width: 0; height: 0;
  border-top: 6px solid transparent; border-bottom: 6px solid transparent;
  border-right: 6px solid var(--bubble-other);
}
.msg-row.self .msg-bubble { background: var(--bubble-self); color: var(--text-primary); border-top-right-radius: 2px; }
.msg-row.self .msg-bubble::before {
  content: ''; position: absolute; right: -6px; top: 10px;
  width: 0; height: 0;
  border-top: 6px solid transparent; border-bottom: 6px solid transparent;
  border-left: 6px solid var(--bubble-self);
}

/* 图片消息 */
.msg-bubble.image-bubble {
  padding: 3px;
  background: transparent;
  box-shadow: none;
  max-width: 300px;
}
.msg-bubble.image-bubble::before { display: none; }
.msg-bubble.image-bubble img {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius-md);
  display: block;
  cursor: pointer;
  object-fit: contain;
  box-shadow: var(--shadow-sm);
}

/* 语音消息气泡 */
.msg-bubble.voice-bubble {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  min-width: 130px;
  max-width: 230px;
  cursor: pointer;
  user-select: none;
}
.voice-play-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(0,0,0,0.08);
  color: var(--text-primary);
  flex-shrink: 0;
  transition: all var(--transition);
}
.voice-play-btn svg { width: 18px; height: 18px; }
.voice-wave {
  position: relative;
  flex: 1;
  height: 18px;
  border-radius: 3px;
  background: repeating-linear-gradient(
    to right,
    var(--text-tertiary) 0 2px,
    transparent 2px 5px
  );
  background-size: 100% 100%;
  background-position: bottom;
  opacity: 0.45;
  overflow: hidden;
}
.msg-row.self .voice-wave { background-color: rgba(0,0,0,0.08); }
.voice-progress {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  background: rgba(7,193,96,0.25);
  transition: width 0.15s linear;
}
.msg-row.self .voice-progress { background: rgba(0,0,0,0.12); }
.voice-bubble.playing .voice-play-btn { background: rgba(7,193,96,0.15); }
.voice-duration {
  font-size: 13px;
  color: var(--text-primary);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* 已撤回消息 */
.msg-bubble.recalled {
  background: transparent !important;
  box-shadow: none !important;
  color: var(--recalled-color) !important;
  font-style: italic;
  font-size: 13px;
  padding: 4px 8px;
}
.msg-bubble.recalled::before { display: none !important; }

/* 搜索高亮 */
.search-highlight {
  background: var(--search-highlight);
  color: #000;
  padding: 0 2px;
  border-radius: 2px;
}

/* 私聊标记 */
.private-tag {
  display: inline-block;
  font-size: 10px;
  color: var(--wx-green);
  background: rgba(7,193,96,0.1);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
}

/* 正在输入 */
.typing-indicator { display: flex; align-items: center; gap: 4px; padding: 4px 0; }
.typing-indicator span {
  width: 7px; height: 7px; background: #B2B2B2; border-radius: 50%;
  animation: typingBounce 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ===== 输入区域 ===== */
.input-area { background: var(--bg-secondary); border-top: 1px solid var(--border-color); flex-shrink: 0; display: flex; flex-direction: column; }
.input-toolbar { display: flex; align-items: center; padding: 8px 16px; gap: 4px; }
.tool-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); color: var(--text-secondary); transition: all var(--transition);
}
.tool-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.tool-btn svg { width: 20px; height: 20px; }
.emoji-panel { border-top: 1px solid var(--border-color); padding: 12px 16px; max-height: 180px; overflow-y: auto; }
.emoji-panel::-webkit-scrollbar { width: 6px; }
.emoji-panel::-webkit-scrollbar-thumb { background: #C9C9C9; border-radius: 3px; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 4px; }
.emoji-item {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; border-radius: var(--radius-sm); cursor: pointer; transition: background var(--transition);
}
.emoji-item:hover { background: var(--bg-hover); }

/* 图片预览 */
.image-preview {
  border-top: 1px solid var(--border-color);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-primary);
}
.image-preview img {
  max-width: 80px;
  max-height: 80px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--border-color);
}
.image-preview-actions { display: flex; gap: 8px; margin-left: auto; }
.image-preview-cancel {
  padding: 6px 16px;
  background: var(--bg-hover);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: background var(--transition);
}
.image-preview-cancel:hover { background: var(--bg-active); }
.image-preview-send {
  padding: 6px 16px;
  background: var(--wx-green);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition);
}
.image-preview-send:hover { background: var(--wx-green-dark); }

/* 录音状态条 */
.voice-recording {
  border-top: 1px solid var(--border-color);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-primary);
}
.voice-rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #FA5151;
  animation: recBlink 1s infinite;
  flex-shrink: 0;
}
@keyframes recBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.voice-rec-time {
  font-size: 14px;
  font-weight: 600;
  color: #FA5151;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.voice-rec-hint {
  font-size: 13px;
  color: var(--text-secondary);
}

/* 语音预览条 */
.voice-preview {
  border-top: 1px solid var(--border-color);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-primary);
}
.voice-preview-play {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--wx-green);
  color: #fff;
  flex-shrink: 0;
  transition: background var(--transition);
}
.voice-preview-play:hover { background: var(--wx-green-dark); }
.voice-preview-play svg { width: 20px; height: 20px; }
.voice-preview-duration {
  font-size: 14px;
  font-weight: 600;
  color: var(--wx-green);
  flex-shrink: 0;
}
.voice-preview-label {
  font-size: 13px;
  color: var(--text-secondary);
  flex: 1;
}
.voice-preview-actions { display: flex; gap: 8px; flex-shrink: 0; }
.voice-preview-btn {
  padding: 6px 14px;
  background: var(--bg-hover);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: background var(--transition);
}
.voice-preview-btn:hover { background: var(--bg-active); }
.voice-preview-send {
  padding: 6px 18px;
  background: var(--wx-green);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition);
}
.voice-preview-send:hover { background: var(--wx-green-dark); }

/* 麦克风录音中状态 */
.tool-btn.recording {
  color: #FA5151;
  background: rgba(250,81,81,0.12);
}
.tool-btn.recording svg { animation: recPulse 1s infinite; }
@keyframes recPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.input-wrapper { display: flex; align-items: flex-end; padding: 0 16px 12px; gap: 12px; }
/* 手动拖拽调整输入框高度时，让输入框填满可用空间 */
.input-area.manual-resize .input-wrapper { flex: 1; min-height: 0; align-items: stretch; }
.input-area.manual-resize #messageInput { max-height: none; height: 100% !important; }
#messageInput {
  flex: 1; resize: none; background: transparent;
  font-size: 14px; line-height: 1.5; color: var(--text-primary);
  max-height: 120px; min-height: 24px; padding: 4px 0; overflow-y: auto;
}
#messageInput::placeholder { color: var(--text-tertiary); }
#messageInput::-webkit-scrollbar { width: 4px; }
#messageInput::-webkit-scrollbar-thumb { background: #C9C9C9; border-radius: 2px; }
.send-btn {
  padding: 6px 18px; background: var(--wx-green); color: #FFFFFF;
  font-size: 13px; border-radius: var(--radius-sm); transition: all var(--transition);
  flex-shrink: 0; font-weight: 500;
}
.send-btn:hover:not(:disabled) { background: var(--wx-green-dark); }
.send-btn:disabled { background: #C9C9C9; cursor: not-allowed; }

/* ===== 弹窗 ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
  max-height: 85vh;
  overflow: hidden;
  animation: modalIn 0.25s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}
.modal-header h3 { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.modal-close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: all var(--transition);
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal-close svg { width: 20px; height: 20px; }
.modal-body { padding: 20px; overflow-y: auto; max-height: calc(85vh - 60px); }

/* 个人资料弹窗 */
.profile-modal { width: 400px; }
.profile-avatar-section {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
.profile-avatar {
  width: 80px; height: 80px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 3px solid var(--wx-green);
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.profile-field { margin-bottom: 16px; }
.profile-field label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}
.profile-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.profile-input-row input {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-primary);
  transition: border-color var(--transition);
}
.profile-input-row input:focus { border-color: var(--wx-green); }
.profile-input-row input:disabled {
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: not-allowed;
}
.profile-edit-btn {
  padding: 8px 14px;
  background: var(--wx-green);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition);
  white-space: nowrap;
}
.profile-edit-btn:hover { background: var(--wx-green-dark); }
.profile-edit-btn.saving { background: var(--text-tertiary); }
.profile-error {
  color: #FA5151;
  font-size: 12px;
  margin-top: 6px;
  min-height: 16px;
}
.profile-value {
  font-size: 14px;
  color: var(--text-primary);
  padding: 8px 12px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  word-break: break-all;
}
.profile-divider {
  height: 1px;
  background: var(--border-color);
  margin: 20px 0;
}

/* 设置区域 */
.settings-section h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
}
.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color);
}
.setting-item:last-child { border-bottom: none; }
.setting-info { flex: 1; }
.setting-label {
  display: block;
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
}
.setting-desc {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* 开关 */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #CCC;
  border-radius: 24px;
  transition: 0.3s;
}
.slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.3s;
}
.switch input:checked + .slider { background: var(--wx-green); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* ===== 右键菜单 ===== */
.context-menu {
  position: fixed;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px 0;
  min-width: 140px;
  z-index: 3000;
  animation: contextIn 0.15s ease;
}
@keyframes contextIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.context-menu-item {
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}
.context-menu-item:hover { background: var(--bg-hover); }
.context-menu-item.disabled {
  color: var(--text-tertiary);
  cursor: not-allowed;
}
.context-menu-item.disabled:hover { background: transparent; }

/* ===== 图片查看器 ===== */
.image-viewer {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4000;
  animation: fadeIn 0.2s ease;
}
.image-viewer img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-md);
}
.image-viewer-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.1);
  border-radius: 50%;
  color: #fff;
  transition: background var(--transition);
}
.image-viewer-close:hover { background: rgba(255,255,255,0.2); }
.image-viewer-close svg { width: 24px; height: 24px; }

/* 连接状态提示 */
.connection-status {
  position: fixed; top: 0; left: 0; right: 0;
  background: #FA5151; color: #fff;
  text-align: center; padding: 8px;
  font-size: 13px; z-index: 2000;
  transform: translateY(-100%); transition: transform 0.3s ease;
}
.connection-status.show { transform: translateY(0); }

/* Toast */
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -50%) scale(0.9); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }

/* ===== 引用回复预览 ===== */
.reply-preview {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  gap: 10px;
}
.reply-preview-info {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.reply-preview-label {
  font-size: 11px;
  color: var(--wx-green);
  font-weight: 500;
}
.reply-preview-name {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
}
.reply-preview-text {
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.reply-preview-cancel {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  border-radius: 4px;
  flex-shrink: 0;
  transition: all var(--transition);
}
.reply-preview-cancel:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.reply-preview-cancel svg { width: 16px; height: 16px; }

/* ===== 消息中的引用块 ===== */
.msg-reply-quote {
  border-left: 3px solid var(--wx-green);
  padding: 4px 8px;
  margin-bottom: 6px;
  background: rgba(7,193,96,0.06);
  border-radius: 0 4px 4px 0;
  cursor: pointer;
  transition: background var(--transition);
}
.msg-reply-quote:hover {
  background: rgba(7,193,96,0.12);
}
.msg-row.self .msg-reply-quote {
  border-left-color: rgba(0,0,0,0.2);
  background: rgba(0,0,0,0.05);
}
.msg-reply-quote-sender {
  font-size: 11px;
  color: var(--wx-green);
  font-weight: 500;
  margin-bottom: 2px;
}
.msg-row.self .msg-reply-quote-sender {
  color: rgba(0,0,0,0.5);
}
.msg-reply-quote-text {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== 时间分隔线 ===== */
.msg-date-divider {
  text-align: center;
  margin: 8px 0;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  justify-content: center;
}
.msg-date-divider::before,
.msg-date-divider::after {
  content: '';
  flex: 1;
  max-width: 60px;
  height: 1px;
  background: var(--border-color);
}
.msg-date-divider span {
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg-primary);
  padding: 2px 10px;
  border-radius: 10px;
  white-space: nowrap;
}

/* ===== 已读状态 ===== */
.msg-read-status {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
  padding: 0 4px;
  text-align: right;
}
.msg-read-status.read {
  color: var(--wx-green);
}

/* ===== 会话置顶 ===== */
.chat-item.pinned {
  background: var(--bg-hover);
}
.chat-item.pinned::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--wx-green);
}

/* ===== 响应式 ===== */

/* 平板（769px - 1024px）：保持三栏布局，收窄侧栏与消息宽度 */
@media (min-width: 769px) and (max-width: 1024px) {
  :root { --sidebar-width: 260px; }
  .msg-row { max-width: 80%; }
  .messages { padding: 16px; }
}

/* 手机 / 小平板竖屏（≤768px）：底部导航 + 会话/聊天单面板切换 */
@media (max-width: 768px) {
  :root { --sidebar-width: 100%; }

  .app {
    flex-direction: column;
    height: 100%;
  }

  /* ---- 底部导航栏 ---- */
  .nav-bar {
    order: 3;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border-color);
    gap: 4px;
  }
  .nav-avatar { width: 40px; height: 40px; margin-bottom: 0; flex-shrink: 0; }
  .nav-items {
    flex: 1;
    flex-direction: row;
    justify-content: space-evenly;
    gap: 2px;
  }
  .nav-bottom { flex-direction: row; gap: 2px; }
  .nav-item { width: 44px; height: 44px; }

  /* ---- 会话列表：默认显示 ---- */
  .sidebar {
    order: 1;
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  /* 移动端单面板布局，隐藏拖拽分隔条 */
  .resizer-x,
  .resizer-y { display: none; }

  /* ---- 聊天区：进入会话后显示 ---- */
  .chat-area {
    order: 2;
    display: none;
    flex: 1 1 auto;
  }
  .app.show-chat .chat-area {
    display: flex;
    animation: panelIn 0.22s ease;
  }
  .app.show-chat .sidebar { display: none; }
  @keyframes panelIn {
    from { opacity: 0; transform: translateX(24px); }
    to { opacity: 1; transform: none; }
  }

  /* ---- 聊天头部：返回按钮 ---- */
  .mobile-back { display: flex; }
  .chat-header { padding: 0 10px 0 4px; }
  .chat-info h2 { font-size: 15px; }
  .chat-status { font-size: 11px; }

  /* ---- 触控目标与输入 ---- */
  .tool-btn { width: 38px; height: 38px; }
  .chat-actions button { width: 40px; height: 40px; }
  .msg-row { max-width: 88%; }
  .msg-bubble.image-bubble { max-width: 220px; }
  .messages { padding: 14px 12px; }
  .input-toolbar { padding: 6px 10px; }
  .input-wrapper { padding: 0 10px calc(8px + env(safe-area-inset-bottom)); }
  .send-btn { padding: 8px 18px; }
  .emoji-panel { max-height: 220px; }

  /* iOS 聚焦输入框不自动放大 */
  #messageInput,
  .search-box input,
  .msg-search-input-wrap input,
  #nicknameInput,
  .profile-input-row input { font-size: 16px; }

  /* 长按交互区：禁用文本选择与系统呼出，交给自定义菜单 */
  .msg-row,
  .chat-item,
  .group-chat-item,
  .msg-bubble img,
  .chat-avatar img,
  .msg-avatar img {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
  .msg-bubble { -webkit-user-select: none; user-select: none; }

  /* ---- 弹窗 ---- */
  .profile-modal { width: 92vw; }
  .modal-body { padding: 16px; }
  .login-box { padding: 36px 24px; }
  .login-box h1 { font-size: 22px; }
}

/* 小屏手机（≤400px）：进一步压缩留白 */
@media (max-width: 400px) {
  .msg-row { max-width: 92%; }
  .msg-avatar { width: 32px; height: 32px; }
  .chat-item { padding: 10px 12px; }
  .login-logo { width: 60px; height: 60px; border-radius: 16px; }
}

/* ===== 视频通话界面 ===== */
.chat-actions button:disabled { opacity: .35; cursor: not-allowed; }
.call-overlay {
  position: fixed; inset: 0; z-index: 3000;
  background: #141414;
  display: flex; align-items: center; justify-content: center;
}
.call-phase {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; color: #fff;
}
.call-avatar {
  width: 96px; height: 96px; border-radius: 50%; overflow: hidden;
  background: #333; display: flex; align-items: center; justify-content: center;
  font-size: 40px; color: #fff;
}
.call-avatar img { width: 100%; height: 100%; object-fit: cover; }
.call-title { font-size: 22px; font-weight: 600; color: #fff; }
.call-status { font-size: 14px; color: #aaa; }
.call-actions-row { display: flex; gap: 24px; margin-top: 12px; }
.call-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  width: 88px; height: 88px; border-radius: 50%; border: none; color: #fff; font-size: 13px;
  background: #333; cursor: pointer; transition: transform .12s, background .15s;
}
.call-btn svg { width: 32px; height: 32px; }
.call-btn:active { transform: scale(.94); }
.call-btn-danger { background: #FA5151; }
.call-btn-danger:hover { background: #e04545; }
.call-btn-accept { background: #07C160; }
.call-btn-accept:hover { background: #06AD56; }
.call-in-actions .call-btn { width: 100px; height: 100px; }

/* 通话中 */
#callActivePhase { background: #000; }
#remoteVideo { width: 100%; height: 100%; object-fit: cover; background: #000; }
#localVideo {
  position: absolute; right: 16px; bottom: 112px;
  width: 160px; height: 220px; object-fit: cover;
  border-radius: 12px; background: #222; z-index: 2;
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
}
.call-topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 3;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; color: #fff; font-size: 15px;
  background: linear-gradient(to bottom, rgba(0,0,0,.55), transparent);
}
.call-topbar #callTimer { font-variant-numeric: tabular-nums; opacity: .85; }
.call-controls {
  position: absolute; bottom: 28px; left: 0; right: 0; z-index: 3;
  display: flex; align-items: center; justify-content: center; gap: 30px;
}
.call-ctrl {
  width: 52px; height: 52px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(255,255,255,.18); color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .12s;
}
.call-ctrl svg { width: 26px; height: 26px; }
.call-ctrl:hover { background: rgba(255,255,255,.3); }
.call-ctrl:active { transform: scale(.92); }
.call-ctrl.off { background: rgba(255,255,255,.85); color: #111; }
.call-ctrl-hangup { background: #FA5151; }
.call-ctrl-hangup:hover { background: #e04545; }

@media (max-width: 768px) {
  #localVideo { width: 110px; height: 160px; right: 12px; bottom: 96px; }
  .call-avatar { width: 76px; height: 76px; font-size: 32px; }
  .call-btn { width: 74px; height: 74px; }
  .call-in-actions .call-btn { width: 86px; height: 86px; }
  .call-ctrl { width: 46px; height: 46px; }
  .call-controls { gap: 22px; }
}

/* 铃声开关 */
.call-ring-toggle {
  position: absolute; top: 18px; right: 18px; z-index: 4;
  width: 40px; height: 40px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(255,255,255,.14); color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.call-ring-toggle:hover { background: rgba(255,255,255,.3); }
.call-ring-toggle svg { width: 22px; height: 22px; }
.call-ring-toggle.off { background: rgba(255,255,255,.7); color: #111; }
