:root {
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #dbeafe;
  --bg: #f4f5f2;
  --surface: #ffffff;
  --ink: #16201f;
  --muted: #66716f;
  --line: #e2e6e3;
  --mine: #2563eb;
  --mine-ink: #ffffff;
  --theirs: #ffffff;
  --theirs-ink: #16201f;
  --danger: #b42318;
  --ok: #15803d;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #60a5fa;
    --accent-ink: #0b1a33;
    --accent-soft: #172554;
    --bg: #0d1220;
    --surface: #161d2e;
    --ink: #e8eeed;
    --muted: #93a19e;
    --line: #253049;
    --mine: #1d4ed8;
    --mine-ink: #f8fbff;
    --theirs: #1e273b;
    --theirs-ink: #e8eeed;
    --danger: #f97066;
    --ok: #4ade80;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

#app {
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ---------- Шапка ---------- */
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  min-height: 56px;
}
.bar h1 { font-size: 20px; margin: 0 0 0 6px; flex: 1; letter-spacing: -0.01em; }
.bar .title { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 4px 6px; }
.bar .title b { display: block; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .title small { color: var(--muted); font-size: 13px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: transparent; display: grid; place-items: center; flex: none;
}
.icon-btn:active { background: var(--line); }
.icon-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; margin-right: 6px; }
.status-dot.on { background: var(--ok); }
.status-dot.poll { background: #d97706; }

/* ---------- Список чатов ---------- */
.list { flex: 1; overflow-y: auto; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 16px; border: 0; border-bottom: 1px solid var(--line);
  background: var(--surface); text-align: left;
}
.row:active { background: var(--line); }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 650; font-size: 17px;
  color: #fff;
}
.row .meta { flex: 1; min-width: 0; }
.row .top { display: flex; justify-content: space-between; gap: 8px; }
.row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .time { color: var(--muted); font-size: 13px; flex: none; }
.row .preview { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; justify-content: space-between; gap: 8px; }
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: 12px; font-weight: 700; padding: 1px 7px; flex: none; }

.empty { flex: 1; display: grid; place-items: center; text-align: center; padding: 32px; color: var(--muted); }
.empty b { color: var(--ink); display: block; font-size: 18px; margin-bottom: 6px; }

.fab {
  position: fixed; right: max(20px, calc(50vw - 340px)); bottom: calc(24px + var(--safe-bottom));
  width: 58px; height: 58px; border-radius: 18px; border: 0;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 6px 20px rgb(0 0 0 / .18); display: grid; place-items: center;
}
.fab svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; }

