:root {
  --accent: #007aff;
  --accent2: #7c5cff;
  --grad: linear-gradient(135deg, #2f8cff 0%, #6a5cff 60%, #a35cff 100%);
  --bg: #ffffff;
  --bg-grouped: #f2f2f7;
  --card: #ffffff;
  --text: #000;
  --text2: #8a8a8e;
  --text3: #c7c7cc;
  --sep: rgba(60, 60, 67, .18);
  --fill: rgba(118, 118, 128, .12);
  --glass: rgba(249, 249, 251, .78);
  --bubble-in: #ffffff;
  --bubble-in-text: #000;
  --shadow: 0 10px 40px rgba(0, 0, 0, .12);
  --danger: #ff3b30;
  --green: #34c759;
  --ease: cubic-bezier(.32, .72, 0, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --rl: #fff4e6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #0a84ff;
    --bg: #000;
    --bg-grouped: #000;
    --card: #1c1c1e;
    --text: #fff;
    --text2: #8d8d93;
    --text3: #48484a;
    --sep: rgba(84, 84, 88, .55);
    --fill: rgba(118, 118, 128, .24);
    --glass: rgba(22, 22, 24, .72);
    --bubble-in: #262628;
    --bubble-in-text: #fff;
    --shadow: 0 10px 40px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --accent: #0a84ff;
  --bg: #000;
  --bg-grouped: #000;
  --card: #1c1c1e;
  --text: #fff;
  --text2: #8d8d93;
  --text3: #48484a;
  --sep: rgba(84, 84, 88, .55);
  --fill: rgba(118, 118, 128, .24);
  --glass: rgba(22, 22, 24, .72);
  --bubble-in: #262628;
  --bubble-in-text: #fff;
  --shadow: 0 10px 40px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { 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 {
  font: 17px/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; letter-spacing: -.01em;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; -webkit-user-select: text; user-select: text; }
svg { display: block; }
.hidden { display: none !important; }
#app { position: fixed; inset: 0; overflow: hidden; }
.screen { position: absolute; inset: 0; }

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
}
.glass-dark {
  background: rgba(30, 30, 32, .55);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  backdrop-filter: saturate(180%) blur(30px);
}

/* ===== Кубик 3D ===== */
.cube-wrap { width: 120px; height: 120px; perspective: 600px; margin: 0 auto; }
.cube-wrap.sm { width: 64px; height: 64px; opacity: .5; }
.cube { --s: 120px; width: var(--s); height: var(--s); position: relative; transform-style: preserve-3d; animation: spin 9s linear infinite; }
.cube-wrap.sm .cube { --s: 64px; }
.cube i {
  position: absolute; inset: 0; border-radius: 22%;
  background: var(--grad); opacity: .92;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .35), inset 0 0 40px rgba(255, 255, 255, .25);
}
.cube .f1 { transform: translateZ(calc(var(--s) / 2)); }
.cube .f2 { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); filter: hue-rotate(40deg); }
.cube .f3 { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); filter: hue-rotate(-30deg) brightness(.85); }
.cube .f4 { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); filter: hue-rotate(20deg) brightness(.9); }
.cube .f5 { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); filter: brightness(1.2); }
.cube .f6 { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); filter: brightness(.7); }
@keyframes spin { from { transform: rotateX(-24deg) rotateY(0); } to { transform: rotateX(-24deg) rotateY(360deg); } }

/* ===== Онбординг ===== */
#onboard {
  display: flex; flex-direction: column; justify-content: space-between; align-items: center;
  padding: calc(var(--sat) + 8vh) 24px calc(var(--sab) + 28px);
  background: radial-gradient(120% 70% at 50% 0%, rgba(106, 92, 255, .28), transparent 60%), var(--bg);
}
.ob-hero { text-align: center; animation: rise .9s var(--ease) both; }
.ob-title { font-size: 44px; font-weight: 800; letter-spacing: -.03em; margin: 34px 0 6px; }
.ob-sub { color: var(--text2); margin: 0; font-size: 17px; }
.ob-step { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; animation: rise .7s var(--ease) .15s both; }
.ob-features { display: grid; gap: 14px; margin-bottom: 18px; }
.ob-features div { display: grid; grid-template-columns: 44px 1fr; grid-template-rows: auto auto; column-gap: 12px; align-items: center; }
.ob-features span { grid-row: span 2; font-size: 28px; width: 44px; height: 44px; display: grid; place-items: center; background: var(--fill); border-radius: 12px; }
.ob-features b { font-size: 16px; }
.ob-features small { color: var(--text2); font-size: 14px; }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.98); } to { opacity: 1; transform: none; } }
.btn-primary {
  height: 52px; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 600; font-size: 17px;
  transition: transform .2s var(--ease), opacity .2s;
}
.btn-primary:active { transform: scale(.97); opacity: .85; }
.btn-text { color: var(--accent); font-size: 17px; padding: 10px; }
.field { display: flex; align-items: center; background: var(--fill); border-radius: 12px; padding: 0 14px; height: 50px; }
.field input { flex: 1; border: 0; background: none; outline: none; height: 100%; font-size: 17px; }
.field.at span { color: var(--text2); margin-right: 2px; }
.hint { color: var(--text2); font-size: 13px; margin: 0 4px; }
.err { color: var(--danger); font-size: 14px; margin: 0 4px; min-height: 18px; }

