/* мессенджер.онлайн — трёхпанельный интерфейс */
:root {
  --tg-chatlist-width: 380px;
  --tg-sidebar: #1c2733;
  --tg-sidebar-active: #0d1117;
  --tg-sidebar-accent: #64b5f6;
  --tg-folder-badge: #64b5f6;
  --tg-chatlist-bg: #ffffff;
  --tg-chatlist-border: #dfe3e6;
  --tg-chatlist-hover: #f4f4f5;
  --tg-chatlist-active: #e3f2fd;
  --tg-chat-bg: #e6ded8;
  /* лёгкий «облачный» паттерн как у дефолтных обоев TG */
  --tg-chat-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cg fill='%23000' fill-opacity='0.035'%3E%3Cpath d='M40 30c8-12 28-12 36 0 6 10 4 24-4 32-8 8-24 8-32-4-6-10-4-22 0-28z'/%3E%3Cpath d='M120 100c10-8 26-6 32 6 6 12 2 28-8 36-10 8-26 6-34-8-6-12-2-26 10-34z'/%3E%3Ccircle cx='90' cy='90' r='3'/%3E%3Ccircle cx='20' cy='140' r='2'/%3E%3Ccircle cx='160' cy='40' r='2'/%3E%3C/g%3E%3C/svg%3E");
  --tg-text: #000;
  --tg-text-muted: #707579;
  --tg-bubble-out: #eeffde;
  --tg-bubble-in: #fff;
  --tg-accent: #3390ec;
  --tg-unread: #3390ec;
  --tg-modal-bg: #fff;
  --cm-msg-font-px: 15px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, system-ui, Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #0e1621;
  color: var(--tg-text);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===== Layout: папки | список чатов | ресайзер | окно чата ===== */
.tgApp {
  display: grid;
  grid-template-columns: 72px var(--tg-chatlist-width) 6px minmax(0, 1fr);
  height: 100vh;
}

.tgPaneResizer {
  grid-column: auto;
  width: 6px;
  margin-left: -1px;
  cursor: col-resize;
  background: transparent;
  z-index: 6;
  touch-action: none;
  flex-shrink: 0;
  align-self: stretch;
}
.tgPaneResizer:hover,
.tgPaneResizer:focus-visible {
  background: rgba(51, 144, 236, 0.35);
}
.tgPaneResizer:active {
  background: rgba(51, 144, 236, 0.55);
}

/* ===== Левая панель: папки ===== */
.tgFoldersNav {
  background: var(--tg-sidebar);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0 12px;
  border-right: 1px solid rgba(0,0,0,0.35);
}

.tgFoldersNavSpacer {
  flex: 1;
  min-height: 8px;
}

.tgNavBtn {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: rgba(255,255,255,0.85);
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.tgNavBtn:hover { background: rgba(255,255,255,0.1); }

.tgNavBtnMenu {
  position: relative;
}

.tgNavBtnMenu.has-notify::after {
  content: '';
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tg-sidebar-accent);
  box-shadow: 0 0 0 2px var(--tg-sidebar);
}

.tgFoldersList {
  flex: 0 1 auto;
  max-height: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px 0 8px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
}

.tgFolderItem {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: rgba(255,255,255,0.85);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  font-size: 20px;
  flex-shrink: 0;
}

.tgFolderItem .tgFolderIconSvg {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tgFolderItem .tgFolderIconSvg .tgIcon {
  width: 22px;
  height: 22px;
}

.tgFolderItem:hover { background: rgba(255,255,255,0.08); }

.tgFolderItem.active {
  background: var(--tg-sidebar-active);
  color: var(--tg-sidebar-accent);
}

.tgFoldersNav .tgFolderItem.active .tgFolderLabel {
  color: var(--tg-sidebar-accent);
}

.tgFoldersNav .tgFolderItem.active .tgFolderIconSvg,
.tgFoldersNav .tgFolderItem.active .tgIcon {
  color: var(--tg-sidebar-accent);
}

.tgNavEditRail {
  flex-shrink: 0;
  margin-top: 4px;
}

.tgNavEditRail .tgFolderLabel {
  color: rgba(255, 255, 255, 0.88);
}

.tgNavEditRail:hover .tgFolderLabel {
  color: #fff;
}

.tgFolderLabel {
  display: none;
}

/* Мини-подписи папок (боковая колонка) */
.tgFoldersNav .tgFolderItem {
  width: 56px;
  min-height: 56px;
  height: auto;
  border-radius: 14px;
  padding: 6px 2px 8px;
  gap: 2px;
}

.tgFoldersNav .tgFolderLabel {
  display: block;
  font-size: 9px;
  font-weight: 600;
  line-height: 1.05;
  max-width: 52px;
  max-height: 2.2em;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  white-space: normal;
  word-break: break-word;
  color: rgba(255, 255, 255, 0.92);
  text-align: center;
}

/* Горизонтальная полоса папок на телефоне — подпись под иконкой */
.tgMobileFolderStrip .tgFolderItem {
  flex: 0 0 auto;
  width: 52px;
  min-height: 56px;
  height: auto;
  flex-direction: column;
  border-radius: 14px;
  padding: 4px 2px 6px;
  gap: 2px;
}

.tgMobileFolderStrip .tgFolderLabel {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-size: 9px;
  font-weight: 600;
  line-height: 1.05;
  max-width: 48px;
  max-height: 2.2em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: break-word;
  color: var(--tg-text-muted);
  text-align: center;
}

.tgMobileFolderStrip .tgFolderItem.active .tgFolderLabel {
  color: rgba(255, 255, 255, 0.95);
}

/* Контекстное меню папки */
.tgFolderCtxMenu {
  position: fixed;
  z-index: 240;
  min-width: 180px;
  padding: 6px 0;
  background: var(--tg-chatlist-bg);
  border: 1px solid var(--tg-chatlist-border);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

.tgFolderCtxItem {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: none;
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  color: var(--tg-text);
}

.tgFolderCtxItem:hover {
  background: var(--tg-chatlist-hover);
}

.tgFolderCtxItem.danger {
  color: #c62828;
}

.tgFolderBadge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--tg-folder-badge);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tgFolderItem:not(.active) .tgFolderBadge {
  background: var(--tg-folder-badge);
  opacity: 0.95;
}

.tgFolderItem.active .tgFolderBadge {
  background: var(--tg-folder-badge);
  opacity: 1;
}

.tgNavBtnBottom {
  margin-top: auto;
  margin-bottom: 0;
}

/* ===== Средняя панель: список чатов ===== */
.tgChatListPanel {
  background: var(--tg-chatlist-bg);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--tg-chatlist-border);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* Шапка списка чатов только на телефоне (меню и «новый чат» — в узкой колонке на десктопе) */
.tgChatListMobileHeader {
  display: none;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--tg-chatlist-border);
  background: var(--tg-chatlist-bg);
}

.tgChatListMobileTitle {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
}

.tgChatListMobileIcon {
  flex-shrink: 0;
}

.tgSearchBar {
  position: relative;
  padding: 12px 16px;
  border-bottom: 1px solid var(--tg-chatlist-border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--tg-chatlist-bg);
}

.tgAutofillTrap {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  pointer-events: none;
  opacity: 0;
}

.tgSearchIcon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.55;
}

