:root {
  --bg: #f2f4f7;
  --panel: #ffffff;
  --line: #e5e8ee;
  --text: #14181f;
  --muted: #737b8c;
  --accent: #2f6df6;
  --accent-2: #3d7bfd;
  --danger: #d64545;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* 关键：hidden 属性必须优先于各区块的 display:flex/grid，否则弹层会全部常显 */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 15px;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; border: none; background: none; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }

/* ---------------- 登录 ---------------- */
.login {
  height: 100%; display: flex; align-items: center; justify-content: center;
  padding: 24px; background:
    radial-gradient(900px 500px at 50% -10%, #e8effe 0%, rgba(232,239,254,0) 70%), var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border-radius: 22px;
  padding: 30px 24px 24px; box-shadow: 0 24px 60px rgba(20, 24, 31, .12);
  text-align: center;
}
.logo {
  width: 54px; height: 54px; margin: 0 auto 12px; border-radius: 16px;
  display: grid; place-items: center; font-size: 26px;
  background: linear-gradient(160deg, #eaf0ff, #dfe8ff);
}
.login h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: .5px; }
.login-sub { margin: 0 0 22px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.field { display: block; text-align: left; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; padding-left: 2px; }
.field input {
  width: 100%; height: 46px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: #fafbfd; outline: none;
  transition: border-color .15s, background .15s;
}
.field input:focus { border-color: #b9cdfb; background: #fff; }
.primary {
  width: 100%; height: 46px; border-radius: 12px; margin-top: 6px;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff; font-weight: 600; letter-spacing: .5px;
  box-shadow: 0 8px 20px rgba(47, 109, 246, .28);
}
.primary:active { transform: translateY(1px); }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }
.login-tip { margin: 14px 0 0; font-size: 12px; color: #9aa2b1; }

/* ---------------- 主体 ---------------- */
.app { display: flex; height: 100dvh; overflow: hidden; }

.sidebar {
  width: 320px; flex: 0 0 320px; display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--line);
}
.me {
  display: flex; align-items: center; gap: 10px; padding: 14px 14px 12px;
  border-bottom: 1px solid var(--line);
}
.me-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.me-text b { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text span { font-size: 12px; color: var(--muted); }

.avatar {
  width: 36px; height: 36px; border-radius: 12px; flex: 0 0 36px;
  display: grid; place-items: center; color: #fff; font-size: 14px; font-weight: 600;
  background: #6b7280; overflow: hidden; user-select: none;
}
.avatar.sm { width: 32px; height: 32px; flex-basis: 32px; border-radius: 10px; font-size: 13px; }

.icon {
  width: 34px; height: 34px; flex: 0 0 34px; border-radius: 10px;
  display: grid; place-items: center; font-size: 18px; color: #5a6273;
}
.icon:hover { background: #f1f4f9; }
.icon.back { display: none; font-size: 26px; line-height: 1; }

.convos { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.convo {
  display: flex; gap: 10px; align-items: center; padding: 12px 14px;
  border-bottom: 1px solid #f3f5f8; cursor: pointer;
}
.convo:hover { background: #f8fafd; }
.convo.active { background: #eef4ff; }
.convo-main { flex: 1; min-width: 0; }
.convo-top { display: flex; align-items: baseline; gap: 6px; }
.convo-name { font-weight: 600; font-size: 14.5px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo-time { font-size: 11px; color: #a2a9b8; flex: 0 0 auto; }
.convo-last {
  font-size: 13px; color: var(--muted); margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: #f04452; color: #fff; font-size: 11px; font-weight: 600;
  display: grid; place-items: center; flex: 0 0 auto;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%; background: #22c55e; flex: 0 0 8px;
  box-shadow: 0 0 0 2px #fff;
}
.sidebar-foot { padding: 10px 14px; font-size: 11.5px; color: #a2a9b8; border-top: 1px solid var(--line); }

/* ---------------- 聊天区 ---------------- */
.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: #a2a9b8; font-size: 14px; text-align: center; }
.empty span { font-size: 13px; color: #b3b9c6; }
.chat-inner { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-head {
  display: flex; align-items: center; gap: 6px; padding: 10px 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding-top: max(10px, env(safe-area-inset-top));
}
.chat-title { display: flex; flex-direction: column; min-width: 0; }
.chat-title b { font-size: 15px; }
.chat-title span { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.msgs { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 0 12px; }
.day { text-align: center; font-size: 11.5px; color: #a2a9b8; margin: 12px 0 4px; }
.sys { text-align: center; font-size: 12px; color: #97a0b0; margin: 8px 0; }

.row { display: flex; gap: 8px; align-items: flex-end; margin: 6px 14px; }
.row.mine { flex-direction: row-reverse; }
.bubble {
  max-width: min(74%, 520px); padding: 9px 12px; border-radius: 14px;
  background: var(--panel); box-shadow: 0 1px 2px rgba(16, 24, 40, .06);
  font-size: 15px; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
  user-select: text;
}
.row.mine .bubble {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff; box-shadow: 0 6px 14px rgba(47, 109, 246, .22);
}
.bubble.recalled { background: #eceff4; color: #97a0b0; font-size: 13px; box-shadow: none; }
.row.mine .bubble.recalled { background: #eceff4; color: #97a0b0; box-shadow: none; }
.bubble img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; }
.bubble.image { padding: 3px; background: #fff; }
.row.mine .bubble.image { background: #fff; }

.composer {
  display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px;
  background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.composer textarea {
  flex: 1; min-height: 38px; max-height: 120px; padding: 9px 12px; resize: none;
  border: 1px solid var(--line); border-radius: 12px; background: #fafbfd; outline: none;
  line-height: 1.4;
}
.composer textarea:focus { border-color: #cbd9fb; background: #fff; }
.send {
  height: 38px; padding: 0 16px; border-radius: 12px; font-weight: 600;
  background: var(--accent); color: #fff; flex: 0 0 auto;
}
.send:disabled { background: #c8d3e8; }

.emoji {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  padding: 8px; background: var(--panel); border-top: 1px solid var(--line);
  max-height: 190px; overflow-y: auto;
}
.emoji button { height: 34px; font-size: 20px; border-radius: 8px; }
.emoji button:hover { background: #f1f4f9; }

/* ---------------- 弹层 ---------------- */
.sheet {
  position: fixed; inset: 0; z-index: 40; background: rgba(16, 24, 40, .38);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-body {
  width: 100%; max-width: 460px; background: var(--panel);
  border-radius: 20px 20px 0 0; padding: 16px 16px max(16px, env(safe-area-inset-bottom));
  max-height: 80dvh; display: flex; flex-direction: column;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.sheet-tip { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.picks { overflow-y: auto; margin-bottom: 10px; }
.pick {
  display: flex; align-items: center; gap: 10px; padding: 11px 8px;
  border-radius: 10px; cursor: pointer;
}
.pick:hover { background: #f6f8fc; }
.pick.on { background: #eef4ff; }
.pick-name { flex: 1; font-size: 14.5px; }
.pick .check { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid #cbd2df; display: grid; place-items: center; font-size: 12px; color: #fff; }
.pick.on .check { background: var(--accent); border-color: var(--accent); }
.group-name {
  height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: #fafbfd; outline: none; margin-bottom: 10px;
}

/* 我的 ID */
.my-code {
  margin-top: 2px; padding: 0; text-align: left; font-size: 11.5px;
  color: #7b8496; letter-spacing: .3px; cursor: pointer;
}
.my-code:hover { color: var(--accent); }

.list-empty { padding: 40px 20px; text-align: center; color: #a2a9b8; font-size: 13px; line-height: 1.9; }

.sidebar-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.admin-link { color: var(--accent); text-decoration: none; font-size: 11.5px; }
.wx-btn {
  font-size: 11.5px; color: #17794a; background: #e6f7ec;
  padding: 3px 9px; border-radius: 999px; font-weight: 600; flex: 0 0 auto;
}
.wx-btn.on { color: #7b8496; background: #eef1f6; font-weight: 400; }
.logout-btn { font-size: 11.5px; color: #9aa2b1; background: none; padding: 3px 2px; flex: 0 0 auto; }
.logout-btn:hover { color: var(--danger); }

/* 登录/注册 tab */
.tabs { display: flex; gap: 4px; background: #f1f3f7; border-radius: 12px; padding: 4px; margin: 0 0 18px; }
.tab {
  flex: 1; height: 36px; border: 0; background: transparent; border-radius: 9px;
  font-size: 14px; color: #7b8496; cursor: pointer; transition: all .15s;
}
.tab.on { background: #fff; color: #1b1f27; font-weight: 600; box-shadow: 0 1px 4px rgba(20,24,31,.08); }
.big-code {
  font-size: 32px; font-weight: 700; letter-spacing: 4px; color: var(--accent);
  margin: 18px 0 4px; font-variant-numeric: tabular-nums; user-select: all;
}

/* 加好友 */
.add-friend { display: flex; gap: 8px; margin-bottom: 8px; }
.add-friend input {
  flex: 1; height: 40px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: #fafbfd; outline: none;
  font-size: 14px; letter-spacing: 1px; text-transform: uppercase;
}
.add-friend input:focus { border-color: #cbd9fb; background: #fff; }
.add-friend button {
  height: 40px; padding: 0 14px; border-radius: 10px; flex: 0 0 auto;
  background: #eef4ff; color: #2a5fd0; font-weight: 600; font-size: 13.5px;
}
.search-result {
  display: flex; align-items: center; gap: 10px; padding: 10px 10px;
  background: #f6f9ff; border: 1px solid #e2ebfd; border-radius: 12px;
  margin-bottom: 10px; font-size: 13px; color: var(--muted);
}
.sr-main { flex: 1; min-width: 0; }
.sr-name { font-weight: 600; color: var(--text); font-size: 14px; }
.sr-code { font-size: 11.5px; color: #8b94a6; margin-top: 1px; letter-spacing: .5px; }
.sr-btn {
  height: 30px; padding: 0 12px; border-radius: 8px; font-size: 12.5px;
  background: var(--accent); color: #fff; font-weight: 600;
}
.sr-btn.ghost { background: #e7ecf6; color: #7b8496; }

/* 自动删除 */
.ttl-bar {
  padding: 6px 14px; font-size: 11.5px; color: #8a6d1f;
  background: #fff8e6; border-bottom: 1px solid #f3e6c4;
  text-align: center;
}
.ttl-opts { display: flex; flex-direction: column; gap: 6px; }
.ttl-opt {
  padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  font-size: 14.5px; cursor: pointer;
}
.ttl-opt:hover { background: #f7f9fd; }
.ttl-opt.on { border-color: var(--accent); background: #eef4ff; color: #2455c0; font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translate(-50%, 20px);
  background: rgba(20, 24, 31, .88); color: #fff; font-size: 13px;
  padding: 9px 16px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: .2s; z-index: 60; max-width: 80vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- 移动端 ---------------- */
@media (max-width: 760px) {
  .app { position: relative; }
  .sidebar { width: 100%; flex-basis: 100%; border-right: none; }
  .chat {
    position: absolute; inset: 0; z-index: 20;
    transform: translateX(100%); transition: transform .22s ease;
    background: var(--bg);
  }
  .app.chat-open .chat { transform: translateX(0); }
  .icon.back { display: grid; }
  .bubble { max-width: 80%; }
  .login-card { padding: 26px 20px 20px; }
}
