/* ===========================================================================
   Палитра и темы
   =========================================================================== */

:root {
  --accent-100: #AFD895;
  --accent-300: #8DC662;
  --accent-500: #6FA747;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  /* HTMX: смена #messenger-outlet, сайдбар не трогаем */
  --nav-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --nav-messenger-pending-dur: 0.2s;
  --nav-messenger-in-dur: 0.34s;

  /* Светлая тема — значения по умолчанию */
  --bg: #f8fbf6;
  --bg-elevated: #ffffff;
  --bg-muted: #eef3eb;
  --fg: #1c2620;
  --fg-muted: #5b6962;
  --border: #d9e1d4;
  --bubble-other: #ffffff;
  --bubble-own: var(--accent-100);
}

[data-theme="dark"] {
  --bg: #0e1411;
  --bg-elevated: #161e1a;
  --bg-muted: #1c2520;
  --fg: #e8efe9;
  --fg-muted: #93a39a;
  --border: #25302a;
  --bubble-other: #1c2520;
  --bubble-own: var(--accent-500);
}

@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --bg: #0e1411;
    --bg-elevated: #161e1a;
    --bg-muted: #1c2520;
    --fg: #e8efe9;
    --fg-muted: #93a39a;
    --border: #25302a;
    --bubble-other: #1c2520;
    --bubble-own: var(--accent-500);
  }
}

/* ===========================================================================
   Базовый сброс и типографика
   =========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-500); text-decoration: none; }
a:hover { text-decoration: underline; }
input, button, select, textarea { font: inherit; color: inherit; }

[x-cloak] { display: none !important; }

/* ---------------------------------------------------------------------------
   HTMX: только #messenger-outlet — пока идёт запрос — мягкое «подзатенение». */

#messenger-outlet.messenger-outlet--pending {
  transition: opacity var(--nav-messenger-pending-dur) ease;
  opacity: 0.82;
}

#messenger-outlet.messenger-outlet--enter {
  animation: messenger-outlet-enter var(--nav-messenger-in-dur) var(--nav-ease) both;
  will-change: opacity;
}

@keyframes messenger-outlet-enter {
  from { opacity: 0.5; }
  to { opacity: 1; }
}