.tgSearchBar input {
  flex: 1;
  min-width: 0;
  border: none;
  background: #f1f1f1;
  border-radius: 22px;
  padding: 9px 16px 9px 4px;
  font-size: 15px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.tgSearchBar input::placeholder { color: var(--tg-text-muted); }
.tgSearchBar input:focus { background: #eaeaea; }

.tgSearchClear {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--tg-text-muted);
  cursor: pointer;
  font-size: 18px;
}

.tgSearchClear:hover { background: #e8e8e8; }

.tgChatList {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Элемент чата в списке */
.chatItem {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  border-bottom: 1px solid var(--tg-chatlist-border);
  transition: background 0.1s;
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Иконки интерфейса (symbol sprite) */
.tgIcon {
  width: 24px;
  height: 24px;
  display: block;
  flex-shrink: 0;
}

.tgIconDrawer {
  width: 22px;
  height: 22px;
  margin-right: 10px;
  opacity: 0.95;
}

.tgIconMuted { opacity: 0.55; }
.tgIconSend { width: 20px; height: 20px; fill: #fff; }

.tgNavBtn .tgIcon,
.tgHeaderBtn .tgIcon,
.tgComposerBtn .tgIcon {
  width: 22px;
  height: 22px;
}

.tgComposerSend .tgIcon {
  width: 20px;
  height: 20px;
}

.tgTabIcon .tgIcon {
  width: 26px;
  height: 26px;
}

.tgDrawerItem {
  display: flex;
  align-items: center;
}

/* Горизонтальные папки (мобильный) */
.tgMobileFolderStrip {
  display: none;
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--tg-chatlist-border);
  background: var(--tg-chatlist-bg);
  scrollbar-width: none;
}
.tgMobileFolderStrip::-webkit-scrollbar { display: none; }

/* Папки над списком чатов (режим «вкладки сверху», десктоп + моб.) */
.tgFolderStripTop {
  display: none;
  flex-direction: row;
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--tg-chatlist-border);
  background: var(--tg-chatlist-bg);
  scrollbar-width: none;
  align-items: flex-start;
}
.tgFolderStripTop::-webkit-scrollbar {
  display: none;
}
.tgApp.folders-tab-top .tgFolderStripTop:not([hidden]) {
  display: flex;
}

.tgFolderStripTop .tgFolderItem {
  flex: 0 0 auto;
  width: 52px;
  min-height: 56px;
  height: auto;
  flex-direction: column;
  border-radius: 14px;
  padding: 4px 2px 6px;
  gap: 2px;
  background: #e8f4fc;
  color: var(--tg-accent);
}

.tgFolderStripTop .tgFolderItem.active {
  background: var(--tg-accent);
  color: #fff;
}

.tgFolderStripTop .tgFolderLabel {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-size: 9px;
  font-weight: 600;
  line-height: 1.05;
  max-width: 48px;
  max-height: 2.2em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: break-word;
  color: var(--tg-text-muted);
  text-align: center;
}

.tgFolderStripTop .tgFolderItem.active .tgFolderLabel {
  color: rgba(255, 255, 255, 0.95);
}

.tgFolderStripTop .tgFolderBadge {
  background: var(--tg-unread);
  color: #fff;
}

.tgFolderStripTop .tgFolderItem:not(.active) .tgFolderBadge {
  background: rgba(51, 144, 236, 0.35);
  color: #fff;
}

/* Модалка «Папки» */
.foldersPanelCard {
  max-width: 420px;
  width: calc(100vw - 32px);
}

.foldersPanelBody {
  max-height: min(72vh, 640px);
  overflow-y: auto;
}

.foldersPanelIllu {
  font-size: 48px;
  text-align: center;
  margin-bottom: 8px;
  line-height: 1;
}

.foldersSectionTitle {
  font-size: 15px;
  font-weight: 600;
  margin: 18px 0 10px;
  color: var(--tg-text);
}

.foldersSectionTitle:first-of-type {
  margin-top: 4px;
}

.foldersPanelMyList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.foldersPanelRow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--tg-chatlist-border);
  border-radius: 12px;
  background: #fafafa;
}

.foldersPanelRowName {
  flex: 1;
  font-size: 15px;
  text-align: left;
}

.foldersPanelRowMeta {
  font-size: 13px;
  color: var(--tg-text-muted);
  margin-right: 4px;
}

.foldersPanelRow .tgIcon {
  width: 22px;
  height: 22px;
  color: var(--tg-accent);
  flex-shrink: 0;
}

.foldersPanelTrash {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  color: #c62828;
  font-size: 18px;
  line-height: 1;
}

.foldersPanelTrash:hover {
  background: rgba(198, 40, 40, 0.08);
}

.foldersPanelAddBtn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px dashed var(--tg-chatlist-border);
  border-radius: 12px;
  background: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  color: var(--tg-accent);
  cursor: pointer;
}

.foldersPanelAddBtn:hover {
  background: var(--tg-chatlist-hover);
}

.foldersPanelNameInput {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--tg-chatlist-border);
  border-radius: 8px;
  margin-bottom: 8px;
  font: inherit;
  box-sizing: border-box;
}

.foldersRecRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--tg-chatlist-border);
  font-size: 14px;
}

.foldersRecRow:last-of-type {
  border-bottom: none;
}

