/* ================= ТОКЕНЫ ================= */
:root {
  --bg: #07061a;
  --panel: rgba(16, 13, 40, .74);
  --panel-solid: #100d28;
  --modal-bg: #120f2e;
  --menu-bg: rgba(20, 16, 48, .97);
  --surface: rgba(255, 255, 255, .04);
  --surface-2: rgba(255, 255, 255, .07);
  --surface-3: rgba(255, 255, 255, .11);
  --border: rgba(255, 255, 255, .08);
  --border-strong: rgba(255, 255, 255, .16);
  --text: #f4f2ff;
  --text-2: #a9a4c7;
  --text-3: #6f6a90;
  --bubble-in: rgba(255, 255, 255, .075);
  --bubble-in-border: rgba(255, 255, 255, .05);
  --overlay: rgba(3, 2, 12, .7);
  --accent-text: #c9b8ff;
  --blue: #2fb4ff;
  --indigo: #4b4bff;
  --violet: #8a3dff;
  --pink: #e65cff;
  --green: #3dffa8;
  --danger: #ff5c7a;
  --grad: linear-gradient(120deg, var(--blue), var(--indigo) 35%, var(--violet) 70%, var(--pink));
  --grad-out: linear-gradient(135deg, var(--indigo), var(--violet) 60%, var(--pink));
  --grad-soft: linear-gradient(135deg, color-mix(in srgb, var(--blue) 16%, transparent), color-mix(in srgb, var(--violet) 16%, transparent) 55%, color-mix(in srgb, var(--pink) 16%, transparent));
  --glow: color-mix(in srgb, var(--violet) 70%, transparent);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Unbounded", var(--font);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f4f2fb;
  --panel: rgba(255, 255, 255, .86);
  --panel-solid: #ffffff;
  --modal-bg: #ffffff;
  --menu-bg: rgba(255, 255, 255, .98);
  --surface: rgba(40, 20, 90, .04);
  --surface-2: rgba(40, 20, 90, .07);
  --surface-3: rgba(40, 20, 90, .11);
  --border: rgba(40, 20, 90, .09);
  --border-strong: rgba(40, 20, 90, .16);
  --text: #1a1630;
  --text-2: #5d5878;
  --text-3: #9591ad;
  --bubble-in: #ffffff;
  --bubble-in-border: rgba(40, 20, 90, .08);
  --overlay: rgba(30, 20, 60, .35);
  --accent-text: var(--violet);
  --green: #10b981;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #root { height: 100%; }
body {
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased; overflow: hidden;
  transition: background .3s;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
button:disabled { cursor: default; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
::selection { background: var(--violet); color: #fff; }
[hidden] { display: none !important; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; }
code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

.bg { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.bg span { position: absolute; border-radius: 50%; filter: blur(130px); opacity: .45; }
.bg span:first-child { width: 600px; height: 600px; background: var(--indigo); top: -250px; left: -200px; }
.bg span:last-child { width: 600px; height: 600px; background: var(--violet); bottom: -260px; right: -200px; }
[data-theme="light"] .bg span { opacity: .18; }

.grad-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.muted-text { color: var(--text-2); }
.hint { font-size: 13px; color: var(--text-3); }
.opt { color: var(--text-3); font-style: normal; }
.tag { font-size: 11px; font-weight: 700; color: var(--accent-text); padding: 2px 8px; border-radius: 6px; background: color-mix(in srgb, var(--violet) 18%, transparent); white-space: nowrap; }

/* ================= КНОПКИ И ПОЛЯ ================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 22px; border-radius: 14px;
  font-weight: 700; font-size: 15px; white-space: nowrap;
  transition: transform .2s var(--ease), box-shadow .3s, background .3s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn svg { width: 18px; height: 18px; }
.btn-primary { color: #fff; background: var(--grad); box-shadow: 0 10px 30px -10px var(--glow), inset 0 1px 0 rgba(255,255,255,.25); }
.btn-primary:hover { box-shadow: 0 14px 40px -10px var(--glow), inset 0 1px 0 rgba(255,255,255,.3); }
.btn-ghost { background: var(--surface-2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-danger { background: rgba(255,92,122,.12); color: var(--danger); border: 1px solid rgba(255,92,122,.25); }
.btn-danger:hover { background: rgba(255,92,122,.2); }
.btn-block { width: 100%; }
.btn-sm { height: 38px; padding: 0 14px; border-radius: 12px; font-size: 14px; }
.btn .spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0;
  color: var(--text-2); transition: background .2s, color .2s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: .35; }

.field { display: grid; gap: 8px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field small { font-size: 12px; color: var(--text-3); min-height: 18px; }
.field small.err { color: var(--danger); }
.field small.ok { color: var(--green); }
.input {
  width: 100%; height: 52px; padding: 0 16px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border); outline: 0;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
select.input { appearance: none; cursor: pointer; background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%); background-position: calc(100% - 22px) 50%, calc(100% - 16px) 50%; background-size: 6px 6px; background-repeat: no-repeat; }
select.input option { background: var(--modal-bg); color: var(--text); }
textarea.input { height: auto; min-height: 90px; padding: 14px 16px; resize: vertical; }
.input::placeholder { color: var(--text-3); }
.input:focus { border-color: color-mix(in srgb, var(--violet) 60%, transparent); background: var(--surface-2); box-shadow: 0 0 0 4px color-mix(in srgb, var(--violet) 15%, transparent); }
.input-prefix { position: relative; }
.input-prefix > b { position: absolute; left: 16px; top: 50%; translate: 0 -50%; color: var(--text-3); font-weight: 600; pointer-events: none; }
.input-prefix .input { padding-left: 34px; }
.input-big { height: 60px; font-size: 20px; font-weight: 600; letter-spacing: .02em; text-align: center; }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 52px; }
.pw-wrap .pw-toggle { position: absolute; right: 6px; top: 6px; }
.check-row { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.check-row input { width: 18px; height: 18px; accent-color: var(--violet); }

/* ================= АВТОРИЗАЦИЯ ================= */
.auth { height: 100%; display: grid; place-items: center; padding: 20px; overflow-y: auto; }
.auth-card {
  width: min(420px, 100%); padding: 44px 36px 36px; border-radius: 28px; text-align: center;
  background: var(--panel); border: 1px solid var(--border-strong);
  backdrop-filter: blur(24px); box-shadow: 0 40px 100px -30px rgba(0,0,0,.5);
  animation: cardIn .6s var(--ease) both;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(20px) scale(.97); } }
.auth-logo { width: 84px; height: 84px; border-radius: 24px; margin: 0 auto 24px; box-shadow: 0 20px 50px -10px var(--glow); animation: float 5s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-6px); } }
.auth h1 { font: 700 24px/1.25 var(--display); letter-spacing: -.02em; }
.auth .sub { color: var(--text-2); margin: 10px 0 28px; }
.auth form { display: grid; gap: 14px; text-align: left; }
.about-link { margin-left: 14px; text-decoration: none; }
.auth-back { display: inline-flex; align-items: center; gap: 6px; margin-top: 18px; color: var(--text-2); font-size: 14px; font-weight: 600; }
.auth-back:hover { color: var(--text); }
.auth-phone { font-weight: 700; color: var(--text); }
.auth-note { font-size: 12px; color: var(--text-3); text-align: center; margin-top: 4px; }
.auth-step { animation: stepIn .4s var(--ease) both; }
@keyframes stepIn { from { opacity: 0; transform: translateX(20px); } }
.avatar-pick { display: flex; justify-content: center; margin-bottom: 6px; }

/* ================= КАРКАС ================= */
.app { height: 100%; display: grid; grid-template-columns: 380px minmax(0, 1fr) auto; }
.sidebar {
  position: relative; display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-right: 1px solid var(--border); backdrop-filter: blur(20px);
}
.side-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px; }
.search {
  flex: 1; display: flex; align-items: center; gap: 10px; height: 42px; padding: 0 14px;
  border-radius: 14px; background: var(--surface); border: 1px solid var(--border);
  transition: border-color .2s, background .2s;
}
.search:focus-within { border-color: color-mix(in srgb, var(--violet) 60%, transparent); background: var(--surface-2); }
.search svg { width: 18px; height: 18px; color: var(--text-3); }
.search input { flex: 1; min-width: 0; background: transparent; border: 0; outline: 0; }
.search input::placeholder { color: var(--text-3); }

.menu {
  position: absolute; top: 60px; left: 14px; z-index: 30; width: 260px; padding: 6px;
  border-radius: 16px; background: var(--menu-bg); border: 1px solid var(--border-strong);
  box-shadow: 0 20px 60px -10px rgba(0,0,0,.45); backdrop-filter: blur(20px);
  animation: pop .18s var(--ease) both; transform-origin: top left;
}
.menu.fab-menu { top: auto; left: auto; right: 20px; bottom: 90px; transform-origin: bottom right; }
.ctx-menu { position: fixed; z-index: 120; width: 240px; transform-origin: top left; }
@keyframes pop { from { opacity: 0; transform: scale(.92); } }
.menu-me { display: flex; align-items: center; gap: 12px; padding: 10px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.menu-me strong { display: block; font-size: 15px; }
.menu-me span { font-size: 13px; color: var(--text-2); }
.menu button { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; font-weight: 600; font-size: 14px; text-align: left; }
.menu button:hover { background: var(--surface-2); }
.menu button svg { color: var(--text-2); width: 18px; height: 18px; }
.menu button.danger, .menu button.danger svg { color: var(--danger); }
.ctx-reactions { display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; padding: 4px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.ctx-reactions button { justify-content: center; padding: 6px 0; font-size: 20px; border-radius: 10px; transition: transform .15s var(--ease), background .15s; }
.ctx-reactions button:hover { transform: scale(1.25); background: transparent; }
.ctx-reactions button.on { background: color-mix(in srgb, var(--violet) 22%, transparent); }

.chat-list { flex: 1; overflow-y: auto; padding: 4px 8px 90px; }
.list-label { padding: 14px 12px 6px; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); }
.list-empty { padding: 50px 24px; text-align: center; color: var(--text-2); }
.list-empty strong { display: block; color: var(--text); font-size: 16px; margin-bottom: 6px; }
.archive-head { display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px; font-weight: 700; color: var(--text-2); border-radius: 12px; }
.archive-head:hover { background: var(--surface); color: var(--text); }
.archive-row .av-in { color: var(--text-2); }

.chat-item {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 16px; text-align: left;
  transition: background .2s; user-select: none; -webkit-touch-callout: none;
}
.chat-item:hover { background: var(--surface); }
.chat-item.active { background: var(--grad-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--violet) 35%, transparent); }
.chat-item .ci-body { flex: 1; min-width: 0; }
.ci-top, .ci-bottom { display: flex; align-items: center; gap: 6px; }
.ci-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-title svg { width: 15px; height: 15px; color: var(--text-2); }
.lock-ico { display: inline-grid; color: var(--green); }
.lock-ico svg { width: 13px; height: 13px; }
.ci-time { font-size: 12px; color: var(--text-3); }
.ci-ticks { display: inline-grid; color: var(--text-3); }
.ci-ticks.read { color: var(--blue); }
.ci-ticks svg { width: 16px; height: 16px; }
.ci-text { flex: 1; min-width: 0; font-size: 14px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-text b { color: var(--text); font-weight: 600; }
.ci-text.typing { color: var(--accent-text); }
.ci-flag { display: inline-grid; color: var(--text-3); }
.ci-flag svg { width: 15px; height: 15px; }
.badge {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; display: grid; place-items: center;
  background: var(--grad); color: #fff; font-size: 12px; font-weight: 800;
  box-shadow: 0 4px 14px -4px var(--glow);
}
.badge.muted { background: var(--surface-3); color: var(--text-2); box-shadow: none; }

.fab {
  position: absolute; right: 20px; bottom: 20px; z-index: 20;
  width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center;
  background: var(--grad); color: #fff;
  box-shadow: 0 14px 40px -10px var(--glow), inset 0 1px 0 rgba(255,255,255,.3);
  transition: transform .3s var(--ease);
}
.fab:hover { transform: translateY(-3px) rotate(-6deg); }
.fab svg { width: 24px; height: 24px; }

/* ================= АВАТАРЫ ================= */
.avatar {
  --s: 48px; position: relative; flex-shrink: 0;
  width: var(--s); height: var(--s); border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 800; font-size: calc(var(--s) * .38); color: #fff; user-select: none;
}
.avatar > .av-in { width: 100%; height: 100%; border-radius: inherit; display: grid; place-items: center; overflow: hidden; background: var(--av-bg, var(--grad)); }
.avatar > .av-in svg { width: 45%; height: 45%; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.online::after {
  content: ""; position: absolute; right: 1px; bottom: 1px;
  width: calc(var(--s) * .26); height: calc(var(--s) * .26); border-radius: 50%;
  background: var(--green); border: 3px solid var(--panel-solid);
}
.avatar.sq > .av-in { border-radius: 30%; }

/* ================= ЧАТ ================= */
.chat { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-empty { flex: 1; display: grid; place-items: center; text-align: center; padding: 30px; color: var(--text-2); }
.chat-empty img { width: 96px; height: 96px; border-radius: 28px; margin: 0 auto 22px; opacity: .9; box-shadow: 0 20px 60px -15px var(--glow); }
.chat-empty h2 { font: 700 22px var(--display); color: var(--text); margin-bottom: 8px; }

.chat-head {
  display: flex; align-items: center; gap: 6px; padding: 10px 12px; min-height: 66px;
  background: var(--panel); border-bottom: 1px solid var(--border); backdrop-filter: blur(20px);
}
.chat-head .who { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; text-align: left; border-radius: 12px; padding: 4px; }
.chat-head .who-text { min-width: 0; }
.chat-head strong { display: flex; align-items: center; gap: 6px; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head strong > svg { width: 16px; height: 16px; color: var(--text-2); }
.chat-head .status { font-size: 13px; color: var(--text-2); }
.chat-head .status.on { color: var(--green); }
.chat-head .status.typing { color: var(--accent-text); }
.back-btn { display: none; }
.sel-count { flex: 1; font-size: 16px; }
.chat-search { height: 40px; }
.search-count { font-size: 13px; color: var(--text-2); white-space: nowrap; padding: 0 6px; }

.pin-bar {
  display: flex; align-items: center; gap: 10px; padding: 6px 12px 6px 16px;
  background: var(--panel); border-bottom: 1px solid var(--border); backdrop-filter: blur(20px);
  animation: fade .2s both;
}
.pin-lines { display: flex; flex-direction: column; gap: 2px; height: 34px; justify-content: center; }
.pin-lines i { width: 3px; flex: 1; max-height: 34px; border-radius: 2px; background: var(--surface-3); }
.pin-lines i.on { background: var(--violet); }
.pin-body { flex: 1; min-width: 0; display: grid; text-align: left; }
.pin-body b { font-size: 13px; color: var(--accent-text); }
.pin-body span { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.messages { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 18px 6% 10px; display: flex; flex-direction: column; gap: 3px; }
.msg-row { position: relative; display: flex; align-items: flex-end; gap: 8px; animation: msgIn .3s var(--ease) both; border-radius: 14px; transition: background .3s; -webkit-touch-callout: none; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } }
.msg-row.out { justify-content: flex-end; }
.msg-row.first { margin-top: 10px; }
.msg-row .avatar-slot { width: 34px; flex-shrink: 0; }
.msg-row.flash { animation: flash 1.6s var(--ease); }
@keyframes flash { 0%, 40% { background: color-mix(in srgb, var(--violet) 22%, transparent); } }
.msg-row.selecting { cursor: pointer; padding-left: 34px; }
.msg-row.selecting:hover { background: var(--surface); }
.msg-row.selected { background: color-mix(in srgb, var(--violet) 14%, transparent); }
.sel-check {
  position: absolute; left: 6px; top: 50%; translate: 0 -50%; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border-strong); display: grid; place-items: center;
}
.sel-check svg { width: 13px; height: 13px; stroke-width: 3.5; color: #fff; opacity: 0; }
.msg-row.selected .sel-check { background: var(--grad); border-color: transparent; }
.msg-row.selected .sel-check svg { opacity: 1; }

.bubble {
  position: relative; max-width: min(560px, 78%); padding: 8px 12px 6px; border-radius: 18px;
  background: var(--bubble-in); border: 1px solid var(--bubble-in-border);
  overflow-wrap: anywhere; user-select: text;
}
[data-theme="light"] .msg-row.in .bubble { box-shadow: 0 2px 8px -4px rgba(40,20,90,.15); }
.msg-row.out .bubble { background: var(--grad-out); border-color: transparent; color: #fff; box-shadow: 0 6px 20px -10px var(--glow); }
.msg-row.in.last .bubble { border-bottom-left-radius: 6px; }
.msg-row.out.last .bubble { border-bottom-right-radius: 6px; }
.bubble.pop-react { animation: popReact .45s var(--ease); }
@keyframes popReact { 40% { transform: scale(1.04); } }
.btext { white-space: pre-wrap; }
.bubble .sender { display: block; font-size: 13px; font-weight: 700; margin-bottom: 2px; cursor: pointer; }
.bubble .meta { float: right; display: inline-flex; align-items: center; gap: 3px; margin: 6px 0 -2px 12px; font-size: 11px; color: var(--text-3); user-select: none; }
.bubble .meta em { font-style: normal; margin-right: 2px; }
.msg-row.out .bubble .meta { color: rgba(255,255,255,.75); }
.meta svg { width: 15px; height: 15px; stroke-width: 2.4; }
.meta .read { color: #9ff0ff; display: inline-grid; }
.ttl-ico { display: inline-grid; }
.ttl-ico svg { width: 12px; height: 12px; }
.bubble a { color: #9fd8ff; }
.msg-row.in .bubble a { color: var(--blue); }
.service { align-self: center; margin: 12px 0; padding: 5px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--text-2); background: var(--surface); border: 1px solid var(--border); text-align: center; animation: msgIn .3s var(--ease) both; }
.service.flash { animation: flash 1.6s var(--ease); }
.day-sep { position: sticky; top: 4px; z-index: 2; align-self: center; margin: 14px 0 6px; padding: 4px 14px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--panel); border: 1px solid var(--border); backdrop-filter: blur(10px); }
.load-more { align-self: center; padding: 8px; color: var(--text-3); font-size: 13px; }
.channel-post .bubble { max-width: min(620px, 90%); }
.e2ee-intro { align-self: center; max-width: 360px; margin: auto 0; padding: 22px; border-radius: 20px; text-align: center; display: grid; justify-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--border); }
.e2ee-intro svg { width: 30px; height: 30px; color: var(--green); }
.e2ee-intro span { font-size: 14px; color: var(--text-2); }

/* Пересылка, ответ, реакции */
.fwd { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--accent-text); margin-bottom: 4px; }
.msg-row.out .fwd { color: rgba(255,255,255,.85); }
.fwd svg { width: 14px; height: 14px; }
.reply-quote {
  display: grid; width: 100%; text-align: left; margin: 2px 0 6px; padding: 4px 10px; border-radius: 8px;
  border-left: 3px solid var(--q, var(--violet)); background: color-mix(in srgb, var(--q, var(--violet)) 12%, transparent);
  transition: background .2s;
}
.reply-quote:hover { background: color-mix(in srgb, var(--q, var(--violet)) 20%, transparent); }
.reply-quote b { font-size: 13px; color: var(--q, var(--violet)); }
.msg-row.out .reply-quote { border-left-color: #fff; background: rgba(255,255,255,.14); }
.msg-row.out .reply-quote b { color: #fff; }
.reply-quote span { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .85; }
.reply-quote.deleted { opacity: .6; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 2px; }
.reaction {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px 2px 6px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); font-size: 14px;
  transition: transform .15s var(--ease), background .2s; animation: pop .25s var(--ease) both;
}
.reaction span { font-size: 12px; font-weight: 700; }
.reaction:hover { transform: scale(1.06); }
.reaction.mine { background: color-mix(in srgb, var(--violet) 28%, transparent); border-color: color-mix(in srgb, var(--violet) 55%, transparent); }
.msg-row.out .reaction { background: rgba(255,255,255,.18); border-color: transparent; color: #fff; }
.msg-row.out .reaction.mine { background: #fff; color: #5b2fd6; }

/* Стикеры и крупные эмодзи */
.msg-row .bubble.sticker-only, .msg-row .bubble.circle-only { background: transparent; border-color: transparent; box-shadow: none; padding: 0; }
.sticker { font-size: 120px; line-height: 1.1; filter: drop-shadow(0 10px 18px rgba(0,0,0,.35)); user-select: none; }
.bubble.sticker-only .meta, .bubble.circle-only > .meta { float: none; display: inline-flex; padding: 2px 8px; border-radius: 999px; background: rgba(0,0,0,.4); color: #fff; margin: 4px 0 0; }
.msg-row.out .bubble.sticker-only { text-align: right; }
.bubble.big-emoji .btext { font-size: 44px; line-height: 1.2; }
.anim-bounce { animation: stBounce 2.4s var(--ease) infinite; }
.anim-zap { animation: stZap 2.2s ease-in-out infinite; }
.anim-wiggle { animation: stWiggle 2s ease-in-out infinite; }
.anim-wave { animation: stWave 1.8s ease-in-out infinite; transform-origin: 70% 80%; }
.anim-float { animation: stFloat 3s ease-in-out infinite; }
@keyframes stBounce { 0%, 60%, 100% { transform: translateY(0) scale(1); } 20% { transform: translateY(-14px) scale(1.05, .95); } 40% { transform: translateY(0) scale(.95, 1.05); } }
@keyframes stZap { 0%, 100% { transform: scale(1); filter: drop-shadow(0 0 0 transparent); } 50% { transform: scale(1.08) rotate(-4deg); filter: drop-shadow(0 0 22px var(--violet)); } }
@keyframes stWiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }
@keyframes stWave { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(18deg); } 60% { transform: rotate(-10deg); } }
@keyframes stFloat { 50% { transform: translateY(-10px); } }

/* Звонки в истории */
.call-bubble { min-width: 240px; }
.call-msg { display: flex; align-items: center; gap: 12px; padding: 2px 0; }
.call-msg > div { flex: 1; display: grid; }
.call-msg small { font-size: 12px; opacity: .75; }
.call-ico { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--green) 20%, transparent); color: var(--green); }
.msg-row.out .call-ico { background: rgba(255,255,255,.2); color: #fff; }
.call-msg.missed .call-ico { background: rgba(255,92,122,.18); color: var(--danger); }
.msg-row.out .call-msg .icon-btn { color: #fff; }
.locked-text { color: var(--text-2); font-style: italic; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.msg-row.out .locked-text { color: rgba(255,255,255,.8); }
.locked-text svg { width: 15px; height: 15px; }

/* ================= ВЛОЖЕНИЯ ================= */
.bubble.has-media { width: min(380px, 78%); padding: 4px; }
.bubble.has-media > .sender, .bubble.has-media > .fwd, .bubble.has-media > .reply-quote { margin-left: 6px; margin-right: 6px; width: auto; }
.bubble.has-media > .sender { padding: 4px 4px 2px; }
.bubble.has-media .btext { padding: 6px 8px 2px; }
.bubble.has-media > .meta { margin: 4px 6px 0 0; }
.media-grid { display: grid; gap: 3px; border-radius: 15px; overflow: hidden; }
.bubble.has-media:not(.media-only) .media-grid { border-bottom-left-radius: 6px; border-bottom-right-radius: 6px; }
.media-grid.n2, .media-grid.n3, .media-grid.n4 { grid-template-columns: 1fr 1fr; }
.media-grid.n3 .media:first-child { grid-column: span 2; aspect-ratio: 2 / 1; }
.media-grid.single .media { aspect-ratio: var(--ratio, 4/3); }
.media { position: relative; display: block; width: 100%; aspect-ratio: 1; overflow: hidden; background: var(--surface-2); cursor: zoom-in; }
.media img, .media video { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .4s var(--ease), filter .3s; }
.media:hover img, .media:hover video { transform: scale(1.03); filter: brightness(1.08); }
.media.loading::before, .circle-msg.loading::before, .video-msg.loading::before {
  content: ""; position: absolute; inset: 0; z-index: 1;
  background: linear-gradient(100deg, transparent 30%, rgba(255,255,255,.12) 50%, transparent 70%) var(--surface-2);
  background-size: 200% 100%; animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.media.broken::after { content: "🔒"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 28px; }
.media-play { position: absolute; left: 50%; top: 50%; translate: -50% -50%; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: rgba(0,0,0,.5); color: #fff; backdrop-filter: blur(4px); pointer-events: none; }
.media-play svg { margin-left: 3px; }
.media-dur { position: absolute; left: 8px; top: 8px; padding: 1px 7px; border-radius: 6px; background: rgba(0,0,0,.5); color: #fff; font-size: 12px; font-weight: 600; }
.media-more { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(7,6,26,.6); font: 700 26px var(--display); color: #fff; }
.msg-row .bubble.media-only { background: transparent; border-color: transparent; box-shadow: none; position: relative; padding: 0; }
.bubble.media-only .media-grid { box-shadow: 0 10px 30px -14px rgba(0,0,0,.6); }
.bubble.media-only > .meta { position: absolute; right: 8px; bottom: 8px; margin: 0; padding: 2px 8px; border-radius: 999px; background: rgba(0,0,0,.5); color: #fff; backdrop-filter: blur(6px); }
.bubble.media-only > .reactions { position: absolute; left: 8px; bottom: 6px; margin: 0; }

.video-msg { position: relative; width: 100%; border-radius: 14px; overflow: hidden; background: #000; }
.video-msg video { width: 100%; height: 100%; display: block; object-fit: contain; background: #000; }
.modal .video-msg { max-height: 75vh; }

.file-card {
  display: flex; align-items: center; gap: 12px; width: 100%; min-width: 220px; padding: 6px 10px 6px 6px; margin: 2px 0;
  border-radius: 14px; color: inherit; text-align: left; transition: background .2s;
}
.file-card:hover { background: var(--surface-2); }
.msg-row.out .file-card:hover { background: rgba(255,255,255,.1); }
.file-icon {
  position: relative; width: 46px; height: 46px; flex-shrink: 0; border-radius: 13px; display: grid; place-items: center;
  background: var(--grad); color: #fff; font: 800 11px var(--font); letter-spacing: .02em; overflow: hidden;
}
.file-icon > span { display: grid; place-items: center; }
.msg-row.out .file-icon { background: rgba(255,255,255,.22); }
.file-icon > svg { position: absolute; width: 20px; height: 20px; opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
.file-icon > span { transition: opacity .2s, transform .2s; }
.file-card:hover:not(:disabled) .file-icon > svg { opacity: 1; transform: none; }
.file-card:hover:not(:disabled) .file-icon > span { opacity: 0; transform: translateY(-6px); }
.file-info { min-width: 0; display: grid; }
.file-info b { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-info small { font-size: 12px; color: var(--text-2); }
.msg-row.out .file-info small { color: rgba(255,255,255,.75); }
.bubble.has-files:not(.has-media) { padding: 6px 8px; }
.bubble.has-files:not(.has-media) .btext { padding: 4px 4px 0; }

/* Голосовые */
.bubble.has-voice { min-width: min(300px, 78%); }
.voice { display: flex; align-items: center; gap: 12px; padding: 4px 2px 2px; }
.voice-play {
  width: 44px; height: 44px; flex-shrink: 0; border-radius: 50%; display: grid; place-items: center;
  background: var(--grad); color: #fff; box-shadow: 0 6px 18px -6px var(--glow); transition: transform .2s var(--ease);
}
.voice-play:hover { transform: scale(1.06); }
.voice-play[data-icon="play"] svg { margin-left: 2px; }
.msg-row.out .voice-play { background: #fff; color: var(--violet); box-shadow: none; }
.voice-body { flex: 1; min-width: 0; display: grid; gap: 4px; }
.voice-wave { height: 30px; display: flex; align-items: center; gap: 2px; cursor: pointer; }
.voice-wave i { flex: 1; min-width: 2px; max-width: 4px; border-radius: 2px; background: var(--surface-3); transition: background .15s; }
.voice-wave i.on { background: var(--violet); }
.msg-row.out .voice-wave i { background: rgba(255,255,255,.4); }
.msg-row.out .voice-wave i.on { background: #fff; }
.voice-time { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.msg-row.out .voice-time { color: rgba(255,255,255,.8); }
.voice.playing .voice-play { animation: voicePulse 1.6s ease-out infinite; }
@keyframes voicePulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--violet) 55%, transparent); } 100% { box-shadow: 0 0 0 12px transparent; } }
.bubble.has-voice > .meta { margin-top: -16px; }

/* Кружочки */
.circle-msg { position: relative; width: 240px; height: 240px; border-radius: 50%; overflow: hidden; cursor: pointer; background: var(--surface-2); box-shadow: 0 12px 30px -12px rgba(0,0,0,.6); }
.circle-msg video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.circle-progress { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); pointer-events: none; }
.circle-progress circle { fill: none; stroke: #fff; stroke-width: 1.2; stroke-dasharray: 100; stroke-dashoffset: 100; stroke-linecap: round; opacity: 0; transition: opacity .2s; }
.circle-msg.active .circle-progress circle { opacity: .9; }
.circle-time { position: absolute; left: 50%; bottom: 14px; translate: -50% 0; padding: 1px 8px; border-radius: 999px; background: rgba(0,0,0,.5); color: #fff; font-size: 12px; font-weight: 600; }
.circle-sound { position: absolute; right: 22px; top: 22px; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: rgba(0,0,0,.45); color: #fff; transition: opacity .2s; }
.circle-sound svg { width: 14px; height: 14px; margin-left: 2px; }
.circle-msg.active .circle-sound { opacity: 0; }
.bubble:not(.circle-only) .circle-msg { margin: 4px auto; }

.circle-rec {
  position: absolute; inset: 0; z-index: 35; display: grid; place-items: center;
  background: var(--overlay); backdrop-filter: blur(10px); animation: fade .2s both; pointer-events: none;
}
.circle-rec-inner { position: relative; width: min(320px, 70vw); aspect-ratio: 1; border-radius: 50%; overflow: hidden; box-shadow: 0 30px 80px -20px rgba(0,0,0,.8); animation: pop .3s var(--ease) both; }
.circle-rec-inner video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.circle-ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.circle-ring circle { fill: none; stroke: var(--pink); stroke-width: 1.5; stroke-linecap: round; transition: stroke-dashoffset .1s linear; filter: drop-shadow(0 0 3px var(--pink)); }

/* ================= КОМПОЗЕР ================= */
.composer { position: relative; padding: 10px 6% 18px; }
.composer-box {
  display: flex; align-items: flex-end; gap: 6px; padding: 6px 6px 6px 12px;
  border-radius: 22px; background: var(--panel); border: 1px solid var(--border-strong);
  backdrop-filter: blur(20px); transition: border-color .2s, box-shadow .2s;
}
.composer-box:focus-within { border-color: color-mix(in srgb, var(--violet) 55%, transparent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--violet) 12%, transparent); }
.composer textarea { flex: 1; max-height: 200px; min-height: 24px; margin: 10px 0; resize: none; background: transparent; border: 0; outline: 0; line-height: 1.45; }
.composer textarea::placeholder { color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attach-btn, .emoji-btn { margin: 2px 0; }
.attach-btn:hover, .emoji-btn:hover { color: var(--accent-text); }
.send-btn {
  width: 44px; height: 44px; border-radius: 16px; display: grid; place-items: center; flex-shrink: 0;
  background: var(--grad); color: #fff; box-shadow: 0 8px 24px -8px var(--glow);
  transition: transform .2s var(--ease), opacity .2s;
}
.send-btn:not([hidden]) { animation: pop .2s var(--ease) both; }
.send-btn:disabled { opacity: .35; box-shadow: none; }
.send-btn:not(:disabled):hover { transform: scale(1.06) rotate(-8deg); }
.send-btn svg { width: 20px; height: 20px; fill: none; stroke: #fff; stroke-width: 2.4; }
.send-btn.bolt svg { fill: #fff; stroke: none; }
.send-btn.alt-btn { background: var(--surface-2); color: var(--text); box-shadow: none; border: 1px solid var(--border); }
.send-btn.alt-btn svg { stroke: var(--text); }
.composer-bar { display: flex; justify-content: center; align-items: center; gap: 12px; padding: 14px; border-radius: 18px; background: var(--panel); border: 1px solid var(--border); color: var(--text-2); font-weight: 600; flex-wrap: wrap; text-align: center; }

.compose-ctx {
  display: flex; align-items: center; gap: 12px; margin-bottom: 8px; padding: 6px 6px 6px 14px;
  border-radius: 16px; background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--violet);
  animation: pop .2s var(--ease) both; transform-origin: bottom;
}
.compose-ctx > svg { color: var(--accent-text); }
.compose-ctx div { flex: 1; min-width: 0; display: grid; }
.compose-ctx b { font-size: 13px; color: var(--accent-text); }
.compose-ctx span { font-size: 14px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.scroll-down {
  position: absolute; right: 6%; bottom: 96px; z-index: 15; width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center; background: var(--panel); border: 1px solid var(--border-strong);
  color: var(--text); box-shadow: 0 10px 30px -10px rgba(0,0,0,.5); backdrop-filter: blur(20px);
  animation: pop .2s var(--ease) both;
}
.scroll-down .badge { position: absolute; top: -8px; right: -4px; }

/* Эмодзи-панель */
.emoji-panel {
  position: absolute; right: 6%; bottom: calc(100% - 6px); z-index: 25; width: min(380px, calc(100vw - 24px)); height: 380px;
  display: flex; flex-direction: column; border-radius: 20px; overflow: hidden;
  background: var(--menu-bg); border: 1px solid var(--border-strong); box-shadow: 0 20px 60px -10px rgba(0,0,0,.5);
  backdrop-filter: blur(20px); animation: pop .2s var(--ease) both; transform-origin: bottom right;
}
.ep-tabs { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--border); }
.ep-tabs button { flex: 1; padding: 8px; border-radius: 10px; font-weight: 700; font-size: 14px; color: var(--text-2); }
.ep-tabs button.on { background: var(--surface-2); color: var(--text); }
.ep-body { flex: 1; overflow-y: auto; padding: 4px 10px 10px; }
.ep-cat > span { display: block; padding: 10px 4px 4px; font-size: 12px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; }
.ep-grid { display: grid; grid-template-columns: repeat(8, 1fr); }
.ep-grid button { aspect-ratio: 1; font-size: 24px; border-radius: 10px; transition: transform .15s var(--ease), background .15s; }
.ep-grid button:hover { background: var(--surface-2); transform: scale(1.15); }
.ep-grid.stickers { grid-template-columns: repeat(4, 1fr); gap: 4px; }
.ep-grid.stickers button { font-size: 48px; }
.ep-nav { display: flex; justify-content: space-around; padding: 6px; border-top: 1px solid var(--border); }
.ep-nav button { font-size: 18px; padding: 4px 6px; border-radius: 8px; opacity: .7; }
.ep-nav button:hover { opacity: 1; background: var(--surface-2); }

/* Лоток вложений */
.attach-tray {
  display: flex; gap: 8px; overflow-x: auto; padding: 10px; margin-bottom: 8px;
  border-radius: 18px; background: var(--panel); border: 1px solid var(--border); backdrop-filter: blur(20px);
  animation: pop .25s var(--ease) both; transform-origin: bottom;
}
.tray-item { position: relative; flex-shrink: 0; display: flex; align-items: center; gap: 10px; padding: 4px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); animation: pop .25s var(--ease) both; }
.tray-item.error { border-color: rgba(255,92,122,.5); }
.tray-thumb { position: relative; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; flex-shrink: 0; display: grid; place-items: center; background: var(--grad-soft); }
.tray-thumb img, .tray-thumb video { width: 100%; height: 100%; object-fit: cover; }
.tray-ext { font: 800 13px var(--font); color: var(--accent-text); }
.tray-item.uploading .tray-thumb img, .tray-item.uploading .tray-thumb video { filter: brightness(.55); }
.tray-progress { position: absolute; left: 8px; right: 8px; bottom: 8px; height: 4px; border-radius: 4px; background: rgba(255,255,255,.25); overflow: hidden; }
.tray-progress i { display: block; height: 100%; background: var(--grad); border-radius: inherit; transition: width .2s; }
.tray-retry { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255,92,122,.35); color: #fff; }
.tray-lock { position: absolute; left: 4px; top: 4px; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; background: rgba(0,0,0,.5); color: var(--green); }
.tray-lock svg { width: 11px; height: 11px; }
.tray-meta { display: grid; max-width: 160px; padding-right: 22px; }
.tray-meta b { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tray-meta small { font-size: 12px; color: var(--text-2); }
.tray-remove { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-solid); border: 1px solid var(--border-strong); color: var(--text); transition: background .2s, transform .2s; }
.tray-remove:hover { background: var(--danger); color: #fff; transform: scale(1.1); }
.tray-remove svg { width: 12px; height: 12px; stroke-width: 3; }

/* Запись голоса */
.recorder {
  display: flex; align-items: center; gap: 12px; padding: 6px 6px 6px 8px;
  border-radius: 22px; background: var(--panel); border: 1px solid rgba(255,92,122,.45);
  box-shadow: 0 0 0 4px rgba(255,92,122,.1); backdrop-filter: blur(20px); animation: pop .25s var(--ease) both;
}
.rec-cancel:hover { color: var(--danger); background: rgba(255,92,122,.12); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 12px var(--danger); animation: recBlink 1s ease-in-out infinite; flex-shrink: 0; }
@keyframes recBlink { 50% { opacity: .25; } }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 44px; }
.rec-wave { flex: 1; min-width: 0; height: 32px; display: flex; align-items: center; justify-content: flex-end; gap: 2px; overflow: hidden; }
.rec-wave i { width: 3px; flex-shrink: 0; border-radius: 3px; background: linear-gradient(var(--pink), var(--blue)); transition: height .06s linear; }
.recorder.circle-mode .rec-wave::before { content: "Запись видеосообщения…"; color: var(--text-2); font-weight: 600; font-size: 14px; margin-right: auto; }

.drop-zone {
  position: absolute; inset: 12px; z-index: 40; display: grid; place-items: center; text-align: center;
  border-radius: 24px; border: 2px dashed color-mix(in srgb, var(--violet) 70%, transparent);
  background: var(--panel); backdrop-filter: blur(8px); animation: fade .15s both; pointer-events: none;
}
.drop-zone div { display: grid; justify-items: center; gap: 6px; }
.drop-zone svg { width: 44px; height: 44px; color: var(--accent-text); margin-bottom: 6px; }
.drop-zone strong { font: 700 20px var(--display); }
.drop-zone span { color: var(--text-2); }

/* ================= ПРАВАЯ ПАНЕЛЬ ================= */
.panel { width: 0; overflow: hidden; background: var(--panel); border-left: 1px solid var(--border); backdrop-filter: blur(20px); transition: width .35s var(--ease); }
.panel.open { width: 380px; }
.panel-inner { width: 380px; height: 100%; display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; min-height: 66px; border-bottom: 1px solid var(--border); }
.panel-head strong { flex: 1; font-size: 16px; }
.panel-tabs { display: flex; gap: 2px; padding: 8px 10px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.panel-tabs button { flex: 1 0 auto; padding: 7px 10px; border-radius: 10px; font-size: 13px; font-weight: 700; color: var(--text-2); }
.panel-tabs button.on { background: var(--grad-soft); color: var(--text); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--violet) 35%, transparent); }
.panel-body { flex: 1; overflow-y: auto; padding: 20px 16px; }
.profile-top { text-align: center; margin-bottom: 18px; }
.profile-top .avatar { margin: 0 auto 14px; }
.profile-top h3 { font-size: 20px; font-weight: 800; }
.profile-top p { color: var(--text-2); font-size: 14px; }
.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.quick-actions button { display: grid; justify-items: center; gap: 4px; padding: 10px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); color: var(--accent-text); font-size: 12px; font-weight: 700; transition: background .2s; }
.quick-actions button:hover { background: var(--surface-2); }
.info-list { display: grid; gap: 2px; margin-bottom: 16px; padding: 6px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); }
.info-row { display: flex; gap: 14px; align-items: flex-start; padding: 10px; }
.info-row > svg { color: var(--text-2); margin-top: 2px; }
.info-row > div { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.info-row span { display: block; font-size: 12px; color: var(--text-3); }
.toggle-line { align-items: center; cursor: pointer; }
.toggle-line .switch { flex-shrink: 0; }
.select-row select { width: 100%; padding: 0; background: transparent; border: 0; outline: 0; font-weight: 600; cursor: pointer; }
.select-row select option { background: var(--modal-bg); }
.panel-actions { display: grid; gap: 8px; margin-bottom: 20px; }
.members-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 4px 8px; font-size: 13px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; }
.e2ee-box { margin-bottom: 16px; padding: 14px; border-radius: 16px; background: color-mix(in srgb, var(--green) 7%, transparent); border: 1px solid color-mix(in srgb, var(--green) 25%, transparent); display: grid; gap: 6px; }
.e2ee-title { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--green); }
.e2ee-title svg { width: 18px; height: 18px; }
.e2ee-box p { font-size: 13px; color: var(--text-2); }
.e2ee-box > span { font-size: 12px; font-weight: 700; color: var(--text-3); margin-top: 4px; }
.e2ee-box em { font-size: 13px; color: var(--text-2); }
.e2ee-box code, .fp { display: block; font-size: 13px; letter-spacing: .06em; padding: 6px 10px; border-radius: 8px; background: var(--surface-2); }
.gallery-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.gallery-item { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.gallery-item img, .gallery-item video { width: 100%; height: 100%; object-fit: cover; }
.gallery-item.round { border-radius: 50%; }
.gallery-item .media-play { width: 34px; height: 34px; }
.gallery-row { padding: 8px 6px; border-bottom: 1px solid var(--border); }
.gallery-row small { font-size: 12px; color: var(--text-3); }

.user-row { width: 100%; display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 14px; text-align: left; transition: background .2s; }
.user-row:hover { background: var(--surface-2); }
.user-row .ur-body { flex: 1; min-width: 0; }
.user-row strong { display: block; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-row span { font-size: 13px; color: var(--text-2); }
.user-row .check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border-strong); display: grid; place-items: center; transition: background .2s, border-color .2s; }
.user-row .check svg { width: 14px; height: 14px; stroke-width: 3.5; color: #fff; opacity: 0; transition: opacity .2s; }
.user-row.selected .check { background: var(--grad); border-color: transparent; }
.user-row.selected .check svg { opacity: 1; }
.user-row .remove { opacity: 0; }
.user-row:hover .remove { opacity: 1; }

/* ================= МОДАЛКИ ================= */
.modal-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: var(--overlay); backdrop-filter: blur(6px); animation: fade .2s both; }
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(460px, 100%); max-height: min(760px, 100%); display: flex; flex-direction: column;
  border-radius: 24px; background: var(--modal-bg); border: 1px solid var(--border-strong);
  box-shadow: 0 40px 120px -20px rgba(0,0,0,.6); animation: modalIn .35s var(--ease) both;
}
.modal.wide { width: min(620px, 100%); }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(.96); } }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 16px 16px 8px 24px; }
.modal-head h2 { flex: 1; min-width: 0; font: 700 19px var(--display); letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-form { display: contents; }
.modal-body { padding: 10px 24px 8px; overflow-y: auto; display: grid; gap: 14px; }
.modal-foot { display: flex; gap: 10px; padding: 14px 24px 22px; }
.modal-foot .btn { flex: 1; }

.set-section { display: grid; gap: 10px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.set-section:last-child { border-bottom: 0; }
.set-section h3 { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.set-section h3 svg { color: var(--accent-text); }
.sub-head { font-size: 13px; font-weight: 700; color: var(--text-2); margin-top: 4px; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.seg button { flex: 1; padding: 9px; border-radius: 10px; font-weight: 700; font-size: 14px; color: var(--text-2); }
.seg button.on { background: var(--grad); color: #fff; }
.accents { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.accents button { display: grid; justify-items: center; gap: 6px; padding: 10px 4px; border-radius: 14px; font-size: 12px; font-weight: 600; color: var(--text-2); border: 1px solid transparent; }
.accents button i { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--a1), var(--a2), var(--a3)); box-shadow: 0 6px 16px -6px var(--a2); }
.accents button.on { border-color: var(--border-strong); background: var(--surface); color: var(--text); }
.session-row { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.session-row > svg { color: var(--accent-text); }
.session-row .ur-body { flex: 1; min-width: 0; display: grid; }
.session-row span { font-size: 13px; color: var(--text-2); }

.avatar-upload { position: relative; cursor: pointer; border-radius: 50%; }
.avatar-upload .overlay { position: absolute; inset: 0; border-radius: inherit; display: grid; place-items: center; background: rgba(0,0,0,.45); opacity: 0; transition: opacity .2s; }
.avatar-upload:hover .overlay { opacity: 1; }
.avatar-upload .overlay svg { width: 28px; height: 28px; color: #fff; }
.avatar-edit { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.link-btn { font-size: 13px; font-weight: 600; color: var(--text-2); }
.link-btn:hover { color: var(--text); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); cursor: pointer; }
.toggle-row div span { display: block; font-size: 13px; color: var(--text-2); }
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; inset: 0; cursor: pointer; z-index: 1; margin: 0; }
.switch input:disabled { cursor: not-allowed; }
.switch i { position: absolute; inset: 0; border-radius: 13px; background: var(--surface-3); transition: background .2s; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .25s var(--ease); }
.switch input:checked + i { background: var(--grad); }
.switch input:checked + i::after { transform: translateX(20px); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 4px; border-radius: 999px; background: var(--grad-soft); border: 1px solid color-mix(in srgb, var(--violet) 35%, transparent); font-size: 13px; font-weight: 600; animation: pop .2s var(--ease) both; }
.chip button { display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; color: var(--text-2); }
.chip button:hover { background: var(--surface-3); color: var(--text); }
.chip button svg { width: 12px; height: 12px; stroke-width: 3; }
.picker-list { display: grid; gap: 2px; max-height: 320px; overflow-y: auto; margin: 0 -8px; }
.picker-hint { padding: 26px 10px; text-align: center; color: var(--text-3); font-size: 14px; }

/* ================= ПРОСМОТР ФОТО ================= */
.viewer { position: fixed; inset: 0; z-index: 150; display: grid; place-items: center; background: rgba(3,2,12,.94); backdrop-filter: blur(10px); animation: fade .2s both; color: #fff; }
.viewer-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px; padding: 14px 18px; background: linear-gradient(rgba(0,0,0,.5), transparent); }
.viewer-info { flex: 1; min-width: 0; display: grid; }
.viewer-info b { font-weight: 700; }
.viewer-info span { font-size: 13px; color: #a9a4c7; }
.viewer-count { font-size: 14px; font-weight: 600; color: #a9a4c7; margin-right: 8px; }
.viewer-top .icon-btn { color: #fff; }
.viewer-top .icon-btn:hover { background: rgba(255,255,255,.1); }
.viewer-img { max-width: calc(100vw - 160px); max-height: calc(100vh - 140px); object-fit: contain; border-radius: 12px; box-shadow: 0 30px 100px -20px rgba(0,0,0,.9); animation: viewerIn .3s var(--ease) both; }
@keyframes viewerIn { from { opacity: 0; transform: scale(.94); } }
.viewer-nav { position: absolute; top: 50%; translate: 0 -50%; width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; color: #fff; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16); transition: background .2s; }
.viewer-nav:hover { background: color-mix(in srgb, var(--violet) 50%, transparent); }
.viewer-nav.prev { left: 24px; }
.viewer-nav.next { right: 24px; }
.viewer-nav svg { width: 26px; height: 26px; }

/* ================= ЗВОНОК ================= */
.call-screen {
  position: fixed; inset: 0; z-index: 200; display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 60px 20px 40px; color: #fff; background: #07061a; overflow: hidden; animation: fade .25s both;
}
.call-bg { position: absolute; inset: -20%; z-index: 0; background: radial-gradient(circle at 30% 30%, color-mix(in srgb, var(--indigo) 70%, transparent), transparent 50%), radial-gradient(circle at 70% 70%, color-mix(in srgb, var(--pink) 55%, transparent), transparent 50%); filter: blur(60px); animation: callBg 12s ease-in-out infinite alternate; }
@keyframes callBg { to { transform: rotate(25deg) scale(1.15); } }
.call-remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; opacity: 0; transition: opacity .4s; background: #000; }
.call-screen.has-remote-video .call-remote { opacity: 1; }
.call-screen.has-remote-video .call-bg { display: none; }
.call-peer { position: relative; z-index: 2; display: grid; justify-items: center; gap: 8px; text-align: center; transition: opacity .3s, transform .3s; }
.call-screen.has-remote-video .call-peer { transform: scale(.7) translateY(-30px); opacity: .9; }
.call-screen.has-remote-video .call-avatar { display: none; }
.call-avatar { position: relative; margin-bottom: 10px; }
.call-screen.ringing .call-avatar::before, .call-screen.ringing .call-avatar::after {
  content: ""; position: absolute; inset: -10px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35); animation: ring 2s ease-out infinite;
}
.call-screen.ringing .call-avatar::after { animation-delay: 1s; }
@keyframes ring { from { transform: scale(.9); opacity: 1; } to { transform: scale(1.5); opacity: 0; } }
.call-peer h2 { font: 700 26px var(--display); text-shadow: 0 2px 12px rgba(0,0,0,.4); }
.call-peer p { font-size: 16px; color: rgba(255,255,255,.8); font-variant-numeric: tabular-nums; }
.call-e2ee { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; color: rgba(255,255,255,.65); }
.call-e2ee svg { width: 13px; height: 13px; }
.call-local {
  position: absolute; right: 20px; top: 20px; z-index: 3; width: 180px; aspect-ratio: 3/4; object-fit: cover; border-radius: 18px;
  background: #000; box-shadow: 0 20px 50px -10px rgba(0,0,0,.7); transform: scaleX(-1); display: none; border: 2px solid rgba(255,255,255,.2);
}
.call-screen.has-local-video .call-local { display: block; }
.call-controls { position: relative; z-index: 3; display: flex; gap: 22px; }
.call-btn { display: grid; justify-items: center; gap: 8px; color: #fff; font-size: 12px; font-weight: 600; }
.call-btn svg { box-sizing: content-box; width: 26px; height: 26px; padding: 19px; border-radius: 50%; background: rgba(255,255,255,.16); backdrop-filter: blur(10px); transition: transform .2s var(--ease), background .2s; }
.call-btn:hover svg { transform: scale(1.06); background: rgba(255,255,255,.26); }
.call-btn.off svg { background: #fff; color: #1a1630; }
.call-btn.danger svg { background: #ff3b5c; }
.call-btn.accept svg { background: #22c55e; animation: acceptPulse 1.4s ease-in-out infinite; }
@keyframes acceptPulse { 50% { box-shadow: 0 0 0 12px rgba(34,197,94,0); } 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.6); } }

/* ================= ТОСТЫ ================= */
.toasts { position: fixed; left: 50%; bottom: 24px; translate: -50% 0; z-index: 300; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { max-width: min(480px, calc(100vw - 32px)); padding: 12px 18px; border-radius: 14px; font-weight: 600; font-size: 14px; text-align: center; background: var(--menu-bg); color: var(--text); border: 1px solid var(--border-strong); box-shadow: 0 20px 50px -10px rgba(0,0,0,.5); animation: toastIn .3s var(--ease) both; }
.toast.err { border-color: rgba(255,92,122,.4); color: var(--danger); }
.toast.out { animation: toastOut .3s var(--ease) both; }
body:has(.call-screen) .toasts { bottom: auto; top: 24px; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.96); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px); } }

/* ================= iPhone: вырез экрана и полоска «Домой» ================= */
.app, .auth { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.call-screen { padding-top: calc(60px + env(safe-area-inset-top)); padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
.call-local { top: calc(20px + env(safe-area-inset-top)); }
.viewer-top { padding-top: calc(14px + env(safe-area-inset-top)); }
.toasts { bottom: calc(24px + env(safe-area-inset-bottom)); }
.panel.open .panel-inner { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }

/* ================= АДАПТИВ ================= */
@media (max-width: 1100px) {
  .panel.open { position: fixed; right: 0; top: 0; bottom: 0; z-index: 50; box-shadow: -30px 0 80px -20px rgba(0,0,0,.6); background: var(--panel-solid); }
}
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .sidebar, .chat { grid-area: 1 / 1; min-width: 0; }
  .panel:not(.open) { display: none; }
  .chat { display: none; }
  .app.show-chat .chat { display: flex; animation: slideIn .3s var(--ease) both; }
  .app.show-chat .sidebar { display: none; }
  @keyframes slideIn { from { transform: translateX(30px); opacity: 0; } }
  .back-btn { display: grid; }
  .messages, .composer { padding-left: 8px; padding-right: 8px; }
  .scroll-down { right: 14px; }
  .emoji-panel { right: 8px; }
  .bubble { max-width: 86%; }
  .bubble.has-media { width: min(320px, 86%); }
  .panel.open, .panel-inner { width: 100%; }
  .auth-card { padding: 34px 22px 26px; }
  .chat-head { gap: 2px; padding: 8px 6px; }
  .chat-head .who { gap: 8px; }
  .circle-msg { width: 200px; height: 200px; }
  .sticker { font-size: 96px; }
  .viewer-img { max-width: 100vw; max-height: calc(100vh - 160px); border-radius: 0; }
  .viewer-nav { top: auto; bottom: 24px; translate: none; }
  .file-card { min-width: 0; }
  .call-local { width: 110px; right: 12px; top: 12px; }
  .call-controls { gap: 14px; }
  .accents { grid-template-columns: repeat(3, 1fr); }
  .composer-box { padding-left: 6px; gap: 2px; }
  .app.show-chat ~ .toasts, body:has(.app.show-chat) .toasts { bottom: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
