:root {
  --bg: #0b141a; --side: #111b21; --pane: #0b141a; --line: #222d34; --hover: #202c33; --sel: #2a3942;
  --text: #e9edef; --muted: #8696a0; --accent: #00a884; --in: #202c33; --out: #005c4b; --danger: #f15c6d;
  --badge: #00a884; --head: #202c33;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #eae6df; --side: #fff; --pane: #efeae2; --line: #e9edef; --hover: #f5f6f6; --sel: #f0f2f5;
    --text: #111b21; --muted: #667781; --in: #fff; --out: #d9fdd3; --head: #f0f2f5; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* .lightbox, .pane-head etc. set display, which would beat the attribute */
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14.5px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; cursor: pointer; }
a { color: var(--accent); }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); background: var(--side); padding: 28px; border-radius: 14px; display: grid; gap: 14px; }
.login label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.login input { padding: 11px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 15px; }
.login button { padding: 11px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; }
.sub { margin: -8px 0 4px; color: var(--muted); }
.err { color: var(--danger); min-height: 1.2em; margin: 0; }
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); display: inline-block; }
.dot.down { background: var(--danger); }

/* layout */
.app { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; height: 100dvh; }
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 14px 16px; background: var(--head); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.who { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.search { padding: 8px 12px; }
.search input { width: 100%; padding: 9px 12px; border-radius: 8px; border: 0; background: var(--head); color: var(--text); font-size: 14px; }
.filters { display: flex; gap: 6px; padding: 0 12px 8px; }
.chip { border: 0; padding: 5px 12px; border-radius: 16px; background: var(--head); color: var(--muted); font-size: 13px; }
.chip.on { background: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--accent); }
.chats { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat { display: grid; grid-template-columns: 46px 1fr auto; gap: 12px; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--line); align-items: center; }
.chat:hover { background: var(--hover); }
.chat.sel { background: var(--sel); }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; color: #fff; font-size: 16px; flex: none; }
.chat .mid { min-width: 0; }
.chat .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat .last { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat .right { display: grid; justify-items: end; gap: 4px; font-size: 12px; color: var(--muted); }
.chat.unread .right .t { color: var(--badge); }
.badge { background: var(--badge); color: #fff; border-radius: 10px; min-width: 20px; padding: 1px 6px; text-align: center; font-size: 11.5px; font-weight: 600; }
.banner { padding: 8px 12px; font-size: 12.5px; background: color-mix(in srgb, var(--danger) 20%, transparent); color: var(--text); }

.pane { display: flex; flex-direction: column; min-height: 0; background: var(--pane); position: relative; }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 24px; }
.empty-mark { font-size: 48px; }
.pane-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--head); }
.pane-head .avatar { width: 40px; height: 40px; font-size: 15px; }
.peer { flex: 1; min-width: 0; }
.peer-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-sub { color: var(--muted); font-size: 12.5px; }
.ghost { background: none; border: 0; color: var(--muted); font-size: 18px; padding: 6px 8px; text-decoration: none; border-radius: 6px; }
.ghost:hover { background: var(--hover); }
.back { display: none; background: none; border: 0; color: var(--text); font-size: 22px; padding: 0 6px 0 0; }

.msgs { flex: 1; overflow-y: auto; padding: 14px 6% 8px; display: flex; flex-direction: column; gap: 3px; }
.more { align-self: center; margin: 6px 0 10px; }
.day { align-self: center; background: var(--head); color: var(--muted); font-size: 12px; padding: 4px 10px; border-radius: 8px; margin: 10px 0 6px; }
.m { max-width: min(75%, 560px); padding: 6px 9px 6px; border-radius: 8px; background: var(--in); align-self: flex-start; box-shadow: 0 1px .5px rgba(0,0,0,.13); white-space: pre-wrap; overflow-wrap: anywhere; position: relative; }
.m.me { background: var(--out); align-self: flex-end; }
.m .meta { float: right; margin: 6px 0 -4px 10px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.m .by { display: block; font-size: 11.5px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.m img.thumb, .m video { display: block; max-width: 100%; max-height: 320px; border-radius: 6px; margin-bottom: 4px; cursor: zoom-in; background: var(--head); min-width: 120px; min-height: 80px; }
.m audio { display: block; width: 260px; max-width: 100%; height: 40px; }
.m .doc { display: flex; gap: 8px; align-items: center; padding: 8px; background: rgba(0,0,0,.12); border-radius: 6px; color: var(--text); text-decoration: none; margin-bottom: 4px; }
.m .kind { color: var(--muted); font-style: italic; }
.m.pending { opacity: .6; }
.m.failed { outline: 1px solid var(--danger); }

.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--head); }
.composer textarea { flex: 1; resize: none; max-height: 140px; padding: 10px 12px; border-radius: 8px; border: 0; background: var(--side); color: var(--text); font: inherit; }
.composer button, .attach { border: 0; background: none; color: var(--muted); font-size: 22px; padding: 6px 8px; cursor: pointer; }
.composer button[type=submit] { color: var(--accent); }
.composer button:disabled { opacity: .4; cursor: default; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; z-index: 10; cursor: zoom-out; }
.lightbox img { max-width: 95vw; max-height: 95vh; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app.open .side { display: none; }
  .app:not(.open) .pane { display: none; }
  .back { display: block; }
  .msgs { padding: 10px 10px 6px; }
  .m { max-width: 88%; }
}