.foldersTabPos {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.foldersRadio {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  cursor: pointer;
}

.foldersRadio input {
  width: 18px;
  height: 18px;
  accent-color: var(--tg-accent);
}

.btn.sm {
  padding: 6px 12px;
  font-size: 13px;
}

.moveFolderList {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
}

.moveFolderList .btn {
  width: 100%;
  text-align: left;
}

.tgChatList {
  position: relative;
  z-index: 1;
  touch-action: pan-y;
}

.chatItem:hover { background: var(--tg-chatlist-hover); }
.chatItem.active { background: var(--tg-chatlist-active); }
.chatItem.unread .chatTitle { font-weight: 600; }

.chatAvatar {
  width: 54px;
  height: 54px;
  min-width: 54px;
  border-radius: 50%;
  background: var(--tg-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 600;
  color: #fff;
  overflow: hidden;
  flex-shrink: 0;
}

.chatAvatar .chatAvatarImg {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 50%;
}

.chatMeta { flex: 1; min-width: 0; }

.chatTopLine {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.chatTitle {
  font-size: 16px;
  font-weight: 500;
  color: var(--tg-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chatTime {
  font-size: 13px;
  color: var(--tg-text-muted);
  flex-shrink: 0;
}

.chatBottomLine {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chatLast {
  flex: 1;
  font-size: 15px;
  color: var(--tg-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chatListEmpty {
  padding: 40px 20px;
  text-align: center;
  color: var(--tg-text-muted);
  font-size: 15px;
  line-height: 1.5;
}

.chatUnread {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--tg-unread);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.badge { font-size: 10px; padding: 2px 6px; border-radius: 6px; margin-left: 4px; }
.badgeWarn { background: #ffeb3b; color: #000; }
.badgeSecret { background: #e1bee7; color: #4a148c; }
.badgeSecretK { background: #b3e5fc; color: #01579b; }

/* ===== Правая панель: окно чата ===== */
.tgChatPanel {
  background-color: var(--tg-chat-bg);
  background-image: var(--tg-chat-pattern);
  background-size: 180px 180px;
  background-position: 0 0;
  background-attachment: local;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  flex: 1;
  min-height: 0;
}

/* Пустое и активное состояние — слои на весь блок (избегаем «не открывается» из-за flex) */
.tgChatPanel .tgChatEmpty,
.tgChatPanel .tgChatActive {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tgChatPanel .tgChatEmpty {
  align-items: center;
  justify-content: center;
  padding: 40px;
  z-index: 1;
}

.tgChatPanel .tgChatActive {
  z-index: 2;
}

.tgChatEmptyBubble {
  padding: 18px 28px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 14px;
  font-size: 15px;
  font-weight: 500;
  color: #8d8e8e;
  text-align: center;
  max-width: 340px;
  line-height: 1.45;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(0, 0, 0, 0.06);
}

/* Активный чат */
.tgChatActive {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tgChatHeader {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--tg-chatlist-bg);
  border-bottom: 1px solid var(--tg-chatlist-border);
}

.tgBackBtn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tgBackBtn:hover { background: var(--tg-chatlist-hover); }

.tgChatHeaderInfo { flex: 1; min-width: 0; }

.tgChatName {
  display: block;
  border: none;
  background: none;
  font-size: 16px;
  font-weight: 600;
  color: var(--tg-text);
  cursor: pointer;
  text-align: left;
  width: 100%;
  padding: 0;
}

.tgChatName:hover { text-decoration: underline; }

.tgChatStatus {
  font-size: 13px;
  color: var(--tg-text-muted);
  display: block;
  margin-top: 2px;
}

.tgChatHeaderActions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* без служебных пилюль в шапке (отладка в консоли / код) */
.tgMetaPills {
  display: none;
}
.pill { font-size: 11px; padding: 4px 8px; border-radius: 4px; background: #eee; color: var(--tg-text-muted); }

.tgHeaderBtn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
}

.tgHeaderBtn:hover { background: var(--tg-chatlist-hover); }

.tgChatBody {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background-color: var(--tg-chat-bg);
  background-image: var(--tg-chat-pattern);
  background-size: auto;
}

.tgChatBody.restrict-copy .mBubble,
.tgChatBody.restrict-copy .mReplyQuote,
.tgChatBody.restrict-copy .mForwardBanner {
  user-select: none;
  -webkit-user-select: none;
}

/* Поиск по сообщениям внутри чата */
.inChatSearchBar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding: 8px 12px;
  background: var(--tg-chatlist-bg);
  border-bottom: 1px solid var(--tg-chatlist-border);
}
.inChatSearchBar[hidden] {
  display: none !important;
}
.inChatSearchInput {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid var(--tg-chatlist-border);
  border-radius: 10px;
  font: inherit;
  font-size: 15px;
}
.inChatSearchMeta {
  font-size: 13px;
  color: var(--tg-text-muted);
  white-space: nowrap;
  min-width: 3ch;
  text-align: center;
}
.inChatSearchNav,
.inChatSearchClose {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  color: var(--tg-text-muted);
}
.inChatSearchNav:hover,
.inChatSearchClose:hover {
  background: var(--tg-chatlist-hover);
}

.mRowSearchHit .mBubble {
  outline: 2px solid rgba(51, 144, 236, 0.45);
  outline-offset: 1px;
}
.mRowSearchCurrent .mBubble {
  outline: 2px solid var(--tg-accent);
  outline-offset: 2px;
}

/* Выпадающее меню «три точки» */
.tgHeaderCtxMenu {
  position: fixed;
  z-index: 450;
  min-width: 268px;
  max-width: min(320px, calc(100vw - 16px));
  max-height: min(70vh, 480px);
  overflow-y: auto;
  padding: 6px 0;
  background: var(--tg-modal-bg);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(0, 0, 0, 0.06);
}
.tgHeaderCtxMenu[hidden] {
  display: none !important;
}
.tgCtxRow {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px 10px 12px;
  border: none;
  background: none;
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  color: var(--tg-text);
}
.tgCtxRow:hover {
  background: var(--tg-chatlist-hover);
}
.tgCtxRow.hasSub {
  justify-content: space-between;
}
.tgCtxChev {
  color: var(--tg-text-muted);
  font-size: 18px;
  font-weight: 300;
}
.tgCtxSep {
  height: 1px;
  margin: 6px 12px;
  background: var(--tg-chatlist-border);
}
.tgCtxRow.danger {
  color: #c62828;
}
.tgCtxIcon {
  width: 22px;
  text-align: center;
  flex-shrink: 0;
  opacity: 0.88;
}

/* Боковая панель «информация» */
.peerInfoOverlay[hidden] {
  display: none !important;
}
.peerInfoOverlay {
  position: fixed;
  inset: 0;
  z-index: 440;
  pointer-events: none;
}
.peerInfoOverlay:not([hidden]) {
  pointer-events: auto;
}
.peerInfoScrim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.peerInfoOverlay:not([hidden]) .peerInfoScrim {
  opacity: 1;
}
.peerInfoDrawer {
  position: absolute;
  top: 0;
  right: 0;
  width: min(380px, 100vw);
  height: 100%;
  max-height: 100dvh;
  background: var(--tg-chatlist-bg);
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.22s ease;
  overflow: hidden;
}
.peerInfoOverlay:not([hidden]) .peerInfoDrawer {
  transform: translateX(0);
}
.peerInfoHead {
  position: relative;
  padding: 20px 16px 16px;
  background: linear-gradient(165deg, #6b2d4a 0%, #4a1d32 48%, #2d1a24 100%);
  color: #fff;
  flex-shrink: 0;
}
.peerInfoClose {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}
.peerInfoClose:hover {
  background: rgba(255, 255, 255, 0.2);
}
.peerInfoAvatarWrap {
  display: flex;
  justify-content: center;
  margin-top: 8px;
}
.peerInfoAvatar {
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.35);
  object-fit: cover;
  background: rgba(0, 0, 0, 0.2);
}
.peerInfoName {
  text-align: center;
  font-size: 19px;
  font-weight: 700;
  margin-top: 12px;
  line-height: 1.25;
  word-break: break-word;
}
.peerInfoStatus {
  text-align: center;
  font-size: 14px;
  opacity: 0.88;
  margin-top: 6px;
}
.peerInfoQuick {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}
.peerInfoQuickBtn {
  padding: 8px 14px;
  border-radius: 10px;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.peerInfoQuickBtn:hover {
  background: rgba(255, 255, 255, 0.25);
}
.peerInfoBody {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 20px;
}
.peerInfoContact {
  padding: 12px 16px;
  border-bottom: 1px solid var(--tg-chatlist-border);
  font-size: 14px;
}
.peerInfoContactRow {
  padding: 10px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}
.peerInfoContactRow:last-child {
  border-bottom: none;
}
.peerInfoContactLabel {
  font-size: 13px;
  color: var(--tg-text-muted);
  margin-bottom: 2px;
}
.peerInfoContactVal {
  font-size: 15px;
  color: var(--tg-text);
  word-break: break-all;
}
.peerInfoStatsTitle {
  padding: 12px 16px 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--tg-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.peerInfoStatRow {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 16px;
  border: none;
  width: 100%;
  background: none;
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  color: var(--tg-text);
}
.peerInfoStatRow:hover {
  background: var(--tg-chatlist-hover);
}
.peerMediaOverlay[hidden] {
  display: none !important;
}
.peerMediaOverlay {
  position: fixed;
  inset: 0;
  z-index: 460;
  pointer-events: none;
}
.peerMediaOverlay:not([hidden]) {
  pointer-events: auto;
}
.peerMediaScrim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
}
.peerMediaPanel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(400px, 100vw);
  height: 100%;
  max-height: 100dvh;
  background: var(--tg-chatlist-bg);
  box-shadow: -6px 0 32px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
}
.peerMediaHead {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 8px;
  border-bottom: 1px solid var(--tg-chatlist-border);
  flex-shrink: 0;
}
.peerMediaBack {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  color: var(--tg-text);
}
.peerMediaBack:hover {
  background: var(--tg-chatlist-hover);
}
.peerMediaTitle {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}
.peerMediaSearchBtn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
}
.peerMediaSearchWrap {
  padding: 8px 12px;
  border-bottom: 1px solid var(--tg-chatlist-border);
}
.peerMediaSearchWrap[hidden] {
  display: none !important;
}
.peerMediaSearchInput {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--tg-chatlist-border);
  font: inherit;
  font-size: 15px;
}
.peerMediaBody {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 16px;
}
.peerMediaMonth {
  padding: 12px 16px 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--tg-text);
  background: rgba(0, 0, 0, 0.03);
}
.peerMediaVoiceRow {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}
.peerMediaPlayBtn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--tg-accent);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}
.peerMediaPlayBtn:hover {
  filter: brightness(1.05);
}
.peerMediaRowMain {
  flex: 1;
  min-width: 0;
}
.peerMediaRowName {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 2px;
}
.peerMediaRowMeta {
  font-size: 13px;
  color: var(--tg-text-muted);
}
.peerMediaLinkRow {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  text-align: left;
}
.peerMediaLinkThumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: linear-gradient(135deg, #e3f2fd, #e8f5e9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  color: var(--tg-accent);
  flex-shrink: 0;
  overflow: hidden;
}
.peerMediaLinkThumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.peerMediaLinkText {
  flex: 1;
  min-width: 0;
}
.peerMediaLinkTitle {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.peerMediaLinkDesc {
  font-size: 13px;
  color: var(--tg-text-muted);
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.peerMediaLinkUrl {
  font-size: 13px;
  color: var(--tg-accent);
  word-break: break-all;
}
.peerMediaPhotoRow {
  padding: 8px 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}
.peerMediaPhotoRow img {
  max-width: 100%;
  max-height: 200px;
  border-radius: 10px;
}
.peerMediaEmpty {
  padding: 40px 20px;
  text-align: center;
  color: var(--tg-text-muted);
  font-size: 15px;
}
.peerInfoStatIcon {
  width: 24px;
  text-align: center;
  flex-shrink: 0;
  opacity: 0.85;
}
.peerInfoStatVal {
  margin-left: auto;
  color: var(--tg-text-muted);
  font-variant-numeric: tabular-nums;
}
.peerInfoFoot {
  padding: 16px;
  border-top: 1px solid var(--tg-chatlist-border);
}
.peerInfoFootBtn {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--tg-chatlist-border);
  background: var(--tg-chatlist-bg);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.peerInfoFootBtn:hover {
  background: var(--tg-chatlist-hover);
}

.tgMessages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
}

.tgDateDivider {
  text-align: center;
  margin: 16px 0;
}

.tgDateDivider span {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 8px;
  background: rgba(0,0,0,0.06);
  font-size: 13px;
  color: var(--tg-text-muted);
}

/* Пузыри */
.mRow { display: flex; margin: 4px 0; }
.mRow.in { justify-content: flex-start; }
.mRow.out { justify-content: flex-end; }

.mBubble {
  max-width: 65%;
  padding: 8px 12px 6px 12px;
  border-radius: 12px;
  border-top-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.mRow.out .mBubble {
  border-radius: 12px;
  border-top-right-radius: 4px;
  background: var(--tg-bubble-out);
}

.mRow.in .mBubble {
  background: var(--tg-bubble-in);
}

.mText {
  font-size: var(--cm-msg-font-px, 15px);
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}
.mMeta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
  font-size: calc(var(--cm-msg-font-px, 15px) * 0.8);
  color: var(--tg-text-muted);
}

.mRow.in .mMeta { justify-content: flex-start; }

.mRow.sys { justify-content: center !important; }
.mRow.sys .mBubble {
  background: rgba(0, 0, 0, 0.06);
  max-width: 90%;
  text-align: center;
}
.mRow.sys .mMeta { justify-content: center; }
.mRowSelect { align-items: flex-start; gap: 8px; }
.mRow.in:not(.sys),
.mRow.out:not(.sys) {
  align-items: flex-end;
  gap: 6px;
}

.mMiniAvatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--tg-text);
  overflow: hidden;
  align-self: flex-end;
  margin-bottom: 2px;
}
.mRow.out .mMiniAvatar {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}
.mMiniAvatarImg {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.mGroupAuthorName {
  font-size: 12px;
  font-weight: 600;
  color: #3390ec;
  margin-bottom: 4px;
  line-height: 1.2;
}
.mRow.out .mGroupAuthorName {
  color: rgba(255, 255, 255, 0.95);
}

.roomInfoMemberList {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  max-height: 200px;
  overflow-y: auto;
  font-size: 14px;
}
.roomInfoMemberList li {
  padding: 6px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}
.roomInfoWritersChecks {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  max-height: 220px;
  overflow-y: auto;
}
.roomInfoWriterRow {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.mReplyQuote {
  font-size: 13px;
  color: var(--tg-text-muted);
  border-left: 3px solid #2481cc;
  padding: 4px 0 4px 8px;
  margin-bottom: 6px;
  background: rgba(0, 0, 0, 0.03);
  border-radius: 4px;
}

.mRevoked {
  font-style: italic;
  color: var(--tg-text-muted);
}

.savedMessagesBanner {
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--tg-text-muted);
  padding: 10px 12px 14px;
  margin: 0 8px 8px;
  border-bottom: 1px solid var(--tg-chatlist-border);
}

.mEditedMark {
  font-size: 12px;
  color: var(--tg-text-muted);
  margin-top: 4px;
  padding-top: 2px;
}

.mReactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.mReactionPill {
  font: inherit;
  font-size: 14px;
  padding: 3px 8px;
  background: rgba(0, 0, 0, 0.06);
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition:
    transform 0.18s ease,
    background 0.18s ease,
    box-shadow 0.18s ease,
    border-color 0.18s ease;
}
.mReactionPill:hover {
  transform: scale(1.08);
  background: rgba(51, 144, 236, 0.12);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.mReactionPill:active {
  transform: scale(0.96);
}
.mReactionPill.mReactionMine {
  background: rgba(51, 144, 236, 0.18);
  border-color: rgba(51, 144, 236, 0.45);
}
.mReactionPill.mReactionMine:hover {
  background: rgba(51, 144, 236, 0.26);
}

.reactionAuthorsPop {
  position: fixed;
  z-index: 700;
  min-width: 200px;
  max-width: 280px;
  max-height: 50vh;
  overflow-y: auto;
  padding: 10px 12px;
  background: var(--tg-modal-bg);
  border: 1px solid var(--tg-chatlist-border);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
  font-size: 14px;
}
.reactionAuthorsPop[hidden] {
  display: none !important;
}
.reactionAuthorsTitle {
  font-weight: 700;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--tg-chatlist-border);
}
.reactionAuthorsRow {
  padding: 6px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}
.reactionAuthorsRow:last-child {
  border-bottom: none;
}

.mSelectTick {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #bbb;
  background: #fff;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 8px;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.mSelectTick.on {
  background: #4caf50;
  border-color: #4caf50;
  color: #fff;
}

.tgMsgSelectBar {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}
.tgMsgSelectBar[hidden] {
  display: none !important;
}
.tgMsgSelectCount {
  font-weight: 600;
  flex: 1;
  min-width: 100px;
}
.tgMsgSelectBtn {
  padding: 8px 14px;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}
.tgMsgSelectBtn.primary {
  background: #2481cc;
  color: #fff;
}
.tgMsgSelectBtn.danger {
  background: #e53935;
  color: #fff;
}
.tgMsgSelectBtn:not(.primary):not(.danger) {
  background: rgba(0, 0, 0, 0.06);
}

.tgReplyBar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-bottom: 6px;
  background: rgba(36, 129, 204, 0.12);
  border-radius: 10px;
  border-left: 3px solid #2481cc;
}
.tgReplyBar[hidden] {
  display: none !important;
}
.tgReplyBarInner {
  flex: 1;
  min-width: 0;
}
.tgReplyBarLabel {
  font-size: 11px;
  font-weight: 700;
  color: #2481cc;
  display: block;
}
.tgReplyBarText {
  font-size: 13px;
  color: var(--tg-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tgReplyBarClose {
  border: none;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  color: var(--tg-text-muted);
}

.tgPinnedMsg {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.04);
  border-bottom: 1px solid var(--tg-chatlist-border);
  font-size: 13px;
}
.tgPinnedMsg[hidden] {
  display: none !important;
}
.tgPinnedLabel {
  font-weight: 700;
  color: var(--tg-text-muted);
  white-space: nowrap;
}
.tgPinnedText {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tgPinnedClose {
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  color: var(--tg-text-muted);
}

.msgCtxMenu {
  position: fixed;
  z-index: 600;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  min-width: 220px;
  max-width: 280px;
  overflow: hidden;
}
.msgReactionDock {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px;
  border-bottom: 1px solid #eee;
  align-items: center;
}
.msgReactionBtn {
  border: none;
  background: #f0f0f0;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 18px;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    background 0.2s ease,
    box-shadow 0.2s ease;
}
.msgReactionBtn:hover {
  transform: scale(1.12);
  background: #e3f2fd;
  box-shadow: 0 2px 10px rgba(51, 144, 236, 0.25);
}
.msgReactionBtn:active {
  transform: scale(0.94);
}
.msgReactionBtn.msgReactionBtnActive {
  background: rgba(51, 144, 236, 0.35);
  box-shadow: inset 0 0 0 2px rgba(51, 144, 236, 0.5);
}
.msgReactionBtn.msgReactionBtnActive:hover {
  background: rgba(51, 144, 236, 0.45);
}
.msgCtxList {
  padding: 6px 0;
}
.msgCtxItem {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  border: none;
  background: none;
  font-size: 15px;
  cursor: pointer;
  color: var(--tg-text);
}
.msgCtxItem:hover {
  background: #f5f5f5;
}

.modal .btn.danger {
  background: #e53935;
  color: #fff;
}

.mVoiceLabel {
  font-size: 13px;
  color: var(--tg-text-muted);
  margin-bottom: 6px;
}

.mVoice audio {
  max-width: 100%;
  height: 36px;
}

.tgComposerBtn.recording {
  background: rgba(211, 47, 47, 0.25);
  border-radius: 50%;
  animation: pulseRecMic 0.9s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(211, 47, 47, 0.45);
}

@keyframes pulseRecMic {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(211, 47, 47, 0.5);
  }
  70% {
    transform: scale(1.05);
    box-shadow: 0 0 0 12px rgba(211, 47, 47, 0);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(211, 47, 47, 0);
  }
}

.tgComposer.isRecording {
  box-shadow: inset 0 3px 0 #e53935;
}

.tgRecBar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 10px;
  background: linear-gradient(90deg, rgba(229, 57, 53, 0.12), rgba(229, 57, 53, 0.04));
  border-bottom: 1px solid rgba(229, 57, 53, 0.25);
  font-size: 14px;
  font-weight: 600;
  color: #c62828;
}

.tgComposer.isRecording .tgRecBar {
  display: flex;
}

.tgRecDot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e53935;
  animation: recBlink 1s step-end infinite;
}

@keyframes recBlink {
  50% {
    opacity: 0.35;
  }
}

.tgRecWave {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 22px;
}

.tgRecWave i {
  display: block;
  width: 4px;
  border-radius: 2px;
  background: #e53935;
  animation: recBar 0.8s ease-in-out infinite;
}

.tgRecWave i:nth-child(1) {
  animation-delay: 0s;
  height: 8px;
}
.tgRecWave i:nth-child(2) {
  animation-delay: 0.1s;
  height: 16px;
}
.tgRecWave i:nth-child(3) {
  animation-delay: 0.2s;
  height: 22px;
}
.tgRecWave i:nth-child(4) {
  animation-delay: 0.15s;
  height: 14px;
}
.tgRecWave i:nth-child(5) {
  animation-delay: 0.05s;
  height: 10px;
}

@keyframes recBar {
  0%,
  100% {
    transform: scaleY(0.45);
    opacity: 0.7;
  }
  50% {
    transform: scaleY(1);
    opacity: 1;
  }
}

.tgRecLabel {
  flex: 1;
}

/* Звонок — компактное всплывающее окно по центру */
.callOverlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.48);
  box-sizing: border-box;
}

.callOverlay.show {
  display: flex;
  position: relative;
}

.callProximityDim {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease-out;
}

.callOverlay.proximityNear .callProximityDim {
  opacity: 0.92;
}

.callFullCard {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 300px;
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  padding: 14px 14px 16px;
  box-sizing: border-box;
  background: linear-gradient(165deg, #2d3e52 0%, #1a2636 55%, #15202c 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
  flex: 0 0 auto;
}

.callTopBar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 32px;
  margin-bottom: 4px;
}

.callTopSpacer {
  flex: 1;
}

.callMinimizeBtn {
  padding: 6px 12px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.92);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.callMinimizeBtn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.callCenterBlock {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px 4px 12px;
}

.callAvatar {
  font-size: 52px;
  margin-bottom: 10px;
  line-height: 1;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.35));
}

