/* ═══════════════════════════════════════════════════════════════════════════
   Сообщения: контейнер
   ═══════════════════════════════════════════════════════════════════════════ */

.messages,
.group-messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0;
  min-width: 0;
  min-height: 0;
  padding: 16px 0 12px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  scroll-behavior: smooth;
  scroll-padding-block: 20px;
  overflow-anchor: auto;
}

/* Кнопка действий над сообщением */

.msg-del-btn {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  color: var(--text2);
  background: var(--bg2);
  border: 0;
  border-radius: 7px;
  box-shadow: var(--shadow-stroke), var(--shadow-low);
  opacity: 0;
  pointer-events: none;
  cursor: pointer;
  transition:
    opacity 0.15s ease,
    background-color 0.15s ease,
    color 0.15s ease,
    transform 0.15s ease;
}

.g-msg:hover .msg-del-btn,
.g-msg:focus-within .msg-del-btn {
  opacity: 1;
  pointer-events: auto;
}

.msg-del-btn:hover {
  color: var(--red);
  background: var(--bg1);
}

.msg-del-btn:active {
  background: var(--active);
  transform: translateY(1px);
}

.msg-del-btn svg {
  width: 18px;
  height: 18px;
}


/* ═══════════════════════════════════════════════════════════════════════════
   Строка ввода
   ═══════════════════════════════════════════════════════════════════════════ */

.msg-bar-wrap {
  box-sizing: border-box;
  flex-shrink: 0;
  min-width: 0;
  padding: 4px 16px 20px;
}

