:root {
  --bg: #0b0f0d;
  --rail: #0d1210;
  --sidebar: #101614;
  --panel: #151c19;
  --panel-2: #1a221f;
  --line: rgba(255, 255, 255, .06);
  --line-2: rgba(255, 255, 255, .09);
  --bubble-in: #1c2421;
  --bubble-out: #1d4a33;
  --accent: #22c55e;
  --accent-d: #1fae5b;
  --accent-soft: rgba(var(--accent-rgb), .14);
  --accent-rgb: 34, 197, 94;
  --on-accent: #05210f;
  --accent-hi: #2fd36a;
  --accent-light: #4ade80;
  --accent-pale: #bbf7d0;
  --online: #22c55e;
  --accent-2: #22c55e;
  --text: #e9efec;
  --muted: #8a9690;
  --muted-2: #66726c;
  --danger: #ef4444;
  --input: #18201d;
  --hover: #161e1b;
  --selected: #1b2722;
  --radius: 14px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, Arial, sans-serif;
}
/* PHASE3: Inter (SIL OFL 1.1) — локальная копия, без внешних CDN; латиница + кириллица, вариативная насыщенность */
@font-face {
  font-family: "Inter";
  src: url("/static/fonts/inter-var.woff2?v=1") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
[hidden] { display: none !important; }
body {
  font: 14px/1.4 var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code {
  font-family: ui-monospace, Consolas, monospace;
  background: rgba(255,255,255,.06);
  padding: 1px 6px;
  border-radius: 6px;
}
svg { flex: none; }

/* ---------- auth ---------- */
.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(11,15,13,.55), rgba(11,15,13,.92)),
    url("/static/bg-mountains.svg") center bottom / cover no-repeat,
    var(--bg);
}
.auth-card {
  width: min(400px, 100%);
  background: rgba(16, 22, 20, .92);
  border: 1px solid var(--line-2);
  border-radius: 18px;
  padding: 28px 26px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .55);
  backdrop-filter: blur(8px);
}
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 22px; }
.brand h1 { margin: 0; font-size: 24px; font-weight: 700; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.logo {
  width: 52px; height: 52px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--accent);
  color: var(--on-accent);
}
.logo.lg { width: 76px; height: 76px; margin: 0 auto 16px; border-radius: 22px; background: var(--accent-soft); color: var(--accent); }
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--input);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 16px;
}
.tabs button {
  border: 0; background: transparent; color: var(--muted);
  padding: 8px; border-radius: 9px; font-weight: 600;
}
.tabs button.on { background: var(--accent-soft); color: var(--accent); }
#auth-form { display: grid; gap: 12px; }
#auth-form label { display: grid; gap: 6px; }
#auth-form span, .field span { font-size: 12.5px; color: var(--muted); font-weight: 500; }
#auth-form input, .field input {
  background: var(--input);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
#auth-form input:focus, .field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#auth-go {
  margin-top: 8px;
  border: 0;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  padding: 12px;
  border-radius: 12px;
}
#auth-go:hover { background: var(--accent-hi); }
#auth-go:disabled { opacity: .6; cursor: default; }
.err { color: var(--danger); margin: 0; font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 16px 0 0; }
.hint.tight { margin: 4px 0 12px; }

/* ---------- shell layout ---------- */
.shell {
  height: 100dvh;
  display: grid;
  grid-template-columns: 220px 340px minmax(0, 1fr) auto;
  background: var(--bg);
  gap: 0;
}

/* rail */
.rail {
  background: var(--rail);
  display: flex;
  flex-direction: column;
  padding: 14px 10px 16px;
  min-width: 0;
  border-right: 1px solid var(--line);
}
.rail-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 2px 6px 18px;
  white-space: nowrap;
}
.brand-logo {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent);
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: .1px; }
.brand-name b { color: var(--accent); font-weight: 700; }
.rail-items { display: grid; gap: 4px; }
.rail-item {
  display: flex; align-items: center; gap: 14px;
  border: 0; background: transparent; color: #c9d3ce;
  padding: 11px 12px; border-radius: 12px;
  text-align: left; font-weight: 500; position: relative;
}
.rail-item svg { color: #aeb9b3; }
.rail-item:hover { background: var(--hover); }
.rail-item.on { background: var(--selected); color: #fff; }
.rail-item.on svg { color: var(--accent); }
.rail-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-badge {
  margin-left: auto;
  min-width: 22px; height: 20px; padding: 0 7px;
  border-radius: 999px; background: var(--accent); color: var(--on-accent);
  font-size: 11.5px; font-weight: 700; display: grid; place-items: center;
}
.rail-storage { margin-top: auto; padding: 0 8px; display: grid; gap: 8px; font-size: 12px; color: var(--muted); }
.rail-storage small { font-size: 12px; color: #b9c4be; }
.meter { height: 6px; border-radius: 99px; background: #1f2925; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }

/* chat list column */
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}
.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}
.side-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 12px 10px;
}
.icon-btn {
  width: 38px; height: 38px;
  border: 0; background: transparent;
  color: #b4bfb9;
  border-radius: 10px;
  display: grid; place-items: center;
  flex: none;
}
.icon-btn:hover { background: rgba(255,255,255,.06); color: var(--text); }
.icon-btn.light { color: #fff; }
.icon-btn.accent { color: var(--accent); }
.search-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}
.search-ico {
  position: absolute;
  left: 12px;
  color: var(--muted);
  pointer-events: none;
}
#search {
  width: 100%;
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px 9px 38px;
  outline: none;
  font-size: 13.5px;
}
#search:focus { border-color: rgba(var(--accent-rgb),.5); }
#search::placeholder, #input::placeholder { color: var(--muted-2); }
.list-tabs {
  display: flex; gap: 4px;
  padding: 0 12px 8px;
  border-bottom: 1px solid var(--line);
}
.list-tabs button {
  border: 0; background: transparent; color: var(--muted);
  padding: 6px 10px; border-radius: 9px; font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 6px;
}
.list-tabs button:hover { color: var(--text); }
.list-tabs button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tab-count {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px;
  background: var(--accent); color: var(--on-accent); font-size: 11px; font-weight: 700;
  display: inline-grid; place-items: center;
}
.people, .chats { overflow: auto; }
.people { border-bottom: 1px solid var(--line); padding: 4px 0; }
.people::before { content: "Глобальный поиск"; display: block; font-size: 11.5px; color: var(--muted); padding: 6px 14px 2px; text-transform: uppercase; letter-spacing: .5px; }
.chats { flex: 1; padding: 4px 0; }
.row {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 9px 14px;
  color: inherit;
  position: relative;
}
.row:hover { background: var(--hover); }
.row.on { background: var(--selected); }
.row.on::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.row.on .av.online::after { border-color: var(--selected); }
.row .meta { min-width: 0; flex: 1; display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; }
.row .top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.row strong { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .preview, .row .sub { min-width: 0; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .preview.typing { color: var(--accent); }
.row time { color: var(--muted); font-size: 11.5px; flex: none; }
.row .unread-time { color: var(--accent); }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--accent); color: var(--on-accent);
  font-size: 11.5px; font-weight: 700; display: grid; place-items: center; flex: none;
}
.row .chk { color: var(--muted); display: inline-flex; flex: none; }
.row .chk.read { color: var(--accent); }
.list-empty { padding: 32px 22px; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.5; }
.list-empty svg { color: var(--muted-2); margin-bottom: 8px; }
.archive-row {
  display: flex; align-items: center; gap: 12px;
  border: 0; border-top: 1px solid var(--line); background: transparent;
  padding: 10px 14px; text-align: left; color: var(--text);
}
.archive-row:hover { background: var(--hover); }
.archive-row .meta { flex: 1; display: grid; }
.archive-row small { color: var(--muted); font-size: 12px; }
.archive-row > svg { color: var(--muted); }
.archive-ico { width: 46px; height: 46px; border-radius: 50%; background: var(--panel-2); display: grid; place-items: center; color: #b9c4be; }

.av {
  --h: 150;
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 600; color: #fff; flex: none;
  background: linear-gradient(150deg, hsl(var(--h), 38%, 42%), hsl(var(--h), 40%, 24%));
  position: relative;
  font-size: 16px;
}
.av img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 50%; }
.av.sm { width: 40px; height: 40px; font-size: 14px; }
.av.tiny { width: 46px; height: 46px; font-size: 16px; }
.av.xl { width: 76px; height: 76px; font-size: 26px; margin: 8px 0 10px; }
.av.huge { width: 120px; height: 120px; font-size: 42px; cursor: pointer; }
.av.online::after {
  content: "";
  position: absolute; right: 0; bottom: 1px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--online);
  border: 2px solid var(--sidebar);
  z-index: 1;
}

/* settings / edit panes */
.menu-hero {
  padding: 12px 18px 22px;
  background: radial-gradient(400px 160px at 30% 0%, rgba(var(--accent-rgb),.18), transparent 70%), var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  position: relative;
}
.menu-title { position: absolute; left: 60px; top: 21px; font-weight: 600; font-size: 15px; }
.menu-hero strong { font-size: 18px; }
.menu-hero span { color: var(--muted); font-size: 13.5px; }
.menu-list { padding: 8px; }
.menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  border: 0;
  background: transparent;
  padding: 12px 12px;
  border-radius: 12px;
  text-align: left;
  color: var(--text);
}
.menu-item:hover { background: var(--hover); }
.menu-item .mi { color: var(--muted); display: grid; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger .mi { color: var(--danger); }
.edit-head {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 60px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.edit-head strong { flex: 1; font-size: 15px; }
.edit-body { padding: 28px 20px 20px; overflow: auto; }
.edit-av-wrap { width: 120px; height: 120px; margin: 0 auto 28px; position: relative; }
.cam {
  position: absolute;
  right: 2px; bottom: 2px;
  width: 40px; height: 40px;
  border: 0; border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  display: grid; place-items: center;
  box-shadow: 0 2px 10px rgba(0,0,0,.45);
}
.cam:hover { filter: brightness(1.08); }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.at {
  display: flex;
  align-items: center;
  background: var(--input);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding-left: 12px;
}
.at em { color: var(--muted); font-style: normal; }
.at input { flex: 1; background: transparent !important; outline: none; border: 0 !important; box-shadow: none !important; padding: 10px 12px 10px 2px !important; }
.at:focus-within { border-color: var(--accent); }
.text-btn { border: 0; background: transparent; color: var(--danger); padding: 8px 0; }

/* ---------- stage / thread ---------- */
.stage { position: relative; min-width: 0; display: grid; background: var(--bg); }
.empty {
  place-self: center;
  text-align: center;
  color: var(--muted);
  padding: 24px;
}
.empty h2 { color: var(--text); margin: 0 0 6px; font-weight: 600; font-size: 20px; }
.empty p { margin: 0; font-size: 14.5px; }
.empty-hint { display: inline-block; margin-top: 14px; padding: 6px 12px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); font-size: 12.5px; }
.stage:has(.empty:not([hidden])) {
  background:
    linear-gradient(180deg, rgba(11,15,13,.7), rgba(11,15,13,.86)),
    url("/static/bg-mountains.svg") center bottom / cover no-repeat;
}

.thread {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  height: 100dvh;
  min-height: 0;
  background:
    linear-gradient(180deg, rgba(11,15,13,.55) 0%, rgba(11,15,13,.25) 40%, rgba(11,15,13,.55) 100%),
    url("/static/bg-mountains.svg") center bottom / cover no-repeat,
    #0b0f0d;
}
.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px 10px 16px;
  min-height: 64px;
  background: rgba(13, 18, 16, .96);
  border-bottom: 1px solid var(--line);
}
.back { display: none; }
.peer-btn {
  display: flex; align-items: center; gap: 12px;
  border: 0; background: transparent; padding: 2px 6px 2px 0;
  min-width: 0; flex: 1; text-align: left; border-radius: 12px;
}
.peer { min-width: 0; display: grid; }
.peer strong { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peer span { color: var(--muted); font-size: 12.5px; }
.peer span.on, .pstatus.on { color: var(--accent); }
.head-actions { display: flex; gap: 4px; }
.head-actions .icon-btn.on { color: var(--accent); background: var(--accent-soft); }

.e2e {
  display: flex; align-items: center; gap: 12px;
  margin: 12px 16px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(20, 46, 32, .78);
  border: 1px solid rgba(var(--accent-rgb), .22);
  backdrop-filter: blur(6px);
}
.e2e-ico { color: var(--accent); display: grid; }
.e2e-text { flex: 1; min-width: 0; display: grid; gap: 1px; }
.e2e-text strong { font-size: 12.5px; font-weight: 600; color: #d6f5e2; }
.e2e-text span { font-size: 12px; color: #9fb8aa; }
.e2e-text b { font-weight: 600; color: #cfe6d9; }
.e2e-more {
  border: 1px solid var(--line-2); background: rgba(255,255,255,.05); color: var(--text);
  padding: 7px 12px; border-radius: 10px; font-size: 12.5px; font-weight: 500; flex: none;
}
.e2e-more:hover { background: rgba(255,255,255,.1); }

.log {
  overflow-y: auto;
  padding: 10px 6% 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}
.day {
  align-self: center;
  font-size: 12px;
  color: #c3cdc8;
  background: rgba(22, 30, 27, .9);
  border: 1px solid var(--line);
  padding: 4px 12px;
  border-radius: 10px;
  margin: 10px 0 6px;
}
.msg { display: flex; max-width: min(68%, 520px); }
.msg.me { align-self: flex-end; }
.bubble {
  padding: 8px 12px 6px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  font-size: 14px;
  line-height: 1.45;
}
.msg.me .bubble {
  background: rgba(29, 74, 51, .96);
  border: 1px solid rgba(var(--accent-rgb),.12);
  border-bottom-right-radius: 6px;
}
.msg.them .bubble {
  background: rgba(28, 36, 33, .96);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.foot {
  display: flex; justify-content: flex-end; align-items: center; gap: 4px;
  font-size: 11px; color: rgba(233,239,236,.5); margin-top: 2px;
  float: right;
  margin-left: 12px;
  position: relative;
  top: 5px;
}
.ticks { display: inline-flex; color: rgba(233,239,236,.55); }
.ticks.read { color: var(--accent); }
.ticks svg { display: block; }
.bubble.media { padding: 4px 4px 6px; overflow: hidden; }
.bubble.media img.photo {
  display: block;
  max-width: min(300px, 70vw);
  max-height: 360px;
  width: auto;
  height: auto;
  border-radius: 10px;
  cursor: zoom-in;
}
.bubble.media img.photo + .foot {
  position: absolute; right: 12px; bottom: 10px; top: auto; float: none;
  background: rgba(0,0,0,.5); color: #fff; padding: 1px 7px; border-radius: 8px; margin: 0;
}
.bubble.media img.photo + .foot .ticks { color: #fff; }
.bubble.media img.photo + .foot .ticks.read { color: var(--accent-light); }
.msg .bubble.media { position: relative; }
.caption { padding: 6px 8px 0; white-space: pre-wrap; word-break: break-word; }
.file-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 230px;
  max-width: 300px;
  padding: 8px 10px 4px 8px;
  color: inherit;
  text-decoration: none;
}
.file-ico {
  width: 42px; height: 42px; border-radius: 10px;
  background: rgba(255,255,255,.1);
  color: #cfe6d9;
  display: grid; place-items: center; flex: none;
}
.msg.me .file-ico { background: rgba(var(--accent-rgb),.18); color: var(--accent-pale); }
.file-name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: 12px; opacity: .65; }
.bubble.media > .foot { margin-right: 8px; }
.voice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 230px;
  max-width: 300px;
  padding: 6px 8px 2px 6px;
}
.voice-play {
  width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; flex: none;
}
.voice-play:hover { background: var(--accent-hi); }
.voice-play svg[hidden] { display: none !important; }
.voice-body { flex: 1; min-width: 0; }
.wave { display: flex; align-items: center; gap: 2px; height: 24px; }
.wave i { display: block; width: 3px; border-radius: 2px; background: rgba(255,255,255,.3); height: 8px; }
.wave i.on { background: var(--accent-light); }
.voice-time { font-size: 11.5px; opacity: .7; margin-top: 2px; }

/* composer */
.rec-bar {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 0 10px;
  min-height: 44px;
  background: var(--input);
  border: 1px solid var(--line-2);
  border-radius: 14px;
}
.rec-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--danger);
  animation: recpulse 1s ease-in-out infinite;
  flex: none;
}
@keyframes recpulse { 50% { opacity: .35; } }
#rec-time { font-variant-numeric: tabular-nums; min-width: 40px; color: var(--text); }
.rec-live {
  flex: 1; height: 22px;
  background: repeating-linear-gradient(90deg, var(--accent) 0 2px, transparent 2px 6px);
  opacity: .6;
  border-radius: 4px;
  animation: recwave .7s linear infinite;
  background-size: 12px 100%;
}
@keyframes recwave { to { background-position: 12px 0; } }
#mic {
  width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: transparent; color: #c3cdc8; display: grid; place-items: center; flex: none;
}
#mic { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none; }
#mic:hover { background: rgba(255,255,255,.06); color: var(--accent); }
#rec-cancel { color: var(--danger); }

