:root {
  --green: #21c063;
  --green-text: #1daa61;
  --tint: #000;
  --bg: #fff;
  --text: #000;
  --sub: #8a8a8e;
  --sep: rgba(60, 60, 67, 0.16);
  --bar: rgba(247, 247, 247, 0.94);
  --field: rgba(118, 118, 128, 0.12);
  --out: #d9fdd3;
  --in: #fff;
  --meta: #667781;
  --read: #4fb6ec;
  --wall: #efe7de;
  --vh: 100dvh;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; overscroll-behavior: none; }
body { position: fixed; inset: 0; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
svg { display: block; }
.noselect { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

#app { position: absolute; left: 0; right: 0; top: 0; height: var(--vh); overflow: hidden; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.layer-chat { transform: translateX(100%); transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1); z-index: 5; }
.layer-chat.in { transform: none; }
.layer-list { transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1); }
.layer-list.behind { transform: translateX(-28%); }

/* ---------- auth screens ---------- */
.splash { align-items: center; justify-content: center; }
.splash .logo { width: 84px; height: 84px; border-radius: 50%; background: var(--green); display: grid; place-items: center; }
.splash .from { position: absolute; bottom: calc(28px + var(--safe-bottom)); color: var(--sub); font-size: 13px; text-align: center; }
.welcome { align-items: center; justify-content: center; padding: 0 32px calc(40px + var(--safe-bottom)); text-align: center; }
.welcome .art { width: 260px; height: 260px; border-radius: 50%; background: #e7fce3; display: grid; place-items: center; margin-bottom: 36px; }
.welcome h1 { font-size: 28px; font-weight: 700; margin: 0 0 14px; letter-spacing: -0.3px; }
.welcome p { font-size: 15px; line-height: 1.35; color: var(--sub); margin: 0 0 22px; }
.welcome p a { color: var(--green-text); text-decoration: none; }
.link-btn { color: var(--green-text); font-size: 18px; font-weight: 600; padding: 10px; }
.navbar { display: flex; align-items: center; justify-content: space-between; padding: calc(var(--safe-top) + 10px) 16px 10px; min-height: 52px; }
.navbar .title { font-size: 17px; font-weight: 600; }
.navbar .action { color: var(--green-text); font-size: 17px; font-weight: 600; min-width: 60px; text-align: right; }
.navbar .action[disabled] { color: #c7c7cc; }
.navbar .back { min-width: 60px; }
.form-hint { color: #3c3c43; font-size: 15px; line-height: 1.35; text-align: center; padding: 6px 28px 22px; }
.group { margin: 0 16px; background: #fff; border-top: 0.5px solid var(--sep); border-bottom: 0.5px solid var(--sep); }
.page-gray { background: #f2f2f7; }
.page-gray .group { border-radius: 12px; border: 0; }
.cell { display: flex; align-items: center; min-height: 46px; padding: 0 14px; font-size: 17px; }
.cell + .cell { border-top: 0.5px solid var(--sep); }
.cell .grow { flex: 1; }
.cell .chev { color: #c4c4c7; }
.country { color: var(--green-text); }
.phone-cell .cc { width: 56px; border-right: 0.5px solid var(--sep); align-self: stretch; display: flex; align-items: center; }
.phone-cell input { flex: 1; border: 0; outline: 0; padding: 0 12px; font-size: 17px; background: transparent; height: 46px; }
.code-box { display: flex; justify-content: center; gap: 6px; margin: 8px 0 18px; }
.code-box span { width: 34px; height: 46px; border-radius: 8px; background: #f2f2f7; display: grid; place-items: center; font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.code-box .dash { width: 12px; background: none; }
.steps { color: #3c3c43; font-size: 15px; line-height: 1.5; padding: 0 28px; }
.steps b { font-weight: 600; }
.center-note { text-align: center; color: var(--sub); font-size: 15px; padding: 20px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid #e5e5ea; border-top-color: var(--green); animation: spin 0.9s linear infinite; margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { height: 4px; border-radius: 2px; background: #e5e5ea; margin: 18px 48px 0; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--green); transition: width 0.4s; }
.gate { justify-content: center; padding: 0 24px; gap: 12px; background: #f2f2f7; }
.gate input { height: 48px; border-radius: 12px; border: 0; padding: 0 14px; font-size: 17px; background: #fff; outline: 0; }
.gate button { height: 48px; border-radius: 12px; background: var(--green); color: #fff; font-weight: 600; font-size: 17px; }
.gate .err { color: #ff3b30; font-size: 14px; min-height: 18px; text-align: center; }

/* ---------- chat list ---------- */
.list-top { padding: calc(var(--safe-top) + 6px) 16px 0; background: #fff; }
.list-top .row1 { display: flex; align-items: center; justify-content: space-between; height: 44px; }
.circle-btn { width: 30px; height: 30px; border-radius: 50%; background: var(--field); display: grid; place-items: center; }
.green-btn { width: 30px; height: 30px; border-radius: 50%; background: var(--green); display: grid; place-items: center; color: #fff; }
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; }
.list-top .right { display: flex; align-items: center; gap: 14px; }
.big-title { font-size: 34px; font-weight: 700; letter-spacing: 0.2px; margin: 2px 0 8px; }
.search { display: flex; align-items: center; gap: 6px; height: 36px; border-radius: 10px; background: var(--field); padding: 0 8px; color: var(--sub); font-size: 17px; }
.chips { display: flex; gap: 8px; padding: 12px 0 8px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 32px; padding: 0 14px; border-radius: 16px; background: #f0f0f0; color: #545458; font-size: 15px; font-weight: 500; display: flex; align-items: center; }
.chip.on { background: #d9fdd3; color: #0b5c34; }
.list-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.archive-row { display: flex; align-items: center; height: 48px; padding: 0 16px; gap: 22px; font-size: 17px; font-weight: 600; }
.archive-row .ico { width: 28px; display: grid; place-items: center; color: #545458; margin-left: 12px; }
.archive-row .cnt { margin-left: auto; color: var(--sub); font-weight: 400; font-size: 15px; }
.chat-row { display: flex; align-items: center; height: 76px; padding-left: 16px; position: relative; }
.chat-row:active { background: #e5e5ea; }
.chat-row .av { width: 52px; height: 52px; margin-right: 12px; flex: none; }
.chat-row .body { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: center; padding-right: 16px; border-bottom: 0.5px solid var(--sep); }
.chat-row:last-child .body { border-bottom: 0; }
.chat-row .top { display: flex; align-items: baseline; gap: 8px; }
.chat-row .name { flex: 1; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row .time { font-size: 15px; color: var(--sub); flex: none; }
.chat-row .time.unread { color: var(--green-text); }
.chat-row .bottom { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.chat-row .preview { flex: 1; min-width: 0; font-size: 15px; color: var(--sub); line-height: 20px; height: 40px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.chat-row .preview .pv-ico { display: inline-block; vertical-align: -3px; margin-right: 3px; }
.chat-row .preview .who { color: #3c3c43; }
.chat-row .preview i { font-style: italic; }
.chat-row .flags { display: flex; gap: 6px; align-items: center; align-self: flex-start; padding-top: 2px; color: #b0b0b5; }
.badge { min-width: 20px; height: 20px; border-radius: 10px; background: var(--green); color: #fff; font-size: 13px; font-weight: 600; display: grid; place-items: center; padding: 0 6px; }
.empty-list { padding: 60px 30px; color: var(--sub); text-align: center; font-size: 15px; }

.tabbar { display: flex; border-top: 0.5px solid var(--sep); background: var(--bar); padding-bottom: var(--safe-bottom); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 0 4px; font-size: 10px; font-weight: 500; color: #000; position: relative; }
.tab.on { color: #000; font-weight: 700; }
.tab .tbadge { position: absolute; top: 2px; left: 50%; margin-left: 6px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--green); color: #fff; font-size: 12px; font-weight: 600; display: grid; place-items: center; padding: 0 5px; }
.placeholder { flex: 1; display: flex; flex-direction: column; }
.placeholder .big-title { padding: calc(var(--safe-top) + 50px) 16px 0; }
.placeholder .note { color: var(--sub); padding: 16px; font-size: 15px; }
.settings-card { margin: 8px 16px; border-radius: 12px; background: #fff; display: flex; align-items: center; gap: 12px; padding: 12px; }
.settings-card .av { width: 60px; height: 60px; }
.danger { color: #ff3b30; }

/* ---------- avatar ---------- */
.av { border-radius: 50%; background: #dfe5e7; overflow: hidden; position: relative; display: block; }
.av img { width: 100%; height: 100%; object-fit: cover; display: block; position: absolute; inset: 0; }
.av svg { width: 100%; height: 100%; }

/* ---------- chat ---------- */
.chat-head { display: flex; align-items: center; gap: 6px; padding: calc(var(--safe-top) + 4px) 10px 6px 4px; background: var(--bar); border-bottom: 0.5px solid var(--sep); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); z-index: 2; min-height: 54px; }
.chat-head .back { display: flex; align-items: center; color: var(--tint); font-size: 17px; height: 44px; padding: 0 2px 0 4px; }
.chat-head .back .cnt { font-size: 15px; font-weight: 600; background: var(--field); border-radius: 10px; padding: 1px 7px; margin-left: -2px; }
.chat-head .av { width: 36px; height: 36px; flex: none; }
.chat-head .who { flex: 1; min-width: 0; padding-left: 6px; }
.chat-head .who .n { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .who .s { font-size: 12px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .acts { display: flex; gap: 18px; padding-right: 6px; color: var(--tint); }
.wall { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; background-color: var(--wall); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='none' stroke='%23b8a998' stroke-opacity='.28' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='24' cy='26' r='9'/%3E%3Cpath d='M70 18l8 8-8 8M100 20h18v14h-18zM104 20v-4h10v4'/%3E%3Cpath d='M136 40c6-10 18-4 12 6l-12 10-12-10c-6-10 6-16 12-6z'/%3E%3Cpath d='M18 74c10 0 14 10 24 0M60 66l14 14M74 66L60 80'/%3E%3Ccircle cx='112' cy='78' r='12'/%3E%3Cpath d='M108 76h.1M117 76h.1M106 84c3 3 9 3 12 0'/%3E%3Cpath d='M20 118l10-12 10 12zM58 112a10 10 0 1 0 20 0 10 10 0 1 0-20 0M98 108h26l-6 18h-14z'/%3E%3Cpath d='M140 106v22M130 116h20'/%3E%3Cpath d='M30 150h20M40 140v20M80 146c8-8 16 8 24 0M128 144l8 8 12-14'/%3E%3C/g%3E%3C/svg%3E"); background-size: 160px; padding: 8px 0 8px; }
.wall.custom { background-image: url('/wallpaper.jpg'); background-size: cover; background-attachment: local; }
.date-pill { display: flex; justify-content: center; margin: 10px 0 8px; }
.date-pill span { background: #fff; color: #54656f; font-size: 12.5px; font-weight: 500; padding: 5px 10px; border-radius: 8px; box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13); }
.sys-pill { display: flex; justify-content: center; margin: 8px 30px; }
.sys-pill span { background: #fdf4c5; color: #54656f; font-size: 12.5px; padding: 6px 10px; border-radius: 8px; text-align: center; line-height: 1.35; box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13); }
.msg { display: flex; padding: 0 12px; margin-top: 2px; }
.msg.first { margin-top: 8px; }
.msg.out { justify-content: flex-end; }
.bubble { position: relative; max-width: 78%; padding: 6px 8px 7px 9px; border-radius: 15px; font-size: 16.5px; line-height: 21px; background: var(--in); box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13); word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; }
.out .bubble { background: var(--out); }
.msg.first.in .bubble { border-top-left-radius: 4px; }
.msg.first.out .bubble { border-top-right-radius: 4px; }
.msg.first.in .bubble::before, .msg.first.out .bubble::before { content: ''; position: absolute; top: 0; width: 10px; height: 13px; background: inherit; }
.msg.first.in .bubble::before { left: -8px; clip-path: path('M1.5 0 H10 V12 L0.8 1.9 Q0 0.4 1.5 0 Z'); }
.msg.first.out .bubble::before { right: -8px; clip-path: path('M8.5 0 H0 V12 L9.2 1.9 Q10 0.4 8.5 0 Z'); }
.bubble .sender { font-size: 13.5px; font-weight: 600; margin-bottom: 1px; }
.bubble .spacer { display: inline-block; height: 1px; vertical-align: bottom; }
.meta { position: absolute; right: 8px; bottom: 4px; display: flex; align-items: center; gap: 3px; font-size: 11px; color: var(--meta); font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1; }
.meta .ck { color: #8696a0; }
.meta .ck.read { color: var(--read); }
.bubble.media { padding: 3px; }
.bubble.media .img { display: block; border-radius: 12px; max-width: 100%; width: 260px; min-height: 120px; object-fit: cover; background: #d0d7db; }
.bubble.media .cap { padding: 5px 6px 2px 6px; }
.bubble.media.nocap .meta { color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, 0.35)); padding: 14px 6px 2px 20px; border-radius: 0 0 12px 0; right: 3px; bottom: 3px; }
.bubble.media.nocap .meta .ck { color: #fff; }
.bubble.media.nocap .meta .ck.read { color: #9fdcff; }
.bubble.deleted { color: #8696a0; font-style: italic; }
.voice { display: flex; align-items: center; gap: 8px; width: 240px; padding: 4px 0 10px; }
.voice .play { color: #8696a0; flex: none; }
.voice .wave { flex: 1; display: flex; align-items: center; gap: 2px; height: 26px; }
.voice .wave i { flex: 1; background: #b4bcc0; border-radius: 2px; }
.bubble .dur { position: absolute; left: 61px; bottom: 5px; font-size: 11px; color: var(--meta); }
.voice .vav { width: 40px; height: 40px; flex: none; }
.doc { display: flex; align-items: center; gap: 8px; background: rgba(0, 0, 0, 0.04); border-radius: 8px; padding: 8px; margin-bottom: 14px; min-width: 200px; }
.label-ico { display: inline-flex; align-items: center; gap: 4px; color: #54656f; }
.msg.pop { animation: pop 0.22s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 6px 10px calc(6px + var(--safe-bottom)); background: var(--bar); border-top: 0.5px solid var(--sep); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); }
.composer .icon-btn { height: 36px; width: 30px; color: var(--tint); }
.composer .field { flex: 1; display: flex; align-items: flex-end; background: #fff; border: 0.5px solid #d1d1d6; border-radius: 18px; min-height: 36px; padding: 0 6px 0 12px; }
.composer textarea { flex: 1; border: 0; outline: 0; resize: none; background: transparent; font-size: 17px; line-height: 22px; padding: 7px 0; max-height: 120px; }
.composer .stk { height: 34px; display: grid; place-items: center; color: var(--tint); }
.send-btn { width: 34px; height: 34px; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; margin-bottom: 1px; }

/* ---------- edit mode (не для съёмки) ---------- */
.edit-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 8px; background: #fff7d6; border-bottom: 1px solid #f0d77a; font-size: 13px; }
.edit-bar .seg { display: flex; border-radius: 8px; overflow: hidden; border: 1px solid #d4b84a; }
.edit-bar .seg button { padding: 5px 10px; font-size: 13px; font-weight: 600; background: #fff; }
.edit-bar .seg button.on { background: #d4b84a; color: #fff; }
.edit-bar input[type='time'], .edit-bar .tbtn { height: 30px; border-radius: 8px; border: 1px solid #d4b84a; background: #fff; padding: 0 8px; font-size: 13px; font-weight: 600; }
.edit-bar .done { margin-left: auto; background: #1f1f1f; color: #fff; border-color: #1f1f1f; }
.editing .msg { cursor: pointer; }
.editing .msg.sel .bubble { outline: 2px solid #d4b84a; outline-offset: 2px; }
.insert-mark { height: 3px; margin: 6px 20px; background: #d4b84a; border-radius: 2px; }
.edit-tip { text-align: center; color: #8a6d00; font-size: 12px; padding: 6px; }

.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.35); display: flex; align-items: flex-end; animation: fade 0.18s; }
@keyframes fade { from { opacity: 0; } }
.sheet { width: 100%; max-height: 88%; overflow-y: auto; background: #f2f2f7; border-radius: 14px 14px 0 0; padding: 14px 14px calc(14px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 10px; animation: up 0.24s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes up { from { transform: translateY(100%); } }
.sheet h3 { margin: 2px 0 4px; font-size: 17px; text-align: center; }
.sheet label { font-size: 13px; color: #6d6d72; display: flex; flex-direction: column; gap: 4px; }
.sheet input, .sheet textarea, .sheet select { border: 0; border-radius: 10px; background: #fff; padding: 10px 12px; font-size: 16px; outline: 0; width: 100%; }
.sheet textarea { min-height: 90px; resize: vertical; }
.sheet .row { display: flex; gap: 8px; }
.sheet .row > * { flex: 1; }
.sheet .btn { height: 46px; border-radius: 12px; background: #fff; font-size: 17px; font-weight: 600; color: #007aff; }
.sheet .btn.primary { background: var(--green); color: #fff; }
.sheet .btn.red { color: #ff3b30; }
.sheet .seg { display: flex; background: #e3e3e8; border-radius: 9px; padding: 2px; }
.sheet .seg button { flex: 1; height: 32px; border-radius: 7px; font-size: 14px; font-weight: 600; }
.sheet .seg button.on { background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.sheet .av-pick { display: flex; align-items: center; gap: 12px; }
.sheet .av-pick .av { width: 56px; height: 56px; }
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%); background: rgba(0, 0, 0, 0.78); color: #fff; padding: 8px 14px; border-radius: 10px; font-size: 14px; z-index: 60; }
