:root {
  --bg: #ffffff; --side: #f6f7f8; --line: #e8eaed; --text: #15171a; --muted: #8a9099;
  --accent: #2f6df6; --accent-text: #fff; --bubble: #f0f2f5; --danger: #d93a3a; --ok: #2bb673;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111315; --side: #17191c; --line: #25282c; --text: #e9eaec; --muted: #7d838c; --bubble: #212428; --accent: #4a82ff; }
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body { font: 15px/1.45 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Segoe UI", sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 14px; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
button.danger { color: var(--danger); }
.icon { border: 0; background: none; font-size: 20px; padding: 4px 8px; line-height: 1; cursor: pointer; color: var(--muted); }
.icon:hover { color: var(--text); }
input, select, textarea { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--bg); outline: none; width: 100%; }
input:focus, textarea:focus { border-color: var(--accent); }
.muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; } .grow { flex: 1; min-width: 0; }
[hidden] { display: none !important; }

#shield { position: fixed; inset: 0; z-index: 9999; display: grid; place-items: center; background: var(--bg); }
body.shielded > :not(#shield) { visibility: hidden; }
#onboard, #lock { height: 100%; display: grid; place-items: center; padding: 16px; }
.card { width: 100%; max-width: 360px; display: grid; gap: 14px; text-align: center; }
.logo { font-size: 48px; color: var(--accent); }

#app { display: flex; height: 100dvh; }
#side { width: 320px; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
#side > header, #chatHead { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); min-height: 60px; }
.me { display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 0; flex: 1; text-align: left; font-weight: 600; min-width: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--ok); }
.avatar { width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 15px; }
#list { list-style: none; padding: 6px; overflow-y: auto; flex: 1; }
#list li { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 12px; cursor: pointer; }
#list li:hover { background: var(--line); }
#list li.active { background: var(--bg); box-shadow: 0 0 0 1px var(--line); }
#list .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#list .last { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#list .badge { background: var(--accent); color: #fff; border-radius: 10px; font-size: 12px; padding: 1px 7px; }
#list .req { color: var(--accent); font-size: 12px; }
#empty { padding: 40px 20px; }

#chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#noChat { margin: auto; }
#chatHead .back { display: none; font-size: 28px; }
#request { display: flex; gap: 8px; align-items: center; padding: 10px 14px; background: var(--side); border-bottom: 1px solid var(--line); font-size: 14px; }
#request span { flex: 1; }
#msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 3px; }
.msg { max-width: min(75%, 520px); padding: 8px 12px; border-radius: 18px; background: var(--bubble); align-self: flex-start; white-space: pre-wrap; word-wrap: break-word; }
.msg.mine { background: var(--accent); color: var(--accent-text); align-self: flex-end; }
.msg img { display: block; max-width: 100%; max-height: 320px; border-radius: 12px; margin: -4px -8px; }
.meta { font-size: 11px; color: var(--muted); align-self: flex-start; margin: 0 6px 8px; }
.meta.mine { align-self: flex-end; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 12px 0 6px; }
#composer, #recBar { display: flex; align-items: flex-end; gap: 6px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
#composer textarea { resize: none; border-radius: 20px; max-height: 140px; }
.send { border-radius: 50%; width: 40px; height: 40px; padding: 0; background: var(--accent); color: #fff; border: 0; flex: none; }

dialog { border: 0; border-radius: 16px; padding: 22px; width: min(400px, calc(100vw - 32px)); background: var(--bg); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog > * + * { margin-top: 12px; }
dialog label { display: grid; gap: 6px; font-size: 14px; }
dialog label.check { display: flex; align-items: center; gap: 8px; }
dialog label.check input { width: auto; }
dialog hr { border: 0; border-top: 1px solid var(--line); }
dialog .close { width: 100%; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
#qr { display: grid; place-items: center; }
#qr svg { width: 220px; height: 220px; background: #fff; border-radius: 12px; padding: 8px; }
.safety { font: 15px/1.7 ui-monospace, Menlo, monospace; letter-spacing: 1px; text-align: center; background: var(--side); border-radius: 10px; padding: 10px; }
code { display: block; word-break: break-all; background: var(--side); padding: 8px; border-radius: 8px; }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 20px; font-size: 14px; }

@media (max-width: 720px) {
  #side { width: 100%; border-right: 0; }
  #app.in-chat #side { display: none; }
  #app:not(.in-chat) #chat { display: none; }
  #chatHead .back { display: block; }
}

.error { color: var(--danger); font-size: 14px; }
button.link { border: 0; background: none; color: var(--muted); font-size: 13px; text-decoration: underline; }
button:disabled { opacity: .6; cursor: default; }
#lockBtn { font-size: 16px; }

.attach { display: grid; place-items: center; height: 40px; }
.send svg { display: block; margin: auto; }
#recBar { align-items: center; display: flex; }
.recdot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
#recTime { font-variant-numeric: tabular-nums; min-width: 40px; }
@keyframes blink { 50% { opacity: .2; } }
.msg.media { padding: 4px; }
.msg.media video { display: block; max-width: 100%; max-height: 360px; border-radius: 14px; background: #000; }
.msg.media audio { display: block; width: 260px; max-width: 100%; height: 40px; }
.msg.file { padding: 0; }
.filecard { display: flex; gap: 10px; align-items: center; padding: 10px 14px; color: inherit; text-decoration: none; }
.ficon { font-size: 26px; }
.fmeta { display: grid; min-width: 0; }
.fmeta b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.fmeta small, .fnote { font-size: 12px; opacity: .75; }
.fname { padding: 6px 10px; }
.fnote { padding: 2px 10px 4px; }
.fnote.retry { cursor: pointer; text-decoration: underline; opacity: 1; }

.avatar.group { border-radius: 12px; }
.sender { font-size: 12px; color: var(--muted); margin: 6px 12px 1px; }
.picklist { list-style: none; padding: 0; max-height: 240px; overflow-y: auto; }
.picklist label, .picklist .member { display: flex; flex-direction: row; align-items: center; gap: 10px; padding: 6px 0; font-size: 15px; }
.picklist input { width: auto; }
.picklist .avatar { width: 30px; height: 30px; font-size: 13px; }
button.small { padding: 4px 10px; font-size: 13px; }
details summary { cursor: pointer; font-size: 14px; color: var(--accent); }
details > * + * { margin-top: 8px; }

.backup-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--side); border-radius: 12px; font-size: 14px; }
#bkAttSize { margin-left: 4px; }