.msg-bar {
  box-sizing: border-box;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  min-width: 0;
  min-height: 48px;
  padding: 0 6px 0 16px;
  background: var(--bg3);
  border: 1px solid transparent;
  border-radius: 12px;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.msg-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.msg-bar.disabled {
  opacity: 0.6;
  pointer-events: none;
}

#msg-input,
#group-msg-input,
.msg-input {
  box-sizing: border-box;
  flex: 1;
  align-self: center;
  min-width: 0;
  max-height: 40vh;
  max-height: min(40dvh, 320px);
  margin: 0;
  padding: 12px 0;
  overflow-x: hidden;
  overflow-y: auto;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 0;
  font: inherit;
  font-size: 16px;
  line-height: 22px;
  overflow-wrap: anywhere;
  resize: none;
  scrollbar-width: thin;
}

#msg-input:focus,
#group-msg-input:focus,
.msg-input:focus {
  outline: none;
  border-color: transparent;
  box-shadow: none;
}

#msg-input::placeholder,
#group-msg-input::placeholder,
.msg-input::placeholder {
  color: var(--text3);
  opacity: 1;
}

.send-btn {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  margin-block: 5px;
  padding: 0;
  color: var(--text2);
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  transition:
    color 0.15s ease,
    background-color 0.15s ease,
    transform 0.15s ease,
    opacity 0.15s ease;
}

.send-btn svg {
  width: 22px;
  height: 22px;
}

.send-btn:hover:not(:disabled) {
  color: #fff;
  background: var(--accent);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.send-btn:disabled {
  color: var(--text2);
  background: transparent;
  opacity: 0.4;
  cursor: not-allowed;
}

.msg-bar-counter {
  flex-shrink: 0;
  align-self: flex-end;
  padding: 0 4px 15px;
  color: var(--text3);
  font-size: 11px;
  line-height: 16px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.msg-bar-counter.limit {
  color: var(--red);
}


/* ═══════════════════════════════════════════════════════════════════════════
   Приветствие чата
   ═══════════════════════════════════════════════════════════════════════════ */

.chat-welcome {
  flex-shrink: 0;
  min-width: 0;
  margin-top: 0;
  padding: 24px 20px 12px;
  overflow-wrap: anywhere;
  user-select: none;
}

.chat-welcome-av {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  margin-bottom: 16px;
  overflow: hidden;
  color: #fff;
  background: var(--neutral-avatar-gradient);
  border-radius: 50%;
  font-size: 32px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.chat-welcome-av img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-welcome-av .group-av-grid {
  border-radius: 50%;
}

.chat-welcome-title {
  color: var(--text-h);
  font-size: 30px;
  font-weight: 700;
  line-height: 38px;
  letter-spacing: -0.6px;
}

.chat-welcome-sub {
  margin-top: 8px;
  color: var(--text2);
  font-size: 15px;
  line-height: 22px;
}

.chat-welcome-sub b {
  color: var(--text-h);
  font-weight: 600;
}


/* ═══════════════════════════════════════════════════════════════════════════
   Разделители и системные сообщения
   ═══════════════════════════════════════════════════════════════════════════ */

.msg-divider {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  height: 0;
  margin: 24px 16px 12px;
  border-top: 1px solid var(--divider);
  user-select: none;
}

.msg-divider span {
  position: relative;
  top: -1px;
  max-width: 100%;
  padding: 2px 8px;
  overflow: hidden;
  color: var(--text3);
  background: var(--bg2);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  line-height: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-divider.new {
  margin-top: 20px;
  border-top-color: var(--red);
}

.msg-divider.new span {
  position: absolute;
  top: -10px;
  right: 0;
  padding: 2px 7px;
  color: #fff;
  background: var(--red);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.msg-system {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 12px;
  min-width: 0;
  min-height: 28px;
  margin-top: 16px;
  padding: 4px 32px;
  color: var(--text2);
  font-size: 14px;
  line-height: 22px;
  overflow-wrap: anywhere;
  transition: background-color 0.15s ease;
}

.msg-system:hover {
  background: var(--msg-hover);
}

.msg-system-icon {
  display: flex;
  flex-shrink: 0;
  color: var(--green);
  font-weight: 700;
}

.msg-system-icon svg {
  width: 18px;
  height: 18px;
}

.msg-system-time {
  flex-shrink: 0;
  margin-left: 4px;
  color: var(--text3);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}


/* ═══════════════════════════════════════════════════════════════════════════
   Markdown в сообщениях
   ═══════════════════════════════════════════════════════════════════════════ */

.g-msg-text {
  white-space: pre-wrap;
}

.g-msg-text.jumbo {
  font-size: 48px;
  line-height: 1.2;
}

.g-msg-text strong {
  font-weight: 700;
}

.g-msg-text em {
  font-style: italic;
}

.g-msg-text s {
  text-decoration: line-through;
}

.g-msg-text u {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.md-code {
  margin: 0;
  padding: 0.12em 0.3em;
  background: var(--bg1);
  border-radius: 4px;
  font-family: var(--font-code);
  font-size: 85%;
  white-space: pre-wrap;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.md-pre {
  box-sizing: border-box;
  max-width: 100%;
  margin: 8px 0 2px;
  padding: 12px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  background: var(--bg1);
  border: 1px solid var(--bg);
  border-radius: 8px;
  font-family: var(--font-code);
  font-size: 13px;
  line-height: 20px;
  tab-size: 2;
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
  scrollbar-width: thin;
}

.md-pre code {
  padding: 0;
  margin: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  white-space: inherit;
  word-break: normal;
  overflow-wrap: normal;
}

.md-link {
  color: var(--link);
  text-decoration: none;
  text-underline-offset: 3px;
  word-break: normal;
  overflow-wrap: anywhere;
}

.md-link:hover {
  text-decoration: underline;
}

.md-spoiler {
  padding: 0 3px;
  color: transparent;
  background: var(--bg);
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  transition:
    background-color 0.15s ease,
    color 0.15s ease;
}

.md-spoiler:hover {
  background: #26272b;
}

.md-spoiler.revealed {
  color: inherit;
  background: rgba(255, 255, 255, 0.1);
  cursor: text;
  user-select: text;
}

.md-spoiler .md-link {
  color: transparent;
}

.md-spoiler.revealed .md-link {
  color: var(--link);
}

/* Вложенное форматирование не должно раскрывать скрытый текст */

.md-spoiler:not(.revealed) * {
  color: transparent;
  text-shadow: none;
}

.gm-section {
  flex-shrink: 0;
  padding: 22px 8px 8px 16px;
  color: var(--text3);
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  user-select: none;
}

.gm-section:first-child {
  padding-top: 24px;
}

/* Баннер соединения */

.conn-banner {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: calc(var(--z-modal) + 1);
  box-sizing: border-box;
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  color: #fff;
  background: var(--red-h);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.16);
  font-size: 13px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  overflow-wrap: anywhere;
  visibility: hidden;
  transform: translateY(-100%);
  transition:
    transform 0.2s ease,
    visibility 0.2s;
}

.conn-banner.show {
  visibility: visible;
  transform: translateY(0);
}


/* ═══════════════════════════════════════════════════════════════════════════
   Группы
   ═══════════════════════════════════════════════════════════════════════════ */

.chat-head-avatar.group-av,
.modal-avatar.group-av,
.f-av.group-av {
  border-radius: 50% !important;
}

.group-av-grid {
  display: grid;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  gap: 1px;
  overflow: hidden;
  background: var(--bg1);
  border-radius: 50%;
}

.group-av-grid.g1 {
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
}

.group-av-grid.g2 {
  grid-template: minmax(0, 1fr) / repeat(2, minmax(0, 1fr));
}

.group-av-grid.g3,
.group-av-grid.g4 {
  grid-template: repeat(2, minmax(0, 1fr)) / repeat(2, minmax(0, 1fr));
}

.group-av-grid.g3 .group-av-cell:first-child {
  grid-column: 1 / -1;
}

.group-av-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  color: #fff;
  background: var(--neutral-avatar-gradient);
  font-size: 10px;
  font-weight: 700;
}

.group-av-cell img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.group-chat-body {
  display: flex;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.group-chat-left {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* Плашка голосового канала над чатом */

.group-voice-bar {
  position: relative;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  flex-shrink: 0;
  gap: 12px 20px;
  min-width: 0;
  min-height: 112px;
  padding: 18px 20px;
  color: var(--text2);
  background: var(--call-bg);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 14px;
}

.group-voice-title {
  display: flex;
  grid-column: 1;
  grid-row: 1;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  min-width: 0;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  line-height: 22px;
  overflow-wrap: anywhere;
}

.group-voice-title small {
  color: var(--text3);
  font-size: 12px;
  font-weight: 400;
  line-height: 18px;
}

.group-voice-members {
  display: flex;
  grid-column: 1;
  grid-row: 2;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  min-width: 0;
  min-height: 48px;
}

/* Размер 48px применяется только внутри голосовой плашки.
   Аватарки участников в sidebar остаются 24px. */

.group-voice-bar .group-voice-member-avatar {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-position: center;
  background-size: cover;
  box-shadow: 0 0 0 2px transparent;
  font-size: 16px;
  transition: box-shadow 0.15s ease;
}

.group-voice-member-avatar.speaking,
.group-voice-members .speaking .group-voice-member-avatar {
  box-shadow: 0 0 0 2px var(--dc-green);
}

.group-voice-actions {
  position: static;
  display: flex;
  grid-column: 2;
  grid-row: 1 / span 2;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
  transform: none;
}

.group-voice-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  background: var(--dc-green);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(35, 165, 89, 0.4);
}

.group-voice-join {
  box-sizing: border-box;
  min-height: 34px;
  padding: 7px 16px;
  color: #fff;
  background: var(--green-btn);
  border-radius: 7px;
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    opacity 0.15s ease;
}

.group-voice-join:hover:not(:disabled) {
  background: var(--green-btn-h);
}

.group-voice-join:active:not(:disabled) {
  background: var(--green-btn-a);
}

.group-voice-join:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Панель участников справа */

.group-members-panel {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  width: var(--members-w);
  min-width: var(--members-w);
  min-height: 0;
  overflow: hidden;
  background: var(--bg1);
  box-shadow: inset 1px 0 0 rgba(0, 0, 0, 0.06);
  user-select: none;
}

.group-members-panel.hidden {
  display: none;
}

.group-members-panel .section-label {
  height: auto;
  min-height: 0;
  padding: 24px 12px 8px 16px;
}

#group-members-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  min-height: 0;
  padding: 0 8px 10px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
}

.gm-item {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 12px;
  min-width: 0;
  min-height: 44px;
  padding: 4px 8px;
  color: var(--text3);
  border-radius: 8px;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    color 0.15s ease,
    opacity 0.15s ease;
}

.gm-item:hover {
  color: var(--text);
  background: var(--hover);
}

.gm-item:active {
  background: var(--active);
}

.gm-item.offline {
  opacity: 0.6;
}

.gm-item.offline:hover,
.gm-item.offline:focus-within {
  opacity: 1;
}

.gm-item .f-dot {
  border-color: var(--bg1);
}

.gm-item:hover .f-dot {
  border-color: #34363c;
}

.gm-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 15px;
  font-weight: 500;
  line-height: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gm-item.owner .gm-name {
  color: var(--text2);
}

.gm-crown {
  flex-shrink: 0;
  color: var(--gold);
}

.btn-invite {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-shrink: 0;
  gap: 12px;
  min-width: 0;
  min-height: 42px;
  margin: 8px;
  padding: 8px;
  color: var(--text3);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  text-align: left;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    color 0.15s ease;
}

.btn-invite:hover {
  color: var(--text-h);
  background: var(--hover);
}

.btn-invite:active {
  background: var(--active);
}

.btn-invite svg {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}


/* ═══════════════════════════════════════════════════════════════════════════
   Сообщение
   ═══════════════════════════════════════════════════════════════════════════ */

.g-msg {
  position: relative;
  box-sizing: border-box;
  display: flex;
  align-items: flex-start;
  flex-shrink: 0;
  gap: 16px;
  min-width: 0;
  margin-top: 16px;
  padding: 3px 48px 3px 16px;
  transition: background-color 0.15s ease;
}

.g-msg:hover {
  background: var(--msg-hover);
}

.g-msg.deleted {
  opacity: 0.65;
}

.g-msg.grouped {
  margin-top: 0;
  padding-top: 2px;
  padding-bottom: 2px;
}

.g-msg.pending {
  opacity: 0.55;
}

.g-msg.failed .g-msg-text {
  color: var(--text-danger);
}

.g-msg.mention {
  background: rgba(250, 166, 26, 0.08);
  box-shadow: inset 3px 0 0 #f0b232;
}

.g-msg.mention:hover {
  background: rgba(250, 166, 26, 0.12);
}

.g-msg.highlight {
  animation: msg-highlight 2s ease-out;
}

@keyframes msg-highlight {
  0%,
  30% {
    background-color: var(--accent-bg2);
  }
}

.g-msg-av {
  flex-shrink: 0;
}

.g-msg-av.clickable,
.g-msg-av[role="button"],
.g-msg-av[style*="cursor: pointer"] {
  cursor: pointer;
  transition: filter 0.15s ease;
}

.g-msg-av.clickable:hover,
.g-msg-av[role="button"]:hover,
.g-msg-av[style*="cursor: pointer"]:hover {
  filter: brightness(1.12);
}

.g-msg-av-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 24px;
}

.g-msg-hover-time {
  color: var(--text3);
  font-size: 10px;
  line-height: 24px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  opacity: 0;
  user-select: none;
  transition: opacity 0.15s ease;
}

.g-msg:hover .g-msg-hover-time,
.g-msg:focus-within .g-msg-hover-time {
  opacity: 1;
}

.g-msg-body {
  flex: 1;
  min-width: 0;
}

.g-msg-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 8px;
  min-width: 0;
  line-height: 22px;
}

.g-msg-nick {
  min-width: 0;
  color: var(--text-h);
  font-size: 15px;
  font-weight: 600;
  overflow-wrap: anywhere;
  text-underline-offset: 3px;
  cursor: pointer;
}

.g-msg-nick:hover {
  text-decoration: underline;
}

.g-msg-time {
  flex-shrink: 0;
  margin-left: 0;
  color: var(--text3);
  font-size: 11px;
  font-weight: 400;
  line-height: 22px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  user-select: none;
}

.g-msg-text {
  color: var(--text);
  font-size: 16px;
  line-height: 24px;
  word-break: normal;
  overflow-wrap: anywhere;
}

.g-msg.deleted .g-msg-text {
  color: var(--text3);
  font-style: italic;
}

.g-msg-edited {
  margin-left: 4px;
  color: var(--text3);
  font-size: 10px;
  white-space: nowrap;
  user-select: none;
}

.g-msg .msg-del-btn {
  position: absolute;
  top: -14px;
  right: 14px;
  z-index: 1;
}

.g-msg.grouped .msg-del-btn {
  top: -12px;
}


/* ═══════════════════════════════════════════════════════════════════════════
   Модалки
   ═══════════════════════════════════════════════════════════════════════════ */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgba(0, 0, 0, 0.76);
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.modal-box {
  position: relative;
  box-sizing: border-box;
  flex-shrink: 0;
  width: 100%;
  max-width: 440px;
  min-width: 0;
  max-height: calc(100vh - 32px);
  max-height: min(90dvh, calc(100dvh - 32px));
  padding: 24px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  color: var(--text);
  background: var(--bg2);
  border-radius: 14px;
  box-shadow:
    var(--shadow-modal),
    0 24px 64px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.05);
  scrollbar-width: thin;
  animation: scaleIn 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.97);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.modal-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 50%;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    color 0.15s ease;
}

.modal-close-btn svg {
  width: 18px;
  height: 18px;
}

.modal-close-btn:hover {
  background: rgba(0, 0, 0, 0.6);
}

.modal-box:not(.modal-profile) .modal-close-btn {
  color: var(--text3);
  background: transparent;
  border-radius: 8px;
}

.modal-box:not(.modal-profile) .modal-close-btn:hover {
  color: var(--text-h);
  background: var(--hover);
}

.modal-title {
  margin-bottom: 20px;
  padding-right: 36px;
  color: var(--text-h);
  font-size: 22px;
  font-weight: 700;
  line-height: 28px;
  letter-spacing: -0.3px;
  overflow-wrap: anywhere;
}

.modal-sub {
  margin: -10px 0 20px;
  color: var(--text2);
  font-size: 14px;
  line-height: 22px;
  overflow-wrap: anywhere;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  margin-top: 16px;
}

/* Футер модалки */

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin: 24px -24px -24px;
  padding: 16px 24px;
  background: var(--bg1);
  border-radius: 0 0 14px 14px;
  box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.06);
}

