/* ============================
   CSS 变量 - 主题配色
   ============================ */
:root {
  --primary: #4a90d9;
  --primary-dark: #3a7bc8;
  --primary-light: #e8f1fb;
  --bg: #f0f2f5;
  --sidebar-bg: #ffffff;
  --chat-bg: #e5ddd5;
  --sent-bg: #4a90d9;
  --sent-text: #ffffff;
  --received-bg: #ffffff;
  --received-text: #333333;
  --text: #1a1a1a;
  --text-secondary: #666666;
  --text-muted: #999999;
  --border: #e0e0e0;
  --border-light: #f0f0f0;
  --danger: #e74c3c;
  --danger-dark: #c0392b;
  --success: #2ecc71;
  --warning: #f39c12;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --sidebar-width: 320px;
  --header-height: 56px;
  --input-area-height: 64px;
  --transition: 0.2s ease;
}

/* ============================
   重置 & 基础
   ============================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  transition: all var(--transition);
}

input, textarea {
  font-family: inherit;
  outline: none;
  border: none;
}

.hidden {
  display: none !important;
}

/* ============================
   整体布局
   ============================ */
#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* ============================
   侧边栏
   ============================ */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 20px;
  overflow-y: auto;
  z-index: 10;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
}

.app-header .app-icon {
  color: var(--primary);
  flex-shrink: 0;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.connection-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel-section label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.id-display {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  border: 1px solid var(--border);
}

.id-display code {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  word-break: break-all;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
}

.icon-btn {
  background: transparent;
  color: var(--text-secondary);
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--border-light);
  color: var(--primary);
}

.connect-row {
  display: flex;
  gap: 8px;
}

.connect-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
}

.connect-row input:focus {
  border-color: var(--primary);
  background: #fff;
}

.primary-btn {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.primary-btn:hover {
  background: var(--primary-dark);
}

.primary-btn:active {
  transform: scale(0.96);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
  transition: background var(--transition);
}

.status-dot.connected {
  background: var(--success);
}

.status-dot.connecting {
  background: var(--warning);
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* 通话按钮 */
.call-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.call-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.call-btn.voice {
  background: var(--success);
}

.call-btn.voice:hover:not(:disabled) {
  background: #27ae60;
}

.call-btn.video {
  background: var(--primary);
}

.call-btn.video:hover:not(:disabled) {
  background: var(--primary-dark);
}

.call-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
  opacity: 0.7;
}

.call-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

.sidebar-footer p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ============================
   聊天主区域
   ============================ */
#chatArea {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--chat-bg);
}

.chat-header {
  height: var(--header-height);
  min-height: var(--header-height);
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  box-shadow: var(--shadow-sm);
  z-index: 5;
}

.menu-toggle {
  display: none;
  background: transparent;
  color: var(--text);
  padding: 4px;
}

.chat-header span {
  font-size: 15px;
  font-weight: 600;
}

/* 消息列表 */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.messages::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
}

.empty-state p {
  margin-top: 12px;
  font-size: 15px;
}

.empty-state .sub {
  font-size: 13px;
  margin-top: 4px;
}