/* ===== Главный ===== */
#main { display: flex; }
.sidebar { position: relative; flex: 0 0 auto; width: 100%; height: 100%; background: var(--bg); transition: transform .45s var(--ease), filter .45s; overflow: hidden; }
.tab-page { position: absolute; inset: 0; opacity: 0; pointer-events: none; transition: opacity .25s; }
.tab-page.active { opacity: 1; pointer-events: auto; }
#tabSettings, #tabCalls { background: var(--bg-grouped); }
.scroll { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: calc(var(--sat) + 44px) 0 calc(var(--sab) + 90px); }
.nav { position: absolute; top: 0; left: 0; right: 0; z-index: 5; padding-top: var(--sat); border-bottom: .5px solid transparent; transition: border-color .2s, background .2s; background: transparent; -webkit-backdrop-filter: none; backdrop-filter: none; }
.nav.scrolled { background: var(--glass); border-bottom-color: var(--sep); -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px); }
.nav-row { height: 44px; display: grid; grid-template-columns: 60px 1fr 60px; align-items: center; padding: 0 8px; }
.nav-title.small { text-align: center; font-weight: 600; opacity: 0; transform: translateY(6px); transition: .25s var(--ease); }
.nav.scrolled .nav-title.small { opacity: 1; transform: none; }
.nav-btn { color: var(--accent); height: 44px; display: flex; align-items: center; justify-content: center; }
.nav-btn.icon svg { width: 26px; height: 26px; }
.nav-row > :last-child { justify-self: end; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(52, 199, 89, .25); transition: background .3s; }
.conn.off { background: #ff9f0a; box-shadow: 0 0 0 3px rgba(255, 159, 10, .25); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }
.large-title { font-size: 34px; font-weight: 700; letter-spacing: -.025em; margin: 2px 16px 8px; }
.search { display: flex; align-items: center; gap: 6px; margin: 0 16px 10px; height: 36px; padding: 0 8px; border-radius: 10px; background: var(--fill); color: var(--text2); }
.search svg { width: 18px; height: 18px; flex: none; }
.search input { flex: 1; border: 0; background: none; outline: none; height: 100%; font-size: 17px; color: var(--text); }

.list { position: relative; }
.item { display: flex; align-items: center; gap: 12px; padding: 8px 16px 8px 14px; position: relative; transition: background .15s; width: 100%; text-align: left; animation: itemIn .45s var(--ease) both; }
.item:active, .item.sel { background: var(--fill); }
@media (min-width: 820px) { .item.sel { background: var(--accent); color: #fff; } .item.sel .i-sub, .item.sel .i-time { color: rgba(255,255,255,.8); } }
@keyframes itemIn { from { opacity: 0; transform: translateY(8px); } }
.item .i-body { flex: 1; min-width: 0; align-self: stretch; display: flex; flex-direction: column; justify-content: center; border-bottom: .5px solid var(--sep); padding: 4px 0 10px; }
.item:last-child .i-body { border-bottom: 0; }
.i-top { display: flex; align-items: baseline; gap: 6px; }
.i-name { font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.i-time { color: var(--text2); font-size: 14px; display: flex; align-items: center; gap: 3px; }
.i-bottom { display: flex; align-items: flex-start; gap: 8px; margin-top: 2px; }
.i-sub { color: var(--text2); font-size: 15px; line-height: 1.3; flex: 1; min-width: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.i-sub .typing { color: var(--accent); }
.badge { min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px; background: var(--accent); color: #fff; font-size: 13px; font-weight: 600; font-style: normal; display: inline-grid; place-items: center; animation: pop .35s var(--spring); }
@keyframes pop { from { transform: scale(0); } }
.ticks { color: var(--accent); width: 18px; height: 12px; }
.empty { text-align: center; color: var(--text2); padding: 60px 30px; }
.empty b { color: var(--text); font-size: 20px; display: block; margin-bottom: 6px; }
.empty-ico { font-size: 56px; margin-bottom: 10px; animation: float 3s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px); } }

/* аватар */
.avatar { --size: 56px; width: var(--size); height: var(--size); border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 600; font-size: calc(var(--size) * .38); position: relative; background: var(--av, var(--grad)); text-transform: uppercase; }
.avatar.sm { --size: 38px; }
.avatar.xs { --size: 30px; }
.avatar.xl { --size: 96px; }
.avatar.xxl { --size: 128px; }
.avatar.online::after { content: ""; position: absolute; right: 1px; bottom: 1px; width: 26%; height: 26%; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 2.5px var(--bg); animation: pop .35s var(--spring); }
.avatar.bot { background: var(--grad); }
.avatar.bot::before { content: "🧊"; font-size: calc(var(--size) * .5); }
.avatar.saved { background: linear-gradient(135deg, #3fb5ff, #2f6bff); }
.avatar.saved::before { content: "🔖"; font-size: calc(var(--size) * .45); }
.verified { width: 16px; height: 16px; display: inline-block; vertical-align: -2px; margin-left: 3px; color: var(--accent); }

/* таб-бар */
.tabbar { position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; padding: 6px 0 calc(var(--sab) + 4px); border-top: .5px solid var(--sep); }
.tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--text2); font-size: 10.5px; font-weight: 500; position: relative; transition: color .2s; }
.tabbar svg { width: 28px; height: 28px; transition: transform .35s var(--spring); }
.tabbar button.active { color: var(--accent); }
.tabbar button:active svg { transform: scale(.85); }
.tabbar .badge { position: absolute; top: -2px; left: calc(50% + 6px); }

/* настройки */
.profile-card { text-align: center; padding: 10px 16px 20px; }
.profile-card .avatar { margin: 0 auto 12px; }
.me-name { font-size: 24px; font-weight: 600; }
.me-user { color: var(--text2); margin-top: 2px; }
.group-title { text-transform: uppercase; font-size: 13px; color: var(--text2); margin: 18px 32px 6px; }
.group { background: var(--card); margin: 0 16px 18px; border-radius: 12px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 16px; position: relative; width: 100%; text-align: left; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--sep); }
.row > span:first-child { flex: none; }
.row input { flex: 1; text-align: right; border: 0; background: none; outline: none; color: var(--text2); min-width: 0; }
.row.col { flex-direction: column; align-items: flex-start; gap: 4px; padding-top: 10px; padding-bottom: 12px; }
.row.col small { color: var(--text2); font-size: 13px; }
.row.link:active { background: var(--fill); }
.row.link span { flex: 1; }
.row.danger { color: var(--danger); justify-content: center; }
.chev { width: 8px; height: 8px; border-right: 2px solid var(--text3); border-top: 2px solid var(--text3); transform: rotate(45deg); }
.accent { color: var(--accent); }
.swatches { display: flex; gap: 8px; margin-left: auto; }
.swatches button { width: 26px; height: 26px; border-radius: 50%; background: var(--av); transition: transform .3s var(--spring), box-shadow .2s; }
.swatches button.on { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--accent); transform: scale(1.08); }
.seg { margin-left: auto; display: flex; background: var(--fill); border-radius: 9px; padding: 2px; }
.seg button { padding: 5px 10px; border-radius: 7px; font-size: 13px; font-weight: 500; transition: background .25s, box-shadow .25s; }
.seg button.on { background: var(--card); box-shadow: 0 3px 8px rgba(0, 0, 0, .12); }
.walls { display: flex; gap: 10px; overflow-x: auto; width: 100%; padding: 4px 2px; }
.walls button { flex: none; width: 58px; height: 86px; border-radius: 10px; border: 2px solid transparent; transition: transform .3s var(--spring); }
.walls button.on { border-color: var(--accent); transform: scale(1.05); }
.foot { text-align: center; color: var(--text2); font-size: 13px; }

/* ===== Чат ===== */
.chat-pane { position: absolute; inset: 0; z-index: 10; transform: translateX(100%); transition: transform .45s var(--ease); background: var(--bg); box-shadow: -10px 0 40px rgba(0, 0, 0, .15); }
#main.chat-open .chat-pane { transform: none; }
#main.chat-open .sidebar { transform: translateX(-28%); filter: brightness(.85); }
.chat-placeholder { display: none; }
.chat { position: absolute; inset: 0; display: flex; flex-direction: column; }
.chat-bg { position: absolute; inset: 0; z-index: 0; background: var(--wall, var(--bg-grouped)); transition: background .4s; }
.chat-bg::after { content: ""; position: absolute; inset: 0; background-image: radial-gradient(rgba(255,255,255,.08) 1px, transparent 1.2px); background-size: 22px 22px; opacity: var(--dots, 0); }
.chat-head { position: absolute; top: 0; left: 0; right: 0; z-index: 4; padding: var(--sat) 6px 0; display: flex; align-items: center; height: calc(var(--sat) + 56px); border-bottom: .5px solid var(--sep); }
.back { color: var(--accent); width: 44px; height: 44px; display: flex; align-items: center; position: relative; }
.back svg { width: 26px; height: 26px; }
.back-badge { position: absolute; left: 24px; top: 4px; }
.who { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; text-align: left; }
.who-text { min-width: 0; display: flex; flex-direction: column; }
.who-text b { font-size: 16.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-text small { color: var(--text2); font-size: 13px; transition: color .2s; white-space: nowrap; }
.who-text small.on { color: var(--accent); }
.chat-head .nav-btn { width: 42px; }

.messages { position: relative; z-index: 1; flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: calc(var(--sat) + 66px) 10px 12px; display: flex; flex-direction: column; overscroll-behavior: contain; }
.messages > * { flex-shrink: 0; }
.messages > :first-child { margin-top: auto; }
.day { align-self: center; margin: 10px 0 8px; font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 12px; color: #fff; background: rgba(0, 0, 0, .25); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); position: sticky; top: calc(var(--sat) + 62px); z-index: 2; }
.msg { display: flex; max-width: 82%; margin-top: 2px; position: relative; animation: msgIn .4s var(--spring) both; }
.msg.me { align-self: flex-end; }
.msg.gap { margin-top: 8px; }
@keyframes msgIn { from { opacity: 0; transform: translateY(14px) scale(.92); } }
.msg.me { transform-origin: right bottom; }
.msg:not(.me) { transform-origin: left bottom; }
.bubble { position: relative; padding: 7px 12px 7px; border-radius: 19px; background: var(--bubble-in); color: var(--bubble-in-text); font-size: 16.5px; line-height: 1.32; word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; box-shadow: 0 1px 1px rgba(0, 0, 0, .06); transition: transform .2s var(--ease); -webkit-user-select: text; user-select: text; }
.msg.me .bubble { background: var(--grad); background-attachment: fixed; color: #fff; }
.msg.tail:not(.me) .bubble { border-bottom-left-radius: 6px; }
.msg.tail.me .bubble { border-bottom-right-radius: 6px; }
.bubble a { color: inherit; text-decoration: underline; }
.meta { float: right; margin: 8px -4px -4px 10px; font-size: 11.5px; display: inline-flex; align-items: center; gap: 2px; opacity: .6; white-space: nowrap; line-height: 1; }
.msg.me .meta { opacity: .85; }
.meta svg { width: 16px; height: 11px; }
.bubble.only-emoji { background: none !important; box-shadow: none; font-size: 52px; line-height: 1.1; padding: 2px 0; }
.bubble.only-emoji .meta { color: var(--text2); opacity: 1; }
.bubble.deleted { font-style: italic; opacity: .6; }
.quote { display: block; border-left: 3px solid currentColor; padding: 2px 8px; margin: 2px -4px 5px; border-radius: 4px; background: rgba(127, 127, 127, .14); font-size: 14px; cursor: pointer; }
.msg:not(.me) .quote { border-color: var(--accent); }
.quote b { display: block; font-size: 13.5px; }
.msg:not(.me) .quote b { color: var(--accent); }
.quote span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .85; max-width: 240px; }
.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; clear: both; }
.reacts button { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px 2px 6px; border-radius: 14px; font-size: 14px; background: rgba(127, 127, 127, .18); animation: pop .35s var(--spring); }
.msg:not(.me) .reacts button.mine { background: var(--accent); color: #fff; }
.msg.me .reacts button { background: rgba(255, 255, 255, .22); }
.msg.me .reacts button.mine { background: #fff; color: #5b5cff; }
.reacts small { font-size: 12.5px; font-weight: 600; }
.bubble.media { padding: 3px; overflow: hidden; }
.bubble.media img { display: block; max-width: min(280px, 64vw); max-height: 360px; border-radius: 16px; cursor: zoom-in; }
.bubble.media .meta { position: absolute; right: 10px; bottom: 9px; background: rgba(0, 0, 0, .4); color: #fff; opacity: 1; padding: 3px 6px; border-radius: 10px; margin: 0; }
.circle-msg { width: min(220px, 56vw); height: min(220px, 56vw); border-radius: 50%; overflow: hidden; position: relative; cursor: pointer; box-shadow: var(--shadow); background: #000; }
.circle-msg video { width: 100%; height: 100%; object-fit: cover; }
.circle-msg svg.prog { position: absolute; inset: 0; transform: rotate(-90deg); pointer-events: none; }
.circle-msg svg.prog circle { fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-dasharray: 301.6; stroke-dashoffset: 301.6; opacity: .9; }
.circle-msg .meta { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); background: rgba(0, 0, 0, .45); color: #fff; opacity: 1; margin: 0; padding: 3px 7px; border-radius: 10px; float: none; }
.circle-msg .play { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 13px; }
.circle-msg .play span { background: rgba(0, 0, 0, .4); padding: 3px 8px; border-radius: 10px; }
.circle-msg.playing .play { display: none; }
.circle-msg.big { width: min(320px, 82vw); height: min(320px, 82vw); }
.circle-msg { transition: width .4s var(--spring), height .4s var(--spring); }
.voice { display: flex; align-items: center; gap: 10px; min-width: 210px; padding: 2px 0; }
.voice .vplay { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.msg.me .voice .vplay { background: #fff; color: #5b5cff; }
.voice .vplay svg { width: 18px; height: 18px; }
.voice .bars { display: flex; align-items: center; gap: 2px; height: 26px; flex: 1; }
.voice .bars i { flex: 1; min-width: 2px; border-radius: 2px; background: currentColor; opacity: .35; transition: opacity .2s; }
.voice .bars i.on { opacity: 1; }
.voice .vdur { font-size: 12px; opacity: .7; }
.call-msg { display: flex; align-items: center; gap: 10px; min-width: 170px; }
.call-msg .cm-ico { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: rgba(127, 127, 127, .18); }
.msg.me .call-msg .cm-ico { background: rgba(255, 255, 255, .22); }
.call-msg .cm-ico svg { width: 18px; height: 18px; }
.call-msg small { display: block; opacity: .7; font-size: 13px; }
.call-msg .missed { color: var(--danger); }
.msg.me .call-msg .missed { color: #ffd0cc; }
.typing-dots { display: inline-flex; gap: 3px; align-items: center; }
.typing-dots i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .4; animation: tdot 1.2s infinite; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes tdot { 30% { opacity: 1; transform: translateY(-3px); } }
.msg.typing-msg .bubble { padding: 12px 14px; }
.msg.hl .bubble { animation: hl 1.2s var(--ease); }
@keyframes hl { 30% { transform: scale(1.04); filter: brightness(1.25); } }
.msg.pending .meta svg { opacity: .5; }

.to-bottom { position: absolute; right: 12px; bottom: calc(var(--sab) + 72px); z-index: 4; width: 40px; height: 40px; border-radius: 50%; background: var(--glass); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); box-shadow: var(--shadow); color: var(--text2); display: grid; place-items: center; animation: pop .3s var(--spring); }
.to-bottom svg { width: 22px; height: 22px; }

.composer-wrap { position: relative; z-index: 3; border-top: .5px solid var(--sep); padding-bottom: var(--sab); }
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 7px 8px; }
.c-btn { width: 36px; height: 36px; flex: none; display: grid; place-items: center; color: var(--text2); border-radius: 50%; transition: transform .25s var(--spring), background .2s; }
.c-btn:active { transform: scale(.85); }
.c-btn svg { width: 26px; height: 26px; }
.c-btn.send { background: var(--accent); color: #fff; animation: pop .3s var(--spring); }
.c-btn.send svg { width: 20px; height: 20px; }
.c-btn.rec .i-cam { display: none; }
.c-btn.rec.cam .i-cam { display: block; }
.c-btn.rec.cam .i-mic { display: none; }
.c-btn.rec svg { animation: pop .3s var(--spring); }
.input-wrap { flex: 1; min-height: 36px; border-radius: 18px; border: .5px solid var(--sep); background: var(--bg); display: flex; align-items: center; padding: 0 12px; }
.input-wrap textarea { flex: 1; resize: none; border: 0; outline: none; background: none; font-size: 17px; line-height: 22px; padding: 7px 0; max-height: 140px; }
.reply-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px 0; animation: rise .3s var(--ease); }
.reply-bar i { width: 3px; align-self: stretch; background: var(--accent); border-radius: 2px; }
.reply-bar div { flex: 1; min-width: 0; font-size: 14px; }
.reply-bar b { color: var(--accent); display: block; }
.reply-bar span { color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.reply-bar button { color: var(--text2); padding: 6px; }
.voice-bar { display: flex; align-items: center; gap: 10px; padding: 7px 8px 7px 16px; height: 50px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
.voice-bar .wave { flex: 1; display: flex; gap: 2px; align-items: center; height: 26px; overflow: hidden; justify-content: flex-end; }
.voice-bar .wave i { width: 3px; flex: none; border-radius: 2px; background: var(--accent); }

/* ===== Листы ===== */
.sheet-back { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .4); animation: fade .3s; }
@keyframes fade { from { opacity: 0; } }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: calc(100% - var(--sat) - 12px); height: calc(100% - var(--sat) - 12px); background: var(--bg-grouped); border-radius: 14px 14px 0 0; transform: translateY(105%); transition: transform .5s var(--ease); overflow-y: auto; padding-bottom: var(--sab); box-shadow: 0 -10px 40px rgba(0, 0, 0, .25); }
#newChatSheet { background: var(--bg); }
.sheet.open { transform: none; }
.sheet.auto { height: auto; }
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--text3); margin: 6px auto 0; }
.sheet-head { display: grid; grid-template-columns: 90px 1fr 90px; align-items: center; height: 50px; padding: 0 6px; text-align: center; }
.sheet-head > :last-child { justify-self: end; }
.sheet-head > :first-child { justify-self: start; }
.p-actions { display: flex; gap: 8px; margin: 0 16px 18px; }
.p-actions button { flex: 1; background: var(--card); border-radius: 12px; padding: 10px 0 8px; color: var(--accent); font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.p-actions svg { width: 24px; height: 24px; }
.install { text-align: center; padding: 20px 24px 24px; }
.app-icon { width: 96px; height: 96px; margin: 10px auto 18px; border-radius: 22px; overflow: hidden; box-shadow: 0 12px 30px rgba(90, 80, 255, .35); animation: float 3s ease-in-out infinite; }
.app-icon img { width: 100%; height: 100%; }
.install h2 { margin: 0 0 6px; font-size: 26px; }
.install p { color: var(--text2); margin: 0 0 20px; }
.install ol { list-style: none; padding: 0; margin: 0 0 24px; text-align: left; background: var(--card); border-radius: 14px; }
.install li { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: .5px solid var(--sep); }
.install li:last-child { border: 0; }
.step-n { width: 28px; height: 28px; flex: none; border-radius: 50%; background: var(--fill); display: grid; place-items: center; font-weight: 600; font-size: 15px; }
.share-ico { width: 22px; height: 22px; color: var(--accent); display: inline-block; vertical-align: -5px; }
.plus-ico { display: inline-grid; place-items: center; width: 20px; height: 20px; border: 1.6px solid currentColor; border-radius: 5px; font-size: 15px; line-height: 1; }
.install .btn-primary { width: 100%; }
.install-arrow { position: fixed; left: 50%; bottom: calc(var(--sab) + 6px); transform: translateX(-50%); font-size: 30px; color: var(--accent); animation: bounce 1.2s infinite; display: none; }
.sheet.open.ios-safari .install-arrow { display: block; }
@keyframes bounce { 50% { transform: translate(-50%, 8px); } }

/* ===== Контекстное меню ===== */
.ctx { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .25); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); animation: fade .25s; }
.ctx.closing { animation: fade .2s reverse forwards; }
.ctx-clone { position: fixed; pointer-events: none; transition: transform .35s var(--spring); }
.ctx-clone .msg { max-width: none; animation: none; }
.ctx-reacts { position: fixed; display: flex; gap: 2px; padding: 6px 8px; background: var(--card); border-radius: 26px; box-shadow: var(--shadow); animation: ctxIn .4s var(--spring) both; }
.ctx-reacts button { font-size: 28px; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; transition: transform .2s var(--spring); animation: pop .4s var(--spring) both; }
.ctx-reacts button:active { transform: scale(1.4); }
.ctx-reacts button.on { background: var(--fill); }
.ctx-menu { position: fixed; min-width: 220px; background: var(--glass); -webkit-backdrop-filter: saturate(180%) blur(30px); backdrop-filter: saturate(180%) blur(30px); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); animation: ctxIn .4s var(--spring) .03s both; }
.ctx-menu button { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 12px 16px; font-size: 17px; border-bottom: .5px solid var(--sep); }
.ctx-menu button:last-child { border: 0; }
.ctx-menu button:active { background: var(--fill); }
.ctx-menu button.danger { color: var(--danger); }
@keyframes ctxIn { from { opacity: 0; transform: scale(.6); } }

.viewer { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .92); display: grid; place-items: center; animation: fade .25s; }
.viewer img { max-width: 100%; max-height: 100%; animation: zoomIn .4s var(--spring); }
@keyframes zoomIn { from { transform: scale(.7); opacity: 0; } }

/* ===== Запись кружка ===== */
.circle-rec { position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, .7); -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; animation: fade .3s; transition: background .4s; }
.cr-light { position: absolute; inset: 0; background: var(--rl); opacity: 0; transition: opacity .35s; pointer-events: none; }
.circle-rec.lit .cr-light { opacity: 1; }
.cr-ring { position: relative; width: min(78vw, 340px); height: min(78vw, 340px); animation: zoomIn .5s var(--spring); }
.cr-ring video { position: absolute; inset: 8px; width: calc(100% - 16px); height: calc(100% - 16px); border-radius: 50%; object-fit: cover; background: #111; }
.cr-ring video.mirror, video.mirror { transform: scaleX(-1); }
.cr-ring svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.cr-track { fill: none; stroke: rgba(255, 255, 255, .2); stroke-width: 2; }
.cr-prog { fill: none; stroke: #fff; stroke-width: 2.5; stroke-linecap: round; stroke-dasharray: 301.6; stroke-dashoffset: 301.6; transition: stroke-dashoffset .25s linear; }
.circle-rec.lit .cr-prog { stroke: var(--accent); }
.circle-rec.lit .cr-track { stroke: rgba(0, 0, 0, .1); }
.cr-time { position: relative; color: #fff; font-variant-numeric: tabular-nums; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.cr-time::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
.circle-rec.lit .cr-time { color: #222; }
.cr-controls { position: relative; display: flex; align-items: center; gap: 18px; }
.round-btn { width: 54px; height: 54px; border-radius: 50%; background: rgba(255, 255, 255, .18); color: #fff; display: grid; place-items: center; transition: transform .25s var(--spring), background .25s; }
.round-btn svg { width: 24px; height: 24px; }
.round-btn:active { transform: scale(.88); }
.round-btn.on { background: #fff; color: #f5a400; }
.round-btn.big { width: 72px; height: 72px; background: var(--accent); }
.circle-rec.lit .round-btn:not(.big):not(.on) { background: rgba(0, 0, 0, .12); color: #222; }
.round-spacer { display: none; }

/* ===== Звонок ===== */
.call { position: fixed; inset: 0; z-index: 70; background: #000; color: #fff; overflow: hidden; animation: callIn .55s var(--ease); transition: background .4s; }
@keyframes callIn { from { opacity: 0; transform: scale(1.06); } }
.call.closing { animation: callIn .4s var(--ease) reverse forwards; }
.call-bg { position: absolute; inset: -40px; background: var(--av, var(--grad)); filter: blur(60px) saturate(1.4) brightness(.7); transform: scale(1.2); transition: opacity .5s; }
.call.has-video .call-bg { opacity: 0; }
.v-main { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: transparent; opacity: 0; transition: opacity .5s, inset .5s var(--ease), border-radius .5s var(--ease); }
.call.has-video .v-main, #camTest .v-main { opacity: 1; }
.call-avatar { position: absolute; left: 50%; top: 32%; transform: translate(-50%, -50%); transition: opacity .4s, transform .5s var(--ease); }
.call.has-video .call-avatar { opacity: 0; transform: translate(-50%, -50%) scale(.8); pointer-events: none; }
.call-avatar .avatar { position: relative; z-index: 1; box-shadow: 0 20px 60px rgba(0, 0, 0, .4); }
.pulse { position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .45); animation: pulse 2.4s var(--ease) infinite; }
.pulse.d2 { animation-delay: 1.2s; }
.call.connected .pulse { animation: none; opacity: 0; }
@keyframes pulse { from { transform: scale(1); opacity: .9; } to { transform: scale(2); opacity: 0; } }
.call-top { position: absolute; top: calc(var(--sat) + 18px); left: 0; right: 0; text-align: center; display: flex; flex-direction: column; gap: 4px; text-shadow: 0 1px 8px rgba(0, 0, 0, .45); z-index: 3; transition: opacity .3s, transform .4s var(--ease); }
.call:not(.has-video) .call-top { top: calc(32% + 92px); }
.call-top b { font-size: 28px; font-weight: 600; letter-spacing: -.02em; }
.call-top span { font-size: 16px; opacity: .85; font-variant-numeric: tabular-nums; }
.call.has-video .call-top b { font-size: 19px; }
.call.lit .call-top { color: #222; text-shadow: none; }

.local-stack { position: absolute; right: 14px; top: calc(var(--sat) + 90px); display: flex; flex-direction: column; gap: 10px; z-index: 4; touch-action: none; transition: transform .45s var(--spring); }
.local-stack.dragging { transition: none; }
.v-pip { position: relative; width: 108px; height: 152px; border-radius: 18px; object-fit: cover; background: #222; box-shadow: 0 10px 30px rgba(0, 0, 0, .45); animation: zoomIn .45s var(--spring); }
.v-pip.mirror { transform: scaleX(-1); }
.v-pip.remote2, .v-pip.test2 { position: absolute; left: 14px; top: calc(var(--sat) + 90px); z-index: 4; width: 132px; height: 186px; border: 2px solid rgba(255, 255, 255, .7); cursor: pointer; }
.v-pip.remote2.swap, .v-pip.test2.swap { width: 132px; }
.call:not(.has-local) .local-stack { display: none; }

/* Кольцевая подсветка экраном */
.call.lit { background: var(--rl); }
.call.lit .v-main { inset: calc(var(--sat) + 76px) 16% calc(var(--sab) + 170px); width: auto; height: auto; border-radius: 28px; width: calc(100% - 32%); height: calc(100% - var(--sat) - var(--sab) - 246px); box-shadow: 0 0 0 3px rgba(0,0,0,.05); }
.call.lit .call-bg { opacity: 0; }
.ring-light { position: absolute; inset: 0; pointer-events: none; z-index: 2; box-shadow: inset 0 0 0 18px var(--rl), inset 0 0 120px 60px var(--rl); animation: fade .35s; }
.call.lit .v-pip { box-shadow: 0 0 0 2px var(--rl), 0 10px 30px rgba(0,0,0,.2); }

.light-pop { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--sab) + 130px); z-index: 6; display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: 30px; background: rgba(30, 30, 32, .7); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); animation: ctxIn .35s var(--spring); }
.light-pop input { width: 180px; accent-color: #ffb340; }

.call-controls { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--sab) + 22px); z-index: 5; display: flex; gap: 10px; padding: 12px 14px 10px; border-radius: 34px; transition: transform .5s var(--ease), opacity .3s; max-width: calc(100% - 20px); --cc-bg: #3a3a3c; }
.call.hide-ui .call-controls { transform: translate(-50%, 160%); }
.call.hide-ui .call-top { opacity: 0; transform: translateY(-20px); }
.cc { display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 11px; font-weight: 500; width: 56px; color: #fff; }
.cc i { width: 52px; height: 52px; border-radius: 50%; background: rgba(255, 255, 255, .2); display: grid; place-items: center; transition: background .25s, color .25s, transform .3s var(--spring); }
.cc:active i { transform: scale(.88); }
.cc svg { width: 25px; height: 25px; }
.cc.on i { background: #fff; color: #000; --cc-bg: #fff; }
.cc.off i { background: rgba(255, 255, 255, .9); color: #000; }
.cc.off i svg { opacity: .9; }
.cc.off i { position: relative; }
.cc.off i::after { content: ""; position: absolute; width: 30px; height: 2.5px; background: #000; transform: rotate(45deg); border-radius: 2px; box-shadow: 0 0 0 1.5px #fff; }
#ccFlash.on i { background: #ffd60a; color: #000; }
.cc.end i { background: var(--danger); }
.cc.end svg { width: 28px; }
.cc.accept i { background: var(--green); animation: ringAcc 1.4s infinite; }
@keyframes ringAcc { 10%, 30% { transform: rotate(-14deg); } 20%, 40% { transform: rotate(14deg); } 50% { transform: none; } }
.cc.disabled { opacity: .35; pointer-events: none; }
.incoming { position: absolute; left: 0; right: 0; bottom: calc(var(--sab) + 60px); display: flex; justify-content: space-around; z-index: 7; padding: 0 40px; }
.incoming .cc { width: 80px; font-size: 14px; }
.incoming .cc i { width: 74px; height: 74px; }
.incoming .cc svg { width: 34px; height: 34px; }
.call.ringing .call-controls { display: none; }

.toast { position: fixed; left: 50%; top: calc(var(--sat) + 10px); transform: translate(-50%, -150%); z-index: 100; max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 18px; background: rgba(40, 40, 42, .9); color: #fff; font-size: 15px; -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); transition: transform .5s var(--spring); text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.toast.show { transform: translate(-50%, 0); }
.banner { position: fixed; left: 8px; right: 8px; top: calc(var(--sat) + 8px); z-index: 90; padding: 12px 14px; border-radius: 18px; display: flex; gap: 10px; align-items: center; background: var(--glass); -webkit-backdrop-filter: saturate(180%) blur(30px); backdrop-filter: saturate(180%) blur(30px); box-shadow: var(--shadow); transform: translateY(-160%); transition: transform .55s var(--spring); cursor: pointer; max-width: 460px; margin: 0 auto; }
.banner.show { transform: none; }
.banner .b-text { min-width: 0; flex: 1; }
.banner b { display: block; font-size: 15px; }
.banner span { display: block; font-size: 14px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== Десктоп / iPad ===== */
@media (min-width: 820px) {
  .sidebar { width: 380px; border-right: .5px solid var(--sep); }
  .chat-pane { position: relative; flex: 1; transform: none !important; box-shadow: none; }
  #main.chat-open .sidebar { transform: none; filter: none; }
  .chat-placeholder { display: grid; place-items: center; align-content: center; gap: 14px; position: absolute; inset: 0; background: var(--bg-grouped); color: var(--text2); }
  .back { display: none; }
  .chat-head { padding-left: 16px; }
  .sheet { left: 50%; right: auto; width: 420px; margin-left: -210px; top: 8vh; bottom: auto; height: 80vh; border-radius: 16px; transform: translateY(120vh); }
  .sheet.open { transform: none; }
  .v-pip { width: 160px; height: 120px; }
  .msg { max-width: 64%; }
}
