:root {
  --bg: #f4f5f7; --panel: #fff; --line: #e3e5e8; --text: #1d2129; --muted: #6b7280;
  --accent: #2563eb; --accent-text: #fff; --mine: #2563eb; --mine-text: #fff; --theirs: #eef0f3;
  --danger: #c62828; --radius: 10px;
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111317; --panel: #1a1d23; --line: #2a2e36; --text: #e6e8eb; --muted: #9aa1ab;
    --theirs: #262a31; --mine: #3b6fe0; --danger: #ef5350; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 8px; padding: 8px 14px; background: var(--accent); color: var(--accent-text); }
button:focus-visible, input:focus-visible, textarea:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
button.danger { background: var(--danger); }
button.link { background: none; color: var(--muted); padding: 4px; }
button.icon { background: none; color: var(--text); font-size: 22px; padding: 4px 10px; }
button.full { width: 100%; }
button:disabled { opacity: .5; cursor: default; }
input, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.err { color: var(--danger); min-height: 1.2em; margin: 4px 0; }
.muted { color: var(--muted); }

/* 登录 */
.login { display: grid; place-items: center; height: 100%; padding: 16px; }
.card { background: var(--panel); padding: 28px; border-radius: var(--radius); width: min(360px, 100%); display: grid; gap: 8px; border: 1px solid var(--line); }
.card h1 { margin: 0 0 8px; font-size: 22px; }
.card input { font-size: 18px; }
#login-code { letter-spacing: 6px; }

/* 布局 */
.app { display: flex; height: 100%; }
.sidebar { width: 300px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.side-head { padding: 12px; border-bottom: 1px solid var(--line); }
.me { font-weight: 600; }
.tabs { display: flex; gap: 4px; margin-top: 10px; }
.tabs button { flex: 1; background: none; color: var(--muted); padding: 6px; position: relative; }
.tabs button[aria-selected="true"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.tab-body { flex: 1; overflow-y: auto; padding: 10px; }
.tab-body h3 { font-size: 13px; color: var(--muted); margin: 14px 4px 6px; font-weight: 500; }
.side-foot { padding: 8px 12px; border-top: 1px solid var(--line); }
.row { display: flex; gap: 6px; }
.row input { flex: 1; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 12px; line-height: 18px; margin-left: 4px; }

.list { list-style: none; margin: 8px 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: 8px; }
.list li.clickable { cursor: pointer; }
.list li.clickable:hover, .list li.active { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.list .grow { flex: 1; min-width: 0; }
.list .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list button { padding: 4px 10px; font-size: 13px; }
.c0 { background: #c62828; } .c1 { background: #ad1457; } .c2 { background: #6a1b9a; } .c3 { background: #283593; } .c4 { background: #0277bd; }
.c5 { background: #00695c; } .c6 { background: #2e7d32; } .c7 { background: #b45309; } .c8 { background: #5d4037; } .c9 { background: #455a64; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 600; flex-shrink: 0; }

/* 聊天区 */
.chat { flex: 1; display: flex; min-width: 0; }
.empty { margin: auto; color: var(--muted); }
.chat-inner { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.chat-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.chat-head h2 { flex: 1; margin: 0; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#back { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: min(70%, 560px); display: flex; flex-direction: column; align-self: flex-start; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg .who { font-size: 12px; color: var(--muted); margin: 0 6px 2px; }
.bubble { background: var(--theirs); padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; }
.msg.mine .bubble { background: var(--mine); color: var(--mine-text); }
.msg.pending .bubble { opacity: .6; }
.msg.failed .bubble { outline: 2px solid var(--danger); }
.msg .time { font-size: 11px; color: var(--muted); margin: 2px 6px 0; }
.sys { align-self: center; font-size: 12px; color: var(--muted); background: var(--theirs); padding: 3px 10px; border-radius: 10px; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 8px 0; }
.file { display: flex; gap: 10px; align-items: center; text-decoration: none; color: inherit; }
.file .ico { font-size: 28px; }
.file .meta { font-size: 12px; opacity: .8; }
.bubble img, .bubble video { max-width: 100%; max-height: 320px; border-radius: 8px; display: block; }
.bubble a { color: inherit; }
.more { align-self: center; }

.uploads { padding: 0 12px; }
.up { display: flex; gap: 8px; align-items: center; font-size: 13px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin-top: 6px; }
.up .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up progress { width: 120px; }
.up button { padding: 2px 8px; font-size: 12px; }

.composer { display: flex; gap: 6px; align-items: flex-end; padding: 10px; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.composer textarea { flex: 1; resize: none; max-height: 160px; }
.file-btn { cursor: pointer; font-size: 22px; padding: 4px 6px; }
.drop { position: absolute; inset: 0; display: grid; place-items: center; font-size: 20px; background: color-mix(in srgb, var(--accent) 20%, transparent); border: 3px dashed var(--accent); pointer-events: none; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); width: min(420px, 92vw); padding: 20px; }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog h3 { margin: 0 0 12px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
dialog label.check { display: flex; gap: 8px; align-items: center; padding: 6px 0; }
dialog input[type=text] { width: 100%; }
.qr { text-align: center; padding: 10px; }
.qr img { width: 240px; max-width: 100%; background: #fff; padding: 8px; border-radius: 8px; }
.menu-list { display: grid; gap: 8px; }
.menu-list button { text-align: left; }

/* 手机：单栏切换 */
@media (max-width: 720px) {
  .sidebar { width: 100%; border-right: 0; }
  .app.in-chat .sidebar { display: none; }
  .app:not(.in-chat) .chat { display: none; }
  #back { display: block; }
  .msg { max-width: 85%; }
}
