:root {
  --bg: #faf9f6;
  --panel: #ffffff;
  --line: #e8e4dc;
  --text: #23211d;
  --muted: #8b857a;
  --mine: #3d7ae0;
  --mine-text: #ffffff;
  --other: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

button { font: inherit; }

/* ───── 登录 ───── */

.auth {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 26px 22px 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .05);
}

.card h1 { margin: 0; font-size: 22px; letter-spacing: .04em; }
.card .sub { margin: 6px 0 18px; color: var(--muted); font-size: 13px; }

.tabs {
  display: flex;
  gap: 6px;
  background: #f2efe9;
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 16px;
}

.tabs button {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 0;
  border-radius: 9px;
  font-size: 14px;
  cursor: pointer;
}

.tabs button.on {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
  font-weight: 600;
}

#authForm { display: flex; flex-direction: column; gap: 10px; }

#authForm input {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fbfaf7;
  font-size: 15px;
  color: var(--text);
  outline: none;
}

#authForm input:focus { border-color: #c9c1b3; background: #fff; }

#authForm button[type=submit] {
  margin-top: 6px;
  padding: 12px;
  border: 0;
  border-radius: 11px;
  background: var(--mine);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

#authForm button[type=submit]:disabled { opacity: .6; }

.err { margin: 2px 0 0; min-height: 18px; color: #d9453f; font-size: 13px; }

/* ───── 通用骨架 ───── */

.screen { height: 100%; display: flex; flex-direction: column; }

.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(250, 249, 246, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
  flex: none;
}

.titles { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.titles strong { font-size: 16px; }
.titles .sub { color: var(--muted); font-size: 12px; }

.ghost {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  border-radius: 10px;
  padding: 6px 11px;
  font-size: 13px;
  cursor: pointer;
  position: relative;
  flex: none;
}

.ghost.icon {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  border-radius: 11px;
}

.badge {
  position: absolute;
  top: -6px;
  right: -5px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: #e04a43;
  color: #fff;
  font-size: 11px;
  line-height: 17px;
  text-align: center;
}

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

.empty.small { padding: 16px 8px; }

/* ───── 会话列表 ───── */

.convList { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }

.conv {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.conv:active { background: #f3f0ea; }

.convMain { flex: 1; min-width: 0; }
.convName { font-size: 15px; font-weight: 600; }
.convPreview {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.convSide { color: var(--muted); font-size: 11px; flex: none; }
.convTime { white-space: nowrap; }

/* ───── 聊天 ───── */

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex: none;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg { display: flex; gap: 8px; align-items: flex-start; max-width: 100%; }
.msg.mine { flex-direction: row-reverse; }
.mine .avatar { display: none; }

.stack { display: flex; flex-direction: column; gap: 3px; max-width: min(78%, 560px); }
.mine .stack { align-items: flex-end; }

.who { font-size: 11px; color: var(--muted); padding: 0 3px; }

.bubble {
  background: var(--other);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 12px;
  overflow: hidden;
  word-break: break-word;
  white-space: pre-wrap;
}

.mine .bubble { background: var(--mine); border-color: var(--mine); color: var(--mine-text); }

.bubble.media { padding: 4px; }
.bubble.media .text { padding: 4px 8px 6px; }

.bubble img, .bubble video {
  display: block;
  max-width: 100%;
  max-height: 340px;
  border-radius: 11px;
}

.bubble audio { width: 240px; max-width: 100%; }

.file { display: flex; align-items: center; gap: 9px; text-decoration: none; color: inherit; padding: 4px 2px; }
.file .ico { font-size: 22px; }
.file .meta { display: flex; flex-direction: column; }
.file .meta small { color: var(--muted); font-size: 11px; }
.mine .file .meta small { color: rgba(255, 255, 255, .78); }

.time { font-size: 11px; color: var(--muted); padding: 0 3px; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex: none;
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfaf7;
  font: inherit;
  color: var(--text);
  outline: none;
}

.composer textarea:focus { border-color: #c9c1b3; background: #fff; }

.composer button[type=submit] {
  flex: none;
  padding: 9px 16px;
  height: 38px;
  border: 0;
  border-radius: 12px;
  background: var(--mine);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.composer button[type=submit]:disabled { opacity: .55; }

/* ───── 好友 ───── */

.friendsBody { flex: 1; overflow-y: auto; padding-bottom: max(16px, env(safe-area-inset-bottom)); }

.searchRow {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 2;
}

.searchRow input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fbfaf7;
  font-size: 14px;
  outline: none;
  min-width: 0;
}

.searchRow input:focus { border-color: #c9c1b3; background: #fff; }

.searchRow button {
  flex: none;
  padding: 0 15px;
  border: 0;
  border-radius: 11px;
  background: var(--mine);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

.groupTitle {
  padding: 14px 14px 6px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .04em;
}

.row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 14px;
}

.row.clickable { cursor: pointer; }
.rowMain { flex: 1; min-width: 0; }
.rowName { font-size: 15px; }
.rowSub { font-size: 12px; color: var(--muted); }
.rowRight { display: flex; align-items: center; gap: 6px; flex: none; }

.mini {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  border-radius: 9px;
  padding: 5px 11px;
  font-size: 13px;
  cursor: pointer;
}

.mini.primary { background: var(--mine); border-color: var(--mine); color: #fff; }
.mini:disabled { opacity: .5; cursor: default; }

.tag { font-size: 12px; color: var(--muted); }

/* ───── 提示 ───── */

.toast {
  position: fixed;
  left: 50%;
  bottom: 76px;
  transform: translateX(-50%);
  background: rgba(35, 33, 29, .92);
  color: #fff;
  padding: 9px 15px;
  border-radius: 10px;
  font-size: 13px;
  max-width: 80vw;
  z-index: 20;
}

@media (min-width: 700px) {
  .messages { padding: 18px max(12px, calc((100% - 720px) / 2)); }
  .composer { padding-left: max(10px, calc((100% - 720px) / 2)); padding-right: max(10px, calc((100% - 720px) / 2)); }
  .top { padding-left: max(14px, calc((100% - 720px) / 2)); padding-right: max(14px, calc((100% - 720px) / 2)); }
  .convList, .friendsBody { padding-left: max(0px, calc((100% - 720px) / 2)); padding-right: max(0px, calc((100% - 720px) / 2)); }
}