/* 消息气泡 */
.message {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: var(--radius);
  word-wrap: break-word;
  word-break: break-word;
  position: relative;
  animation: msgIn 0.25s ease;
  box-shadow: var(--shadow-sm);
  font-size: 14px;
  line-height: 1.5;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.sent {
  align-self: flex-end;
  background: var(--sent-bg);
  color: var(--sent-text);
  border-bottom-right-radius: 4px;
}

.message.received {
  align-self: flex-start;
  background: var(--received-bg);
  color: var(--received-text);
  border-bottom-left-radius: 4px;
}

.message .msg-text {
  white-space: pre-wrap;
}

.message .msg-text a {
  color: inherit;
  text-decoration: underline;
  word-break: break-all;
}

.message.sent .msg-text a {
  color: #e8f4ff;
}

.message .timestamp {
  display: block;
  font-size: 11px;
  opacity: 0.6;
  margin-top: 4px;
  text-align: right;
}

/* 消息中的媒体 */
.message .media-container {
  margin: -4px -6px 4px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.message img {
  max-width: 100%;
  max-height: 300px;
  display: block;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.message video {
  max-width: 100%;
  max-height: 300px;
  display: block;
  border-radius: var(--radius-sm);
}

.message audio {
  width: 100%;
  max-width: 280px;
  margin-top: 4px;
}

/* 文件附件 */
.message .file-attachment {
  display: flex;
  align-items: center;
  gap: 12px; /* 图标和文字的间距稍微拉开一点 */
  
  /* 核心：彻底清空所有干扰样式，让它像普通文字一样 */
  padding: 0; 
  margin: 0;
  background: transparent !important; /* 强制透明，干掉残留的半透明白色背景 */
  border: none;
  box-shadow: none;
  max-width: none; /* 取消宽度限制，让气泡自己撑开 */
  
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.message.sent .file-attachment {
  background: rgba(255, 255, 255, 0.15);
}

.message .file-attachment:hover {
  opacity: 0.85;
}

.message .file-attachment:hover .file-name {
  text-decoration: underline;
}

.message.sent .file-attachment:hover {
  background: rgba(255, 255, 255, 0.25);
}

.file-attachment .file-icon {
  flex-shrink: 0;
  font-size: 32px; /* 从 24px 调大到 32px，视觉更清晰 */
  line-height: 1;
  width: auto;   /* 取消固定宽度限制 */
  height: auto;  /* 取消固定高度限制 */
  display: flex;
  align-items: center;
}

.file-attachment .file-icon svg {
  width: 24px;
  height: 24px;
  stroke: currentColor; /* 使用当前文字颜色 */
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.file-attachment .file-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px; /* 名字和大小之间的间距 */
}

.file-attachment .file-name {
  font-size: 14px;
  font-weight: 600; 
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.file-attachment .file-size {
  font-size: 12px;
  font-weight: 400;
  color: inherit;
  opacity: 0.7; 
  line-height: 1.2;
}

/* 文件传输进度 */
.file-progress {
  margin-top: 6px;
  font-size: 11px;
  opacity: 0.8;
}

/* 系统消息 */
.message.system {
  align-self: center;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 20px;
  box-shadow: none;
  max-width: 90%;
}

/* ============================
   录音/录像状态栏
   ============================ */
.recording-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: #fff;
  border-top: 1px solid var(--border);
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.rec-pulse {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--danger);
  animation: recPulse 1s infinite;
  flex-shrink: 0;
}

@keyframes recPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.recording-bar #recordingLabel {
  font-size: 13px;
  font-weight: 600;
  color: var(--danger);
}

.rec-timer {
  font-size: 13px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  flex: 1;
}

.rec-cancel {
  padding: 6px 14px;
  border-radius: 6px;
  background: var(--border-light);
  color: var(--text-secondary);
  font-size: 13px;
}

.rec-cancel:hover {
  background: var(--border);
}

.rec-stop {
  padding: 6px 16px;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

.rec-stop:hover {
  background: var(--primary-dark);
}

/* ============================
   输入区域
   ============================ */
.input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: var(--sidebar-bg);
  border-top: 1px solid var(--border);
  min-height: var(--input-area-height);
}

.input-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.icon-action-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-action-btn:hover {
  background: var(--bg);
  color: var(--primary);
}

.icon-action-btn:active {
  transform: scale(0.9);
}

#messageInput {
  flex: 1;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-size: 14px;
  resize: none;
  max-height: 120px;
  min-height: 38px;
  line-height: 1.4;
  background: var(--bg);
  color: var(--text);
  transition: border-color var(--transition);
}
#messageInput::-webkit-scrollbar {
  width: 6px;
}

#messageInput::-webkit-scrollbar-track {
  background: transparent; /* 轨道透明 */
  border-radius: 10px;     /* 轨道圆角，建议设为输入框圆角的一半或稍小 */
  margin: 10px 0;          /* 上下留出间距，避免滑块顶到输入框边缘 */
}

#messageInput::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2); /* 滑块颜色，可根据主题调整 */
  border-radius: 10px;            /* 滑块圆角 */
}

#messageInput::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3); /* 鼠标悬停时滑块颜色加深 */
}
#messageInput:focus {
  border-color: var(--primary);
  background: #fff;
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.send-btn svg {
  display: block; /* 消除行内元素默认的底部空白和基线偏移 */
  /* 如果加了上面那行还是觉得偏右/偏下，就取消下面这行的注释，进行物理微调 */
  transform: translate(-1px, 0.5px);
}

.send-btn:hover {
  background: var(--primary-dark);
}

.send-btn:active {
  transform: scale(0.92);
}

/* ============================
   视频通话覆盖层
   ============================ */
.call-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.call-overlay video#remoteVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #1a1a1a;
}