/* ---------- Чат ---------- */
.messages { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; color: var(--muted); font-size: 12px; margin: 10px 0 4px; background: var(--surface); padding: 3px 10px; border-radius: 999px; }
.bubble {
  max-width: 82%; padding: 8px 12px 6px; border-radius: var(--radius);
  white-space: pre-wrap; overflow-wrap: anywhere; position: relative;
  box-shadow: 0 1px 1px rgb(0 0 0 / .06);
}
.bubble.theirs { align-self: flex-start; background: var(--theirs); color: var(--theirs-ink); border-bottom-left-radius: 6px; }
.bubble.mine { align-self: flex-end; background: var(--mine); color: var(--mine-ink); border-bottom-right-radius: 6px; }
.bubble.bad { font-style: italic; opacity: .75; }
.bubble .stamp { font-size: 11px; opacity: .7; margin-left: 10px; float: right; margin-top: 6px; }
.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px; min-height: 42px;
  padding: 10px 14px; border-radius: 21px; border: 1px solid var(--line);
  background: var(--bg); outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.send {
  width: 42px; height: 42px; border-radius: 50%; border: 0; flex: none;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
}
.send:disabled { opacity: .4; }
.send svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Формы и страницы ---------- */
.page { flex: 1; overflow-y: auto; padding: 20px 16px calc(32px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h2 { font-size: 15px; margin: 0 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.card p { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
label { display: block; font-size: 14px; color: var(--muted); margin: 0 0 6px; }
.input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); outline: none;
}
.input:focus { border-color: var(--accent); }
.input.id { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .15em; text-transform: uppercase; font-size: 20px; }
textarea.input { min-height: 90px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.btn {
  width: 100%; padding: 13px 16px; border-radius: 14px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 650;
}
.btn.secondary { background: var(--accent-soft); color: var(--ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn + .btn { margin-top: 8px; }
.big-id {
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 30px; font-weight: 700;
  letter-spacing: .14em; text-align: center; padding: 8px 0 12px; color: var(--accent);
}
.code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 20px; text-align: center;
  letter-spacing: .06em; line-height: 1.6; padding: 6px 0 10px;
}
.verified { color: var(--ok); font-weight: 600; }
.unverified { color: #d97706; font-weight: 600; }
.hint { font-size: 13px; color: var(--muted); }

/* ---------- Приветствие ---------- */
.welcome { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 18px; padding: 32px 24px calc(32px + var(--safe-bottom)); }
.logo { width: 96px; height: 96px; border-radius: 22px; margin: 0 auto; display: block; box-shadow: 0 10px 30px rgb(37 99 235 / .3); }
.welcome h1 { text-align: center; font-size: 34px; margin: 0; letter-spacing: -0.02em; }
.welcome .lead { text-align: center; color: var(--muted); margin: 0 0 12px; }
.points { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 10px; }
.points li { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; font-size: 15px; }

#toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px); z-index: 10;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Безопасность ---------- */
.messages, .list { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.cipher { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .02em; }
.bubble.cipher { opacity: .85; }
.bubble.selected { outline: 3px solid var(--accent); outline-offset: 2px; }
body.privacy #app { filter: blur(24px); }

select.input { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
.switch { display: flex; align-items: center; gap: 12px; color: var(--ink); font-size: 15px; margin: 4px 0; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 8px 0 4px; text-align: center; }
.warn { color: #b45309; font-size: 13px; margin: 12px 0 0 !important; }
@media (prefers-color-scheme: dark) { .warn { color: #fbbf24; } }

.lockform { display: flex; flex-direction: column; gap: 10px; }
.lockform .input { text-align: center; font-size: 18px; }

.overlay {
  position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
.sheet {
  width: 100%; max-width: 480px; background: var(--surface);
  border-radius: 22px 22px 0 0; padding: 22px 18px calc(18px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 10px; text-align: center;
  animation: up .2s ease;
}
.sheet b { font-size: 17px; margin-bottom: 4px; }
.sheet .error { margin: 0; }
.sheet .btn + .btn { margin-top: 0; }
.sheet-icon { width: 48px; height: 48px; margin: 0 auto; border-radius: 50%; background: var(--accent-soft); display: grid; place-items: center; }
.sheet-icon svg { width: 24px; height: 24px; stroke: var(--accent); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@media (min-width: 600px) { .overlay { align-items: center; } .sheet { border-radius: 22px; } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }

/* ---------- VPN ---------- */
.card.center { text-align: center; }
.qr { width: 100%; max-width: 280px; aspect-ratio: 1; margin: 6px auto 4px; display: block; background: #fff; border-radius: 14px; padding: 8px; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; font-size: 15px; }

/* ---------- Звонок ---------- */
.call-screen {
  position: fixed; inset: 0; z-index: 30; color: #fff;
  background: radial-gradient(120% 80% at 50% 0%, #1d4ed8 0%, #0b1226 60%, #060912 100%);
  display: flex; flex-direction: column; align-items: center;
  padding: calc(40px + var(--safe-top)) 20px calc(28px + var(--safe-bottom));
  animation: fade .2s ease;
}
.call-screen .remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; display: none; }
.call-screen.video.live .remote { display: block; }
.call-screen .local {
  position: absolute; top: calc(16px + var(--safe-top)); right: 16px; width: 104px; aspect-ratio: 3 / 4;
  object-fit: cover; border-radius: 14px; background: #111; transform: scaleX(-1);
  box-shadow: 0 6px 20px rgb(0 0 0 / .4); display: none; z-index: 2;
}
.call-screen.has-local .local { display: block; }
.call-top { position: relative; z-index: 1; text-align: center; margin-top: 8vh; }
.call-screen.video.live .call-top { margin-top: 0; align-self: flex-start; text-align: left; text-shadow: 0 1px 4px rgb(0 0 0 / .6); }
.call-screen.video.live .call-avatar { display: none; }
.call-avatar {
  width: 112px; height: 112px; border-radius: 50%; margin: 0 auto 18px;
  background: rgb(255 255 255 / .14); display: grid; place-items: center; font-size: 46px; font-weight: 650;
  box-shadow: 0 0 0 10px rgb(255 255 255 / .05), 0 0 0 22px rgb(255 255 255 / .03);
}
.call-name { font-size: 26px; font-weight: 650; }
.call-status { opacity: .8; margin-top: 6px; font-size: 15px; font-variant-numeric: tabular-nums; }
.call-voice {
  position: relative; z-index: 1; margin-top: auto; margin-bottom: 22px;
  display: flex; align-items: center; gap: 8px; font-size: 14px;
  background: rgb(0 0 0 / .35); padding: 6px 8px 6px 12px; border-radius: 999px;
}
.call-voice svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; display: block; }
.voice-sel { background: rgb(255 255 255 / .15); color: #fff; border: 0; border-radius: 999px; padding: 6px 10px; font-size: 14px; }
.voice-sel option { color: #000; }
.call-controls { position: relative; z-index: 1; display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; }
.call-ctl { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; opacity: .95; width: 68px; text-align: center; }
.call-btn {
  width: 62px; height: 62px; border-radius: 50%; border: 0; color: #fff;
  background: rgb(255 255 255 / .16); display: grid; place-items: center; backdrop-filter: blur(8px);
}
.call-btn svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.call-btn.off { background: #fff; color: #0b1226; }
.call-btn.red { background: #e5383b; }
.call-btn.green { background: #16a34a; }
.call-btn.red svg { transform: rotate(0deg); }

/* ---------- Запись экрана (только в приложении для Android/iPhone) ---------- */
.capture-cover { display: none; }
body.captured #app, body.captured .call-screen > :not(.capture-cover), body.captured .overlay { visibility: hidden; }
body.captured::after, body.captured .capture-cover {
  content: "Обнаружена запись экрана. Содержимое скрыто.";
  position: fixed; inset: 0; z-index: 100; background: #000; color: #fff;
  display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; text-align: center; padding: 24px; font-size: 16px;
}
body.captured .call-screen .capture-cover { visibility: visible; }

/* ---------- Защита от съёмки другим телефоном ---------- */
#watermark { position: fixed; inset: 0; z-index: 50; pointer-events: none; display: none; background-repeat: repeat; }
.day.sys { font-size: 12px; max-width: 86%; text-align: center; }
.once-btn {
  width: 42px; height: 42px; border-radius: 50%; flex: none; border: 1px solid var(--line);
  background: var(--bg); color: var(--muted); font-weight: 700; font-size: 14px;
}
.once-btn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.bubble.once { cursor: pointer; font-style: italic; border: 1px dashed var(--accent); }
.once-tag { font-weight: 700; opacity: .8; }
.once-view .once-text {
  font-size: 18px; padding: 14px; border-radius: 14px; background: var(--bg); text-align: left;
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 50vh; overflow-y: auto;
  -webkit-user-select: none; user-select: none;
}

/* ---------- Пароль, предупреждения ---------- */
.strength { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-size: 13px; color: var(--muted); min-height: 18px; }
.strength .bar { flex: 1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.strength .bar i { display: block; height: 100%; width: 0; transition: .2s; }
.key-banner { background: #fef2f2; border-bottom: 1px solid #fecaca; padding: 12px 16px; color: #7f1d1d; }
.key-banner p { margin: 4px 0 10px; font-size: 14px; }
@media (prefers-color-scheme: dark) { .key-banner { background: #3b1111; border-color: #5b1f1f; color: #fecaca; } }
.warn-icon { background: #fef3c7 !important; }
.warn-icon svg { stroke: #b45309 !important; }
.device-warn { background: #fffbeb; border: 1px solid #fde68a; color: #78350f; border-radius: var(--radius); padding: 12px 14px; font-size: 14px; }
@media (prefers-color-scheme: dark) { .device-warn { background: #332507; border-color: #5c4510; color: #fde68a; } }
