/* ============================================================
   P2P 加密通讯 - 完整样式表
   设计理念：现代极简、深色主题、响应式
   ============================================================ */

/* ========== 基础重置 ========== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-tertiary: #242836;
  --bg-input: #2a2e3a;
  --text-primary: #e4e6eb;
  --text-secondary: #b0b3b8;
  --text-muted: #6b7080;
  --accent: #4f8cff;
  --accent-hover: #3b78f2;
  --accent-glow: rgba(79, 140, 255, 0.2);
  --success: #34c759;
  --warning: #ff9f0a;
  --danger: #ff3b30;
  --danger-hover: #e0352b;
  --border: #2d3140;
  --border-focus: #4f8cff;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
  --transition: 0.2s ease;
  --font-mono: 'Consolas', 'Courier New', monospace;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 
               'Microsoft YaHei', sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ========== 横幅提示 ========== */
.banner {
  padding: 10px 16px;
  font-size: 12.5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  line-height: 1.5;
  animation: slideDown 0.3s ease;
}

.banner.warning {
  background: linear-gradient(135deg, rgba(255,159,10,0.12), rgba(255,159,10,0.06));
  border-bottom: 1px solid rgba(255,159,10,0.2);
  color: var(--warning);
}

.banner button {
  background: rgba(255,159,10,0.15);
  border: 1px solid rgba(255,159,10,0.3);
  color: var(--warning);
  padding: 5px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  transition: var(--transition);
}

.banner button:hover {
  background: rgba(255,159,10,0.25);
}

@keyframes slideDown { from { transform: translateY(-100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ========== 服务器状态栏（所有页面底部常驻） ========== */
#server-status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 36px;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 0 16px;
  z-index: 500;
  font-size: 11px;
  backdrop-filter: blur(8px);
}

#server-status-bar .status-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

#server-status-bar .status-label {
  color: var(--text-muted);
  font-weight: 500;
}

#server-status-bar .status-value {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-weight: 600;
}

#server-status-bar .status-warn {
  color: var(--warning);
  margin-left: 8px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}

#server-status-bar .status-warn-icon {
  font-size: 12px;
}

/* 状态栏时间跳动动画 */
#server-status-bar .status-value.tick {
  animation: statusTick 0.3s ease;
}

@keyframes statusTick {
  0% { color: var(--accent); }
  100% { color: var(--text-primary); }
}

/* 小屏适配 */
@media (max-width: 768px) {
  #server-status-bar {
    gap: 10px;
    font-size: 10px;
    padding: 0 8px;
    height: 32px;
  }
  #server-status-bar .status-warn {
    display: none;
  }
  #chat-panel { height: calc(100% - 42px - 32px); }
  #key-panel, #auth-panel { padding-bottom: 32px; }
  .panel { padding-bottom: 0; }
}

/* ========== 面板通用 ========== */
.panel {
  display: flex;
  height: 100%;
  box-sizing: border-box;
  /* 为底部常驻的服务器状态栏留出空间，避免遮挡聊天输入框 */
  padding-bottom: 40px;
}

.panel.hidden { display: none !important; }

/* 用户名 + 随机按钮 同一行 */
.name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.name-row #input-username {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
}
/* 注意：#auth-panel button 会强制 width:100%，此处用更高优先级覆盖，避免🎲按钮独占整行 */
.name-row #btn-rand-name {
  flex: 0 0 auto;
  width: auto;
  height: 44px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 16px;
  transition: var(--transition);
}
.name-row #btn-rand-name:hover {
  background: var(--accent);
  color: #fff;
}

/* 语音通话远端音频：视觉隐藏但保持渲染，避免 display:none 被浏览器暂停而无声 */
.remote-audio {
  position: fixed;
  width: 1px;
  height: 1px;
  left: 0;
  bottom: 0;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
}

