:root {
  --primary: #0f6e6a;
  --on-primary: #fff;
  --bg: #fafcfc;
  --surface: #fff;
  --text: #0f2a2e;
  --muted: #51606b;
  --mine: #cdedea;
  --theirs: #e3ecef;
  --danger: #b3261e;
  --border: #d5e0e2;
  color-scheme: light dark;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --primary: #3fb8af;
    --on-primary: #00201e;
    --bg: #0e1517;
    --surface: #152024;
    --text: #e0eaeb;
    --muted: #9aaab0;
    --mine: #15524e;
    --theirs: #2c3a40;
    --danger: #ff8a80;
    --border: #2a3a3f;
  }
}
* { box-sizing: border-box; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { display: flex; justify-content: center; }
#app { width: 100%; max-width: 760px; height: 100%; display: flex; flex-direction: column; background: var(--bg); }
header { display: flex; align-items: center; gap: 8px; background: var(--primary); color: var(--on-primary); padding: 10px 12px; }
header h1 { flex: 1; font-size: 1.15rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header .icon { background: none; color: var(--on-primary); font-size: 1.3rem; padding: 4px 10px; width: auto; }
main { flex: 1; overflow-y: auto; position: relative; }
main.page { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
form { display: flex; flex-direction: column; gap: 10px; }
h2 { font-size: 1.05rem; margin: 18px 0 4px; color: var(--primary); }
h3 { font-size: .85rem; margin: 12px 16px 4px; color: var(--primary); text-transform: uppercase; letter-spacing: .03em; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; width: 100%;
}
textarea { resize: vertical; }
button {
  font: inherit; border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer;
  background: var(--primary); color: var(--on-primary);
}
button:disabled { opacity: .5; cursor: default; }
button.secondary { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
button.danger { background: var(--danger); color: #fff; }
button.link { background: none; color: var(--muted); text-decoration: underline; padding: 4px; }
.secret { display: flex; gap: 6px; }
.secret input { flex: 1; }
.eye { background: transparent; color: var(--text); border: 1px solid var(--border); min-width: 3.5em; }
.error { color: var(--danger); min-height: 1em; margin: 0; }
.ok { color: var(--primary); margin: 0; }
.hint { color: var(--muted); font-size: .9rem; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; word-break: break-all; }
.code { font-size: 1.15rem; line-height: 1.6; text-align: center; }
.code.sas { font-size: 2.4rem; font-weight: 700; letter-spacing: 0.08em; margin: 0.5rem 0; }
.qr { width: 240px; height: 240px; align-self: center; background: #fff; border-radius: 8px; image-rendering: pixelated; }
.banner { padding: 10px 16px; background: var(--theirs); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.banner:empty, .banner[hidden] { display: none; }
.banner.danger { background: color-mix(in srgb, var(--danger) 20%, var(--bg)); }
.banner button { padding: 6px 10px; }
.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tabs button { flex: 1; background: none; color: var(--muted); border-radius: 0; border-bottom: 3px solid transparent; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.list { display: flex; flex-direction: column; padding-bottom: 80px; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: none; color: var(--text); border-radius: 0; padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.row:hover { background: var(--surface); }
.row.static { cursor: default; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--mine); font-weight: 700;
}
.grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { color: var(--muted); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; color: var(--muted); font-size: .8rem; }
.badge { background: var(--primary); color: var(--on-primary); border-radius: 10px; padding: 0 7px; font-size: .8rem; }
.warn { color: var(--danger); }
.fab { position: fixed; bottom: 20px; right: max(20px, calc(50% - 360px)); box-shadow: 0 3px 8px rgba(0,0,0,.25); }
main.chat { padding: 0; }
.messages { height: 100%; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.bubble {
  max-width: 78%; background: var(--theirs); border-radius: 14px; padding: 8px 12px; align-self: flex-start;
  display: flex; flex-direction: column; position: relative; white-space: pre-wrap; overflow-wrap: anywhere;
}
.bubble.mine { background: var(--mine); align-self: flex-end; }
.bubble .time { align-self: flex-end; font-size: .75rem; color: var(--muted); margin-top: 2px; }
.bubble .actions { position: absolute; top: -12px; left: -12px; display: inline-flex; gap: 2px; }
.bubble .more { padding: 2px 6px; font-size: .8rem; opacity: .35; }
.bubble:hover .more, .bubble .more:focus { opacity: 1; }
.system { text-align: center; color: var(--muted); font-size: .85rem; margin: 6px 0; }
.composer { flex-direction: row; padding: 8px; border-top: 1px solid var(--border); }
.composer textarea { flex: 1; min-width: 0; }
.composer .icon { padding-inline: 8px; }
.geo-choice { display: flex; align-items: center; gap: 8px; }
.geo-choice input { width: auto; flex: none; }
.geo-message { display: flex; flex-direction: column; gap: 6px; }
.geo-share { max-height: calc(100dvh - 32px); overflow-y: auto; }
.media-index { max-height: calc(100dvh - 32px); overflow-y: auto; }
.media-index-list { display: flex; flex-direction: column; gap: 8px; }
.media-index .media-entry { text-align: left; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble:focus { outline: 2px solid var(--primary); outline-offset: 2px; }
dialog { border: 0; border-radius: 14px; padding: 16px; background: var(--surface); color: var(--text); display: flex; flex-direction: column; gap: 8px; min-width: 260px; max-width: 420px; }
dialog:not([open]) { display: none; }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; }
body[data-conn="offline"] #conn::before { content: "● "; color: var(--danger); }

/* Этап 2: группы, вложения, голосовые, ответы, реакции */
.composer .icon { flex: none; }
.reply-bar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-top: 1px solid var(--line, #ccc); font-size: 0.9em; }
.reply-bar[hidden] { display: none; }
.bubble .author { display: block; font-size: 0.8em; font-weight: 600; opacity: 0.8; }
.bubble .quote { display: block; border-left: 3px solid currentColor; padding-left: 6px; margin-bottom: 4px; font-size: 0.85em; opacity: 0.75; }
.bubble .reactions { display: inline-flex; gap: 4px; margin: 2px 0; font-size: 0.9em; }
.bubble .reactions span { border-radius: 10px; padding: 0 6px; background: rgba(127, 127, 127, 0.18); }
.bubble .media { display: flex; flex-direction: column; gap: 4px; }
.bubble .media .photo { max-width: 260px; max-height: 320px; border-radius: 8px; }
.bubble .media audio { max-width: 260px; }
.risky { display: block; color: var(--danger); font-size: 0.85rem; }
.wave { display: inline-flex; align-items: center; gap: 1px; height: 24px; }
.wave i { display: inline-block; width: 2px; background: currentColor; opacity: 0.7; }
.wave i.v0 { height: 3px; } .wave i.v1 { height: 5px; } .wave i.v2 { height: 8px; } .wave i.v3 { height: 11px; }
.wave i.v4 { height: 14px; } .wave i.v5 { height: 17px; } .wave i.v6 { height: 20px; } .wave i.v7 { height: 24px; }
.emoji-row { display: flex; gap: 6px; flex-wrap: wrap; font-size: 1.4em; }
.bubble .fwd { display: block; font-size: 0.75rem; opacity: 0.7; }
.banner.pin { cursor: default; }

/* Звонок (Этап 4): экран поверх приложения. */
.call { position: fixed; inset: 0; z-index: 50; background: #101418; color: #fff; display: flex; flex-direction: column; }
.call video.remote { flex: 1; width: 100%; min-height: 0; object-fit: contain; background: #000; }
.call video.local { position: absolute; right: 12px; top: 12px; width: 28vw; max-width: 180px; border-radius: 8px; background: #222; }
.call .call-info { padding: 12px 16px; text-align: center; }
.call .call-info h2 { margin: 4px 0; }
.call .call-info .hint { color: #c8d0d8; }
.call .call-controls { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 12px 16px 24px; }
.call .call-controls .accept { background: #1e8e3e; }

.group-call { width: min(900px, 95vw); max-height: 95vh; overflow: auto; }
.group-players { display: grid; grid-template-columns: repeat(auto-fit,minmax(220px,1fr)); gap: 8px; }
.group-players video { width: 100%; background: #111; }

.group-players figure { margin: 0; min-width: 0; }
.group-players figcaption { overflow-wrap: anywhere; }
.group-players audio { display: none; }
.group-roster { display: flex; flex-wrap: wrap; gap: 8px 24px; padding-left: 24px; }

/* Этап 9: общие поверхности, типографика и навигация. Без внешних шрифтов. */
:root { --primary:#087f78; --bg:#f4f7fa; --surface:#fff; --text:#172e38; --muted:#536773; --mine:#d4f2e7; --theirs:#fff; --border:#dce5eb; }
@media (prefers-color-scheme:dark) {
  :root { --primary:#73d9c7; --bg:#101b22; --surface:#182830; --text:#e5eef2; --muted:#a5b9c4; --mine:#194c48; --theirs:#233640; --border:#344952; }
}
html { font-size:16px; }
body { line-height:1.5; }
#app { min-height:0; height:100dvh; box-shadow:0 0 50px #102f3910; }
header { flex:none; min-height:72px; background:var(--surface); color:var(--text); border-bottom:1px solid var(--border); padding:12px 16px; }
header h1 { font-size:1.25rem; font-weight:750; letter-spacing:-.035em; }
header .icon { color:var(--primary); min-width:44px; min-height:44px; padding:6px; display:grid; place-items:center; border-radius:14px; }
header .icon:hover { background:var(--bg); }
main { min-height:0; overscroll-behavior:contain; }
main.page { gap:16px; padding:24px; }
main.page > h2 { border-top:1px solid var(--border); padding-top:22px; margin-top:14px; font-size:1rem; }
main.page > h2:first-child { border-top:0; }
main.page p { margin:0; }
main.page > button { min-height:48px; text-align:left; }
input, textarea, select { min-height:48px; border-radius:16px; }
input[type="checkbox"], input[type="radio"] { width:20px; min-height:20px; accent-color:var(--primary); vertical-align:middle; }
button { min-height:44px; border-radius:14px; font-weight:600; }
button.secondary { border-color:var(--border); background:var(--surface); }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline:3px solid var(--primary); outline-offset:3px; }
.home-search { padding:14px 18px; background:var(--surface); }
.home-search input { border-radius:24px; background:var(--bg); }
.tabs { flex:none; border-top:1px solid var(--border); border-bottom:0; background:var(--surface); padding:8px 8px max(8px, env(safe-area-inset-bottom)); gap:4px; }
.tabs button { display:flex; flex-direction:column; align-items:center; justify-content:center; gap:4px; border:0; border-radius:16px; font-size:.8rem; min-height:60px; }
.tabs button.active { color:var(--primary); background:var(--mine); border:0; }
.home-list .fab { position:absolute; bottom:20px; right:20px; border-radius:20px; box-shadow:0 6px 20px #183a382b; padding:15px 20px; }
.home-list .list { padding-bottom:100px; }
.list > .hint { padding:32px 24px; text-align:center; }
.row { min-height:88px; padding:16px 20px; gap:14px; border-bottom:1px solid color-mix(in srgb,var(--border) 55%,transparent); font-weight:400; }
.row:hover { background:var(--surface); }
.avatar { width:52px; height:52px; border-radius:19px; background:var(--mine); color:var(--primary); font-size:1.05rem; letter-spacing:-.04em; }
.title { font-weight:650; font-size:1rem; }
.grow { gap:4px; }
.meta { align-self:flex-start; padding-top:3px; gap:10px; font-size:.72rem; }
.badge { min-width:22px; text-align:center; font-weight:700; }
.sub { font-size:.875rem; }
.profile-hero { display:flex; flex-direction:column; align-items:center; gap:12px; padding:18px 0 24px; }
.profile-hero .avatar { width:88px; height:88px; border-radius:30px; font-size:1.9rem; }
.profile-hero h2 { font-size:1.4rem; color:var(--text); margin:0; }
.banner { flex:none; font-size:.875rem; padding:12px 18px; line-height:1.45; }
.banner.conn { color:var(--muted); background:var(--surface); font-size:.75rem; padding:5px 20px; }
.messages { padding:20px 18px; gap:10px; }
.bubble { max-width:min(84%,520px); padding:11px 14px; border-radius:20px 20px 20px 5px; box-shadow:0 1px 2px #142a3810; line-height:1.5; }
.bubble.mine { border-radius:20px 20px 5px 20px; }
.bubble .time { font-size:.7rem; margin-top:5px; }
.bubble .more { opacity:.7; min-width:36px; min-height:32px; border-radius:10px; }
.bubble .media .photo { max-width:100%; }
.composer { flex:none; align-items:flex-end; gap:6px; padding:10px 12px max(10px,env(safe-area-inset-bottom)); background:var(--surface); }
.composer textarea { resize:none; min-height:48px; max-height:144px; border-radius:24px; padding:12px 16px; background:var(--bg); line-height:22px; }
.composer button { min-width:44px; min-height:48px; border-radius:18px; padding:8px; }
.reply-bar { background:var(--surface); border-color:var(--border); }
dialog { border:1px solid var(--border); border-radius:24px; padding:22px; gap:12px; width:min(440px,calc(100vw - 24px)); min-width:0; max-height:calc(100dvh - 32px); overflow:auto; box-shadow:0 18px 64px #05192244; }
dialog::backdrop { background:#08192399; }
dialog .actions { flex-wrap:wrap; }
.call { background:#101b22; }
.call .call-info { background:linear-gradient(transparent,#101b22); padding:24px; }
.call .call-info h2 { color:#fff; font-size:1.6rem; }
.call .call-controls { background:#101b22; gap:12px; padding-bottom:max(24px,env(safe-area-inset-bottom)); }
.call .call-controls button { min-height:52px; border-radius:20px; }
.call video.local { border-radius:20px; border:1px solid #ffffff50; }
.group-call { width:min(960px,calc(100vw - 24px)); }
.group-players { gap:12px; grid-template-columns:repeat(auto-fit,minmax(min(200px,100%),1fr)); }
.group-players figure { background:var(--bg); border-radius:18px; overflow:hidden; }
.group-players video { aspect-ratio:16 / 10; object-fit:contain; display:block; }
.group-players figcaption { padding:8px 12px; font-size:.85rem; }
@media (max-width:420px) {
  header { gap:2px; padding:10px 8px; min-height:64px; }
  header h1 { font-size:1.05rem; }
  header .icon { min-width:40px; }
  main.page { padding:18px; }
  .messages { padding:14px 10px; }
  .composer { padding-inline:6px; gap:4px; }
  .composer button { min-width:40px; }
}
.chat-entry { display:flex; align-items:center; }
.chat-entry .row { min-width:0; flex:1; padding-right:6px; }
.pin-chat { flex:none; width:40px; padding:8px; margin-right:8px; background:transparent; color:var(--muted); opacity:.6; }
.pin-chat.selected { color:var(--primary); opacity:1; background:var(--mine); }
.pin-chat:hover, .pin-chat:focus-visible { opacity:1; }
/* Одно меню сообщения вместо перекрывающих текст кнопок. */
.bubble { min-width:110px; }
.bubble .time { padding-right:34px; min-height:24px; }
.bubble-menu { position:absolute; right:2px; bottom:0; width:40px; min-height:36px; padding:4px; color:var(--muted); background:transparent; font-size:1.2rem; }
.message-actions .actions { flex-direction:column; gap:8px; }
.message-actions .actions button { text-align:left; padding:12px 16px; background:var(--bg); color:var(--text); }
.settings-section { padding:20px; border:1px solid var(--border); border-radius:22px; display:flex; flex-direction:column; gap:12px; background:var(--surface); }
.settings-section h2 { margin:0 0 6px; }
.settings-section p { font-size:.875rem; }
.settings-section label { line-height:1.6; }
@media(max-width:420px) { main.settings-page { padding:12px; } .settings-section { padding:16px; } }
.member-row { flex-wrap:wrap; gap:10px; border:1px solid var(--border); border-radius:18px; margin-bottom:8px; background:var(--surface); }
.member-row .grow { flex-basis:calc(100% - 72px); }
.member-row button { font-size:.8rem; flex:1 1 auto; }
.row input, .row select { min-width:0; }

.call-portrait { flex:1; min-height:160px; display:grid; place-items:center; background:radial-gradient(ellipse at center,#204d51 0%,#101b22 70%); }
.call-avatar { display:grid; place-items:center; width:128px; height:128px; border-radius:44px; background:#75d7c925; color:#a2ebdc; font-size:2.8rem; font-weight:650; }
.call-portrait[hidden], .call video[hidden] { display:none; }

/* Голосовая заметка остаётся локальной до явной отправки. */
.voice-mic {touch-action:none;user-select:none}
.voice-preview {display:flex;align-items:center;gap:8px;padding:8px 12px;flex-wrap:wrap;background:var(--surface)}
.voice-preview[hidden] {display:none}
.voice-preview audio {min-width:180px;flex:1;height:40px}

.chat-header {gap:6px;padding-block:8px}
.chat-heading {display:flex;align-items:center;gap:10px;flex:1;min-width:0}
.chat-heading .avatar {width:36px;height:36px;font-size:14px;flex-shrink:0}
.chat-heading-text {min-width:0;display:flex;flex-direction:column;gap:2px}
.chat-heading h1 {font-size:16px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.chat-heading small {font-size:11px;opacity:.75}
.chat-header .icon {min-width:40px;padding:8px}
.day-divider {align-self:center;text-align:center;font-size:12px;opacity:.75;margin:10px 0}
.messages .consecutive {margin-top:2px}
/* Ссылка открывает установленное Android-приложение без регистрации в браузере. */
a.button { display:block; min-height:44px; padding:12px 18px; border-radius:14px; background:var(--primary); color:var(--on-primary, #082725); text-align:center; text-decoration:none; font-weight:600; }
a.button:focus-visible { outline:3px solid var(--primary); outline-offset:3px; }
.settings-entry { display:flex; align-items:center; gap:16px; width:100%; text-align:left; padding:20px; }
.settings-entry span:first-of-type { flex:1; }
.settings-entry svg { width:24px; height:24px; }
.local-camera-state { position:absolute; right:12px; top:12px; width:28vw; max-width:180px; min-height:120px; display:grid; place-items:center; padding:12px; border-radius:20px; color:white; background:#26383f; }
.local-camera-state[hidden] { display:none; }
.settings-profile { display:flex; align-items:center; gap:16px; width:100%; text-align:left; padding:20px; }
.settings-profile img { width:64px; height:64px; object-fit:cover; border-radius:20px; }
.settings-profile small { display:block; margin-top:4px; }
.emoji-panel { flex:none; min-width:0; border-top:1px solid var(--border); background:var(--surface); padding:0 8px max(8px,env(safe-area-inset-bottom)); }
.emoji-panel[hidden] { display:none; }
.emoji-heading { display:flex; align-items:center; justify-content:space-between; padding:4px 8px; }
.emoji-heading button { min-height:40px; padding:6px 10px; }
.emoji-tabs { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:4px; padding:4px 0; }
.emoji-tabs button { min-width:0; background:transparent; color:var(--text); border-radius:12px; min-height:44px; padding:8px 3px; font-size:13px; }
.emoji-tabs button[aria-selected="true"] { background:var(--mine); color:var(--primary); }
.emoji-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(44px,1fr)); gap:4px; max-height:min(196px,32dvh); overflow-y:auto; overscroll-behavior:contain; padding:4px; }
.emoji-grid button { min-width:0; min-height:44px; padding:3px; font-size:27px; line-height:38px; background:transparent; color:var(--text); touch-action:manipulation; border-radius:12px; }
.emoji-grid button:hover { background:var(--mine); }
.composer:has(+ .emoji-panel:not([hidden])) { padding-bottom:8px; }

.login-methods { display:flex; flex-wrap:wrap; gap:8px; margin-bottom:16px; }
.login-methods button[aria-pressed="true"] { background:var(--mine); color:var(--primary); }
