:root {
  --bg: #f4f2ee; --panel: #fff; --ink: #1d1b19; --muted: #6f6a64; --line: #e4dfd8;
  --accent: #2f6b5a; --accent-ink: #fff; --warn: #9a5b00; --bad: #b42318; --mine: #e5f1ec;
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink); background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151615; --panel: #1e201f; --ink: #ecebe8; --muted: #a29d96; --line: #2f3230; --accent: #5fb39a; --accent-ink: #0c1411; --mine: #22332d; --warn: #e3a64a; --bad: #ff7b72; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
[hidden] { display: none !important; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.86em; word-break: break-all; }
h1 { margin: 0 0 6px; font-size: 28px; letter-spacing: -0.02em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.sub { color: var(--muted); margin: 0 0 16px; line-height: 1.5; }
input, textarea { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; width: 100%; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn { font: inherit; font-weight: 600; border: 0; border-radius: 8px; padding: 10px 16px; background: var(--accent); color: var(--accent-ink); cursor: pointer; min-height: 44px; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 14px; }
.link { background: none; border: 0; padding: 4px 0; color: var(--accent); font: inherit; font-size: 13px; cursor: pointer; }

/* 登录 */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(460px, 100%); display: grid; gap: 12px; }
.card label { font-size: 14px; font-weight: 600; }
.keyrow { display: flex; gap: 8px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400 !important; color: var(--muted); }
.check input { width: auto; }
.warn { border-left: 3px solid var(--warn); padding: 8px 12px; background: color-mix(in srgb, var(--warn) 10%, transparent); font-size: 14px; line-height: 1.55; }
.err { color: var(--bad); min-height: 1em; margin: 0; }
.facts { margin: 4px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.7; }

/* 主画面 */
.app { display: grid; grid-template-columns: 300px 1fr; height: 100dvh; }
.side { border-right: 1px solid var(--line); background: var(--panel); padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; }
.me { display: flex; gap: 10px; align-items: flex-start; }
.me img, .conv img, .member img { width: 36px; height: 36px; border-radius: 8px; flex: none; }
.meinfo { min-width: 0; }
.mebtns { display: flex; gap: 12px; }
.keybox { display: block; margin-top: 6px; padding: 8px; border-radius: 6px; background: color-mix(in srgb, var(--warn) 14%, transparent); user-select: all; }
.mini { display: grid; gap: 8px; }
.listh { margin-bottom: -10px; }
.convs { display: grid; gap: 4px; }
.conv { display: flex; align-items: center; gap: 10px; border: 0; background: none; color: inherit; font: inherit; padding: 8px; border-radius: 8px; cursor: pointer; text-align: left; min-height: 48px; }
.conv:hover { background: var(--bg); }
.conv.active { background: var(--mine); }
.ctitle { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: 12px; padding: 1px 7px; font-weight: 700; }
.invite { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; border: 1px solid var(--accent); border-radius: 10px; padding: 8px; font-size: 14px; }
.invite img { width: 28px; height: 28px; border-radius: 6px; }
.invite span { flex: 1; }

.main { min-width: 0; display: flex; flex-direction: column; }
.empty { margin: auto; text-align: center; padding: 24px; }
.chat { display: flex; flex-direction: column; height: 100dvh; }
.chathead { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.ttl { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ttl code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 600; }
.status { font-size: 12px; }
.status.ok { color: var(--accent); }
.status.wait { color: var(--warn); }
.backbtn { display: none; }
.chatbody { flex: 1; display: flex; min-height: 0; }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.members { width: 220px; border-left: 1px solid var(--line); padding: 12px; overflow-y: auto; display: none; flex-direction: column; gap: 4px; background: var(--panel); }
.show-members .members { display: flex; }
.member { display: flex; align-items: center; gap: 8px; border: 0; background: none; color: inherit; font: inherit; font-size: 13px; padding: 6px; border-radius: 8px; cursor: pointer; text-align: left; }
.member:hover { background: var(--bg); }
.member img { width: 28px; height: 28px; }
.sys { align-self: center; color: var(--muted); font-size: 12px; text-align: center; max-width: 80%; }
.msg { display: flex; gap: 10px; max-width: min(720px, 92%); }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg .avatar { width: 32px; height: 32px; border-radius: 8px; cursor: pointer; flex: none; }
.msg .body { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; min-width: 0; }
.msg.mine .body { background: var(--mine); }
.msg.bad .text { color: var(--bad); font-style: italic; }
.head { display: flex; gap: 8px; align-items: baseline; font-size: 12px; color: var(--muted); margin-bottom: 2px; flex-wrap: wrap; }
.head b { color: var(--ink); font-weight: 600; }
.verified { color: var(--accent); }
.text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
.sendbar { display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
.sendbar textarea { resize: none; max-height: 160px; }
.sendbar .btn { white-space: nowrap; flex: none; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 10; }

/* 手机：列表与聊天分开两页 */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side { border-right: 0; }
  .main { display: none; }
  .chatting .side { display: none; }
  .chatting .main { display: flex; }
  .backbtn { display: inline-block; }
  .show-members .members { position: absolute; right: 0; top: 60px; bottom: 70px; z-index: 5; box-shadow: -4px 0 16px rgba(0,0,0,.15); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