.call-overlay .local-video {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 150px;
  height: 210px;
  object-fit: cover;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: #2a2a2a;
  z-index: 2;
  box-shadow: var(--shadow-lg);
}

.call-info {
  position: absolute;
  top: 20px;
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: #fff;
  z-index: 2;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.call-info span {
  font-size: 14px;
  font-weight: 600;
}

.call-info #callStatus {
  font-size: 12px;
  opacity: 0.8;
  font-weight: 400;
}

.call-controls-overlay {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 20px;
  z-index: 3;
}

.call-control-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.call-control-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.call-control-btn.muted,
.call-control-btn.video-off {
  background: rgba(255, 255, 255, 0.5);
  color: #333;
}

.call-control-btn.end-call {
  background: var(--danger);
}

.call-control-btn.end-call:hover {
  background: var(--danger-dark);
}

.call-control-btn:active {
  transform: scale(0.92);
}

/* ============================
   来电弹窗
   ============================ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-content {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 36px 32px 28px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.25s ease;
  max-width: 90%;
  width: 320px;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.modal-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: ringPulse 1.5s infinite;
}

@keyframes ringPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 144, 217, 0.4); }
  50% { box-shadow: 0 0 0 16px rgba(74, 144, 217, 0); }
}

.modal-content p {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.modal-sub {
  font-size: 14px !important;
  font-weight: 400 !important;
  color: var(--text-secondary);
  margin-bottom: 24px !important;
}

.modal-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.reject-btn {
  padding: 12px 28px;
  border-radius: 50px;
  background: var(--danger);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

.reject-btn:hover {
  background: var(--danger-dark);
}

.answer-btn {
  padding: 12px 28px;
  border-radius: 50px;
  background: var(--success);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

.answer-btn:hover {
  background: #27ae60;
}

/* ============================
   Toast 通知
   ============================ */
.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: rgba(30, 30, 30, 0.92);
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.toast.error {
  background: rgba(231, 76, 60, 0.92);
}

.toast.success {
  background: rgba(46, 204, 113, 0.92);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================
   图片预览弹窗
   ============================ */
.image-preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 250;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.image-preview-overlay img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.image-preview-overlay .close-preview {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================
   响应式 - 移动端
   ============================ */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 100%;
  }

  #app {
    flex-direction: column;
  }

  #sidebar {
    position: fixed;
    inset: 0;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 50;
    padding: 16px;
  }

  #sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .menu-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
  }

  #chatArea {
    width: 100%;
  }

  .chat-header {
    padding: 0 12px;
  }

  .messages {
    padding: 12px;
  }

  .message {
    max-width: 85%;
  }

  .input-area {
    padding: 8px 10px;
    gap: 6px;
  }

  .icon-action-btn {
    width: 36px;
    height: 36px;
  }

  #messageInput {
    font-size: 16px; /* 防止 iOS 缩放 */
  }

  .send-btn {
    width: 40px;
    height: 40px;
  }

  /* 移动端视频通话 */
  .call-overlay .local-video {
    width: 100px;
    height: 140px;
    top: 12px;
    right: 12px;
    border-radius: 8px;
  }

  .call-info {
    top: 12px;
    left: 12px;
  }

  .call-controls-overlay {
    bottom: 24px;
    gap: 16px;
  }

  .call-control-btn {
    width: 50px;
    height: 50px;
  }

  .modal-content {
    width: 90%;
    padding: 28px 24px 24px;
  }

  .toast {
	  max-width: min(85vw, 360px);
	  white-space: nowrap;
	  text-align: center;
	}
}

/* 超小屏幕 */
@media (max-width: 380px) {
  .input-actions {
    gap: 0;
  }

  .icon-action-btn {
    width: 34px;
    height: 34px;
  }

  .message {
    max-width: 92%;
  }
}

/* 横屏适配 */
@media (max-height: 500px) and (orientation: landscape) {
  .call-overlay .local-video {
    width: 120px;
    height: 80px;
    top: 10px;
    right: 10px;
  }

  .call-controls-overlay {
    bottom: 12px;
  }
}

/* ============================ 自定义语音消息气泡 ============================ */
.voice-message {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 100px;
  max-width: 220px;
  cursor: pointer;
  user-select: none;
  padding: 4px 0;
}

/* 播放/暂停按钮 */
.voice-play-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.voice-play-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor; /* 继承气泡的文字颜色（发送方白色，接收方黑色） */
}