.messenger-outlet {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.messenger-outlet > .window {
  flex: 1;
  min-height: 0;
}
.messenger-outlet > .chat-main-split {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: row;
}
.chat-main-split > .window {
  flex: 1;
  min-width: 0;
  min-height: 0;
}

/* Подтемы — вторая колонка (как список чатов по стилю) */
.topics-panel {
  width: min(296px, 34vw);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-elevated);
  min-height: 0;
  /* Без transition по width: при смене подтемы HTMX подменяет блок, иначе на каждую
     навигацию анимация 296px↔56px с «свёрнутым» смотрится как моргание рейки */
}
.topics-panel--collapsed {
  width: 56px;
}
.topics-panel--collapsed .topics-topic__text {
  display: none !important;
}
.topics-panel--collapsed .topics-panel__section-title {
  display: none !important;
}
.topics-panel--collapsed .topics-panel__group-name {
  display: none !important;
}
.topics-panel--collapsed .topics-panel__group-hit {
  justify-content: center;
  padding: 4px;
  flex: 0 0 auto;
}
.topics-panel--collapsed .topics-panel__top {
  flex-direction: column;
  align-items: stretch;
  padding: 8px 4px 6px;
  gap: 6px;
}
.topics-panel--collapsed .topics-panel__collapse-btn {
  align-self: center;
}
.topics-panel--collapsed .topics-topic__hit {
  grid-template-columns: 1fr;
  justify-items: center;
  padding: 9px 4px !important;
}
.topics-panel--collapsed .topics-topic__badge {
  margin: 0 auto;
}
.topics-panel__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 8px 6px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-width: 0;
}
.topics-panel__group-hit {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 6px 8px;
  border: none;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  color: inherit;
  text-align: left;
  font: inherit;
  transition: background 120ms ease;
}
.topics-panel__group-hit:hover,
.topics-panel__group-hit:focus-visible {
  background: var(--bg-muted);
  outline: none;
}
.topics-panel__group-ava {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-muted);
  display: grid;
  place-items: center;
}
.topics-panel__group-ava-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.topics-panel__group-ava-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent-300), var(--accent-500));
  color: #0c1a08;
  font-weight: 700;
  font-size: 13px;
}
.topics-panel__group-name {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topics-panel__section-title {
  margin: 0;
  padding: 4px 12px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
  flex-shrink: 0;
}

.topics-panel__collapse-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
  flex-shrink: 0;
}
.topics-panel__collapse-btn:hover,
.topics-panel__collapse-btn:focus-visible {
  background: var(--bg-muted);
  color: var(--fg);
}
.topics-panel__collapse-btn .material-symbols-outlined {
  font-size: 22px;
  line-height: 1;
}
.topics-panel__list {
  list-style: none;
  margin: 0;
  padding: 4px 0 12px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.topics-topic {
  margin: 0;
}
.topics-topic--active .topics-topic__hit {
  background: var(--bg-muted);
}
.topics-topic__row {
  display: flex;
  align-items: stretch;
}
.topics-topic__hit {
  position: relative;
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 6px;
  padding: 8px 10px 8px 12px;
  align-items: start;
  text-decoration: none;
  color: inherit;
}
.topics-topic__hit--has-unread {
  padding-right: 40px;
}
.topics-topic__unread {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--accent-500);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  pointer-events: none;
  box-shadow: 0 0 0 2px var(--bg-elevated);
}
[data-theme="dark"] .topics-topic__unread { color: #0b120d; }
@media (prefers-color-scheme: dark) {
  [data-theme="system"] .topics-topic__unread { color: #0b120d; }
}
.topics-topic__hit:hover {
  background: color-mix(in srgb, var(--bg-muted) 75%, transparent);
  text-decoration: none;
}
.topics-topic__badge {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  line-height: 1;
  flex-shrink: 0;
  padding-top: 1px;
  background: none;
  border: none;
}
.topics-topic__text {
  min-width: 0;
}
.topics-topic__title {
  display: block;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.25;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topics-topic__preview {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.28;
  color: var(--fg-muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topics-topic__preview--muted {
  opacity: 0.92;
}

@media (max-width: 720px) {
  /* Подтемы на мобилке — узкий вертикальный рейл слева; разворачивается оверлеем поверх чата */
  .messenger-outlet > .chat-main-split {
    flex-direction: row;
    position: relative;
    min-height: 0;
    overflow: hidden;
  }
  /* Пока Alpine не выставил класс «развернуто», панель остаётся в потоке (56px) —
     :not(--collapsed) до гидратации давал position:absolute и визуальный сдвиг. */
  .topics-panel {
    position: relative;
    z-index: 1;
    width: 56px;
    flex: 0 0 56px;
    max-height: none;
    border-right: 1px solid var(--border);
    border-bottom: none;
    transition: none;
  }
  .topics-panel--collapsed {
    width: 56px;
    flex: 0 0 56px;
    max-height: none;
  }
  /* Развёрнуто только после гидратации Alpine — оверлей поверх чата */
  .topics-panel.topics-panel--rail-expanded {
    position: absolute;
    z-index: 5;
    left: 0;
    top: 0;
    bottom: 0;
    flex: 0 1 auto;
    width: min(78vw, 280px);
    max-width: calc(100% - env(safe-area-inset-left, 0px));
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  }
  .topics-panel__list {
    display: block;
    overflow-x: hidden;
    overflow-y: auto;
    gap: 0;
    padding-inline: 0;
  }
  .topics-topic__row {
    flex-direction: row;
    min-width: 0;
  }
  .topics-topic__hit {
    min-width: 0;
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  #messenger-outlet.messenger-outlet--pending {
    transition: opacity 0.15s ease;
    filter: none;
    transform: none;
  }
  #messenger-outlet.messenger-outlet--enter {
    animation: messenger-outlet-enter-reduced 0.2s ease both;
  }
  @keyframes messenger-outlet-enter-reduced {
    from { opacity: 0.5; }
    to { opacity: 1; }
  }
}

/* Alpine: плавное появление/скрытие (сайдбар) */
.sfx-htmx,
.srs-htmx { transition: opacity 0.2s var(--nav-ease), transform 0.2s var(--nav-ease); }
.sfx-from { opacity: 0; transform: translateY(-5px) scale(0.98); }
.sfx-to { opacity: 1; transform: none; }
.srs-from { opacity: 0; transform: translateY(-4px); }
.srs-to { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .sfx-htmx, .srs-htmx { transition: opacity 0.12s ease; }
  .sfx-from, .srs-from { transform: none; }
}

/* ===========================================================================
   Кнопки
   =========================================================================== */

.btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--fg);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  cursor: pointer;
  transition: background 120ms ease, transform 80ms ease;
}
.btn:hover { background: var(--bg-muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary {
  background: var(--accent-300);
  border-color: var(--accent-500);
  color: #0c1a08;
  font-weight: 600;
}
.btn--primary:hover { background: var(--accent-500); color: #fff; }
.btn--small {
  padding: 6px 10px;
  font-size: 13px;
}
.btn--danger {
  border-color: rgba(192, 57, 43, 0.45);
  color: #c0392b;
}
.btn--danger:hover {
  background: rgba(192, 57, 43, 0.08);
  color: #a93226;
}
.btn--block {
  display: block;
  width: 100%;
  box-sizing: border-box;
}
.btn--danger-soft {
  border-color: rgba(192, 57, 43, 0.45);
  color: #b03a2e;
  background: rgba(192, 57, 43, 0.06);
}
.btn--danger-soft:hover {
  background: rgba(192, 57, 43, 0.14);
}

/* ===========================================================================
   Аутентификация (страницы login/register/profile)
   =========================================================================== */

.auth {
  min-height: 100%;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  background:
    radial-gradient(circle at 20% 0%, rgba(141, 198, 98, 0.18), transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(111, 167, 71, 0.12), transparent 50%),
    var(--bg);
}
.auth__card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.auth__title { margin: 0 0 4px; font-size: 28px; }
.auth__subtitle { margin: 0 0 24px; color: var(--fg-muted); font-size: 14px; }
.auth__form { display: grid; gap: 14px; }
.auth__field { display: grid; gap: 6px; font-size: 13px; color: var(--fg-muted); }
.auth__field input, .auth__field select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--bg);
  color: var(--fg);
  outline: none;
  transition: border-color 120ms ease;
}
.auth__field input:focus, .auth__field select:focus { border-color: var(--accent-500); }
.auth__alt { margin: 16px 0 0; text-align: center; color: var(--fg-muted); font-size: 13px; }
.auth__hint { margin: 4px 0 0; text-align: center; color: var(--fg-muted); font-size: 12px; }
.auth__error {
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: rgba(220, 60, 60, 0.12); color: #c0392b;
}

/* ===========================================================================
   Главный layout
   =========================================================================== */

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  transition: grid-template-columns 0.28s var(--nav-ease);
}

.app--sidebar-rail {
  /* В шапке две кнопки — только в колонку; ширина хватает под 36px + паддинги */
  grid-template-columns: 52px 1fr;
  overflow: visible;
}

/* ---- Сайдбар ----
   Голова: гамбургер + поиск, ниже — список чатов. */

.sidebar {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-elevated);
}
.sidebar__head {
  flex: 0 0 auto;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar__head-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.sidebar__menu-anchor { position: relative; flex: 0 0 auto; }
.sidebar__menu-btn {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  margin: 0; padding: 0;
  border: none; border-radius: 10px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: background 120ms ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.sidebar__menu-btn:hover,
.sidebar__menu-btn:focus-visible {
  background: var(--bg-muted);
  outline: none;
}
.sidebar__menu-icon { display: flex; line-height: 0; }

.sidebar__rail-btn {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 40px; height: 40px;
  margin: 0; padding: 0;
  border: none; border-radius: 10px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: background 120ms ease;
  font: inherit;
}
.sidebar__rail-btn:hover,
.sidebar__rail-btn:focus-visible {
  background: var(--bg-muted);
  outline: none;
}
.sidebar__rail-chevron {
  font-size: 14px;
  line-height: 1;
  font-weight: 600;
  letter-spacing: -0.1em;
  user-select: none;
}

/* Узкий сайдбар: только кнопки в шапке + аватары */
.app--sidebar-rail .sidebar__search { display: none; }
/* Две кнопки (≈40px) в ряд в колонку ~32–40px внутри = обрезка; в колонку + компактные hit-area */
.app--sidebar-rail .sidebar__head {
  padding: 8px 4px;
  overflow: visible;
}
.app--sidebar-rail .sidebar__head-row {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}
.app--sidebar-rail .sidebar__menu-btn,
.app--sidebar-rail .sidebar__rail-btn {
  width: 36px;
  height: 36px;
  min-width: 0;
  flex-shrink: 0;
  box-sizing: border-box;
  border-radius: 8px;
}
.app--sidebar-rail .sidebar__menu-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}
.app--sidebar-rail .sidebar__menu-icon svg {
  display: block;
  width: 20px;
  height: 20px;
  max-width: 100%;
  max-height: 100%;
}
.app--sidebar-rail .sidebar__rail-chevron {
  font-size: 13px;
  letter-spacing: -0.05em;
  line-height: 1.2;
}
/* Меню у края — открываем вправо от колонки, иначе режется overflow */
.app--sidebar-rail .sidebar__dropdown {
  top: 0;
  left: 100%;
  right: auto;
  margin-top: 0;
  margin-left: 6px;
}
.app--sidebar-rail .sidebar { overflow: visible; }
.app--sidebar-rail .sidebar__result { grid-template-columns: 1fr; justify-items: center; }
.app--sidebar-rail .sidebar__result-text { display: none; }
/* Узкая колонка: stable-gutter резервировал полоску справа — контраст с фоном + на узкой ширине «наезжало» на авы */
.app--sidebar-rail .sidebar__chats {
  scrollbar-gutter: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.app--sidebar-rail .sidebar__chats::-webkit-scrollbar {
  width: 6px;
}
.app--sidebar-rail .sidebar__chats::-webkit-scrollbar-track {
  background: transparent;
}
.app--sidebar-rail .sidebar__chats::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.app--sidebar-rail .chat-item a {
  position: relative;
  grid-template-columns: 1fr;
  justify-items: center;
  padding: 6px 4px 6px 4px;
}
.app--sidebar-rail .chat-item__text { display: none; }
.app--sidebar-rail .chat-item__meta {
  position: absolute;
  top: 2px; right: 2px;
  display: block;
  padding: 0;
  justify-self: auto;
  line-height: 1;
}
.app--sidebar-rail .chat-item__unread {
  min-width: 16px; height: 16px; font-size: 10px; padding: 0 3px;
}
.app--sidebar-rail .chat-item--empty { font-size: 10px; line-height: 1.2; padding: 10px 4px; }
.sidebar__dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 50;
  min-width: 240px;
  padding: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.sidebar__dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border: none; border-radius: 8px;
  background: none;
  font: inherit; font-size: 14px;
  color: var(--fg);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background 120ms ease;
}
a.sidebar__dropdown-item:hover,
a.sidebar__dropdown-item:focus-visible,
button.sidebar__dropdown-item:not(:disabled):hover,
button.sidebar__dropdown-item:not(:disabled):focus-visible {
  background: var(--bg-muted);
  text-decoration: none;
  outline: none;
  color: inherit;
}
.sidebar__dropdown-item--active { background: var(--bg-muted); }
.sidebar__dropdown-item--stub {
  opacity: 0.55;
  cursor: not-allowed;
}
.sidebar__dropdown-ico { flex: 0 0 auto; display: flex; line-height: 0; color: var(--fg-muted); }
.sidebar__search {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  padding: 10px 14px;
  border-radius: 999px;
  outline: none;
  transition: border-color 120ms ease;
}
.sidebar__search:focus { border-color: var(--accent-500); }
.sidebar__search::-webkit-search-cancel-button {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-right: 2px;
  cursor: pointer;
  background-color: color-mix(in srgb, var(--fg-muted) 70%, var(--accent-500));
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'/%3E%3C/svg%3E");
  -webkit-mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
}
.sidebar__search::-webkit-search-cancel-button:hover,
.sidebar__search::-webkit-search-cancel-button:focus-visible {
  background-color: var(--accent-500);
}

.sidebar__results {
  flex: 0 0 auto;
  list-style: none; margin: 0; padding: 8px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-muted);
  max-height: 240px; overflow-y: auto;
}
.sidebar__result {
  display: grid; grid-template-columns: 36px 1fr; gap: 10px;
  align-items: center; padding: 8px 14px; cursor: pointer;
}
.sidebar__result:hover { background: var(--bg-elevated); }
.sidebar__result-name { font-weight: 500; }
.sidebar__result-tag { font-size: 12px; color: var(--fg-muted); }

.sidebar__chats {
  flex: 1 1 auto;
  min-height: 0;
  list-style: none; margin: 0; padding: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--fg-muted) 38%, var(--border)) transparent;
}
.sidebar__chats::-webkit-scrollbar {
  width: 6px;
}
.sidebar__chats::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar__chats::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--fg-muted) 28%, var(--border));
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.sidebar__chats:hover::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--accent-500) 32%, var(--fg-muted));
  background-clip: padding-box;
}
.chat-item a {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 8px 6px;
  /* Симметрия с .sidebar__head (12px), без «коридора» справа у подсветки */
  padding: 8px 12px;
  align-items: start;
  color: inherit;
}
/* Тень вправо закрашивает полосу под scrollbar-gutter (stable), как будто фон до края колонки */
.chat-item a:hover,
.chat-item--active a {
  background: var(--bg-muted);
  box-shadow: 15px 0 0 var(--bg-muted);
  text-decoration: none;
}
.app--sidebar-rail .chat-item a:hover,
.app--sidebar-rail .chat-item--active a {
  box-shadow: none;
}
.chat-item__text { min-width: 0; margin-top: -1px; }
.chat-item__title {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.2;
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-item__preview {
  font-size: 12px;
  line-height: 1.2;
  margin-top: 1px;
  color: var(--fg-muted);
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-item__preview--muted { opacity: 0.85; }
.chat-item__meta { justify-self: end; padding-top: 1px; flex-shrink: 0; }
.chat-item__unread {
  min-width: 20px; height: 20px; padding: 0 5px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; background: var(--accent-500);
  color: #fff; font-size: 11px; font-weight: 600;
  line-height: 1;
  box-shadow: 0 0 0 1px var(--bg-elevated);
}
[data-theme="dark"] .chat-item__unread { color: #0b120d; }
@media (prefers-color-scheme: dark) {
  [data-theme="system"] .chat-item__unread { color: #0b120d; }
}
.chat-item--empty {
  padding: 24px 18px; color: var(--fg-muted); font-size: 13px; text-align: center;
}

/* ---- Аватар ---- */

.avatar {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-300), var(--accent-500));
  color: #0c1a08; font-weight: 700; font-size: 14px;
  flex-shrink: 0;
}
.avatar--lg { width: 44px; height: 44px; font-size: 16px; }
.chat-item .avatar, .sidebar__result .avatar { width: 36px; height: 36px; }
.avatar--img {
  display: block;
  object-fit: cover;
  padding: 0;
  background: var(--bg-muted);
}
.chat-item .avatar--img, .sidebar__result .avatar--img {
  width: 36px; height: 36px;
}
.avatar--lg.avatar--img { width: 44px; height: 44px; }
.avatar-wrap {
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ---- Окно чата ---- */

.window {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  background: var(--bg);
}
.window__head {
  display: grid; grid-template-columns: 44px 1fr; gap: 12px;
  align-items: center; padding: 12px 18px;
  border-bottom: 1px solid var(--border); background: var(--bg-elevated);
}
.window__head-back {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.window__head-back:hover,
.window__head-back:focus-visible {
  background: var(--bg-muted);
  outline: none;
}
.window__head-back .material-symbols-outlined {
  font-size: 24px;
  line-height: 1;
}
.window__head-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
}
.window__head-avatar--topic-emoji {
  width: 44px;
  height: 44px;
  box-sizing: border-box;
  background: transparent;
  border: none;
}
.window__head-topic-emoji {
  font-size: 1.65rem;
  line-height: 1;
  display: block;
}
.window__name { font-weight: 600; font-size: 16px; letter-spacing: -0.01em; }
.window__sub { font-size: 13px; color: var(--fg-muted); }

.window__head-hit {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  grid-column: 1 / -1;
  margin: 0;
  padding: 4px 8px;
  margin-left: -8px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.window__head-hit:hover,
.window__head-hit:focus-visible {
  background: var(--bg-muted);
  outline: none;
}
.window__title { min-width: 0; }
@media (max-width: 720px) {
  .window__head-hit {
    grid-column: 2 / -1;
  }
}
.window--splash {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  background:
    radial-gradient(circle at 20% 0%, rgba(141, 198, 98, 0.18), transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(111, 167, 71, 0.12), transparent 50%),
    var(--bg);
}
[data-theme="dark"] .window--splash {
  background:
    radial-gradient(circle at 20% 0%, rgba(141, 198, 98, 0.14), transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(111, 167, 71, 0.1), transparent 50%),
    var(--bg);
}
@media (prefers-color-scheme: dark) {
  [data-theme="system"] .window--splash {
    background:
      radial-gradient(circle at 20% 0%, rgba(141, 198, 98, 0.14), transparent 50%),
      radial-gradient(circle at 100% 100%, rgba(111, 167, 71, 0.1), transparent 50%),
      var(--bg);
  }
}
.window__placeholder {
  color: var(--fg-muted);
  padding: 32px;
}
.window__placeholder--center {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.window__splash-title {
  margin: 0;
  color: var(--fg);
  font-size: clamp(22px, 4vw, 30px);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.messages {
  list-style: none; margin: 0; padding: 14px 16px 18px;
  overflow-y: auto;
  overflow-anchor: none; /* без «перепрыгивания» при подгрузке высоты (картинки) внизу */
  display: flex; flex-direction: column; gap: 4px;
}
.messages__end {
  flex-shrink: 0;
  height: 1px;
  width: 100%;
  margin: 0;
  pointer-events: none;
}
.messages__empty {
  margin: auto; color: var(--fg-muted); font-size: 14px;
}

.message-row__bundle {
  display: contents;
}
.messages__unread-divider {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 4px 6px;
  margin: 8px 0 4px;
  color: #c0392b;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  transition: opacity 320ms ease;
}
.messages__unread-divider::before,
.messages__unread-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: color-mix(in srgb, #c0392b 75%, transparent);
}
.messages__unread-divider-text {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
[data-theme="dark"] .messages__unread-divider {
  color: #ff6b5e;
}
[data-theme="dark"] .messages__unread-divider::before,
[data-theme="dark"] .messages__unread-divider::after {
  background: color-mix(in srgb, #ff6b5e 65%, transparent);
}
@media (prefers-color-scheme: dark) {
  [data-theme="system"] .messages__unread-divider {
    color: #ff6b5e;
  }
  [data-theme="system"] .messages__unread-divider::before,
  [data-theme="system"] .messages__unread-divider::after {
    background: color-mix(in srgb, #ff6b5e 65%, transparent);
  }
}

.messages__scroll-bottom {
  position: sticky;
  align-self: flex-end;
  bottom: 12px;
  margin: 0 0 4px;
  margin-inline-end: 4px;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  aspect-ratio: 1 / 1;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--fg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  transition: background 120ms ease, transform 120ms ease;
  z-index: 12;
}
.messages__scroll-bottom:hover,
.messages__scroll-bottom:focus-visible {
  background: var(--bg-muted);
  outline: none;
}
.messages__scroll-bottom .material-symbols-outlined {
  font-size: 22px;
  line-height: 1;
}
.messages__scroll-bottom-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent-500);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--bg-elevated);
  pointer-events: none;
}
[data-theme="dark"] .messages__scroll-bottom-badge { color: #0b120d; }
@media (prefers-color-scheme: dark) {
  [data-theme="system"] .messages__scroll-bottom-badge { color: #0b120d; }
}

.messages__older {
  align-self: center;
  flex-shrink: 0;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--fg-muted);
  user-select: none;
}

/* Скелетон пока грузится история (нет мигания текста «legacy» на пустых пузырях) */
.messages__skeleton {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
}
.message-row--skel {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: min(92%, 580px);
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}
.message-row--skel.message-row--skel--own {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.message-skel-ava {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(
    105deg,
    var(--bg-muted) 0%,
    var(--bg-elevated) 48%,
    var(--bg-muted) 100%
  );
  background-size: 200% 100%;
  animation: message-skel-wave 1.2s ease-in-out infinite;
}
.message__col--skel {
  min-width: 0;
  flex: 1;
  max-width: min(82%, 420px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.message-row--skel--own .message__col--skel {
  align-items: flex-end;
}
.message-skel-bubble-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.message-skel-bar {
  height: 13px;
  border-radius: 10px;
  width: 78%;
  max-width: 100%;
  background: linear-gradient(
    105deg,
    var(--bg-muted) 0%,
    var(--border) 45%,
    var(--bg-muted) 100%
  );
  background-size: 220% 100%;
  animation: message-skel-wave 1.2s ease-in-out infinite;
}
.message-skel-bar--long { width: 92%; height: 15px; }
.message-skel-bar--short {
  width: 48%;
  height: 11px;
  opacity: 0.92;
}
.messages__skeleton .message-row--skel:nth-child(3n) .message-skel-bar { animation-duration: 1.05s; }
@keyframes message-skel-wave {
  0%, 100% { background-position: 100% 50%; opacity: 0.65; }
  50% { background-position: 0% 50%; opacity: 0.95; }
}
@media (prefers-reduced-motion: reduce) {
  .message-skel-ava,
  .message-skel-bar {
    animation: none;
    opacity: 0.75;
  }
}
.message-row {
  display: flex; align-items: flex-start; gap: 8px;
  max-width: min(92%, 580px);
  align-self: flex-start;
}
.message-row--own {
  align-self: flex-end;
}
/* Выпадашка ⋯ должна быть над сообщениями ниже */
.message-row--menu-open {
  position: relative;
  z-index: 240;
}

.message-ava--in {
  /* верх пузыря = верх колонки; + смещение к первой строке текста внутри padding */
  margin-top: 7px;
}
.message-ava {
  flex: 0 0 32px;
  width: 32px; height: 32px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-muted);
  display: flex; align-items: center; justify-content: center;
}
.message-ava__img {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
}
.message-ava__fallback {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
  color: #0c1a08;
  background: linear-gradient(135deg, var(--accent-300), var(--accent-500));
}
.message__col {
  min-width: 0; flex: 1; max-width: 100%;
  display: flex; flex-direction: column; align-items: flex-start;
}
.message-row--own .message__col { align-items: flex-end; }
.message__bubble {
  background: var(--bubble-other);
  border: 1px solid var(--border);
  border-radius: 18px 18px 18px 6px;
  padding: 8px 13px 7px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 16px;
  line-height: 1.4;
  display: inline-block;
  max-width: 100%;
}
.message-row--own .message__bubble {
  background: var(--bubble-own);
  border-color: transparent;
  border-radius: 18px 18px 6px 18px;
  color: #0c1a08;
}

.message__legacy-hint {
  display: inline-block;
  max-width: 100%;
  padding: 6px 10px;
  font-size: 13px;
  line-height: 1.35;
  color: var(--fg-muted);
  font-style: italic;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--bg-muted);
}

.message-row--own .message__legacy-hint {
  text-align: right;
}

/* Вложения: message__file-imgwrap, message__file-thumb, message__file-video-c */
body.gh-lightbox-open {
  overflow: hidden;
}

.message__files {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 7px;
  width: 100%;
  min-width: 0;
  max-width: min(100%, min(98vw, 600px));
  margin-top: 2px;
  margin-bottom: 2px;
  box-sizing: border-box;
}
.message__files a:hover,
.message__files a:focus-visible {
  text-decoration: none;
}
.message-row--own .message__files {
  margin-left: auto;
  align-self: flex-end;
}
/*
 * Медиа-галерея: строго квадратные ячейки сеткой 3×N (как блоки 3×3).
 * Раньше разные модификаторы c2…c10 давали конфликт aspect-ratio/grid и «полоски».
 */
.message__files--media {
  display: grid;
  gap: 6px;
  width: 100%;
  max-width: min(100%, min(98vw, 600px));
  box-sizing: border-box;
  align-content: start;
  justify-content: start;
  /* три равные колонки → квадраты задаёт aspect-ratio на ячейке */
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: auto;
}

/* Одно фото/видео — без квадрата: исходное соотношение сторон */
.message__files--media.message__files--one {
  grid-template-columns: minmax(0, min(100%, 560px));
  max-width: min(100%, 560px);
}

.message__files--media .message__file {
  min-width: 0;
  width: 100%;
  margin: 0;
  padding: 0;
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-muted);
  isolation: isolate;
  /* квадрат только у сетки из нескольких медиа */
  aspect-ratio: 1 / 1;
  min-height: 112px;
}

.message-row--menu-open .message__files--media .message__file {
  overflow: visible;
}

.message__files--media.message__files--one .message__file {
  aspect-ratio: auto;
  min-height: 0;
  width: fit-content;
  max-width: 100%;
  align-self: flex-start;
}

.message-row--own .message__files--media.message__files--one .message__file {
  align-self: flex-end;
}

@media (max-width: 380px) {
  .message__files--media:not(.message__files--one) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.message__file {
  display: block;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.message__file-imgwrap {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border-radius: 12px;
  overflow: hidden;
  line-height: 0;
  background: var(--bg-muted);
  cursor: zoom-in;
}
.message__file-thumb {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: min(52vh, 460px);
  object-fit: contain;
  object-position: center;
}

.message__file-original-meta {
  font-size: 12px;
  line-height: 1.35;
  color: var(--fg-muted);
  margin: 0 0 6px;
}

.message__file-original-meta--stack {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
}

.message__file-original-meta--single {
  margin: 0 0 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message__file-original-meta__l1 {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg);
  line-height: 1.3;
}

.message__file-original-meta__l2 {
  font-size: 11px;
  color: var(--fg-muted);
  line-height: 1.27;
}

.message__file-image-bundle {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: min(100%, min(98vw, 600px));
}

.message__file-image-bundle--orig {
  max-width: min(100%, 420px);
}

.message__file-image-bundle__row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.message__file-image-bundle__txt {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding: 2px 0;
}

.message__file-image-bundle__l1 {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  line-height: 1.25;
}

.message__file-image-bundle__l2 {
  font-size: 11px;
  line-height: 1.25;
  color: var(--fg-muted);
}

.message__file-imgwrap--mini {
  flex: 0 0 auto;
  width: 112px;
  max-width: min(40vw, 140px);
  aspect-ratio: 1 / 1;
  max-height: none;
}

.message__file-imgwrap--mini .message__file-thumb {
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: cover;
}

.message__files--media .message__file-imgwrap--mini.message__file-imgwrap {
  position: relative;
  inset: auto;
}

.message__file-img-menu {
  flex: 0 0 auto;
  align-self: center;
}

.message__file-player__menuwrap--float {
  z-index: 60;
}

.message__file-player__menu--up {
  top: auto;
  bottom: calc(100% + 6px);
  margin-bottom: 0;
}

.message__files--media .message__file > a.message__file-imgwrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
  max-height: none;
  cursor: zoom-in;
}
.message__files--media .message__file > a.message__file-imgwrap .message__file-thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: cover;
  object-position: center;
}
.message__files--media.message__files--one .message__file > a.message__file-imgwrap {
  position: relative;
  inset: auto;
  width: auto;
  max-width: min(100%, 560px);
  height: auto;
  border-radius: 12px;
}
.message__files--media.message__files--one .message__file > a.message__file-imgwrap .message__file-thumb {
  position: relative;
  inset: auto;
  width: auto;
  max-width: min(100%, 560px);
  max-height: min(72vh, 680px);
  height: auto;
  object-fit: contain;
  object-position: center;
}
.message__file-video-c {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border-radius: 12px;
  overflow: hidden;
  line-height: 0;
  background: #0a0a0a;
  position: relative;
}
.message__file-openlb {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  cursor: pointer;
  transition: background 0.12s ease;
}
.message__file-openlb:hover {
  background: rgba(0, 0, 0, 0.7);
}
.message__file-openlb .material-symbols-outlined {
  font-size: 20px;
  line-height: 1;
}
.message__file-video {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: min(52vh, 400px);
  border-radius: 0;
  background: #000;
  vertical-align: middle;
}
.message__files--media .message__file-video-c {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-height: none;
  border-radius: 0;
}
.message__files--media .message__file-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: cover;
}

.message__files--media.message__files--one .message__file-video-c {
  position: relative;
  inset: auto;
  width: auto;
  max-width: min(100%, 560px);
  height: auto;
}

.message__files--media.message__files--one .message__file-video {
  position: relative;
  inset: auto;
  display: block;
  width: auto;
  max-width: min(100%, 560px);
  max-height: min(72vh, 680px);
  height: auto;
  object-fit: contain;
}

/* Инлайн-плеер аудио/видео в сообщении */
.message__file-player {
  width: 100%;
  min-width: 0;
  max-width: min(100%, min(420px, 94vw));
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 11px;
  border-radius: 14px;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  box-sizing: border-box;
}

.message-row--own .message__file-player {
  background: color-mix(in srgb, var(--bubble-own, #c8f0b0) 22%, var(--bg-muted));
  border-color: color-mix(in srgb, var(--bubble-own, #c8f0b0) 55%, transparent);
}

.message__file-player__video-hit {
  display: block;
  position: relative;
  line-height: 0;
  margin: 0;
  padding: 0;
  border-radius: 10px;
  overflow: hidden;
  cursor: zoom-in;
  background: #0c0d0c;
  max-height: min(220px, 52vh);
  border: none;
  width: 100%;
  box-sizing: border-box;
}

.message__file-player__video-hit:focus-visible {
  outline: 2px solid var(--accent-500);
  outline-offset: 2px;
}

.message__file-player__video {
  display: block;
  width: 100%;
  max-height: min(220px, 52vh);
  margin: 0;
  pointer-events: none;
  border-radius: 10px;
  background: #0c0d0c;
  object-fit: contain;
}

.message__file-player__bar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
  position: relative;
  z-index: 0;
}

.message__file-player__play {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: var(--accent-500);
  color: #0c1a08;
  cursor: pointer;
  display: grid;
  place-items: center;
  line-height: 0;
}

.message-row--own .message__file-player__play {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.message__file-player__play:focus-visible {
  outline: 2px solid var(--accent-500);
  outline-offset: 2px;
}

.message__file-player__play:hover {
  filter: brightness(1.06);
}

.message__file-player__play .material-symbols-outlined {
  font-size: 26px;
  margin-left: 2px; /* play arrow optically центрируется */
}

.message__file-player__seek {
  flex: 1;
  min-width: 48px;
  height: 6px;
  margin: 0;
  accent-color: var(--accent-500);
  cursor: pointer;
  position: relative;
  z-index: 0;
  max-width: 100%;
}

.message__file-player__times {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  line-height: 1.25;
  color: var(--fg-muted);
  white-space: nowrap;
}

.message__file-player__menuwrap {
  position: relative;
  flex: 0 0 auto;
  align-self: center;
  z-index: 8;
}

.message__file-player__dots {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
  position: relative;
  z-index: 2;
}

.message__file-player__dots:hover,
.message__file-player__dots:focus-visible {
  background: var(--bg-elevated);
  color: var(--fg);
}

.message__file-player__dots .material-symbols-outlined {
  font-size: 22px;
}

.message__file-player__menu {
  position: absolute;
  right: 0;
  left: auto;
  top: calc(100% + 6px);
  bottom: auto;
  min-width: 156px;
  padding: 6px 4px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.22);
  z-index: 10050;
}

@media (max-width: 380px) {
  .message__file-player__times {
    font-size: 11px;
  }

  .message__file-player__play {
    width: 38px;
    height: 38px;
  }
}

.message__file-player__download {
  display: block;
  width: 100%;
  padding: 9px 14px;
  margin: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  font-size: 14px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.message__file-player__download:hover {
  background: var(--bg-muted);
}

.message__file-doc {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 11px;
  min-width: 0;
  max-width: 100%;
  padding: 10px 13px;
  border-radius: 11px;
  background: var(--bg-muted);
  color: var(--fg);
  text-decoration: none;
  font-size: 14px;
  line-height: 1.35;
  border: 1px solid var(--border);
  word-break: break-word;
  overflow-wrap: anywhere;
  transition: background 0.1s ease;
}
.message__file-doc:hover {
  background: var(--bg-elevated);
}
.message__file-doc-ico {
  font-size: 34px;
  line-height: 1;
  color: var(--accent-500);
  flex: 0 0 auto;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  user-select: none;
}
.message__file-doc-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.message__file-name {
  font-weight: 500;
  color: var(--fg);
}
.message__file-meta {
  font-size: 13px;
  color: var(--fg-muted);
}
.message-row--own[data-pending="1"] .message__files {
  opacity: 0.6;
}

/* Лайтбокс: затемнение чата, навигация, счётчик */
.media-lightbox {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-sizing: border-box;
}
.media-lightbox__backdrop {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.82);
  z-index: 0;
  cursor: zoom-out;
}
.media-lightbox__stage {
  position: relative;
  z-index: 1;
  max-width: min(96vw, 1200px);
  max-height: 88vh;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 48px 56px 72px;
  pointer-events: auto;
}
.media-lightbox__img {
  max-width: 100%;
  max-height: 82vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
}
.media-lightbox__video {
  max-width: 100%;
  max-height: 82vh;
  width: auto;
  background: #000;
  border-radius: 4px;
  pointer-events: auto;
}
.media-lightbox__nav {
  position: absolute;
  z-index: 2;
  top: 0;
  bottom: 0;
  width: 48px;
  margin: 0;
  padding: 0;
  border: none;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  pointer-events: auto;
}
.media-lightbox__nav:hover,
.media-lightbox__nav:focus-visible {
  background: rgba(0, 0, 0, 0.5);
  outline: none;
}
.media-lightbox__nav--prev {
  left: 0;
  padding-left: 4px;
  border-radius: 0 8px 8px 0;
}
.media-lightbox__nav--next {
  right: 0;
  padding-right: 4px;
  border-radius: 8px 0 0 8px;
}
.media-lightbox__nav-sym {
  display: block;
  font-size: 2.2rem;
  font-weight: 300;
  line-height: 1;
  opacity: 0.95;
  user-select: none;
}
.media-lightbox__bar {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 12px 16px 20px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  color: #e8e8e8;
  font-size: 13px;
  text-align: center;
  pointer-events: none;
}
.media-lightbox__bar-count {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  letter-spacing: 0.02em;
  opacity: 0.95;
}
.media-lightbox__bar-name {
  max-width: min(90vw, 640px);
  word-break: break-word;
  opacity: 0.85;
  font-size: 12px;
}
@media (max-width: 520px) {
  .media-lightbox__stage {
    padding: 40px 40px 68px;
  }
  .media-lightbox__nav {
    width: 40px;
  }
}

.message__time {
  display: block; font-size: 12px; color: var(--fg-muted);
  margin-top: 3px; padding: 0 2px 0 4px;
}
.message__time--own { text-align: right; padding: 0 4px 0 2px; }
.message__time-row--own {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  width: 100%;
  flex-wrap: wrap;
  margin-top: 3px;
}
.message__time-row--own .message__time {
  margin-top: 0;
  flex: 0 0 auto;
}
.message__receipt {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.message__receipt .material-symbols-outlined {
  font-size: 15px;
  line-height: 1;
}
.message__receipt--sent {
  color: color-mix(in srgb, var(--fg-muted) 88%, transparent);
}
.message__receipt--delivered {
  color: color-mix(in srgb, var(--fg-muted) 82%, transparent);
  opacity: 0.92;
}
.message__receipt--read {
  color: var(--accent-500);
}
.message__receipt--read .material-symbols-outlined {
  font-variation-settings: 'FILL' 1, 'wght' 500;
}
.message-row--own[data-pending="1"] .message__bubble { opacity: 0.6; }

/* Подсветка при «переходе к ответу»: вся ширина ленты, на всю высоту карточки, без квадратиков/скруглений */
.message-row--flash {
  --msg-bleed: 14px; /* = гориз. padding .messages; полоска на полную ширину области чата */
  position: relative;
  z-index: 0;
  align-self: stretch !important;
  box-sizing: border-box;
  width: auto !important;
  max-width: none !important;
  margin-left: calc(-1 * var(--msg-bleed));
  margin-right: calc(-1 * var(--msg-bleed));
  padding: 5px var(--msg-bleed) 6px;
  border-radius: 0;
  justify-content: flex-start;
}
.message-row--own.message-row--flash {
  justify-content: flex-end;
}
.message-row--flash::before {
  content: "";
  position: absolute;
  z-index: 0;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  border-radius: 0;
  background: rgba(141, 198, 98, 0.2);
  pointer-events: none;
  animation: message-row-flash-wash 1.55s ease-out forwards;
}
.message-row--flash > * {
  position: relative;
  z-index: 1;
}
@keyframes message-row-flash-wash {
  0% { opacity: 1; }
  40% { opacity: 0.6; }
  100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .message-row--flash { padding: 4px 0; }
  .message-row--flash::before {
    animation: message-row-flash-wash-reduce 0.45s ease-out forwards;
  }
  @keyframes message-row-flash-wash-reduce {
    0% { opacity: 0.9; }
    100% { opacity: 0; }
  }
}

/* Цитата (ответ) над пузырём — как в Telegram; кнопка — переход к исходному */
button.message__quote {
  display: flex; gap: 6px; align-items: stretch;
  max-width: 100%;
  margin: 0 0 3px; padding: 2px 4px 2px 1px;
  border: none; border-radius: 8px;
  background: transparent; font: inherit; text-align: left;
  cursor: pointer; color: inherit;
  -webkit-tap-highlight-color: transparent;
}
button.message__quote:hover,
button.message__quote:focus-visible {
  background: rgba(0, 0, 0, 0.05);
  outline: none;
}
.message-row--own button.message__quote:hover,
.message-row--own button.message__quote:focus-visible {
  background: rgba(0, 0, 0, 0.06);
}
.message__quote-bar {
  width: 3px; border-radius: 2px; flex: 0 0 auto;
  background: var(--accent-500);
}
.message-row--own .message__quote-bar { background: #4a6b35; }
.message__quote-text { min-width: 0; }
.message__quote-name {
  font-size: 13px; font-weight: 600; color: var(--accent-500);
  line-height: 1.25;
  margin-bottom: 1px;
}
.message-row--own .message__quote-name { color: #3d5a2a; }
.message__quote-preview {
  font-size: 13px; line-height: 1.25;
  color: var(--fg-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: min(320px, 100%);
}
.message__bubble--deleted {
  font-style: italic;
  opacity: 0.8;
  color: var(--fg-muted);
}
.message-row--deleted .message__quote { opacity: 0.85; }

/* ПКМ-меню */
.message-ctx {
  min-width: 168px; padding: 4px 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.message-ctx__btn {
  display: block; width: 100%;
  margin: 0; padding: 9px 14px; border: none; background: none;
  font: inherit; font-size: 14px; text-align: left; cursor: pointer;
  color: var(--fg);
  transition: background 0.1s ease;
}
.message-ctx__btn:hover,
.message-ctx__btn:focus-visible {
  background: var(--bg-muted);
  outline: none;
}
.message-ctx__btn--danger { color: #c0392b; }
.message-ctx__btn--danger:hover,
.message-ctx__btn--danger:focus-visible { background: rgba(192, 57, 43, 0.1); }

.composer {
  display: flex; flex-direction: column;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 0;
  gap: 0;
}
.composer__reply {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  background: var(--bg-muted);
}
.composer__reply-goto {
  flex: 1; min-width: 0; margin: 0; padding: 0;
  border: none; border-radius: 8px;
  background: transparent; font: inherit; text-align: left;
  cursor: pointer; color: inherit;
  -webkit-tap-highlight-color: transparent;
}
.composer__reply-goto:hover,
.composer__reply-goto:focus-visible {
  background: rgba(0, 0, 0, 0.05);
  outline: none;
}
.composer__reply-text { flex: 1; min-width: 0; }
.composer__reply-line { font-size: 13px; color: var(--accent-500); font-weight: 600; }
.composer__reply-preview { font-size: 13px; color: var(--fg-muted); margin-top: 2px; line-height: 1.3; }
.composer__reply-close {
  flex: 0 0 28px; width: 28px; height: 28px; margin: 0; padding: 0; border: none;
  border-radius: 8px; background: transparent; color: var(--fg-muted);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.composer__reply-close:hover { background: var(--bg-elevated); color: var(--fg); }

.composer__attach-opts {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  padding: 9px 15px; border-bottom: 1px solid var(--border);
  background: var(--bg-muted);
  font-size: 13px; color: var(--fg);
}
.composer__opt { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.composer__opt input { width: 14px; height: 14px; accent-color: var(--accent-500); }
.composer__chips {
  list-style: none; margin: 0; padding: 6px 12px; border-bottom: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 6px; max-height: 120px; overflow-y: auto;
  background: var(--bg);
}
.composer__chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 4px 7px 4px 9px; border-radius: 6px; background: var(--bg-muted);
  font-size: 13px; color: var(--fg); border: 1px solid var(--border);
}
.composer__chip-thumb {
  flex-shrink: 0;
  width: 28px; height: 28px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--bg-muted);
  display: block;
}
.composer__chip-ico {
  flex-shrink: 0;
  width: 28px; height: 28px;
  display: grid;
  place-items: center;
  font-size: 22px;
  line-height: 1;
  color: var(--fg-muted);
}
.composer__chip-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer__chip-x {
  margin: 0; padding: 0 2px; border: none; background: none; cursor: pointer;
  font-size: 16px; line-height: 1; color: var(--fg-muted);
}
.composer__chip-x:hover { color: var(--fg); }

.composer__row {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 6px 10px; align-items: center;
  padding: 13px 18px;
}
.composer__clip {
  display: grid; place-items: center; width: 44px; height: 44px; margin: 0; padding: 0;
  border: none; border-radius: 10px; background: transparent; color: var(--fg-muted);
  cursor: pointer; flex-shrink: 0;
  transition: background 0.12s ease, color 0.12s ease;
}
.composer__clip:hover:not(:disabled),
.composer__clip:focus-visible {
  background: var(--bg-muted); color: var(--accent-500); outline: none;
}
.composer__clip:disabled { opacity: 0.4; cursor: not-allowed; }
.composer__clip-ico {
  display: block;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  pointer-events: none;
  transform: translate(0.5px, 0.5px);
  opacity: 0.9;
  transition: opacity 0.12s ease;
}
.composer__clip:hover:not(:disabled) .composer__clip-ico,
.composer__clip:focus-visible:not(:disabled) .composer__clip-ico {
  opacity: 1;
}
.composer__input {
  border: 1px solid var(--border); background: var(--bg); color: var(--fg);
  border-radius: 999px; padding: 11px 18px; outline: none;
  font-size: 15px;
  transition: border-color 120ms ease;
}
.composer__input:focus { border-color: var(--accent-500); }
.composer__send {
  display: grid;
  place-items: center;
  padding: 6px 8px;
  margin: 0;
  min-width: 44px;
  min-height: 44px;
  background: transparent;
  border: none;
  color: var(--accent-500);
  cursor: pointer;
  box-shadow: none;
  border-radius: var(--radius-sm);
  transition: opacity 120ms ease, transform 80ms ease;
}
.composer__send:hover {
  background: transparent;
  color: var(--accent-300);
  opacity: 0.9;
}
.composer__send:disabled { opacity: 0.4; cursor: not-allowed; }
.composer__send-icon {
  display: block;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

/* ---- Профиль справа ---- */

.profile-pane {
  display: block;
  overflow-y: auto;
  padding: 20px 24px 40px;
}
.profile-stack {
  width: 100%;
  max-width: min(640px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
  box-sizing: border-box;
}
.profile-flash {
  list-style: none;
  margin: 0 0 8px;
  padding: 10px 14px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  border-radius: var(--radius-sm);
  background: rgba(141, 198, 98, 0.2);
  border: 1px solid var(--accent-300);
  color: var(--fg);
  font-size: 14px;
}
/* Секции профиля — только отступы, без линий-разделителей */
.profile-sec { margin: 0; padding: 0; }
.profile-block__h {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
}
.profile-fields { display: grid; gap: 12px; }
/* Размер/цвет иконок (семейство задаётся стилями Google Fonts Material Symbols) */
.profile-ico {
  font-size: 24px;
  line-height: 1;
  color: var(--accent-500);
  user-select: none;
}
.profile-ico--btn {
  font-size: 20px;
  color: inherit;
  opacity: 0.95;
}
.profile-hero__page-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
}
.profile-hero__h1 { margin: 0; font-size: 26px; font-weight: 700; }
.profile-hero {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 20px 28px;
  align-items: start;
  padding: 0;
  margin: 0;
  border: none;
}
.profile-hero__subhead {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
}
.profile-hero__avatar .profile-avatar-label {
  margin: 0;
  justify-items: start;
  max-width: none;
  gap: 0;
}
.profile-sec--actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 4px;
}
.profile-sec--actions .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  box-sizing: border-box;
}
/* Выпадающий список темы */
select.select-theme {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding: 11px 44px 11px 14px;
  font-size: 14px;
  line-height: 1.4;
  font-weight: 500;
  color: var(--fg);
  background-color: var(--bg-elevated);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236FA747' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 1.1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
select.select-theme:hover {
  border-color: var(--accent-300);
}
select.select-theme:focus {
  outline: none;
  border-color: var(--accent-500);
  box-shadow: 0 0 0 3px rgba(111, 167, 71, 0.22);
}
[data-theme="dark"] select.select-theme {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23AFD895' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
@media (prefers-color-scheme: dark) {
  [data-theme="system"] select.select-theme {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23AFD895' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  }
}
.profile-avatar-label {
  display: grid;
  justify-items: center;
  gap: 10px;
  cursor: pointer;
  max-width: 220px;
  margin: 0 auto;
}
.profile-avatar-target {
  position: relative;
  width: 112px;
  height: 112px;
  border-radius: 50%;
}
.profile-avatar-ring {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--accent-300);
  box-shadow: 0 6px 24px rgba(111, 167, 71, 0.25);
  background: var(--bg-muted);
}
.profile-avatar-ring--fallback {
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--accent-100), var(--accent-500));
  color: #0c1a08;
  font-size: 40px;
  font-weight: 800;
}
.profile-avatar-hint { font-size: 12px; color: var(--accent-500); text-align: center; }
.profile-avatar-input {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Мастер группы ---- */

.group-wizard {
  position: fixed;
  inset: 0;
  z-index: 8000;
  display: grid;
  place-items: center;
  padding: 16px;
  box-sizing: border-box;
}
.group-wizard__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
}
.group-wizard__panel {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  max-height: min(88vh, 720px);
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.group-wizard__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.group-wizard__title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}
.group-wizard__close {
  margin: 0;
  padding: 0 8px;
  border: none;
  background: none;
  font-size: 24px;
  line-height: 1;
  color: var(--fg-muted);
  cursor: pointer;
  border-radius: 8px;
}
.group-wizard__close:hover {
  background: var(--bg-muted);
  color: var(--fg);
}
.group-wizard__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.group-wizard__hint {
  margin: 0;
  font-size: 13px;
  color: var(--fg-muted);
  line-height: 1.4;
}
.group-wizard__field {
  display: grid;
  gap: 6px;
}
.group-wizard__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
}
.group-wizard__input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  background: var(--bg);
}
.group-wizard__input:focus {
  outline: none;
  border-color: var(--accent-500);
}
.group-wizard__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.group-wizard__avatar-box {
  flex-shrink: 0;
}
.group-wizard__avatar-preview {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  border: 1px solid var(--border);
  background: var(--bg-muted);
}
.group-wizard__avatar-placeholder {
  width: 56px;
  height: 56px;
  font-size: 20px;
}
.group-wizard__browse {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-muted);
  font-size: 14px;
  cursor: pointer;
  color: var(--fg);
}
.group-wizard__browse:hover {
  background: var(--bg);
}
.group-wizard__file {
  cursor: pointer;
  margin: 0;
}
.group-wizard__clear-photo {
  border: none;
  background: none;
  color: var(--accent-600, var(--accent-500));
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
}
.group-wizard__list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}
.group-wizard__empty {
  font-size: 13px;
  color: var(--fg-muted);
  padding: 8px 4px;
}
.group-wizard__user {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--bg);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  width: 100%;
}
.group-wizard__user:hover {
  background: var(--bg-muted);
}
.group-wizard__user--on {
  border-color: var(--accent-500);
  background: rgba(111, 167, 71, 0.12);
}
.group-wizard__user .avatar--sm-fix {
  width: 36px;
  height: 36px;
}
.group-wizard__user-text {
  min-width: 0;
}
.group-wizard__user-name {
  display: block;
  font-weight: 600;
  font-size: 14px;
}
.group-wizard__user-tag {
  font-size: 12px;
  color: var(--fg-muted);
}
.group-wizard__check {
  font-size: 22px !important;
  color: var(--fg-muted);
  opacity: 0.28;
}
.group-wizard__user--on .group-wizard__check {
  color: var(--accent-500);
  opacity: 1;
}
.group-wizard__error {
  margin: 4px 0 0;
  font-size: 13px;
  color: #c0392b;
}
.group-wizard__foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-muted);
}

/* Модалки подтем (супергруппа) — те же паттерны, выше по слою */
.group-wizard.topic-modal {
  z-index: 8075;
}
.topic-modal__panel--narrow {
  width: min(400px, 100%);
}
.topic-modal__text {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--fg);
}
.topic-modal__text strong {
  font-weight: 600;
  word-break: break-word;
}

.topic-emoji-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.topic-emoji-pick {
  width: 42px;
  height: 40px;
  font-size: 1.35rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-muted);
  cursor: pointer;
  line-height: 1;
  padding: 0;
  transition:
    border-color 0.12s ease,
    background 0.12s ease,
    transform 0.12s ease;
}
.topic-emoji-pick:hover {
  background: var(--bg);
  border-color: var(--accent-500);
}
.topic-emoji-pick--on {
  border-color: var(--accent-500);
  background: color-mix(in srgb, var(--accent-300) 22%, transparent);
}

/* ---- Инфо группы (модалка) ---- */

.group-info {
  position: fixed;
  inset: 0;
  z-index: 8050;
  display: grid;
  place-items: center;
  padding: 16px;
  box-sizing: border-box;
}
.group-info__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
}
.group-info__panel {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  max-height: min(88vh, 720px);
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.group-info__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.group-info__title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}
.group-info__close {
  margin: 0;
  padding: 0 8px;
  border: none;
  background: none;
  font-size: 24px;
  line-height: 1;
  color: var(--fg-muted);
  cursor: pointer;
  border-radius: 8px;
}
.group-info__close:hover {
  background: var(--bg-muted);
  color: var(--fg);
}
.group-info__body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0;
}
.group-info__sheet {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 16px 16px;
}
.gh-scroll-pane {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--fg-muted) 35%, var(--border)) transparent;
}
.gh-scroll-pane::-webkit-scrollbar {
  width: 6px;
}
.gh-scroll-pane::-webkit-scrollbar-track {
  background: transparent;
}
.gh-scroll-pane::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--fg-muted) 28%, var(--border));
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.gh-scroll-pane:hover::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--accent-500) 32%, var(--fg-muted));
  background-clip: padding-box;
}