.callPeerName {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 6px;
  word-break: break-word;
  color: #fff;
  max-width: 100%;
}

.callStatusText {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.62);
  margin-bottom: 4px;
  min-height: 20px;
}

/* Мобильные кнопки звонка: микрофон, громкая связь (скрыты на ПК) */
.callMobileControls {
  display: none;
  flex-direction: row;
  justify-content: center;
  align-items: stretch;
  gap: 20px;
  padding: 12px 8px 4px;
}

.callProximityHint {
  display: none;
  margin: 0 0 8px;
  padding: 0 8px;
  font-size: 12px;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
}

.callRoundBtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 72px;
  min-height: 72px;
  padding: 8px 6px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  -webkit-tap-highlight-color: transparent;
}

.callRoundBtn:active {
  transform: scale(0.96);
}

.callRoundBtn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.callRoundBtn.on {
  background: rgba(52, 199, 89, 0.45);
}

.callRoundBtn.muted {
  background: rgba(255, 59, 48, 0.55);
}

.callRoundBtn.speakerOn {
  background: rgba(100, 181, 246, 0.45);
}

.callRoundBtnIcon {
  font-size: 22px;
  line-height: 1;
}

.callRoundBtnLabel {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

@media (max-width: 720px) {
  .callOverlay.show .callMobileControls {
    display: flex;
  }

  .callOverlay.show .callProximityHint:not(:empty) {
    display: block;
  }

  .callFullCard {
    width: calc(100% - 8px);
    max-width: min(400px, 100vw - 24px);
  }
}

.callActionsBig {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 8px 0 0;
}

.callBtn {
  padding: 11px 14px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  min-width: 0;
}

.callBtn.accept,
.callBtn.reject {
  flex: 1 1 calc(50% - 4px);
  max-width: calc(50% - 4px);
}

.callBtn.hangup {
  flex: 1 1 100%;
}

.callBtn.accept {
  background: #34c759;
  color: #fff;
}

.callBtn.reject {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.callBtn.hangup {
  background: #ff3b30;
  color: #fff;
}

/* Свернутый звонок — правый верх */
.callMinimizedPill {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 510;
  display: none;
  align-items: stretch;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  background: rgba(30, 40, 55, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.callMinimizedPill.show {
  display: flex;
}

.callPillExpand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 10px 14px;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  max-width: 200px;
}

.callPillIcon {
  font-size: 18px;
}

.callPillLabel {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.callPillHangup {
  width: 44px;
  border: none;
  background: rgba(255, 59, 48, 0.35);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.callPillHangup:hover {
  background: #ff3b30;
}

#callRemoteAudio {
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

/* Свайп-удаление в списке чатов */
.chatRowSwipe {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--tg-chatlist-border);
}

.chatRowSwipeInner {
  display: flex;
  width: 100%;
  transition: transform 0.22s ease-out;
  will-change: transform;
  background: var(--tg-chatlist-bg);
}

.chatRowSwipe .chatItem {
  flex: 1;
  border-bottom: none;
}

.chatRowSwipeDelete {
  flex: 0 0 76px;
  width: 76px;
  border: none;
  background: #e53935;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  padding: 0 6px;
}

.chatRowSwipeDelete:hover {
  background: #c62828;
}

/* Контекстное меню чата (ПК) */
.tgChatListCtxMenu {
  position: fixed;
  z-index: 235;
  min-width: 200px;
  padding: 6px 0;
  background: var(--tg-chatlist-bg);
  border: 1px solid var(--tg-chatlist-border);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

.tgChatListCtxItem {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: none;
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  color: var(--tg-text);
}

.tgChatListCtxItem:hover {
  background: var(--tg-chatlist-hover);
}

.tgChatListCtxItem.danger {
  color: #c62828;
}

/* Превью чата при долгом нажатии */
.chatPeekSheet {
  position: fixed;
  inset: 0;
  z-index: 230;
  display: none;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
}

.chatPeekSheet.show {
  display: flex;
  pointer-events: auto;
}

.chatPeekScrim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.chatPeekPanel {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: min(78vh, 620px);
  background: var(--tg-chatlist-bg);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: peekUp 0.25s ease-out;
}

@keyframes peekUp {
  from {
    transform: translateY(100%);
    opacity: 0.8;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.chatPeekTitle {
  padding: 14px 16px;
  font-size: 17px;
  font-weight: 700;
  border-bottom: 1px solid var(--tg-chatlist-border);
}

.chatPeekMsgs {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.45;
  background: var(--tg-chat-bg);
  min-height: 120px;
  max-height: 38vh;
}

.chatPeekLine {
  margin-bottom: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.85);
}

.chatPeekLine.out {
  margin-left: 24px;
  background: var(--tg-bubble-out);
}

.chatPeekLine.in {
  margin-right: 24px;
}

.chatPeekMeta {
  font-size: 11px;
  color: var(--tg-text-muted);
  margin-bottom: 4px;
}

.chatPeekActions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--tg-chatlist-border);
  background: var(--tg-chatlist-bg);
}

.chatPeekBtn {
  padding: 12px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  background: #f0f0f0;
  color: var(--tg-text);
}

.chatPeekBtn.primary {
  grid-column: 1 / -1;
  background: var(--tg-accent);
  color: #fff;
}

.chatPeekBtn.danger {
  grid-column: 1 / -1;
  background: rgba(229, 57, 53, 0.12);
  color: #c62828;
}

/* Эмодзи-панель — позиционирование относительно .tgComposer ниже */

.tgEmojiPopover {
  position: absolute;
  bottom: 100%;
  right: 8px;
  left: auto;
  width: 52px;
  max-height: min(52vh, 360px);
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--tg-chatlist-bg);
  border: 1px solid var(--tg-chatlist-border);
  border-radius: 12px;
  box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.14);
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  z-index: 50;
  margin-bottom: 6px;
  scrollbar-width: thin;
}

.tgEmojiPopover[hidden] {
  display: none !important;
}

.tgEmojiBtn {
  border: none;
  background: transparent;
  font-size: 26px;
  line-height: 1.15;
  padding: 8px 4px;
  border-radius: 10px;
  cursor: pointer;
  width: 100%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, background 0.12s ease;
}

.tgEmojiBtn:hover {
  background: var(--tg-chatlist-hover);
  transform: scale(1.08);
}

.tgEmojiBtn:active {
  transform: scale(0.95);
}

/* Composer */
.tgComposer {
  position: relative;
  padding: 12px 16px;
  background: var(--tg-chatlist-bg);
  border-top: 1px solid var(--tg-chatlist-border);
}

.tgComposerInner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 14px;
  background: #f0f0f0;
  border-radius: 24px;
  min-height: 48px;
}

.tgComposerBtn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  font-size: 20px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tgComposerBtn:hover { background: rgba(0,0,0,0.06); }

#msg {
  flex: 1;
  min-height: 24px;
  max-height: 120px;
  padding: 10px 4px;
  border: none;
  background: transparent;
  font-size: 15px;
  resize: none;
  font-family: inherit;
}

