:root {
  --bg: #0e1621;
  --bg-elev: #17212b;
  --bg-elev-2: #1e2c39;
  --bubble-out: #2b5278;
  --bubble-in: #182533;
  --text: #e9eef2;
  --text-dim: #708499;
  --text-mute: #5a6c7d;
  --accent: #3aa0ff;
  --accent-2: #6ab2f2;
  --danger: #e53935;
  --success: #43b581;
  --gold: #ffb84a;
  --vip: #a06bff;
  --member: #ff9d3a;
  --pro: #3aa0ff;
  --border: #243341;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: transparent; }
input, textarea { font: inherit; color: inherit; }

.screen { display: none; height: 100vh; }
.screen.active { display: block; }

/* ===== AUTH ===== */
#screen-auth {
  display: none;
  min-height: 100vh;
  background:
    radial-gradient(1100px 600px at 20% -10%, rgba(58,160,255,.18), transparent 70%),
    radial-gradient(900px 500px at 100% 100%, rgba(160,107,255,.15), transparent 60%),
    var(--bg);
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#screen-auth.active { display: flex; }

.auth-card {
  width: 100%; max-width: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.logo { text-align: center; margin-bottom: 22px; }
.logo h1 { margin: 12px 0 4px; font-size: 26px; letter-spacing: .5px; }
.muted { color: var(--text-dim); }
.small { font-size: 12px; }
.hint { color: var(--text-mute); font-size: 12px; margin-top: 14px; text-align: center; }

.tabs {
  display: flex; gap: 4px; padding: 4px;
  background: var(--bg-elev-2);
  border-radius: 12px; margin-bottom: 18px;
}
.tab {
  flex: 1; padding: 9px 0; border-radius: 9px;
  color: var(--text-dim); font-weight: 500;
}
.tab.active { background: var(--accent); color: #fff; }

.form { display: none; flex-direction: column; gap: 8px; }
.form.active { display: flex; }
.form label { font-size: 13px; color: var(--text-dim); margin-top: 6px; }
.form input {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  outline: none;
  transition: border-color .15s;
}
.form input:focus { border-color: var(--accent); }
.row-flex { display: flex; justify-content: space-between; align-items: center; }
.link-btn { color: var(--accent); font-size: 13px; }
.link-btn:hover { text-decoration: underline; }

.btn-primary {
  margin-top: 14px;
  background: linear-gradient(135deg, var(--accent), #2b8be6);
  color: #fff; font-weight: 600;
  padding: 12px 16px; border-radius: 10px;
  transition: transform .1s, box-shadow .15s;
  box-shadow: 0 4px 14px rgba(58,160,255,.35);
}
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }

/* ===== APP LAYOUT ===== */
.app {
  display: none;
  grid-template-columns: 360px 1fr;
  height: 100vh;
  height: 100dvh;
}
.app.active { display: grid; }

/* SIDEBAR */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-height: 0;
}
.sidebar-header {
  padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border);
}
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-dim);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-elev-2); color: var(--text); }
.send-btn { color: var(--accent); }
.send-btn:disabled { opacity: .4; }