/* Профиль с баннером */

.modal-profile {
  padding-top: 0;
}

.modal-profile-header {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 60px 0 20px;
  text-align: center;
}

.modal-profile-header::before {
  content: "";
  position: absolute;
  top: 0;
  right: -24px;
  left: -24px;
  z-index: 0;
  height: 104px;
  background: var(--accent);
  background-image:
    linear-gradient(
      125deg,
      rgba(255, 255, 255, 0.12),
      transparent 55%,
      rgba(0, 0, 0, 0.12)
    );
}

.modal-profile-header > * {
  position: relative;
  z-index: 1;
}

.modal-profile-header .modal-avatar {
  box-sizing: content-box;
  flex-shrink: 0;
  margin-bottom: 4px;
  border: 6px solid var(--bg2);
}

.modal-profile-header .modal-avatar.group-av {
  border-radius: 50% !important;
}

.modal-profile-name {
  max-width: 100%;
  color: var(--text-h);
  font-size: 22px;
  font-weight: 700;
  line-height: 28px;
  letter-spacing: -0.3px;
  overflow-wrap: anywhere;
}

.modal-profile-id {
  max-width: 100%;
  color: var(--text2);
  font-size: 13px;
  line-height: 18px;
  overflow-wrap: anywhere;
}

.modal-online-badge {
  margin-top: 4px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  line-height: 16px;
}