.dock { position: relative; background: rgba(13, 18, 16, .96); border-top: 1px solid var(--line); }
.sheet {
  position: absolute;
  left: 12px; bottom: 66px;
  width: 220px;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  padding: 6px;
  box-shadow: 0 14px 34px rgba(0,0,0,.5);
  z-index: 5;
  display: grid;
  gap: 2px;
}
.sheet button {
  display: flex; align-items: center; gap: 12px;
  border: 0; background: transparent; color: var(--text);
  padding: 8px; border-radius: 10px; text-align: left;
}
.sheet button:hover { background: var(--hover); }
.sheet-ico {
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center; color: #fff; flex: none;
}
.sheet-ico.photo { background: #1fae5b; }
.sheet-ico.file { background: #2d6a4f; }
.emoji-panel {
  height: 250px;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--line);
  background: var(--sidebar);
}
.emoji-tabs { display: flex; gap: 2px; padding: 6px 8px 0; overflow-x: auto; }
.emoji-tabs button {
  border: 0; background: transparent; color: var(--muted);
  padding: 6px 8px; border-radius: 8px; font-size: 18px; line-height: 1;
}
.emoji-tabs button.on { background: var(--accent-soft); }
.emoji-grid {
  flex: 1;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 2px;
  padding: 6px 8px 10px;
}
.emoji-grid button {
  border: 0; background: transparent;
  font-size: 22px; line-height: 1.2;
  border-radius: 8px; padding: 4px;
}
.emoji-grid button:hover { background: var(--hover); }
.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 14px 12px;
}
.composer > .icon-btn#attach-btn {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--input); border: 1px solid var(--line-2);
}
.composer-field {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--input);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  min-width: 0;
  min-height: 44px;
}
.composer-field:focus-within { border-color: rgba(var(--accent-rgb),.45); }
#input {
  flex: 1;
  resize: none;
  max-height: 140px;
  background: transparent;
  border: 0;
  padding: 11px 6px 11px 14px;
  outline: none;
  line-height: 1.35;
  font-size: 14px;
}
.composer-field .icon-btn { margin: 3px; }
.composer .icon-btn { color: #aeb9b3; }
.composer .icon-btn:hover, #emoji-btn.on { color: var(--accent); }
#send {
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); display: grid; place-items: center; flex: none;
  box-shadow: 0 4px 14px rgba(var(--accent-rgb),.3);
}
#send svg { transform: translateX(1px); }
#send:hover { background: var(--accent-hi); }
#send:disabled { opacity: .45; }

