:root {
  --bg: #f0f2f5; --panel: #fff; --text: #111b21; --muted: #667781; --line: #e9edef;
  --accent: #00a884; --accent-d: #008f72; --out: #d9fdd3; --in: #fff; --err: #d93025; --warn: #fff4cc;
  --tick: #8696a0; --tick-read: #53bdeb;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b141a; --panel: #111b21; --text: #e9edef; --muted: #8696a0; --line: #222d34;
    --accent: #00a884; --accent-d: #06cf9c; --out: #005c4b; --in: #202c33; --err: #ff7b72; --warn: #3d3516;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.4 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* auth */
.auth { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 14px; padding: 28px; display: grid; gap: 14px; box-shadow: 0 4px 24px rgba(0,0,0,.1); }
.card h1 { margin: 0; font-size: 26px; }
.sub { margin: 0; color: var(--muted); font-size: 14px; }
.card label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.card input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-size: 16px; }
.card input:focus, textarea:focus, .search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.tabs { display: flex; background: var(--bg); border-radius: 8px; padding: 3px; }
.tab { flex: 1; border: 0; background: none; padding: 8px; border-radius: 6px; color: var(--muted); }
.tab.active { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.note { margin: 0; font-size: 12.5px; background: var(--warn); padding: 10px; border-radius: 8px; }
.error { margin: 0; color: var(--err); font-size: 13px; min-height: 1em; }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 11px; font-weight: 600; }
.primary:hover { background: var(--accent-d); } .primary:disabled { opacity: .6; cursor: wait; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; }

/* layout */
.app { display: grid; grid-template-columns: 340px 1fr; height: 100dvh; max-width: 1500px; margin: 0 auto; background: var(--panel); }
.sidebar { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--bg); }
.me-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.icon { background: none; border: 0; font-size: 20px; padding: 6px 8px; border-radius: 8px; color: var(--muted); }
.icon:hover { background: var(--line); }
.search { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.search input { width: 100%; padding: 9px 14px; border: 0; border-radius: 8px; background: var(--bg); }
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.hint { padding: 24px; color: var(--muted); text-align: center; font-size: 14px; }
.item { display: flex; gap: 12px; padding: 11px 14px; align-items: center; cursor: pointer; border-bottom: 1px solid var(--line); }
.item:hover, .item.active { background: var(--bg); }
.mid { flex: 1; min-width: 0; }
.name { font-weight: 600; } .preview { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side { display: grid; justify-items: end; gap: 4px; }
.time { font-size: 11.5px; color: var(--muted); }
.badge { background: var(--accent); color: #fff; font-size: 11.5px; font-weight: 700; min-width: 20px; padding: 1px 6px; border-radius: 10px; text-align: center; }
.avatar { width: 42px; height: 42px; flex: none; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; position: relative; }
.avatar.online::after { content: ''; position: absolute; right: 0; bottom: 0; width: 11px; height: 11px; background: #25d366; border: 2px solid var(--panel); border-radius: 50%; }

/* chat */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 24px; }
.empty .big { font-size: 56px; } .empty h2 { color: var(--text); margin: 8px 0; }
.thread { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.who { flex: 1; min-width: 0; } .peer-name { font-weight: 600; }
.status { font-size: 12.5px; color: var(--muted); min-height: 1em; } .status.typing { color: var(--accent); }
.back { display: none; }
.banner { background: var(--warn); padding: 10px 14px; font-size: 13px; }
.messages { flex: 1; overflow-y: auto; padding: 16px clamp(12px, 6%, 64px); display: flex; flex-direction: column; gap: 4px; }
.msg { max-width: min(75%, 560px); padding: 6px 10px 4px; border-radius: 10px; box-shadow: 0 1px 1px rgba(0,0,0,.1); }
.msg.in { align-self: flex-start; background: var(--in); border-top-left-radius: 2px; }
.msg.out { align-self: flex-end; background: var(--out); border-top-right-radius: 2px; }
.body { white-space: pre-wrap; overflow-wrap: anywhere; } .body.bad { color: var(--muted); font-style: italic; }
.meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 1px; }
.tick { color: var(--tick); letter-spacing: -2px; } .tick.read { color: var(--tick-read); }
.composer { display: flex; gap: 8px; padding: 10px 12px; background: var(--panel); align-items: flex-end; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.composer textarea { flex: 1; resize: none; border: 0; background: var(--bg); border-radius: 20px; padding: 10px 16px; max-height: 140px; }
.send { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 18px; }

dialog { border: 0; border-radius: 14px; padding: 24px; max-width: 380px; background: var(--panel); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog h3 { margin-top: 0; }
.safety { font: 600 20px/1.6 ui-monospace, Menlo, monospace; text-align: center; margin: 16px 0; letter-spacing: 1px; word-spacing: 8px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 10; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .chat { display: none; } .app.chat-open .sidebar { display: none; } .app.chat-open .chat { display: flex; }
  .back { display: block; }
  .msg { max-width: 85%; }
}

.card.flat { box-shadow: none; padding: 0; max-width: none; }
.card.flat h3, .card.flat h4 { margin: 0; }
.secondary { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px; }
.secondary:hover { background: var(--line); }
.loading { text-align: center; color: var(--muted); font-size: 12px; padding: 4px; }

.msg { position: relative; }
.msg.has-reacts { margin-bottom: 14px; }
.msg-menu { position: absolute; top: 2px; right: 4px; opacity: 0; background: none; border: 0; font-size: 16px; line-height: 1; padding: 2px 6px; border-radius: 6px; color: var(--muted); }
.msg:hover .msg-menu, .msg-menu:focus-visible { opacity: 1; background: var(--panel); }
@media (hover: none) { .msg-menu { opacity: .6; } }
.quote { border-left: 3px solid var(--accent); background: rgba(0,0,0,.06); border-radius: 6px; padding: 4px 8px; margin: 2px 0 4px; font-size: 13px; cursor: pointer; }
.quote b { display: block; color: var(--accent-d); font-size: 12px; }
.quote span { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40ch; }
.body.deleted { color: var(--muted); font-style: italic; }
.reacts { position: absolute; bottom: -13px; right: 8px; display: flex; gap: 3px; }
.react { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 0 6px; font-size: 12px; line-height: 20px; cursor: pointer; }
.react.mine { border-color: var(--accent); }
.flash { animation: flash 1.2s; } @keyframes flash { 0%, 60% { outline: 2px solid var(--accent); } 100% { outline-color: transparent; } }
.menu { position: fixed; z-index: 20; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.25); padding: 6px; min-width: 190px; display: grid; gap: 2px; }
.menu .emojis { display: flex; justify-content: space-between; padding: 2px 2px 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu .emojis button { background: none; border: 0; font-size: 20px; padding: 3px 5px; border-radius: 8px; }
.menu .emojis button.on { background: var(--line); }
.menu .emojis button:hover, .menu > button:hover { background: var(--bg); }
.menu > button { background: none; border: 0; text-align: left; padding: 8px 10px; border-radius: 8px; }
.menu > button.danger { color: var(--err); }
.reply-bar { display: flex; align-items: center; gap: 8px; background: var(--panel); border-top: 1px solid var(--line); padding: 6px 12px; border-left: 4px solid var(--accent); }
.reply-text { flex: 1; min-width: 0; font-size: 13px; } .reply-text b { display: block; color: var(--accent-d); }
.reply-text span { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
