/* chat.css - 聊天面板(顶级) */

/* ★ v4.3.0-fix25dao: 引用回复预览条 */
.chat-reply-bar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-card, #f5f5f5); border: 1px solid var(--border, #e0e0e0);
  border-radius: 8px; padding: 8px 12px; margin: 8px 12px 0; font-size: 13px;
  color: var(--text-secondary, #555);
}
.chat-reply-bar-info { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-reply-bar-info b { color: var(--text-primary, #333); }
.chat-reply-bar-close {
  background: transparent; border: 0; cursor: pointer; padding: 0 4px;
  color: var(--text-tertiary, #888); font-size: 16px; line-height: 1;
}

/* ★ v4.3.0-fix25dao: 引用回复气泡 */
.chat-msg-reply-preview {
  background: rgba(0,0,0,0.05); border-left: 3px solid var(--brand, #0ea5e9);
  padding: 4px 8px; margin-bottom: 4px; border-radius: 4px;
  font-size: 12px; color: var(--text-secondary, #555);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-msg-row.self .chat-msg-reply-preview {
  background: rgba(255,255,255,0.2); border-left-color: rgba(255,255,255,0.6);
  color: rgba(255,255,255,0.85);
}
.chat-msg-reply-preview b { margin-right: 4px; }
.chat-msg-reply-preview .reply-quote { font-style: italic; }

/* ★ v4.3.0-fix25dao: @提醒高亮 */
.chat-msg-mention {
  background: rgba(14,165,233,0.15); padding: 1px 4px; border-radius: 3px;
  color: #0ea5e9; font-weight: 500;
}
.chat-msg-row.self .chat-msg-mention {
  background: rgba(255,255,255,0.25); color: #fff;
}

/* ★ v4.3.0-fix25dao: 长按菜单 reply 按钮 */
.chat-msg-actions [data-act=reply]::before { content: "↩ "; }
.chat-msg-actions [data-act=reply] { color: var(--brand, #0ea5e9); }

/* ★ v4.3.0-fix25dao: chat-panel.open 状态机完整 (CSS 选择器驱动内部显示) */
.chat-panel.open { z-index: 201; }
.chat-panel {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg-chat);
  display: flex; flex-direction: column;
  max-width: 720px; margin: 0 auto;
  animation: slideInRight var(--t-base) var(--ease);
}
@keyframes slideInRight { from { transform: translateX(100%); } to { transform: none; } }
.chat-panel.closing { animation: slideOutRight var(--t-base) var(--ease) forwards; }
@keyframes slideOutRight { to { transform: translateX(100%); } }

.chat-header {
  height: calc(var(--h-header) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  flex-shrink: 0;
  display: flex; align-items: center; gap: var(--sp-2);
  padding-left: var(--sp-2);
  padding-right: var(--sp-2);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  border-bottom: 1px solid var(--glass-border);
}
.chat-header-back { color: var(--text-2); }
.chat-header-main { flex: 1; min-width: 0; text-align: center; padding: 0 var(--sp-2); }
.chat-header-title {
  font-size: var(--fs-md); font-weight: var(--fw-semibold);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-header-subtitle {
  font-size: var(--fs-xs); color: var(--text-3);
  display: flex; align-items: center; justify-content: center; gap: 4px;
}
.chat-header-status-dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--success);
}
.chat-header-status-dot.offline { background: var(--text-4); }

.chat-messages {
  flex: 1; overflow-y: auto; padding: var(--sp-3) var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-1);
  -webkit-overflow-scrolling: touch;
}

/* 时间分隔:扁平化,移除两侧装饰横线,仅保留文字 */
.chat-time-divider {
  text-align: center; font-size: var(--fs-xs); color: var(--text-3);
  margin: var(--sp-2) 0; position: relative;
}

.chat-msg-row {
  display: flex; gap: var(--sp-2);
  align-items: flex-start;
  max-width: 85%;
  animation: msgIn var(--t-base) var(--ease);
  position: relative;
  /* ★ v4.3.0-fix20dao: flex + overflow:hidden 会让 Chrome height 坍 0; 这里不设 overflow */
}

/* ★ v4.3.0-fix24dao: 仿微信——同一人连续消息紧贴 */
.chat-msg-row.consecutive {
  margin-top: -6px;  /* 覆盖 gap, 紧贴 */
  gap: 0;
}
.chat-msg-row.consecutive .chat-msg-avatar {
  visibility: hidden;
}
.chat-msg-row .chat-msg-row-inner {
  display: flex; gap: var(--sp-2); align-items: flex-start;
  flex: 1; min-width: 0;
  transition: transform 0.25s ease;
  will-change: transform;
  touch-action: pan-y;
}
.chat-msg-row.swipe-open { z-index: 2; }
.chat-msg-row.swipe-open .chat-msg-row-inner { transform: translateX(-70px); }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.chat-msg-row.me { align-self: flex-end; flex-direction: row-reverse; }

.chat-msg-avatar { flex-shrink: 0; }

.chat-msg-bubble-wrap { display: flex; flex-direction: column; gap: 2px; max-width: 100%; position: relative; }
.chat-msg-row.me .chat-msg-bubble-wrap { align-items: flex-end; }

.chat-msg-sender {
  font-size: var(--fs-xs); color: var(--text-3);
  padding: 0 var(--sp-2);
}

.chat-msg-bubble {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  line-height: 1.5;
  word-wrap: break-word; word-break: break-word;
  position: relative;
  max-width: 100%;
  white-space: pre-wrap;
}
/* ★ 方向性气泡 (iMessage 风格)
   - 我方:右下角 4px(尾巴指向对方),其他三角 18px
   - 对方:左下角 4px(尾巴指向我),其他三角 18px
   - 视觉效果:一眼看出"谁说的"——靠形状而非颜色
*/
/* me 气泡:蓝底白字,右下角尖 */
.chat-msg-row.me .chat-msg-bubble {
  background: linear-gradient(135deg, var(--brand-500) 0%, var(--brand-600) 100%);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 1px 2px rgba(14, 165, 233, 0.12);
}
/* 其他气泡:白底深字,左下角尖 */
.chat-msg-row:not(.me) .chat-msg-bubble {
  background: var(--bg-card);
  color: var(--text-1);
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.chat-msg-bubble.revoked {
  background: transparent !important; color: var(--text-3) !important;
  font-style: italic; box-shadow: none;
  border: 1px dashed var(--border-2);
}
.chat-msg-edited {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  color: var(--text-3);
  font-weight: 400;
  opacity: 0.7;
  vertical-align: baseline;
}

.chat-msg-status {
  display: flex; align-items: center; gap: 2px;
  font-size: var(--fs-xs); color: var(--text-3);
  padding: 0 var(--sp-2);
}
.chat-msg-time {
  font-size: 10px;
  color: var(--text-3);
  opacity: 0.6;
  margin-top: 2px;
  padding: 0 var(--sp-1);
  font-weight: 400;
  letter-spacing: 0.2px;
}
.chat-msg-row.me .chat-msg-time { text-align: right; }
.chat-msg-status .read { color: var(--brand-500); }

/* ★ v4.1 状态四态 (发送中/已送达/已读/失败) */
/* meta 容器: 水平排列时间+状态图标 */
.chat-msg-meta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  padding: 0 var(--sp-1);
}
.chat-msg-row.me .chat-msg-meta { justify-content: flex-end; }
.chat-msg-status {
  font-size: 11px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}
.chat-msg-status.sending {
  color: var(--text-3);
  animation: chat-msg-sending-spin 1.2s linear infinite;
  display: inline-block;
}
@keyframes chat-msg-sending-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.chat-msg-status.sent {
  color: var(--text-3);
  opacity: 0.5;
}
.chat-msg-status.delivered {
  color: var(--text-3);
  opacity: 0.8;
}
.chat-msg-status.read {
  color: var(--brand-500);
  font-weight: 600;
}
.chat-msg-status.failed {
  color: #e11d48;
  cursor: pointer;
}
.chat-msg-status.failed:hover {
  opacity: 0.7;
}

/* ★ v4.1 对方正在输入... 状态 */
.chat-typing-indicator {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 4px 16px;
  font-size: 12px;
  color: var(--text-3);
  opacity: 0;
  transition: opacity 0.2s ease;
  user-select: none;
}
.chat-typing-indicator.visible {
  display: flex;
  opacity: 1;
}
.chat-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.chat-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  animation: chat-typing-bounce 1.2s ease-in-out infinite;
  opacity: 0.5;
}
.chat-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
/* ★ v4.3.0-detail-pass: header 内的 typing 点(更小) */
.chat-typing-dots-inline {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-right: 4px;
}
.chat-typing-dots-inline span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--brand-500);
  animation: chat-typing-bounce 1.2s ease-in-out infinite;
  opacity: 0.6;
}
.chat-typing-dots-inline span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dots-inline span:nth-child(3) { animation-delay: 0.4s; }
.chat-header-typing {
  display: inline-flex;
  align-items: center;
  font-size: var(--fs-xs);
  color: var(--brand-500);
  font-weight: 500;
}
/* ★ v4.3.0-fix21dao: [hidden] 属性被 display:inline-flex 覆盖导致 typing 显示冲突; 加 !important 兑底 */
.chat-header-typing[hidden] { display: none !important; }
@keyframes chat-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* 消息操作菜单:纯白底 + 细边框,无阴影 */
.chat-msg-actions {
  position: absolute; top: -32px; right: 0;
  display: none; gap: 4px;
  background: var(--bg-card); border: 1px solid var(--border-1);
  border-radius: var(--r-md);
  padding: 2px;
}
.chat-msg-row:hover .chat-msg-actions,
.chat-msg-row.show-actions .chat-msg-actions { display: flex; }
.chat-msg-action-btn {
  width: 28px; height: 28px; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-sm); color: var(--text-2);
  background: transparent;
}
.chat-msg-action-btn:hover { background: var(--gray-100); }
.chat-msg-action-btn.danger { color: var(--danger); }

/* ===== 媒体消息气泡(图片/语音/文件/视频) ===== */

/* 容器:所有媒体气泡去掉默认 padding(各子组件自带) */
.chat-msg-bubble.bubble-image,
.chat-msg-bubble.bubble-voice,
.chat-msg-bubble.bubble-file,
.chat-msg-bubble.bubble-video {
  padding: 0;
  background: transparent !important;
  box-shadow: none;
  overflow: hidden;
  max-width: 280px;
  min-width: 80px;
}

/* ===== 图片 ===== */
.chat-msg-image {
  display: block;
  max-width: 240px;
  max-height: 240px;
  width: auto;
  height: auto;
  border-radius: var(--r-md);
  cursor: zoom-in;
  background: var(--gray-100);
  object-fit: cover;
  transition: opacity var(--t-fast) var(--ease);
}
.chat-msg-image:hover { opacity: 0.92; }
/* ★ v4.3.0-detail-pass: 图片加载失败占位 */
.chat-msg-image-error {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 180px;
  height: 120px;
  background: var(--gray-100);
  color: var(--text-4);
  font-size: var(--fs-sm);
  border: 1px dashed var(--gray-300);
  cursor: default;
}
.chat-msg-image.loading {
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  min-width: 160px; min-height: 160px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ===== 语音 ===== */
.chat-msg-voice {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 10px var(--sp-3);
  min-width: 140px;
  cursor: pointer;
  user-select: none;
  border-radius: var(--r-md);
  background: var(--gray-100);
  transition: background var(--t-fast) var(--ease);
}
.chat-msg-row.me .chat-msg-voice { background: rgba(255, 255, 255, 0.18); }
.chat-msg-voice:hover { background: var(--gray-200); }
.chat-msg-row.me .chat-msg-voice:hover { background: rgba(255, 255, 255, 0.28); }
.voice-play-btn {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--brand-500); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; flex-shrink: 0;
  transition: all var(--t-fast) var(--ease);
}
.chat-msg-row.me .voice-play-btn { background: #fff; color: var(--brand-500); }
.voice-bars {
  display: flex; gap: 2px; align-items: center; height: 18px; flex: 1;
}
.voice-bars span {
  display: block; width: 2px; background: var(--text-3);
  border-radius: 1px;
  animation: voiceIdle 1.5s ease-in-out infinite;
}
.chat-msg-row.me .voice-bars span { background: rgba(255, 255, 255, 0.85); }
.voice-bars span:nth-child(1) { height: 6px; animation-delay: 0s; }
.voice-bars span:nth-child(2) { height: 12px; animation-delay: 0.2s; }
.voice-bars span:nth-child(3) { height: 18px; animation-delay: 0.4s; }
.voice-bars span:nth-child(4) { height: 14px; animation-delay: 0.6s; }
.voice-bars span:nth-child(5) { height: 8px; animation-delay: 0.8s; }
@keyframes voiceIdle {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1); }
}
.chat-msg-voice.playing .voice-bars span { animation: voicePlay 0.6s ease-in-out infinite; }
@keyframes voicePlay {
  0%, 100% { transform: scaleY(0.3); }
  50% { transform: scaleY(1.2); }
}
.voice-duration {
  font-size: var(--fs-xs); color: var(--text-3); flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.chat-msg-row.me .voice-duration { color: rgba(255, 255, 255, 0.85); }

/* ===== 文件 ===== */
.chat-msg-file {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3);
  min-width: 200px; max-width: 260px;
  background: var(--gray-100);
  border-radius: var(--r-md);
  text-decoration: none;
  color: inherit;
  transition: background var(--t-fast) var(--ease);
}
.chat-msg-row.me .chat-msg-file { background: rgba(255, 255, 255, 0.18); }
.chat-msg-file:hover { background: var(--gray-200); }
.chat-msg-row.me .chat-msg-file:hover { background: rgba(255, 255, 255, 0.28); }
.file-icon {
  width: 40px; height: 40px; border-radius: var(--r-sm);
  background: var(--brand-500); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.chat-msg-row.me .file-icon { background: #fff; color: var(--brand-500); }
.file-info { flex: 1; min-width: 0; }
.file-name {
  font-size: var(--fs-sm); font-weight: var(--fw-medium);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 180px;
}
.file-size {
  font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px;
}
.chat-msg-row.me .file-size { color: rgba(255, 255, 255, 0.7); }

/* ===== 视频 ===== */
.chat-msg-video {
  display: block;
  max-width: 260px; max-height: 240px;
  width: 100%; height: auto;
  border-radius: var(--r-md);
  background: #000;
  cursor: pointer;
}

/* ===== Lightbox 全屏预览(图片/视频) ===== */
.media-lightbox {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0, 0, 0, 0.92);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn var(--t-base) var(--ease);
  touch-action: none;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.media-lightbox img,
.media-lightbox video {
  max-width: 95vw; max-height: 90vh;
  border-radius: var(--r-sm);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
.media-lightbox-close {
  position: absolute; top: 16px; right: 16px;
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.1); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  backdrop-filter: blur(10px);
}
.media-lightbox-toolbar {
  position: absolute; bottom: 32px; left: 50%; transform: translateX(-50%);
  display: flex; gap: var(--sp-2);
  background: rgba(0, 0, 0, 0.5);
  padding: var(--sp-2); border-radius: var(--r-lg);
  backdrop-filter: blur(10px);
}
.media-lightbox-btn {
  padding: 8px 16px; border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.1); color: #fff;
  font-size: var(--fs-sm);
  display: flex; align-items: center; gap: 6px;
}
.media-lightbox-btn:hover { background: rgba(255, 255, 255, 0.2); }

/* 撤回系统消息 */
.chat-msg-system {
  align-self: center;
  font-size: var(--fs-xs); color: var(--text-3);
  background: var(--gray-100); padding: 4px var(--sp-3);
  border-radius: var(--r-pill);
}

/* 底部输入栏 */
.chat-input-bar {
  display: flex; align-items: flex-end;
  padding: var(--sp-2) var(--sp-3) calc(var(--sp-2) + env(safe-area-inset-bottom, 0));
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur-strong)) saturate(var(--glass-saturate));
  -webkit-backdrop-filter: blur(var(--glass-blur-strong)) saturate(var(--glass-saturate));
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
}
.chat-input-tools { display: none; } /* ★ v4.1-fix7dao-v2: 保留作兼容空节点 */

