/* ========== XTELL 深色主题（移动优先） ========== */
:root {
  --bg: #0d1117;
  --panel: #161b26;
  --panel2: #1c2333;
  --bubble-other: #1f2733;
  --bubble-own: #2b5278;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.16);
  --text: #e6e9f0;
  --muted: #8b93a7;
  --danger: #ff5c5c;
  --border: #262d3d;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled { opacity: 0.45; cursor: not-allowed; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #2a3245; }
::-webkit-scrollbar-track { background: transparent; }

/* ========== 登录 / 注册 ========== */
.auth-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.auth-card {
  width: min(360px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);

  padding: 28px 24px 24px;
}

.auth-logo {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--accent);
  text-align: center;
}

.auth-sub {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin: 4px 0 20px;
}

.auth-tabs {
  display: flex;
  background: var(--panel2);

  padding: 3px;
  margin-bottom: 16px;
}

.auth-tabs button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 8px 0;

  font-size: 14px;
}

.auth-tabs button.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

#loginForm input, #registerForm input {
  display: block;
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);

  padding: 11px 12px;
  font-size: 16px; /* 防 iOS 聚焦缩放 */
  margin-bottom: 12px;
  outline: none;
}

#loginForm input:focus, #registerForm input:focus {
  border-color: var(--accent);
}

.btn-primary {
  width: 100%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;

  padding: 11px 0;
  margin-top: 4px;
}

.btn-primary:disabled { opacity: 0.6; }

.auth-error {
  margin-top: 12px;
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  word-break: break-all;
}

/* ========== 聊天布局 ========== */
.chat-wrap {
  display: flex;
  flex-direction: row;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  background: var(--bg);
  overflow: hidden;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ========== 左侧成员栏 ========== */
#sideBar {
  width: 200px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 11px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.side-head small { color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }

#sideList { flex: 1; overflow-y: auto; padding: 6px; }

.member-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;

  font-size: 13px;
  word-break: break-all;
}

.member-row .dot {
  width: 8px; height: 8px;

  background: #3a4257;
  flex-shrink: 0;
}

.member-row.on .dot {
  background: #7ddc8f;
}

.member-row.me { color: var(--accent); }

.member-empty {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 20px 8px;
}

/* 移动端抽屉遮罩 */
#sideMask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 80;
}

/* 三条杠按钮（仅移动端显示） */
.burger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  background: transparent;
  border: none;
  padding: 8px 8px 8px 0;
  flex-shrink: 0;
}

.burger i {
  display: block;
  width: 18px; height: 2px;

  background: var(--text);
}

@media (max-width: 760px) {
  #sideBar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 240px;
    z-index: 90;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
  }
  #sideBar.open { transform: translateX(0); }
  .burger { display: flex; }
}

/* 顶栏 */
.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 30;
}

.chat-title { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }

.logo-dot {
  width: 12px; height: 12px;
  background: var(--accent);
  flex-shrink: 0;
}

.chat-title .tt { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.chat-title b { font-size: 16px; }
.chat-title small { font-size: 11px; color: var(--muted); }

.chat-actions { display: flex; gap: 8px; flex-shrink: 0; }

.hbtn {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);

  font-size: 12px;
  padding: 6px 12px;
}

/* 消息列表 */
#msgList {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px 6px;
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
}

.empty {
  margin: auto;
  color: var(--muted);
  text-align: center;
  padding: 40px 20px;
  font-size: 13px;
}

.msg {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: min(80%, 720px);
  margin: 7px 0;
}

.msg.own { align-self: flex-end; align-items: flex-end; }

.msg-meta {
  font-size: 11px;
  color: var(--muted);
  margin: 0 5px 3px;
  display: flex;
  gap: 6px;
}

.msg.own .msg-meta .m-user { display: none; }

.bubble {
  background: var(--bubble-other);
  padding: 9px 12px;

  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.msg.own .bubble {
  background: var(--bubble-own);
  color: #eaf2ff;

}

.bubble a { color: var(--accent); word-break: break-all; }
.msg.own .bubble a { color: #9cc4ff; }

/* 图片消息（固定预留框：媒体加载零布局位移，进入聊天稳定贴底） */
.msg-img {
  display: block;
  width: min(240px, 60vw);
  height: 320px;
  object-fit: contain;

  cursor: zoom-in;
  background: #0a0e15;
}

/* 视频消息（首帧封面 + 播放按钮，点击在灯箱内播放；固定预留框同上） */
.msg-video {
  display: block;
  width: min(240px, 78vw);
  height: 150px;
  object-fit: cover;

  background: #000;
  cursor: pointer;
}

.bubble.video { position: relative; }

.video-play-mask {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.25);
  pointer-events: none;
}

.video-play-mask::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-38%, -50%);
  border-style: solid;
  border-width: 9px 0 9px 15px;
  border-color: transparent transparent transparent #fff;
}