#msg::placeholder { color: var(--tg-text-muted); }
#msg:focus { outline: none; }

.tgComposerSend {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border: none;
  border-radius: 50%;
  background: var(--tg-accent);
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.tgComposerSend .tgIcon {
  fill: currentColor;
}

.tgComposerSend:hover { opacity: 0.9; }
.tgComposerSend:disabled { opacity: 0.5; cursor: not-allowed; }

.tgComposerRow { margin-top: 8px; }
.tgWarn { color: #d32f2f; font-size: 13px; }

/* ===== Drawer ===== */
.tgDrawer {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
}

.tgDrawer.show { display: block; }

.tgDrawerScrim {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  transition: opacity 0.2s;
}

.tgDrawer.show .tgDrawerScrim { opacity: 1; }

.tgDrawerPanel {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: min(300px, 85vw);
  background: var(--tg-sidebar);
  transform: translateX(-100%);
  transition: transform 0.2s;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tgDrawer.show .tgDrawerPanel { transform: translateX(0); }

.tgDrawerHeader {
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  gap: 12px;
  align-items: center;
}

.tgDrawerAvatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--tg-sidebar-active);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 600;
  color: #fff;
}

.tgDrawerName { font-size: 17px; font-weight: 600; color: #fff; }
.tgDrawerSub { font-size: 14px; color: rgba(255,255,255,0.7); margin-top: 2px; }

.tgDrawerItems { padding: 12px; flex: 1; overflow-y: auto; }

.tgDrawerItem {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: #fff;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 2px;
}

.tgDrawerItem:hover { background: rgba(255,255,255,0.1); }
.tgDrawerItem.danger { color: #ff6b6b; }
.tgDrawerItemEmoji {
  font-size: 18px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
  line-height: 1;
}
.tgDrawerSep { height: 1px; background: rgba(255,255,255,0.1); margin: 8px 0; }

/* ===== Sheet ===== */
.tgSheet {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
}

.tgSheet.show { pointer-events: auto; }

.tgSheetScrim {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  transition: opacity 0.2s;
}

.tgSheet.show .tgSheetScrim { opacity: 1; }

.tgSheetPanel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--tg-chatlist-bg);
  border-radius: 16px 16px 0 0;
  transform: translateY(100%);
  transition: transform 0.25s;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
}

.tgSheet.show .tgSheetPanel { transform: translateY(0); }

.tgSheetHeader { padding: 16px; border-bottom: 1px solid var(--tg-chatlist-border); }
.tgSheetTitle { font-size: 17px; font-weight: 600; }
.tgSheetSub { font-size: 14px; color: var(--tg-text-muted); margin-top: 4px; }
.tgSheetItems { padding: 8px; }

.tgSheetItem {
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--tg-text);
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}

.tgSheetItem:hover { background: var(--tg-chatlist-hover); }
.tgSheetItem.danger { color: #d32f2f; }
.tgSheetSep { height: 1px; background: var(--tg-chatlist-border); margin: 8px 0; }

.tgKeys { margin: 16px; padding: 12px; background: #f5f5f5; border-radius: 12px; }
.tgKeys > summary { cursor: pointer; font-size: 14px; font-weight: 500; }
.tgKeysGrid { margin-top: 12px; display: grid; gap: 12px; }
.tgKeysLabel { font-size: 12px; color: var(--tg-text-muted); margin-bottom: 6px; }
.tgKeysRow { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.tgKeysHint { margin-top: 8px; font-size: 12px; color: var(--tg-text-muted); }

.tgSheetViz { margin: 16px; padding-top: 16px; border-top: 1px solid var(--tg-chatlist-border); }
.tgSheetVizTop { margin-bottom: 8px; }
.tgSheetVizTitle { font-size: 14px; font-weight: 600; }
.tgSheetVizCanvasWrap { height: 160px; border-radius: 12px; overflow: hidden; background: #f0f0f0; }

/* ===== Tab bar (mobile) ===== */
.tgTabBar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 56px;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--tg-chatlist-bg);
  border-top: 1px solid var(--tg-chatlist-border);
  z-index: 100;
  justify-content: space-around;
  align-items: center;
}

.tgTabItem {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px;
  border: none;
  background: transparent;
  color: var(--tg-text-muted);
  cursor: pointer;
  font-size: 11px;
}

.tgTabItem.active { color: var(--tg-accent); }
.tgTabIcon { font-size: 22px; }

/* ===== Модалки ===== */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0,0,0,0.5);
  z-index: 150;
}