/* Узкий скролл: вложения и похожие списки (чаще колесо, не тащат ползунок) */
.gh-scrollbar--fine {
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--fg-muted) 38%, var(--border)) transparent;
}
.gh-scrollbar--fine::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
.gh-scrollbar--fine::-webkit-scrollbar-track {
  background: transparent;
  margin: 4px 0;
}
.gh-scrollbar--fine::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--fg-muted) 32%, var(--border));
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.gh-scrollbar--fine:hover::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--accent-500) 35%, var(--fg-muted));
  background-clip: padding-box;
}
.group-info__loading {
  padding: 16px 16px 0;
  color: var(--fg-muted);
  font-size: 14px;
}
.group-info__error {
  margin: 12px 16px 0;
  font-size: 13px;
  color: #c0392b;
}
.group-info__hero {
  position: relative;
  width: min(280px, 72vw);
  height: min(280px, 72vw);
  margin: 16px auto 4px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.group-info__hero-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.group-info__hero-placeholder {
  width: 100%;
  height: 100%;
  font-size: 72px;
}
.group-info__hero-edit {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 12px;
}
.group-info__hero-edit:focus-visible {
  outline: 2px solid var(--accent-500);
  outline-offset: 2px;
}
.group-info__hero-edit[disabled] {
  cursor: wait;
}
.group-info__hero-edit-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.52);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.02em;
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
}
.group-info__hero-edit:hover:not([disabled]) .group-info__hero-edit-label {
  opacity: 1;
}
@media (hover: none) {
  .group-info__hero-edit:not([disabled]) .group-info__hero-edit-label {
    opacity: 1;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 12px;
    background: linear-gradient(
      to top,
      rgba(0, 0, 0, 0.72) 0%,
      transparent 55%
    );
  }
}
.group-info__hero-busy {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  pointer-events: none;
  z-index: 2;
}
.group-info__accordion {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.group-info__acc-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  margin: 0;
  padding: 12px 10px;
  border: none;
  border-radius: 10px;
  background: transparent;
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  color: var(--fg);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.group-info__acc-trigger:hover,
.group-info__acc-trigger:focus-visible {
  background: var(--bg-muted);
  outline: none;
}
.group-info__acc-trigger-text {
  flex: none;
}
.group-info__acc-meta {
  font-weight: 600;
  color: var(--fg-muted);
}
.group-info__acc-chevron {
  margin-left: auto;
  font-size: 22px !important;
  color: var(--fg-muted);
  transition: transform 0.2s ease;
}
.group-info__acc-chevron--open {
  transform: rotate(180deg);
}
.group-info__acc-panel {
  padding: 4px 0 12px 4px;
  border-bottom: 1px solid var(--border);
}
.group-info__acc-panel:last-of-type {
  border-bottom: none;
}
.group-info__invite-list {
  max-height: min(240px, 42vh);
  overflow-y: auto;
}

.group-info__hint {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--fg-muted);
  line-height: 1.4;
}
.group-info__field {
  display: block;
  margin-bottom: 8px;
}
.group-info__label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
}
.group-info__member-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.group-info__member {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.group-info__member:last-child {
  border-bottom: none;
}
.group-info__member-ava {
  flex-shrink: 0;
}
.group-info__member-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.group-info__member-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.group-info__member-name {
  font-weight: 500;
  font-size: 15px;
}
.group-info__member-tag {
  font-size: 13px;
  color: var(--fg-muted);
}
.group-info__member-role {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-muted);
  line-height: 1.3;
}
.group-info__member-actions {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  align-self: flex-start;
  min-width: min(174px, 42vw);
}
.group-info__member-actions .btn--small {
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  white-space: normal;
  line-height: 1.25;
  padding-left: 10px;
  padding-right: 10px;
}
.group-info__add-members {
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.group-info__invite-foot {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}
.group-info__settings-mgmt {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
  display: grid;
  gap: 10px;
}
.group-info__hint--spaced {
  margin: 0;
}
.group-info__hint--spaced-top {
  margin: 16px 0 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.group-info__topics-block {
  display: grid;
  gap: 12px;
}
.group-info__topics-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: min(240px, 38vh);
  overflow-y: auto;
}
.group-info__topic-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-muted);
  border: 1px solid color-mix(in srgb, var(--border) 82%, transparent);
}
.group-info__topic-emoji {
  flex-shrink: 0;
  font-size: 1.25rem;
  line-height: 1;
}
.group-info__topic-title {
  flex: 1;
  min-width: 0;
  font-weight: 500;
  font-size: 14px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
}
.group-info__topic-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 2px;
}
.group-info__topic-icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 30px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
  opacity: 0.88;
  -webkit-tap-highlight-color: transparent;
}
.group-info__topic-icon-btn:hover,
.group-info__topic-icon-btn:focus-visible {
  opacity: 1;
  background: color-mix(in srgb, var(--fg-muted) 12%, transparent);
  outline: none;
}
.group-info__topic-icon-btn .material-symbols-outlined {
  font-size: 18px;
  line-height: 1;
}
.group-info__topic-icon-btn--danger:hover,
.group-info__topic-icon-btn--danger:focus-visible {
  color: var(--danger, #c62828);
}
.group-info__rename-form {
  display: grid;
  gap: 10px;
}
.group-info__rename-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.group-info__delete-row {
  margin-top: 4px;
}

/* Общее: вложения в карточке группы / собеседника */
.chat-attachments-hub {
  margin-top: 4px;
}
.chat-attachments-hub--peer {
  margin-top: 16px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}
.chat-attachments-hub__panel {
  padding-top: 4px;
}
.chat-attachments-hub__hint {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--fg-muted);
  line-height: 1.35;
}
.chat-attachments-hub__error {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--danger, #c62828);
}
.chat-attachments-hub__loading {
  font-size: 13px;
  color: var(--fg-muted);
  padding: 8px 0;
}
.chat-attachments-hub__tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.chat-attachments-hub__tab {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-muted);
  font-size: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chat-attachments-hub__tab:hover,