/* ★ v4.1-fix7dao-v2: 行内工具按钮（emoji/+）与输入框在同一灰色背板上 */
.chat-input-tool-inline {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: transparent; flex-shrink: 0;
  transition: background var(--t-fast) var(--ease);
}
.chat-input-tool-inline:hover { background: var(--gray-200); }
.chat-input-tool-inline:active { transform: scale(0.92); }

.chat-input-wrap {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: var(--sp-1);
  background: var(--gray-100);
  border-radius: 22px;
  padding: 4px 6px 4px 8px;
  min-height: 36px;
  transition: all var(--t-fast) var(--ease);
}
.chat-input-wrap:focus-within { background: var(--brand-50); }
.chat-input {
  flex: 1; min-width: 0;
  background: transparent; border: none; outline: none;
  font-size: var(--fs-md); line-height: 1.4;
  resize: none; max-height: 120px;
  min-height: 24px;
  padding: 2px 0;
  font-family: inherit;
}
.chat-input-send {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-500); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-md); flex-shrink: 0;
  transition: all var(--t-fast) var(--ease);
}
.chat-input-send:hover { background: var(--brand-600); }
.chat-input-send:active { transform: scale(0.95); }
.chat-input-send:disabled { background: var(--gray-300); cursor: not-allowed; }

/* 表情/更多面板 */
.chat-extra-panel {
  display: none; flex-shrink: 0;
  background: var(--bg-card); border-top: 1px solid var(--border-1);
  padding: var(--sp-4); max-height: 240px; overflow-y: auto;
}
.chat-extra-panel.show { display: block; }
.emoji-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: var(--sp-2);
}
.emoji-btn {
  aspect-ratio: 1; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; transition: all var(--t-fast) var(--ease);
}
.emoji-btn:hover { background: var(--gray-100); }
.emoji-btn:active { transform: scale(0.9); }
