:root {
  --bg: #0f1222; --panel: #171b31; --panel2: #1f2440; --line: #2a3054;
  --text: #eef0fa; --muted: #9aa0c3; --accent: #5b8cff; --accent2: #7b5bff;
  --mine: linear-gradient(135deg, #5b8cff, #7b5bff); --theirs: #232946;
  --danger: #ff5b7a; --ok: #3ddc97; --warn: #ffb547;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
#app { height: 100dvh; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, textarea { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; width: 100%; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); }
.btn { background: var(--mine); color: #fff; border-radius: 12px; padding: 13px 18px; font-weight: 600; width: 100%; }
.btn:disabled { opacity: .5; }
.btn.secondary { background: var(--panel2); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.small { width: auto; padding: 8px 12px; font-size: 14px; }
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; min-height: 1.2em; }
.splash { flex: 1; display: grid; place-items: center; align-content: center; gap: 12px; color: var(--muted); }

/* lock logo */
.logo-lock { flex: none; width: 64px; height: 64px; border-radius: 18px; background: var(--mine); position: relative; box-shadow: 0 10px 30px #5b8cff55; }
.logo-lock::before { content: ""; position: absolute; left: 20px; top: 12px; width: 24px; height: 20px; border: 5px solid #fff; border-bottom: 0; border-radius: 14px 14px 0 0; }
.logo-lock::after { content: ""; position: absolute; left: 15px; top: 30px; width: 34px; height: 24px; background: #fff; border-radius: 6px; }

/* auth */
.auth { flex: 1; overflow: auto; padding: calc(32px + var(--safe-top)) 24px calc(24px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 14px; }
.auth h1 { margin: 8px 0 0; font-size: 26px; }
.auth .tabs { display: flex; background: var(--panel); border-radius: 12px; padding: 4px; }
.auth .tabs button { flex: 1; padding: 10px; border-radius: 9px; color: var(--muted); font-weight: 600; }
.auth .tabs button.on { background: var(--panel2); color: var(--text); }
.auth form { display: flex; flex-direction: column; gap: 12px; }
.auth label { font-size: 13px; color: var(--muted); margin-bottom: -6px; }
.badge-e2e { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--ok); }
.badge-e2e::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }

/* header */
.top { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-top)) 12px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.top h2 { flex: 1; margin: 0; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .sub { display: block; font-size: 12px; color: var(--ok); font-weight: 400; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; background: var(--panel2); flex: none; }
.back { font-size: 26px; background: none; }

/* lists */
.list { flex: 1; overflow: auto; padding-bottom: calc(80px + var(--safe-bottom)); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid #ffffff08; width: 100%; text-align: left; }
.row:active { background: var(--panel); }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; flex: none; color: #fff; }
.row .main { flex: 1; min-width: 0; }
.row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .preview { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .time { color: var(--muted); font-size: 12px; align-self: flex-start; margin-top: 4px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none; }
.fab { position: fixed; right: max(20px, calc(50% - 340px)); bottom: calc(22px + var(--safe-bottom)); width: 60px; height: 60px; border-radius: 20px;
  background: var(--mine); color: #fff; font-size: 30px; box-shadow: 0 10px 30px #5b8cff66; }
.empty { padding: 40px 24px; text-align: center; color: var(--muted); }
.check { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; font-size: 14px; }
.check.on { background: var(--accent); border-color: var(--accent); }

/* chat */
.chat { flex: 1; overflow: auto; padding: 12px 12px 6px; display: flex; flex-direction: column; gap: 4px; }
.msg { max-width: 80%; padding: 8px 12px 6px; border-radius: 18px; background: var(--theirs); align-self: flex-start; word-wrap: break-word; white-space: pre-wrap; }
.msg.mine { background: var(--mine); align-self: flex-end; border-bottom-right-radius: 6px; }
.msg.theirs { border-bottom-left-radius: 6px; }
.msg .who { font-size: 12px; font-weight: 700; color: #9fb8ff; margin-bottom: 2px; }
.msg .meta { font-size: 11px; opacity: .7; text-align: right; margin-top: 2px; }
.msg.bad { background: #3a1f2a; color: #ffb3c2; font-style: italic; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); padding: 4px 10px; border-radius: 10px; margin: 8px 0; }
.e2e-note { align-self: center; text-align: center; font-size: 12px; color: var(--warn); background: #2b2616; padding: 8px 12px; border-radius: 10px; margin: 6px 0; max-width: 90%; }
.composer { display: flex; gap: 8px; padding: 8px 10px calc(8px + var(--safe-bottom)); background: var(--panel); border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { resize: none; max-height: 140px; min-height: 46px; border-radius: 22px; padding: 11px 16px; }
.send { width: 46px; height: 46px; border-radius: 50%; background: var(--mine); color: #fff; font-size: 20px; flex: none; }
.warnbar { background: #3b2a12; color: var(--warn); padding: 10px 14px; font-size: 14px; }

/* pages */
.page { flex: 1; overflow: auto; padding: 16px 16px calc(24px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card h3 { margin: 0; font-size: 16px; }
.safety { font: 600 18px/1.6 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 1px; color: #cfe0ff; word-spacing: 6px; }
.code { font: 700 24px ui-monospace, Menlo, monospace; letter-spacing: 3px; color: var(--ok); text-align: center; padding: 10px; background: var(--bg); border-radius: 10px; user-select: all; }
.inline { display: flex; gap: 8px; align-items: center; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 8px; background: var(--panel2); color: var(--muted); }
.tag.admin { color: var(--warn); }
.tag.off { color: var(--danger); }
.toast { position: fixed; left: 50%; bottom: calc(100px + var(--safe-bottom)); transform: translateX(-50%); background: #000c; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 9; }
