/*
 * ChatPanel 共享样式 — 给 /chat.html 全功能版 + 各子游戏（survival 等）
 * 共用。所有选择器都以 .chat-panel 容器作用域，避免污染宿主页面其他元素。
 *
 * 调用方差异通过 .chat-panel-bubbles / .chat-panel-flat 两套 modifier 切，
 * mount() 时根据 features.bubbles 自动加。
 */

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  height: 100%;
}

/* ── Header ───────────────────────────────────────────────────────────── */
.chat-panel .chat-header {
  padding: 12px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  background: rgba(255,255,255,0.04);
  min-height: 60px;
  position: relative;
}
.chat-panel .chat-header-back {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  min-height: 36px;
  min-width: 36px;
}
.chat-panel .chat-header-info { flex: 1; min-width: 0; }
.chat-panel .chat-header-name {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-panel .chat-header-sub {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}
.chat-panel .chat-header-actions { display: flex; gap: 8px; }
.chat-panel .header-action-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
  min-height: 36px;
}
.chat-panel .header-action-btn:hover { background: rgba(255,255,255,0.14); }
.chat-panel .header-action-btn.danger { color: #f87171; }
.chat-panel .header-action-btn.danger:hover { background: rgba(239,68,68,0.12); }

/* ── Voice 控件（mic/spk on/off + 通话人数）── */
.chat-panel .voice-mic-btn,
.chat-panel .voice-speaker-btn { font-size: 12px; }
.chat-panel .voice-mic-btn.on,
.chat-panel .voice-speaker-btn.on {
  background: rgba(34,197,94,0.18);
  border-color: rgba(34,197,94,0.35);
  color: #86efac;
}
.chat-panel .voice-mic-btn.off,
.chat-panel .voice-speaker-btn.off {
  background: rgba(239,68,68,0.10);
  border-color: rgba(239,68,68,0.25);
  color: #fca5a5;
}
.chat-panel .voice-members-info {
  align-self: center;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-left: 4px;
}

/* ── 搜索（header 内 + 结果浮层）── */
.chat-panel .chat-header-search {
  display: none;
  flex: 1;
  align-items: center;
  gap: 8px;
}
.chat-panel .chat-header-search.active { display: flex; }
.chat-panel .chat-header-search input {
  flex: 1;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--text-primary);
  font-size: 13px;
}
.chat-panel .chat-header-search input:focus {
  outline: none;
  border-color: rgba(147,197,253,0.4);
}
.chat-panel .search-results {
  position: absolute;
  top: 60px;
  left: 0; right: 0;
  max-height: 320px;
  overflow-y: auto;
  background: var(--surface-section, rgba(20,24,40,0.97));
  border-bottom: 1px solid rgba(255,255,255,0.08);
  z-index: 8;
  display: none;
}
.chat-panel .search-results.active { display: block; }
.chat-panel .search-result-item {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  cursor: pointer;
  font-size: 13px;
}
.chat-panel .search-result-item:hover { background: rgba(255,255,255,0.06); }
.chat-panel .search-result-item .sr-meta {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 3px;
}
.chat-panel .search-results-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── Messages-wrap：相对定位容器，给 jump-bottom 锚点 ── */
.chat-panel .messages-wrap {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-panel .messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.chat-panel .messages-area::-webkit-scrollbar { width: 5px; }
.chat-panel .messages-area::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }

.chat-panel .date-sep {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 6px;
  color: var(--text-muted);
  font-size: 11px;
}
.chat-panel .date-sep::before,
.chat-panel .date-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255,255,255,0.08);
}

/* ── Message bubble（默认气泡式样）── */
.chat-panel .msg-row {
  display: flex;
  gap: 8px;
  max-width: 75%;
  position: relative;
}
.chat-panel .msg-row.self {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.chat-panel .msg-row.other { align-self: flex-start; }

.chat-panel .msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(147,197,253,0.6), rgba(147,197,253,0.3));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  color: #fff;
  text-transform: uppercase;
  align-self: flex-end;
}

.chat-panel .msg-content { display: flex; flex-direction: column; gap: 2px; }
.chat-panel .msg-row.self .msg-content { align-items: flex-end; }

.chat-panel .msg-sender {
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 4px;
}
.chat-panel .msg-sender .msg-voice-tag {
  margin-left: 4px;
  font-size: 12px;
  line-height: 1;
}
.chat-panel .msg-sender .msg-voice-tag:empty { display: none; }