/* ========== 个人信息卡（侧栏顶部 · 自己的资料） ========== */
.self-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.self-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent-glow);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.self-info {
  flex: 1;
  min-width: 0;
}
.self-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.self-sub {
  font-size: 11px;
  color: var(--success);
  margin-top: 2px;
}
.self-clear {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.self-clear:hover {
  background: rgba(255,59,48,0.12);
  border-color: var(--danger);
  color: var(--danger);
}

/* ========== 未选择联系人时的空状态提示 ========== */
.chat-empty-hint {
  margin: auto;
  align-self: center;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  opacity: 0.55;
  padding: 40px 24px;
  line-height: 1.9;
}

/* 清除当前会话按钮（聊天头部）：hover 变红警示 */
#btn-clear-chat:hover {
  background: rgba(255,59,48,0.12);
  border-color: var(--danger);
  color: var(--danger);
}

/* ========== KEY验证面板（第一屏，最高安全） ========== */
#key-panel {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  gap: 14px;
  padding: 40px 20px 36px;
  height: 100%;
}

#key-panel h2 {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

#key-panel .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  max-width: 360px;
  text-align: center;
}

#key-panel input {
  width: 100%;
  max-width: 360px;
  padding: 13px 16px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 16px;
  letter-spacing: 2px;
  font-family: var(--font-mono);
  transition: var(--transition);
  outline: none;
  text-align: center;
}

#key-panel input:focus {
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(52,199,89,0.2);
}

#key-panel input.error-anim {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 4px rgba(255,59,48,0.25) !important;
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

#btn-verify-key {
  width: 100%;
  max-width: 360px;
  padding: 13px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  background: var(--success);
  color: #fff;
  position: relative;
  overflow: hidden;
}

#btn-verify-key:hover { filter: brightness(1.1); }
#btn-verify-key:active { transform: scale(0.98); }
#btn-verify-key:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
  filter: none;
}

.key-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  max-width: 360px;
  text-align: center;
  line-height: 1.5;
  opacity: 0.7;
}

.key-hint.cooldown {
  color: var(--danger);
  opacity: 1;
  font-weight: 500;
}

/* ========== 登录/注册面板 ========== */
#auth-panel {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  gap: 14px;
  padding: 40px 20px 36px;
}

#auth-panel h2 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

#auth-panel .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

#auth-panel input {
  width: 100%;
  max-width: 360px;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
  transition: var(--transition);
  outline: none;
}

#auth-panel input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#auth-panel button {
  width: 100%;
  max-width: 360px;
  padding: 12px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

#btn-register {
  background: var(--accent);
  color: #fff;
}
#btn-register:hover { background: var(--accent-hover); }
#btn-register:active { transform: scale(0.98); }

#btn-login {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1.5px solid var(--border) !important;
}
#btn-login:hover { background: var(--bg-input); border-color: var(--accent) !important; }

/* ========== 聊天面板 ========== */
#chat-panel {
  display: flex;
  height: calc(100% - 42px - 36px);  /* banner + 状态栏 */
}

/* 在线列表 */
#online-list {
  width: 260px;
  min-width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#online-list h3 {
  padding: 16px 18px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-bottom: 1px solid var(--border);
}

#user-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

#user-list::-webkit-scrollbar { width: 4px; }
#user-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

#user-list li {
  padding: 12px 14px;
  margin: 2px 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
}

#user-list li:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

#user-list li.active {
  background: var(--accent-glow);
  color: var(--accent);
  font-weight: 600;
}

#user-list li .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

#user-list li .dot.away { background: var(--warning); }
#user-list li .dot.offline { background: var(--text-muted); }

/* 聊天主区域 */
#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-primary);
}

/* 聊天头部 */
#chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}

#peer-name {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
}

#conn-status {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
}

.status-online { color: var(--success); background: rgba(52,199,89,0.1); }
.status-warning { color: var(--warning); background: rgba(255,159,10,0.1); }
.status-error { color: var(--danger); background: rgba(255,59,48,0.1); }
.status-calling { color: var(--accent); background: var(--accent-glow); animation: pulse 1.5s infinite; }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

