:root {
  --fb-blue: #1877f2;
  --fb-blue-dark: #166fe5;
  --ms-blue: #0084ff;
  --ms-blue-soft: #d8e9ff;
  --bg-page: #f0f2f5;
  --bg-white: #ffffff;
  --bubble-mine: #0084ff;
  --bubble-mine-text: #fff;
  --bubble-theirs: #e4e6eb;
  --bubble-theirs-text: #050505;
  --text-1: #050505;
  --text-2: #65676b;
  --text-3: #b0b3b8;
  --border: #ced0d4;
  --red: #fa3e3e;
  --green: #31a24c;
}
* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html,body { height:100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg-page);
  color: var(--text-1);
  overflow:hidden;
}
.hidden { display:none !important; }
button { cursor:pointer; border:none; background:none; font-family:inherit; }

/* ========== 直达布局（无封面/无入口选择；网址即身份） ========== */
.screen { position:fixed; inset:0; }
/* .btn-enter 保留：用于“被顶下线”提示卡的重进按钮 */
.btn-enter {
  background:var(--ms-blue); color:#fff;
  padding:10px 16px; border-radius:10px;
  font-size:15px; font-weight:700;
}
.btn-enter:hover { background:var(--fb-blue-dark); }

/* ========== 聊天主布局 ========== */
#screen-chat { background: var(--bg-page); }
.chat-root {
  display:flex;
  height:100vh;
  height:100dvh;
  max-width: 1280px;
  margin:0 auto;
  background:#fff;
  box-shadow: 0 0 40px rgba(0,0,0,.08);
}