/* 声波动画容器 */
.voice-waves {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 24px;
  flex: 1;
}
.voice-wave-bar {
  width: 3px;
  background-color: currentColor;
  border-radius: 2px;
  opacity: 0.6;
  transition: height 0.2s ease;
}
/* 静态声波高低错落 */
.voice-wave-bar:nth-child(1) { height: 8px; }
.voice-wave-bar:nth-child(2) { height: 16px; }
.voice-wave-bar:nth-child(3) { height: 10px; }
.voice-wave-bar:nth-child(4) { height: 20px; }
.voice-wave-bar:nth-child(5) { height: 12px; }

/* 播放时的声波跳动动画 */
.voice-message.playing .voice-wave-bar {
  animation: waveJump 0.6s infinite ease-in-out alternate;
  opacity: 1;
}
.voice-message.playing .voice-wave-bar:nth-child(1) { animation-delay: 0.0s; }
.voice-message.playing .voice-wave-bar:nth-child(2) { animation-delay: 0.1s; }
.voice-message.playing .voice-wave-bar:nth-child(3) { animation-delay: 0.2s; }
.voice-message.playing .voice-wave-bar:nth-child(4) { animation-delay: 0.3s; }
.voice-message.playing .voice-wave-bar:nth-child(5) { animation-delay: 0.4s; }

@keyframes waveJump {
  0% { height: 6px; }
  100% { height: 22px; }
}

/* 语音时长 */
.voice-duration {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 500;
  opacity: 0.85;
  min-width: 32px;
  text-align: right;
}

/* 隐藏原生的 audio 标签 */
.voice-message audio {
  display: none !important;
}

/* ============================ 连接状态行布局 ============================ */
.connection-row {
  display: flex;
  justify-content: space-between; /* 🌟 核心魔法：让 label 靠左，状态靠右 */
  align-items: center;            /* 🌟 垂直居中对齐 */
  width: 100%;
  margin-bottom: 8px;             /* 和下方输入框保持一点间距 */
}

/* 稍微调整一下 label 的样式，让它看起来更精致 */
.connection-row label {
  font-size: 14px;
  font-weight: 600;
  color: #333; /* 根据你的主题颜色自行调整 */
  margin: 0;   /* 清除默认的 margin */
}

/* 确保状态指示灯内部也是水平排列的 */
.connection-status {
  display: flex;
  align-items: center;
  gap: 6px; /* 圆点和文字之间的间距 */
}

/* 状态文字的样式微调 */
#statusText {
  font-size: 13px;
  color: #666;
  font-weight: 500;
}

/* ============================ 录像预览悬浮窗 ============================ */
.video-preview-overlay {
  position: absolute;
  bottom: 90px;
  right: 20px;
  width: 200px;
  height: 280px;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  z-index: 50;
  animation: fadeInScale 0.25s ease;
  border: 2px solid rgba(255, 255, 255, 0.2);
  /* 🌟 新增：拖拽相关 */
  user-select: none;
  -webkit-user-select: none;
  touch-action: none; /* 防止移动端页面跟随滚动 */
  transition: box-shadow 0.2s ease;
}

.video-preview-overlay:active {
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.local-record-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* 镜像翻转，让用户感觉像照镜子一样自然 */
  transform: scaleX(-1); 
}

/* 左上角的 REC 指示器 */
.rec-indicator {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.5);
  padding: 4px 10px;
  border-radius: 20px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
}

.rec-dot {
  width: 8px;
  height: 8px;
  background: #ff3b30;
  border-radius: 50%;
  animation: recPulse 1s infinite;
}

/* 移动端适配 */
@media (max-width: 768px) {
  .video-preview-overlay {
    width: 120px;
    height: 160px;
    bottom: 80px;
    right: 12px;
    border-radius: 8px;
  }
  .rec-indicator {
    top: 8px;
    left: 8px;
    padding: 2px 6px;
    font-size: 10px;
  }
  .rec-dot {
    width: 6px;
    height: 6px;
  }
  #chatArea {
    width: 100%;
    height: 100%;      /* 🌟 新增 */
    min-height: 0;     /* 🌟 新增：关键！允许 flex 子项收缩到比内容更小 */
    overflow: hidden;  /* 🌟 新增：防止内容溢出 */
  }
}

/* 侧边栏遮罩 */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 49; /* 比 sidebar(50) 低一层即可 */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* 打开状态 - 由 JS 添加此类 */
.sidebar-overlay.active {
  opacity: 1;
  visibility: visible;
}