#chat-header button {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

#chat-header button:hover {
  background: var(--bg-input);
  border-color: var(--accent);
  color: var(--accent);
}

/* 消息列表 */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.msg-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 70%;
  animation: msgIn 0.25s ease;
}

@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.msg-wrapper.sent { align-self: flex-end; }
.msg-wrapper.received { align-self: flex-start; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
}

.msg-wrapper.sent .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-wrapper.received .msg-bubble {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.msg-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.msg-wrapper.sent .msg-time { text-align: right; }

.msg-encrypted {
  font-size: 10px;
  color: rgba(255,255,255,0.4);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}

.msg-wrapper.sent .msg-encrypted { justify-content: flex-end; }

/* 内联图片气泡 */
.msg-bubble.has-image {
  padding: 6px;
  line-height: normal;
}
.msg-image {
  max-width: 240px;
  max-height: 320px;
  border-radius: var(--radius-sm);
  display: block;
  cursor: zoom-in;
  object-fit: contain; /* 完整显示整张图片，不裁剪 */
}
.msg-wrapper.sent .msg-image { margin-left: auto; }
/* 图片内联消息中的保存/校验提示 */
.img-save-btn {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 6px 8px;
  font-size: 13px;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.img-save-btn:hover { filter: brightness(1.1); }
.img-hash-fail {
  margin-top: 4px;
  font-size: 12px;
  color: #ffb4b4;
}

/* 送达状态标识 */
.msg-status {
  font-size: 11px;
  margin-top: 2px;
  padding: 0 4px;
  color: var(--text-muted);
}
.msg-wrapper.sent .msg-status { text-align: right; }
.msg-status.sent { color: var(--text-muted); }
.msg-status.sending { color: var(--warning); }
.msg-status.delivered { color: var(--success); }
.msg-status.failed { color: var(--danger); }

.msg-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.msg-file .file-icon { font-size: 24px; }
.msg-file .file-name { font-size: 13px; flex: 1; }
.msg-file .file-size { font-size: 11px; color: var(--text-muted); }

/* 输入区 */
#input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

#input-message {
  flex: 1;
  padding: 11px 16px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: 24px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
}

#input-message:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#btn-send, #btn-file {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#btn-send {
  background: var(--accent);
  color: #fff;
}
#btn-send:hover { background: var(--accent-hover); }
#btn-send:active { transform: scale(0.95); }

#btn-file {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
#btn-file:hover { background: var(--bg-input); color: var(--accent); }

/* ========== 浮动通话栏（不遮挡聊天，通话中可正常聊天/发文件） ========== */
#call-float-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: linear-gradient(135deg, rgba(79,140,255,0.08), rgba(0,204,136,0.04));
  border: 1px solid rgba(79,140,255,0.15);
  border-radius: var(--radius-md);
  margin: 10px 14px 6px;
  animation: callBarIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  z-index: 5;
}

@keyframes callBarIn { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: translateY(0); } }

#call-float-bar.cfb-hiding { opacity: 0; transform: translateY(-8px); transition: all 0.3s ease; }

#call-float-bar.cfb-reconnecting {
  border-color: rgba(255,159,10,0.3);
  background: rgba(255,159,10,0.06);
}

#call-float-bar .cfb-left { display: flex; align-items: center; gap: 10px; min-width: 0; }

#call-float-bar .cfb-icon { font-size: 22px; flex-shrink: 0; }

#call-float-bar .cfb-info { display: flex; flex-direction: column; gap: 1px; min-width: 0; }

#call-float-bar .cfb-label {
  font-size: 12px; font-weight: 600; color: var(--text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

#call-float-bar .cfb-status {
  font-size: 11px; color: var(--success); font-weight: 500;
}

#call-float-bar.cfb-reconnecting .cfb-status { color: var(--warning); }

#call-float-bar .cfb-timer {
  font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); font-weight: 600;
}

