:root {
  --bg: #0e1621; --side: #17212b; --panel: #17212b; --hover: #202b36; --active: #2b5278;
  --in: #182533; --out: #2b5278; --text: #f5f5f5; --muted: #7f91a4; --accent: #5288c1;
  --ok: #4ecc5e; --bad: #e56555; --line: #0b121a; --input: #242f3d;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--bad); min-height: 20px; margin-top: 10px; font-size: 14px; }

/* вход */
.screen { height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--side); }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-logo { width: 88px; height: 88px; border-radius: 24px; }
.login-card h1 { margin: 12px 0 4px; font-size: 26px; }
.login-card input { display: block; width: 100%; margin-top: 12px; padding: 13px 14px; border-radius: 12px; border: 1px solid #2c3a4a; background: var(--input); color: var(--text); font-size: 16px; }
.login-card button { width: 100%; margin-top: 16px; padding: 13px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-size: 16px; font-weight: 600; }
.login-card button:disabled { opacity: .6; }

/* раскладка: слева чаты, справа переписка; на телефоне - по очереди */
.layout { height: 100%; display: flex; }
aside { width: 340px; min-width: 260px; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: relative; }
.side-head { display: flex; align-items: center; gap: 4px; padding: 10px 8px 6px 16px; }
.side-title { flex: 1; display: flex; flex-direction: column; }
.side-title b { font-size: 18px; }
.icon-btn { background: none; border: 0; width: 38px; height: 38px; border-radius: 50%; font-size: 18px; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--hover); }
.search { margin: 4px 12px 8px; padding: 9px 14px; border-radius: 20px; border: 0; background: var(--input); color: var(--text); font-size: 15px; outline: none; }
.chat-list { flex: 1; overflow-y: auto; }
.item { display: flex; gap: 12px; align-items: center; padding: 8px 12px; cursor: pointer; }
.item:hover { background: var(--hover); }
.item.active { background: var(--active); }
.item-body { flex: 1; min-width: 0; }
.item-top, .item-bottom { display: flex; gap: 6px; align-items: baseline; }
.item-name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-time { font-size: 12px; color: var(--muted); }
.item-last { flex: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.item.active .item-last, .item.active .item-time { color: #c9d8e7; }
.badge { background: var(--accent); color: #fff; border-radius: 11px; min-width: 22px; height: 22px; padding: 0 7px; font-size: 13px; display: flex; align-items: center; justify-content: center; font-weight: 600; }
.ava { width: 48px; height: 48px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 19px; color: #fff; object-fit: cover; position: relative; }
.ava.small { width: 40px; height: 40px; font-size: 16px; }
.online-dot { position: absolute; right: 1px; bottom: 1px; width: 13px; height: 13px; border-radius: 50%; background: var(--ok); border: 2px solid var(--side); }
.menu { position: absolute; top: 52px; right: 10px; z-index: 5; background: #1f2b38; border-radius: 12px; padding: 6px; min-width: 220px; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.menu button { display: block; width: 100%; text-align: left; padding: 10px 12px; background: none; border: 0; border-radius: 8px; }
.menu button:hover { background: var(--hover); }
.menu .danger { color: var(--bad); }
.menu-me { padding: 8px 12px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }

/* переписка */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.chat-empty { margin: auto; padding: 6px 14px; border-radius: 14px; background: rgba(0,0,0,.25); }
.chat.empty > :not(.chat-empty) { display: none; }
.chat:not(.empty) .chat-empty { display: none; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.chat-head .back { display: none; }
.chat-title { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-title b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msgs { flex: 1; overflow-y: auto; padding: 12px max(12px, calc((100% - 760px) / 2)); display: flex; flex-direction: column; gap: 3px; }
.day { align-self: center; margin: 10px 0 6px; padding: 3px 12px; border-radius: 12px; background: rgba(0,0,0,.3); font-size: 13px; color: #c9d8e7; }
.row { display: flex; align-items: flex-end; gap: 6px; }
.row.mine { justify-content: flex-end; }
.bubble { max-width: min(520px, 78%); background: var(--in); border-radius: 14px; padding: 6px 10px 6px; position: relative; word-wrap: break-word; overflow-wrap: anywhere; }
.row.mine .bubble { background: var(--out); }
.bubble .who { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.bubble .text { white-space: pre-wrap; }
.bubble .text a { color: #8cc4ff; }
.bubble .meta { float: right; margin: 6px 0 -4px 10px; font-size: 12px; color: #8fa6bd; white-space: nowrap; user-select: none; }
.row.mine .meta { color: #a9c6e3; }
.meta .ticks.read { color: #8cd4ff; }
.quote { border-left: 3px solid var(--accent); padding: 2px 8px; margin: 2px 0 4px; border-radius: 4px; background: rgba(255,255,255,.05); font-size: 14px; cursor: pointer; }
.quote b { display: block; color: #8cc4ff; font-size: 13px; }
.quote span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #c9d8e7; }
.fwd { font-size: 13px; color: #8cc4ff; margin-bottom: 2px; }
.photo { display: block; max-width: 100%; max-height: 360px; border-radius: 10px; margin: 2px 0 4px; cursor: zoom-in; background: rgba(0,0,0,.2); }
.file { display: flex; gap: 10px; align-items: center; padding: 4px 0; cursor: pointer; }
.file-ico { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; flex: none; font-size: 18px; }
.file-name { font-weight: 600; word-break: break-all; }
.media { display: block; max-width: 100%; max-height: 360px; border-radius: 10px; margin: 2px 0 4px; }
audio.media { width: 260px; }
.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.react { background: rgba(255,255,255,.12); border-radius: 12px; padding: 1px 8px; font-size: 14px; }
.react.mine { background: rgba(140,196,255,.35); }
.row .act { opacity: 0; background: none; border: 0; color: var(--muted); font-size: 16px; padding: 4px; }
.row:hover .act { opacity: 1; }
.row.flash .bubble { animation: flash 1.2s; }
@keyframes flash { 0%, 60% { box-shadow: 0 0 0 3px rgba(140,196,255,.6); } 100% { box-shadow: none; } }
.list-items { margin: 4px 0 2px; padding-left: 4px; }
.list-items div { font-size: 14px; }
.reply-bar, .upload-bar { display: flex; align-items: center; gap: 10px; padding: 6px 12px 6px 16px; background: var(--panel); border-top: 1px solid var(--line); }
.reply-line { flex: 1; border-left: 3px solid var(--accent); padding-left: 8px; min-width: 0; }
.reply-line b { display: block; color: #8cc4ff; font-size: 13px; }
.reply-line span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.upload-bar { font-size: 14px; color: var(--muted); }
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; max-height: 180px; padding: 9px 12px; border-radius: 18px; border: 0; background: var(--input); color: var(--text); font: inherit; font-size: 15px; outline: none; }
.send-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 17px; flex: none; }

/* окна */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 10; display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheet { width: 100%; max-width: 420px; max-height: 80vh; background: var(--side); border-radius: 16px; display: flex; flex-direction: column; overflow: hidden; }
.sheet header { display: flex; align-items: center; padding: 10px 8px 4px 16px; }
.sheet header b { flex: 1; font-size: 17px; }
.viewer { background: rgba(0,0,0,.92); }
.viewer-close { position: absolute; top: 12px; right: 12px; color: #fff; }
#viewerBody img, #viewerBody video { max-width: 96vw; max-height: 92vh; border-radius: 6px; }

@media (max-width: 720px) {
  aside { width: 100%; border-right: 0; }
  .chat { display: none; }
  .layout.in-chat aside { display: none; }
  .layout.in-chat .chat { display: flex; }
  .chat-head .back { display: block; }
  .row .act { opacity: .6; }
  .bubble { max-width: 85%; }
}
.pad { padding: 12px 16px; margin: 0; }
.small-btn { margin-top: 6px; padding: 5px 10px; border-radius: 8px; border: 1px solid #34404f; background: none; color: var(--accent); font-size: 13px; }
.small-btn:disabled { opacity: .7; }
.danger-btn { color: var(--bad); }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 20; background: #2b3a4a; color: #fff; padding: 10px 16px; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.4); font-size: 14px; max-width: 90vw; }
