/* Спокойная тема в духе Telegram. Светлая — база, тёмная — по системе или вручную (data-theme). */
:root {
  --bg: #ffffff; --bg2: #e6ebf0; --panel: #ffffff; --panel2: #f1f3f6;
  --text: #14181f; --muted: #707a86; --faint: #97a1ad;
  --accent: #4a86e8; --accent2: #4a86e8; --danger: #e5484d;
  --border: rgba(20,24,31,.08); --border2: rgba(20,24,31,.14);
  --surface: rgba(20,24,31,.05); --surface2: rgba(20,24,31,.09);
  --bubble-in: #ffffff;         /* принятый пузырь — белый на сером фоне чата */
  --grad: linear-gradient(120deg, #6d4bff, #12b8d8);  /* фирменный градиент — только для бренда/аватаров */
  --ring: rgba(74,134,232,.25);
  --ic-search: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3.6-3.6'/%3E%3C/svg%3E");
  --ic-reply: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 17l-5-5 5-5'/%3E%3Cpath d='M4 12h11a5 5 0 0 1 5 5v1'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0e1621; --bg2: #0e1621; --panel: #17212b; --panel2: #1d2a35;
    --text: #e9edf0; --muted: #7d8b99; --faint: #63707d;
    --accent: #58a6f0; --accent2: #58a6f0; --danger: #ff6b6b;
    --border: rgba(255,255,255,.07); --border2: rgba(255,255,255,.14);
    --surface: rgba(255,255,255,.06); --surface2: rgba(255,255,255,.11);
    --bubble-in: #1e2c3a;
    --ring: rgba(88,166,240,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0e1621; --bg2: #0e1621; --panel: #17212b; --panel2: #1d2a35;
  --text: #e9edf0; --muted: #7d8b99; --faint: #63707d;
  --accent: #58a6f0; --accent2: #58a6f0; --danger: #ff6b6b;
  --border: rgba(255,255,255,.07); --border2: rgba(255,255,255,.14);
  --surface: rgba(255,255,255,.06); --surface2: rgba(255,255,255,.11);
  --bubble-in: #1e2c3a;
  --ring: rgba(88,166,240,.4);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI Variable Display", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background .3s ease, color .2s ease;
  overscroll-behavior: none;
}
#app { min-height: 100%; display: flex; flex-direction: column; }
/* Оболочка приложения прибита к экрану (position:fixed надёжнее 100dvh —
   некоторые моб.браузеры считают 100dvh больше видимой области → скроллился весь документ) */
#app.app-shell { position: fixed; inset: 0; height: auto; min-height: 0; }

/* ---- Двухпанельная оболочка (список + чат) ---- */
.shell { display: flex; width: 100%; height: 100%; overflow: hidden; }
#sidebar { display: flex; flex-direction: column; min-height: 0; width: 100%; background: var(--bg); }
#side-content { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
#main { display: none; flex-direction: column; min-height: 0; width: 100%; background: var(--bg2); }
.app-shell.chat-open #sidebar { display: none; }
.app-shell.chat-open #main { display: flex; }
.main-empty { flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--muted); padding: 24px; text-align: center; font-size: .95em; }

/* Чат в главной панели: шапка/закреп/композер фиксированы, скроллятся только сообщения */
#main > .topbar, #main > .select-bar, #main > .pinned-bar,
#main > #composerExtra, #main > .composer, #main > .channel-footer { flex: 0 0 auto; }
#main > .messages { flex: 1; min-height: 0; }
/* Инфо чата / создание группы-канала в главной панели — прокручиваемая область (фикс: не листалось) */
#main > .content { flex: 1 1 auto; min-height: 0; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* Нижние вкладки (мобайл — как в Telegram) */
#tabbar { flex: 0 0 auto; display: flex; background: var(--panel);
  border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.tab { flex: 1; background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 8px 4px 6px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: .7em; font-weight: 600; transition: color .15s; }
.tab .tab-ico { display: flex; }
.tab .tab-ico svg { width: 24px; height: 24px; display: block; }
.tab.active { color: var(--accent); }

/* Десктоп: две колонки, как в Telegram Desktop */
@media (min-width: 900px) {
  .shell { max-width: 1500px; margin: 0 auto; box-shadow: 0 0 60px rgba(0,0,0,.4); }
  #sidebar { width: clamp(300px, 30%, 400px); border-right: 1px solid var(--border); }
  #main { display: flex; }
  .app-shell.chat-open #sidebar { display: flex; }
  #main > .topbar #back { display: none; }
}
.center { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.muted { color: var(--muted); }
a { color: var(--accent); text-decoration: none; }

/* ---- Auth ---- */
.auth-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; }
.card {
  width: 100%; max-width: 360px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; padding: 24px;
}
.brand { text-align: center; font-size: 1.7em; font-weight: 820; letter-spacing: -.02em; margin-bottom: 4px;
  background: linear-gradient(100deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand .dot { color: var(--accent2); -webkit-text-fill-color: var(--accent2); }
.subtitle { text-align: center; color: var(--muted); margin-bottom: 20px; font-size: .92em; }
label { display: block; font-size: .82em; color: var(--muted); margin: 12px 0 6px; }
input, textarea {
  width: 100%; padding: 12px 14px; border-radius: 11px;
  border: 1px solid var(--border2); background: var(--panel2); color: var(--text);
  font-size: 1em; outline: none; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.btn {
  width: 100%; margin-top: 16px; padding: 12px 20px; border: none; border-radius: 12px;
  background: var(--accent); color: #fff;
  font-size: 1em; font-weight: 600; cursor: pointer;
  transition: filter .15s ease, background .15s ease;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { filter: brightness(.95); }
.btn.danger-btn { background: none; color: var(--danger); border: 1px solid var(--border2); }
.btn.danger-btn:hover { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); filter: none; }
.btn:disabled { opacity: .55; cursor: default; filter: none; }
.switch { text-align: center; margin-top: 16px; font-size: .9em; }
.error { color: var(--danger); font-size: .85em; margin-top: 12px; min-height: 1.1em; text-align: center; }

/* ---- App shell ---- */
.topbar {
  position: sticky; top: 0; z-index: 6;
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding-top: max(12px, env(safe-area-inset-top));
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; font-weight: 600; color: #fff;
  background: var(--accent); font-size: 1.05em;
}
.avatar.sm { width: 46px; height: 46px; }
.avatar.xl { width: 110px; height: 110px; font-size: 2.6em; }
.avatar.has-img { background-image: none; background-size: cover; background-position: center; color: transparent; }
.topbar .who { flex: 1; min-width: 0; }
.topbar .who .name { font-weight: 600; }
.topbar .who .handle { color: var(--muted); font-size: .85em; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 1.3em; cursor: pointer;
  padding: 6px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px;
  transition: color .15s, background .15s; }
.icon-btn:hover { color: var(--text); background: var(--surface); }
.icon-btn svg { width: 22px; height: 22px; display: block; }
.content { flex: 1; padding: 10px 16px 16px; max-width: 640px; width: 100%; margin: 0 auto; }
.search { position: relative; margin-bottom: 6px; }
.search input { padding-left: 40px; }
.search::before {
  content: ""; position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  width: 17px; height: 17px; background: var(--muted); opacity: .8;
  -webkit-mask: var(--ic-search) center / contain no-repeat;
          mask: var(--ic-search) center / contain no-repeat;
}
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 10px 8px;
  border-radius: 12px; cursor: pointer;
}
.row:hover { background: var(--surface); }
.row .name { font-weight: 600; }
.row .handle { color: var(--muted); font-size: .85em; }
.hint { color: var(--muted); text-align: center; padding: 32px 16px; font-size: .92em; line-height: 1.5; }
.section-title { color: var(--muted); font-size: .8em; text-transform: uppercase; letter-spacing: .05em; margin: 12px 4px 6px; }

/* dialog rows */
.row .grow { flex: 1; min-width: 0; }
.row-top { display: flex; align-items: baseline; gap: 8px; }
.row-top .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-top .time { color: var(--muted); font-size: .78em; flex: 0 0 auto; }
.preview { color: var(--muted); font-size: .88em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Список диалогов — во всю ширину сайдбара, плоские строки как в Telegram
   (гасим боковые отступы .content отрицательным margin у контейнера) */
#chats { margin: 0 -16px; }
#chats .list { display: flex; flex-direction: column; }

/* Вкладки-папки над списком чатов */
.folder-tabs {
  display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 8px; margin-bottom: 2px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.folder-tabs::-webkit-scrollbar { display: none; }
.folder-tab {
  flex: 0 0 auto; border: none; cursor: pointer; padding: 6px 14px; border-radius: 16px;
  background: var(--surface); color: var(--muted); font-size: .86em; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px; transition: background .15s, color .15s;
}
.folder-tab.active { background: var(--accent); color: #fff; }
.folder-badge {
  background: var(--accent); color: #fff; border-radius: 10px; padding: 0 6px;
  font-size: .82em; min-width: 16px; text-align: center;
}
.folder-tab.active .folder-badge { background: rgba(255,255,255,.28); }

/* Строка диалога со свайпом: фон-архив под слайдящейся частью.
   display:block — гасим flex от .row, чтобы .chat-row-inner тянулся на всю ширину */
.chat-row { display: block; position: relative; overflow: hidden; padding: 0; }
.chat-row-inner {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 16px; border-radius: 0;
  background: var(--bg); position: relative; z-index: 1;
  will-change: transform;
}
.chat-row:hover .chat-row-inner { background: var(--surface); }
.chat-row.pinned .chat-row-inner { background: color-mix(in srgb, var(--accent) 6%, var(--bg)); }
.chat-row.pinned:hover .chat-row-inner { background: color-mix(in srgb, var(--accent) 10%, var(--bg)); }
.swipe-bg {
  position: absolute; inset: 0;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 28px; opacity: 0;
}
.chat-row.swiping .swipe-bg { opacity: 1; }
.swipe-bg svg { width: 22px; height: 22px; }
.pin-ico { display: inline-flex; vertical-align: -0.14em; margin-right: 4px; color: var(--faint); }
.pin-ico svg { width: 13px; height: 13px; }
/* Полка «Архив» — тоже во всю ширину и плоская */
#chats .archive-shelf { border-radius: 0; padding: 9px 16px; }
.archive-shelf .avatar-ico { background: var(--faint) !important; }
.saved-ico { background: var(--accent) !important; }
.archive-shelf .name { color: var(--text); }

/* ---- Chat view ---- */
.messages {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 4px;
  max-width: 720px; width: 100%; margin: 0 auto;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
  overscroll-behavior: contain;
}
.messages::-webkit-scrollbar { width: 7px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
.messages::-webkit-scrollbar-thumb:hover { background: var(--border2); }
.msg { display: flex; }
.msg.mine { justify-content: flex-end; }
.bubble {
  position: relative; max-width: 78%; padding: 7px 11px; line-height: 1.4;
  border-radius: 14px; background: var(--bubble-in);
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
  word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.mine .bubble { background: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.meta { float: right; display: inline-flex; align-items: center; gap: 4px; margin: 5px 0 0 10px; }
.msg-time { font-size: .68em; opacity: .6; }
.ticks { font-size: .74em; letter-spacing: -3px; padding-right: 2px; color: rgba(255,255,255,.7); }
.ticks.read { color: #dff1ff; }
.presence.online { color: var(--accent); }
.presence.typing { color: var(--accent); }

/* вложения */
.bubble.has-att, .msg.has-att .bubble { padding: 4px 4px 6px; }
.att-img, .att-video { display: block; max-width: 260px; max-height: 340px; width: auto; border-radius: 10px; cursor: pointer; }
.msg.has-att .caption { padding: 4px 8px 0; }

/* Альбомы (несколько фото/видео одним сообщением, сеткой как в Telegram) */
.msg.has-album .bubble { padding: 4px 4px 6px; }
.album { display: grid; gap: 3px; grid-template-columns: repeat(2, 1fr);
  width: min(300px, 72vw); border-radius: 12px; overflow: hidden; }
.album.album-many { grid-template-columns: repeat(3, 1fr); }
.album.album-3 .album-cell:first-child { grid-column: 1 / -1; aspect-ratio: 2.1; }
.album-cell { position: relative; aspect-ratio: 1; overflow: hidden; cursor: pointer; background: var(--surface); }
.album-media { width: 100%; height: 100%; object-fit: cover; display: block; }
.album-play { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 1.7em; color: #fff; text-shadow: 0 1px 8px rgba(0,0,0,.7); pointer-events: none; }
.msg.has-album .caption { padding: 6px 8px 0; }
.msg.has-att .meta { margin-right: 6px; margin-bottom: 2px; }
.att-file {
  display: flex; align-items: center; gap: 10px; color: inherit;
  padding: 6px 10px; min-width: 180px; max-width: 280px;
}
.att-ico { font-size: 1.7em; flex: 0 0 auto; }
.att-info { min-width: 0; }
.att-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { font-size: .8em; opacity: .7; }
.attach-btn { flex: 0 0 auto; font-size: 1.25em; }

/* счётчик непрочитанных */
.row-bot { display: flex; align-items: center; gap: 8px; }
.row-bot .preview { flex: 1; min-width: 0; }
.badge {
  flex: 0 0 auto; background: var(--accent); color: #fff; border-radius: 999px;
  min-width: 20px; height: 20px; padding: 0 6px; font-size: .74em; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}

/* действия над сообщениями */
.msg { cursor: default; }
.bubble { cursor: pointer; }
.reply-quote {
  border-left: 3px solid var(--accent); padding: 2px 8px; margin-bottom: 5px;
  background: var(--surface); border-radius: 4px; font-size: .9em; max-width: 100%;
}
.msg.mine .reply-quote { border-left-color: #cfe8ff; background: rgba(255,255,255,.15); }
.rq-name { font-weight: 600; font-size: .85em; opacity: .9; }
.rq-text { opacity: .8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.edited-mark { font-size: .68em; opacity: .55; font-style: italic; }
.deleted { font-style: italic; opacity: .6; }
.msg.deleted-msg .bubble { cursor: default; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; clear: both; }
.react-pill {
  border: none; cursor: pointer; border-radius: 999px; padding: 2px 8px; font-size: .82em;
  background: var(--surface2); color: inherit; line-height: 1.4;
}
.react-pill.mine { background: var(--accent); color: #fff; }

/* контекстное меню сообщения (как в Telegram) */
.ctx-overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.5);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
.ctx-group { position: absolute; display: flex; flex-direction: column; gap: 10px; animation: ctxIn .13s ease-out; }
.ctx-group.mine { align-items: flex-end; }
@keyframes ctxIn { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: scale(1); } }
.ctx-reactions {
  display: flex; gap: 2px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 6px; box-shadow: 0 8px 30px rgba(0,0,0,.4);
  max-width: 92vw; overflow-x: auto; scrollbar-width: none;
}
.ctx-reactions::-webkit-scrollbar { display: none; }
.ctx-react {
  background: none; border: none; cursor: pointer; font-size: 1.5em; line-height: 1;
  width: 40px; height: 40px; border-radius: 50%; flex: 0 0 auto;
}
.ctx-react:hover { background: var(--panel2); transform: scale(1.12); }
.ctx-expand { font-size: 1.1em; color: var(--muted); background: var(--panel2); }
.ctx-menu {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  min-width: 200px; padding: 6px; box-shadow: 0 8px 30px rgba(0,0,0,.4); overflow: hidden;
}
.ctx-item {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: none; border: none; color: var(--text); cursor: pointer;
  padding: 11px 12px; border-radius: 9px; font-size: 1em;
}
.ctx-item:hover { background: var(--panel2); }
.ctx-item.danger { color: var(--danger); }
.ctx-item .ci { width: 22px; text-align: center; font-size: 1.05em; }

/* полный эмодзи-пикер */
.emoji-card {
  width: 340px; max-width: 92vw; max-height: 60vh; background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; padding: 12px;
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.emoji-search {
  border-radius: 10px; background: var(--panel2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 14px; font-size: .95em; outline: none;
}
.emoji-search:focus { border-color: var(--accent); }
.emoji-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.emoji-grid::-webkit-scrollbar { width: 7px; }
.emoji-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
.emoji-cell {
  background: none; border: none; cursor: pointer; font-size: 1.5em; line-height: 1;
  aspect-ratio: 1; border-radius: 8px;
}
.emoji-cell:hover { background: var(--panel2); }

/* закреплённое / переслано / выбор / диалог удаления */
.pinned-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.pin-ico { font-size: 1em; }
.pin-body { flex: 1; min-width: 0; border-left: 2px solid var(--accent); padding-left: 8px; cursor: pointer; }
.pin-title { font-size: .8em; color: var(--accent); font-weight: 600; }
.pin-text { font-size: .88em; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin-x { background: none; border: none; color: var(--muted); font-size: 1em; cursor: pointer; }

.fwd-label { font-size: .8em; color: var(--accent); margin-bottom: 3px; font-weight: 500; }
.msg.mine .fwd-label { color: #cfe8ff; }

.select-bar {
  display: flex; align-items: center; gap: 14px; padding: 12px 16px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.sel-count { flex: 1; font-weight: 600; }
.sel-actions { display: flex; gap: 8px; }
.msg.selected .bubble { outline: 2px solid var(--accent); }
.msg.selected { background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 10px; }
.msg.flash .bubble { animation: flash 1.2s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: none; } }

.confirm-card {
  margin: auto; width: 300px; max-width: 90vw; background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; padding: 16px;
  display: flex; flex-direction: column; gap: 8px; box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.confirm-title { text-align: center; font-weight: 600; margin-bottom: 6px; }
.confirm-btn {
  background: var(--panel2); border: none; color: var(--text); padding: 12px;
  border-radius: 10px; font-size: 1em; cursor: pointer;
}
.confirm-btn.danger { color: var(--danger); }

.fwd-card {
  margin: auto; width: 360px; max-width: 92vw; max-height: 70vh; background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; padding: 14px;
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.fwd-title { font-weight: 600; text-align: center; }
.fwd-list { overflow-y: auto; scrollbar-width: thin; }
.fwd-row { cursor: pointer; }

/* группы */
.chat-head { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; cursor: pointer; }
.sender-name { font-size: .82em; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.msg-system { align-self: center; margin: 8px 0; }
.msg-system span {
  background: rgba(0,0,0,.25); color: var(--muted); font-size: .8em;
  padding: 4px 12px; border-radius: 999px;
}
.cg-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  background: var(--accent); color: #fff; border-radius: 999px; padding: 4px 10px;
  font-size: .85em; cursor: pointer;
}
.danger-btn { margin-top: 16px; background: var(--danger); }

/* каналы */
.channel-footer {
  text-align: center; color: var(--muted); padding: 14px;
  background: var(--panel); border-top: 1px solid var(--border);
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}
.cc-desc {
  width: 100%; padding: 12px 14px; border-radius: 10px; resize: vertical;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  font-size: 1em; font-family: inherit; outline: none; margin-bottom: 8px;
}
.cc-desc:focus { border-color: var(--accent); }
.ch-desc {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; color: var(--text); line-height: 1.4; margin-bottom: 8px; white-space: pre-wrap;
}
.ch-handle { color: var(--accent); font-weight: 600; margin: 4px 0 8px; }
.handle-field {
  display: flex; align-items: center; gap: 4px; background: var(--panel2);
  border: 1px solid var(--border); border-radius: 10px; padding: 0 12px; margin-bottom: 8px;
}
.handle-field .handle-at { color: var(--muted); }
.handle-field input { border: none; background: none; padding: 12px 4px; }
.handle-field input:focus { border: none; }
.btn.small { padding: 8px 16px; font-size: .92em; width: auto; display: inline-block; }
.spacer { height: 12px; }

/* профиль */
.profile { text-align: center; }
.profile label { text-align: left; }
.profile input, .profile textarea { text-align: left; }
.profile-av { position: relative; margin: 8px auto 16px; width: 110px; cursor: pointer; }
.profile-av .av-edit {
  position: absolute; right: -2px; bottom: -2px; width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
  border: 3px solid var(--bg); font-size: .95em;
}
.profile-name { font-size: 1.35em; font-weight: 700; margin-top: 4px; }

/* форматирование в сообщениях */
.bubble a { color: inherit; text-decoration: underline; word-break: break-all; }
.msg.mine .bubble a { color: #eaf5ff; }
.bubble code { background: rgba(0,0,0,.28); border-radius: 4px; padding: 1px 5px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .92em; }
.bubble pre { background: rgba(0,0,0,.28); border-radius: 8px; padding: 8px 10px; margin: 4px 0; overflow-x: auto; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em; white-space: pre-wrap; }
.draft-label { color: var(--danger); }

/* превью ссылок */
.link-preview {
  display: block; margin-top: 6px; border-left: 3px solid var(--accent);
  background: rgba(0,0,0,.16); border-radius: 6px; overflow: hidden;
  text-decoration: none; color: inherit; max-width: 320px;
}
.msg.mine .link-preview { border-left-color: #cfe8ff; background: rgba(255,255,255,.14); }
.lp-img { width: 100%; height: 150px; background-size: cover; background-position: center; }
.lp-body { padding: 7px 10px; }
.lp-site { font-size: .74em; color: var(--accent); text-transform: lowercase; }
.msg.mine .lp-site { color: #dff1ff; }
.lp-title { font-weight: 600; font-size: .92em; margin-top: 2px; }
.lp-desc { font-size: .84em; opacity: .8; margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* панель ответа/редактирования над полем ввода */
.extra-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  background: var(--panel); border-top: 1px solid var(--border);
}
.extra-ico { display: inline-flex; color: var(--accent); }
.extra-ico svg { width: 20px; height: 20px; }
.extra-body { flex: 1; min-width: 0; border-left: 2px solid var(--accent); padding-left: 8px; }
.extra-title { font-size: .82em; color: var(--accent); font-weight: 600; }
.extra-text { font-size: .88em; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.extra-x { background: none; border: none; color: var(--muted); cursor: pointer; display: inline-flex; padding: 4px; }
.extra-x svg { width: 20px; height: 20px; }
.composer {
  display: flex; gap: 8px; padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--border);
}
.composer input {
  flex: 1; border-radius: 20px; background: var(--panel2);
  border: 1px solid var(--border); padding: 11px 16px;
}
.send-btn {
  flex: 0 0 auto; width: 44px; height: 44px; border: none; border-radius: 50%;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 20px -8px var(--ring); transition: transform .15s; }
.send-btn:hover { transform: scale(1.06); }
.send-btn svg { width: 20px; height: 20px; display: block; }
.attach-btn svg { width: 24px; height: 24px; }
/* Переключатель темы (как на сайте: sun/moon в скруглённой рамке) */
.theme-btn { border: 1px solid var(--border2); border-radius: 11px; width: 38px; height: 38px; padding: 0; }
.theme-btn:hover { border-color: var(--accent); background: none; }
.theme-seg { display: flex; gap: 8px; margin-top: 8px; }
.theme-seg button {
  flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--border2);
  background: var(--panel2); color: var(--text); cursor: pointer; font-size: .9em;
  display: flex; flex-direction: column; align-items: center; gap: 4px; transition: border-color .15s, color .15s; }
.theme-seg button svg { width: 20px; height: 20px; }
.theme-seg button.active { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 2px var(--ring); }

/* ---------- Опросы ---------- */
.msg.has-poll .bubble { min-width: 240px; }
.poll { display: flex; flex-direction: column; gap: 4px; }
.poll-q { font-weight: 600; line-height: 1.3; }
.poll-sub { font-size: .74em; opacity: .7; text-transform: uppercase; letter-spacing: .03em; margin-bottom: 4px; }
.poll-opts { display: flex; flex-direction: column; gap: 6px; margin: 2px 0; }
.poll-opt.vote {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--border);
  color: inherit; padding: 10px 12px; border-radius: 10px; font-size: .95em; cursor: pointer;
}
.msg.mine .poll-opt.vote { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.25); }
.poll-opt.vote:hover { background: var(--surface2); }
.poll-opt.vote.sel { border-color: var(--accent); }
.po-mark { flex: 0 0 auto; font-size: 1.05em; opacity: .85; }
.poll-opt.vote .po-text { flex: 1; }
.poll-opt.result { display: flex; flex-direction: column; gap: 4px; }
.po-row { display: flex; align-items: center; gap: 8px; font-size: .93em; }
.po-check { flex: 0 0 16px; color: var(--accent); font-weight: 700; }
.msg.mine .po-check { color: #fff; }
.po-text { word-break: break-word; }
.po-row .po-text { flex: 1; }
.po-pct { flex: 0 0 auto; font-variant-numeric: tabular-nums; opacity: .85; font-size: .9em; }
.po-bar { height: 5px; border-radius: 3px; background: var(--surface2); overflow: hidden; }
.po-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width .35s ease; }
.msg.mine .po-bar-fill { background: #fff; }
.poll-opt.result.lead .po-pct { font-weight: 700; opacity: 1; }
.po-voters { font-size: .78em; opacity: .65; padding-left: 24px; }
.poll-total { font-size: .78em; opacity: .6; margin-top: 2px; }
.poll-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.poll-btn {
  background: var(--surface2); border: 1px solid var(--border); color: inherit;
  padding: 9px; border-radius: 10px; font-size: .92em; cursor: pointer;
}
.poll-btn:disabled { opacity: .4; cursor: default; }
.poll-link {
  background: none; border: none; color: var(--accent); font-size: .86em;
  cursor: pointer; padding: 4px; align-self: center;
}
.msg.mine .poll-link { color: #eaf4ff; }

/* Модалка создания опроса */
.poll-modal {
  margin: auto; width: 360px; max-width: 92vw; max-height: 84vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 16px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.pm-head { font-weight: 600; text-align: center; font-size: 1.05em; }
.pm-q {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: 1em; resize: vertical; font-family: inherit;
}
.pm-q:focus { border-color: var(--accent); outline: none; }
.pm-label { font-size: .78em; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 4px; }
.pm-options { display: flex; flex-direction: column; gap: 8px; }
.pm-opt-input {
  width: 100%; background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: .95em;
}
.pm-opt-input:focus { border-color: var(--accent); outline: none; }
.pm-toggles { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.pm-toggle { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: .92em; cursor: pointer; margin: 0; }
.pm-toggle input { width: auto; }
.pm-actions { display: flex; gap: 8px; margin-top: 6px; }
.pm-btn { flex: 1; padding: 11px; border-radius: 10px; border: none; font-size: .95em; cursor: pointer; }
.pm-btn.cancel { background: var(--panel2); color: var(--text); }
.pm-btn.create { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }
.pm-btn.create:disabled { opacity: .45; cursor: default; }

/* Переключатель видимости (публичный/закрытый) на экранах создания */
.seg { display: flex; gap: 8px; margin: 4px 0; }
.seg-btn { flex: 1; padding: 11px; border-radius: 11px; border: 1px solid var(--border2);
  background: var(--panel2); color: var(--text); cursor: pointer; font-size: .92em;
  transition: border-color .15s, color .15s, box-shadow .15s; }
.seg-btn.active { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 2px var(--ring); }

/* ---------- Управление группой/каналом (блок 3) ---------- */
.cfgrow { display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border); }
.mini-select { width: auto; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border2);
  background: var(--panel2); color: var(--text); font-size: .9em; }
.invite-row { display: flex; gap: 8px; align-items: center; margin: 8px 0 6px; }
.invite-row input { flex: 1; font-size: .85em; }
.invite-row .btn.small { margin: 0; flex: 0 0 auto; white-space: nowrap; }

/* Плейсхолдер-шиммер для картинок, пока грузятся */
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.att-img, .att-video, .album-media {
  background: linear-gradient(100deg, var(--surface) 25%, var(--surface2) 50%, var(--surface) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite linear;
}
/* Значок «без звука» в списке диалогов */
.mute-ico { display: inline-flex; vertical-align: -0.12em; margin-left: 5px; color: var(--faint); }
.mute-ico svg { width: 14px; height: 14px; }
.badge.muted { background: var(--faint); }

/* ---------- Разделители дат, группировка, кнопка «вниз» ---------- */
.date-divider { display: flex; justify-content: center; margin: 12px 0 6px; }
.date-divider span {
  background: var(--surface); color: var(--muted); font-size: .74em; font-weight: 600;
  padding: 3px 12px; border-radius: 999px; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.msg.same-sender { margin-top: -2px; }
.mention { color: var(--accent); font-weight: 600; cursor: pointer; }
.msg.mine .mention { color: #fff; text-decoration: underline; }
.new-divider { display: flex; justify-content: center; margin: 14px 0 8px; position: relative; }
.new-divider::before { content: ""; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: var(--accent); opacity: .35; }
.new-divider span {
  position: relative; background: var(--accent); color: #fff; font-size: .72em; font-weight: 700;
  padding: 3px 14px; border-radius: 999px; letter-spacing: .02em;
}
.msg.same-sender .sender-name { display: none; }
/* Скругление «хвоста» у сгруппированных подряд сообщений (как в Telegram) */
.msg.same-sender.mine .bubble { border-top-right-radius: 7px; }
.msg.same-sender:not(.mine) .bubble { border-top-left-radius: 7px; }
#main { position: relative; }
.scroll-down {
  position: absolute; right: 14px; bottom: 84px; z-index: 8;
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.3); transition: transform .12s, opacity .2s;
}
.scroll-down:hover { transform: translateY(-2px); }
.scroll-down svg { width: 22px; height: 22px; }
.sd-badge {
  position: absolute; top: -6px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 999px; background: var(--accent); color: #fff; font-size: .72em; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
/* Иконки внутри кнопок с подписью (замена эмодзи) */
.btn-ico { display: inline-flex; vertical-align: -0.15em; }
.btn-ico svg { width: 1.05em; height: 1.05em; }
.btn .btn-ico, .seg-btn .btn-ico { margin-right: 6px; }
.confirm-btn .btn-ico { margin-right: 8px; }
.ctx-item .ci svg { width: 18px; height: 18px; display: block; }
.avatar.avatar-ico svg { width: 55%; height: 55%; stroke: #fff; }
.fwd-label svg { width: .95em; height: .95em; vertical-align: -0.12em; }

/* ---------- Поиск по сообщениям в чате ---------- */
.search-bar { flex: 0 0 auto; background: var(--panel); border-bottom: 1px solid var(--border); padding: 8px 12px; }
.chat-search-in { margin-bottom: 0; }
.search-results { max-height: 42vh; overflow-y: auto; margin-top: 6px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.sr-row .grow { min-width: 0; }
.sr-row .preview { white-space: normal; }

/* ---------- GIF-пикер (Tenor) ---------- */
.gif-modal {
  margin: auto; width: 420px; max-width: 94vw; height: 70vh; max-height: 560px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 12px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.gif-head { display: flex; align-items: center; gap: 8px; }
.gif-search { flex: 1; margin-bottom: 0; }
.gif-grid { flex: 1; overflow-y: auto; column-count: 3; column-gap: 5px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.gif-grid .hint { column-span: all; }
.gif-cell { display: block; width: 100%; padding: 0; margin: 0 0 5px; border: none; cursor: pointer;
  background: var(--surface); border-radius: 8px; overflow: hidden; break-inside: avoid;
  transition: transform .12s, opacity .2s; }
.gif-cell:hover { transform: scale(1.03); }
.gif-cell img { width: 100%; display: block; }
.gif-cell.picking { opacity: .4; pointer-events: none; }
@media (max-width: 520px) { .gif-grid { column-count: 2; } }

/* ---------- Анимации и плавность (как в Telegram) ---------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes panelIn { from { transform: translateX(18px); opacity: .3; } to { transform: none; opacity: 1; } }
@keyframes sidebarIn { from { transform: translateX(-18px); opacity: .3; } to { transform: none; opacity: 1; } }
@keyframes msgIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes msgOut { to { opacity: 0; transform: scale(.85); height: 0; margin: 0; padding: 0; } }
@keyframes popIn { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }

/* Появление контента экранов */
.content, .messages, .auth-wrap { animation: fadeIn .2s ease; }
@media (max-width: 899px) {
  .app-shell.chat-open #main { animation: panelIn .24s cubic-bezier(.22,.61,.36,1); }
  .app-shell:not(.chat-open) #sidebar { animation: sidebarIn .22s cubic-bezier(.22,.61,.36,1); }
}

/* Отклик на нажатие по строкам/кнопкам */
.row { transition: background .15s, transform .08s; }
.row:active { transform: scale(.985); }
.confirm-btn, .btn, .tab, .send-btn, .icon-btn { transition: transform .08s, background .15s, color .15s, box-shadow .2s, filter .2s; }
.confirm-btn:active, .tab:active, .icon-btn:active { transform: scale(.94); }

/* Живое появление/исчезание сообщений */
.msg.msg-in { animation: msgIn .26s cubic-bezier(.22,.61,.36,1); }
.msg.msg-out { animation: msgOut .28s ease forwards; overflow: hidden; pointer-events: none; }

/* Всплывающие карточки/меню — мягкое появление */
.confirm-card, .poll-modal, .gif-modal, .fwd-card, .ctx-group { animation: popIn .16s ease; }

/* Просмотр аватара во весь экран (лайтбокс, как в Telegram) */
.avatar { cursor: pointer; }
.lightbox {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.85); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  animation: fadeIn .18s ease; padding: 24px;
}
.lightbox img { max-width: min(900px, 94vw); max-height: 88vh; border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6); animation: popIn .2s ease; }
/* Свайп-вправо для ответа: стрелка слева проявляется при сдвиге */
.msg { position: relative; }
.msg::before {
  content: ""; position: absolute; left: -26px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; opacity: 0; transition: opacity .15s; pointer-events: none;
  background: var(--accent);
  -webkit-mask: var(--ic-reply) center/contain no-repeat; mask: var(--ic-reply) center/contain no-repeat;
}
.msg.swipe-reply::before { opacity: 1; }

/* Предпросмотр медиа с подписью перед отправкой */
.media-preview-ov {
  position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.6); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  animation: fadeIn .18s ease; padding: 20px;
}
.media-preview {
  width: 100%; max-width: 460px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; overflow: hidden; display: flex; flex-direction: column; animation: popIn .2s ease;
  max-height: 88vh;
}
.mp-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.mp-title { flex: 1; font-weight: 600; }
.mp-thumbs { padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.mp-thumbs.multi { display: grid; grid-template-columns: repeat(2, 1fr); }
.mp-thumb { position: relative; border-radius: 12px; overflow: hidden; background: var(--surface); }
.mp-thumb img, .mp-thumb video { width: 100%; max-height: 60vh; object-fit: contain; display: block; }
.mp-thumbs.multi .mp-thumb img, .mp-thumbs.multi .mp-thumb video { aspect-ratio: 1; object-fit: cover; max-height: none; }
.mp-play { position: absolute; right: 8px; bottom: 8px; color: #fff; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.mp-play svg { width: 22px; height: 22px; }
.mp-foot { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); }
.mp-caption { flex: 1; }

/* Спойлер: размытый текст, тап открывает */
.spoiler {
  color: transparent; text-shadow: 0 0 9px var(--text);
  background: color-mix(in srgb, var(--text) 8%, transparent); border-radius: 4px; padding: 0 2px;
  cursor: pointer; -webkit-user-select: none; user-select: none;
  transition: color .25s, text-shadow .25s, background .25s;
}
.spoiler.revealed { color: inherit; text-shadow: none; background: transparent; cursor: text; user-select: text; }

/* Галерея альбома */
.gallery-lb { flex-direction: row; }
.glb-stage { flex: 1; display: flex; align-items: center; justify-content: center; min-width: 0; }
.glb-stage img, .glb-stage video {
  max-width: min(900px, 88vw); max-height: 88vh; border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6); animation: popIn .2s ease;
}
.glb-nav {
  position: fixed; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 48px; height: 48px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(255,255,255,.14); color: #fff; font-size: 28px; line-height: 1;
  display: flex; align-items: center; justify-content: center; transition: background .15s;
}
.glb-nav:hover { background: rgba(255,255,255,.26); }
.glb-nav svg { width: 26px; height: 26px; }
.glb-nav.prev { left: 16px; }
.glb-nav.next { right: 16px; }
.glb-counter {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 2;
  color: #fff; font-size: .9em; background: rgba(0,0,0,.4); padding: 4px 12px; border-radius: 20px;
}
.glb-icon {
  position: fixed; top: 14px; right: 16px; z-index: 3;
  width: 42px; height: 42px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(255,255,255,.14); color: #fff; display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.glb-icon:hover { background: rgba(255,255,255,.26); }
.glb-icon svg { width: 20px; height: 20px; }
.glb-caption {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 2;
  max-width: 86vw; color: #fff; text-align: center; font-size: .95em;
  background: rgba(0,0,0,.45); padding: 8px 16px; border-radius: 14px; text-shadow: 0 1px 3px rgba(0,0,0,.6);
}
@media (max-width: 600px) { .glb-nav { width: 40px; height: 40px; font-size: 24px; } }

.lightbox .lb-fallback {
  width: min(320px, 80vw); aspect-ratio: 1; border-radius: 24px; display: flex; align-items: center;
  justify-content: center; font-size: 6em; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); animation: popIn .2s ease;
}

/* ================= Истории (Stories) ================= */
.avatar.st { width: 54px; height: 54px; font-size: 1.15em; }

.stories-bar {
  display: flex; gap: 14px; overflow-x: auto; padding: 2px 4px 6px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.stories-bar::-webkit-scrollbar { display: none; }
.story-cell { flex: 0 0 auto; width: 66px; text-align: center; cursor: pointer; }
.story-ring {
  width: 62px; height: 62px; border-radius: 50%; margin: 0 auto;
  padding: 3px; box-sizing: border-box; position: relative;
  background: linear-gradient(135deg, #58a6f0, #7c5cff, #e5484d);
}
.story-cell.seen .story-ring { background: var(--faint); }
.story-ring.plain { background: var(--surface2); }
.story-ring .avatar {
  width: 100%; height: 100%; border: 2px solid var(--bg); box-sizing: border-box;
}
.story-add-badge {
  position: absolute; right: -2px; bottom: -2px; width: 22px; height: 22px;
  background: var(--accent); color: #fff; border-radius: 50%;
  border: 2px solid var(--bg); display: flex; align-items: center; justify-content: center;
}
.story-add-badge svg { width: 16px; height: 16px; }
.story-add-badge.sm { width: 20px; height: 20px; }
.story-name {
  font-size: .72em; color: var(--muted); margin-top: 5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Просмотрщик */
.story-viewer {
  position: fixed; inset: 0; z-index: 3000; background: #000;
  display: flex; flex-direction: column; animation: fadeIn .18s ease;
}
.sv-progress { display: flex; gap: 4px; padding: 10px 12px 4px; }
.sv-bar { flex: 1; height: 3px; border-radius: 3px; background: rgba(255,255,255,.28); overflow: hidden; }
.sv-bar span { display: block; height: 100%; width: 0; background: #fff; border-radius: 3px; }
.sv-bar span.done { width: 100%; }
.sv-bar span.run { animation: svFill linear forwards; animation-duration: 5s; }
.story-viewer.paused .sv-bar span.run { animation-play-state: paused; }
@keyframes svFill { from { width: 0; } to { width: 100%; } }
.sv-head {
  display: flex; align-items: center; gap: 10px; padding: 6px 14px 10px; color: #fff;
  position: relative; z-index: 5;
}
.sv-who { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.sv-who .avatar { width: 38px; height: 38px; }
.sv-who-txt .name { font-weight: 600; font-size: .95em; }
.sv-time { font-size: .78em; opacity: .8; }
.sv-close { background: none; border: none; color: #fff; cursor: pointer; padding: 6px; }
.sv-close svg { width: 24px; height: 24px; }
.sv-stage {
  flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.sv-stage img, .sv-stage video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.sv-caption {
  color: #fff; text-align: center; padding: 12px 20px; font-size: .95em;
  text-shadow: 0 1px 4px rgba(0,0,0,.6); position: relative; z-index: 5;
}
.sv-foot {
  display: flex; align-items: center; justify-content: center; gap: 20px;
  padding: 10px 16px 22px; position: relative; z-index: 5;
}
.sv-views, .sv-del {
  background: rgba(255,255,255,.14); border: none; color: #fff; cursor: pointer;
  display: flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 20px; font-size: .9em;
}
.sv-del { background: rgba(229,72,77,.22); }
.sv-views svg, .sv-del svg { width: 18px; height: 18px; }
.sv-tap { position: absolute; top: 60px; bottom: 80px; width: 40%; z-index: 3; cursor: pointer; }
.sv-tap.left { left: 0; }
.sv-tap.right { right: 0; }
.sv-viewer-list { max-height: 46vh; overflow-y: auto; margin: 4px 0 10px; }

/* Нижний лист (bottom sheet) — поверх просмотрщика историй (z 3000) */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 3600; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0,0,0,.5); opacity: 0; transition: opacity .25s;
}
.sheet-overlay.open { opacity: 1; }
.sheet {
  width: 100%; max-width: 520px; background: var(--panel); border-radius: 20px 20px 0 0;
  max-height: 72vh; display: flex; flex-direction: column; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .28s cubic-bezier(.2,.8,.2,1);
  box-shadow: 0 -12px 44px rgba(0,0,0,.45);
}
.sheet-overlay.open .sheet { transform: translateY(0); }
.sheet-grip { width: 40px; height: 4px; border-radius: 4px; background: var(--border2); margin: 4px auto 12px; flex: 0 0 auto; }
.sheet-title { font-weight: 600; display: flex; align-items: center; gap: 8px; padding: 0 2px 10px;
  border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.sheet-eye { display: inline-flex; color: var(--muted); }
.sheet-eye svg { width: 18px; height: 18px; }
.sheet-body { overflow-y: auto; margin-top: 8px; min-height: 60px; }
.sheet-body .row { cursor: default; }

/* Ответ + реакции на историю */
.sv-reply { width: 100%; max-width: 520px; margin: 0 auto; }
.sv-reacts { display: flex; justify-content: center; gap: 6px; margin-bottom: 10px; }
.sv-react {
  background: rgba(255,255,255,.14); border: none; border-radius: 50%; width: 42px; height: 42px;
  font-size: 20px; cursor: pointer; transition: transform .1s, background .15s;
}
.sv-react:hover { background: rgba(255,255,255,.26); }
.sv-react:active { transform: scale(1.25); }
.sv-react.chosen { background: var(--accent); transform: scale(1.1); }
.viewer-react { font-size: 1.2em; flex: 0 0 auto; }

/* Превью истории в пузыре-ответе на историю */
.story-reply-quote { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; opacity: .92;
  border-left: 2px solid var(--accent); padding: 3px 8px; border-radius: 6px; background: rgba(127,127,127,.12); }
.msg.mine .story-reply-quote { border-left-color: rgba(255,255,255,.7); background: rgba(255,255,255,.14); }
.srq-thumb { width: 34px; height: 34px; border-radius: 6px; background-size: cover; background-position: center;
  flex: 0 0 auto; background-color: var(--surface); }
.srq-vid { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.srq-vid svg { width: 18px; height: 18px; }
.srq-label { font-size: .78em; color: var(--accent); font-weight: 600; }
.msg.mine .srq-label { color: #fff; }
.sv-reply-row { display: flex; gap: 8px; align-items: center; }
.sv-reply-input {
  flex: 1; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.2); color: #fff;
  border-radius: 22px; padding: 10px 16px;
}
.sv-reply-input::placeholder { color: rgba(255,255,255,.6); }
.sv-reply-send {
  background: var(--accent); border: none; color: #fff; width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; cursor: pointer; flex: 0 0 auto;
}
.sv-reply-send svg { width: 20px; height: 20px; }

/* Тост */
.toast {
  position: fixed; bottom: 88px; left: 50%; transform: translateX(-50%) translateY(16px);
  background: rgba(20,24,31,.94); color: #fff; padding: 10px 20px; border-radius: 22px;
  font-size: .9em; z-index: 4000; opacity: 0; transition: opacity .3s, transform .3s; pointer-events: none;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ Голосовые сообщения ============ */
.voice { display: flex; align-items: center; gap: 10px; min-width: 180px; max-width: 280px; padding: 4px 2px; }
.voice-play {
  flex: 0 0 auto; width: 38px; height: 38px; border: none; border-radius: 50%;
  background: var(--accent); color: #fff; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.msg.mine .voice-play { background: rgba(255,255,255,.22); }
.voice-play svg { width: 18px; height: 18px; }
.voice-body { flex: 1; min-width: 0; }
.voice-wave { display: flex; align-items: center; gap: 2px; height: 30px; cursor: pointer; }
.vw-bar {
  flex: 1; min-width: 2px; max-width: 4px; border-radius: 2px;
  background: color-mix(in srgb, var(--accent) 35%, transparent); transition: background .1s;
}
.msg.mine .vw-bar { background: rgba(255,255,255,.35); }
.vw-bar.played { background: var(--accent); }
.msg.mine .vw-bar.played { background: #fff; }
.voice-time { flex: 0 0 auto; font-size: .78em; color: var(--muted); min-width: 30px; text-align: right; }
.msg.mine .voice-time { color: rgba(255,255,255,.85); }

/* ============ Видео-кружки ============ */
.circle-note { position: relative; width: 200px; height: 200px; max-width: 62vw; max-height: 62vw; cursor: pointer; }
.circle-video {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover;
  background: #000; display: block;
}
.circle-note.active .circle-video { box-shadow: 0 0 0 3px var(--accent); }
.circle-dur {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 3px;
  background: rgba(0,0,0,.55); color: #fff; font-size: .72em; padding: 2px 8px; border-radius: 12px;
}
.circle-dur svg { width: 11px; height: 11px; }
.circle-note.active .circle-dur { display: none; }

/* ============ Кнопка микрофона в композере ============ */
.mic-btn { flex: 0 0 auto; width: 44px; height: 44px; }
.mic-btn svg { width: 23px; height: 23px; }

/* ============ Панель записи голосового ============ */
.rec-bar {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--border);
}
.rec-dot { flex: 0 0 auto; width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: recPulse 1.1s infinite; }
@keyframes recPulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 42px; }
.rec-hint { flex: 1; color: var(--muted); font-size: .9em; }
.rec-cancel { color: var(--danger); }
.rec-send { flex: 0 0 auto; }

/* ============ Модалка записи кружка ============ */
.circle-rec-ov { display: flex; }
.circle-rec {
  margin: auto; background: var(--panel); border: 1px solid var(--border);
  border-radius: 20px; padding: 22px; display: flex; flex-direction: column;
  align-items: center; gap: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.circle-rec-frame { position: relative; width: 240px; height: 240px; max-width: 74vw; max-height: 74vw; }
.circle-rec-video { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; background: #000; transform: scaleX(-1); }
.circle-rec-dot { position: absolute; top: 12px; right: 12px; width: 14px; height: 14px; border-radius: 50%; background: var(--danger); animation: recPulse 1.1s infinite; }
.circle-rec-time { color: var(--muted); font-size: .9em; }
.circle-rec-btns { display: flex; gap: 10px; width: 100%; }
.circle-rec-btns .confirm-btn { flex: 1; }

/* ============ Кнопки-модалки: основной вариант и ряды действий ============ */
.confirm-btn.primary { background: var(--accent); color: #fff; }
.confirm-actions { display: flex; gap: 8px; }
.confirm-actions .confirm-btn { flex: 1; }
.sch-input {
  width: 100%; border-radius: 10px; border: 1px solid var(--border2);
  background: var(--panel2); color: var(--text); padding: 10px 12px; font-size: 1em;
}

/* ============ Bottom-sheet: список запланированных ============ */
.sheet { margin: auto auto 0; width: 100%; max-width: 440px; background: var(--panel);
  border-radius: 16px 16px 0 0; border: 1px solid var(--border); border-bottom: none;
  display: flex; flex-direction: column; max-height: 70vh; box-shadow: 0 -8px 40px rgba(0,0,0,.4); }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.sheet-title { flex: 1; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.sheet-body { overflow-y: auto; padding: 6px 10px 16px; }
.sch-row { display: flex; align-items: center; gap: 10px; padding: 10px 6px; border-bottom: 1px solid var(--border); }
.sch-row .grow { flex: 1; min-width: 0; }
.sch-when { font-size: .82em; color: var(--accent); font-weight: 600; }
.sch-text { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sch-del { color: var(--danger); }

/* ============ Радио-список (авто-удаление) ============ */
.radio-list { display: flex; flex-direction: column; gap: 2px; }
.radio-row { display: flex; align-items: center; gap: 10px; padding: 11px 8px; background: none;
  border: none; color: var(--text); font-size: 1em; cursor: pointer; border-radius: 8px; text-align: left; }
.radio-row:hover { background: var(--surface); }
.radio-dot { flex: 0 0 auto; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border2); }
.radio-row.sel .radio-dot { border-color: var(--accent); background:
  radial-gradient(circle at center, var(--accent) 0 5px, transparent 6px); }
.radio-row.sel { color: var(--accent); }

/* ============ Мультиаккаунт (переключатель) ============ */
.acct-row { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px;
  cursor: pointer; border: 1px solid var(--border); margin-bottom: 6px; background: var(--panel); }
.acct-row:hover { background: var(--surface); }
.acct-row.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--panel)); cursor: default; }
.acct-row .grow { min-width: 0; flex: 1; }
.acct-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-row .handle { color: var(--muted); font-size: .85em; }
.acct-badge { flex: 0 0 auto; color: var(--accent); display: inline-flex; }
.acct-badge svg { width: 20px; height: 20px; }
.acct-x { flex: 0 0 auto; background: none; border: none; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; }
.acct-x:hover { color: var(--danger); background: var(--surface); }
.acct-x svg { width: 18px; height: 18px; display: block; }
.acct-add { width: 100%; }

/* ============ Звонки (WebRTC) ============ */
.call-overlay {
  position: fixed; inset: 0; z-index: 5000; background: #0b1017;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff;
}
.call-remote {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  background: #0b1017; display: none;
}
.call-overlay.video-mode .call-remote { display: block; }
.call-overlay.video-mode .call-center { opacity: 0; pointer-events: none; }
.call-center {
  position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center;
  gap: 12px; transition: opacity .3s;
}
.call-avatar .avatar { width: 120px; height: 120px; font-size: 2.6em; }
.call-name { font-size: 1.5em; font-weight: 600; }
.call-status { color: #b9c4d0; font-size: 1em; font-variant-numeric: tabular-nums; }
.call-local {
  position: absolute; right: 14px; bottom: 110px; width: 110px; height: 150px;
  object-fit: cover; border-radius: 14px; background: #000; z-index: 3;
  transform: scaleX(-1); box-shadow: 0 6px 24px rgba(0,0,0,.5); border: 1px solid rgba(255,255,255,.15);
}
.call-controls {
  position: absolute; bottom: 40px; left: 0; right: 0; z-index: 4;
  display: flex; align-items: center; justify-content: center; gap: 22px;
  padding-bottom: env(safe-area-inset-bottom);
}
.call-btn {
  width: 62px; height: 62px; border-radius: 50%; border: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.16); color: #fff; transition: transform .12s, background .15s;
}
.call-btn:hover { transform: scale(1.06); }
.call-btn svg { width: 26px; height: 26px; }
.call-btn.accept { background: #2fb344; }
.call-btn.decline { background: var(--danger); }
.call-btn.toggle.off { background: #fff; color: #14181f; }

/* Запись звонка в истории чата */
.call-log { display: inline-flex; align-items: center; gap: 8px; }
.call-log-ico { display: inline-flex; opacity: .85; }
.call-log-ico svg { width: 17px; height: 17px; }
.call-log.missed { color: var(--danger); }
.msg.mine .call-log.missed { color: #ffd7d7; }