.chat-attachments-hub__tab:focus-visible {
  background: color-mix(in srgb, var(--fg-muted) 10%, transparent);
  outline: none;
}
.chat-attachments-hub__tab--on {
  background: color-mix(in srgb, var(--accent-500) 26%, transparent);
  border-color: color-mix(in srgb, var(--accent-500) 52%, transparent);
  font-weight: 600;
}
.chat-attachments-hub__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.chat-attachments-hub__cell {
  position: relative;
  display: block;
  min-width: 0;
}
.chat-attachments-hub__thumb-btn {
  position: relative;
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-muted);
  cursor: zoom-in;
  aspect-ratio: 1;
}
.chat-attachments-hub__thumb-img,
.chat-attachments-hub__thumb-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  vertical-align: bottom;
}
.chat-attachments-hub__thumb-btn--vid .chat-attachments-hub__thumb-video {
  display: block;
}
.chat-attachments-hub__vid-ico {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 36px;
  color: #fff;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.55));
  pointer-events: none;
}
.chat-attachments-hub__thumb-btn--vid::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.06),
    rgba(0, 0, 0, 0.32)
  );
  pointer-events: none;
}
/* Кнопка «Показать в чате» — иконка-плашка поверх плитки и в списках */
.chat-attachments-hub__goto {
  position: absolute;
  top: 6px;
  right: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  z-index: 1;
}
.chat-attachments-hub__goto .material-symbols-outlined {
  font-size: 16px;
  line-height: 1;
}
.chat-attachments-hub__goto-label {
  font-weight: 600;
  letter-spacing: 0.01em;
}
.chat-attachments-hub__cell:hover .chat-attachments-hub__goto,
.chat-attachments-hub__cell:focus-within .chat-attachments-hub__goto {
  opacity: 1;
}
.chat-attachments-hub__goto:hover,
.chat-attachments-hub__goto:focus-visible {
  background: rgba(0, 0, 0, 0.78);
  outline: none;
}
@media (hover: none) {
  .chat-attachments-hub__goto {
    opacity: 1;
  }
}
/* Инлайн-вариант — для файлов и ссылок */
.chat-attachments-hub__goto--inline {
  position: static;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  justify-content: center;
  background: var(--bg-muted);
  color: var(--fg-muted);
  border: 1px solid var(--border);
  opacity: 1;
}
.chat-attachments-hub__goto--inline .material-symbols-outlined {
  font-size: 18px;
}
.chat-attachments-hub__goto--inline:hover,
.chat-attachments-hub__goto--inline:focus-visible {
  background: color-mix(in srgb, var(--accent-500) 16%, var(--bg-muted));
  color: var(--accent-500);
  border-color: color-mix(in srgb, var(--accent-500) 50%, var(--border));
}
.chat-attachments-hub__more {
  display: block;
  width: 100%;
  margin: 0 0 12px;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-muted);
  color: var(--fg);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
}
.chat-attachments-hub__more[disabled] {
  opacity: 0.65;
  cursor: default;
}
.chat-attachments-hub__more:not([disabled]):hover,
.chat-attachments-hub__more:not([disabled]):focus-visible {
  background: color-mix(in srgb, var(--accent-500) 14%, var(--bg-muted));
  border-color: color-mix(in srgb, var(--accent-500) 36%, var(--border));
  outline: none;
}
.chat-attachments-hub__empty {
  font-size: 13px;
  color: var(--fg-muted);
  padding: 6px 0 12px;
}
.chat-attachments-hub__file-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: grid;
  gap: 10px;
  max-height: min(260px, 36vh);
  overflow-y: auto;
}
.peer-card-modal .chat-attachments-hub__file-list {
  max-height: min(200px, 30vh);
}
.chat-attachments-hub__file-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
}
.chat-attachments-hub__file-doc {
  display: flex;
  gap: 10px;
  min-width: 0;
  flex: 1;
  text-decoration: none;
  color: inherit;
}
.chat-attachments-hub__file-doc:hover .chat-attachments-hub__file-name {
  text-decoration: underline;
}
.chat-attachments-hub__file-ico {
  flex-shrink: 0;
  font-size: 24px;
  color: var(--fg-muted);
  line-height: 1;
}
.chat-attachments-hub__file-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.chat-attachments-hub__file-name {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-attachments-hub__file-meta {
  font-size: 12px;
  color: var(--fg-muted);
}
.chat-attachments-hub__link-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: grid;
  gap: 10px;
  max-height: min(260px, 36vh);
  overflow-y: auto;
}
.peer-card-modal .chat-attachments-hub__link-list {
  max-height: min(200px, 30vh);
}
.chat-attachments-hub__link-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  font-size: 13px;
  min-width: 0;
}
.chat-attachments-hub__link-main {
  flex: 1;
  min-width: 120px;
  display: grid;
  gap: 2px;
  text-decoration: none;
  color: inherit;
}
.chat-attachments-hub__link-main:hover .chat-attachments-hub__link-text {
  text-decoration: underline;
}
.chat-attachments-hub__link-host {
  font-weight: 600;
  font-size: 12px;
  color: var(--fg-muted);
}
.chat-attachments-hub__link-text {
  word-break: break-all;
  line-height: 1.35;
  color: var(--accent-500);
}
.chat-attachments-hub__link-meta {
  font-size: 12px;
  color: var(--fg-muted);
}

