:root { --bg: #f4f5f7; --card: #fff; --ink: #1c1f24; --muted: #6b7280; --line: #e3e6ea; --blue: #0a5bd3; --me: #0a5bd3; --them: #e9ebef;
  --ok-bg: #e7f6ec; --ok: #1d6b3a; --err-bg: #fdeceb; --err: #a52a21; color-scheme: light dark; }
@media (prefers-color-scheme: dark) { :root { --bg: #15171b; --card: #1f2227; --ink: #e8eaed; --muted: #9aa1ab; --line: #2e3238;
  --them: #2c3036; --ok-bg: #173323; --ok: #8be0a8; --err-bg: #3d1a18; --err: #ffaaa3; } }
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--blue); }
header.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
header .brand { font-weight: 700; text-decoration: none; color: var(--ink); }
header nav { display: flex; gap: 14px; align-items: center; font-size: 14px; }
header nav form { margin: 0; }
main { max-width: 760px; margin: 0 auto; padding: 14px; }
main.narrow { max-width: 420px; padding-top: 40px; }
h1 { font-size: 24px; margin: 0 0 12px; } h2 { font-size: 18px; margin: 24px 0 8px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.flash { padding: 10px 14px; border-radius: 10px; margin: 0 0 12px; background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--err-bg); color: var(--err); }
.stack { display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
textarea { resize: vertical; }
button, .button { font: inherit; background: var(--blue); color: #fff; border: 0; border-radius: 10px; padding: 10px 16px; cursor: pointer; text-decoration: none; display: inline-block; }
button.link { background: none; color: var(--blue); padding: 0; }
.compose { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; margin-bottom: 12px; }
.compose summary { cursor: pointer; font-weight: 600; }
.compose form { margin-top: 12px; }
.filters a { display: inline-block; padding: 4px 10px; border-radius: 99px; background: var(--card); border: 1px solid var(--line);
  text-decoration: none; color: var(--ink); font-size: 13px; margin: 0 4px 6px 0; }
.filters a.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.threads { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.threads li + li { border-top: 1px solid var(--line); }
.threads a { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 12px 14px; text-decoration: none; color: var(--ink); }
.threads .who { font-weight: 600; } .threads .when { color: var(--muted); font-size: 13px; }
.threads .preview { grid-column: 1 / -1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.threads .via { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }
.threads li.unread .preview { color: var(--ink); font-weight: 600; }
.count { background: var(--blue); color: #fff; border-radius: 99px; font-size: 12px; padding: 0 7px; font-weight: 600; }
.empty { color: var(--muted); padding: 24px; text-align: center; }
main.chat { display: flex; flex-direction: column; height: calc(100dvh - 50px); padding-bottom: 0; }
.chathead { padding: 4px 0 10px; font-size: 17px; }
.chathead .back { text-decoration: none; font-size: 26px; line-height: 1; margin-right: 6px; }
.msgs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 6px 2px 12px; }
.msg { max-width: 78%; display: flex; flex-direction: column; }
.msg.in { align-self: flex-start; } .msg.out { align-self: flex-end; align-items: flex-end; }
.msg .text { padding: 8px 12px; border-radius: 18px; background: var(--them); white-space: normal; overflow-wrap: anywhere; }
.msg.out .text { background: var(--me); color: #fff; } .msg.out .text a { color: #fff; }
.msg.failed .text { background: var(--err-bg); color: var(--err); }
.msg img { max-width: 240px; max-height: 320px; border-radius: 14px; display: block; margin-bottom: 4px; }
.msg .meta { font-size: 11px; color: var(--muted); margin: 2px 8px; }
.reply { display: flex; gap: 8px; align-items: flex-end; padding: 10px 0 max(10px, env(safe-area-inset-bottom)); background: var(--bg); }
.reply textarea { flex: 1; border-radius: 20px; min-height: 42px; max-height: 160px; }
.reply button { border-radius: 20px; }
.reply .attach { font-size: 22px; cursor: pointer; display: block; padding: 6px 2px; color: var(--ink); }
.reply .attach input { display: none; }
.reply .attach.has { color: var(--blue); }
