:root {
  --bg: #f4f6fa; --panel: #fff; --text: #1b1f27; --muted: #6b7280; --line: #e3e7ee;
  --accent: #2b3a55; --accent-text: #fff; --mine: #e9dccb; --warm: #e8734a; --theirs: #fff; --ok: #16a34a; --off: #9ca3af; --err: #dc2626;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1218; --panel: #171b23; --text: #e6e9ef; --muted: #9aa3b2; --line: #262c37;
    --mine: #4a3a2a; --theirs: #202633; --accent: #d9ab7b; --accent-text: #1b1f27; }
}
* { 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; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-text); padding: 10px 14px; }
button.link, label.link { background: none; color: var(--muted); padding: 4px 6px; font-size: 13px; cursor: pointer; }
button.link:hover, label.link:hover { color: var(--text); }
input, textarea { font: inherit; font-size: 16px; /* иначе iOS зумит поле */ color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.msg { min-height: 1.2em; margin: 8px 0 0; }
.msg.err { color: var(--err); }
.msg a { color: var(--accent); word-break: break-all; }

.screen { height: 100%; }
/* главная страница */
.landing { min-height: 100%; height: auto; display: flex; flex-direction: column; align-items: center; padding: 0 16px; }
.l-top { width: 100%; max-width: 880px; display: flex; align-items: center; gap: 10px; padding: 16px 0; }
.l-top img { border-radius: 8px; }
.l-brand { font-weight: 700; }
.l-hero { width: 100%; max-width: 560px; text-align: center; padding: 32px 0 24px; }
.l-logo { width: 128px; height: 128px; border-radius: 30px; box-shadow: 0 12px 32px rgba(43,58,85,.25); }
.l-badge { display: block; width: max-content; margin: 24px auto 0; padding: 6px 14px; border-radius: 999px; background: var(--warm); color: #fff; font-weight: 600; font-size: 14px; }
.l-hero h1 { font-size: clamp(34px, 8vw, 52px); line-height: 1.05; margin: 14px 0 12px; letter-spacing: -0.02em; }
.l-lead { font-size: 18px; color: var(--muted); margin: 0 auto; max-width: 30em; }
.l-form { margin-top: 28px; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.l-form label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.l-row { display: flex; gap: 8px; }
.l-row button { flex: none; padding: 10px 20px; }
.l-facts { list-style: none; padding: 0; margin: 8px 0 0; width: 100%; max-width: 880px; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.l-facts li { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.l-facts b { display: block; margin-bottom: 4px; }
.l-facts span { color: var(--muted); font-size: 14px; }
.l-foot { color: var(--muted); font-size: 13px; padding: 32px 0 24px; margin-top: auto; }
@media (max-width: 480px) { .l-row { flex-direction: column; } .l-hero { padding-top: 12px; } }

#app { display: grid; grid-template-columns: 300px 1fr; }
#sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.me { padding-top: max(14px, env(safe-area-inset-top)) !important; display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.me-name { font-weight: 600; cursor: pointer; }
.net { width: 10px; height: 10px; border-radius: 50%; background: var(--off); }
.net.on { background: var(--ok); }
.invite { display: flex; gap: 6px; padding: 12px 16px 0; }
.invite button { padding: 0 14px; font-size: 18px; }
#invite-msg { padding: 0 16px; }
#contacts { list-style: none; margin: 0; padding: 4px 8px; overflow-y: auto; flex: 1; }
#contacts li { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; cursor: pointer; }
#contacts li:hover { background: var(--bg); }
#contacts li.active { background: var(--mine); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--off); flex: none; }
.dot.online { background: #f59e0b; }
.dot.p2p { background: var(--ok); }
.c-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 999px; font-size: 12px; padding: 1px 7px; }
.side-foot { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 12px; border-top: 1px solid var(--line); }

#chat { display: flex; min-width: 0; min-height: 0; }
.empty { margin: auto; padding: 24px; text-align: center; }
#conv { display: flex; flex-direction: column; flex: 1; min-height: 0; height: 100%; }
.conv-head { padding-top: max(12px, env(safe-area-inset-top)) !important; display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.peer-name { font-weight: 600; }
.back { display: none; background: none; color: var(--text); font-size: 26px; padding: 0 8px 0 0; }
#messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.m { max-width: min(560px, 80%); padding: 8px 12px; border-radius: 14px; background: var(--theirs); border: 1px solid var(--line); white-space: pre-wrap; word-wrap: break-word; }
.m.out { align-self: flex-end; background: var(--mine); border-color: transparent; }
.m .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 8px 0; }
.composer { display: flex; gap: 8px; padding: 10px 12px; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.composer textarea { resize: none; max-height: 160px; }
.composer button { font-size: 18px; padding: 0 16px; }

.banner { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: calc(100% - 32px); display: flex; gap: 12px; align-items: center; }
.banner button { padding: 6px 10px; }

@media (max-width: 720px) {
  #app { grid-template-columns: 1fr; }
  #app.chatting #sidebar { display: none; }
  #app:not(.chatting) #chat { display: none; }
  .back { display: block; }
}