/* 语音消息 */
.bubble.voice {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  width: var(--voice-w, 150px);
  min-width: 130px;
  padding-bottom: 11px;
}

.voice-play {
  width: 32px; height: 32px;

  border: none;
  flex-shrink: 0;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}

.msg.own .voice-play { background: rgba(255, 255, 255, 0.18); color: #fff; }

.voice-dur { font-size: 12px; color: var(--muted); flex: 1; }
.msg.own .voice-dur { color: #cfe0ff; }

.voice-bar {
  position: absolute;
  left: 14px; right: 14px; bottom: 5px;
  height: 2px;

  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.voice-bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.15s linear;
}

/* 文件消息 */
.bubble.file {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  min-width: 190px;
  max-width: 100%;
  padding: 10px 12px;
}

.file-icon {
  width: 38px; height: 38px;

  background: var(--accent-soft);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.file-info { min-width: 0; }
.file-name {
  font-size: 13px;
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.file-size { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ========== 底部输入区 ========== */
.chat-footer {
  position: relative;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  flex-shrink: 0;
  z-index: 40;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ibtn {
  min-width: 44px;
  height: 42px;
  border: 1px solid var(--border);

  background: var(--panel2);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}

.ibtn.hold {
  font-size: 14px;
  padding: 0 12px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none; /* 长按期间禁止页面滚动 */
}

.ibtn.hold.holding {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

#textForm {
  display: flex;
  flex: 1;
  gap: 6px;
  min-width: 0;
}

#textInput {
  flex: 1;
  min-width: 0;
  font-size: 16px; /* 防 iOS 聚焦缩放 */
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);

  padding: 9px 12px;
  outline: none;
}

#textInput:focus { border-color: var(--accent); }

#sendBtn {
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;

  padding: 0 14px;
  flex-shrink: 0;
}

/* ========== 录音 / 上传悬浮面板 ========== */
#recPanel, #uploadPanel {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(74px + env(safe-area-inset-bottom));
  background: rgba(22, 27, 38, 0.96);
  border: 1px solid var(--border);

  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 50;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  max-width: calc(100vw - 24px);
}

.rec-dot {
  width: 10px; height: 10px;

  background: var(--danger);
  animation: pulse 1s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.75); }
}

#recTime { font-variant-numeric: tabular-nums; font-weight: 600; }
#recHint { color: var(--muted); }

#recPanel.cancel { border-color: var(--danger); }
#recPanel.cancel #recHint { color: var(--danger); font-weight: 600; }

#recCancelBtn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);

  font-size: 12px;
  padding: 4px 10px;
}

#uploadTrack {
  width: 130px;
  height: 6px;

  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  flex-shrink: 1;
  min-width: 48px;
}

#uploadFill {
  height: 100%;
  width: 0;
  background: var(--accent);

  transition: width 0.2s ease;
}

#uploadText { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* ========== 灯箱 ========== */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
  z-index: 300;
}

/* 顶栏：关闭按钮 + 文件名，媒体在此栏下方展示，永不遮挡 */
#lbBar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: #0d1117;
  border-bottom: 1px solid var(--border);
  cursor: default;
}

#lbClose {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  padding: 2px 8px;
  cursor: pointer;
}

#lbClose:hover {
  color: #fff;
}

#lbTitle {
  flex: 1;
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 媒体展示区：在顶栏下方居中 */
#lbStage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  cursor: default;
}

#lightboxImg {
  max-width: 100%;
  max-height: 100%;
}

#lightboxVideo {
  max-width: 100%;
  max-height: 100%;
  background: #000;
  cursor: default;
}

/* 视频播放失败兜底气泡 */
.bubble.video-fail { width: 240px; height: 150px; }

.video-fail-tip {
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.video-fail-dl {
  display: inline-block;
  margin-top: 8px;
  font-weight: 600;
}

/* ========== 轻提示 ========== */
#toastBox {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 24px);
}

.toast {
  background: rgba(28, 35, 51, 0.96);
  border: 1px solid var(--border);
  color: var(--text);

  padding: 9px 16px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.2s ease;
}

.toast.err { border-color: rgba(255, 92, 92, 0.5); color: #ffb3b3; }

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

/* ---------- 历史分页上滑（加载反馈） ---------- */
.top-load,
.history-end {
  text-align: center;
  font-size: 12px;
  color: #8a93a6;
  padding: 8px 0;
}
.history-end { color: #5d6675; }