/* 左侧栏 */
.sidebar {
  width: 300px; flex:none;
  border-right: 1px solid var(--border);
  display:flex; flex-direction:column;
  background: var(--bg-white);
}
.sb-header {
  padding: 14px 16px 10px;
  display:flex; align-items:center;
}
.sb-logo { font-size:20px; font-weight:800; color:var(--fb-blue); }
.sb-search {
  margin: 4px 12px 10px;
  padding: 8px 12px;
  background: var(--bg-page);
  border-radius: 50px;
  color: var(--text-2);
  font-size:13px;
}
.conv-list { flex:1; overflow-y:auto; }
.conv-item {
  display:flex; align-items:center; gap:12px;
  padding: 10px 12px;
  cursor:pointer;
}
.conv-item.active { background: var(--ms-blue-soft); }
.conv-avatar-wrap { position:relative; flex:none; }
.conv-avatar, .h-avatar {
  width:56px; height:56px; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  font-size:28px;
}
.conv-avatar { background:linear-gradient(135deg,#1877f2,#063a8f); }
.conv-online, .h-online {
  position:absolute; bottom:0; right:0;
  width:14px; height:14px; border-radius:50%;
  background:#b0b3b8; border:2.5px solid #fff;
}
.conv-online.on, .h-online.on { background: var(--green); }
.conv-body { flex:1; min-width:0; }
.conv-top { display:flex; justify-content:space-between; align-items:baseline; gap:6px; }
.conv-name { font-weight:600; font-size:15px; }
.conv-time { font-size:11px; color:var(--text-3); }
.conv-preview {
  font-size:13px; color:var(--text-2);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
  margin-top:2px;
}
.sb-footer {
  border-top:1px solid var(--border);
  padding:8px;
}
.sb-me { display:flex; align-items:center; gap:10px; width:100%; padding:8px; border-radius:10px; text-align:left; }
.sb-me:hover { background:var(--bg-page); }
.me-avatar {
  width:40px; height:40px; border-radius:50%; flex:none;
  display:flex; align-items:center; justify-content:center; font-size:22px;
}
.me-info { flex:1; min-width:0; display:flex; flex-direction:column; }
.me-name { font-weight:600; font-size:14px; }
.me-role { font-size:12px; color:var(--text-2); }
.me-switch { font-size:12px; color:var(--ms-blue); }

/* 主聊天区 */
.main { flex:1; display:flex; flex-direction:column; min-width:0; background:#fff; }
.chat-header {
  display:flex; align-items:center; gap:12px;
  padding: 8px 14px;
  border-bottom:1px solid var(--border);
  background:#fff;
  min-height:62px;
}
.h-avatar-wrap { position:relative; }
.h-avatar { width:44px; height:44px; font-size:24px; }
.h-online { width:12px; height:12px; border-width:2px; }
.h-meta { flex:1; min-width:0; }
.h-name { font-weight:700; font-size:16px; }
.h-status { font-size:12.5px; color:var(--text-2); }
.h-status.on { color: var(--green); }

.typing-bar { padding:4px 20px; font-size:12.5px; color:var(--ms-blue); background:#fff; border-bottom:1px solid #f0f2f5; }

/* 消息区 */
.msgs {
  flex:1; overflow-y:auto;
  padding: 16px 18px 8px;
  background: #fff;
  scroll-behavior: smooth;
}
.msg-loader { text-align:center; font-size:12px; color:var(--text-3); padding:6px 0 2px; cursor:pointer; }

.day-divider {
  text-align:center; margin:12px 0 8px;
}
.day-divider span {
  background: var(--bg-page);
  color: var(--text-2);
  font-size:12px; font-weight:600;
  padding:4px 12px; border-radius:50px;
}

.msg-row { display:flex; margin:2px 0; }
.msg-row.mine { justify-content:flex-end; }
.msg-row.theirs { justify-content:flex-start; }
.msg-row+.msg-row { margin-top:1px; }
.msg-row.group-gap { margin-top:10px; }

.msg-avatar {
  width:34px; height:34px; border-radius:50%; flex:none;
  display:flex; align-items:center; justify-content:center;
  font-size:18px; margin-right:8px;
  align-self:flex-end;
}
.msg-row .bubble-wrap { max-width:min(66%, 560px); min-width:0; }
.msg-row .sender-name {
  font-size:12.5px; font-weight:700; color:var(--text-2);
  margin:0 4px 2px;
}
.bubble {
  position:relative;
  padding: 8px 13px;
  border-radius: 18px;
  font-size:15px;
  line-height:1.42;
  word-break:break-word;
  white-space:pre-wrap;
  cursor:pointer;
}
.bubble .msg-time {
  display:block;
  font-size:10px; opacity:.75;
  text-align:right;
  margin-top:2px;
  user-select:none;
}
.msg-row.mine .bubble {
  background: var(--bubble-mine);
  color: var(--bubble-mine-text);
  border-top-right-radius: 4px;
}
.msg-row.theirs .bubble {
  background: var(--bubble-theirs);
  color: var(--bubble-theirs-text);
  border-top-left-radius: 4px;
}
.bubble.pending-trans { font-style:italic; opacity:.85; }

/* 引用块 */
.reply-preview {
  display:block;
  background: rgba(0,0,0,.06);
  border-left: 3px solid rgba(0,0,0,.25);
  border-radius: 6px;
  padding: 4px 8px;
  margin-bottom: 6px;
  font-size: 12.5px;
  line-height: 1.35;
  pointer-events:auto;
  cursor:pointer;
}
.msg-row.mine .reply-preview { background: rgba(255,255,255,.16); border-left-color: rgba(255,255,255,.5); }
.reply-preview .r-name { font-weight:700; opacity:.85; display:block; }
.reply-preview .r-text { opacity:.8; display:block; }

/* 撤回样式 */
.recall-note {
  font-size: 13px;
  color: var(--text-2);
  font-style: italic;
  padding: 4px 10px;
  background: transparent;
  cursor: default !important;
}
.recall-note.own { text-align:right; }

/* 图片消息 */
.msg-img {
  max-width: 320px; max-height: 320px;
  border-radius: 12px;
  display:block;
  object-fit: cover;
}
.msg-row.mine .bubble.img-bubble { padding:3px; background:var(--bubble-mine); border-radius:18px; }
.msg-row.theirs .bubble.img-bubble { padding:3px; background:var(--bubble-theirs); }
.bubble.img-bubble .msg-time { padding:0 6px 2px; }

/* 已撤回时间/失败提示 */
.tstatus-failed {
  display:block; font-size:11px; margin-top:4px;
  color:#f1c40f; cursor:pointer; text-decoration:underline;
}
.msg-row.mine .tstatus-failed { color:#ffe08a; }

/* 菜单 */
.msg-menu {
  position:fixed; z-index:99;
  background:#fff; border-radius:10px;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  padding:6px;
  min-width:150px;
}
.msg-menu button {
  display:flex; align-items:center; gap:8px;
  width:100%; padding:9px 12px;
  border-radius:8px; font-size:14px; text-align:left;
  color:var(--text-1);
}
.msg-menu button:hover { background:var(--bg-page); }
.msg-menu button.danger { color: var(--red); }

/* 输入区 */
.composer-wrap { border-top:1px solid var(--border); background:#fff; position:relative; }

/* ===== 表情面板（Messenger 风格） ===== */
.emoji-sheet {
  position:absolute; left:0; right:0; bottom:100%; z-index:30;
  background:#fff;
  border-top:1px solid var(--border);
  box-shadow: 0 -8px 28px rgba(0,0,0,.14);
  display:flex; flex-direction:column;
  max-height: min(44vh, 340px);
  border-radius: 14px 14px 0 0;
  overflow:hidden;
}
.emoji-tabs {
  display:flex; gap:4px; align-items:center;
  padding:5px 10px 0;
  border-bottom:1px solid var(--border);
  background:#f7f8fa;
  flex:none;
}
.em-tab {
  width:44px; height:38px; font-size:21px;
  border-radius:9px;
  display:flex; align-items:center; justify-content:center;
  color:#8a8d91;
}
.em-tab:hover { background:#eceff3; }
.em-tab.active { background:#e7f3ff; box-shadow: inset 0 -2px 0 var(--ms-blue); color:var(--ms-blue); }
.emoji-grid {
  overflow-y:auto; flex:1;
  padding:6px 8px 8px;
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap:2px;
}
.em-item {
  height:42px; font-size:25px;
  display:flex; align-items:center; justify-content:center;
  border-radius:9px;
}
.em-item:hover { background:var(--bg-page); }
.em-item:active { background:#d8e9ff; transform:scale(.92); }

/* 引用栏 */
.quote-bar {
  margin:6px 12px 0; padding:8px 10px;
  background:var(--bg-page); border-radius:10px;
  border-left:3px solid var(--ms-blue);
}
.quote-content { position:relative; padding-right:18px; }
.quote-x { position:absolute; right:0; top:0; cursor:pointer; font-size:13px; color:var(--text-2); padding:2px; }
.quote-name { font-size:12px; font-weight:700; color:var(--ms-blue); display:block; }
.quote-text {
  font-size:13px; color:var(--text-2);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; display:block;
}
.composer {
  display:flex; align-items:flex-end; gap:8px;
  padding: 8px 12px 10px;
  background:#fff;
}
.c-btn {
  flex:none;
  width:40px; height:40px; border-radius:50%;
  font-size:20px;
  display:flex; align-items:center; justify-content:center;
  color:var(--ms-blue);
}
.c-btn:hover { background:var(--bg-page); }
#msgInput {
  flex:1; min-height:40px; max-height:150px;
  border:none; outline:none; resize:none;
  font-size:15px; font-family:inherit;
  padding:10px 14px;
  border-radius:22px;
  background:var(--bg-page);
  line-height:1.35;
}
.c-send {
  flex:none;
  width:40px; height:40px; border-radius:50%;
  background:var(--ms-blue);
  color:#fff; font-size:18px;
  display:flex; align-items:center; justify-content:center;
  transition: transform .1s;
}
.c-send:disabled { background:var(--border); cursor:default; }
.c-send:not(:disabled):active { transform:scale(.92); }

/* 灯箱 */
.lightbox {
  position:fixed; inset:0; z-index:200;
  background: rgba(0,0,0,.9);
  display:flex; align-items:center; justify-content:center;
  cursor:zoom-out;
}
.lightbox img { max-width:95vw; max-height:95vh; border-radius:8px; }

/* Toast */
.toast {
  position:fixed; z-index:300;
  left:50%; bottom:90px;
  transform: translateX(-50%);
  background: rgba(0,0,0,.82); color:#fff;
  padding: 9px 18px; border-radius: 50px;
  font-size: 13.5px;
  max-width: 88vw; text-align:center;
  animation: toastIn .2s ease;
}
@keyframes toastIn { from { opacity:0; transform:translate(-50%,8px);} to { opacity:1; transform:translate(-50%,0);} }

/* 打字动画 */
.typing-dots::after {
  content:'';
  animation: dots 1.2s steps(4,end) infinite;
}
@keyframes dots { 0%{content:'';} 25%{content:'.';} 50%{content:'..';} 75%{content:'...';} }

/* 滚动条 */
::-webkit-scrollbar { width:8px; }
::-webkit-scrollbar-thumb { background:#ccd0d5; border-radius:4px; }
::-webkit-scrollbar-thumb:hover { background:#b0b3b8; }

/* ===== 移动端：Messenger App 级适配 ===== */

/* iPad / 窄桌面：隐藏左栏、单聊为主 */
@media (max-width: 860px) {
  .sidebar { display:none; }
  .chat-root { max-width:100%; height:100vh; height:100dvh; box-shadow:none; }
  .msg-row .bubble-wrap { max-width:82%; }
  /* 刘海屏 / 底部横条安全区 */
  .chat-header { padding-top: max(8px, env(safe-area-inset-top)); min-height:calc(52px + env(safe-area-inset-top)); }
  .composer { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(100px + env(safe-area-inset-bottom)); }
}
/* 手机（≤480px）：隐藏气泡头像、气泡更宽、触控目标 ≥44px */
@media (max-width: 480px) {
  .msg-avatar { display:none !important; }          /* Messenger 手机版气泡无头像 */
  .sender-name { margin-left:4px !important; }
  .msg-row .bubble-wrap { max-width:88%; }
  .msg-img { max-width:100%; max-height:220px; width:auto; }
  .bubble { font-size:16px; padding:9px 14px; border-radius:20px; }
  .h-avatar { width:40px; height:40px; font-size:22px; }
  .chat-header { gap:8px; padding-left:8px; padding-right:8px; }
  .c-btn, .c-send { width:44px; height:44px; font-size:21px; flex:none; }
  .composer { gap:2px; padding:6px 6px; }
  #msgInput {
    font-size:16px;               /* ≥16px 防 iOS 聚焦自动放大 */
    min-height:44px;
    padding:12px 16px;
    border-radius:24px;
  }
  .emoji-grid { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); }
  .em-tab { width:46px; }
  .msgs { padding:10px 8px 6px; }
  .msg-row.group-gap { margin-top:14px; }
  .recall-note { font-size:12.5px; }
  .conv-avatar { width:48px; height:48px; }
}

/* ============ URL 直达制 / 已读回执 / Last seen / 被顶下线 ============ */

/* 自己消息的已读状态：未读半透明灰✓，对方已读亮白✓✓（蓝底气泡内） */
.seen-badge {
  font-style:normal; font-weight:800; font-size:10.5px;
  letter-spacing:1.5px; vertical-align:baseline;
  opacity:.42; user-select:none;
}
.seen-badge.read { opacity:1; color:#fff; text-shadow:0 1px 2px rgba(0,0,0,.3); }

/* 被顶下线全屏提示卡 */
.kick-overlay {
  position:fixed; inset:0; z-index:300;
  display:flex; align-items:center; justify-content:center;
  background:rgba(0,0,0,.45); backdrop-filter:blur(3px);
}
.kick-card {
  background:#fff; border-radius:18px; padding:34px 28px 24px;
  width:min(360px, 90vw); text-align:center;
  box-shadow:0 20px 60px rgba(0,0,0,.32);
}
.kick-emoji { font-size:52px; line-height:1; }
.kick-title { font-size:18px; font-weight:800; margin-top:14px; color:#050505; }
.kick-sub { font-size:13px; color:#65676b; margin:8px 0 20px; line-height:1.5; }
#kickRetry { display:block; width:100%; }
.kick-home {
  display:inline-block; margin-top:16px; font-size:13px;
  color:#65676b; text-decoration:none;
}
.kick-home:hover { text-decoration:underline; }

/* ============ 图片来源弹层：拍照 / 相册（Messenger 风格底部卡片） ============ */
.media-sheet {
  position:fixed; inset:0; z-index:260;
  display:flex; align-items:flex-end; justify-content:center;
  background:rgba(0,0,0,.42);
  animation:msFade .15s ease;
}
@keyframes msFade { from{opacity:0} to{opacity:1} }
.media-card {
  width:min(560px, 100%);
  background:#fff; border-radius:20px 20px 0 0;
  padding:12px 14px calc(16px + env(safe-area-inset-bottom));
  box-shadow:0 -8px 44px rgba(0,0,0,.24);
  animation:msUp .18s ease;
}
@keyframes msUp { from{transform:translateY(80px)} to{transform:translateY(0)} }
.media-title {
  text-align:center; font-size:12.5px; font-weight:600;
  color:var(--text-2); padding:6px 0 2px;
}
.media-item {
  display:flex; align-items:center; justify-content:center; gap:8px;
  width:100%; padding:14px 0; margin-top:8px;
  font-size:15px; font-weight:600; color:#050505;
  background:#f0f2f5; border-radius:10px;
}
.media-item:hover { background:#e4e6eb; }
.media-item.cancel { color:var(--ms-blue); background:transparent; }

/* ============ FB 风格消息操作按钮「⋯」(桌面 hover 显现，触屏隐藏走长按) ============ */
.bubble-more {
  flex:none; align-self:flex-end;
  width:28px; height:28px; margin:0 2px 8px 4px;
  display:flex; align-items:center; justify-content:center;
  border:none; border-radius:50%; background:transparent;
  color:var(--text-2); font-size:16px; line-height:1;
  opacity:0; transition:opacity .12s ease, background .12s ease;
  cursor:pointer; padding:0;
}
.msg-row:hover .bubble-more,
.bubble-more:focus-visible,
.bubble-more:active { opacity:1; background:var(--bg-page); color:var(--text-1); }
@media (hover:none) {
  /* 触屏设备没有 hover：隐藏 ⋯，改用长按气泡弹菜单（Messenger App 同款） */
  .bubble-more { display:none; }
}
