:root {
  --bg: #f6f6f4; --panel: #ffffff; --line: #e4e3df; --text: #1f1e1c; --muted: #77746d;
  --accent: #c96442; --accent-text: #fff; --mine: #f3e3dc; --theirs: #ffffff; --danger: #b3261e;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1d1c1a; --panel: #262523; --line: #383633; --text: #ecebe8; --muted: #9c9890;
    --mine: #4a3027; --theirs: #2f2e2b; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
button { font: inherit; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-text); padding: 8px 14px; cursor: pointer; }
button.ghost { background: transparent; color: var(--muted); padding: 4px 8px; }
button.ghost:hover { color: var(--text); }
input, textarea { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
code { background: var(--line); padding: 0 4px; border-radius: 4px; }

.login { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(380px, 100%); display: grid; gap: 12px; }
.card h1 { margin: 0; font-size: 24px; }
.card label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.sub, .hint { margin: 0; color: var(--muted); font-size: 13px; }
.msg { margin: 0; min-height: 1.5em; font-size: 13px; color: var(--danger); }

.app { display: grid; grid-template-columns: 280px 1fr; height: 100%; }
.side { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; gap: 8px; padding: 14px; border-bottom: 1px solid var(--line); }
.side-head strong { flex: 1; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn.live { background: #2e7d32; } .conn.poll { background: #b8860b; } .conn.offline { background: var(--danger); }
.new { display: flex; gap: 6px; padding: 10px 14px; }
.new button { padding: 8px 12px; }
.convs { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.convs li { padding: 10px 14px; cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; border-left: 3px solid transparent; }
.convs li:hover { background: var(--bg); }
.convs li.active { background: var(--bg); border-left-color: var(--accent); }
.convs .name { font-weight: 600; }
.convs .time { font-size: 12px; color: var(--muted); }
.convs .preview { grid-column: 1; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convs .badge { background: var(--accent); color: var(--accent-text); border-radius: 10px; font-size: 12px; padding: 0 7px; justify-self: end; }

.chat { display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.chat-head strong { flex: 1; }
.back { display: none; }
.verify { margin: 0; padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line); font-size: 13px; }
.verify b { font-family: ui-monospace, Consolas, monospace; font-size: 15px; letter-spacing: 1px; }
.messages { list-style: none; margin: 0; padding: 18px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.messages li { max-width: min(72%, 560px); padding: 8px 12px; border-radius: 12px; background: var(--theirs); border: 1px solid var(--line); white-space: pre-wrap; word-break: break-word; align-self: flex-start; }
.messages li.mine { align-self: flex-end; background: var(--mine); border-color: transparent; }
.messages li.bad { color: var(--danger); }
.messages time { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.messages .day { align-self: center; background: none; border: 0; color: var(--muted); font-size: 12px; padding: 4px; }
.send { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--panel); }
.send textarea { resize: none; max-height: 160px; }

@media (max-width: 700px) {
  .app { grid-template-columns: 1fr; }
  .app.in-chat .side { display: none; }
  .app:not(.in-chat) .chat { display: none; }
  .back { display: inline-block; }
}