.modal.show { display: flex; }

.modalCard {
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 16px;
  background: var(--tg-modal-bg);
  box-shadow: 0 24px 48px rgba(0,0,0,0.2);
}

.modalHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--tg-chatlist-border);
}

.modalTitle { font-size: 18px; font-weight: 600; }
.modalBody { padding: 20px; }
.modalHint { font-size: 14px; color: var(--tg-text-muted); margin-bottom: 16px; line-height: 1.45; }
.modalRow { display: flex; gap: 12px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.modalStatus { font-size: 13px; color: var(--tg-text-muted); }
.modalFound { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--tg-chatlist-border); }

.accountModalCard {
  max-width: 480px;
}

/* Экран «Настройки» */
#mAccount.modal {
  align-items: flex-start;
  justify-content: center;
  padding: 12px;
  padding-top: max(12px, env(safe-area-inset-top));
}

.tgSettingsModalCard {
  position: relative;
  max-width: 420px;
  width: 100%;
  max-height: min(92vh, 900px);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  border-radius: 12px;
  background: var(--tg-chatlist-bg);
}

.tgSettingsHeader {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 4px 6px 0;
  flex-shrink: 0;
  border-bottom: 1px solid var(--tg-chatlist-border);
  background: var(--tg-chatlist-bg);
}

.tgSettingsHeaderBtn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--tg-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tgSettingsHeaderBtn:hover {
  background: var(--tg-chatlist-hover);
}

.tgSettingsTitle {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  padding: 0 4px;
}

.tgSettingsHeaderActions {
  display: flex;
  align-items: center;
  gap: 0;
}

.tgSettingsBody {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.tgSettingsHero {
  text-align: center;
  padding: 20px 20px 8px;
}

.tgSettingsAvatarWrap {
  position: relative;
  width: 96px;
  height: 96px;
  margin: 0 auto 14px;
}

.tgSettingsAvatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  background: var(--tg-chatlist-hover);
}

.tgSettingsCamFab {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--tg-chatlist-bg);
  background: var(--tg-accent);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.tgSettingsCamFab:hover {
  filter: brightness(1.05);
}

.tgSettingsNameDisplay {
  font-size: 21px;
  font-weight: 700;
  text-align: center;
  padding: 6px 20px 4px;
  min-height: 34px;
  color: var(--tg-text);
  line-height: 1.25;
}

.tgSettingsOnline {
  font-size: 14px;
  color: var(--tg-text-muted);
  line-height: 1.3;
}

.tgSettingsAccountBlock {
  padding: 4px 0 0;
}

.tgSettingsAccRow {
  display: flex;
  gap: 14px;
  padding: 12px 18px;
  align-items: flex-start;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.tgSettingsAccIcon {
  width: 28px;
  text-align: center;
  color: var(--tg-text-muted);
  font-size: 20px;
  flex-shrink: 0;
  line-height: 1.4;
  padding-top: 2px;
}

.tgSettingsAccIconInfo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-top: 2px;
  margin-left: 3px;
  border-radius: 50%;
  border: 2px solid var(--tg-text-muted);
  font-size: 12px;
  font-weight: 800;
  font-style: italic;
  color: var(--tg-text-muted);
  line-height: 1;
  padding: 0;
}

.tgSettingsAccCol {
  flex: 1;
  min-width: 0;
}

.tgSettingsAccValue {
  font-size: 16px;
  color: var(--tg-text);
  word-break: break-word;
  line-height: 1.35;
}

.tgSettingsAccMuted {
  color: var(--tg-text-muted);
}

.tgSettingsAccLabel {
  font-size: 13px;
  color: var(--tg-text-muted);
  margin-top: 5px;
  line-height: 1.25;
}

.tgSettingsAccInput,
.tgSettingsAccTextarea {
  width: 100%;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  font-size: 16px;
  color: var(--tg-text);
  background: transparent;
  outline: none;
  line-height: 1.35;
}

.tgSettingsAccReadonly {
  color: var(--tg-text);
  cursor: default;
}

.tgSettingsAccTextarea {
  resize: vertical;
  min-height: 40px;
  max-height: 160px;
}

.tgSettingsAccRowBio .tgSettingsAccTextarea {
  min-height: 48px;
}

.tgSettingsDivider {
  height: 1px;
  margin: 8px 0;
  background: var(--tg-chatlist-border);
  border: none;
}

.tgSettingsDividerLoose {
  margin: 16px 0 10px;
}

.tgSettingsMenuDetails {
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.tgSettingsMenuDetails > summary {
  list-style: none;
}

.tgSettingsMenuDetails > summary::-webkit-details-marker {
  display: none;
}

.tgSettingsMenuRow {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
  background: var(--tg-chatlist-bg);
}

.tgSettingsMenuRow:hover {
  background: var(--tg-chatlist-hover);
}

.tgSettingsMenuRowStatic {
  cursor: default;
}

.tgSettingsMenuRowStatic:hover {
  background: var(--tg-chatlist-bg);
}

.tgSettingsMenuRowButton {
  width: 100%;
  border: none;
  font: inherit;
  text-align: left;
}

.tgSettingsMenuIcon {
  width: 28px;
  text-align: center;
  font-size: 20px;
  opacity: 0.72;
  flex-shrink: 0;
}

.tgSettingsMenuIconLang {
  font-weight: 700;
  font-size: 17px;
  opacity: 0.55;
}

.tgSettingsMenuIconStar {
  opacity: 1;
  filter: saturate(1.2);
}

.tgSettingsMenuText {
  flex: 1;
  font-size: 16px;
  color: var(--tg-text);
}

.tgSettingsMenuHint {
  font-size: 15px;
  color: var(--tg-text-muted);
  flex-shrink: 0;
}

.tgSettingsMenuRowPremium .tgSettingsMenuText {
  color: var(--tg-accent);
  font-weight: 600;
}

.tgSettingsSubpanel {
  padding: 0 18px 16px 60px;
  background: rgba(0, 0, 0, 0.02);
}

.tgSettingsSubLabel {
  margin-top: 10px !important;
}

.tgSettingsSubHint {
  font-size: 13px;
  color: var(--tg-text-muted);
  margin-top: 10px;
  line-height: 1.4;
}

.tgSettingsFieldLabel {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--tg-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 12px;
  margin-bottom: 6px;
}

.tgSettingsFieldLabel:first-child {
  margin-top: 4px;
}

.tgSettingsFieldInput,
.tgSettingsFieldSelect {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--tg-chatlist-border);
  font: inherit;
  font-size: 15px;
  background: var(--tg-modal-bg);
  color: var(--tg-text);
}

.tgSettingsPassRow {
  display: flex;
  gap: 8px;
  align-items: center;
}

.tgSettingsFieldInputFlex {
  flex: 1;
}

.tgSettingsEyeBtn {
  flex-shrink: 0;
  padding: 8px 12px;
}

.tgSettingsSaveBlock {
  padding: 20px 18px 8px;
}

.tgSettingsSaveBtn {
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
  border-radius: 10px;
}

.tgSettingsStatus {
  display: block;
  margin-top: 10px;
  font-size: 13px;
  color: var(--tg-text-muted);
  text-align: center;
}

.tgSettingsOverflow {
  position: absolute;
  top: 48px;
  right: 8px;
  min-width: 200px;
  background: var(--tg-chatlist-bg);
  border: 1px solid var(--tg-chatlist-border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  z-index: 5;
  padding: 6px;
}

.tgSettingsOverflowItem {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  color: var(--tg-text);
}

.tgSettingsOverflowItem:hover {
  background: var(--tg-chatlist-hover);
}

/* «Изменить профиль» (карандаш в настройках) */
.tgEditProfileLayer {
  position: absolute;
  inset: 0;
  z-index: 14;
  display: flex;
  flex-direction: column;
  background: var(--tg-chatlist-bg);
  border-radius: inherit;
  overflow: hidden;
}
.tgEditProfileLayer[hidden] {
  display: none !important;
}
.tgEditProfileHead {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px 6px 0;
  flex-shrink: 0;
  border-bottom: 1px solid var(--tg-chatlist-border);
}
.tgEditProfileBack {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  color: var(--tg-text);
}
.tgEditProfileBack:hover {
  background: var(--tg-chatlist-hover);
}
.tgEditProfileTitle {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
}
.tgEditProfileHeadSpacer {
  width: 40px;
  flex-shrink: 0;
}
.tgEditProfileScroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 0 24px;
}
.tgEditProfileAvatarWrap {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 8px auto 24px;
}
.tgEditProfileAvatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  background: var(--tg-chatlist-hover);
}
.tgEditProfileCamFab {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid var(--tg-chatlist-bg);
  background: var(--tg-accent);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}
