:root {
  --accent: #3390ec;
  --accent-hover: #2a7fd6;
  --bg: #ffffff;
  --bg-2: #f4f4f5;
  --text: #000000;
  --muted: #707579;
  --border: #dfe1e5;
  --hover: #f4f4f5;
  --active: #3390ec;
  --chat-bg: linear-gradient(160deg, #c9dfb2 0%, #a8cfa4 35%, #8fbfa9 70%, #b4cf9b 100%);
  --in-bubble: #ffffff;
  --out-bubble: #e3fee0;
  --out-meta: #4fae4e;
  --in-meta: #a0acb6;
  --danger: #e53935;
  --green: #4fae4e;
  --shadow: 0 1px 2px rgba(16, 35, 47, .15);
  --radius: 15px;
  --theme-color: #3390ec;
  --on-accent: #fff;
  color-scheme: light;
  /* Монохром: мелкая сетка точек и мягкие светлые пятна на чёрном */
  --mono-sky:
    radial-gradient(circle at 1px 1px, rgba(255,255,255,.07) 1px, transparent 1.6px) 0 0 / 22px 22px,
    radial-gradient(ellipse 70% 50% at 18% 12%, rgba(255,255,255,.08), transparent 70%) no-repeat,
    radial-gradient(ellipse 60% 45% at 85% 88%, rgba(255,255,255,.06), transparent 70%) no-repeat,
    #050505;
  /* Ночное небо: звёзды разной яркости (плитки взаимно простых размеров, чтобы не было видно повтора),
     туманность, Млечный Путь и луна поверх градиента от тёмно-синего к фиолетовому */
  --stars:
    radial-gradient(circle at 17px 211px, rgba(255,255,255,.7) 0 .7px, transparent 1.3px) 0 0 / 251px 263px,
    radial-gradient(circle at 199px 43px, rgba(255,255,255,.55) 0 .6px, transparent 1.2px) 0 0 / 269px 241px,
    radial-gradient(circle at 89px 131px, rgba(255,255,255,.85) 0 1px, transparent 1.6px) 0 0 / 283px 307px,
    radial-gradient(circle at 241px 277px, rgba(220,228,255,.6) 0 .7px, transparent 1.3px) 0 0 / 293px 311px,
    radial-gradient(circle at 151px 19px, rgba(255,255,255,.75) 0 .8px, transparent 1.4px) 0 0 / 317px 281px,
    radial-gradient(circle at 37px 61px, rgba(255,245,230,.65) 0 .7px, transparent 1.3px) 0 0 / 331px 347px,
    radial-gradient(circle at 293px 173px, rgba(255,255,255,.9) 0 1.1px, transparent 1.7px) 0 0 / 353px 337px,
    radial-gradient(circle at 113px 331px, rgba(210,220,255,.7) 0 .9px, transparent 1.5px) 0 0 / 367px 383px,
    radial-gradient(circle at 257px 97px, rgba(255,255,255,.5) 0 .6px, transparent 1.2px) 0 0 / 389px 359px,
    radial-gradient(circle at 61px 287px, rgba(255,255,255,.8) 0 1px, transparent 1.6px) 0 0 / 409px 421px,
    radial-gradient(circle at 337px 389px, rgba(255,240,220,.85) 0 1.2px, transparent 1.9px) 0 0 / 433px 443px,
    radial-gradient(circle at 181px 239px, rgba(220,228,255,.6) 0 .7px, transparent 1.3px) 0 0 / 449px 419px,
    radial-gradient(circle at 401px 59px, rgba(255,255,255,.7) 0 .9px, transparent 1.5px) 0 0 / 479px 467px,
    radial-gradient(circle at 127px 431px, rgba(255,255,255,.95) 0 1.3px, transparent 2px) 0 0 / 523px 509px,
    radial-gradient(circle at 467px 311px, rgba(210,220,255,.75) 0 1px, transparent 1.6px) 0 0 / 571px 557px,
    radial-gradient(circle at 229px 523px, rgba(255,255,255,.6) 0 .8px, transparent 1.4px) 0 0 / 619px 601px;
  --night-sky:
    var(--stars),
    radial-gradient(circle at calc(100% - 64px) 120px, #fffbea 0 13px, rgba(255,246,214,.28) 14px, rgba(255,246,214,.07) 34px, transparent 64px) no-repeat,
    radial-gradient(ellipse 60% 45% at 15% 12%, rgba(124,92,255,.24), transparent 70%) no-repeat,
    radial-gradient(ellipse 55% 40% at 88% 88%, rgba(56,128,255,.18), transparent 70%) no-repeat,
    linear-gradient(115deg, transparent 32%, rgba(160,170,255,.05) 44%, rgba(205,195,255,.09) 50%, rgba(160,170,255,.05) 56%, transparent 68%) no-repeat,
    linear-gradient(180deg, #050817 0%, #0a1030 40%, #141a46 75%, #22184a 100%);
  --twinkle-stars:
    radial-gradient(circle at 211px 19px, #fff 0 1.4px, rgba(180,200,255,.35) 2.2px, transparent 4.5px) 0 0 / 397px 431px,
    radial-gradient(circle at 301px 341px, #fff 0 1.6px, rgba(180,200,255,.3) 2.6px, transparent 5.5px) 0 0 / 541px 499px,
    radial-gradient(circle at 73px 187px, #fff 0 1.2px, rgba(200,210,255,.3) 2px, transparent 4px) 0 0 / 463px 487px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #212121; --bg-2: #2c2c2c; --text: #ffffff; --muted: #aaaaaa;
    --border: #303030; --hover: #2c2c2c; --active: #8774e1; --accent: #8774e1; --accent-hover: #7563d0;
    --chat-bg: linear-gradient(160deg, #1e2a24 0%, #161d26 50%, #22202e 100%);
    --in-bubble: #212121; --out-bubble: #8774e1; --out-meta: #e8e4ff; --in-meta: #8a8a8a;
    --theme-color: #212121;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #212121; --bg-2: #2c2c2c; --text: #ffffff; --muted: #aaaaaa;
  --border: #303030; --hover: #2c2c2c; --active: #8774e1; --accent: #8774e1; --accent-hover: #7563d0;
  --chat-bg: linear-gradient(160deg, #1e2a24 0%, #161d26 50%, #22202e 100%);
  --in-bubble: #212121; --out-bubble: #8774e1; --out-meta: #e8e4ff; --in-meta: #8a8a8a;
  --theme-color: #212121;
  color-scheme: dark;
}
:root[data-theme="night"] {
  --bg: #0c1129; --bg-2: #151c3d; --text: #e9ecff; --muted: #8e98c4;
  --border: #1e2750; --hover: #161e44; --active: #4c5bd4; --accent: #8ea2ff; --accent-hover: #7b90f5;
  --chat-bg: var(--night-sky);
  --in-bubble: #172046; --out-bubble: linear-gradient(135deg, #5a4fcf 0%, #3d63dd 100%);
  --out-meta: #d5dcff; --in-meta: #7d88b8;
  --danger: #ff6b86; --green: #4fd1a5;
  --shadow: 0 1px 3px rgba(0, 0, 0, .45);
  --theme-color: #070b1f;
  color-scheme: dark;
}
:root[data-theme="night"] .sidebar { background: linear-gradient(180deg, #0c1129 0%, #0e1435 100%); }
:root[data-theme="night"] #auth { background: var(--night-sky); }
:root[data-theme="night"] .chat { isolation: isolate; }
/* Самые яркие звёзды медленно мерцают отдельным слоем */
:root[data-theme="night"] .chat::before, :root[data-theme="night"] #auth::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: var(--twinkle-stars); animation: twinkle 4.5s ease-in-out infinite alternate;
}
:root[data-theme="night"] #auth { position: relative; isolation: isolate; }
@keyframes twinkle { from { opacity: .2; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  :root[data-theme="night"] .chat::before, :root[data-theme="night"] #auth::before { animation: none; opacity: .7; }
}
:root[data-theme="night"] .msg.out .bubble { color: #fff; }
:root[data-theme="night"] .msg.out .file-ic { background: rgba(255, 255, 255, .22); }
:root[data-theme="night"] .call { background: radial-gradient(circle at 50% 30%, rgba(90, 79, 207, .35), transparent 60%), var(--night-sky); }
:root[data-theme="night"] .pill, :root[data-theme="night"] .e2e-note { background: rgba(12, 17, 41, .6); backdrop-filter: blur(6px); }
:root[data-theme="night"] .drawer-head { background: var(--night-sky); color: #fff; }

/* ---------- Монохром ---------- */
:root[data-theme="mono"] {
  --bg: #0a0a0a; --bg-2: #161616; --text: #f2f2f2; --muted: #8c8c8c;
  --border: #232323; --hover: #161616; --active: #f2f2f2; --accent: #f2f2f2; --accent-hover: #ffffff; --on-accent: #000;
  --chat-bg: var(--mono-sky);
  --in-bubble: #1a1a1a; --out-bubble: #f2f2f2; --out-meta: #6b6b6b; --in-meta: #7a7a7a;
  --danger: #ff5c5c; --green: #f2f2f2;
  --shadow: 0 1px 2px rgba(0, 0, 0, .6);
  --theme-color: #000000;
  color-scheme: dark;
}
:root[data-theme="mono"] .msg.out .bubble, :root[data-theme="mono"] .msg.out .text a { color: #000; }
:root[data-theme="mono"] .item.active { color: #000; }
:root[data-theme="mono"] .item.active .muted, :root[data-theme="mono"] .item.active .item-time,
:root[data-theme="mono"] .item.active .item-text, :root[data-theme="mono"] .item.active .handle { color: rgba(0, 0, 0, .65); }
:root[data-theme="mono"] .item.active .badge { background: #000; color: #fff; }
:root[data-theme="mono"] .badge.hot { background: #f2f2f2; color: #000; }
:root[data-theme="mono"] .avatar.online::after { background: #fff; }
:root[data-theme="mono"] .set-ic { background: #222 !important; }
:root[data-theme="mono"] input:checked + .switch::after { background: #000; }
:root[data-theme="mono"] .drawer-head { background: var(--mono-sky); color: #fff; }
:root[data-theme="mono"] .call { background: radial-gradient(circle at 50% 30%, #2a2a2a 0%, #000 70%); }
:root[data-theme="mono"] .pill, :root[data-theme="mono"] .e2e-note { background: rgba(255, 255, 255, .08); backdrop-filter: blur(6px); }
:root[data-theme="mono"] #auth { background: var(--mono-sky); position: relative; isolation: isolate; }
:root[data-theme="mono"] .chat { isolation: isolate; }
/* Медленно плывущие светлые пятна */
:root[data-theme="mono"] .chat::before, :root[data-theme="mono"] #auth::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(circle at 30% 30%, rgba(255,255,255,.11), transparent 32%),
    radial-gradient(circle at 70% 60%, rgba(255,255,255,.08), transparent 36%),
    radial-gradient(circle at 50% 85%, rgba(255,255,255,.06), transparent 30%);
  background-size: 170% 170%;
  animation: mono-drift 22s ease-in-out infinite alternate;
}
@keyframes mono-drift {
  from { background-position: 0% 0%, 100% 100%, 50% 0%; }
  to { background-position: 100% 70%, 0% 20%, 30% 100%; }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0; font-size: 14px; }

/* ---------- auth ---------- */
.screen { height: 100%; }
#auth { display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
.auth-card { width: 100%; max-width: 360px; text-align: center; }
.auth-logo { width: 120px; height: 120px; margin-bottom: 16px; }
.auth-card h1 { margin: 0 0 6px; font-size: 28px; }
.tabs { display: flex; gap: 4px; margin: 24px 0 16px; background: var(--bg-2); border-radius: 12px; padding: 4px; }
.tab { flex: 1; border: 0; background: none; padding: 9px; border-radius: 9px; color: var(--muted); font-weight: 500; }
.tab.active { background: var(--bg); color: var(--text); box-shadow: var(--shadow); }
#authForm input {
  width: 100%; padding: 15px 16px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg); margin-bottom: 12px; outline: none; transition: border-color .15s;
}
#authForm input:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.btn-primary {
  width: 100%; padding: 14px; border: 0; border-radius: 12px; background: var(--accent);
  color: var(--on-accent); font-weight: 600; text-transform: uppercase; letter-spacing: .3px;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.hint { color: var(--muted); font-size: 13px; }
#authForm textarea, .modal-card input:not([type=checkbox]), .modal-card select, .modal-card textarea,
.page-body input:not([type=checkbox]), .page-body select, .page-body textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); outline: none; color: var(--text);
}
#authForm textarea { padding: 13px 14px; border-radius: 12px; resize: none; }
#authForm textarea:focus, .modal-card input:focus, .modal-card select:focus, .modal-card textarea:focus,
.page-body input:focus, .page-body select:focus, .page-body textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.modal-card select:disabled, .page-body select:disabled { opacity: .6; }
.page-body textarea { resize: vertical; }
.key-text { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; resize: none; }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 500; padding: 8px; }
.btn-secondary { flex: 1; padding: 11px; border: 1px solid var(--accent); border-radius: 12px; background: none; color: var(--accent); font-weight: 600; }
.btn-secondary:hover { background: var(--hover); }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.field { display: block; margin: 16px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.perm { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--bg-2); border-radius: 10px; padding: 8px 8px 8px 12px; font-size: 14px; min-height: 44px; }
.level { height: 6px; background: var(--bg-2); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.level b { display: block; height: 100%; width: 0; background: var(--green); transition: width .08s; }
.warn { color: var(--danger) !important; }
.peer-info, .chat-head .avatar { cursor: pointer; }
.handle { color: var(--accent); }
.item.active .handle { color: #fff; }
.handle-field { display: block; width: 100%; text-align: left; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-2); color: var(--text); }
.handle-btn { border: 0; background: none; color: var(--accent); font-weight: 500; padding: 3px 8px; border-radius: 8px; }
.handle-btn:hover, .handle-field:hover { background: var(--hover); }
.counter { text-align: right; font-size: 12px; color: var(--muted); margin-top: 4px; }
.profile { text-align: center; }
.profile .avatar.big { margin: 4px auto 14px; }
.profile-name { font-size: 22px; font-weight: 700; overflow-wrap: anywhere; }
.profile-status { color: var(--muted); font-size: 14px; margin-top: 2px; }
.profile-status.on { color: var(--accent); }
.profile-bio { margin: 14px 0 0; padding: 12px 14px; background: var(--bg-2); border-radius: 12px; text-align: left; white-space: pre-wrap; overflow-wrap: anywhere; }
.profile-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 8px; margin-top: 16px; }
.profile-act { border: 0; background: var(--bg-2); border-radius: 12px; padding: 10px 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 13px; font-weight: 500; color: var(--accent); }
.profile-act:hover { background: var(--hover); }
.profile-act b { font-size: 20px; line-height: 1.2; }
.profile-since { color: var(--muted); font-size: 12.5px; margin-top: 14px; }
.themes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.theme-card { border: 2px solid var(--border); border-radius: 14px; padding: 5px 5px 8px; background: none; font-size: 14px; font-weight: 500; display: flex; flex-direction: column; gap: 7px; }
.theme-card.active { border-color: var(--accent); }
.theme-prev { height: 88px; border-radius: 10px; padding: 10px 9px; display: flex; flex-direction: column; justify-content: flex-end; gap: 6px; overflow: hidden; }
.theme-prev i { display: block; height: 13px; width: 62%; border-radius: 7px 7px 7px 3px; }
.theme-prev i + i { align-self: flex-end; width: 48%; border-radius: 7px 7px 3px 7px; }
.get-app { display: block; margin-top: 18px; font-size: 14px; color: var(--muted); text-decoration: none; transition: color .2s; }
.get-app:hover { color: var(--text); text-decoration: underline; }
.ios-hint { margin-top: 18px; background: var(--bg-2); border-radius: 12px; padding: 12px 14px 4px; text-align: left; font-size: 14px; }
.ios-hint p { margin: 6px 0 0; color: var(--muted); }
.ios-hint .link-btn { padding: 8px 0; }

/* ---------- layout ---------- */
#app { display: flex; }
.sidebar { width: 380px; min-width: 300px; border-right: 1px solid var(--border); display: flex; flex-direction: column; background: var(--bg); position: relative; }
.chat { flex: 1; display: flex; flex-direction: column; background: var(--chat-bg); min-width: 0; position: relative; }

.icon-btn { border: 0; background: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--hover); }

.side-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; position: relative; }
.search { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--bg-2); border-radius: 22px; padding: 0 14px; height: 42px; border: 2px solid transparent; }
.search:focus-within { border-color: var(--accent); background: var(--bg); }
.search svg { width: 20px; height: 20px; color: var(--muted); }
.search input { flex: 1; border: 0; background: none; outline: none; min-width: 0; }


.conn-bar { background: var(--bg-2); color: var(--muted); text-align: center; padding: 6px; font-size: 13px; }

.list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.list-title { color: var(--muted); font-size: 14px; font-weight: 500; padding: 10px 10px 6px; }
.item { display: flex; gap: 12px; padding: 9px 10px; border-radius: 12px; cursor: pointer; align-items: center; }
.item:hover { background: var(--hover); }
.item.active { background: var(--active); color: #fff; }
.item.active .muted, .item.active .item-time, .item.active .item-text { color: rgba(255,255,255,.85); }
.item-body { flex: 1; min-width: 0; }
.item-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.item-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-time { font-size: 12px; color: var(--muted); flex: none; }
.item-text { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.item-text.typing { color: var(--accent); }
.item.active .item-text.typing { color: #fff; }
.badge { background: #c4c9cc; color: #fff; font-size: 12px; font-weight: 600; border-radius: 12px; min-width: 22px; height: 22px; padding: 0 7px; display: grid; place-items: center; flex: none; }
.badge.hot { background: var(--green); }
.item.active .badge { background: #fff; color: var(--active); }

.avatar {
  width: 54px; height: 54px; border-radius: 50%; flex: none; display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 20px; position: relative; text-transform: uppercase;
}
.avatar.online::after { content: ""; position: absolute; right: 1px; bottom: 1px; width: 12px; height: 12px; border-radius: 50%; background: #0ac630; border: 2px solid var(--bg); }
.item.active .avatar.online::after { border-color: var(--active); }

/* ---------- chat ---------- */
.empty { flex: 1; display: grid; place-items: center; }
.pill { background: rgba(0,0,0,.25); color: #fff; padding: 6px 14px; border-radius: 16px; font-size: 14px; font-weight: 500; text-align: center; max-width: 90%; }
.chat-inner { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 6px 12px; background: var(--bg); border-bottom: 1px solid var(--border); min-height: 56px; }
.chat-head .avatar { width: 42px; height: 42px; font-size: 16px; }
.chat-head .avatar.online::after { width: 10px; height: 10px; }
.peer-info { flex: 1; min-width: 0; }
.peer-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-status { color: var(--muted); font-size: 14px; }
.peer-status.on { color: var(--accent); }
.back { display: none; }

.key-warn { background: #fff4d6; color: #6b4e00; padding: 8px 14px; font-size: 14px; display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.key-warn button { border: 0; background: #6b4e00; color: #fff; border-radius: 8px; padding: 4px 10px; }

.messages { flex: 1; overflow-y: auto; padding: 12px max(16px, calc((100% - 760px) / 2)); display: flex; flex-direction: column; gap: 2px; }
.day { align-self: center; margin: 10px 0; }
.e2e-note { align-self: center; background: rgba(0,0,0,.25); color: #fff; padding: 10px 16px; border-radius: 14px; font-size: 13.5px; max-width: 340px; text-align: center; margin: 16px 0; line-height: 1.45; }
.msg { display: flex; }
.msg.out { justify-content: flex-end; }
.msg.grp-end { margin-bottom: 6px; }
.bubble {
  max-width: min(480px, 80%); background: var(--in-bubble); padding: 6px 10px 6px 10px;
  border-radius: var(--radius); box-shadow: var(--shadow); position: relative; word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.out .bubble { background: var(--out-bubble); }
.msg.in.grp-end .bubble { border-bottom-left-radius: 4px; }
.msg.out.grp-end .bubble { border-bottom-right-radius: 4px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]):not([data-theme="mono"]) .msg.out .bubble { color: #fff; } }
:root[data-theme="dark"] .msg.out .bubble { color: #fff; }
.text { white-space: pre-wrap; }
.text a { color: var(--accent); }
.msg.out .text a { color: inherit; text-decoration: underline; }
.meta { float: right; margin: 6px -2px -4px 10px; font-size: 12px; color: var(--in-meta); display: inline-flex; align-items: center; gap: 3px; user-select: none; position: relative; top: 3px; }
.msg.out .meta { color: var(--out-meta); }
.ticks { font-size: 13px; letter-spacing: -4px; padding-right: 4px; }
.meta .clock { width: 12px; height: 12px; stroke-width: 2.4; }
.bubble.media { padding: 4px; }
.bubble.media img { display: block; max-width: 100%; max-height: 360px; border-radius: 11px; cursor: zoom-in; }
.bubble.media .meta { position: absolute; right: 10px; bottom: 10px; margin: 0; background: rgba(0,0,0,.45); color: #fff; padding: 1px 6px; border-radius: 10px; top: auto; float: none; }
.file { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; padding: 2px 0; }
.file-ic { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; color: var(--on-accent); flex: none; }
.msg.out .file-ic { background: var(--out-meta); }
.file-name { font-weight: 500; word-break: break-all; }
.voice { display: flex; align-items: center; gap: 8px; }
.voice audio { height: 36px; max-width: 260px; }
.bubble.sys { background: var(--bg-2); font-size: 14px; }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px max(16px, calc((100% - 760px) / 2)) 14px; }
.composer > textarea, .rec {
  flex: 1; border: 0; outline: none; resize: none; background: var(--bg); border-radius: 22px;
  padding: 12px 16px; max-height: 180px; min-height: 48px; box-shadow: var(--shadow); line-height: 1.4;
}
.composer .icon-btn { background: var(--bg); width: 48px; height: 48px; box-shadow: var(--shadow); }
.composer .send { background: var(--accent); color: var(--on-accent); position: relative; }
.composer .send:hover { background: var(--accent-hover); }
.composer .send .i-send { display: none; }
.composer.has-text .send .i-send { display: block; }
.composer.has-text .send .i-mic { display: none; }
.composer.recording .send .i-mic { display: none; }
.composer.recording .send .i-send { display: block; }
.rec { display: flex; align-items: center; gap: 10px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
.rec .link { margin-left: auto; border: 0; background: none; color: var(--accent); font-weight: 500; }
@keyframes blink { 50% { opacity: .25; } }

/* ---------- call ---------- */
.call { position: fixed; inset: 0; z-index: 50; background: radial-gradient(circle at 50% 30%, #3a4d6b 0%, #18202d 70%); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 48px 16px 40px; }
#remoteVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; display: none; }
.call.has-video #remoteVideo { display: block; }
#localVideo { position: absolute; right: 16px; top: 16px; width: 180px; max-width: 32vw; aspect-ratio: 3/4; object-fit: cover; border-radius: 14px; background: #000; display: none; z-index: 2; transform: scaleX(-1); box-shadow: 0 4px 20px rgba(0,0,0,.4); }
.call.has-local #localVideo { display: block; }
.call-center { text-align: center; position: relative; z-index: 1; margin-top: 6vh; }
.call.has-video .call-center { margin-top: 0; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.call.has-video .call-center .avatar { display: none; }
.avatar.big { width: 140px; height: 140px; font-size: 52px; margin: 0 auto 20px; }
.call.ringing .avatar.big { animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,255,255,.35); } 70% { box-shadow: 0 0 0 28px rgba(255,255,255,0); } 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); } }
.call-name { font-size: 26px; font-weight: 600; }
.call-status { opacity: .8; margin-top: 6px; font-variant-numeric: tabular-nums; }
.call-e2e { font-size: 13px; opacity: .6; margin-top: 10px; }
.call-controls { display: flex; gap: 22px; position: relative; z-index: 1; flex-wrap: wrap; justify-content: center; }
.round { border: 0; background: rgba(255,255,255,.18); color: #fff; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; position: relative; backdrop-filter: blur(8px); }
.round:hover { background: rgba(255,255,255,.28); }
.round span { color: #fff; position: absolute; top: 72px; font-size: 12.5px; white-space: nowrap; opacity: .85; }
.round.on { background: #fff; color: #18202d; }
.round.off { background: rgba(255,255,255,.18); }
.round.off::after { content: ""; position: absolute; width: 34px; height: 2.5px; background: currentColor; transform: rotate(-45deg); border-radius: 2px; }
.round.red { background: #f02c2c; }
.round.green { background: #2ecb59; }
.call-controls { margin-bottom: 22px; }
.meter { position: absolute; bottom: 9px; left: 20px; right: 20px; height: 3px; background: rgba(0,0,0,.15); border-radius: 2px; overflow: hidden; }
.meter b { display: block; height: 100%; width: 0; background: var(--green); transition: width .08s; }
.round:disabled { opacity: .35; cursor: default; }

/* ---------- misc ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal-card { background: var(--bg); border-radius: 16px; padding: 22px; width: 100%; max-width: 420px; box-shadow: 0 10px 40px rgba(0,0,0,.3); max-height: calc(100vh - 32px); overflow: auto; }
.modal-card h3 { margin: 0 0 12px; }
.code { font: 600 19px/1.7 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 1px; text-align: center; background: var(--bg-2); border-radius: 12px; padding: 12px; margin: 12px 0; word-spacing: 6px; }
.modal-card p { color: var(--muted); font-size: 14px; }
.modal-card .btn-primary { margin-top: 10px; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.88); z-index: 70; display: grid; place-items: center; cursor: zoom-out; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: rgba(0,0,0,.8); color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 80; font-size: 14px; max-width: calc(100% - 32px); text-align: center; }
.drop { outline: 3px dashed var(--accent); outline-offset: -12px; }

/* ---------- боковое меню ---------- */
.drawer-wrap { position: fixed; inset: 0; z-index: 40; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.42); animation: fade-in .22s ease both; }
.drawer { position: absolute; top: 0; bottom: 0; left: 0; width: min(300px, 86vw); background: var(--bg); box-shadow: 4px 0 28px rgba(0,0,0,.28); display: flex; flex-direction: column; animation: drawer-in .28s cubic-bezier(.2,.8,.2,1) both; padding-bottom: env(safe-area-inset-bottom); }
.drawer-wrap.closing .drawer { animation: drawer-out .22s ease both; }
.drawer-wrap.closing .drawer-backdrop { animation: fade-out .22s ease both; }
.drawer-head { padding: 18px 16px 14px 18px; background: linear-gradient(135deg, var(--accent), var(--accent-hover)); color: var(--on-accent); cursor: pointer; margin-bottom: 6px; }
.drawer-top { display: flex; justify-content: space-between; align-items: flex-start; }
.drawer-head .avatar { width: 64px; height: 64px; font-size: 24px; box-shadow: 0 2px 10px rgba(0,0,0,.25); }
.drawer-head .icon-btn { color: inherit; }
.drawer-head .icon-btn:hover { background: rgba(255,255,255,.15); }
#nightToggle svg { transition: transform .4s cubic-bezier(.3,1.5,.5,1); }
#nightToggle .i-sun, #nightToggle.is-dark .i-moon { display: none; }
#nightToggle.is-dark .i-sun { display: block; animation: spin-in .5s ease; }
#nightToggle:not(.is-dark) .i-moon { animation: spin-in .5s ease; }
.drawer-me { margin-top: 12px; display: flex; flex-direction: column; gap: 1px; }
.drawer-me b { font-size: 16px; }
.drawer-me span { opacity: .8; font-size: 14px; }
.drawer-item { display: flex; align-items: center; gap: 22px; padding: 13px 22px; border: 0; background: none; text-align: left; font-size: 15px; font-weight: 500; color: var(--text); animation: slide-in-left .3s backwards; }
.drawer-item:nth-of-type(2) { animation-delay: .04s; } .drawer-item:nth-of-type(3) { animation-delay: .08s; } .drawer-item:nth-of-type(4) { animation-delay: .12s; }
.drawer-item svg { color: var(--muted); }
.drawer-item:hover { background: var(--hover); }
.drawer-foot { margin-top: auto; padding: 16px 22px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.drawer-foot span { opacity: .7; }

/* ---------- страницы настроек ---------- */
.pages { position: absolute; inset: 0; pointer-events: none; z-index: 15; }
.page { position: absolute; inset: 0; background: var(--bg); display: flex; flex-direction: column; pointer-events: auto; animation: page-in .3s cubic-bezier(.2,.8,.2,1) both; }
.page.leaving { animation: page-out .22s ease both; }
.page-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; min-height: 56px; border-bottom: 1px solid var(--border); }
.page-head h2 { font-size: 18px; margin: 0; }
.page-body { flex: 1; overflow-y: auto; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
.page-body .avatar.big { margin: 4px auto 16px; }
.set-group { margin: 14px -8px 0; display: flex; flex-direction: column; }
.set-row { position: relative; display: flex; align-items: center; gap: 14px; width: 100%; padding: 11px 10px; border: 0; background: none; border-radius: 12px; text-align: left; cursor: pointer; color: var(--text); }
.set-row:hover { background: var(--hover); }
.set-row > svg { color: var(--muted); width: 20px; height: 20px; flex: none; }
.set-row.danger { color: var(--danger); }
.set-ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: #fff; flex: none; }
.set-ic svg { width: 20px; height: 20px; }
.ic-user { background: #e17076; } .ic-shield { background: #4fae4e; } .ic-palette { background: #a695e7; }
.ic-mic { background: #faa774; } .ic-bell { background: #65aadd; } .ic-logout { background: #e53935; }
.set-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.set-text small { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-row.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 40px; height: 24px; border-radius: 12px; background: var(--border); position: relative; transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .25s cubic-bezier(.3,1.4,.5,1); box-shadow: 0 1px 3px rgba(0,0,0,.3); }
input:checked + .switch { background: var(--accent); }
input:checked + .switch::after { transform: translateX(16px); }
.me-card { display: flex; align-items: center; gap: 14px; width: 100%; padding: 12px; border: 0; background: var(--bg-2); border-radius: 16px; text-align: left; cursor: pointer; color: var(--text); }
.me-card .avatar { width: 64px; height: 64px; font-size: 24px; }
.me-card-text { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.me-card-text b { font-size: 17px; }
.me-card-text small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; color: var(--accent); margin: 20px 0 8px; }
.card-title:first-child { margin-top: 4px; }
.card-title svg { width: 18px; height: 18px; }
.card { background: var(--bg-2); border-radius: 14px; padding: 14px; }
.card p { margin: 0 0 10px; color: var(--muted); }
.card .code { background: var(--bg); margin-top: 0; }
.status-ok { font-weight: 600; margin-bottom: 4px; }
.danger-btn { border-color: var(--danger) !important; color: var(--danger) !important; }
.check { display: flex; gap: 10px; align-items: center; margin: 14px 0 4px; font-size: 14px; cursor: pointer; text-align: left; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.code-input { width: 100%; text-align: center; font: 600 26px/1 ui-monospace, Consolas, monospace; letter-spacing: 10px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); color: var(--text); outline: none; margin: 8px 0; }
.code-input:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.twofa { animation: fade-up .3s both; }
.twofa h3 { margin: 4px 0 6px; }
.tf-icon { font-size: 52px; animation: float 3s ease-in-out infinite; }
.tf-links { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.link-btn:disabled { color: var(--muted); cursor: default; }

/* ---------- ответ, правка, закреп ---------- */
.chat-inner { position: relative; }
.compose-bar { display: flex; align-items: center; gap: 10px; margin: 6px max(16px, calc((100% - 760px) / 2)) 0; padding: 6px 6px 6px 12px; background: var(--bg); border-radius: 14px; box-shadow: var(--shadow); border-left: 3px solid var(--accent); animation: slide-up .2s ease both; cursor: pointer; }
.cb-ic { color: var(--accent); flex: none; }
.compose-bar .i-edit, .compose-bar.editing .i-reply { display: none; }
.compose-bar.editing .i-edit { display: block; }
.cb-body { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 14px; }
.cb-body b { color: var(--accent); }
.cb-body span { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinned { display: flex; align-items: center; gap: 10px; padding: 5px 8px 5px 14px; background: var(--bg); border-bottom: 1px solid var(--border); cursor: pointer; animation: slide-down .22s ease both; }
.pin-body { flex: 1; min-width: 0; border-left: 2px solid var(--accent); padding-left: 10px; display: flex; flex-direction: column; font-size: 14px; }
.pin-body b { color: var(--accent); font-size: 13px; }
.pin-body span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fab { position: absolute; right: 18px; bottom: 86px; width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--bg); color: var(--muted); box-shadow: 0 2px 12px rgba(0,0,0,.22); display: grid; place-items: center; z-index: 5; animation: pop-in .2s cubic-bezier(.2,.9,.3,1.3) both; }
.fab-badge { position: absolute; top: -6px; right: -4px; background: var(--accent); color: var(--on-accent); font-size: 12px; font-weight: 700; min-width: 22px; height: 22px; border-radius: 11px; display: grid; place-items: center; padding: 0 6px; }

/* ---------- элементы сообщений ---------- */
.messages { overflow-x: hidden; }
.msg { position: relative; touch-action: pan-y; }
.msg.swipe-back { transition: transform .25s ease; }
.msg::after { content: "↩"; position: absolute; right: -40px; top: 50%; transform: translateY(-50%) scale(.4); opacity: 0; color: var(--accent); font-size: 22px; font-weight: 700; transition: opacity .15s, transform .2s; pointer-events: none; }
.msg.swipe-ready::after { opacity: 1; transform: translateY(-50%) scale(1); }
.msg.appear { animation: msg-in .3s cubic-bezier(.2,.9,.3,1.1) both; }
.msg.out.appear { transform-origin: 100% 100%; }
.msg.in.appear { transform-origin: 0 100%; }
.msg.flash .bubble { animation: flash 1.3s ease; }
.fwd { font-size: 13px; color: var(--accent); margin-bottom: 2px; }
.msg.out .fwd { color: var(--out-meta); }
.quote { border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); border-radius: 6px; padding: 3px 8px; margin: 2px 0 5px; cursor: pointer; display: flex; flex-direction: column; font-size: 14px; min-width: 0; }
.quote b { color: var(--accent); font-size: 13px; }
.quote span { opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg.out .quote { border-color: var(--out-meta); background: rgba(0,0,0,.07); }
.msg.out .quote b { color: var(--out-meta); }
.edited { font-style: italic; margin-right: 3px; opacity: .85; }
.text.jumbo { font-size: 46px; line-height: 1.2; }
.bubble:has(.jumbo) { background: none !important; box-shadow: none; }
.bubble:has(.jumbo) .meta, .msg.is-sticker .meta { float: none; position: static; display: inline-flex; background: rgba(0,0,0,.4); color: #fff; padding: 1px 7px; border-radius: 10px; margin: 2px 0 0; top: 0; }
.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; clear: both; }
.react { display: inline-flex; align-items: center; gap: 4px; border: 0; border-radius: 14px; padding: 2px 9px; font-size: 15px; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); cursor: pointer; transition: transform .15s; }
.msg.out .react { background: rgba(0,0,0,.08); color: var(--out-meta); }
.react.mine { background: var(--accent); color: var(--on-accent); }
.msg.out .react.mine { background: var(--out-meta); color: #fff; }
.react b { font-size: 13px; }
.react:hover { transform: scale(1.08); }
.react.pop span { display: inline-block; animation: react-pop .55s cubic-bezier(.3,1.6,.5,1); }
.typing-dots { display: inline-flex; gap: 3px; margin-right: 6px; vertical-align: middle; }
.typing-dots i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; animation: dot 1.2s infinite ease-in-out; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
.draft { color: var(--danger); }
.burst { position: fixed; z-index: 95; pointer-events: none; font-size: 26px; animation: burst 1s ease-out both; }

/* ---------- стикеры ---------- */
.msg.is-sticker .bubble { background: none !important; box-shadow: none; padding: 0; }
.msg.out.is-sticker .bubble { text-align: right; }
.sticker-bubble .quote, .sticker-bubble .fwd { background: var(--in-bubble); padding: 4px 8px; border-radius: 10px; }
.sticker { font-size: 112px; line-height: 1.12; cursor: pointer; user-select: none; display: inline-block; }
.sticker span { display: inline-block; animation: var(--st) 1.6s ease-in-out 2; }
.sticker:hover span { animation-iteration-count: infinite; }
.sticker-img { display: block; max-width: 180px; max-height: 180px; margin-left: auto; }
.msg.in .sticker-img { margin-left: 0; }
.a-laugh { --st: st-laugh; } .a-beat { --st: st-beat; } .a-float { --st: st-float; } .a-tilt { --st: st-tilt; }
.a-ponder { --st: st-ponder; } .a-sob { --st: st-sob; } .a-rage { --st: st-rage; } .a-party { --st: st-party; }
.a-zoom { --st: st-zoom; } .a-pop { --st: st-pop; } .a-flicker { --st: st-flicker; } .a-burst { --st: st-burst; }
.a-wave { --st: st-wave; } .a-snooze { --st: st-snooze; } .a-bounce { --st: st-bounce; } .a-rattle { --st: st-rattle; }
.a-nod { --st: st-nod; } .a-fly { --st: st-fly; } .a-sway { --st: st-sway; } .a-spin { --st: st-spin; } .a-explode { --st: st-explode; }
.a-wave span { transform-origin: 70% 90%; }
@keyframes st-laugh { 0%,100% { transform: rotate(0) scale(1); } 20% { transform: rotate(-12deg) scale(1.12); } 40% { transform: rotate(10deg) scale(1.05); } 60% { transform: rotate(-8deg) scale(1.1); } 80% { transform: rotate(6deg); } }
@keyframes st-beat { 0%,100% { transform: scale(1); } 15% { transform: scale(1.25); } 30% { transform: scale(1); } 45% { transform: scale(1.18); } 60% { transform: scale(1); } }
@keyframes st-float { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-12px) rotate(3deg); } }
@keyframes st-tilt { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-14deg) translateX(-6px); } 60% { transform: rotate(10deg) translateX(4px); } }
@keyframes st-ponder { 0%,100% { transform: rotate(0); } 30% { transform: rotate(-10deg) translateY(-4px); } 70% { transform: rotate(-6deg) translateY(2px); } }
@keyframes st-sob { 0%,100% { transform: translateY(0); } 10%,30%,50%,70% { transform: translateY(3px) scale(1.02,.96); } 20%,40%,60% { transform: translateY(-2px); } }
@keyframes st-rage { 0%,100% { transform: none; filter: none; } 10%,30%,50%,70%,90% { transform: translate(-4px,1px) rotate(-3deg); filter: drop-shadow(0 0 12px rgba(255,40,40,.8)); } 20%,40%,60%,80% { transform: translate(4px,-1px) rotate(3deg); } }
@keyframes st-party { 25% { transform: translateY(-18px) rotate(-15deg); } 50% { transform: scale(1.1,.9); } 75% { transform: translateY(-10px) rotate(12deg); } }
@keyframes st-zoom { 0%,100% { transform: scale(1); } 30% { transform: scale(1.35); } 40% { transform: scale(1.25) rotate(-4deg); } 50% { transform: scale(1.35) rotate(4deg); } 70% { transform: scale(1); } }
@keyframes st-pop { 20% { transform: scale(.8); } 45% { transform: scale(1.3) rotate(-8deg); } 65% { transform: scale(.95); } 85% { transform: scale(1.05); } }
@keyframes st-flicker { 0%,100% { transform: none; filter: brightness(1); } 25% { transform: scale(1.05,1.15) translateY(-4px); filter: brightness(1.2); } 50% { transform: scale(.97,.95); } 75% { transform: scale(1.04,1.12) translateY(-3px); filter: brightness(1.15); } }
@keyframes st-burst { 0% { transform: scale(.6) rotate(-30deg); opacity: .6; } 40% { transform: scale(1.3) rotate(10deg); opacity: 1; } 60% { transform: rotate(-5deg); } }
@keyframes st-wave { 15% { transform: rotate(20deg); } 30% { transform: rotate(-12deg); } 45% { transform: rotate(18deg); } 60% { transform: rotate(-8deg); } 75% { transform: rotate(10deg); } }
@keyframes st-snooze { 50% { transform: translateY(4px) scale(1.04,.96); opacity: .85; } }
@keyframes st-bounce { 30% { transform: translateY(-24px) scale(.95,1.05); } 50% { transform: scale(1.1,.9); } 65% { transform: translateY(-8px); } 80% { transform: none; } }
@keyframes st-rattle { 10%,30%,50%,70%,90% { transform: rotate(-8deg) translateY(-2px); } 20%,40%,60%,80% { transform: rotate(8deg); } }
@keyframes st-nod { 30% { transform: rotate(6deg) translateY(4px); } 60% { transform: rotate(-4deg) translateY(2px); } }
@keyframes st-fly { 40% { transform: translate(18px,-22px) rotate(-6deg); } 60% { transform: translate(14px,-18px); } }
@keyframes st-sway { 0%,100% { transform: rotate(-10deg); filter: drop-shadow(0 0 6px rgba(255,240,180,.4)); } 50% { transform: rotate(10deg); filter: drop-shadow(0 0 22px rgba(255,240,180,.9)); } }
@keyframes st-spin { 50% { transform: rotate(180deg) scale(1.2); } 100% { transform: rotate(360deg); } }
@keyframes st-explode { 20% { transform: scale(.9); } 40% { transform: scale(1.4) rotate(-6deg); } 50% { transform: scale(1.3) rotate(6deg); } 70% { transform: scale(1.05); } }

/* ---------- панель эмодзи и стикеров ---------- */
#emojiBtn.on { color: var(--accent); }
.emoji-panel { position: absolute; right: max(16px, calc((100% - 760px) / 2)); bottom: 74px; width: min(360px, calc(100% - 32px)); height: 390px; background: var(--bg); border-radius: 16px; box-shadow: 0 8px 32px rgba(0,0,0,.28); display: flex; flex-direction: column; overflow: hidden; z-index: 20; transform-origin: 100% 100%; animation: pop-in .2s cubic-bezier(.2,.9,.3,1.2) both; }
.ep-tabs { display: flex; gap: 4px; padding: 6px; border-bottom: 1px solid var(--border); }
.ep-tab { flex: 1; border: 0; background: none; padding: 7px; border-radius: 9px; font-weight: 600; color: var(--muted); transition: background .15s, color .15s; }
.ep-tab.active { background: var(--bg-2); color: var(--text); }
.ep-body { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.ep-title { position: sticky; top: 0; background: var(--bg); color: var(--muted); font-size: 13px; font-weight: 600; padding: 8px 4px 4px; z-index: 1; }
.ep-grid { display: grid; grid-template-columns: repeat(8, 1fr); }
.ep-emoji { border: 0; background: none; font-size: 24px; padding: 4px 0; border-radius: 8px; cursor: pointer; transition: transform .12s; }
.ep-emoji:hover { background: var(--hover); transform: scale(1.2); }
.ep-cats { display: flex; justify-content: space-around; border-top: 1px solid var(--border); padding: 4px; }
.ep-cats button { border: 0; background: none; font-size: 18px; padding: 6px; border-radius: 8px; opacity: .7; }
.ep-cats button:hover { opacity: 1; background: var(--hover); }
.st-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.st-item { border: 0; background: none; border-radius: 12px; aspect-ratio: 1; display: grid; place-items: center; cursor: pointer; padding: 4px; overflow: hidden; }
.st-item:hover { background: var(--hover); }
.st-item img { max-width: 100%; max-height: 100%; }
.st-item.sticker { font-size: 44px; }
.st-item.sticker span { animation: none; }
.st-item.sticker:hover span { animation: var(--st) 1.6s ease-in-out infinite; }
.st-add { font-size: 34px; color: var(--accent); border: 2px dashed var(--border) !important; }
.ep-hint { padding: 8px 4px 0; margin: 0; }

/* ---------- меню сообщения ---------- */
.ctx { position: fixed; z-index: 90; background: var(--bg); border-radius: 14px; box-shadow: 0 8px 32px rgba(0,0,0,.3); padding: 6px; min-width: 230px; max-width: calc(100vw - 16px); }
.ctx.pop { animation: ctx-in .18s cubic-bezier(.2,.9,.3,1.2) both; }
.ctx-reacts { display: flex; gap: 2px; padding: 2px 2px 6px; border-bottom: 1px solid var(--border); margin-bottom: 4px; overflow-x: auto; }
.ctx-reacts button { border: 0; background: none; font-size: 22px; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; transition: transform .15s; flex: none; animation: react-in .3s cubic-bezier(.3,1.6,.5,1) backwards; }
.ctx-reacts button:nth-child(2) { animation-delay: .02s; } .ctx-reacts button:nth-child(3) { animation-delay: .04s; } .ctx-reacts button:nth-child(4) { animation-delay: .06s; }
.ctx-reacts button:nth-child(5) { animation-delay: .08s; } .ctx-reacts button:nth-child(6) { animation-delay: .1s; } .ctx-reacts button:nth-child(7) { animation-delay: .12s; } .ctx-reacts button:nth-child(8) { animation-delay: .14s; }
.ctx-reacts button:hover { transform: scale(1.25); background: var(--hover); }
.ctx-reacts button.on { background: var(--hover); box-shadow: inset 0 0 0 2px var(--accent); }
.ctx-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 12px; border: 0; background: none; border-radius: 8px; text-align: left; font-size: 14.5px; cursor: pointer; color: var(--text); }
.ctx-item:hover { background: var(--hover); }
.ctx-item.danger { color: var(--danger); }
.ctx-ic { width: 20px; text-align: center; }
.fwd-list { max-height: 50vh; overflow-y: auto; margin-top: 8px; display: flex; flex-direction: column; }
.fwd-item { display: flex; align-items: center; gap: 12px; border: 0; background: none; padding: 8px; border-radius: 10px; text-align: left; font-weight: 500; cursor: pointer; color: var(--text); }
.fwd-item:hover { background: var(--hover); }
.fwd-item .avatar { width: 40px; height: 40px; font-size: 15px; }

/* ---------- анимации ---------- */
.modal:not(.hidden) { animation: fade-in .18s ease both; }
.modal:not(.hidden) .modal-card { animation: pop-in .24s cubic-bezier(.2,.9,.3,1.2) both; }
.modal.closing { animation: fade-out .17s ease both; }
.modal.closing .modal-card { animation: pop-out .17s ease both; }
.chat-inner.chat-enter { animation: fade-in .25s ease both; }
.toast:not(.hidden) { animation: toast-in .25s cubic-bezier(.2,.9,.3,1.2) both; }
.composer .send .i-send, .composer .send .i-mic { display: block !important; position: absolute; transition: opacity .18s, transform .25s cubic-bezier(.3,1.5,.5,1); }
.composer .send .i-send { opacity: 0; transform: scale(.4) rotate(-60deg); }
.composer.has-text .send .i-send, .composer.recording .send .i-send { opacity: 1; transform: none; }
.composer.has-text .send .i-mic, .composer.recording .send .i-mic { opacity: 0; transform: scale(.4); }
.icon-btn, .btn-primary, .btn-secondary, .set-row, .drawer-item, .theme-card, .profile-act, .round, .ep-tab, .fab { transition: transform .12s ease, background-color .15s, border-color .2s; }
.icon-btn:active, .btn-primary:active, .btn-secondary:active, .set-row:active, .drawer-item:active, .theme-card:active, .profile-act:active, .round:active, .fab:active { transform: scale(.95); }
.item { transition: background-color .15s; }
.theme-card.active { transform: translateY(-2px); }
.auth-card { animation: fade-up .45s cubic-bezier(.2,.8,.2,1) both; }
.auth-logo { animation: float 4s ease-in-out infinite; }
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(.9); } }
@keyframes pop-out { to { opacity: 0; transform: scale(.94); } }
@keyframes slide-up { from { opacity: 0; transform: translateY(10px); } }
@keyframes slide-down { from { opacity: 0; transform: translateY(-10px); } }
@keyframes slide-in-left { from { opacity: 0; transform: translateX(-16px); } }
@keyframes fade-up { from { opacity: 0; transform: translateY(14px); } }
@keyframes drawer-in { from { transform: translateX(-100%); } }
@keyframes drawer-out { to { transform: translateX(-100%); } }
@keyframes page-in { from { transform: translateX(48px); opacity: 0; } }
@keyframes page-out { to { transform: translateX(48px); opacity: 0; } }
@keyframes msg-in { from { opacity: 0; transform: translateY(14px) scale(.95); } }
@keyframes flash { 20%, 60% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 55%, transparent); } }
@keyframes ctx-in { from { opacity: 0; transform: scale(.85); } }
@keyframes react-in { from { opacity: 0; transform: scale(.3); } }
@keyframes react-pop { 0% { transform: scale(0); } 60% { transform: scale(1.45); } 100% { transform: scale(1); } }
@keyframes dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
@keyframes burst { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.3); } 20% { opacity: 1; transform: translate(-50%, -50%) scale(1.25); } 100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.8); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px) scale(.95); } }
@keyframes float { 50% { transform: translateY(-6px); } }
@keyframes spin-in { from { transform: rotate(-120deg) scale(.4); opacity: 0; } }
html.no-anim *, html.no-anim *::before, html.no-anim *::after { animation: none !important; transition: none !important; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  #app { position: relative; overflow: hidden; }
  .sidebar { position: absolute; inset: 0; width: 100%; min-width: 0; border-right: 0; transition: transform .32s cubic-bezier(.2,.8,.2,1); }
  .chat { position: absolute; inset: 0; display: flex; transform: translateX(100%); transition: transform .32s cubic-bezier(.2,.8,.2,1); box-shadow: -8px 0 24px rgba(0,0,0,.15); }
  #app.chat-open .chat { transform: none; }
  #app.chat-open .sidebar { transform: translateX(-28%); }
  .chat-inner.chat-enter { animation: none; }
  .emoji-panel { left: 8px; right: 8px; width: auto; bottom: 68px; height: 46vh; }
  .fab { right: 12px; bottom: 76px; }
  .compose-bar { margin: 6px 8px 0; }
  .back { display: grid; }
  .chat-head .icon-btn { width: 36px; }
  .messages { padding: 10px 8px; }
  .composer { padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); gap: 6px; }
  input, textarea, select { font-size: 16px !important; } /* iOS Safari увеличивает страницу при фокусе на поле мельче 16px */
  .call { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
  .bubble { max-width: 86%; }
  .call-controls { gap: 14px; }
  .round { width: 58px; height: 58px; }
  .round span { top: 64px; font-size: 11.5px; }
}