/* Карточка собеседника (личный чат) — как group-info */
.peer-card-modal {
  position: fixed;
  inset: 0;
  z-index: 8050;
  display: grid;
  place-items: center;
  padding: 16px;
  box-sizing: border-box;
}
.peer-card-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
}
.peer-card-modal__panel {
  position: relative;
  z-index: 1;
  width: min(380px, 100%);
  max-height: min(92vh, 720px);
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.peer-card-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.peer-card-modal__title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}
.peer-card-modal__close {
  margin: 0;
  padding: 0 8px;
  border: none;
  background: none;
  font-size: 24px;
  line-height: 1;
  color: var(--fg-muted);
  cursor: pointer;
  border-radius: 8px;
}
.peer-card-modal__close:hover,
.peer-card-modal__close:focus-visible {
  background: var(--bg-muted);
  outline: none;
  color: var(--fg);
}
.peer-card-modal__body {
  padding: 20px 20px 24px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.peer-card-modal__hero {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}
.peer-card-modal__hero-img {
  width: min(112px, 40vw);
  height: min(112px, 40vw);
  border-radius: 50%;
  object-fit: cover;
  display: block;
  border: 1px solid var(--border);
  background: var(--bg-muted);
}
.peer-card-modal__hero-ph {
  width: min(112px, 40vw);
  height: min(112px, 40vw);
}
.peer-card-modal__line--name {
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  word-break: break-word;
}
.peer-card-modal__line--tag {
  margin-top: 4px;
  font-size: 14px;
  color: var(--fg-muted);
  text-align: center;
}
.peer-card-modal__email {
  display: block;
  margin-top: 14px;
  text-align: center;
  font-size: 14px;
  color: var(--accent-500);
  word-break: break-all;
  text-decoration: none;
}
.peer-card-modal__email:hover {
  text-decoration: underline;
}

/* ---- Модалка ---- */

.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: grid; place-items: center;
  z-index: 100;
}
.modal__card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 24px;
  width: min(420px, 90vw);
  display: grid; gap: 14px;
  box-shadow: var(--shadow);
}
.modal__card h3 { margin: 0; }