#call-float-bar .cfb-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }

#call-float-bar .cfb-btn {
  padding: 7px 14px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-tertiary); color: var(--text-primary); font-size: 13px;
  cursor: pointer; transition: var(--transition); font-weight: 600;
}

#call-float-bar .cfb-btn:hover { background: var(--bg-input); }

#call-float-bar .cfb-hangup {
  background: var(--danger); color: #fff; border: none;
  padding: 7px 18px; border-radius: 20px; font-size: 13px;
  font-weight: 700; cursor: pointer; transition: var(--transition);
}

#call-float-bar .cfb-hangup:hover { background: var(--danger-hover); transform: scale(1.03); }

/* 音频输出设备选择列表 */
.out-dev-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.out-dev-item {
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-tertiary); color: var(--text-primary); cursor: pointer;
  font-size: 14px; text-align: left; transition: var(--transition);
}
.out-dev-item:hover { background: var(--bg-input); border-color: var(--accent); }

/* 视频窗口（浮动栏展开时） */
.cfb-video-wrap {
  display: flex; gap: 8px; width: 100%;
  padding-top: 6px; border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0; position: relative; /* 作为自画面 PIP 的绝对定位参照，避免遮挡挂断按钮 */
}

.cfb-remote-video {
  width: 200px; height: 120px; background: #000; border-radius: var(--radius-sm);
  object-fit: cover; border: 1px solid var(--border); flex-shrink: 0;
}

.cfb-local-video {
  width: 100px; height: 75px; background: #000; border-radius: var(--radius-sm);
  object-fit: cover; border: 1px solid var(--border); flex-shrink: 0;
  position: absolute; top: 6px; right: 6px; opacity: 0.9; z-index: 2;
}

/* ========== 离线通知 ========== */
.offline-notice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 20px;
  margin: 12px 20px;
  background: rgba(255,159,10,0.08);
  border: 1px solid rgba(255,159,10,0.25);
  border-radius: var(--radius-md);
  animation: slideDown 0.3s ease;
}

.offline-notice .notice-icon { font-size: 24px; flex-shrink: 0; }

.offline-notice .notice-content strong {
  display: block;
  color: var(--warning);
  font-size: 14px;
  margin-bottom: 4px;
}

.offline-notice p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
}

.offline-notice .notice-hint {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 4px;
}

.offline-notice .notice-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  flex-shrink: 0;
}

/* ========== 文件进度条 ========== */
.file-progress {
  padding: 8px 14px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.file-progress .progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 6px;
}

.file-progress .progress-header .name {
  color: var(--text-primary);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  margin-right: 8px;
}

.file-progress .progress-header .pct {
  color: var(--accent);
  flex-shrink: 0;
}

.file-progress .progress-bar {
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  overflow: hidden;
}

.file-progress .progress-bar .fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.2s ease;
}

/* ========== 模态框 ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 30px;
  max-width: 480px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  animation: scaleIn 0.25s ease;
}

@keyframes scaleIn { from { transform: scale(0.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.modal-box h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
}

.modal-box .data-policy ul {
  padding-left: 18px;
  margin: 10px 0;
  font-size: 13px;
  line-height: 2;
  color: var(--text-secondary);
}

.modal-box .data-policy p {
  margin: 8px 0 4px;
  font-size: 13px;
  color: var(--text-secondary);
}

.modal-box .btn {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.modal-box .btn:hover { background: var(--accent-hover); }

/* ========== 错误提示（增强Toast） ========== */
.toast-bar {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  padding: 10px 22px;
  border-radius: 24px;
  font-size: 13px;
  font-weight: 500;
  z-index: 10000;
  opacity: 0;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 80vw;
  text-align: center;
  word-break: break-word;
}

.toast-bar.toast-show { opacity: 1; transform: translateX(-50%) translateY(0); }