.tgFloatField {
  position: relative;
  margin: 0 18px 16px;
}
.tgFloatInput,
.tgFloatTextarea {
  width: 100%;
  box-sizing: border-box;
  padding: 18px 14px 10px;
  border: 1px solid var(--tg-chatlist-border);
  border-radius: 12px;
  font: inherit;
  font-size: 16px;
  background: var(--tg-chatlist-bg);
  color: var(--tg-text);
  outline: none;
}
.tgFloatInput:focus,
.tgFloatTextarea:focus {
  border-color: var(--tg-accent);
  box-shadow: 0 0 0 1px var(--tg-accent);
}
.tgFloatFieldMultiline .tgFloatTextarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.4;
}
.tgFloatLabel {
  position: absolute;
  left: 14px;
  top: 17px;
  font-size: 16px;
  color: var(--tg-text-muted);
  pointer-events: none;
  transition: transform 0.16s ease, color 0.16s ease;
  transform-origin: left top;
  background: var(--tg-chatlist-bg);
  padding: 0 5px;
  max-width: calc(100% - 36px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tgFloatInput:focus + .tgFloatLabel,
.tgFloatInput:not(:placeholder-shown) + .tgFloatLabel,
.tgFloatTextarea:focus + .tgFloatLabel,
.tgFloatTextarea:not(:placeholder-shown) + .tgFloatLabel {
  transform: translateY(-11px) scale(0.82);
  color: var(--tg-accent);
}
.tgEditProfileHint {
  margin: -8px 18px 18px;
  padding: 0 2px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--tg-text-muted);
}
.tgEditProfileSectionTitle {
  margin: 8px 18px 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--tg-accent);
}
.tgEditProfileActions {
  padding: 8px 18px 0;
}
.tgEditProfileDone {
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
  border-radius: 10px;
}
.tgEditProfileStatus {
  display: block;
  margin-top: 10px;
  font-size: 13px;
  color: var(--tg-text-muted);
  text-align: center;
}