/* ===========================================================================
   Адаптив
   =========================================================================== */

@media (max-width: 720px) {
  /* Список чатов: одна колонка; узкий rail не используем — полная ширина под бургер и поиск */
  .app,
  .app.app--sidebar-rail {
    grid-template-columns: 1fr;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }
  /* Заставка «выберите чат» не дублирует список */
  #messenger-outlet.messenger-outlet--splash-only {
    display: none !important;
  }
  /* Открытый чат: только лента, без сайдбара — стрелка «назад» + шапка как на десктопе */
  .app.app--chat-open aside.sidebar {
    display: none !important;
  }
  .app.app--chat-open {
    grid-template-rows: minmax(0, 1fr);
  }
  .app.app--chat-open #messenger-outlet {
    min-height: 0;
  }
  /* Узкая колонка-«рейка» только на десктопе */
  .sidebar__rail-btn {
    display: none !important;
  }
  .window__head-back {
    display: flex;
  }
  .window__head {
    grid-template-columns: 40px 44px 1fr;
    gap: 8px 10px;
    align-items: center;
  }
  .window__head, .composer__row { padding: 11px 14px; }
  .composer__reply { padding-left: 12px; padding-right: 12px; }
  .messages { padding: 12px 12px 16px; }
  .message-row--flash { --msg-bleed: 11px; }
  .profile-hero { grid-template-columns: 1fr; }
  .profile-pane { padding: 16px 14px 32px; }
}