.toast-error { background: var(--danger); color: #fff; box-shadow: 0 4px 20px rgba(255,59,48,0.3); }
.toast-success { background: var(--success); color: #fff; box-shadow: 0 4px 20px rgba(0,204,136,0.3); }
.toast-info { background: var(--accent); color: #fff; box-shadow: 0 4px 20px rgba(79,140,255,0.3); }

/* ========== 来电接听模态框 ========== */
.call-accept-overlay { z-index: 10001; }

.call-accept-box {
  background: var(--bg-secondary);
  border: 2px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 32px 30px 24px;
  max-width: 360px;
  width: 90%;
  text-align: center;
  box-shadow: 0 0 60px rgba(79,140,255,0.15), var(--shadow-lg);
  animation: cardBounceIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.call-accept-box .ca-icon { font-size: 48px; margin-bottom: 12px; animation: caPulse 1.5s ease-in-out infinite; }

@keyframes caPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }

.call-accept-box h3 { font-size: 18px; font-weight: 700; color: var(--text-primary); margin-bottom: 6px; }

.call-accept-box .ca-from {
  font-size: 13px; color: var(--text-secondary); margin-bottom: 18px; line-height: 1.5;
}

.call-accept-box .ca-actions { display: flex; gap: 12px; }

.call-accept-box .ca-accept {
  flex: 1; padding: 13px; background: var(--success); color: #fff;
  border: none; border-radius: var(--radius-md); font-size: 15px;
  font-weight: 700; cursor: pointer; transition: var(--transition);
}

.call-accept-box .ca-accept:hover { filter: brightness(1.15); transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,204,136,0.3); }

.call-accept-box .ca-reject {
  flex: 0.5; padding: 13px; background: var(--bg-tertiary); color: var(--text-secondary);
  border: 1px solid var(--border); border-radius: var(--radius-md); font-size: 14px;
  font-weight: 600; cursor: pointer; transition: var(--transition);
}

.call-accept-box .ca-reject:hover { border-color: var(--danger); color: var(--danger); }

/* ========== 会话过期提示（全屏优雅卡片） ========== */
.session-expired-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  animation: fadeIn 0.3s ease;
  backdrop-filter: blur(6px);
}

.session-expired-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px 32px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: 0 0 60px rgba(79,140,255,0.08), var(--shadow-lg);
  animation: cardBounceIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes cardBounceIn {
  from { transform: scale(0.8) translateY(30px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.session-expired-card .se-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 20px;
  background: linear-gradient(135deg, rgba(255,159,10,0.15), rgba(255,59,48,0.1));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  animation: iconPulse 2s ease-in-out infinite;
}

@keyframes iconPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,159,10,0.3); }
  50% { box-shadow: 0 0 0 16px rgba(255,159,10,0); }
}

.session-expired-card h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  letter-spacing: -0.3px;
}

.session-expired-card .se-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 8px;
}

.session-expired-card .se-reason {
  display: inline-flex;
  align-items: flex-start;
  gap: 10px;
  text-align: left;
  padding: 14px 18px;
  margin: 16px 0;
  background: rgba(255,159,10,0.06);
  border: 1px solid rgba(255,159,10,0.2);
  border-radius: var(--radius-md);
}

.session-expired-card .se-reason .se-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
  margin-top: 5px;
  flex-shrink: 0;
  box-shadow: 0 0 8px rgba(255,159,10,0.5);
}

.session-expired-card .se-reason span {
  font-size: 12px;
  color: var(--warning);
  line-height: 1.6;
}

.session-expired-card .se-reason span strong {
  color: #ffb340;
}

.session-expired-card .se-action {
  display: block;
  width: 100%;
  margin-top: 20px;
  padding: 13px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  letter-spacing: 0.5px;
}

.session-expired-card .se-action:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.session-expired-card .se-action:active {
  transform: scale(0.98);
}

.session-expired-card .se-footer {
  margin-top: 14px;
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.6;
}