.modal-online-badge:empty {
  display: none;
}

.modal-online-badge.online {
  color: var(--green);
  background: var(--green-bg);
}

.modal-online-badge.offline {
  color: var(--text3);
  background: var(--bg4);
}

.modal-profile-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 16px;
  background: var(--bg1);
  border-radius: 10px;
}

.modal-profile-body .section-label {
  height: auto;
  min-height: 0;
  padding: 0 0 2px;
}

.profile-info-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.profile-info-row + .profile-info-row {
  padding-top: 14px;
  border-top: 1px solid var(--divider);
}

.profile-info-label {
  color: var(--text-h);
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.profile-info-value {
  color: var(--text);
  font-size: 14px;
  line-height: 21px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.profile-info-value:empty::before {
  content: "—";
  color: var(--text3);
}

/* Редактирование профиля */

.edit-avatar-wrap {
  position: relative;
  width: fit-content;
  margin: 0 auto 24px;
}

.edit-avatar-wrap .edit-avatar {
  transition: filter 0.15s ease;
}

.edit-avatar-wrap:hover .edit-avatar {
  filter: brightness(0.85);
}

.avatar-upload-btn {
  position: absolute;
  right: 0;
  bottom: 0;
  box-sizing: content-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  color: #fff;
  background: var(--bg4);
  border: 3px solid var(--bg2);
  border-radius: 50%;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.avatar-upload-btn svg {
  width: 16px;
  height: 16px;
}

.avatar-upload-btn:hover {
  background: var(--bg5);
}

.avatar-upload-btn:focus-within {
  box-shadow: 0 0 0 2px var(--focus);
}

/* Заблокированные */

.blocked-users-list {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-height: 360px;
  margin: 0 -8px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
}

.blocked-user-item {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 12px;
  min-width: 0;
  min-height: 62px;
  padding: 10px 8px;
  border-top: 1px solid var(--divider);
  border-radius: 8px;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.blocked-user-item:first-child {
  border-top: 0;
}

.blocked-user-item:hover {
  background: var(--hover);
  border-top-color: transparent;
}

.blocked-user-item:hover + .blocked-user-item {
  border-top-color: transparent;
}

.blocked-user-item .f-av {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  font-size: 13px;
}

.blocked-user-info {
  flex: 1;
  min-width: 0;
}

.blocked-user-nick {
  overflow: hidden;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  line-height: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.blocked-user-id {
  overflow: hidden;
  color: var(--text3);
  font-size: 12px;
  line-height: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.blocked-user-item .btn-unblock {
  flex-shrink: 0;
  margin-left: auto;
}

.blocked-users-empty {
  padding: 28px 8px;
  color: var(--text3);
  font-size: 14px;
  line-height: 20px;
  text-align: center;
}

/* Выбор друзей */

.friends-picker {
  min-width: 0;
  max-height: 240px;
  margin: 0 -8px;
  padding: 2px 8px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
}

.picker-item {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  min-height: 46px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease;
}

.picker-item:hover {
  background: var(--hover);
}

.picker-item:active {
  background: var(--active);
}

.picker-item.selected {
  background: var(--selected);
}

.picker-item .f-nick {
  font-size: 15px;
  color: var(--text);
}

.picker-check {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  margin-left: auto;
  color: transparent;
  border: 1px solid var(--text4);
  border-radius: 6px;
  font-size: 12px;
  transition:
    border-color 0.15s ease,
    background-color 0.15s ease,
    color 0.15s ease;
}

.picker-item:hover .picker-check {
  border-color: var(--text2);
}

.picker-item.selected .picker-check {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.picker-empty {
  padding: 28px 8px;
  color: var(--text3);
  font-size: 14px;
  line-height: 20px;
  text-align: center;
}

/* Участники группы: инфо-модалка */

.group-members-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  max-height: 250px;
  margin: 0 -8px;
  padding: 2px 8px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
}

.group-member-item {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 12px;
  min-width: 0;
  min-height: 46px;
  padding: 6px 8px;
  border-radius: 8px;
  transition: background-color 0.15s ease;
}

.group-member-item:hover {
  background: var(--hover);
}

.group-member-item .f-nick {
  color: var(--text);
  font-size: 15px;
}

.owner-badge {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  color: var(--gold);
  font-size: 12px;
}

.btn-kick {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  margin-left: auto;
  padding: 0;
  color: var(--text3);
  border-radius: 6px;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    color 0.15s ease,
    opacity 0.15s ease;
}

.group-member-item:hover .btn-kick,
.group-member-item:focus-within .btn-kick,
.btn-kick:focus-visible {
  opacity: 1;
  pointer-events: auto;
}

.btn-kick:hover {
  color: var(--red);
  background: var(--red-bg);
}


/* ═══════════════════════════════════════════════════════════════════════════
   Всплывашки
   ═══════════════════════════════════════════════════════════════════════════ */

.delete-confirm-popup {
  position: fixed;
  bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  z-index: var(--z-popup);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  width: max-content;
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 120px);
  padding: 14px 16px;
  overflow-y: auto;
  color: var(--text);
  background: var(--bg-floating);
  border-radius: 12px;
  box-shadow: var(--shadow-lg), var(--shadow-stroke);
  font-size: 14px;
  line-height: 20px;
  overflow-wrap: anywhere;
  transform: translateX(-50%);
  animation: popIn 0.18s ease-out;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: translate(-50%, 10px);
  }

  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.transient-notice {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  z-index: var(--z-toast);
  box-sizing: border-box;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  color: var(--text);
  background: var(--bg-floating);
  border-radius: 10px;
  box-shadow: var(--shadow-lg), var(--shadow-stroke);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  text-align: center;
  overflow-wrap: anywhere;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.transient-notice.show {
  opacity: 1;
  transform: translate(-50%, -4px);
}


/* ═══════════════════════════════════════════════════════════════════════════
   Звонки: переменные
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --call-bg: #111214;
  --call-tile: #1e1f22;
  --call-tile-2: #2b2d31;
  --call-pill: rgba(0, 0, 0, 0.62);
  --call-ctrl: rgba(78, 80, 88, 0.55);
  --call-ctrl-h: rgba(78, 80, 88, 0.85);
  --call-radius: 12px;
}


/* ═══════════════════════════════════════════════════════════════════════════
   Звонки: входящий вызов и круглые кнопки
   ═══════════════════════════════════════════════════════════════════════════ */

.modal-box.call-incoming-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: 360px;
  padding: 36px 28px 32px;
  text-align: center;
}

.call-incoming-avatar {
  flex-shrink: 0;
  width: 84px;
  height: 84px;
  margin-bottom: 8px;
  overflow: visible;
  border-radius: 50%;
  font-size: 30px;
  animation: call-pulse 1.8s ease-in-out infinite;
}

.call-incoming-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

@keyframes call-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(88, 101, 242, 0.35);
  }

  50% {
    box-shadow: 0 0 0 14px rgba(88, 101, 242, 0);
  }
}

.call-incoming-nick {
  max-width: 100%;
  margin-top: 6px;
  color: var(--text-h);
  font-size: 22px;
  font-weight: 700;
  line-height: 28px;
  letter-spacing: -0.3px;
  overflow-wrap: anywhere;
}

.call-incoming-sub {
  color: var(--text2);
  font-size: 14px;
  line-height: 20px;
}

.call-incoming-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 28px;
  margin-top: 20px;
}

.call-round-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  padding: 0;
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    background-color 0.15s ease,
    color 0.15s ease,
    opacity 0.15s ease;
}

.call-round-btn svg {
  width: 24px;
  height: 24px;
}

.call-round-btn:hover:not(:disabled) {
  transform: translateY(-2px);
}

.call-round-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.call-round-btn:disabled {
  opacity: 0.5;
  transform: none;
  cursor: not-allowed;
}

.call-accept {
  background: var(--green-btn);
}

.call-accept:hover:not(:disabled) {
  background: var(--green-btn-h);
}

.call-decline {
  background: var(--red-h);
}

.call-decline:hover:not(:disabled) {
  background: var(--red-a);
}

.call-control {
  background: var(--call-ctrl);
}

.call-control:hover:not(:disabled) {
  background: var(--call-ctrl-h);
}

.call-control.active-off {
  color: #111214;
  background: #fff;
}

.call-control.active-off:hover:not(:disabled) {
  background: #e3e5e8;
}


/* ═══════════════════════════════════════════════════════════════════════════
   Фокус с клавиатуры
   ═══════════════════════════════════════════════════════════════════════════ */

.msg-del-btn:focus-visible,
.send-btn:focus-visible,
.md-link:focus-visible,
.md-spoiler:focus-visible,
.group-voice-join:focus-visible,
.gm-item:focus-visible,
.btn-invite:focus-visible,
.g-msg-av:focus-visible,
.g-msg-nick:focus-visible,
.modal-close-btn:focus-visible,
.avatar-upload-btn:focus-visible,
.blocked-user-item .btn-unblock:focus-visible,
.picker-item:focus-visible,
.btn-kick:focus-visible,
.call-round-btn:focus-visible {
  outline: 2px solid var(--focus, var(--accent));
  outline-offset: 2px;
}

.gm-item:focus-visible,
.picker-item:focus-visible {
  outline-offset: -2px;
}

.call-round-btn:focus-visible {
  outline-color: var(--text-h);
}


/* ═══════════════════════════════════════════════════════════════════════════
   Небольшие экраны
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 600px) {
  .group-voice-bar {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    padding: 16px;
  }

  .group-voice-title,
  .group-voice-members,
  .group-voice-actions {
    grid-column: 1;
    grid-row: auto;
  }

  .group-voice-actions {
    justify-content: flex-start;
  }

  .group-voice-members {
    gap: 10px;
  }
}

@media (max-width: 480px) {
  .messages,
  .group-messages {
    padding-top: 12px;
  }

  .msg-bar-wrap {
    padding: 4px 10px 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .msg-bar {
    gap: 4px;
    padding-left: 12px;
    border-radius: 10px;
  }

  .msg-bar-counter {
    padding-right: 0;
    padding-left: 0;
    font-size: 10px;
  }

  .chat-welcome {
    padding: 20px 14px 10px;
  }

  .chat-welcome-av {
    width: 68px;
    height: 68px;
    margin-bottom: 14px;
    font-size: 28px;
  }

  .chat-welcome-title {
    font-size: 25px;
    line-height: 32px;
  }

  .chat-welcome-sub {
    font-size: 14px;
    line-height: 21px;
  }

  .msg-divider {
    margin-right: 12px;
    margin-left: 12px;
  }

  .msg-system {
    gap: 8px;
    padding-right: 12px;
    padding-left: 22px;
    font-size: 13px;
  }

  .g-msg {
    gap: 10px;
    padding-right: 40px;
    padding-left: 12px;
  }

  .g-msg-head {
    column-gap: 6px;
  }

  .g-msg-nick {
    font-size: 14px;
  }

  .g-msg-time {
    font-size: 10px;
  }

  .g-msg-text {
    font-size: 15px;
    line-height: 23px;
  }

  .g-msg-text.jumbo {
    font-size: 40px;
  }

  .g-msg .msg-del-btn {
    right: 8px;
  }

  .md-pre {
    padding: 10px;
    font-size: 12px;
    line-height: 19px;
  }

  .modal-overlay {
    padding: 12px;
  }

  .modal-box {
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    padding: 20px;
    border-radius: 12px;
  }

  .modal-title {
    font-size: 20px;
    line-height: 26px;
  }

  .modal-footer {
    margin: 20px -20px -20px;
    padding: 14px 20px;
    border-radius: 0 0 12px 12px;
  }

  .modal-profile {
    padding-top: 0;
  }

  .modal-profile-header::before {
    right: -20px;
    left: -20px;
  }

  .modal-profile-body {
    padding: 14px;
  }

  .blocked-user-item {
    flex-wrap: wrap;
    gap: 8px;
  }

  .blocked-user-info {
    flex-basis: 100px;
  }

  .modal-box.call-incoming-box {
    padding: 32px 20px 28px;
  }

  .delete-confirm-popup,
  .transient-notice {
    max-width: calc(100vw - 24px);
  }
}


/* ═══════════════════════════════════════════════════════════════════════════
   Сенсорные устройства
   ═══════════════════════════════════════════════════════════════════════════ */

@media (hover: none) {
  .msg-del-btn,
  .btn-kick {
    opacity: 0.75;
    pointer-events: auto;
  }

  .g-msg-hover-time {
    opacity: 0.7;
  }

  .call-round-btn:hover:not(:disabled) {
    transform: none;
  }
}


/* ═══════════════════════════════════════════════════════════════════════════
   Уменьшение анимации по настройке системы
   ═══════════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  .messages,
  .group-messages {
    scroll-behavior: auto;
  }

  .g-msg.highlight {
    animation: none;
    background-color: var(--accent-bg2);
  }

  .modal-overlay,
  .modal-box,
  .delete-confirm-popup,
  .call-incoming-avatar {
    animation: none;
  }

  .msg-del-btn,
  .msg-bar,
  .send-btn,
  .msg-system,
  .md-spoiler,
  .conn-banner,
  .group-voice-bar .group-voice-member-avatar,
  .group-voice-join,
  .gm-item,
  .btn-invite,
  .g-msg,
  .g-msg-av.clickable,
  .g-msg-av[role="button"],
  .g-msg-av[style*="cursor: pointer"],
  .g-msg-hover-time,
  .modal-close-btn,
  .edit-avatar-wrap .edit-avatar,
  .avatar-upload-btn,
  .blocked-user-item,
  .picker-item,
  .picker-check,
  .group-member-item,
  .btn-kick,
  .transient-notice,
  .call-round-btn {
    transition: none;
  }

  .send-btn:active:not(:disabled),
  .call-round-btn:hover:not(:disabled),
  .call-round-btn:active:not(:disabled) {
    transform: none;
  }
}
