/* Protocol — тёмная тема в духе Telegram */
:root {
  --bg: #0e1621;
  --panel: #17212b;
  --panel-2: #1c2733;
  --hover: #202b36;
  --selected: #2b5278;
  --out: #2b5278;
  --out-deep: #25527b;
  --in: #182533;
  --text: #ffffff;
  --muted: #7f91a4;
  --faint: #5a6e82;
  --accent: #5288c1;
  --accent-bright: #6ab3f3;
  --danger: #e53935;
  --badge: #5288c1;
  --radius: 12px;
  --shadow: 0 8px 40px rgba(0,0,0,.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
#app { height: 100dvh; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, textarea { font: inherit; color: var(--text); }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: #2f3d4d; border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Кнопки, поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 600;
  transition: filter .15s, background .15s;
  user-select: none;
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--hover); }
.btn.danger { background: var(--danger); }
.btn.wide { width: 100%; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%; padding: 11px 14px; border-radius: 10px;
  background: var(--bg); border: 1px solid #2a3a4a; color: var(--text);
  outline: none; transition: border-color .15s;
}
.input:focus { border-color: var(--accent); }
textarea.input { resize: none; }
.hint { font-size: 12px; color: var(--faint); margin-top: 4px; }
.error-text { color: #ff7d7d; font-size: 13px; min-height: 18px; margin: 4px 0 8px; }

/* ---------- Аватары ---------- */
.avatar {
  position: relative; flex: none;
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: #fff; font-size: 17px;
  background: var(--accent); user-select: none; overflow: visible;
}
.avatar img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  border-radius: 50%; object-fit: cover; z-index: 1;
}
.avatar .online-dot { z-index: 2; }
.avatar.channel::after, .avatar.group::after { z-index: 3; }
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }
.avatar.lg { width: 72px; height: 72px; font-size: 27px; }
.avatar.xl { width: 96px; height: 96px; font-size: 36px; }
.avatar .online-dot {
  position: absolute; right: 0; bottom: 0;
  width: 12px; height: 12px; border-radius: 50%;
  background: #4dcd5e; border: 2px solid var(--panel);
}
.avatar.channel::after, .avatar.group::after {
  content: ''; position: absolute; right: -2px; bottom: -2px;
  width: 17px; height: 17px; border-radius: 50%;
  background: var(--panel-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%236ab3f3'%3E%3Cpath d='M3 10v4h4l5 5V5L7 10H3zm13.5 2c0-1.8-1-3.3-2.5-4v8c1.5-.7 2.5-2.2 2.5-4zM14 3.2v2.1c2.9.9 5 3.5 5 6.7s-2.1 5.8-5 6.7v2.1c4-.9 7-4.5 7-8.8s-3-7.9-7-8.8z'/%3E%3C/svg%3E") center/11px no-repeat;
}

/* ---------- Экран авторизации ---------- */
.auth-screen {
  height: 100dvh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 800px at 20% 0%, #17212b 0%, #0e1621 60%);
  padding: 20px;
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--panel); border-radius: 16px; padding: 32px 28px;
  box-shadow: var(--shadow);
}
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 22px; }
.auth-logo img { width: 88px; height: 88px; border-radius: 22px; box-shadow: 0 4px 24px rgba(82,136,193,.25); }
.auth-logo h1 { font-size: 26px; font-weight: 700; letter-spacing: .5px; }
.auth-logo p { color: var(--muted); font-size: 13px; margin-top: -8px; }
.auth-tabs { display: flex; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.auth-tabs button {
  flex: 1; padding: 8px; border-radius: 8px; color: var(--muted); font-weight: 600;
}
.auth-tabs button.active { background: var(--accent); color: #fff; }

/* ---------- Подключение к серверу ---------- */
.connect-note { font-size: 13px; color: var(--muted); margin-bottom: 16px; text-align: center; }

/* ---------- Каркас приложения ---------- */
.app { display: flex; height: 100dvh; overflow: hidden; }
.sidebar {
  width: 380px; flex: none; display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid #101921;
  min-width: 0;
}
.chat-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

/* ---------- Шапка сайдбара ---------- */
.sidebar-header {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; flex: none;
}
.sidebar-header .avatar { cursor: pointer; }
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: #4dcd5e; flex: none; transition: background .3s; }
.conn-dot.off { background: #e57373; }
.search-wrap { position: relative; flex: 1; }
.search-wrap svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; fill: var(--faint); pointer-events: none;
}
.search-wrap input {
  width: 100%; padding: 9px 12px 9px 34px; border-radius: 18px;
  background: #242f3d; border: 1px solid transparent; color: var(--text); outline: none;
  transition: border-color .15s, background .15s;
}
.search-wrap input:focus { border-color: var(--accent); background: #202b36; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn svg { width: 21px; height: 21px; fill: currentColor; }

/* ---------- Список чатов ---------- */
.chat-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.chat-item {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 10px; border-radius: var(--radius);
  cursor: pointer; user-select: none;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--selected); }
.chat-item .ci-body { flex: 1; min-width: 0; }
.ci-top, .ci-bottom { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ci-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-time { font-size: 12px; color: var(--muted); flex: none; white-space: nowrap; }
.ci-preview { font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.ci-preview .unread-inline { color: var(--accent-bright); font-weight: 600; }
.badge {
  flex: none; min-width: 21px; height: 21px; padding: 0 6px; border-radius: 11px;
  background: var(--badge); color: #fff; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.list-section { padding: 14px 12px 6px; font-size: 13px; font-weight: 700; color: var(--accent-bright); text-transform: uppercase; letter-spacing: .4px; }
.empty-list { padding: 40px 20px; text-align: center; color: var(--faint); font-size: 14px; }

/* ---------- Шапка чата ---------- */
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px; background: var(--panel);
  border-bottom: 1px solid #101921; flex: none; min-height: 58px;
  cursor: pointer;
}
.chat-header .back { display: none; }
.ch-body { flex: 1; min-width: 0; }
.ch-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-sub.online { color: var(--accent-bright); }

/* ---------- Сообщения ---------- */
.messages { flex: 1; overflow-y: auto; padding: 12px 5% 8px; scroll-behavior: smooth; }
.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  color: var(--muted);
}
.chat-empty img { width: 108px; height: 108px; border-radius: 26px; opacity: .9; }
.chat-empty h2 { font-weight: 600; color: var(--text); }
.date-sep { display: flex; justify-content: center; margin: 10px 0 6px; }
.date-sep span {
  background: rgba(0,0,0,.35); border-radius: 13px; padding: 3px 12px;
  font-size: 12.5px; color: #c9d6e2;
}
.msg-row { display: flex; margin: 1.5px 0; }
.msg-row.out { justify-content: flex-end; }
.msg-row.svc { justify-content: center; margin: 6px 0; }
.msg-row.svc span { background: rgba(0,0,0,.3); padding: 3px 12px; border-radius: 12px; font-size: 12.5px; color: #b8c6d4; }
.bubble {
  position: relative; max-width: min(72%, 520px);
  padding: 7px 11px 6px; border-radius: 14px;
  background: var(--in); word-wrap: break-word; overflow-wrap: break-word; white-space: pre-wrap;
  cursor: default;
}
.msg-row.out .bubble { background: var(--out); border-bottom-right-radius: 5px; }
.msg-row.in .bubble { border-bottom-left-radius: 5px; }
.bubble .b-sender { font-size: 13px; font-weight: 700; color: var(--accent-bright); margin-bottom: 2px; }
.bubble .b-text a { color: var(--accent-bright); }
.b-meta {
  display: inline-flex; align-items: center; gap: 4px;
  float: right; margin: 6px -3px -2px 8px;
  font-size: 11.5px; color: rgba(255,255,255,.55); white-space: nowrap; user-select: none;
}
.b-meta .ticks { fill: currentColor; width: 16px; height: 11px; display: block; }
.b-meta .ticks.read { color: #62d0ff; }
.b-meta .views { display: inline-flex; align-items: center; gap: 3px; }
.b-meta .views svg { width: 13px; height: 13px; fill: currentColor; }
.bubble.deleted .b-text { color: var(--faint); font-style: italic; }
.bubble .b-edited { font-size: 11px; color: rgba(255,255,255,.45); margin-right: 2px; }
.bubble.pending { opacity: .55; }
.typing-note { text-align: center; color: var(--faint); font-size: 12.5px; padding: 4px; }

/* ---------- Поле ввода ---------- */
.composer { flex: none; padding: 9px 5% 12px; background: var(--bg); }
.composer.editing { background: #142031; border-top: 1px solid #27405e; }
.composer-bar {
  display: flex; align-items: flex-end; gap: 9px;
  background: var(--panel); border-radius: 16px; padding: 6px 6px 6px 16px;
}
.composer textarea {
  flex: 1; background: none; border: none; outline: none; resize: none;
  max-height: 132px; padding: 8px 0; line-height: 1.4;
}
.send-btn {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
  transition: filter .15s, transform .1s;
}
.send-btn:hover { filter: brightness(1.15); }
.send-btn:active { transform: scale(.94); }
.send-btn svg { width: 20px; height: 20px; fill: #fff; margin: 1px 2px 0 0; }
.edit-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 13px; color: var(--accent-bright); padding: 5px 8px 9px;
}
.edit-banner .cancel-edit { color: var(--muted); }
.composer-note {
  text-align: center; color: var(--muted); font-size: 13.5px;
  background: var(--panel); border-radius: 14px; padding: 13px;
}
.btn.subscribe-btn { padding: 11px 26px; border-radius: 14px; }

/* ---------- Модалки и меню ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 18px; animation: fadeIn .15s;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 420px; max-height: 86dvh; overflow-y: auto;
  background: var(--panel-2); border-radius: 14px; padding: 22px;
  box-shadow: var(--shadow); animation: slideUp .18s ease-out;
}
@keyframes slideUp { from { transform: translateY(14px); opacity: 0; } }
.modal h3 { font-size: 18px; margin-bottom: 16px; display: flex; align-items: center; gap: 10px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }
.ctx-menu {
  position: fixed; z-index: 200; min-width: 180px;
  background: var(--panel-2); border-radius: 10px; padding: 5px;
  box-shadow: var(--shadow); animation: slideUp .12s ease-out;
}
.ctx-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border-radius: 7px; text-align: left; font-size: 14px;
}
.ctx-menu button:hover { background: var(--hover); }
.ctx-menu button.danger { color: #ff8a80; }
.ctx-menu svg { width: 17px; height: 17px; fill: currentColor; flex: none; }

/* ---------- Профиль / участники ---------- */
.profile-head { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 18px; }
.profile-head .name { font-size: 19px; font-weight: 700; }
.profile-head .username { color: var(--accent-bright); font-size: 14px; }
.profile-head .status { color: var(--muted); font-size: 13px; }
.member-row {
  display: flex; align-items: center; gap: 11px; padding: 7px 8px;
  border-radius: 10px; cursor: pointer;
}
.member-row:hover { background: var(--hover); }
.member-row .mr-body { flex: 1; min-width: 0; }
.member-row .mr-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-row .mr-sub { font-size: 12.5px; color: var(--muted); }
.member-row .role-tag { font-size: 12px; color: var(--accent-bright); flex: none; }
.member-row .kick { color: var(--faint); width: 30px; height: 30px; border-radius: 50%; }
.member-row .kick:hover { color: #ff8a80; background: var(--hover); }
.pick-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.pick-chips .chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--hover); border-radius: 14px; padding: 3px 6px 3px 4px; font-size: 13px;
}
.pick-chips .chip button { color: var(--muted); font-size: 15px; line-height: 1; padding: 0 4px; }
.divider { height: 1px; background: #26333f; margin: 14px 0; }
.muted { color: var(--muted); font-size: 13.5px; }
.center { text-align: center; }

/* ---------- Аватары с фото, профиль, настройки ---------- */
.msg-row.in { align-items: flex-end; }
.msg-ava { width: 30px; flex: none; margin-right: 8px; }
.msg-ava:empty { display: none; }
.msg-ava .avatar { width: 28px; height: 28px; font-size: 11px; }
.msg-ava .avatar.channel::after, .msg-ava .avatar.group::after { display: none; }
.mention { color: var(--accent-bright); cursor: pointer; }
.mention:hover { text-decoration: underline; }
.bio-text { max-width: 300px; white-space: pre-wrap; }
.ava-wrap { position: relative; display: inline-block; }
.ava-cam {
  position: absolute; right: -2px; bottom: -2px; z-index: 4;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.45);
}
.ava-cam svg { width: 15px; height: 15px; fill: #fff; }
.link-btn { color: var(--accent-bright); font-size: 13.5px; }
.link-btn:hover { text-decoration: underline; }
.set-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 8px; border-radius: 10px; cursor: pointer;
}
.set-row:hover { background: var(--hover); }
.set-row .avatar { width: 42px; height: 42px; font-size: 15px; }
.set-row .set-arrow { color: var(--faint); font-size: 22px; margin-left: auto; }
.set-info {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 7px 8px; color: var(--muted); font-size: 14px;
}
.set-info b { color: var(--text); font-weight: 600; max-width: 70%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Мобильная версия ---------- */
@media (max-width: 768px) {
  .app { position: relative; }
  .sidebar { width: 100%; }
  .app.chat-open .sidebar { display: none; }
  .app:not(.chat-open) .chat-pane { display: none; }
  .chat-header .back { display: flex; }
  .messages { padding: 10px 10px 6px; }
  .composer { padding: 7px 10px 10px; }
  .bubble { max-width: 84%; }
  .modal { padding: 18px 16px; }
}

/* ---------- Медиа в сообщениях ---------- */
.m-img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin: -2px 0 2px; cursor: zoom-in; }
.m-video { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin: -2px 0 2px; background: #000; }
.m-audio { display: block; min-width: 220px; margin: 2px 0; }
.m-file { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; padding: 4px 2px; }
.mf-icon { width: 38px; height: 38px; border-radius: 50%; background: rgba(255,255,255,.14); display: flex; align-items: center; justify-content: center; flex: none; }
.mf-icon svg { width: 20px; height: 20px; fill: #fff; }
.mf-body { display: flex; flex-direction: column; min-width: 0; }
.mf-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mf-size { font-size: 12px; color: rgba(255,255,255,.6); }
.mf-dl svg { width: 20px; height: 20px; fill: rgba(255,255,255,.7); }

/* ---------- Загрузка ---------- */
.upl { position: relative; height: 4px; background: #243447; border-radius: 2px; margin-bottom: 6px; }
.upl-fill { height: 100%; background: var(--accent-bright); border-radius: 2px; width: 0; transition: width .2s; }
.upl-name { position: absolute; right: 22px; top: -18px; font-size: 11px; color: var(--muted); max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upl-cancel { position: absolute; right: 0; top: -24px; color: var(--muted); font-size: 16px; }
.attach-btn { width: 34px; height: 34px; margin-right: 2px; }
.attach-btn svg { width: 20px; height: 20px; }

/* ---------- Лайтбокс ---------- */
.lightbox { position: fixed; inset: 0; z-index: 400; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; animation: fadeIn .15s; }
.lightbox img { max-width: 96vw; max-height: 88vh; object-fit: contain; }
.lb-bar { position: fixed; top: 10px; right: 12px; display: flex; gap: 8px; align-items: center; }
.lb-bar .icon-btn { color: #fff; background: rgba(255,255,255,.12); }

/* ---------- Звонки ---------- */
#call-overlay { position: fixed; inset: 0; z-index: 500; background: #0b131b; display: flex; flex-direction: column; animation: fadeIn .2s; }
.call-remote { position: relative; flex: 1; overflow: hidden; display: flex; align-items: center; justify-content: center; }
#call-remote { width: 100%; height: 100%; object-fit: cover; }
.call-remote.novideo #call-remote { display: none; }
.call-ph { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.call-ph-name { font-size: 22px; font-weight: 600; }
.call-local { position: absolute; right: 14px; bottom: 14px; width: 110px; border-radius: 12px; box-shadow: 0 4px 18px rgba(0,0,0,.5); background: #000; }
.call-bottom { flex: none; padding: 14px 5% 22px; display: flex; align-items: center; justify-content: space-between; gap: 10px; background: rgba(0,0,0,.35); }
.call-name { font-weight: 600; font-size: 16px; }
.call-status { color: var(--muted); font-size: 13px; }
.call-btns { display: flex; gap: 14px; }
.call-btns.center { justify-content: center; margin-top: 18px; }
.call-btn { width: 52px; height: 52px; border-radius: 50%; background: #2b3a4a; display: flex; align-items: center; justify-content: center; transition: filter .15s; }
.call-btn svg { width: 24px; height: 24px; fill: #fff; }
.call-btn:hover { filter: brightness(1.2); }
.call-btn.danger { background: var(--danger); }
.call-btn.off { background: #5a3b3b; }
.call-btn.big { width: 64px; height: 64px; }
.call-btn.accept { background: #2ecc71; }
.call-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.call-lbl { font-size: 12px; color: var(--muted); }
.call-modal { text-align: center; }
.avatar.ring { animation: ringPulse 1s infinite; }
@keyframes ringPulse { 0%,100% { box-shadow: 0 0 0 0 rgba(106,179,243,.5); } 50% { box-shadow: 0 0 0 16px rgba(106,179,243,0); } }

/* Иконки внутри обычных кнопок и заголовков модалок */
.btn svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.modal h3 svg { width: 20px; height: 20px; fill: var(--accent-bright); flex: none; }

/* ---------- Боковое меню (drawer) ---------- */
#drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 150; animation: fadeIn .15s; }
.drawer { position: fixed; top: 0; left: 0; bottom: 0; width: 300px; max-width: 86vw; background: var(--panel-2); z-index: 151; display: flex; flex-direction: column; animation: slideRight .18s ease-out; overflow-y: auto; padding-bottom: 12px; }
@keyframes slideRight { from { transform: translateX(-24px); opacity: 0; } }
.drawer-head { padding: 22px 18px 16px; border-bottom: 1px solid #26333f; cursor: pointer; }
.drawer-head:hover { background: var(--hover); }
.drawer-head .avatar { margin-bottom: 10px; }
.drawer-name { font-size: 17px; font-weight: 700; }
.drawer-sub { color: var(--accent-bright); font-size: 13.5px; }
.drawer-item { display: flex; align-items: center; gap: 14px; padding: 11px 18px; cursor: pointer; font-size: 14.5px; user-select: none; }
.drawer-item:hover { background: var(--hover); }
.drawer-item .d-ic { display: flex; }
.drawer-item .d-ic svg { width: 20px; height: 20px; fill: var(--muted); }
.drawer-item .grow { flex: 1; }
.drawer-item.danger { color: #ff8a80; }
.drawer-item.danger .d-ic svg { fill: #ff8a80; }
.drawer-footer { margin-top: auto; padding: 12px 18px 4px; color: var(--faint); font-size: 12px; }
.switch { width: 34px; height: 20px; border-radius: 10px; background: var(--faint); position: relative; flex: none; transition: background .15s; }
.switch::after { content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: left .15s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch.on { background: var(--accent); }
.switch.on::after { left: 16px; }
.burger { position: relative; }
.burger-dot { position: absolute; top: 4px; right: 4px; width: 9px; height: 9px; border: 2px solid var(--panel); }
.muted-bell svg { width: 13px; height: 13px; fill: var(--faint); }

/* ---------- Светлая тема ---------- */
body.light {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #ffffff;
  --hover: #f1f4f8;
  --selected: #d7e8fa;
  --out: #d7e8fa;
  --in: #f1f4f8;
  --text: #17212b;
  --muted: #6d7f90;
  --faint: #a2b1bf;
  --accent: #4a95d3;
  --accent-bright: #2b7ec4;
  --badge: #4a95d3;
}
body.light .sidebar { border-right-color: #e6ecf2; }
body.light .chat-header { border-bottom-color: #e6ecf2; }
body.light .search-wrap input { background: #eef2f6; }
body.light .date-sep span { background: #e6ecf2; color: #5a6b7c; }
body.light .msg-row.svc span { background: #e6ecf2; color: #5a6b7c; }
body.light .b-meta { color: rgba(23,33,43,.45); }
body.light .bubble .b-edited { color: rgba(23,33,43,.4); }
body.light .bubble.deleted .b-text { color: var(--faint); }
body.light .drawer-head { border-bottom-color: #e6ecf2; }
body.light .composer.editing { background: #f7fafd; border-top-color: #d7e3ee; }

.star-in svg { width: 22px; height: 22px; fill: #fff; }

/* ---------- Профиль и инфо в стиле Telegram ---------- */
.modal { position: relative; }
.pm-close, .pm-edit { position: absolute; top: 8px; width: 36px; height: 36px; z-index: 2; }
.pm-close { right: 8px; color: var(--muted); }
.pm-edit { right: 52px; color: var(--muted); }
.info-rows { background: rgba(0,0,0,.16); border-radius: 10px; padding: 3px 0; margin-top: 10px; text-align: left; }
body.light .info-rows { background: #f1f4f8; }
.info-row { padding: 9px 14px; }
.ir-value { font-size: 15px; word-break: break-word; white-space: pre-wrap; }
.ir-label { font-size: 13px; color: var(--muted); margin-top: 2px; }
.ir-value.accent { color: var(--accent-bright); }
.profile-head { margin-bottom: 14px; }
.status.accent { color: var(--accent-bright); font-weight: 500; }

/* ---------- Тип (публичный/приватный) и ссылки ---------- */
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.seg-btn { flex: 1; padding: 8px; border-radius: 8px; color: var(--muted); font-weight: 600; text-align: center; }
.seg-btn.active { background: var(--accent); color: #fff; }
.invite-row { display: flex; gap: 8px; align-items: center; }
.invite-row .input { flex: 1; min-width: 0; font-size: 13.5px; }
.invite-row .btn { padding: 10px 14px; flex: none; }
.invite-link { cursor: pointer; }
.invite-link:hover { text-decoration: underline; }

/* ---------- Настройки в тг-стиле ---------- */
.set-profile { display: flex; align-items: center; gap: 14px; padding: 6px 6px 14px; cursor: pointer; border-radius: 10px; }
.set-profile:hover { background: var(--hover); }
.set-profile .avatar { width: 56px; height: 56px; font-size: 21px; }
.mr-name.big { font-size: 17px; font-weight: 700; }
.drawer-item { padding: 12px 18px; }
.modal .drawer-item { padding: 11px 8px; }
.cs-section { color: var(--accent-bright); font-weight: 700; font-size: 13.5px; text-transform: uppercase; letter-spacing: .3px; margin: 16px 0 10px; }
.theme-cards { display: flex; gap: 12px; }
.theme-card { display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; color: var(--muted); font-size: 13px; }
.tc-prev { width: 76px; height: 56px; border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 5px; background: #17212b; border: 2px solid transparent; }
.tc-prev.lite { background: #f1f4f8; }
.theme-card.sel .tc-prev { border-color: var(--accent-bright); }
.theme-card.sel { color: var(--accent-bright); }
.tc-b { height: 9px; border-radius: 5px; }
.tc-b.b1 { width: 60%; background: var(--accent); }
.tc-b.b2 { width: 80%; background: #2b3a4a; align-self: flex-end; }
.tc-prev.lite .tc-b.b2 { background: #d3dde6; }
.accent-row { display: flex; gap: 12px; flex-wrap: wrap; padding: 2px 4px; }
.accent-dot { width: 30px; height: 30px; border-radius: 50%; cursor: pointer; display: inline-block; box-shadow: inset 0 0 0 2px rgba(0,0,0,.15); }
.accent-dot.sel { box-shadow: 0 0 0 3px var(--panel-2), 0 0 0 5px var(--accent-bright); }
.messages { font-size: var(--msgfont, 15px); }

/* ---------- Голосовые и кружки ---------- */
.voice { display: flex; align-items: center; gap: 10px; min-width: 230px; padding: 2px 0; }
.v-play { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; flex: none; cursor: pointer; border: none; }
.v-play svg { width: 20px; height: 20px; fill: #fff; margin-left: 2px; }
.msg-row.out .v-play { background: rgba(255,255,255,.92); }
.msg-row.out .v-play svg { fill: var(--accent); }
.v-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.v-wave { display: flex; align-items: center; gap: 1.5px; height: 26px; }
.v-wave span { flex: 1; min-width: 1px; max-width: 3px; border-radius: 1.5px; background: rgba(255,255,255,.34); }
.v-wave span.on { background: #fff; }
.v-info { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: rgba(255,255,255,.55); }
.v-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-bright); flex: none; }
.voice audio { display: none; }
.round-wrap { position: relative; width: 232px; max-width: 100%; }
.round-video { width: 100%; aspect-ratio: 1; border-radius: 50%; object-fit: cover; display: block; background: #000; cursor: pointer; }
.rv-badge { position: absolute; bottom: 12px; display: flex; align-items: center; gap: 5px; background: rgba(0,0,0,.5); border-radius: 11px; padding: 2.5px 8px; font-size: 11.5px; color: #fff; }
.rv-badge .ticks { width: 15px; height: 11px; fill: currentColor; display: block; }
.rv-badge .ticks.read { color: #62d0ff; }
.rv-left { left: 12px; }
.rv-right { right: 12px; }
.rv-mute { position: absolute; top: 12px; right: 12px; width: 30px; height: 30px; border-radius: 50%; background: rgba(0,0,0,.5); border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.rv-mute svg { width: 16px; height: 16px; fill: #fff; }
.mic-btn { background: var(--hover); color: var(--accent-bright); }
.mic-btn svg { fill: var(--accent-bright); }
/* запись */
.rec-bar { display: flex; align-items: center; gap: 10px; background: var(--panel); border-radius: 16px; padding: 8px 12px; }
.rec-cancel { color: #ff8a80; }
.rec-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--danger); animation: recBlink 1s infinite; flex: none; }
@keyframes recBlink { 50% { opacity: .2; } }
#rec-time { font-variant-numeric: tabular-nums; font-size: 14px; flex: none; }
.rec-wave { flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 2px; height: 26px; overflow: hidden; }
.rec-wave span { width: 3px; background: var(--accent-bright); border-radius: 2px; animation: recWave 1s ease-in-out infinite; }
@keyframes recWave { 0%,100% { transform: scaleY(.4); } 50% { transform: scaleY(1); } }
.rec-prev { position: absolute; right: 16px; bottom: 84px; width: 130px; height: 130px; border-radius: 50%; object-fit: cover; border: 3px solid var(--panel-2); background: #000; z-index: 5; }
.composer { position: relative; }

/* ===== Ответы, пересылка, реакции, закрепы, поиск, галерея ===== */
.fwd-line { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--accent-bright); margin-bottom: 3px; opacity: .9; }
.fwd-line svg { width: 14px; height: 14px; fill: currentColor; }
.fwd-line b { cursor: pointer; }
.reply-quote { border-left: 3px solid var(--accent-bright); background: rgba(255,255,255,.06); border-radius: 6px; padding: 4px 8px; margin-bottom: 5px; cursor: pointer; max-width: 100%; overflow: hidden; }
.reply-quote .rq-name { font-size: 12.5px; color: var(--accent-bright); font-weight: 600; }
.reply-quote .rq-text { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@keyframes flashBg { 0%,100% { background: transparent; } 30% { background: rgba(255,255,255,.14); } }
.bubble.flash { animation: flashBg 1.5s ease; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.rchip { display: inline-flex; align-items: center; gap: 3px; background: rgba(255,255,255,.08); border: 1px solid transparent; border-radius: 12px; padding: 2px 8px; font-size: 13px; cursor: pointer; transition: background .15s; }
.rchip:hover { background: rgba(255,255,255,.15); }
.rchip.mine { background: rgba(42,143,255,.25); border-color: var(--accent-bright); }
.rchip b { font-size: 11.5px; color: var(--muted); }
.react-menu { display: flex; gap: 2px; padding: 4px; }
.react-menu button { font-size: 20px; padding: 4px 6px; border: none; background: transparent; cursor: pointer; border-radius: 8px; }
.react-menu button:hover { background: var(--hover); }
.pin-bar { display: flex; align-items: center; gap: 10px; background: var(--panel); border-bottom: 1px solid var(--border); padding: 6px 14px; cursor: pointer; min-height: 34px; }
.pin-bar .pb-icon svg { width: 16px; height: 16px; fill: var(--accent-bright); }
.pin-bar .pb-body { flex: 1; min-width: 0; }
.pin-bar .pb-title { font-size: 12px; color: var(--accent-bright); font-weight: 600; }
.pin-bar .pb-text { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pin-bar .pb-unpin svg { width: 16px; height: 16px; }
.eb-body { flex: 1; min-width: 0; }
.eb-title { font-size: 12.5px; color: var(--accent-bright); font-weight: 600; }
.eb-text { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cancel-reply { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 0 4px; }
@keyframes typingPulse { 0%,100% { opacity: .5; } 50% { opacity: 1; } }
.typing-anim { animation: typingPulse 1.2s ease-in-out infinite; }
.cs-results { margin-top: 10px; max-height: 46dvh; overflow-y: auto; }
.cs-row { width: 100%; text-align: left; border: none; background: transparent; cursor: pointer; }
.cs-row:hover { background: var(--hover); }
.cs-time { font-size: 11.5px; color: var(--muted); flex: none; }
.media-grid { max-height: 30dvh; overflow-y: auto; }
.media-grid-inner { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.mg-item { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; cursor: pointer; border: none; background: #1c2733; color: #fff; font-size: 20px; }
.mg-video { display: flex; align-items: center; justify-content: center; }
.lb-video { max-width: min(92vw, 900px); max-height: 82dvh; border-radius: 10px; background: #000; }
.lightbox { display: flex; align-items: center; justify-content: center; z-index: 260; }
.lb-close { position: fixed; top: 14px; right: 14px; z-index: 261; }
.mic-btn { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.bubble:has(.round-wrap) { background: transparent !important; padding: 0 !important; box-shadow: none !important; }
.drawer-item .pv-val { color: var(--accent-bright); font-size: 14px; }

/* ===== Эмодзи-панель ===== */
.ep-wrap { position: absolute; left: 8px; right: 8px; bottom: calc(100% + 6px); background: var(--panel); border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,.45); z-index: 60; display: flex; flex-direction: column; height: 340px; overflow: hidden; }
.ep-search { padding: 10px 10px 6px; }
.ep-search input { width: 100%; box-sizing: border-box; background: var(--panel-2); border: none; border-radius: 10px; padding: 9px 14px; color: var(--text); outline: none; font-size: 14px; }
.ep-body { flex: 1; overflow-y: auto; padding: 0 8px 6px; }
.ep-h { font-size: 13px; color: var(--muted); padding: 10px 6px 6px; }
.ep-grid { display: grid; grid-template-columns: repeat(8, 40px); justify-content: center; gap: 2px 4px; }
.ep-em { width: 40px; height: 40px; cursor: pointer; border: none; background-color: transparent; background-repeat: no-repeat; border-radius: 8px; }
.ep-em:hover { background-color: var(--hover); }
.ep-strip { display: flex; overflow-x: auto; gap: 4px; padding: 2px 0 4px; }
.ep-strip .ep-em { flex: none; width: 38px; height: 38px; }
.ep-tabs { display: flex; border-top: 1px solid var(--border); padding: 3px 4px; }
.ep-tab { flex: 1; height: 38px; display: flex; align-items: center; justify-content: center; border: none; background-color: transparent; opacity: .45; cursor: pointer; border-radius: 8px; min-width: 0; }
.ep-tab.sel { opacity: 1; background-color: var(--hover); }
.ep-ic { display: block; width: 24px; height: 24px; background-repeat: no-repeat; flex: none; }
.ep-body::-webkit-scrollbar { width: 4px; }
.ep-body::-webkit-scrollbar-thumb { background: var(--hover); border-radius: 2px; }
.emj { display: inline-block; width: 20px; height: 20px; vertical-align: -4px; background-repeat: no-repeat; }
.rchip .emj { width: 16px; height: 16px; vertical-align: -3px; }

/* ===== Стикеры ===== */
.sticker-wrap { position: relative; width: 176px; max-width: 100%; }
.sticker-img { width: 100%; display: block; }
.bubble:has(.sticker-img) { background: transparent !important; padding: 0 !important; box-shadow: none !important; }
.bubble:has(.sticker-img) .sticker-wrap .rv-badge { bottom: 6px; }
.ep-grid.ep-stickers { grid-template-columns: repeat(3, 1fr); gap: 6px; }
.ep-st { width: 100%; aspect-ratio: 1; border: none; background: transparent; cursor: pointer; border-radius: 10px; padding: 4px; }
.ep-st:hover { background: var(--hover); }
.ep-st img { width: 100%; height: 100%; object-fit: contain; display: block; }
.ep-top { display: flex; border-bottom: 1px solid var(--border); }
.ep-top button { flex: 1; height: 42px; background: none; border: none; border-bottom: 2px solid transparent; color: var(--muted); font-size: 14px; cursor: pointer; }
.ep-top button.sel { color: var(--accent-bright); border-bottom-color: var(--accent-bright); font-weight: 600; }
.ep-wrap.mode-stickers .ep-search, .ep-wrap.mode-stickers .ep-tabs { display: none; }
.ep-wrap.mode-stickers .ep-body { padding-top: 6px; }