/* ========== 模态框遮罩（通用） ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.25s ease;
  backdrop-filter: blur(4px);
}

/* ========== 传输横幅（聊天区域顶部） ========== */
#transfer-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: linear-gradient(135deg, rgba(79,140,255,0.08), rgba(0,204,136,0.05));
  border: 1px solid rgba(79,140,255,0.2);
  border-radius: var(--radius-md);
  margin: 8px 12px 6px;
  animation: slideBannerIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

@keyframes slideBannerIn {
  from { opacity: 0; transform: translateY(-16px); }
  to { opacity: 1; transform: translateY(0); }
}

#transfer-banner.tb-done {
  opacity: 0;
  transform: translateY(-8px);
  transition: all 0.6s ease;
}

#transfer-banner .tb-icon { font-size: 22px; flex-shrink: 0; }

#transfer-banner .tb-info {
  flex: 1;
  min-width: 0;
}

#transfer-banner .tb-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#transfer-banner .tb-meta {
  display: flex;
  gap: 12px;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}

#transfer-banner .tb-bar {
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}

#transfer-banner .tb-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #00cc88);
  border-radius: 2px;
  transition: width 0.3s ease;
}

#transfer-banner .tb-pct {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  margin-top: 2px;
}

#transfer-banner .tb-warn {
  font-size: 10px;
  color: var(--warning);
  background: rgba(255,159,10,0.1);
  border: 1px solid rgba(255,159,10,0.25);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  text-align: center;
  line-height: 1.4;
  flex-shrink: 0;
  white-space: nowrap;
}

/* ========== 文件接收确认框 ========== */
.file-accept-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 30px 24px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  box-shadow: 0 0 50px rgba(79,140,255,0.12), var(--shadow-lg);
  animation: cardBounceIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.file-accept-box .fa-icon {
  font-size: 44px;
  margin-bottom: 12px;
}

.file-accept-box h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.file-accept-box .fa-from {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.file-accept-box .fa-file {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
}

.file-accept-box .fa-fname {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-accept-box .fa-fsize {
  font-size: 12px;
  color: var(--text-secondary);
}

.file-accept-box .fa-fsize.large {
  color: var(--warning);
  font-weight: 700;
}

.file-accept-box .fa-warn {
  font-size: 11px;
  color: var(--warning);
  background: rgba(255,159,10,0.08);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  margin-bottom: 8px;
}

.file-accept-box .fa-note {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.7;
  line-height: 1.5;
  margin-bottom: 16px;
}

.file-accept-box .fa-actions {
  display: flex;
  gap: 10px;
}

.file-accept-box .fa-accept {
  flex: 1;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
}

.file-accept-box .fa-accept:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 16px var(--accent-glow);
  transform: translateY(-1px);
}

.file-accept-box .fa-reject {
  flex: 0.6;
  padding: 12px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.file-accept-box .fa-reject:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(255,59,48,0.05);
}

.file-accept-box .fa-timeout {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 12px;
  opacity: 0.5;
}

/* ========== 文件就绪卡片（接收完成） ========== */
.file-ready {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: rgba(0,204,136,0.06);
  border: 1px solid rgba(0,204,136,0.2);
  border-radius: var(--radius-md);
  margin: 8px 0;
  animation: fadeInUp 0.4s ease;
}

.file-ready .file-icon { font-size: 28px; flex-shrink: 0; }

.file-ready .file-info { flex: 1; min-width: 0; }

.file-ready .file-info .name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-ready .file-info .size {
  font-size: 11px;
  color: var(--success);
  margin-top: 2px;
}

.file-ready .file-info .warn {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.8;
  margin-top: 4px;
  line-height: 1.4;
}

.file-ready .btn-save-file {
  flex-shrink: 0;
  padding: 9px 14px;
  background: var(--success);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.file-ready .btn-save-file:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,204,136,0.3);
}

.file-ready .btn-save-file:active {
  transform: scale(0.96);
}

.file-ready.saved {
  border-color: var(--success);
  background: rgba(0,204,136,0.08);
}