.me { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.me-meta { min-width: 0; }
.me-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-uid { font-size: 12px; color: var(--text-mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #6ab2f2);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; flex-shrink: 0; user-select: none;
  overflow: hidden; position: relative;
}
.avatar > img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.big { width: 64px; height: 64px; font-size: 24px; }
.avatar.huge { width: 96px; height: 96px; font-size: 36px; border-radius: 50%; }

.avatar-edit {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 8px 0 16px;
}
.avatar-edit .avatar.huge { cursor: pointer; }
.avatar-edit-actions { display: flex; gap: 14px; }
.btn-link {
  background: none; border: none; color: var(--accent);
  font-size: 13px; padding: 4px 6px; cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--danger, #e85a6a); }

.search-row {
  padding: 8px 10px; display: flex; gap: 6px; align-items: center;
  border-bottom: 1px solid var(--border);
}
.search-row input {
  flex: 1; background: var(--bg-elev-2); border: 1px solid transparent;
  border-radius: 18px; padding: 8px 14px; outline: none;
}
.search-row input:focus { border-color: var(--accent); }

.sidebar-tabs {
  display: flex; padding: 4px 10px 8px; gap: 4px;
}
.sidebar-tabs button {
  padding: 6px 12px; border-radius: 8px;
  color: var(--text-dim); font-size: 13px;
}
.sidebar-tabs button.active { background: var(--bg-elev-2); color: var(--text); }

.list { flex: 1; overflow-y: auto; display: none; }
.list.active { display: block; }

.list-item {
  padding: 10px 14px;
  display: flex; gap: 12px; align-items: center;
  cursor: pointer; border-bottom: 1px solid rgba(36,51,65,.4);
  transition: background .12s;
}
.list-item:hover { background: var(--bg-elev-2); }
.list-item .meta { flex: 1; min-width: 0; }
.list-item .name { font-weight: 500; display: flex; align-items: center; gap: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .preview { font-size: 13px; color: var(--text-mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  font-size: 10px; padding: 2px 6px; border-radius: 6px;
  background: var(--accent); color: #fff; font-weight: 600;
}
.badge.member { background: var(--member); }
.badge.vip { background: var(--vip); }
.badge.pro { background: linear-gradient(135deg, #3aa0ff, #a06bff); }
.badge.vanity {
  background: linear-gradient(135deg, #ffb84a, #ff7e3a); color: #fff;
}

/* CHAT */
.chat {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  height: 100%;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(58,160,255,.06), transparent 70%),
    var(--bg);
}
.chat-header {
  padding: 10px 14px;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.back-btn { display: none; }
.peer-info { flex: 1; min-width: 0; }
.peer-name { font-weight: 600; display: flex; gap: 6px; align-items: center; }
.peer-sub { font-size: 12px; color: var(--text-mute); }

.messages {
  flex: 1; overflow-y: auto;
  padding: 16px 4% 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.empty-hint {
  margin: auto; text-align: center; color: var(--text-mute);
}
.empty-hint h3 { margin: 8px 0 4px; }

.msg {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 14px;
  word-wrap: break-word; overflow-wrap: anywhere;
  position: relative;
  animation: msgIn .2s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
.msg.out {
  align-self: flex-end;
  background: var(--bubble-out); color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.in {
  align-self: flex-start;
  background: var(--bubble-in); color: var(--text);
  border-bottom-left-radius: 4px;
}
.msg .meta { font-size: 10px; opacity: .65; margin-top: 4px; text-align: right; }
.msg.image { padding: 4px; background: transparent !important; }
.msg.image img { max-width: 280px; max-height: 320px; border-radius: 12px; display: block; }
.msg.voice {
  display: flex; align-items: center; gap: 8px;
  min-width: 160px;
}
.msg.voice button {
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255,255,255,.18); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
}
.msg.voice .wave { flex: 1; height: 20px; opacity: .8; }
.msg.voice .dur { font-size: 12px; opacity: .8; }
.msg.file {
  display: flex; align-items: center; gap: 10px;
  min-width: 200px;
}
.msg.file .file-icon {
  width: 36px; height: 36px; border-radius: 8px;
  background: rgba(255,255,255,.15); display: flex; align-items: center; justify-content: center;
}
.msg.sticker { background: transparent !important; padding: 0; }
.msg.sticker img { width: 140px; height: 140px; object-fit: contain; }
.msg.system {
  align-self: center; background: rgba(255,255,255,.05);
  color: var(--text-mute); font-size: 12px;
  border-radius: 8px; padding: 4px 10px;
}

/* COMPOSER */
.composer {
  padding: 10px 14px;
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
}
#msg-input {
  flex: 1; background: var(--bg-elev-2);
  border: 1px solid transparent;
  border-radius: 20px;
  padding: 10px 16px;
  outline: none;
}
#msg-input:focus { border-color: var(--accent); }

/* EMOJI */
.emoji-panel {
  position: absolute; bottom: 70px; left: 50%; transform: translateX(-50%);
  width: min(560px, 90%);
  max-height: 280px; overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 10px;
  display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px;
}
.emoji-panel button {
  font-size: 22px; padding: 6px; border-radius: 8px;
  transition: background .1s;
}
.emoji-panel button:hover { background: var(--bg-elev-2); }

/* RECORDING */
.recording-panel {
  position: absolute; bottom: 70px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 8px 14px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow);
}
.rec-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--danger);
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .4; transform: scale(.8); }
}
.btn-cancel, .btn-send-rec {
  padding: 6px 12px; border-radius: 8px; font-size: 13px;
}
.btn-cancel { color: var(--text-dim); }
.btn-send-rec { background: var(--accent); color: #fff; }

/* DRAWER */
.drawer {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.5);
  display: flex; justify-content: flex-end;
  animation: fadeIn .15s;
}
.drawer[hidden] { display: none; }
.emoji-panel[hidden], .recording-panel[hidden], .composer[hidden] { display: none !important; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.drawer-content {
  width: min(420px, 92%);
  background: var(--bg-elev);
  height: 100%; overflow-y: auto;
  padding: 24px 22px;
  position: relative;
  animation: slideIn .2s;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: none; } }
.drawer-close { position: absolute; top: 14px; right: 14px; }
.drawer-content h2 { margin: 0 0 14px; }
.drawer-content h3 { margin: 22px 0 10px; color: var(--text-dim); font-size: 13px; text-transform: uppercase; letter-spacing: 1px; }

.me-card {
  display: flex; gap: 14px; align-items: center;
  background: var(--bg-elev-2);
  border-radius: var(--radius);
  padding: 16px;
}
.me-name-row { font-weight: 600; font-size: 17px; display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }

/* === Telegram 风格个人主页 === */
.profile-header {
  text-align: center;
  padding: 24px 0 18px;
  background: linear-gradient(180deg, var(--bg-elev-2) 0%, transparent 100%);
  border-radius: 0 0 24px 24px;
  margin: -24px -22px 18px;
}
.profile-header .avatar.huge {
  width: 96px; height: 96px; font-size: 36px;
  margin: 0 auto 12px;
}
.profile-name-row {
  font-size: 22px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 8px;
}
.profile-uid {
  margin-top: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
}

.profile-info {
  background: var(--bg-elev-2);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 16px;
}
.info-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--bg);
}
.info-row:last-child { border-bottom: none; }
.info-label { color: var(--text-dim); font-size: 14px; }
.info-value { font-size: 14px; font-weight: 500; }

.profile-menu {
  background: var(--bg-elev-2);
  border-radius: 12px;
  overflow: hidden;
}
.profile-menu-item {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  padding: 13px 16px;
  text-align: left;
  font-size: 15px;
  color: var(--text);
  border-bottom: 1px solid var(--bg);
  transition: background .12s;
}
.profile-menu-item:last-child { border-bottom: none; }
.profile-menu-item:hover { background: var(--bg); }
.profile-menu-item span:nth-child(2) { flex: 1; }
.profile-menu-item .chev { color: var(--text-mute); font-size: 20px; }
.profile-menu-item.danger { color: var(--danger); }
.profile-menu-item.danger svg { color: var(--danger); }

.profile-foot {
  text-align: center;
  padding: 24px 0 8px;
  font-size: 11px;
  opacity: .7;
}

/* 子页面 */
.subpage .drawer-content { padding: 0; }
.subpage-header {
  display: flex; align-items: center; gap: 4px;
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky; top: 0; z-index: 2;
}
.subpage-header h2 { margin: 0; font-size: 18px; flex: 1; text-align: center; padding-right: 38px; }
.subpage .form { padding: 22px; }
.subpage .form input, .subpage .form textarea {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  outline: none;
  font-family: inherit;
  resize: vertical;
}
.subpage .form input:focus, .subpage .form textarea:focus { border-color: var(--accent); }

.section-title {
  margin: 18px 4px 10px;
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.info-block {
  padding: 22px;
  background: var(--bg-elev-2);
  border-radius: 12px;
  margin: 22px;
}
.info-block p { margin: 0 0 10px; line-height: 1.6; }
.info-block code { font-size: 11px; opacity: .7; word-break: break-all; }

.tiers {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.tier {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  transition: transform .12s, border-color .12s;
  position: relative; overflow: hidden;
}
.tier:hover { transform: translateY(-2px); border-color: var(--accent); }
.tier.active { border-color: var(--accent); }
.tier::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--c, var(--accent));
}
.tier h4 { margin: 0 0 4px; font-size: 15px; }
.tier .price { color: var(--gold); font-weight: 700; margin: 6px 0; }
.tier ul { margin: 0; padding-left: 16px; font-size: 12px; color: var(--text-dim); }
.tier li { margin: 3px 0; }

.vanity {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.vanity-row {
  display: grid; grid-template-columns: 2fr 1fr auto; gap: 6px; margin-top: 8px;
}
.vanity-row input {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; outline: none;
}
.vanity-row input:focus { border-color: var(--accent); }
.vanity-row button { white-space: nowrap; padding: 8px 14px; }

/* TOAST */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elev-2); color: var(--text);
  padding: 10px 18px; border-radius: 24px;
  box-shadow: var(--shadow); z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: 80%;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* RESPONSIVE */
@media (max-width: 800px) {
  /* 手机端把侧栏和聊天面板都做成 absolute 覆盖,
     哪个 active 哪个就在最上面,彻底避免 grid 隐式行带来的高度计算错乱。 */
  .app { position: relative; display: block; height: 100dvh; height: 100vh; }
  .sidebar,
  .chat {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }
  /* 默认:侧栏在上,聊天面板隐藏 */
  .sidebar { display: flex; z-index: 1; }
  .chat { display: none; z-index: 2; }
  /* 进入聊天后:侧栏隐藏,聊天面板占满 */
  .app.show-chat .sidebar { display: none; }
  .app.show-chat .chat { display: flex !important; }
  .back-btn { display: inline-flex; }
  /* 点击聊天页里的 ☰ 按钮:以浮层形式拉出侧栏,不退出聊天 */
  .sidebar-btn { display: inline-flex; }
  .app.show-sidebar .sidebar {
    position: fixed;
    inset: 0;
    z-index: 200;
    width: 86%;
    max-width: 360px;
    box-shadow: 4px 0 24px rgba(0,0,0,.45);
    animation: slideInSidebar .22s ease;
  }
  .app.show-sidebar::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 199;
    animation: fadeIn .18s ease;
  }
  .messages { padding: 12px 14px 8px; gap: 6px; }
  .msg { max-width: 86%; }
}

/* === 手机端小屏(<= 480px)细化 === */
@media (max-width: 480px) {
  /* 登录/注册卡片 */
  #screen-auth { padding: 14px; }
  .auth-card { padding: 22px 18px; border-radius: 14px; }
  .logo h1 { font-size: 22px; }
  .logo .logo-mark svg { width: 48px; height: 48px; }
  .form input { padding: 11px 13px; font-size: 16px; } /* iOS 不缩放 */
  .btn-primary { padding: 13px 16px; font-size: 15px; }
  .tabs { padding: 3px; }
  .tab { padding: 8px 0; font-size: 13px; }

  /* 侧栏头:小屏更紧凑 */
  .sidebar-header { padding: 8px 10px; gap: 8px; }
  .sidebar-header .icon-btn { width: 34px; height: 34px; }
  .sidebar-header .avatar { width: 36px; height: 36px; font-size: 14px; }
  .sidebar-header .me-meta .me-name { font-size: 14px; }
  .me-uid { font-size: 11px; }
  .sidebar-header .me { gap: 8px; min-width: 0; }
  .sidebar-tabs button { padding: 5px 10px; font-size: 12px; }
  .search-row { padding: 6px 8px; }
  .search-row input { padding: 7px 12px; font-size: 14px; }

  /* 聊天页头 */
  .chat-header { padding: 8px 8px; gap: 8px; }
  .chat-header .icon-btn { width: 34px; height: 34px; }
  .chat-header .avatar { width: 36px; height: 36px; font-size: 14px; }
  .peer-name { font-size: 14px; }
  .peer-sub { font-size: 11px; }

  /* 消息气泡 */
  .messages { padding: 10px 12px 6px; gap: 5px; }
  .msg { max-width: 88%; padding: 7px 10px; font-size: 14px; border-radius: 12px; }
  .msg .meta { font-size: 10px; margin-top: 3px; }
  .msg.image img { max-width: 220px; max-height: 260px; border-radius: 10px; }
  .msg.sticker img { width: 110px; height: 110px; }
  .msg.voice { min-width: 140px; }
  .msg.voice button { width: 28px; height: 28px; }
  .msg.file { min-width: 180px; }

  /* 输入行 */
  .composer { padding: 8px 8px; gap: 4px; }
  .composer .icon-btn { width: 34px; height: 34px; }
  #msg-input { padding: 8px 14px; font-size: 16px; } /* iOS 不缩放 */

  /* emoji / 录音 面板 */
  .emoji-panel { width: 94%; bottom: 56px; grid-template-columns: repeat(8, 1fr); padding: 8px; }
  .emoji-panel button { font-size: 20px; padding: 5px; }
  .recording-panel { bottom: 56px; padding: 7px 12px; }

  /* 抽屉 / 子页面 */
  .drawer-content {
    width: 100%; max-width: 100%;
    border-radius: 0;
  }
  .drawer { align-items: stretch; }
  .profile-header { padding: 18px 16px 14px; }
  .profile-header .avatar.huge { width: 80px; height: 80px; font-size: 30px; }
  .profile-name-row { font-size: 19px; }
  .profile-info { padding: 0 16px; }
  .profile-menu { padding: 0 8px 14px; }
  .profile-menu-item { padding: 13px 14px; font-size: 14px; }
  .subpage-header { padding: 8px 6px; }
  .subpage-header h2 { font-size: 16px; }
  .tiers { grid-template-columns: 1fr; gap: 8px; }
  .vanity-row input { padding: 8px 10px; font-size: 14px; }
  .info-block { padding: 14px 16px; font-size: 14px; }
  .member-picker { padding: 8px; }
  .member-row { padding: 8px; font-size: 14px; }

  /* 列表 */
  .list-item { padding: 9px 12px; gap: 10px; }
  .list-item .avatar { width: 38px; height: 38px; font-size: 14px; }
  .list-item .name { font-size: 14px; }
  .list-item .preview { font-size: 12px; }
  .unread-badge { font-size: 10px; padding: 1px 6px; min-width: 18px; }

  /* Toast */
  .toast { bottom: 70px; font-size: 13px; padding: 9px 16px; }

  /* 长按消息菜单 */
  .message-menu-item { padding: 13px 18px; font-size: 14px; }
}

/* === 极窄屏(<= 360px)再细化 === */
@media (max-width: 360px) {
  .msg { max-width: 92%; font-size: 13.5px; }
  .msg.image img { max-width: 180px; }
  .auth-card { padding: 20px 14px; }
}

/* === 横屏手机:消息区给消息多留位置 === */
@media (max-width: 800px) and (orientation: landscape) and (max-height: 480px) {
  .chat-header { padding: 6px 8px; }
  .composer { padding: 6px 8px; }
  .messages { padding: 8px 12px; }
}
@keyframes slideInSidebar {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* === PWA / iOS standalone / 安全区 === */
@supports (padding: max(0px)) {
  .sidebar-header { padding-top: max(12px, env(safe-area-inset-top)); }
  .chat-header { padding-top: max(10px, env(safe-area-inset-top)); }
  .composer { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .drawer-content { padding-top: max(24px, env(safe-area-inset-top)); padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  .subpage-header { padding-top: max(14px, env(safe-area-inset-top)); }
  .auth-card { margin-top: env(safe-area-inset-top); margin-bottom: env(safe-area-inset-bottom); }
}

/* 阻止橡皮筋刷新(整个页面不能下拉刷新) */
html, body { overscroll-behavior-y: contain; }
.sidebar, .messages, .drawer-content, .member-picker, .member-list { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }

/* iOS standalone 时隐藏地址栏 */
body { -webkit-tap-highlight-color: transparent; }

/* 上面的 @media (max-width: 480px) 已包含小屏侧栏头紧凑化,
   此处旧规则已并入,删除避免重复。 */

/* === 长按消息菜单 === */
.msg.longpress-flash { background: rgba(58,160,255,.25) !important; transition: background .15s; }

.message-menu {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 250;
  background: var(--bg-elev);
  border-radius: 16px 16px 0 0;
  padding: 8px 0 max(20px, env(safe-area-inset-bottom));
  box-shadow: 0 -4px 24px rgba(0,0,0,.5);
  animation: slideUpMenu .2s ease;
}
@keyframes slideUpMenu {
  from { transform: translateY(100%); }
  to { transform: none; }
}
.message-menu-item {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  padding: 14px 20px;
  text-align: left;
  font-size: 15px;
  color: var(--text);
  border: none;
  background: transparent;
}
.message-menu-item:active { background: var(--bg-elev-2); }
.message-menu-item.danger { color: var(--danger); }
.message-menu-item svg { color: inherit; opacity: .8; }
.message-menu-backdrop {
  position: fixed; inset: 0; z-index: 240;
  background: rgba(0,0,0,.5);
  animation: fadeIn .15s;
}

/* === 未读计数 === */
.unread-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  margin-left: auto;
  min-width: 20px;
  text-align: center;
}
.unread-badge.muted { background: var(--text-mute); }

/* === 未读分隔条 === */
.unread-divider {
  align-self: center;
  background: var(--accent);
  color: #fff;
  padding: 5px 14px;
  border-radius: 12px;
  font-size: 12px;
  margin: 8px auto;
  cursor: pointer;
  animation: msgIn .2s ease;
}

/* === 已读蓝色 === */
.msg.out .meta { color: var(--accent-2); }
.msg.out.delivered .meta { color: #5dade2; }

.msg .reply-quote {
  background: rgba(255,255,255,.08);
  border-left: 2px solid var(--accent);
  padding: 4px 8px;
  border-radius: 6px;
  margin-bottom: 4px;
  font-size: 12px;
  cursor: pointer;
}
.msg .reply-quote .q-name { color: var(--accent-2); font-weight: 600; margin-right: 6px; }
.msg .reply-quote .q-text { color: var(--text-dim); }

/* === 已撤回消息 === */
.msg.deleted {
  background: transparent !important;
  border: 1px dashed var(--border);
  color: var(--text-mute);
  font-style: italic;
  font-size: 12px;
  padding: 6px 12px;
}

/* === 群@提醒 === */
.msg .mention {
  background: rgba(58,160,255,.2);
  color: var(--accent-2);
  padding: 1px 4px;
  border-radius: 4px;
  font-weight: 500;
}

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-mute); }

/* === 群聊 === */
.list-item.group .avatar {
  background: linear-gradient(135deg, var(--accent), var(--vip));
}
.list-item.group .icon-btn.remove {
  width: 28px; height: 28px; font-size: 18px; color: var(--danger);
}

.member-picker {
  background: var(--bg-elev-2);
  border-radius: 12px;
  overflow: hidden;
  max-height: 360px;
  overflow-y: auto;
}
.member-picker .member-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--bg);
  cursor: pointer;
  transition: background .12s;
}
.member-picker .member-row:last-child { border-bottom: none; }
.member-picker .member-row:hover { background: var(--bg); }
.member-picker .member-row.selected { background: rgba(58,160,255,.15); }
.member-picker .check {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--text-mute);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-left: auto;
  color: transparent;
}
.member-picker .member-row.selected .check {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.member-list {
  background: var(--bg-elev-2);
  border-radius: 12px;
  overflow: hidden;
  margin: 0 22px 16px;
}
.member-list .member-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--bg);
}
.member-list .member-row:last-child { border-bottom: none; }
.member-list .meta { flex: 1; min-width: 0; }
.member-list .name { font-weight: 500; display: flex; align-items: center; gap: 6px; }
.member-list .role {
  font-size: 10px; padding: 2px 6px; border-radius: 4px;
  background: var(--bg); color: var(--text-dim); margin-left: 6px;
}
.member-list .role.owner { background: var(--accent); color: #fff; }
.member-list .role.admin { background: var(--vip); color: #fff; }
.member-list .kick {
  font-size: 12px; color: var(--danger);
  background: transparent; padding: 4px 8px; border-radius: 6px;
}
.member-list .kick:hover { background: rgba(229,57,53,.12); }

.msg .sender-name {
  font-size: 12px; font-weight: 600; margin-bottom: 2px;
  color: var(--accent-2);
}
.msg.in.grouped { margin-top: -2px; } /* 同人连续消息贴得更紧 */