/* ---------- profile panel ---------- */
.profile {
  width: 320px;
  background: var(--sidebar);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0; height: 100dvh;
}
.profile-top { display: flex; justify-content: space-between; padding: 10px 10px 0; }
.profile-scroll { overflow-y: auto; padding: 0 14px 18px; display: grid; gap: 12px; align-content: start; }
.profile-hero { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 0 0 4px; }
.av.profile-av { width: 112px; height: 112px; font-size: 38px; margin-bottom: 14px; box-shadow: 0 0 0 4px rgba(var(--accent-rgb),.12); }
.av.profile-av.online::after { width: 16px; height: 16px; right: 6px; bottom: 6px; border-width: 3px; }
.profile-hero strong { font-size: 18px; font-weight: 600; }
.pstatus { color: var(--muted); font-size: 12.5px; margin-top: 2px; display: inline-flex; align-items: center; gap: 6px; }
.pstatus.on::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.profile-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; width: 100%; margin-top: 18px; }
.profile-actions button {
  border: 0; background: transparent; color: #c3cdc8; font-size: 11.5px;
  display: grid; justify-items: center; gap: 6px; padding: 2px;
}
.profile-actions button span {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line-2);
  color: var(--text);
}
.profile-actions button:hover span { background: var(--accent-soft); color: var(--accent); }
.pcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.about { padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
.about h4 { margin: 0 0 4px; font-size: 13px; font-weight: 600; }
.about p { margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.prow {
  display: flex; align-items: center; gap: 12px; width: 100%;
  border: 0; background: transparent; color: var(--text);
  padding: 11px 14px; text-align: left; font-size: 13px; cursor: pointer;
}
.prow:hover { background: var(--hover); }
.prow > svg:first-child { color: #aeb9b3; }
.prow > span { flex: 1; min-width: 0; display: grid; }
.prow small { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.prow em { font-style: normal; color: var(--muted); font-size: 12.5px; }
.prow > svg:last-child:not(:first-child) { color: var(--muted-2); }
.soon-tag { display: inline-flex; align-items: center; gap: 4px; color: var(--accent) !important; }
.prow.enc > svg:first-child { color: var(--accent); }
.switch {
  appearance: none; -webkit-appearance: none; margin: 0;
  width: 38px; height: 22px; border-radius: 99px; background: #2a3430; position: relative; cursor: pointer; flex: none;
  transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #d9e2dd; transition: transform .15s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(16px); background: #fff; }
.pdanger {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid rgba(239,68,68,.18); background: rgba(239,68,68,.06); color: var(--danger);
  padding: 12px 14px; border-radius: var(--radius); font-size: 13px; font-weight: 500; text-align: left;
}
.pdanger:hover { background: rgba(239,68,68,.12); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #1b2622; color: var(--text); border: 1px solid rgba(var(--accent-rgb),.3);
  padding: 10px 16px; border-radius: 12px; box-shadow: 0 12px 30px rgba(0,0,0,.5);
  z-index: 60; font-size: 13px; max-width: calc(100vw - 32px);
  animation: toastin .18s ease-out;
}
.toast b { color: var(--accent); font-weight: 600; }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } }

.lightbox {
  position: fixed; inset: 0;
  background: rgba(3,6,5,.9);
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 48px 16px 56px;
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 10px; }
.lightbox #lightbox-close { position: absolute; top: 8px; right: 8px; font-size: 20px; color: #fff; }
.lightbox-dl {
  position: absolute; bottom: 16px; left: 50%;
  transform: translateX(-50%);
  color: var(--on-accent);
  text-decoration: none;
  background: var(--accent);
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 10px;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #26302c; border-radius: 99px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- responsive ---------- */
@media (max-width: 1440px) {
  .shell { grid-template-columns: 200px 320px minmax(0, 1fr) auto; }
  .profile { width: 300px; }
}
/* narrower: profile becomes overlay */
@media (max-width: 1280px) {
  .profile {
    position: fixed; right: 0; top: 0; bottom: 0; z-index: 30;
    box-shadow: -20px 0 50px rgba(0,0,0,.5);
  }
  .shell { grid-template-columns: 200px 320px minmax(0, 1fr); }
}
/* rail collapses to icons */
@media (max-width: 1100px) {
  .shell { grid-template-columns: 68px 300px minmax(0, 1fr); }
  .rail { padding: 14px 8px; align-items: center; }
  .rail-brand { padding: 2px 0 18px; }
  .brand-name, .rail-label, .rail-storage { display: none; }
  .rail-item { padding: 11px; justify-content: center; }
  .rail-badge { position: absolute; top: 2px; right: 0; min-width: 18px; height: 17px; padding: 0 5px; font-size: 10.5px; margin: 0; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .rail {
    grid-row: 2; flex-direction: row; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--line);
  }
  .rail-brand { display: none; }
  .rail-items { display: flex; justify-content: space-around; width: 100%; }
  .rail-item { padding: 10px; }
  .sidebar { grid-row: 1; border-right: 0; min-height: 0; }
  .stage { display: none; }
  .shell.chat-open .sidebar, .shell.chat-open .rail { display: none; }
  .shell.chat-open { grid-template-rows: 1fr; }
  .shell.chat-open .stage { display: grid; grid-row: 1; }
  .back { display: grid; }
  .msg { max-width: 86%; }
  .log { padding: 10px 10px 12px; }
  .head-actions .icon-btn:not(#profile-toggle) { display: none; }
  .e2e { margin: 8px 10px 0; }
  .e2e-text span { display: none; }
  .profile { width: 100%; border-left: 0; }
  .composer { padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); }
}
.prow > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.prow > span small { display: block; white-space: normal; }
.prow em { white-space: nowrap; }

.av.saved { background: var(--accent); color: var(--on-accent); }
.row strong { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.row .pin { color: var(--muted); display: inline-flex; transform: rotate(0deg); }
.row.pinned .pin { color: #9fb8aa; }

/* PIN/SAVED ============================================================ */
.av.saved svg { display: block; }
.pin-menu {
  position: fixed; z-index: 1000; min-width: 190px; padding: 6px 0;
  background: var(--panel, #151c19); color: var(--text, #e9efec);
  border: 1px solid var(--line, rgba(255,255,255,.06));
  border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
.pin-menu button {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 16px; border: 0; background: transparent; color: inherit;
  font: inherit; text-align: left; cursor: pointer;
}
.pin-menu button:hover:not(:disabled) { background: var(--hover, rgba(255,255,255,.06)); }
.pin-menu button:disabled { opacity: .6; cursor: default; }
.pin-menu svg { flex: none; color: var(--muted, #8a9690); }
.pin-btn.on { color: var(--accent, #22c55e); }
.row[data-cid] { -webkit-touch-callout: none; }
.saved-mode .ps-hide { display: none !important; }
.row[data-cid] { -webkit-user-select: none; user-select: none; }
/* на узких экранах кнопка закрепа остаётся видимой */
.head-actions #pin-btn:not([hidden]) { display: grid !important; }
/* /PIN/SAVED =========================================================== */

/* ADMIN/SUPPORT ======================================================== */
:root { --admin: #ef4444; --admin-soft: rgba(239, 68, 68, .12); }
.av.admin-av { background: linear-gradient(160deg, #f87171, #dc2626) !important; color: #fff; }
.av.admin-av svg { display: block; }
.row.admin-chat { background: var(--admin-soft); box-shadow: inset 3px 0 0 var(--admin); }
.row.admin-chat:hover { background: rgba(239, 68, 68, .18); }
.row.admin-chat.on { background: rgba(239, 68, 68, .24); }
.row.admin-chat strong { color: var(--admin); display: inline-flex; align-items: center; gap: 4px; }
.verified { color: var(--admin); flex: none; }
.thread.admin-mode #peer-name { color: var(--admin); }
.thread.admin-mode #peer-name::after {
  content: ""; display: inline-block; width: 14px; height: 14px; margin-left: 5px; vertical-align: -2px;
  background: var(--admin);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2 4 5v6.1c0 5 3.4 9.7 8 10.9 4.6-1.2 8-5.9 8-10.9V5z'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2 4 5v6.1c0 5 3.4 9.7 8 10.9 4.6-1.2 8-5.9 8-10.9V5z'/%3E%3C/svg%3E") center/contain no-repeat;
}
.thread.admin-mode .chat-head { box-shadow: inset 0 -2px 0 var(--admin); }
.profile.admin-mode #profile-name { color: var(--admin); }
.profile.admin-mode .pdanger { display: none !important; }
.admin-link { color: var(--admin) !important; text-decoration: none; }
/* /ADMIN/SUPPORT ======================================================= */

/* CLOUD ================================================================ */
button.rail-storage { border: 0; background: transparent; font: inherit; text-align: left; cursor: pointer; border-radius: 12px; padding: 10px 8px; color: var(--muted); }
button.rail-storage:hover { background: rgba(255,255,255,.04); }
button.rail-storage:hover small { color: var(--text); }
.meter i { transition: width .35s ease, background-color .2s; }
.meter.warn i { background: #eab308; }
.meter.full i { background: var(--danger); }

.files-view:not([hidden]) {
  grid-column: 2 / -1; grid-row: 1;
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--bg); position: relative; padding: 22px 28px 0;
}
.shell.files-open > .sidebar, .shell.files-open > .stage, .shell.files-open > .profile { display: none !important; }
.fv-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.fv-title { flex: 1 1 200px; min-width: 0; }
.fv-title h2 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.fv-title small { color: var(--muted); font-size: 12.5px; }
.fv-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fv-search { display: flex; align-items: center; gap: 8px; background: var(--input); border: 1px solid var(--line); border-radius: 11px; padding: 0 12px; height: 38px; color: var(--muted); }
.fv-search input { border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 13.5px; width: 190px; }
#fv-sort { height: 38px; background: var(--input); color: var(--text); border: 1px solid var(--line); border-radius: 11px; padding: 0 10px; font: inherit; font-size: 13px; }
.fv-view { display: flex; background: var(--input); border: 1px solid var(--line); border-radius: 11px; padding: 3px; }
.fv-view button { width: 32px; height: 30px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; }
.fv-view button.on { background: var(--selected); color: var(--accent); }
.fv-upload { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 16px; border: 0; border-radius: 11px; background: var(--accent); color: var(--on-accent); font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer; }
.fv-upload:hover { background: var(--accent-d); }
.fv-quota { margin: 16px 0 4px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 8px; }
.fv-quota .meter { height: 8px; }
.fv-quota-text { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 12.5px; color: #b9c4be; }
#fv-saved { color: var(--accent); }
.fv-quota.warn { border-color: rgba(234,179,8,.35); }
.fv-quota.full { border-color: rgba(239,68,68,.45); }
.fv-filters { display: flex; gap: 6px; padding: 12px 0; overflow-x: auto; scrollbar-width: none; }
.fv-filters button { flex: none; border: 1px solid var(--line); background: transparent; color: #b9c4be; border-radius: 99px; padding: 7px 14px; font: inherit; font-size: 13px; cursor: pointer; }
.fv-filters button:hover { background: var(--hover); }
.fv-filters button.on { background: var(--accent-soft); color: var(--accent); border-color: rgba(var(--accent-rgb),.35); }
.fv-uploads { display: grid; gap: 6px; }
.fv-uploads:empty { display: none; }
.fv-uploads { margin-bottom: 10px; max-height: 172px; overflow-y: auto; flex: none; }
.fv-up { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(80px, 1fr) auto auto; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 6px 6px 14px; font-size: 13px; }
.fv-up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fv-up-bar { height: 6px; border-radius: 99px; background: #1f2925; overflow: hidden; }
.fv-up-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.fv-up-st { color: var(--muted); font-size: 12px; white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.fv-up.err { border-color: rgba(239,68,68,.4); }
.fv-up.err .fv-up-bar i { background: var(--danger); }
.fv-up.err .fv-up-st { color: #fca5a5; white-space: normal; }
.fv-up.ok .fv-up-st { color: var(--accent); }
.fv-selbar:not([hidden]) { display: flex; align-items: center; gap: 10px; background: var(--selected); border: 1px solid rgba(var(--accent-rgb),.25); border-radius: 12px; padding: 8px 12px; margin-bottom: 10px; font-size: 13px; }
.fv-selbar span { flex: 1; }
.fv-selbar button { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 9px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.fv-selbar button.danger { color: #fff; background: var(--danger); border-color: transparent; }
.fv-body { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: 24px; }
.fv-body.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; align-content: start; }
.fv-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: border-color .15s, transform .15s; outline: none; }
.fv-card:hover, .fv-card:focus-visible { border-color: rgba(var(--accent-rgb),.4); }
.fv-card.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.fv-thumb { position: relative; aspect-ratio: 4 / 3; display: grid; place-items: center; background: #111816; overflow: hidden; }
.fv-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.fv-ext { position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.6); color: #e9efec; font-size: 10.5px; font-weight: 700; letter-spacing: .04em; padding: 2px 6px; border-radius: 6px; }
.fv-play { position: absolute; inset: 0; margin: auto; width: 40px; height: 40px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center; font-size: 15px; padding-left: 3px; }
.fv-check { position: absolute; left: 8px; top: 8px; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 7px; background: rgba(0,0,0,.55); opacity: 0; transition: opacity .15s; cursor: pointer; }
.fv-check input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; margin: 0; }
.fv-card:hover .fv-check, .fv-card.sel .fv-check, .fv-row .fv-check { opacity: 1; }
.fv-more { position: absolute; right: 8px; top: 8px; width: 28px; height: 28px; border: 0; border-radius: 8px; background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center; opacity: 0; cursor: pointer; }
.fv-card:hover .fv-more { opacity: 1; }
.fv-cap { padding: 10px 12px 12px; display: grid; gap: 3px; min-width: 0; }
.fv-cap b { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fv-cap small { font-size: 11.5px; color: var(--muted); }
.fv-ico { color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); border-radius: 12px; display: inline-grid; place-items: center; padding: 10px; flex: none; }
.fv-thumb .fv-ico { padding: 18px; border-radius: 18px; }
.fv-row .fv-ico { padding: 7px; border-radius: 9px; }
.fv-lhead, .fv-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) 150px 140px 84px; align-items: center; gap: 10px; padding: 0 10px; }
.fv-lhead { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.fv-row { min-height: 56px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.fv-row:hover { background: var(--hover); }
.fv-row.sel { background: var(--selected); }
.fv-row .fv-check { position: static; background: transparent; }
.fv-name { display: flex; align-items: center; gap: 12px; min-width: 0; }
.fv-name > span { display: grid; min-width: 0; }
.fv-name b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fv-name small { color: var(--muted); font-size: 11.5px; }
.fv-mini { width: 36px; height: 36px; object-fit: cover; border-radius: 9px; flex: none; }
.fv-size em { display: block; font-style: normal; color: var(--accent); font-size: 11.5px; }
.fv-date { color: var(--muted); }
.fv-acts { display: flex; justify-content: flex-end; }
.fv-empty { grid-column: 1 / -1; display: grid; justify-items: center; gap: 8px; text-align: center; padding: 70px 20px; color: var(--muted); }
.fv-empty b { color: var(--text); font-size: 16px; }
.fv-drop:not([hidden]) { position: absolute; inset: 10px; z-index: 5; display: grid; place-items: center; border: 2px dashed var(--accent); border-radius: 18px; background: rgba(11,15,13,.88); pointer-events: none; }
.fv-drop div { display: grid; justify-items: center; gap: 6px; color: var(--accent); }
.fv-drop b { font-size: 18px; color: var(--text); }
.fv-drop span { color: var(--muted); font-size: 13px; }
.fv-modal:not([hidden]) { position: fixed; inset: 0; z-index: 70; background: rgba(3,6,5,.82); display: grid; place-items: center; padding: 24px; }
.fv-modal-card { width: min(1100px, 100%); max-height: calc(100dvh - 48px); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.fv-modal-card.small { width: min(420px, 100%); }
.fv-modal-card header { display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--line); }
.fv-m-title { flex: 1; min-width: 0; display: grid; }
.fv-m-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.fv-m-title small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fv-m-actions { display: flex; gap: 2px; }
.fv-m-actions a.icon-btn { color: #b4bfb9; }
.icon-btn.danger:hover { color: var(--danger); }
.fv-m-body { flex: 1; min-height: 240px; overflow: auto; display: grid; place-items: center; background: #0c110f; }
.fv-m-body img { max-width: 100%; max-height: calc(100dvh - 140px); object-fit: contain; display: block; }
.fv-m-body video { max-width: 100%; max-height: calc(100dvh - 140px); }
.fv-m-body.audio { gap: 18px; padding: 40px; align-content: center; }
.fv-m-body.pdf iframe { width: 100%; height: calc(100dvh - 140px); border: 0; background: #fff; }
.fv-m-body.text { place-items: stretch; }
.fv-text { margin: 0; padding: 18px 20px; white-space: pre-wrap; word-break: break-word; font: 12.5px/1.55 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; color: #d5ddd9; }
.fv-nopreview { display: grid; justify-items: center; gap: 10px; padding: 40px; text-align: center; color: var(--muted); }
.fv-nopreview img { max-width: 260px; border-radius: 12px; }
.fv-nopreview b { color: var(--text); word-break: break-all; }
.fv-pick-list { overflow-y: auto; padding: 6px; max-height: 60dvh; }
.fv-pick-row { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: transparent; color: var(--text); padding: 8px 10px; border-radius: 10px; font: inherit; font-size: 14px; text-align: left; cursor: pointer; }
.fv-pick-row:hover { background: var(--hover); }
.fv-muted { color: var(--muted); padding: 16px; }
.fv-menu button.danger { color: var(--danger); }
@media (max-width: 1100px) {
  .files-view:not([hidden]) { padding: 18px 18px 0; }
  .fv-lhead, .fv-row { grid-template-columns: 30px minmax(0, 1fr) 110px 84px; }
  .fv-lhead span:nth-child(4), .fv-row .fv-date { display: none; }
}
@media (max-width: 860px) {
  .files-view:not([hidden]) { grid-column: 1; grid-row: 1; padding: 14px 12px 0; }
  .shell.files-open .rail { display: flex !important; }
  .shell.files-open { grid-template-rows: minmax(0, 1fr) auto; }
  .fv-tools { width: 100%; }
  .fv-search { flex: 1 1 100%; min-width: 0; }
  .fv-search input { width: 100%; }
  #fv-sort { flex: 1; min-width: 0; }
  .fv-upload span { display: none; }
  .fv-upload { padding: 0 12px; }
  .fv-body.grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .fv-check, .fv-more { opacity: 1; }
  .fv-lhead { display: none; }
  .fv-lhead, .fv-row { grid-template-columns: 26px minmax(0, 1fr) 76px 40px; gap: 8px; padding: 0 4px; }
  .fv-row .fv-acts a { display: none; }
  .fv-up { grid-template-columns: minmax(0, 1fr) 60px auto; }
  .fv-up-st { display: none; }
  .fv-up.err .fv-up-st { display: block; grid-column: 1 / -1; }
  .fv-modal:not([hidden]) { padding: 0; }
  .fv-modal-card { max-height: 100dvh; height: 100dvh; border-radius: 0; }
  .fv-modal-card.small { height: auto; border-radius: 18px 18px 0 0; align-self: end; }
}
/* /CLOUD =============================================================== */

/* AUTH/COOKIE: «Запомнить меня» */
#auth-form label.remember { display: flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13.5px; color: #b9c4be; user-select: none; }
#auth-form label.remember input { width: 17px; height: 17px; margin: 0; padding: 0; accent-color: var(--accent); cursor: pointer; flex: none; }

/* Пустой чат / «Избранное»: строки сетки закреплены, чтобы скрытый баннер не сжимал ленту */
.thread > .chat-head { grid-row: 1; }
.thread > .e2e { grid-row: 2; }
.thread > .log { grid-row: 3; }
.thread > .dock { grid-row: 4; }
.chat-empty { margin: auto; display: grid; justify-items: center; gap: 8px; text-align: center; max-width: 320px; padding: 28px 24px; border-radius: 20px; background: rgba(13,18,16,.72); border: 1px solid var(--line); backdrop-filter: blur(6px); color: var(--muted); font-size: 13.5px; line-height: 1.45; }
.chat-empty b { color: var(--text); font-size: 16px; font-weight: 600; }
.chat-empty-ico { width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); margin-bottom: 4px; }
.chat-empty.saved .chat-empty-ico { background: var(--accent); color: var(--on-accent); }

/* MSGDEL/MSGEDIT ======================================================= */
.pin-menu button.danger, .pin-menu button.danger svg { color: var(--danger); }
.foot .edited { font-style: italic; margin-right: 2px; }
.msg[data-mid] { -webkit-touch-callout: none; }
.msg.menu-on .bubble, .msg.editing .bubble { box-shadow: 0 0 0 2px var(--accent-soft), 0 0 0 1px var(--accent) inset; }
.thread.selecting .msg[data-mid] { cursor: pointer; position: relative; }
.thread.selecting .msg[data-mid]::before {
  content: ""; position: absolute; top: 50%; width: 18px; height: 18px; margin-top: -9px; border-radius: 50%;
  border: 2px solid var(--muted); box-sizing: border-box;
}
.thread.selecting .msg.them[data-mid] { margin-left: 30px; }
.thread.selecting .msg.them[data-mid]::before { left: -28px; }
.thread.selecting .msg.me[data-mid]::before { left: -28px; }
.thread.selecting .msg.selected[data-mid]::before {
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23fff' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round' d='m6 12.5 4 4L18 8'/%3E%3C/svg%3E") center/12px no-repeat;
  border-color: var(--accent);
}
.thread.selecting .msg.selected .bubble { filter: brightness(1.15); }
.sel-bar:not([hidden]), .edit-bar:not([hidden]) {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; margin: 0 0 6px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px;
}
.sel-bar #sel-count { flex: 1; font-weight: 600; }
.sel-del { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 10px; padding: 8px 14px;
  background: var(--danger); color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
.thread.selecting #composer, .thread.selecting .edit-bar { display: none !important; }
.edit-bar .eb-ico { color: var(--accent); display: inline-flex; }
.edit-bar .eb-body { flex: 1; min-width: 0; display: flex; flex-direction: column; border-left: 2px solid var(--accent); padding-left: 10px; }
.edit-bar .eb-body b { color: var(--accent); font-size: 13px; }
.edit-bar #eb-orig { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread.peer-deleted #composer, .thread.peer-deleted .edit-bar { display: none !important; }
.peer-deleted-note:not([hidden]) { text-align: center; color: var(--muted); padding: 14px; font-size: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.cb-modal { position: fixed; inset: 0; z-index: 2000; background: rgba(3,6,5,.72); display: grid; place-items: center; padding: 20px; }
.cb-card { width: min(400px, 100%); background: var(--panel); color: var(--text); border: 1px solid var(--line-2);
  border-radius: 16px; padding: 20px 20px 16px; box-shadow: 0 30px 80px rgba(0,0,0,.6); display: flex; flex-direction: column; gap: 12px; }
.cb-card h3 { margin: 0; font-size: 17px; }
.cb-card p { margin: 0; color: var(--muted); line-height: 1.45; }
.cb-check { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.cb-check input { width: 18px; height: 18px; accent-color: var(--danger); }
.cb-input { background: var(--input); border: 1px solid var(--line-2); color: var(--text); border-radius: 10px; padding: 10px 12px; font: inherit; }
.cb-err { color: var(--danger); font-size: 13px; }
.cb-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.cb-actions button { border: 0; border-radius: 10px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer;
  background: transparent; color: var(--accent); }
.cb-actions button:hover { background: var(--hover); }
.cb-actions .cb-ok.danger { color: var(--danger); }
.cb-actions .cb-ok:disabled { opacity: .5; cursor: default; }

/* BULKDEL: режим выбора нескольких диалогов */
.dsel-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 0 8px 8px 6px;
  border-bottom: 1px solid var(--line);
}
.dsel-bar[hidden] { display: none; }
.dsel-count { flex: 1; font-weight: 600; font-size: 14px; white-space: nowrap; }
.dsel-all, .dsel-del {
  border: 0; border-radius: 10px; padding: 8px 11px; font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.dsel-all { background: var(--accent-soft); color: var(--accent); }
.dsel-del { background: rgba(239, 68, 68, .16); color: var(--danger); }
.dsel-del:not(:disabled):hover { background: var(--danger); color: #fff; }
.dsel-all:disabled, .dsel-del:disabled { opacity: .45; cursor: default; }
.list-tabs.dsel-hide { display: none; }
.chats.selecting .row { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.dsel-box {
  flex: none; width: 22px; height: 22px; border-radius: 7px;
  border: 2px solid var(--muted); display: grid; place-items: center;
  color: transparent; transition: background .12s, border-color .12s;
}
.row.dsel-on { background: var(--accent-soft); }
.row.dsel-on .dsel-box { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.row.dsel-locked { opacity: .55; cursor: not-allowed; }
.dsel-box.locked { border-style: dashed; color: var(--muted); }
.dsel-bar .icon-btn { width: 34px; height: 34px; }
.dsel-count { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.dsel-all, .dsel-del { padding: 7px 10px; flex: none; }

/* FEATURES: ответы, пересылка, закрепы, реакции, поиск, «Пароль и устройства» ========= */
.thread { grid-template-rows: auto auto auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); }
.thread > * { min-width: 0; }
.thread > .e2e { grid-row: 2; }
.thread > .topbars { grid-row: 3; }
.thread > .log { grid-row: 4; }
.thread > .dock { grid-row: 5; }
.topbars { display: flex; flex-direction: column; min-width: 0; position: relative; z-index: 3; }
.topbars:empty { display: none; }

/* закреплённые */
.pinbar:not([hidden]) { display: flex; align-items: center; gap: 4px; padding: 6px 10px 6px 14px;
  background: rgba(13, 18, 16, .94); border-bottom: 1px solid var(--line); backdrop-filter: blur(6px); }
.pb-main { flex: 1; min-width: 0; display: flex; align-items: stretch; gap: 10px; border: 0; background: transparent;
  color: inherit; text-align: left; padding: 2px 0; cursor: pointer; font: inherit; }
.pb-lines { display: flex; flex-direction: column; gap: 2px; width: 3px; flex: none; }
.pb-lines i { flex: 1; border-radius: 2px; background: rgba(var(--accent-rgb), .3); min-height: 6px; }
.pb-lines i.on { background: var(--accent); }
.pb-body { min-width: 0; display: flex; flex-direction: column; }
.pb-body b { color: var(--accent); font-size: 12.5px; font-weight: 600; }
.pb-body span { color: var(--text); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinbar .icon-btn { width: 32px; height: 32px; }
.pin-mark { display: inline-flex; color: var(--accent); opacity: .85; }
.pins-menu { max-width: min(360px, calc(100vw - 12px)); max-height: 60vh; overflow: auto; }
.pins-menu button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* поиск по чату */
.csearch:not([hidden]) { display: block; background: rgba(13, 18, 16, .97); border-bottom: 1px solid var(--line); }
.cs-row { display: flex; align-items: center; gap: 2px; padding: 6px 8px 6px 12px; }
.cs-ico { color: var(--muted); display: inline-flex; margin-right: 6px; }
#cs-input { flex: 1; min-width: 60px; background: var(--input); border: 1px solid var(--line-2); color: var(--text);
  border-radius: 10px; padding: 8px 10px; font: inherit; outline: none; }
#cs-input:focus { border-color: var(--accent); }
.cs-count { color: var(--muted); font-size: 12.5px; white-space: nowrap; padding: 0 6px; }
.cs-row .icon-btn { width: 34px; height: 34px; }
.cs-row .icon-btn:disabled { opacity: .35; }
.cs-row .icon-btn.on { color: var(--accent); background: var(--accent-soft); }
.cs-results:not([hidden]) { max-height: min(42vh, 340px); overflow: auto; border-top: 1px solid var(--line); padding: 4px 0; }
.cs-item { display: flex; flex-direction: column; gap: 2px; width: 100%; padding: 8px 16px; border: 0; background: transparent;
  color: inherit; text-align: left; font: inherit; cursor: pointer; }
.cs-item:hover { background: var(--hover); }
.cs-item.on { background: var(--accent-soft); }
.cs-top { display: flex; gap: 8px; justify-content: space-between; font-size: 12.5px; }
.cs-top b { color: var(--accent); font-weight: 600; }
.cs-top em { color: var(--muted); font-style: normal; white-space: nowrap; }
.cs-snip { color: #c8d2cd; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
mark { background: rgba(250, 204, 21, .35); color: inherit; border-radius: 3px; padding: 0 1px; }
.msg.search-hit .bubble { box-shadow: 0 0 0 2px rgba(250, 204, 21, .6), 0 2px 8px rgba(0,0,0,.25); }
.head-actions #chat-search-btn.on { color: var(--accent); background: var(--accent-soft); }

/* переход к сообщению */
@keyframes feat-flash { 0%, 30% { background: rgba(var(--accent-rgb), .22); } 100% { background: transparent; } }
.msg.flash { animation: feat-flash 1.8s ease-out; border-radius: 14px; }

/* ответ / пересылка в пузыре */
.fwd-from, .reply-q, .reacts { white-space: normal; }
.fwd-from { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--accent); margin: 0 0 3px; }
.fwd-from svg { flex: none; }
.fwd-from b { font-weight: 600; }
.reply-q { display: flex; flex-direction: column; align-items: flex-start; width: 100%; min-width: 120px; max-width: 100%;
  margin: 0 0 5px; padding: 4px 10px 5px; border: 0; border-left: 3px solid var(--accent); border-radius: 6px;
  background: rgba(var(--accent-rgb), .1); color: inherit; font: inherit; text-align: left; cursor: pointer; }
.reply-q:hover { background: rgba(var(--accent-rgb), .18); }
.reply-q b { color: var(--accent); font-size: 12.5px; font-weight: 600; }
.reply-q span { font-size: 13px; color: #c8d2cd; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.reply-q.gone span { font-style: italic; color: var(--muted); }
.bubble.media > .fwd-from, .bubble.media > .reply-q { margin-left: 6px; margin-right: 6px; width: auto; margin-top: 4px; }
.reply-bar .eb-body { border: 0; border-left: 2px solid var(--accent); background: transparent; color: inherit; font: inherit;
  text-align: left; cursor: pointer; }
.reply-bar #rb-text, .reply-bar #rb-name { display: block; max-width: 100%; }
.reply-bar #rb-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar #rb-text { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* реакции */
.reacts { clear: both; display: flex; flex-wrap: wrap; gap: 4px; padding-top: 6px; }
.bubble.media > .reacts { padding: 6px 6px 0; }
.react { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px 2px 6px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,.08); background: rgba(255,255,255,.07); color: var(--text); font: inherit;
  font-size: 12.5px; line-height: 20px; cursor: pointer; }
.react i { font-style: normal; font-size: 15px; }
.react:hover { background: rgba(255,255,255,.12); }
.react.mine { background: var(--accent-soft); border-color: rgba(var(--accent-rgb), .55); color: var(--accent-pale); }
.msg.me .react.mine { background: rgba(var(--accent-rgb), .3); }
.react-row { display: grid; grid-template-columns: repeat(9, 34px); gap: 2px; padding: 2px 8px 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.react-row.all { grid-template-columns: repeat(8, 34px); max-height: 200px; overflow: auto; }
.pin-menu .react-row button { width: 34px; height: 34px; padding: 0; justify-content: center; border-radius: 10px; font-size: 20px; gap: 0; }
.pin-menu .react-row button.mine { background: var(--accent-soft); }
.pin-menu .react-row button.more { color: var(--muted); font-size: 14px; }
.pin-menu .react-row button:hover { transform: scale(1.12); }

/* пересылка: выбор чатов */
.fwd-card { width: min(420px, 100%); max-height: min(640px, calc(100dvh - 40px)); }
.fwd-search { display: flex; align-items: center; gap: 8px; background: var(--input); border: 1px solid var(--line-2);
  border-radius: 10px; padding: 0 10px; color: var(--muted); }
.fwd-search input { flex: 1; border: 0; background: transparent; color: var(--text); padding: 10px 0; font: inherit; outline: none; }
.fwd-list { overflow: auto; min-height: 120px; max-height: 50vh; margin: 0 -8px; }
.fwd-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px; border: 0; border-radius: 10px;
  background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.fwd-row:hover { background: var(--hover); }
.fwd-row.on { background: var(--accent-soft); }
.fwd-row.on .dsel-box { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.fwd-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fwd-empty { color: var(--muted); text-align: center; padding: 24px; }
.cb-actions .cb-ok:not(.danger) { color: var(--accent); }
.sel-fwd { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 10px; padding: 8px 14px;
  background: var(--accent-soft); color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; }

/* глобальный поиск по сообщениям */
#chats-pane.searching .chats { flex: 0 1 auto; max-height: 45%; }
.msg-results:not([hidden]) { overflow: auto; flex: 1 1 auto; border-top: 1px solid var(--line); min-height: 0; }
.mr-head { font-size: 11.5px; color: var(--muted); padding: 10px 14px 4px; text-transform: uppercase; letter-spacing: .5px; }
.mr-head span { color: var(--accent); }
.mr-empty { color: var(--muted); padding: 10px 14px 16px; font-size: 13px; }
.mr-snip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* «Пароль и устройства» */
.sec-body { display: flex; flex-direction: column; gap: 16px; padding-top: 16px; }
.sec-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 14px 12px; }
.sec-card h4 { margin: 0 0 12px; font-size: 14.5px; display: flex; align-items: center; gap: 8px; }
.sec-count { font-size: 12px; color: var(--accent); background: var(--accent-soft); border-radius: 99px; padding: 1px 8px; }
.sec-btn { width: 100%; border: 0; border-radius: 10px; padding: 10px 14px; margin-top: 8px; font: inherit; font-weight: 600;
  background: var(--accent); color: var(--on-accent); cursor: pointer; }
.sec-btn.ghost { background: var(--accent-soft); color: var(--accent); }
.sec-btn.danger { background: rgba(239, 68, 68, .14); color: var(--danger); }
.sec-btn:disabled { opacity: .5; cursor: default; }
.okmsg { color: var(--accent); font-size: 13px; margin: 0 0 6px; }
.sess-list { display: flex; flex-direction: column; gap: 2px; margin: 0 -6px 4px; }
.sess { display: flex; align-items: center; gap: 12px; padding: 8px 6px; border-radius: 10px; }
.sess.cur { background: var(--accent-soft); }
.sess-ico { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); color: var(--muted); flex: none; }
.sess.cur .sess-ico { color: var(--accent); }
.sess-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sess-meta b { font-size: 13.5px; font-weight: 600; }
.sess-meta small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess-badge { color: var(--accent); font-style: normal; }
.sess-end { border: 0; border-radius: 8px; padding: 6px 10px; background: rgba(239, 68, 68, .12); color: var(--danger);
  font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; flex: none; }
#edit-username[readonly] { color: var(--muted); cursor: not-allowed; }

@media (max-width: 860px) {
  .head-actions #chat-search-btn { display: grid !important; }
  .cs-row { padding: 6px 4px 6px 10px; }
  .cs-ico { display: none; }
  .cs-row .icon-btn { width: 32px; height: 32px; }
  .react-row { grid-template-columns: repeat(9, 32px); padding: 2px 6px 6px; }
  .react-row.all { grid-template-columns: repeat(8, 34px); }
  .pin-menu .react-row button { width: 32px; height: 34px; }
  .sel-fwd span, .sel-del span { display: none; }
}
/* /FEATURES ============================================================ */
/* FEATURES: длинная цитата не расширяет пузырь */
.msg > .bubble { min-width: 0; max-width: 100%; }
.reply-q { overflow: hidden; }

/* PHASE2 ================================================================ */
/* список чатов: значок группы, «без звука», приглушённый счётчик */
.row strong .grp-ico { color: var(--muted); vertical-align: -2px; margin-right: 4px; }
.row strong .mute-ico { color: var(--muted-2); vertical-align: -2px; margin-left: 5px; }
.badge.muted { background: #3a4540; color: #d6dfda; }
.row .chk.delivered { color: var(--muted); }
.p2-create-btn { margin-top: 14px; display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 999px;
  padding: 9px 16px; background: var(--accent); color: var(--on-accent); font-weight: 600; font-size: 13px; cursor: pointer; }
.p2-create-btn svg { color: var(--on-accent); margin: 0; }

/* сообщения: системные, отправитель в группе, галочки */
.sys-msg { align-self: center; max-width: min(86%, 520px); text-align: center; margin: 4px 0; }
.sys-msg span { display: inline-block; font-size: 12.5px; line-height: 1.4; color: #c9d4ce; background: rgba(22, 30, 27, .88);
  border: 1px solid var(--line); padding: 4px 12px; border-radius: 12px; word-break: break-word; }
.msg.grp { align-items: flex-end; gap: 8px; max-width: min(74%, 560px); }
.av.gav { width: 32px; height: 32px; font-size: 12px; align-self: flex-start; }
.av.gav.ghost { visibility: hidden; }
.msg.grp:not(.first) { margin-top: -3px; }
.g-sender { font-size: 12.5px; font-weight: 600; color: hsl(var(--h), 60%, 66%); margin-bottom: 2px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.ticks.delivered { color: rgba(233,239,236,.75); }
.ticks .rc { font-size: 10.5px; font-weight: 700; margin-left: 1px; color: var(--accent); }
.thread.selecting .msg.grp[data-mid] { margin-left: 30px; }

/* шапка группы: звонки скрыты */
.thread.group-mode .head-actions [data-soon] { display: none; }

/* панель группы */
.profile.group-mode .about, .profile.group-mode .prow[data-soon], .profile.group-mode .pdanger,
.profile.group-mode .profile-actions [data-soon], .profile.group-mode .pcard:has(.prow.enc) { display: none; }
.profile.group-mode .profile-actions { grid-template-columns: 1fr; max-width: 120px; margin-left: auto; margin-right: auto; }
.group-card { margin-bottom: 0; }
.gc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px 6px; font-size: 13px; }
.gc-add { display: inline-flex; align-items: center; gap: 6px; border: 0; background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 6px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.gc-add svg { width: 16px; height: 16px; }
.gc-list { display: grid; padding: 2px 4px 6px; max-height: 360px; overflow-y: auto; }
.gc-row { display: flex; align-items: center; gap: 6px; border-radius: 10px; padding-right: 4px; }
.gc-row:hover { background: var(--hover); }
.gc-person { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; border: 0; background: transparent; color: var(--text);
  padding: 7px 8px; text-align: left; cursor: pointer; }
.gc-person .av.sm { width: 38px; height: 38px; }
.gc-person .av.online::after { border-color: var(--panel); }
.gc-meta { min-width: 0; display: grid; }
.gc-meta b { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gc-meta small { color: var(--muted); font-size: 11.5px; }
.gc-meta small.on { color: var(--accent); }
.gc-you { font-style: normal; font-weight: 500; color: var(--muted); font-size: 11.5px; }
.gc-role { flex: none; font-size: 10.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.gc-role.owner { background: var(--accent-soft); color: var(--accent); }
.gc-more { width: 30px; height: 30px; flex: none; }
.gc-actions { border-top: 1px solid var(--line); }
.gc-actions .prow svg { color: #aeb9b3; }
.gc-actions .prow.danger, .gc-actions .prow.danger svg { color: var(--danger); }
.gc-loading { padding: 16px; color: var(--muted); font-size: 13px; }

/* окно выбора людей / новая группа */
.p2-picker { width: min(440px, 100%); max-height: min(640px, calc(100dvh - 40px)); display: flex; flex-direction: column; }
.p2-picker .cb-input { width: 100%; box-sizing: border-box; }
.pk-top { display: flex; align-items: center; gap: 12px; }
.pk-av { width: 56px; height: 56px; border: 1px dashed var(--line-2); background: var(--panel-2); color: var(--accent); cursor: pointer; overflow: hidden; }
.pk-av img { width: 100%; height: 100%; object-fit: cover; }
.pk-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pk-chips[hidden] { display: none; }
.pk-chip { border: 0; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.pk-list { flex: 1; min-height: 120px; max-height: 300px; overflow-y: auto; display: grid; align-content: start; gap: 2px;
  border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.pk-row { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; color: var(--text); text-align: left;
  padding: 7px 8px; border-radius: 10px; cursor: pointer; }
.pk-row:hover { background: var(--hover); }
.pk-meta { flex: 1; min-width: 0; display: grid; }
.pk-meta b { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pk-meta small { color: var(--muted); font-size: 12px; }
.pk-row .dsel-box { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--muted-2); display: grid; place-items: center; color: transparent; flex: none; }
.pk-row.on .dsel-box { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.pk-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 22px 8px; margin: 0; }

/* информация о сообщении */
.p2-info h5 { margin: 12px 0 6px; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.p2-info h5 em { font-style: normal; color: var(--muted); font-weight: 500; }
.mi-row { display: flex; align-items: center; gap: 10px; padding: 4px 0; font-size: 13px; }
.av.mi-av { width: 30px; height: 30px; font-size: 11px; }
.mi-sent, .mi-empty, .mi-note { color: var(--muted); font-size: 12.5px; margin: 4px 0; }
.mi-state { margin: 10px 0 0; font-weight: 600; color: var(--accent); }

/* настройки уведомлений и конфиденциальности */
.np-perm { display: grid; gap: 8px; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.np-perm .sec-btn[hidden] { display: none; }
.np-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 13.5px; cursor: pointer; }
.np-row > span:first-child { flex: 1; min-width: 0; display: grid; gap: 2px; }
.np-row small { color: var(--muted); font-size: 11.5px; line-height: 1.4; }
.np-vol { cursor: default; }
.np-vol > span:first-child { flex: none; }
.np-vol input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
.np-vol b { width: 40px; text-align: right; font-weight: 600; font-size: 12.5px; color: var(--muted); }
.np-test { border: 0; background: var(--panel-2); color: var(--accent); width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; flex: none; }
@media (max-width: 860px) {
  .msg.grp { max-width: 88%; }
  .av.gav { width: 28px; height: 28px; }
}
.peer #peer-status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* /PHASE2 */

/* PHASE3 ================================================================ */
/* Элементы мобильной вёрстки; на компьютере большинство скрыто */
#m-head, .m-pins, .m-cloud, .m-cancel, .m-only, .m-only-ico { display: none; }
.m-head { display: flex; align-items: center; gap: 12px; padding: 14px 14px 8px; }
.m-title { flex: 1; min-width: 0; margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.m-round { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line-2); background: rgba(255,255,255,.04);
  color: var(--text); display: grid; place-items: center; flex: none; padding: 0; }
.m-round.m-plus { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.tab-count.soft { background: var(--panel-2); color: var(--muted); }
.list-tabs button.on .tab-count.soft { background: var(--accent); color: var(--on-accent); }
/* «Контакты» */
.ct-search { display: flex; align-items: center; gap: 8px; margin: 2px 12px 8px; padding: 0 12px; border-radius: 12px;
  background: var(--input); border: 1px solid var(--line); color: var(--muted); }
.ct-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 10px 0; font-size: 14px; }
.ct-search:focus-within { border-color: rgba(var(--accent-rgb), .5); }
.ct-list { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: 8px; }
.ct-sec { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 12px 16px 4px; }
.ct-empty { padding: 32px 22px; text-align: center; color: var(--muted); }
.ct-on { color: var(--online); }

@media (max-width: 860px) {
  :root {
    --bg: #070a12;
    --rail: rgba(9, 12, 21, .94);
    --sidebar: #070a12;
    --panel: #111726;
    --panel-2: #182033;
    --line: rgba(255, 255, 255, .07);
    --line-2: rgba(255, 255, 255, .11);
    --bubble-in: #161e2e;
    --bubble-out: #2459d8;
    --accent: #38b6ff;
    --accent-rgb: 56, 182, 255;
    --accent-d: #1f9ff0;
    --accent-hi: #63c7ff;
    --accent-light: #7dd3fc;
    --accent-pale: #d3efff;
    --on-accent: #031322;
    --online: #22c55e;
    --text: #f2f5fa;
    --muted: #9aa4b8;
    --muted-2: #6f7a90;
    --input: #121a2a;
    --hover: rgba(255, 255, 255, .045);
    --selected: rgba(56, 182, 255, .12);
    --grad: linear-gradient(135deg, #22d3ee 0%, #3b82f6 100%);
    --glow: 0 6px 18px rgba(59, 130, 246, .35);
    --radius: 18px;
  }
  /* ---- клавиатура: страница не прокручивается, приложение = видимая область ---- */
  html, body {
    position: fixed; inset: 0; width: 100%; height: 100%;
    overflow: hidden; overscroll-behavior: none;
  }
  body {
    font-size: 16px; line-height: 1.35;
    background: var(--bg);
    -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
  }
  .shell {
    position: fixed; left: 0; right: 0; top: var(--vv-top, 0px);
    height: var(--app-height, 100dvh);
    background:
      radial-gradient(120% 55% at 105% -5%, rgba(124, 58, 237, .20), transparent 60%),
      radial-gradient(90% 45% at -10% 105%, rgba(14, 165, 233, .10), transparent 60%),
      var(--bg);
  }
  .auth {
    position: fixed; left: 0; right: 0; top: var(--vv-top, 0px);
    height: var(--app-height, 100dvh); min-height: 0;
    overflow-y: auto; overscroll-behavior: contain;
    padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  }
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), textarea, select { font-size: 16px !important; }
  .m-hide, .d-only { display: none !important; }
  .m-only { display: inline; }
  .m-only-ico { display: block; }
  button { -webkit-user-select: none; user-select: none; }

  /* ---- нижняя панель вкладок ---- */
  .rail {
    grid-row: 2; flex-direction: row; align-items: stretch;
    padding: 6px 4px calc(4px + env(safe-area-inset-bottom));
    background: var(--rail); border-top: 1px solid var(--line);
    -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  }
  .rail-items { display: flex; justify-content: space-around; align-items: flex-start; width: 100%; gap: 0; }
  .rail .rail-item {
    flex: 1 1 0; min-width: 0; flex-direction: column; align-items: center; justify-content: flex-start;
    gap: 3px; padding: 6px 2px 4px; border-radius: 14px; background: transparent; color: #9aa4b8;
  }
  .rail .rail-item svg { color: #9aa4b8; width: 25px; height: 25px; }
  .rail .rail-item:hover { background: transparent; }
  .rail .rail-item .rail-label { display: block; font-size: 11.5px; font-weight: 500; line-height: 1.2; max-width: 100%; }
  .rail .rail-item.on { background: transparent; color: var(--accent); }
  .rail .rail-item.on svg { color: var(--accent); }
  .rail .rail-item.on .rail-label { font-weight: 600; }
  .rail .rail-badge {
    position: absolute; top: 1px; left: calc(50% + 4px); right: auto; margin: 0;
    min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px;
    background: #ef4444; color: #fff; font-size: 11.5px; font-weight: 700; border: 2px solid #0a0e18;
  }
  .m-cloud { display: grid; justify-items: center; gap: 3px; width: 100%; }
  .m-cloud .meter { width: 72%; max-width: 70px; height: 4px; background: rgba(255,255,255,.12); }
  .m-cloud .meter i { background: linear-gradient(90deg, #22c55e, #22d3ee); }
  .m-cloud .meter.warn i { background: #eab308; }
  .m-cloud .meter.full i { background: var(--danger); }
  .m-cloud small { font-size: 10px; font-weight: 600; color: #8fd0ff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 100%; font-variant-numeric: tabular-nums; line-height: 1.1; }
  .m-cloud small:empty { display: none; }

  /* ---- экран «Чаты» ---- */
  .sidebar { background: transparent; }
  #m-head { display: flex; }
  .m-head { gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 16px 8px; min-height: 64px; }
  .m-logo {
    width: 42px; height: 42px; border-radius: 14px; flex: none; position: relative;
    display: grid; place-items: center; color: #fff; background: var(--grad); box-shadow: var(--glow);
  }
  .m-logo::after { content: ""; position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%;
    background: var(--online); border: 2.5px solid var(--bg); }
  .m-title { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
  .m-round { width: 44px; height: 44px; border: 1px solid var(--line-2); background: rgba(255,255,255,.05); }
  .m-round.m-plus { background: var(--grad); color: #fff; border: 0; box-shadow: var(--glow); }
  #chats-pane:not(.m-searching) .side-head { display: none; }
  #chats-pane.m-searching #m-head { display: none; }
  #chats-pane.m-searching .side-head { padding: calc(10px + env(safe-area-inset-top)) 12px 8px 16px; }
  .side-head .icon-btn { display: none; }
  .m-cancel { display: block; border: 0; background: transparent; color: var(--accent); font-size: 16px; font-weight: 500; padding: 8px 4px 8px 6px; }
  #search { height: 44px; border-radius: 14px; padding-left: 40px; background: var(--input); border-color: var(--line-2); }

  .list-tabs { gap: 8px; padding: 4px 16px 10px; border: 0; overflow-x: auto; scrollbar-width: none; }
  .list-tabs::-webkit-scrollbar { display: none; }
  .list-tabs button {
    flex: none; height: 38px; padding: 0 16px; border-radius: 999px; gap: 8px;
    background: rgba(255,255,255,.05); border: 1px solid var(--line); color: #c8cfdd; font-size: 15px; font-weight: 500;
  }
  .list-tabs button.on { background: var(--grad); color: #fff; border-color: transparent; font-weight: 600; box-shadow: 0 6px 16px rgba(59,130,246,.28); }
  .list-tabs .tab-count, .list-tabs .tab-count.soft { min-width: 22px; height: 22px; padding: 0 6px; font-size: 12.5px; font-weight: 700;
    background: rgba(255,255,255,.1); color: #dbe2ee; }
  .list-tabs button.on .tab-count, .list-tabs button.on .tab-count.soft { background: rgba(255,255,255,.26); color: #fff; }

  /* закреплённые чаты */
  .m-pins:not([hidden]) { display: block; margin: 0 12px 8px; padding: 2px 6px 6px; border-radius: 18px;
    background: rgba(255,255,255,.035); border: 1px solid var(--line); flex: none; }
  .mp-head { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: transparent; padding: 8px 6px;
    color: #cfd6e4; font-size: 14px; font-weight: 600; text-align: left; }
  .mp-star { color: #fbbf24; display: inline-flex; }
  .mp-title { flex: 1; min-width: 0; }
  .mp-head em { font-style: normal; color: var(--muted); font-weight: 500; font-size: 13px; }
  .mp-chev { display: inline-flex; color: var(--muted); transition: transform .18s; }
  .m-pins:not(.open) .mp-chev { transform: rotate(180deg); }
  .m-pins:not(.open) .mp-row { display: none; }
  .mp-row { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; padding: 0 0 2px; }
  .mp-row::-webkit-scrollbar { display: none; }
  .mp-tile {
    flex: 1 0 calc(50% - 4px); min-width: 0; max-width: 100%; scroll-snap-align: start;
    display: flex; align-items: center; gap: 8px; padding: 8px 8px; border-radius: 14px;
    background: rgba(255,255,255,.05); border: 1px solid var(--line); color: var(--text); text-align: left;
  }
  .mp-tile:active { background: rgba(255,255,255,.08); }
  .mp-tile .av.sm { width: 38px; height: 38px; font-size: 14px; }
  .mp-tile .av.online::after { border-color: #11161f; width: 12px; height: 12px; }
  .mp-meta { flex: 1; min-width: 0; display: grid; gap: 2px; }
  .mp-top, .mp-bottom { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-width: 0; }
  .mp-top b { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mp-top time { font-size: 11px; color: var(--muted); flex: none; }
  .mp-prev { flex: 1; min-width: 0; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mp-prev.typing { color: var(--accent); }
  .mp-pin { color: var(--muted-2); display: inline-flex; flex: none; }
  .mp-tile .badge { min-width: 20px; height: 20px; font-size: 11.5px; }

  /* строки чатов */
  .chats { padding: 0 0 10px; overscroll-behavior: contain; }
  .people { overscroll-behavior: contain; }
  .row { gap: 14px; padding: 9px 16px; min-height: 76px; }
  .chats .row::after, .people .row::after, .ct-list .row::after {
    content: ""; position: absolute; left: 86px; right: 0; bottom: 0; height: 1px; background: var(--line); pointer-events: none;
  }
  .row:hover { background: transparent; }
  .row:active { background: var(--hover); }
  .row .meta { gap: 4px; }
  .av.tiny { width: 56px; height: 56px; font-size: 19px; }
  .row strong { font-size: 16.5px; font-weight: 600; letter-spacing: -.005em; }
  .row .preview, .row .sub { font-size: 14.5px; color: var(--muted); }
  .row time { font-size: 13px; }
  .row .unread-time { color: var(--accent); font-weight: 600; }
  .badge { min-width: 24px; height: 24px; padding: 0 7px; font-size: 13px; background: var(--grad); color: #fff; }
  .badge.muted { background: #2a3245; color: #c7cfdd; }
  .row .chk { color: var(--muted); }
  .row .chk.read { color: var(--accent); }
  .av.online::after { width: 14px; height: 14px; right: 0; bottom: 1px; border: 3px solid var(--bg); background: var(--online); }
  .row .av.saved, .av.saved {
    background: radial-gradient(circle at 50% 40%, #13213d, #0b1222); color: #60a5fa;
    box-shadow: inset 0 0 0 2px rgba(96,165,250,.55), 0 0 14px rgba(59,130,246,.28);
  }
  .row.on { background: transparent; }
  .row.on::before { display: none; }
  .row.dsel-on { background: var(--selected); }
  .list-empty { font-size: 15px; }

  /* «Контакты» */
  .ct-head { padding: calc(10px + env(safe-area-inset-top)) 16px 6px; }
  .ct-search { margin: 4px 16px 10px; height: 44px; border-radius: 14px; border-color: var(--line-2); }
  .ct-sec { padding: 14px 16px 4px; font-size: 12.5px; }

  /* ---- экран чата ---- */
  .stage { min-height: 0; background: transparent; }
  .shell.chat-open .stage { height: 100%; }
  .thread {
    height: 100%;
    background:
      radial-gradient(120% 50% at 100% 0%, rgba(124, 58, 237, .14), transparent 60%),
      radial-gradient(100% 40% at 0% 100%, rgba(14, 165, 233, .08), transparent 60%),
      var(--bg);
  }
  .chat-head {
    min-height: 60px; gap: 6px;
    padding: calc(6px + env(safe-area-inset-top)) 6px 6px 4px;
    background: rgba(9, 12, 21, .92); border-bottom: 1px solid var(--line);
    -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  }
  .back { width: 40px; height: 44px; color: var(--accent); }
  .peer-btn { gap: 10px; }
  .chat-head .av.sm { width: 42px; height: 42px; font-size: 15px; }
  .chat-head .av.online::after { border-color: #0a0e18; width: 12px; height: 12px; }
  .peer strong { font-size: 17px; font-weight: 600; line-height: 1.25; }
  .peer span { font-size: 13.5px; line-height: 1.25; }
  .head-actions .icon-btn { width: 40px; height: 40px; color: #c3cad8; }
  .e2e { margin: 8px 12px 0; padding: 8px 10px 8px 12px; border-radius: 14px;
    background: rgba(56, 182, 255, .08); border: 1px solid rgba(56, 182, 255, .18); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .e2e-text strong { font-size: 13.5px; color: #dbeeff; }
  .e2e-more { display: none; }
  .e2e-text strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .kb-open .e2e { display: none; }
  .pinbar:not([hidden]), .csearch:not([hidden]) { background: rgba(9, 12, 21, .94); }
  .pb-body b { font-size: 13px; }
  .pb-body span { font-size: 14.5px; }

  .log { padding: 10px 10px 12px; gap: 4px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .log > :first-child:not(.chat-empty) { margin-top: auto; }
  .msg { max-width: 84%; }
  .day { font-size: 13px; font-weight: 500; color: #c8d0df; background: rgba(255,255,255,.07); border: 0; border-radius: 99px; padding: 4px 12px; }
  .bubble { font-size: 16px; line-height: 1.35; padding: 7px 12px 6px; border-radius: 18px; box-shadow: none; }
  .msg.me .bubble { background: linear-gradient(160deg, #2f6cf2 0%, #2153d4 100%); border: 0; border-bottom-right-radius: 6px; color: #fff; }
  .msg.them .bubble { background: var(--bubble-in); border: 1px solid rgba(255,255,255,.06); border-bottom-left-radius: 6px; }
  .foot { font-size: 11.5px; color: rgba(242, 245, 250, .55); }
  .msg.me .foot { color: rgba(255, 255, 255, .72); }
  .msg.me .ticks { color: rgba(255, 255, 255, .72); }
  .msg.me .ticks.read { color: #a5f3fc; }
  .msg.me .ticks .rc { color: #a5f3fc; }
  .bubble.media { padding: 3px 3px 5px; }
  .bubble.media img.photo { border-radius: 15px; max-width: min(300px, 72vw); }
  .msg.me .file-ico { background: rgba(255,255,255,.18); color: #fff; }
  .file-name { font-size: 15px; }
  .file-meta { font-size: 13px; }
  .msg.me .voice-play { background: #fff; color: #1f4fd0; }
  .msg.me .wave i { background: rgba(255,255,255,.35); }
  .msg.me .wave i.on { background: #fff; }
  .msg.me .reply-q { background: rgba(255,255,255,.14); border-left-color: #a5f3fc; }
  .msg.me .reply-q b, .msg.me .fwd-from { color: #e0f2fe; }
  .msg.me .reply-q span { color: rgba(255,255,255,.85); }
  .msg.me .react { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.14); color: #fff; }
  .msg.me .react.mine { background: rgba(255,255,255,.3); }
  .reply-q span, .cs-snip { font-size: 14px; }
  .react { font-size: 13.5px; }
  .g-sender { font-size: 13.5px; }
  .sys-msg span { font-size: 13.5px; color: #c8d0df; background: rgba(255,255,255,.06); border: 0; border-radius: 99px; padding: 5px 12px; }
  .msg.menu-on .bubble, .msg.editing .bubble { box-shadow: 0 0 0 2px rgba(var(--accent-rgb), .55); }
  .chat-empty { background: rgba(17, 23, 38, .8); border-radius: 22px; font-size: 15px; }

  /* поле ввода */
  .dock { background: rgba(9, 12, 21, .94); border-top: 1px solid var(--line); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
  .composer { gap: 6px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); align-items: flex-end; }
  .kb-open .composer { padding-bottom: 8px; }
  .composer > .icon-btn#attach-btn { width: 44px; height: 44px; border-radius: 50%; background: transparent; border: 0; color: #a9b2c5; }
  .composer-field { border-radius: 22px; background: #131b2b; border: 1px solid rgba(255,255,255,.09); min-height: 44px; }
  .composer-field:focus-within { border-color: rgba(var(--accent-rgb), .5); }
  #input { font-size: 16px; line-height: 1.35; padding: 11px 4px 11px 16px; max-height: calc(16px * 1.35 * 5 + 22px); overflow-y: auto; }
  .composer-field .icon-btn { width: 38px; height: 38px; margin: 3px; color: #a9b2c5; }
  #send { width: 44px; height: 44px; background: var(--grad); color: #fff; box-shadow: 0 4px 14px rgba(59,130,246,.4); }
  #send:hover { background: var(--grad); }
  #mic { width: 44px; height: 44px; border-radius: 50%; color: #a9b2c5; }
  .rec-bar { border-radius: 22px; background: #131b2b; }
  .sheet { border-radius: 18px; background: #141b2b; bottom: calc(100% + 8px); left: 8px; }
  .sheet button { font-size: 16px; padding: 10px; }
  .sheet-ico.photo { background: linear-gradient(135deg, #22d3ee, #3b82f6); }
  .sheet-ico.file { background: linear-gradient(135deg, #a78bfa, #6366f1); }
  .emoji-panel { background: #0c111d; height: min(250px, 40vh); }
  .kb-open .emoji-panel { display: none; }
  .sel-bar:not([hidden]), .edit-bar:not([hidden]) { border-radius: 14px; margin: 6px 8px 0; font-size: 15px; }

  /* ---- панели: профиль, группа, настройки ---- */
  .profile { position: fixed; left: 0; right: 0; top: var(--vv-top, 0px); bottom: auto; height: var(--app-height, 100dvh);
    width: 100%; background: #0a0e18; border: 0; z-index: 30; box-shadow: none; }
  .profile-top { padding: calc(6px + env(safe-area-inset-top)) 8px 0; }
  .profile-scroll { padding: 0 14px calc(18px + env(safe-area-inset-bottom)); overscroll-behavior: contain; }
  .profile-hero strong { font-size: 22px; font-weight: 700; }
  .pstatus { font-size: 14px; }
  .profile-actions button { font-size: 12.5px; }
  .profile-actions button span { width: 50px; height: 50px; background: rgba(255,255,255,.05); }
  .pcard, .sec-card { border-radius: 18px; background: rgba(255,255,255,.035); }
  .prow { font-size: 15.5px; padding: 13px 14px; }
  .prow small { font-size: 12.5px; }
  .prow em { font-size: 14px; }
  .about h4 { font-size: 14px; } .about p { font-size: 14px; }
  .gc-head { font-size: 14px; }
  .gc-meta b { font-size: 15.5px; } .gc-meta small { font-size: 13px; }
  .gc-role { font-size: 11.5px; }
  .switch { width: 46px; height: 28px; }
  .switch::after { width: 22px; height: 22px; }
  .switch:checked::after { transform: translateX(18px); }

  #menu-pane, #edit-pane, #security-pane, #notify-pane, #contacts-pane { overflow-y: auto; overscroll-behavior: contain; }
  .menu-hero {
    align-items: center; text-align: center; border: 0;
    padding: calc(10px + env(safe-area-inset-top)) 20px 20px;
    background: radial-gradient(70% 90% at 50% 0%, rgba(59,130,246,.18), transparent 70%);
  }
  .menu-hero .menu-title { color: var(--text); position: static; order: -1; align-self: stretch; text-align: left; font-size: 28px; font-weight: 700;
    letter-spacing: -.02em; margin: 6px 0 14px; }
  #menu-back { display: none; }
  .menu-hero .av.xl { width: 92px; height: 92px; font-size: 32px; margin: 0 0 12px; box-shadow: 0 0 0 3px rgba(56,182,255,.25); }
  .menu-hero strong { font-size: 22px; font-weight: 700; }
  .menu-hero span:not(.menu-title) { font-size: 15px; }
  .menu-list { margin: 0 14px 16px; padding: 4px; border-radius: 18px; background: rgba(255,255,255,.035); border: 1px solid var(--line); }
  .menu-item { font-size: 16px; padding: 12px 10px; gap: 14px; min-height: 54px; }
  .menu-item:hover { background: transparent; }
  .menu-item:active { background: var(--hover); }
  .menu-item .mi { width: 36px; height: 36px; border-radius: 11px; place-items: center; background: rgba(56,182,255,.14); color: var(--accent); }
  .menu-item.danger .mi { background: rgba(239,68,68,.14); }
  .edit-head { min-height: 56px; padding: calc(6px + env(safe-area-inset-top)) 8px 6px; background: rgba(9,12,21,.92); }
  .edit-head strong { font-size: 17px; font-weight: 600; }
  .edit-body { padding: 22px 16px calc(20px + env(safe-area-inset-bottom)); }
  .sec-body { padding-top: 14px; }
  .sec-card h4 { font-size: 16px; }
  .np-row { font-size: 15.5px; padding: 12px 0; }
  .np-row small { font-size: 13px; }
  .hint { font-size: 14px; }
  #auth-form span, .field span { font-size: 14px; }
  #auth-form input, .field input, .cb-input { padding: 12px 14px; border-radius: 12px; }
  .sec-btn, #auth-go { padding: 13px 14px; border-radius: 14px; font-size: 16px; }
  .sec-btn:not(.ghost):not(.danger), #auth-go { background: var(--grad); color: #fff; }
  .sess-meta b { font-size: 15px; } .sess-meta small { font-size: 13px; }
  .auth { background: radial-gradient(120% 60% at 100% 0%, rgba(124,58,237,.22), transparent 60%), radial-gradient(90% 50% at 0% 100%, rgba(14,165,233,.12), transparent 60%), var(--bg); }
  .auth-card { background: rgba(17,23,38,.9); border-radius: 22px; }
  .logo { background: var(--grad); color: #fff; }
  .tabs button { font-size: 15px; padding: 10px; }

  /* ---- облако ---- */
  .files-view:not([hidden]) { padding: calc(10px + env(safe-area-inset-top)) 14px 0; background: transparent; }
  .fv-title h2 { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
  .fv-title small { font-size: 14px; }
  .fv-search, #fv-sort, .fv-view, .fv-upload { height: 44px; border-radius: 14px; }
  .fv-upload { background: var(--grad); color: #fff; }
  .fv-quota { border-radius: 18px; background: rgba(255,255,255,.035); }
  .fv-quota .meter { background: rgba(255,255,255,.1); }
  .fv-quota .meter i { background: linear-gradient(90deg, #22c55e, #22d3ee); }
  .fv-quota-text { font-size: 14px; color: #c8cfdd; }
  .fv-filters button { font-size: 14.5px; padding: 8px 15px; background: rgba(255,255,255,.04); color: #c8cfdd; }
  .fv-filters button.on { background: var(--grad); color: #fff; border-color: transparent; }
  .fv-card { border-radius: 16px; background: rgba(255,255,255,.04); }
  .fv-thumb { background: #0c1220; }
  .fv-cap b { font-size: 14.5px; } .fv-cap small { font-size: 12.5px; }
  .fv-row { font-size: 15px; } .fv-name small { font-size: 12.5px; }
  .fv-body { overscroll-behavior: contain; }

  /* ---- модальные окна и меню (над клавиатурой) ---- */
  .cb-modal, .fv-modal:not([hidden]), .lightbox {
    top: var(--vv-top, 0px); bottom: auto; height: var(--app-height, 100dvh);
  }
  .cb-modal { align-items: end; padding: 0; background: rgba(2, 4, 10, .66); }
  .cb-card {
    width: 100%; max-width: none; border-radius: 22px 22px 0 0; border-bottom: 0;
    padding: 18px 16px calc(14px + env(safe-area-inset-bottom)); max-height: calc(var(--app-height, 100dvh) - 24px); overflow-y: auto;
    background: #111726; animation: p3sheet .2s ease-out;
  }
  .kb-open .cb-card { padding-bottom: 12px; }
  .cb-card h3 { font-size: 19px; }
  .cb-card p { font-size: 15px; }
  .cb-actions button { font-size: 16px; padding: 11px 16px; }
  .p2-picker, .fwd-card { max-height: calc(var(--app-height, 100dvh) - 24px); }
  .pk-list, .fwd-list { max-height: none; flex: 1 1 auto; min-height: 120px; }
  .kb-open .pk-list, .kb-open .fwd-list { min-height: 64px; }
  .pk-meta b, .fwd-name { font-size: 15.5px; }
  .fv-modal-card { height: 100%; max-height: 100%; }
  .fv-modal-card.small { height: auto; max-height: calc(100% - 24px); }
  .pin-menu { border-radius: 16px; background: #141b2b; border-color: var(--line-2); padding: 6px; min-width: 210px; }
  .pin-menu button { font-size: 16px; padding: 12px 14px; border-radius: 11px; }
  .toast { bottom: calc(92px + env(safe-area-inset-bottom)); background: #141b2b; border-color: rgba(var(--accent-rgb), .35); font-size: 15px; border-radius: 14px; }
  .kb-open .toast, .shell.chat-open ~ .toast { bottom: calc(80px); }
}
@keyframes p3sheet { from { transform: translateY(24px); opacity: .6; } }
/* /PHASE3 */

/* PHASE4: боты ============================================================ */
.bot-badge {
  display: inline-flex; align-items: center; margin-left: 6px; padding: 1px 5px 0; border-radius: 5px;
  font-size: 9.5px; font-weight: 700; letter-spacing: .06em; line-height: 14px; vertical-align: 1px;
  color: #93c5fd; background: rgba(59,130,246,.16); border: 1px solid rgba(96,165,250,.28); flex: none;
}
.p4-verified { color: #3b82f6; margin-left: 4px; vertical-align: -2px; flex: none; }
.av.p4-sys-av { background: linear-gradient(150deg, #60a5fa, #2563eb 70%) !important; color: #fff; }
.av.p4-sys-av svg { display: block; }
#p4-head-badge { display: inline-flex; align-items: center; margin-left: 2px; }
#p4-head-badge:empty { display: none; }
.p4-namerow { display: flex; align-items: center; min-width: 0; max-width: 100%; }
.p4-namerow > strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* текст ботов */
.bubble a.p4-link, .bubble a.p4-mention, .bubble a.p4-cmd { color: var(--accent-light); text-decoration: none; }
.bubble a.p4-link:hover, .bubble a.p4-mention:hover, .bubble a.p4-cmd:hover { text-decoration: underline; }
.msg.me .bubble a.p4-link, .msg.me .bubble a.p4-mention, .msg.me .bubble a.p4-cmd { color: var(--accent-pale); }
.bubble .p4-tag { color: var(--accent-light); }
.bubble code { font-size: 12.5px; }
.bubble pre.p4-pre {
  margin: 4px 0; padding: 8px 10px; border-radius: 8px; background: rgba(0,0,0,.28); border-left: 3px solid rgba(var(--accent-rgb),.6);
  overflow-x: auto; white-space: pre; font-size: 12.5px;
}
.bubble pre.p4-pre code { background: none; padding: 0; }
.bubble pre.p4-pre[data-lang]::before { content: attr(data-lang); display: block; font: 600 11px var(--font); color: var(--accent-light); margin-bottom: 4px; }
.bubble blockquote.p4-quote {
  margin: 3px 0; padding: 2px 8px 2px 10px; border-left: 3px solid var(--accent); border-radius: 4px;
  background: rgba(var(--accent-rgb),.08);
}
.bubble blockquote.p4-quote.expandable:not(.open) { max-height: 4.4em; overflow: hidden; cursor: pointer; position: relative; }
.bubble blockquote.p4-quote.expandable:not(.open)::after { content: "▾"; position: absolute; right: 6px; bottom: 0; color: var(--accent-light); }
.bubble .spoiler { background: rgba(233,239,236,.22); color: transparent; border-radius: 4px; cursor: pointer; transition: color .2s, background .2s; }
.bubble .spoiler * { color: transparent !important; }
.bubble .spoiler.on { background: rgba(233,239,236,.06); color: inherit; cursor: auto; }
.bubble .spoiler.on * { color: inherit !important; }
.p4-via { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.p4-via a { color: var(--accent-light) !important; font-weight: 600; }
.p4-game { display: grid; gap: 4px; margin: 0 0 4px; white-space: normal; }
.p4-game img, .p4-game .p4-game-ph { width: 100%; max-width: 360px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 10px; display: block; }
.p4-game .p4-game-ph { display: grid; place-items: center; background: linear-gradient(135deg, rgba(var(--accent-rgb),.25), rgba(59,130,246,.25)); }
.p4-game .p4-game-ph svg { width: 40px; height: 40px; }
.p4-game b { font-size: 14.5px; }
.p4-game span { color: var(--muted); font-size: 13px; }

/* inline-клавиатура под сообщением */
.p4-col { display: flex; flex-direction: column; gap: 4px; min-width: 0; max-width: 100%; }
.msg.me .p4-col { align-items: stretch; }
.ikb { display: grid; gap: 4px; }
.ikb-row { display: flex; gap: 4px; }
.ikb-btn {
  flex: 1 1 0; min-width: 0; min-height: 36px; position: relative; display: flex; align-items: center; justify-content: center; gap: 4px;
  padding: 7px 18px; border-radius: 10px; border: 1px solid rgba(var(--accent-rgb),.18);
  background: rgba(22, 32, 28, .92); color: var(--text); font-size: 13.5px; font-weight: 500; line-height: 1.2;
  backdrop-filter: blur(6px); transition: background .15s, transform .08s;
}
.ikb-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ikb-btn:hover { background: rgba(var(--accent-rgb),.18); }
.ikb-btn:active { transform: scale(.98); }
.ikb-btn i { position: absolute; top: 4px; right: 5px; display: flex; color: var(--accent-light); opacity: .85; }
.ikb-btn.busy { color: transparent; pointer-events: none; }
.ikb-btn.busy span { color: transparent; }
.ikb-btn.busy::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(var(--accent-rgb),.3); border-top-color: var(--accent); animation: p4spin .8s linear infinite;
}
@keyframes p4spin { to { transform: rotate(360deg); } }

/* док: «Запустить», «Меню», reply-клавиатура, подсказки */
.composer.p4-hide { display: none !important; }
.p4-start {
  display: block; width: calc(100% - 28px); margin: 10px 14px 12px; min-height: 46px; border: 0; border-radius: 14px;
  background: var(--accent); color: var(--on-accent); font-weight: 650; font-size: 15px; letter-spacing: .01em;
  box-shadow: 0 6px 18px rgba(var(--accent-rgb),.28);
}
.p4-start:hover { background: var(--accent-hi); }
.p4-start:disabled { opacity: .6; }
.p4-menu {
  height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid rgba(var(--accent-rgb),.25); flex: none;
  display: inline-flex; align-items: center; gap: 6px; background: rgba(var(--accent-rgb),.12); color: var(--accent-light);
  font-weight: 600; font-size: 13.5px; max-width: 42%;
}
.p4-menu span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p4-menu:hover { background: rgba(var(--accent-rgb),.2); }
.p4-menu.app { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.p4-kbtoggle.on { color: var(--accent) !important; }
.p4-kb { padding: 0 14px 12px; display: grid; gap: 6px; max-height: 260px; overflow-y: auto; }
.p4-kb-row { display: flex; gap: 6px; }
.p4-kb button {
  flex: 1 1 0; min-width: 0; min-height: 48px; border-radius: 12px; border: 1px solid var(--line-2);
  background: var(--panel-2); color: var(--text); font-weight: 500; padding: 8px 10px; display: flex; align-items: center; justify-content: center; gap: 6px;
}
.p4-kb.compact button { min-height: 38px; }
.p4-kb button:hover { background: rgba(var(--accent-rgb),.14); border-color: rgba(var(--accent-rgb),.3); }
.p4-kb button i { display: flex; color: var(--accent-light); }
.p4-panel {
  margin: 0 14px; border: 1px solid var(--line-2); border-bottom: 0; border-radius: 14px 14px 0 0;
  background: var(--panel); max-height: 300px; overflow-y: auto; box-shadow: 0 -10px 30px rgba(0,0,0,.35);
}
.p4-cmds button {
  display: flex; width: 100%; align-items: baseline; gap: 12px; padding: 10px 14px; border: 0; background: transparent;
  color: var(--text); text-align: left; border-bottom: 1px solid var(--line);
}
.p4-cmds button:last-child { border-bottom: 0; }
.p4-cmds button:hover { background: var(--hover); }
.p4-cmds b { color: var(--accent-light); font-weight: 600; flex: none; }
.p4-cmds span { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p4-inline.loading { opacity: .65; }
.p4-inl-head { padding: 8px 14px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.p4-inl-btn { display: block; width: 100%; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--accent-light); padding: 10px 14px; font-weight: 600; text-align: left; }
.p4-inl-item { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: transparent; color: var(--text); padding: 8px 14px; text-align: left; }
.p4-inl-item:hover { background: var(--hover); }
.p4-inl-item img, .p4-inl-ph { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; flex: none; }
.p4-inl-ph { display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.p4-inl-item .t { display: grid; min-width: 0; }
.p4-inl-item .t b, .p4-inl-item .t small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p4-inl-item .t small { color: var(--muted); }

/* пустой чат с ботом */
.chat-empty.p4-empty .chat-empty-ico { background: linear-gradient(150deg, rgba(96,165,250,.25), rgba(var(--accent-rgb),.22)); color: #93c5fd; }
.chat-empty.p4-empty .p4-desc { white-space: pre-wrap; color: var(--text); opacity: .85; }
.chat-empty.p4-empty a { color: var(--accent-light); }

/* профиль бота */
#profile .pdanger.p4-off { display: none; }
.pdanger.p4-block.p4-unblock { color: var(--accent); }
#profile-about .p4-uname { color: var(--muted); }
#profile-about a { color: var(--accent-light); }

/* веб-приложения и игры */
.wa-modal { position: fixed; inset: 0; z-index: 2100; background: rgba(3,6,5,.72); display: grid; place-items: center; padding: 20px; }
.wa-card {
  width: min(420px, 100%); height: min(720px, calc(100dvh - 40px)); display: flex; flex-direction: column;
  background: var(--sidebar); border: 1px solid var(--line-2); border-radius: 18px; overflow: hidden; box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.wa-modal.expanded .wa-card { width: min(720px, 100%); height: calc(100dvh - 40px); }
.wa-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.wa-title { flex: 1; min-width: 0; display: grid; text-align: center; }
.wa-title b, .wa-title small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-title small { color: var(--muted); font-size: 12px; }
.wa-body { flex: 1; position: relative; background: #fff; }
.wa-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
.wa-loading { position: absolute; inset: 0; display: grid; place-items: center; color: #555; background: var(--sidebar); color: var(--muted); }
.wa-modal.loaded .wa-loading { display: none; }
.wa-main {
  margin: 0; min-height: 50px; border: 0; background: var(--accent); color: var(--on-accent); font-weight: 650; font-size: 15px;
}
.wa-main:disabled { opacity: .55; }
.wa-main.progress { color: transparent; background-image: linear-gradient(90deg, transparent, rgba(255,255,255,.25), transparent); background-size: 200% 100%; animation: p4bar 1s linear infinite; }
@keyframes p4bar { to { background-position: -200% 0; } }

@media (max-width: 860px) {
  .wa-modal { padding: 0; align-items: end; }
  .wa-card { width: 100%; height: calc(100dvh - 48px); border-radius: 18px 18px 0 0; }
  .wa-modal.expanded .wa-card { height: 100dvh; border-radius: 0; }
  .p4-kb { padding: 0 10px 10px; }
  .p4-panel { margin: 0 8px; }
  .p4-start { width: calc(100% - 20px); margin: 8px 10px calc(10px + env(safe-area-inset-bottom)); }
  .p4-menu { height: 40px; padding: 0 10px; }
  .p4-menu span { max-width: 90px; }
  .ikb-btn { min-height: 38px; font-size: 13px; padding: 7px 14px; }
}
/* PHASE4: на телефоне кнопка меню команд — только значок, чтобы поле ввода не сжималось */
@media (max-width: 640px) {
  .p4-menu:not(.app) { width: 40px; padding: 0; justify-content: center; }
  .p4-menu:not(.app) span { display: none; }
  .p4-menu.app span { max-width: 72px; }
}
code.p4-code { cursor: pointer; }
code.p4-code:active { opacity: .7; }

/* PHASE5: анимации и плавные переходы ==================================== */
@keyframes p5-fade-scale { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
@keyframes p5-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes p5-fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes p5-pop-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: scale(.95); } }
@keyframes p5-slide-in { from { transform: translate3d(100%, 0, 0); } to { transform: none; } }
@keyframes p5-chat-in { from { opacity: 0; transform: translate3d(32%, 0, 0); } 40% { opacity: 1; } to { opacity: 1; transform: none; } }
@keyframes p5-slide-out { from { transform: none; } to { transform: translate3d(100%, 0, 0); } }
@keyframes p5-list-back { from { opacity: .4; transform: translate3d(-12%, 0, 0); } to { opacity: 1; transform: none; } }
@keyframes p5-rise { from { opacity: 0; transform: translate3d(0, 10px, 0); } to { opacity: 1; transform: none; } }
@keyframes p5-sheet-up { from { transform: translate3d(0, 105%, 0); } to { transform: none; } }
@keyframes p5-sheet-down { from { transform: none; } to { transform: translate3d(0, 105%, 0); } }
@keyframes p5-pane-in { from { opacity: 0; transform: translate3d(14px, 0, 0); } to { opacity: 1; transform: none; } }
@keyframes p5-held { 0% { transform: scale(.955); } 55% { transform: scale(1.015); } 100% { transform: none; } }

@media (prefers-reduced-motion: no-preference) {
  /* меню, диалоги, просмотрщики — появление с затуханием и масштабом */
  .pin-menu { animation: p5-fade-scale .16s cubic-bezier(.2, .8, .3, 1); transform-origin: top left; }
  .pin-menu.p5-closing { animation: p5-pop-out .15s ease forwards; pointer-events: none; }
  .cb-modal, .wa-modal, .fv-modal:not([hidden]), .lightbox:not([hidden]) { animation: p5-fade .18s ease; }
  .cb-card, .wa-card, .fv-modal-card, .lightbox:not([hidden]) img { animation: p5-fade-scale .22s cubic-bezier(.2, .8, .3, 1); }
  .sheet:not([hidden]), .emoji-panel:not([hidden]) { animation: p5-rise .18s cubic-bezier(.2, .8, .3, 1); transform-origin: bottom left; }
  .toast:not([hidden]) { animation: p5-rise .2s ease; }
  /* отклик кнопок */
  .rail-item, .m-round, .icon-btn, .sec-btn, .cb-actions button, .pin-menu button { transition: transform .12s ease, background-color .15s ease, opacity .15s ease; }
  .rail-item:active, .m-round:active, .icon-btn:active:not(:disabled), .sec-btn:active, .cb-actions button:active, .list-tabs button:active { transform: scale(.93); }
  .pin-menu button:active:not(:disabled) { background: var(--hover, rgba(255,255,255,.08)); transform: scale(.985); }
  .row { transition: transform .15s ease, background-color .15s ease; }
  .row:active:not(.p5-press) { background: var(--hover, rgba(255,255,255,.05)); }
  .list-tabs button { transition: background-color .2s ease, color .2s ease, transform .12s ease; }
  /* строки списка чатов — каскадное появление */
  .chats.p5-enter > .row { animation: p5-rise .28s cubic-bezier(.2, .8, .3, 1) both; }
  .chats.p5-enter > .row:nth-child(2) { animation-delay: .02s; }
  .chats.p5-enter > .row:nth-child(3) { animation-delay: .04s; }
  .chats.p5-enter > .row:nth-child(4) { animation-delay: .06s; }
  .chats.p5-enter > .row:nth-child(5) { animation-delay: .08s; }
  .chats.p5-enter > .row:nth-child(6) { animation-delay: .10s; }
  .chats.p5-enter > .row:nth-child(7) { animation-delay: .12s; }
  .chats.p5-enter > .row:nth-child(n+8) { animation-delay: .14s; }
  /* долгое нажатие: строка медленно «вдавливается» и подсвечивается, затем «отпружинивает» */
  .row.p5-press { transform: scale(.955); background: var(--selected, rgba(34, 197, 94, .14)); transition: transform .45s cubic-bezier(.3, .7, .4, 1), background-color .45s ease; }
  .row.p5-held { animation: p5-held .4s cubic-bezier(.2, .8, .3, 1); background: var(--selected, rgba(34, 197, 94, .14)); }
}

@media (max-width: 860px) and (prefers-reduced-motion: no-preference) {
  /* открытие чата — въезжает справа; «Назад» — уезжает вправо, список возвращается */
  .shell.chat-open .stage { animation: p5-chat-in .26s cubic-bezier(.2, .8, .25, 1); will-change: transform, opacity; }
  .shell.chat-open.p5-leaving .stage { animation: p5-slide-out .2s cubic-bezier(.4, 0, .8, .4) forwards; }
  .shell:not(.chat-open) .sidebar { animation: p5-list-back .24s cubic-bezier(.2, .8, .3, 1); }
  /* смена экранов (Настройки, Контакты, Облако) */
  .sidebar > .pane:not([hidden]) { animation: p5-pane-in .22s cubic-bezier(.2, .8, .3, 1); }
  .files-view:not([hidden]) { animation: p5-pane-in .22s cubic-bezier(.2, .8, .3, 1); }
  .profile:not([hidden]) { animation: p5-slide-in .24s cubic-bezier(.2, .8, .25, 1); }
}

/* панель действий чата по долгому нажатию (телефон) */
.p5-backdrop { position: fixed; inset: 0; z-index: 999; background: rgba(0, 0, 0, .45); -webkit-tap-highlight-color: transparent; }
.pin-menu.p5-sheet {
  left: 8px !important; right: 8px; top: auto !important; bottom: calc(8px + env(safe-area-inset-bottom));
  min-width: 0; padding: 6px 0 8px; border-radius: 18px; transform-origin: bottom center;
}
.pin-menu.p5-sheet button { padding: 14px 20px; font-size: 16px; }
.p5-sheet-title { padding: 10px 20px 8px; font-weight: 600; color: var(--muted, #8a9690); font-size: 13px; text-align: center; border-bottom: 1px solid var(--line, rgba(255,255,255,.06)); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p5-sheet-title::before { content: ""; display: block; width: 36px; height: 4px; border-radius: 2px; margin: 0 auto 10px; background: rgba(255, 255, 255, .18); }
@media (prefers-reduced-motion: no-preference) {
  .p5-backdrop { animation: p5-fade .18s ease; }
  .p5-backdrop.p5-closing { animation: p5-fade-out .16s ease forwards; }
  .pin-menu.p5-sheet { animation: p5-sheet-up .26s cubic-bezier(.2, .85, .25, 1); }
  .pin-menu.p5-sheet.p5-closing { animation: p5-sheet-down .17s ease-in forwards; }
}
.p5-app-card .sec-btn { display: block; width: 100%; margin: 6px 0; text-align: left; }
/* /PHASE5 ================================================================ */
.np-perm[hidden], .np-row[hidden] { display: none; }

/* ROLES: значок ранга в профиле */
.rank-pill { display: inline-block; vertical-align: middle; font-size: 11px; font-weight: 600; line-height: 1; padding: 4px 8px; border-radius: 999px; letter-spacing: .01em; }
.rank-pill.admin { background: rgba(239, 68, 68, .16); color: #f87171; }
.rank-pill.moderator { background: rgba(37, 99, 235, .18); color: #60a5fa; }

/* UPLOAD: загрузка файлов в чат — прогресс, отмена, ошибка, повтор */
.chat-ups { display: grid; gap: 6px; padding: 8px 12px 0; max-height: 196px; overflow-y: auto; }
.chat-ups:empty { display: none; }
.cu { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 7px 6px 7px 8px; font-size: 13px; }
.cu-ic { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: rgba(34,197,94,.12); color: var(--accent); font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em; overflow: hidden; }
.cu-main { min-width: 0; display: grid; gap: 5px; }
.cu-top { display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.cu-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cu-st { flex: none; color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cu-bar { height: 5px; border-radius: 99px; background: #1f2925; overflow: hidden; }
.cu-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s linear; }
.cu-btns { display: flex; gap: 2px; }
.cu-btns .icon-btn { width: 32px; height: 32px; }
.cu-retry { border: 0; background: transparent; color: var(--accent); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; padding: 0 8px; height: 32px; border-radius: 8px; }
.cu-retry:hover { background: rgba(34,197,94,.1); }
.cu.err { border-color: rgba(239,68,68,.45); }
.cu.err .cu-ic { background: rgba(239,68,68,.12); color: #fca5a5; }
.cu.err .cu-bar i { background: var(--danger); width: 100% !important; }
.cu-msg { color: #fca5a5; font-size: 12.5px; line-height: 1.35; white-space: normal; }
.cu.ok .cu-st { color: var(--accent); }

/* OWNER =================================================================
   Яркая красная подсветка (row.admin-chat, thread.admin-mode, красный щит, rk-owner) — только «Главный администратор».
   Администраторы и модераторы — спокойная подсветка в цвет темы (зелёный на компьютере, голубой на телефоне). */
.av.admin-av.soft { background: rgba(var(--accent-rgb), .16) !important; color: var(--accent); box-shadow: inset 0 0 0 1px rgba(var(--accent-rgb), .32); }
.row.staff-chat { box-shadow: inset 2px 0 0 rgba(var(--accent-rgb), .55); }
.row.staff-chat strong { display: inline-flex; align-items: center; gap: 4px; }
.row.staff-chat .verified { color: rgba(var(--accent-rgb), .85); }
.thread.staff-mode #peer-name::after {
  content: ""; display: inline-block; width: 13px; height: 13px; margin-left: 5px; vertical-align: -2px;
  background: rgba(var(--accent-rgb), .85);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2 4 5v6.1c0 5 3.4 9.7 8 10.9 4.6-1.2 8-5.9 8-10.9V5z'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2 4 5v6.1c0 5 3.4 9.7 8 10.9 4.6-1.2 8-5.9 8-10.9V5z'/%3E%3C/svg%3E") center/contain no-repeat;
}
.thread.staff-mode .chat-head { box-shadow: inset 0 -1px 0 rgba(var(--accent-rgb), .35); }
.profile.admin-mode.soft #profile-name { color: var(--text); }
/* сообщения сотрудников */
.rk-lbl { display: flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; line-height: 1.2; margin: 0 0 3px; letter-spacing: .01em; }
.rk-lbl svg { flex: none; }
.rk-lbl.staff { color: rgba(var(--accent-rgb), .9); }
.rk-lbl.owner { color: var(--admin); }
.msg.them.rk-staff .bubble { box-shadow: inset 2px 0 0 rgba(var(--accent-rgb), .6); }
.msg.them.rk-owner .bubble { background: linear-gradient(var(--admin-soft), var(--admin-soft)), var(--bubble-in); border-color: rgba(239, 68, 68, .45); box-shadow: inset 3px 0 0 var(--admin), 0 0 0 1px rgba(239, 68, 68, .12), 0 4px 18px rgba(239, 68, 68, .12); }
.rank-pill.owner { background: linear-gradient(135deg, rgba(245, 158, 11, .2), rgba(239, 68, 68, .2)); color: #fbbf24; }

/* ===== MOBILE UI 10.10.2026: только телефон (<=860px), десктоп не затронут ===== */
@media (max-width: 860px) {
  /* 1. поля ввода 16px — iOS не приближает страницу */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), textarea, select,
  #input, #search, .auth input, #fv-sort { font-size: 16px !important; }

  /* 2. кнопки-иконки не меньше 44x44 */
  .icon-btn, .head-actions .icon-btn, .composer-field .icon-btn, .m-round { min-width: 44px; min-height: 44px; }
  .composer-field .icon-btn { width: 44px; height: 44px; margin: 0; }

  /* 3. нижняя панель: все кнопки помещаются (до 360px), без обрезки, с учётом полосы жестов */
  .shell .rail { padding: 4px 2px calc(4px + env(safe-area-inset-bottom)); min-width: 0; }
  .shell .rail .rail-items { display: flex; flex-wrap: nowrap; justify-content: space-evenly; align-items: flex-end; width: 100%; min-width: 0; gap: 0; }
  .shell .rail .rail-items > * { flex: 1 1 0; min-width: 44px; min-height: 48px; max-width: none; }
  .shell .rail .rail-item { padding: 4px 1px 2px; gap: 2px; }
  .shell .rail .rail-item svg { flex: none; }
  .shell .rail .rail-item .rail-label, .shell .rail .ia-label {
    display: block; max-width: 100%; font-size: 11px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .shell .rail .m-cloud { min-width: 0; }

  /* 4. экран «Чаты»: прокручивается весь список целиком (реклама, колесо, облако, сортировка, диалоги) */
  .shell .sidebar { overflow: hidden; }
  #chats-pane:not(.searching):not(.m-searching) {
    overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
    padding-bottom: 12px; }
  #chats-pane:not(.searching):not(.m-searching) > * { flex: none; }
  #chats-pane:not(.searching):not(.m-searching) > .chats { overflow: visible; flex: none; min-height: auto; }
  #chats-pane:not(.searching):not(.m-searching) > #m-head {
    position: sticky; top: 0; z-index: 5; background: var(--bg); }

  /* 5. диалоги выше: меньше отступов; реклама VPN и колесо удачи — 2 баннера рядом */
  .shell .m-head { min-height: 0; padding-bottom: 4px; }
  #chats-pane .list-tabs { padding-top: 2px; padding-bottom: 6px; }
  #chats-pane .rd-cloud { margin-top: 2px; margin-bottom: 6px; }
  #ia-top { grid-template-columns: 1fr 1fr; gap: 8px; padding: 2px 12px 6px; align-items: stretch; }
  #ia-top > :only-child { grid-column: 1 / -1; }
  #ia-top .ia-ad, #ia-top .ia-wheel {
    min-width: 0; min-height: 64px; height: 100%; box-sizing: border-box; gap: 8px; padding: 8px 10px; border-radius: 14px; overflow: hidden; }
  #ia-top .ia-ad { padding-right: 28px; }
  #ia-top .ia-ad-ava { width: 32px; height: 32px; }
  #ia-top .ia-ad-ava span { font-size: 14px; }
  #ia-top .ia-ad-text, #ia-top .ia-wheel-text { min-width: 0; gap: 1px; }
  #ia-top .ia-ad-name { gap: 4px; }
  #ia-top .ia-ad-name b, #ia-top .ia-wheel-text b { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #ia-top .ia-ad-name small, #ia-top .ia-ad-name em { display: none; }
  #ia-top .ia-ad-desc, #ia-top .ia-wheel-text small {
    font-size: 11.5px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  #ia-top .ia-ad-x { top: 4px; right: 4px; width: 22px; height: 22px; }
  #ia-top .ia-wheel-ico { width: 32px; height: 32px; }
  #ia-top .ia-wheel-go, #ia-top .ia-wheel-more { display: none; }
}
