:root {
  --bg: #0e1116;
  --bg2: #151a21;
  --card: #1a2029;
  --line: #232b36;
  --text: #e8eef5;
  --muted: #8a97a6;
  --accent: #3b82f6;
  --bubble-me: #2b6cb0;
  --bubble-other: #1e252e;
  --radius: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
.dim { color: var(--muted); }
.screen { height: 100dvh; display: flex; flex-direction: column; }

/* ---------- 登录 ---------- */
#auth { align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--bg2); border: 1px solid var(--line);
  border-radius: 22px; padding: 28px 22px; box-shadow: 0 24px 70px rgba(0,0,0,.5);
}
.logo { font-size: 42px; text-align: center; }
.auth-card h1 { margin: 8px 0 2px; font-size: 22px; text-align: center; }
.sub { color: var(--muted); font-size: 12.5px; text-align: center; margin: 0 0 16px; }
.tabs { display: flex; gap: 6px; background: #0d1218; padding: 4px; border-radius: 12px; margin-bottom: 14px; }
.tab { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 9px; border-radius: 9px; font-size: 14px; }
.tab.active { background: var(--card); color: var(--text); }
.form { display: flex; flex-direction: column; gap: 10px; }
input, textarea {
  width: 100%; background: #0d1218; border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px 13px; font-size: 15px; outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
.btn { border: 0; background: var(--accent); color: #fff; border-radius: 12px; padding: 12px; font-size: 15px; font-weight: 600; }
.btn.ghost { background: #232b36; color: var(--text); }
.btn.small { padding: 8px 14px; font-size: 13.5px; border-radius: 10px; }
.msg { color: #ff8a8a; font-size: 13px; min-height: 18px; margin: 10px 0 0; text-align: center; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--bg2); border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.tb-title { flex: 1; font-size: 17px; font-weight: 700; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--line);
  background: #0d1218; color: var(--text); font-size: 17px; line-height: 1;
}

/* ---------- 视图 ---------- */
.view { flex: 1; overflow-y: auto; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
.list { display: flex; flex-direction: column; }
.empty { color: var(--muted); text-align: center; padding: 46px 20px; font-size: 13.5px; line-height: 1.9; }
.section-title { color: var(--muted); font-size: 12px; padding: 16px 16px 6px; }

/* ---------- 会话列表 ---------- */
.chat-item { display: flex; align-items: center; gap: 12px; padding: 11px 14px; }
.chat-item:active { background: #151b23; }
.chat-body { flex: 1; min-width: 0; }
.chat-line1 { display: flex; align-items: baseline; gap: 8px; }
.chat-name { font-size: 15.5px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-time { color: var(--muted); font-size: 11.5px; flex: 0 0 auto; }
.chat-line2 { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.chat-preview { color: var(--muted); font-size: 13px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread { flex: 0 0 auto; min-width: 19px; height: 19px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 11.5px; display: grid; place-items: center; }

/* ---------- 头像 ---------- */
.avatar {
  width: 48px; height: 48px; border-radius: 50%; flex: 0 0 auto; overflow: hidden;
  display: grid; place-items: center; font-size: 18px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden;
  background: linear-gradient(135deg, #2b6cb0, #6b46c1); background-size: cover; background-position: center;
}
.avatar.big { width: 84px; height: 84px; font-size: 30px; }
.avatar.sm { width: 30px; height: 30px; font-size: 12.5px; }

/* ---------- 联系人 ---------- */
.searchbar { padding: 10px 14px; }
.user-item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.user-item .who { flex: 1; min-width: 0; }
.user-item .name { font-size: 15px; font-weight: 600; }
.user-item .uid { color: var(--muted); font-size: 12px; }
.add-btn { border: 1px solid var(--accent); color: var(--accent); background: transparent; border-radius: 9px; padding: 7px 12px; font-size: 13px; }
.add-btn.done { border-color: var(--line); color: var(--muted); }
.row-item { display: flex; align-items: center; padding: 15px 16px; border-bottom: 1px solid var(--line); font-size: 15px; }
.row-item .chev { margin-left: auto; color: var(--muted); }
.profile { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 26px 16px 18px; }
.profile-name { font-size: 18px; font-weight: 700; }
.profile-id { color: var(--muted); font-size: 12.5px; }
.about { color: var(--muted); font-size: 12.5px; padding: 0 16px; }

/* ---------- 聊天窗口 ---------- */
.chat-pane { position: fixed; inset: 0; background: var(--bg); z-index: 10; display: flex; flex-direction: column; }
.chat-head { flex: 1; min-width: 0; }
.chat-head .chat-name { font-size: 15.5px; font-weight: 700; }
.chat-sub { color: var(--muted); font-size: 11.5px; }
.messages {
  flex: 1; overflow-y: auto; padding: 12px 12px 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.messages > :first-child { margin-top: auto; }
.day-divider { text-align: center; color: var(--muted); font-size: 11.5px; margin: 10px 0 6px; }
.msg-row { display: flex; align-items: flex-end; gap: 7px; margin-top: 2px; }
.msg-row.first { margin-top: 12px; }
.msg-row.me { flex-direction: row-reverse; }
.msg-col { display: flex; flex-direction: column; max-width: 78%; min-width: 0; }
.msg-row.me .msg-col { align-items: flex-end; }
.sender { color: var(--muted); font-size: 11.5px; margin: 0 4px 3px; }
.bubble {
  padding: 8px 12px; border-radius: 16px; font-size: 15px; line-height: 1.45;
  white-space: pre-wrap; overflow-wrap: anywhere; width: fit-content; max-width: 100%;
}
.msg-row.other .bubble { background: var(--bubble-other); border-bottom-left-radius: 6px; }
.msg-row.me .bubble { background: var(--bubble-me); border-bottom-right-radius: 6px; }
.msg-time { color: var(--muted); font-size: 10.5px; margin: 3px 4px 0; }
.avatar-holder { width: 30px; flex: 0 0 30px; }
.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: var(--bg2); border-top: 1px solid var(--line); flex: 0 0 auto;
}
.composer textarea { flex: 1; resize: none; max-height: 120px; border-radius: 20px; padding: 10px 14px; }
.send-btn {
  width: 42px; height: 42px; flex: 0 0 42px; border: 0; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 16px;
}

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex;
  background: var(--bg2); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 8;
}
.tabbar button {
  flex: 1; border: 0; background: none; color: var(--muted); font-size: 11px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; position: relative;
}
.tabbar button.on { color: var(--accent); }
.tabbar .ico { width: 22px; height: 22px; line-height: 1; }
.tabbar .ico svg { width: 100%; height: 100%; }
.badge {
  position: absolute; top: 2px; right: calc(50% - 24px);
  background: #e05252; color: #fff; font-size: 10.5px; border-radius: 9px; padding: 0 5px; line-height: 16px;
}

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.62); z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.modal-card {
  width: 100%; max-width: 560px; background: var(--bg2); border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 88dvh;
  display: flex; flex-direction: column; gap: 10px;
}
.modal-card h2 { margin: 0; font-size: 17px; }
.user-list { overflow-y: auto; max-height: 42dvh; display: flex; flex-direction: column; gap: 4px; }
.pick { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 12px; background: #0d1218; border: 1px solid var(--line); }
.pick.on { border-color: var(--accent); background: #14203a; }
.modal-actions { display: flex; gap: 8px; }
.modal-actions .btn { flex: 1; }