/* ========== 文件校验气泡（发送方） ========== */
.file-verify-sent {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  margin: 8px auto 8px 0;
  max-width: 350px;
  animation: fadeInUp 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.file-verify-sent.fv-pass {
  background: rgba(0,204,136,0.08);
  border: 1px solid rgba(0,204,136,0.3);
}

.file-verify-sent.fv-fail {
  background: rgba(255,59,48,0.08);
  border: 1px solid rgba(255,59,48,0.25);
}

.file-verify-sent.fv-timeout {
  background: rgba(255,159,10,0.06);
  border: 1px solid rgba(255,159,10,0.2);
}

.file-verify-sent .fv-icon { font-size: 24px; flex-shrink: 0; margin-top: 1px; }

.file-verify-sent .fv-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.file-verify-sent .fv-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.file-verify-sent.fv-pass .fv-label { color: var(--success); }
.file-verify-sent.fv-fail .fv-label { color: var(--danger); }
.file-verify-sent.fv-timeout .fv-label { color: var(--warning); }

.file-verify-sent .fv-name {
  font-size: 12px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-verify-sent .fv-size {
  font-size: 10px;
  color: var(--text-secondary);
}

.file-verify-sent .fv-hash {
  font-size: 10px;
  color: var(--success);
  font-family: var(--font-mono);
  font-weight: 600;
}

.file-verify-sent .fv-hash-mismatch {
  font-size: 10px;
  color: var(--danger);
  font-family: var(--font-mono);
  word-break: break-all;
}

.file-verify-sent .fv-note {
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.8;
  margin-top: 2px;
  line-height: 1.4;
}

/* ========== 文件就绪卡片 · 哈希校验行 ========== */
.file-ready .file-hash {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-family: var(--font-mono);
  margin-top: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  line-height: 1.4;
}

.file-ready .file-hash.hash-pass {
  color: var(--success);
  background: rgba(0,204,136,0.08);
  border: 1px solid rgba(0,204,136,0.2);
}

.file-ready .file-hash.hash-fail {
  color: var(--danger);
  background: rgba(255,59,48,0.08);
  border: 1px solid rgba(255,59,48,0.2);
}

.file-ready .file-hash .fh-icon { font-size: 12px; flex-shrink: 0; }

/* ========== 在线列表增强 ========== */
.user-list .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
  margin-right: 8px;
  box-shadow: 0 0 6px rgba(0,204,136,0.4);
}

.user-list .dot.connected { background: #00e676; }
.user-list .dot.online { background: #ffb300; }  /* 仅信令在线，尚未建立 P2P */

.user-list .user-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 在线列表中的连接状态文字：已连接 / 在线 */
.user-list .user-state {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  padding-left: 6px;
}
.user-list .online-item .dot.connected + .user-state { color: #00e676; }

/* 未读消息红点/数字徽标 */
.unread-badge {
  margin-left: 6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger, #ff4d4f);
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  font-weight: 600;
  flex-shrink: 0;
}

.user-list .empty-state {
  color: var(--text-muted);
  font-size: 12px;
  opacity: 0.7;
  line-height: 1.6;
}

.user-list .empty-state small {
  font-size: 10px;
  opacity: 0.5;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========== 响应式 ========== */
@media (max-width: 768px) {
  #online-list {
    width: 200px;
    min-width: 200px;
  }

  .msg-wrapper { max-width: 85%; }
  
  .cfb-remote-video { width: 160px; height: 100px; }
  .cfb-local-video { width: 70px; height: 55px; }
}

@media (max-width: 480px) {
  #chat-panel { flex-direction: column; }

  #online-list {
    width: 100%;
    min-width: 100%;
    max-height: 180px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  #user-list { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; }
  #user-list li { padding: 6px 10px; font-size: 12px; }

  #chat-area { height: 0; flex: 1; }
  
  .msg-wrapper { max-width: 90%; }
}