/* Вложенный экран «Основные» */
.tgGeneralSettingsLayer {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: flex;
  flex-direction: column;
  background: var(--tg-chatlist-bg);
  border-radius: inherit;
  overflow: hidden;
}
.tgGeneralSettingsLayer[hidden] {
  display: none !important;
}
.tgGeneralSettingsHead {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px 6px 0;
  flex-shrink: 0;
  border-bottom: 1px solid var(--tg-chatlist-border);
}
.tgGeneralSettingsBack {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  color: var(--tg-text);
}
.tgGeneralSettingsBack:hover {
  background: var(--tg-chatlist-hover);
}
.tgGeneralSettingsTitle {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
}
.tgGeneralSettingsHeadSpacer {
  width: 40px;
  flex-shrink: 0;
}
.tgGeneralSettingsScroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 24px;
}
.tgGeneralSectionTitle {
  padding: 14px 18px 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--tg-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tgGeneralSectionTitleSpaced {
  margin-top: 8px;
}
.tgGenSliderBlock {
  padding: 8px 18px 16px;
}
.tgGenSliderLabelRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.tgGenSliderLabel {
  font-size: 15px;
  color: var(--tg-text);
}
.tgGenSliderValue {
  font-size: 15px;
  font-weight: 600;
  color: var(--tg-text-muted);
  min-width: 28px;
  text-align: right;
}
.tgGenSlider {
  width: 100%;
  height: 4px;
  accent-color: var(--tg-accent);
  cursor: pointer;
}

.tgGenInlineHint {
  margin: -6px 18px 14px;
  padding: 0 2px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--tg-text-muted);
}
.tgGenInlineHint[hidden] {
  display: none !important;
}
.tgGenMenuRow {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 18px;
  border: none;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  background: var(--tg-chatlist-bg);
  font: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--tg-text);
}
.tgGenMenuRow:hover {
  background: var(--tg-chatlist-hover);
}
.tgGenMenuRowToggle {
  cursor: pointer;
}
.tgGenMenuIcon {
  width: 28px;
  text-align: center;
  font-size: 20px;
  flex-shrink: 0;
  opacity: 0.75;
}
.tgGenMenuIconCheck {
  color: var(--tg-accent);
  font-weight: 800;
  font-size: 18px;
  opacity: 1;
}
.tgGenMenuRowToggle[aria-pressed='false'] .tgGenMenuIconCheck {
  opacity: 0.2;
  color: var(--tg-text-muted);
}
.tgGenMenuText {
  flex: 1;
  font-size: 16px;
}
.tgGenMenuRight {
  font-size: 15px;
  color: var(--tg-text-muted);
  flex-shrink: 0;
}
.tgThemePresetStrip {
  display: flex;
  gap: 10px;
  padding: 4px 18px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tgThemePresetCard {
  flex: 0 0 58px;
  height: 74px;
  border-radius: 10px;
  border: 2px solid transparent;
  cursor: pointer;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #e8ecf0 0%, #d4dde8 40%, #c5d5e8 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}
.tgThemePresetCard[data-preset='1'] {
  background: linear-gradient(145deg, #fff8e6 0%, #ffe0b2 100%);
}
.tgThemePresetCard[data-preset='2'] {
  background: linear-gradient(145deg, #e3f2fd 0%, #b3e5fc 100%);
}
.tgThemePresetCard[data-preset='3'] {
  background: linear-gradient(145deg, #f3e5f5 0%, #e1bee7 100%);
}
.tgThemePresetCard[data-preset='4'] {
  background: linear-gradient(145deg, #eceff1 0%, #cfd8dc 100%);
}
.tgThemePresetCard.selected {
  border-color: var(--tg-accent);
  box-shadow: 0 0 0 1px var(--tg-accent);
}
.tgGenRadioGroup {
  padding: 0 0 8px;
}
.tgGenRadioBlock {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  cursor: pointer;
  margin: 0;
}
.tgGenRadioBlock input {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--tg-accent);
}
.tgGenRadioMain {
  font-size: 16px;
  color: var(--tg-text);
  line-height: 1.35;
}
.tgGenRadioSub {
  font-size: 13px;
  color: var(--tg-text-muted);
  margin-top: 4px;
  line-height: 1.35;
}
.tgGenRadioBlockTall {
  align-items: flex-start;
}

body.theme-night {
  --tg-chatlist-bg: #17212b;
  --tg-chatlist-border: #2b3540;
  --tg-chatlist-hover: #1e2a35;
  --tg-chatlist-active: #2b5278;
  --tg-text: #e8eaed;
  --tg-text-muted: #8a9aa8;
  --tg-modal-bg: #17212b;
  --tg-bubble-in: #182533;
  --tg-bubble-out: #2b5278;
}

.ui-reduce-motion,
.ui-reduce-motion * {
  scroll-behavior: auto !important;
}
.ui-reduce-motion * {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
}

/* Лёгкие варианты фона чата (пресеты) */
html[data-tg-chat-preset='0'] {
  --tg-chat-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cg fill='%23000' fill-opacity='0.035'%3E%3Cpath d='M40 30c8-12 28-12 36 0 6 10 4 24-4 32-8 8-24 8-32-4-6-10-4-22 0-28z'/%3E%3Cpath d='M120 100c10-8 26-6 32 6 6 12 2 28-8 36-10 8-26 6-34-8-6-12-2-26 10-34z'/%3E%3Ccircle cx='90' cy='90' r='3'/%3E%3C/g%3E%3C/svg%3E");
}
html[data-tg-chat-preset='1'] {
  --tg-chat-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Crect fill='%23ff9800' fill-opacity='0.06' width='120' height='120'/%3E%3Ccircle cx='30' cy='40' r='20' fill='%23ffcc80' fill-opacity='0.15'/%3E%3Ccircle cx='90' cy='80' r='24' fill='%23ffe082' fill-opacity='0.12'/%3E%3C/svg%3E");
}
html[data-tg-chat-preset='2'] {
  --tg-chat-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Crect fill='%232196f3' fill-opacity='0.05' width='100' height='100'/%3E%3Cpath fill='%2364b5f6' fill-opacity='0.1' d='M0 60 L100 40 L100 100 L0 100 Z'/%3E%3C/svg%3E");
}
html[data-tg-chat-preset='3'] {
  --tg-chat-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80'%3E%3Crect fill='%239c27b0' fill-opacity='0.05' width='80' height='80'/%3E%3Cpolygon fill='%23ce93d8' fill-opacity='0.12' points='40,5 75,70 5,70'/%3E%3C/svg%3E");
}
html[data-tg-chat-preset='4'] {
  --tg-chat-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Crect fill='%23445564' fill-opacity='0.04' width='140' height='140'/%3E%3Ccircle cx='70' cy='70' r='50' fill='%2378909c' fill-opacity='0.08'/%3E%3C/svg%3E");
}

.accDetails {
  margin-bottom: 12px;
  border: 1px solid var(--tg-chatlist-border);
  border-radius: 12px;
  padding: 4px 14px 14px;
  background: rgba(0, 0, 0, 0.02);
}

.accDetailsSummary {
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  padding: 10px 0 6px;
  list-style: none;
}

.accDetailsSummary::-webkit-details-marker {
  display: none;
}

.accCheckLabel {
  display: flex !important;
  align-items: center;
  gap: 10px;
  flex-direction: row !important;
  margin-top: 14px !important;
  cursor: pointer;
  font-size: 15px;
  color: var(--tg-text);
}

.accCheckLabel input {
  width: auto !important;
  margin: 0 !important;
  flex-shrink: 0;
}

/* «Сохраненные»: свои заметки справа, пересланное слева (как обычный in/out) */
.mBubbleSaved {
  max-width: min(92%, 520px);
  border: 1px solid rgba(51, 144, 236, 0.35);
  background: linear-gradient(135deg, rgba(227, 242, 253, 0.96) 0%, rgba(232, 245, 233, 0.92) 100%);
}

.mBubbleSavedFwd {
  border-color: rgba(0, 0, 0, 0.1);
  background: var(--tg-bubble-in);
}

.mForwardBanner {
  font-size: 12px;
  font-weight: 600;
  color: var(--tg-accent);
  line-height: 1.35;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(51, 144, 236, 0.22);
}

/* Пересланное в обычных чатах — лёгкая подсветка пузыря */
.mBubbleForwarded {
  border: 1px solid rgba(51, 144, 236, 0.28);
}

.profileValBio {
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 120px;
  overflow-y: auto;
}

.peerMediaFileRow {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}
.peerMediaFileIcon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--tg-chatlist-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.peerMediaFileName {
  font-weight: 600;
  font-size: 14px;
  word-break: break-word;
}
.peerMediaFileMeta {
  font-size: 12px;
  color: var(--tg-text-muted);
  margin-top: 2px;
}

.mSavedDualCaption {
  font-size: 11px;
  font-weight: 700;
  color: var(--tg-accent);
  text-align: center;
  margin-bottom: 6px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

body.theme-light {
  --tg-chatlist-bg: #ffffff;
  --tg-chatlist-border: #e2e5e8;
  --tg-chatlist-hover: #f0f2f4;
  --tg-chatlist-active: #e3f2fd;
  --tg-text: #1a1a1a;
  --tg-text-muted: #5c6368;
  --tg-modal-bg: #fff;
}

.ui-compact .tgNavBtn {
  width: 44px;
  height: 44px;
}

.ui-compact .tgFoldersNav .tgFolderItem {
  min-height: 50px;
  padding-top: 4px;
  padding-bottom: 6px;
}

.forwardModalCard {
  max-width: 440px;
}

.forwardSearchInput {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 10px;
}

.forwardChatList {
  max-height: min(42vh, 360px);
  overflow-y: auto;
  border: 1px solid var(--tg-chatlist-border);
  border-radius: 12px;
  background: #fafafa;
  margin-bottom: 12px;
}

.forwardChatRow {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: none;
  border-bottom: 1px solid var(--tg-chatlist-border);
  background: transparent;
  cursor: pointer;
  font: inherit;
}

.forwardChatRow:last-child {
  border-bottom: none;
}

.forwardChatRow:hover {
  background: var(--tg-chatlist-hover);
}

.forwardChatRow.selected {
  background: var(--tg-chatlist-active);
  outline: 2px solid var(--tg-accent);
  outline-offset: -2px;
}

.forwardChatRowTitle {
  font-weight: 600;
  font-size: 15px;
  color: var(--tg-text);
}

.forwardChatRowSub {
  font-size: 13px;
  color: var(--tg-text-muted);
  margin-top: 2px;
}

label { display: block; font-size: 14px; color: var(--tg-text-muted); margin-bottom: 6px; margin-top: 16px; }
label:first-child { margin-top: 0; }

input, textarea, select {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--tg-chatlist-border);
  border-radius: 12px;
  background: #fff;
  color: var(--tg-text);
  font-size: 16px;
  font-family: inherit;
}

input:focus, textarea:focus { outline: none; border-color: var(--tg-accent); }
input[readonly] { background: #f5f5f5; }

.btn {
  padding: 10px 18px;
  border: none;
  border-radius: 12px;
  background: #e8e8e8;
  color: var(--tg-text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

.btn:hover { background: #ddd; }
.btn.primary { background: var(--tg-accent); color: #fff; }
.btn.primary:hover { opacity: 0.95; }

.profileHero { display: flex; gap: 16px; align-items: center; padding-bottom: 16px; border-bottom: 1px solid var(--tg-chatlist-border); margin-bottom: 16px; }
.profileAvatar { width: 72px; height: 72px; border-radius: 50%; background: var(--tg-accent); object-fit: cover; }
.profileName { font-size: 18px; font-weight: 600; }
.profileSub { font-size: 14px; color: var(--tg-text-muted); margin-top: 4px; }
.profileGrid { display: flex; flex-direction: column; gap: 8px; }
.profileRow { display: flex; justify-content: space-between; padding: 12px 16px; background: #f5f5f5; border-radius: 12px; }
.profileKey { font-size: 13px; color: var(--tg-text-muted); }
.profileVal { font-size: 14px; }

.secretActions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Auth pages */
.tgAuthPage {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--tg-sidebar);
}

.tgAuthCard {
  width: 100%;
  max-width: 400px;
  padding: 40px 32px;
  background: var(--tg-chatlist-bg);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.3);
}

.tgAuthTitle { font-size: 28px; font-weight: 700; text-align: center; margin-bottom: 8px; }
.tgAuthSub { font-size: 15px; color: var(--tg-text-muted); text-align: center; margin-bottom: 28px; }
.tgAuthForm { display: flex; flex-direction: column; }
.tgAuthForm label { margin-top: 16px; }
.tgAuthForm label:first-of-type { margin-top: 0; }
.tgAuthBtn { width: 100%; padding: 14px; font-size: 16px; font-weight: 600; margin-top: 24px; }
.tgAuthLink { text-align: center; margin-top: 20px; }
.tgAuthLink a { color: var(--tg-accent); text-decoration: none; }
.tgAuthLink a:hover { text-decoration: underline; }
.meta.warn { color: #d32f2f; font-size: 13px; margin-top: 8px; }

/* Модалка «мастер-пароль» после регистрации / загрузка на входе */
.tgVaultOverlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
}
.tgVaultOverlay[hidden] {
  display: none !important;
}
.tgVaultCard {
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px 24px;
  background: var(--tg-chatlist-bg);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.tgVaultTitle {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 10px;
  text-align: center;
}
.tgVaultDesc {
  font-size: 14px;
  color: var(--tg-text-muted);
  margin: 0 0 12px;
  line-height: 1.45;
}
.tgVaultSummary {
  font-size: 13px;
  font-family: ui-monospace, monospace;
  background: var(--tg-sidebar);
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 16px;
  white-space: pre-wrap;
  word-break: break-all;
}
.tgVaultCard label {
  display: block;
  margin-top: 14px;
  font-size: 14px;
}
.tgVaultCard label:first-of-type {
  margin-top: 0;
}
.tgVaultCard input[type='password'] {
  width: 100%;
  margin-top: 6px;
  box-sizing: border-box;
}
.tgVaultActions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}
.tgVaultActions .tgAuthBtn {
  margin-top: 0;
}
button.tgAuthLinkBtn {
  background: none;
  border: none;
  color: var(--tg-accent);
  cursor: pointer;
  font-size: 15px;
  text-decoration: underline;
  padding: 0;
  margin-top: 12px;
}
button.tgAuthLinkBtn:hover {
  opacity: 0.9;
}

/* Responsive — не сжимать в 1 колонку на 721–900px: body overflow:hidden обрезал панель чата */

@media (max-width: 720px) {
  /* Flex вместо absolute+grid: иначе строки сетки схлопываются и список не виден */
  .tgApp {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    position: relative;
    /* Убирает задержку double-tap zoom и улучшает отклик тапов (iOS/Android) */
    touch-action: manipulation;
  }

  /* iOS: без cursor:pointer часть <button> не получает нормальный synthetic click */
  button,
  .tgHeaderBtn,
  .tgTabItem,
  .tgNavBtn,
  .tgDrawerItem,
  .tgSheetItem,
  .tgFolderItem,
  .peerInfoStatRow,
  .tgSettingsMenuRowButton {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .tgPaneResizer {
    display: none !important;
  }

  .tgFoldersNav {
    display: none;
  }

  .tgMobileFolderStrip {
    display: flex;
  }

  .tgApp.folders-tab-top #mobileFoldersBar {
    display: none !important;
  }

  .tgChatListMobileHeader {
    display: flex;
  }

  .tgChatListPanel {
    position: relative !important;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    transform: none !important;
    z-index: 2;
    display: flex;
    flex-direction: column;
    /* нижняя навигация fixed — не перекрывать список */
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  }

  .tgChatPanel {
    position: relative !important;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    transform: none !important;
    z-index: 3;
    padding-bottom: 56px;
    box-sizing: border-box;
  }

  .tgApp[data-view="list"] .tgChatListPanel {
    display: flex !important;
  }
  .tgApp[data-view="list"] .tgChatPanel {
    display: none !important;
  }

  .tgApp[data-view="chat"] .tgChatListPanel {
    display: none !important;
  }
  .tgApp[data-view="chat"] .tgChatPanel {
    display: flex !important;
    flex-direction: column;
  }

  .tgMobileFolderStrip .tgFolderItem {
    background: #e8f4fc;
    color: var(--tg-accent);
    border-radius: 12px;
  }
  .tgMobileFolderStrip .tgFolderItem.active {
    background: var(--tg-accent);
    color: #fff;
  }
  .tgMobileFolderStrip .tgFolderBadge {
    background: var(--tg-unread);
    color: #fff;
  }
  .tgMobileFolderStrip .tgFolderItem:not(.active) .tgFolderBadge {
    background: rgba(51, 144, 236, 0.35);
    color: #fff;
  }

  .tgBackBtn { display: flex !important; }
  .tgTabBar {
    display: flex;
    touch-action: manipulation;
  }

  /* В открытом чате на телефоне — только переписка, без нижней «Чаты / Контакты / Настройки» */
  body.cm-mobile-chat-open .tgTabBar {
    display: none !important;
  }
  body.cm-mobile-chat-open .tgChatPanel {
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px)) !important;
  }

  .tgMetaPills { display: none; }
}

canvas { width: 100%; height: 100%; display: block; }