.chat-panel .msg-bubble {
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 420px;
}
.chat-panel.chat-panel-bubbles .msg-row.self .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-panel.chat-panel-bubbles .msg-row.other .msg-bubble {
  background: var(--surface-card, rgba(255,255,255,0.10));
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

/* flat 模式：紧凑、无气泡（survival / 嵌入式聊天用） */
.chat-panel.chat-panel-flat {
  font-size: 12px;
}
.chat-panel.chat-panel-flat .msg-row {
  max-width: 100%;
  margin-bottom: 2px;
}
.chat-panel.chat-panel-flat .msg-bubble {
  padding: 0;
  background: transparent !important;
  border-radius: 0;
  font-size: 12px;
  color: var(--text-primary);
  max-width: 100%;
}
.chat-panel.chat-panel-flat .msg-content { gap: 0; }
.chat-panel.chat-panel-flat .msg-sender {
  display: inline;
  font-size: 12px;
  font-weight: 600;
  padding: 0 6px 0 0;
}
.chat-panel.chat-panel-flat .msg-sender::after { content: ':'; }
.chat-panel.chat-panel-flat .msg-row {
  flex-direction: row !important;
  align-self: stretch !important;
}
.chat-panel.chat-panel-flat .msg-content {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0;
  align-items: baseline;
}
.chat-panel.chat-panel-flat .msg-time { display: none; }

.chat-panel .msg-time {
  font-size: 10px;
  color: var(--text-muted);
  padding: 0 4px;
}

.chat-panel .msg-loading,
.chat-panel .msg-error {
  align-self: center;
  padding: 12px;
  color: var(--text-muted);
  font-size: 13px;
}
.chat-panel .msg-error { color: #f87171; }

/* ── 引用预览（消息内嵌 + 输入框上方） ── */
.chat-panel .msg-reply-preview {
  font-size: 12px;
  color: var(--text-tertiary);
  background: rgba(255,255,255,0.06);
  border-left: 3px solid rgba(147,197,253,0.7);
  padding: 5px 8px;
  border-radius: 4px;
  margin: 0 0 4px 0;
  max-width: 380px;
  cursor: pointer;
  line-height: 1.4;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-panel .msg-reply-preview .reply-sender {
  color: var(--text-secondary, #cbd5e1);
  font-weight: 600;
  margin-right: 4px;
}
.chat-panel .msg-reply-preview.recalled .reply-snippet { font-style: italic; opacity: 0.7; }

/* ── 撤回 / 编辑标记 ── */
.chat-panel .msg-bubble.recalled {
  background: rgba(255,255,255,0.05) !important;
  color: var(--text-muted) !important;
  font-style: italic;
}
.chat-panel .msg-edited {
  font-size: 10px;
  color: var(--text-muted);
  margin-left: 4px;
  opacity: 0.85;
}

/* ── 消息悬浮菜单 ── */
.chat-panel .msg-actions {
  position: absolute;
  top: -10px;
  display: none;
  gap: 2px;
  background: var(--surface-section, rgba(20,24,40,0.95));
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 2px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
  z-index: 5;
}
.chat-panel .msg-row.self .msg-actions { right: 40px; }
.chat-panel .msg-row.other .msg-actions { left: 40px; }
.chat-panel .msg-row:hover .msg-actions,
.chat-panel .msg-row.menu-open .msg-actions { display: flex; }
.chat-panel .msg-actions button {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  min-height: 28px;
  min-width: 28px;
}
.chat-panel .msg-actions button:hover { background: rgba(255,255,255,0.10); }

/* ── 反应（reactions）── */
.chat-panel .msg-reactions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding: 0 4px;
  margin-top: 2px;
}
.chat-panel .msg-reaction {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: rgba(255,255,255,0.10);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.chat-panel .msg-reaction:hover { background: rgba(255,255,255,0.16); }
.chat-panel .msg-reaction.me-reacted {
  background: rgba(147,197,253,0.22);
  border-color: rgba(147,197,253,0.45);
}
.chat-panel .msg-reaction-count {
  font-size: 11px;
  color: var(--text-tertiary);
}

/* ── Emoji picker ── */
.chat-panel .emoji-picker {
  position: absolute;
  top: -42px;
  display: flex;
  gap: 2px;
  background: var(--surface-section, rgba(20,24,40,0.97));
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 999px;
  padding: 4px 6px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
  z-index: 10;
}
.chat-panel .msg-row.self .emoji-picker { right: 0; }
.chat-panel .msg-row.other .emoji-picker { left: 40px; }
.chat-panel .emoji-picker button {
  background: transparent;
  border: none;
  font-size: 18px;
  padding: 4px;
  cursor: pointer;
  border-radius: 50%;
  width: 32px; height: 32px;
  transition: transform 0.1s;
}
.chat-panel .emoji-picker button:hover { transform: scale(1.2); }

/* ── 引用回复条 ── */
.chat-panel .reply-bar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  margin: 0 16px 0;
  background: rgba(255,255,255,0.05);
  border-left: 3px solid rgba(147,197,253,0.6);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-tertiary);
}
.chat-panel .reply-bar.active { display: flex; }
.chat-panel .reply-bar .reply-bar-content {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-panel .reply-bar .reply-bar-cancel {
  background: none; border: none; color: var(--text-muted);
  font-size: 16px; cursor: pointer; padding: 2px 6px; border-radius: 4px;
}
.chat-panel .reply-bar .reply-bar-cancel:hover {
  background: rgba(255,255,255,0.10);
  color: var(--text-primary);
}

/* ── Typing ── */
.chat-panel .typing-indicator {
  display: none;
  padding: 4px 20px;
  color: var(--text-tertiary);
  font-size: 12px;
  font-style: italic;
  animation: cpTypingFade 0.3s ease;
}
.chat-panel .typing-indicator.active { display: block; }
@keyframes cpTypingFade { from { opacity: 0; } to { opacity: 1; } }

/* ── Jump-bottom ── */
.chat-panel .jump-bottom-btn {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 38px;
  height: 38px;
  background: rgba(20, 26, 48, 0.92);
  color: var(--text-primary, #fff);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 5;
  box-shadow: 0 6px 18px rgba(0,0,0,0.40);
  transition: transform 0.15s, background 0.15s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.chat-panel .jump-bottom-btn.active { display: inline-flex; }
.chat-panel .jump-bottom-btn:hover {
  transform: translateY(-2px);
  background: rgba(28, 34, 60, 0.97);
}
.chat-panel .jump-bottom-btn .jump-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #ef4444;
  color: #fff;
  border-radius: 999px;
  padding: 0 5px;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.45);
  border: 1.5px solid rgba(20, 26, 48, 0.92);
}

/* ── 输入区 ── */
.chat-panel .chat-input-area {
  padding: 12px 20px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
  background: rgba(0,0,0,0.18);
}
.chat-panel .chat-input-area textarea {
  flex: 1;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  line-height: 1.5;
  transition: border-color 0.2s;
}
.chat-panel .chat-input-area textarea:focus {
  outline: none;
  border-color: rgba(147,197,253,0.4);
}
.chat-panel .chat-input-area textarea::placeholder { color: var(--text-muted); }

.chat-panel .chat-input-area button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 0 18px;
  height: 44px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.chat-panel .chat-input-area button:hover { opacity: 0.88; }
.chat-panel .chat-input-area button:disabled { opacity: 0.4; cursor: not-allowed; }

/* compact 模式：input 更小 */
.chat-panel.chat-panel-flat .chat-input-area {
  padding: 8px;
  gap: 6px;
}
.chat-panel.chat-panel-flat .chat-input-area textarea {
  min-height: 32px;
  padding: 6px 8px;
  font-size: 12px;
}
.chat-panel.chat-panel-flat .chat-input-area button {
  height: 32px;
  padding: 0 12px;
  font-size: 12px;
}

/* 移动端：mobile back 按钮显示 */
@media (max-width: 600px) {
  .chat-panel .chat-header-back { display: inline-block; }
}

/* ── 主动呼叫按钮 / 响铃状态 ── */
.chat-panel .voice-call-btn {
  background: rgba(34,197,94,0.18);
  border-color: rgba(34,197,94,0.35);
  color: #86efac;
  font-size: 12px;
}
.chat-panel .voice-call-btn:hover { background: rgba(34,197,94,0.28); }
.chat-panel .voice-call-btn.ringing {
  background: rgba(239,68,68,0.18);
  border-color: rgba(239,68,68,0.35);
  color: #fca5a5;
  animation: cpRingingPulse 1.2s ease-in-out infinite;
}
@keyframes cpRingingPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.35); }
  50%      { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}
.chat-panel .voice-members-info.ringing { color: #fca5a5; }

/* ── 来电弹框（page-level，非 panel scoped）── */
.incoming-call-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  animation: cpCallFadeIn 0.18s ease;
}
.incoming-call-modal.active { display: flex; }
@keyframes cpCallFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.incoming-call-box {
  background: var(--surface-section, rgba(20,24,40,0.97));
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 18px;
  padding: 28px 28px 22px;
  min-width: 280px;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
  animation: cpCallBoxIn 0.25s cubic-bezier(0.4,0,0.2,1);
}
@keyframes cpCallBoxIn {
  from { transform: translateY(20px) scale(0.96); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
.incoming-call-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), rgba(147,197,253,0.6));
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  animation: cpCallAvatarPulse 1.4s ease-in-out infinite;
}
@keyframes cpCallAvatarPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(147,197,253,0.5); }
  50%      { transform: scale(1.04); box-shadow: 0 0 0 12px rgba(147,197,253,0); }
}
.incoming-call-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  word-break: break-word;
}
.incoming-call-sub {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 4px;
  margin-bottom: 22px;
}
.incoming-call-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
}
.incoming-call-btn {
  flex: 1;
  padding: 12px 16px;
  border-radius: 12px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  min-height: 48px;
}
.incoming-call-btn:hover { opacity: 0.88; }
.incoming-call-btn:active { transform: scale(0.97); }
.incoming-call-btn.accept {
  background: #22c55e;
  color: #fff;
}
.incoming-call-btn.decline {
  background: rgba(239,68,68,0.16);
  border: 1px solid rgba(239,68,68,0.35);
  color: #fca5a5;
}

/* ── 通话状态 toast（被拒/超时/取消）── */
.call-toast {
  display: none;
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20,24,40,0.95);
  border: 1px solid rgba(255,255,255,0.14);
  color: var(--text-primary);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 13px;
  z-index: 2100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: cpToastIn 0.2s ease;
}
.call-toast.active { display: block; }
@keyframes cpToastIn {
  from { transform: translate(-50%, -8px); opacity: 0; }
  to   { transform: translate(-50%, 0); opacity: 1; }
}
