/* ================================
   Auth / Registration Styles
   ================================ */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Firefox iOS: viewport meta с max-scale (см. useVisualViewportCss) + меньше ложного «зума» от жестов */
html.fx-ios body.nodum-app {
  touch-action: manipulation;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: manipulation;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  box-sizing: border-box;
  background: var(--bg-app, #0b1220);
  backdrop-filter: blur(20px);
}

/*
 * Клавиатура (iOS PWA / Safari): layout viewport часто остаётся полноэкранным, а видимая
 * область меньше — поджимаем оверлей к visualViewport, чтобы поле ввода не пряталось под IME.
 */
@media (max-width: 904px) {
  html.vv-keyboard .auth-overlay {
    top: var(--vv-visual-offset-top, 0px);
    left: 0;
    right: 0;
    bottom: auto;
    height: var(--vv-visual-height, 100dvh);
    max-height: var(--vv-visual-height, 100dvh);
  }
}

.auth-overlay[hidden] {
  display: none !important;
}

.auth-container {
  width: min(420px, 100%);
  max-width: 100%;
  box-sizing: border-box;
  max-height: min(calc(100dvh - 24px), 900px);
  margin: auto 0;
  padding: 28px 24px 32px;
  overflow-y: auto;
  background: var(--panel-bg, #121a2a);
  border-radius: 24px;
  box-shadow: 0 25px 80px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.05);
  animation: authSlideIn 0.4s ease;
}

@media (min-width: 480px) {
  .auth-container {
    padding: 40px 32px;
    margin: auto;
  }

  .auth-overlay {
    align-items: center;
  }
}

@keyframes authSlideIn {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.auth-brand {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo {
  margin-bottom: 16px;
}

.auth-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary, #f1f5f9);
  margin: 0 0 8px;
}

.auth-subtitle {
  font-size: 15px;
  color: var(--text-secondary, #94a3b8);
  margin: 0;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.auth-form[hidden] {
  display: none !important;
}

.auth-step-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary, #f1f5f9);
  margin: 0 0 8px;
  text-align: center;
}

.auth-step-hint {
  font-size: 14px;
  color: var(--text-secondary, #94a3b8);
  margin: 0 0 8px;
  text-align: center;
  line-height: 1.5;
}

.auth-spam-notice {
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-secondary, #94a3b8);
  margin: 0;
  padding: 12px 14px;
  text-align: left;
  border-radius: 12px;
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.28);
  box-sizing: border-box;
}

.auth-spam-notice--compact {
  margin-top: -8px;
}

.auth-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary, #94a3b8);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.auth-input {
  height: 52px;
  padding: 0 16px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text-primary, #f1f5f9);
  background: var(--input-bg, #0b1220);
  border: 1px solid var(--input-border, rgba(148,163,184,0.15));
  border-radius: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.auth-input:focus {
  border-color: var(--accent, #34d399);
  box-shadow: 0 0 0 3px rgba(52,211,153,0.15);
}

.auth-input::placeholder {
  color: var(--text-tertiary, #64748b);
}

/* Phone Input */
.auth-phone-input {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 52px;
  padding: 0 16px;
  background: var(--input-bg, #0b1220);
  border: 1px solid var(--input-border, rgba(148,163,184,0.15));
  border-radius: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.auth-phone-input:focus-within {
  border-color: var(--accent, #34d399);
  box-shadow: 0 0 0 3px rgba(52,211,153,0.15);
}

.auth-country-code {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent, #34d399);
  user-select: none;
}

.auth-phone-input .auth-input {
  flex: 1;
  height: 100%;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
}

/* Code Input */
.auth-code-inputs {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 8px 0;
}

.auth-code-digit {
  width: 48px;
  height: 56px;
  text-align: center;
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary, #f1f5f9);
  background: var(--input-bg, #0b1220);
  border: 2px solid var(--input-border, rgba(148,163,184,0.15));
  border-radius: 12px;
  outline: none;
  transition: all 0.2s;
}

.auth-code-digit:focus {
  border-color: var(--accent, #34d399);
  box-shadow: 0 0 0 4px rgba(52,211,153,0.15);
  transform: scale(1.05);
}

.auth-code-digit.filled {
  border-color: var(--accent, #34d399);
  background: rgba(52,211,153,0.1);
}

/* Avatar Upload */
.auth-avatar-upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: 8px 0 16px;
}

.auth-avatar-preview {
  position: relative;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--input-bg, #0b1220);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  border: 3px dashed var(--input-border, rgba(148,163,184,0.3));
  transition: all 0.2s;
}

.auth-avatar-preview:hover {
  border-color: var(--accent, #34d399);
  background: rgba(52,211,153,0.05);
}

.auth-avatar-preview.has-image {
  border-style: solid;
  border-color: var(--accent, #34d399);
}

.auth-avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.auth-avatar-placeholder {
  font-size: 40px;
  opacity: 0.6;
}

.auth-avatar-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  transition: opacity 0.2s;
  font-size: 28px;
}

.auth-avatar-preview:hover .auth-avatar-overlay {
  opacity: 1;
}

.auth-avatar-preview.has-image .auth-avatar-overlay {
  opacity: 0;
}

.auth-avatar-preview.has-image:hover .auth-avatar-overlay {
  opacity: 1;
}

/* Tag Input */
.auth-tag-input {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 16px;
  background: var(--input-bg, #0b1220);
  border: 1px solid var(--input-border, rgba(148,163,184,0.15));
  border-radius: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.auth-tag-input:focus-within {
  border-color: var(--accent, #34d399);
  box-shadow: 0 0 0 3px rgba(52,211,153,0.15);
}

.auth-tag-prefix {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent, #34d399);
  user-select: none;
}

.auth-tag-input .auth-input {
  flex: 1;
  height: 100%;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
}

.auth-hint {
  font-size: 12px;
  color: var(--text-tertiary, #64748b);
  margin-top: 4px;
}

/* Buttons */
.auth-btn {
  height: 52px;
  padding: 0 24px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.auth-btn--primary {
  background: var(--accent, #34d399);
  color: #0b1220;
}

.auth-btn--primary:hover {
  background: #2bc88a;
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(52,211,153,0.3);
}

.auth-btn--primary:active {
  transform: translateY(0);
}

.auth-btn--secondary {
  background: transparent;
  color: var(--text-secondary, #94a3b8);
  border: 1px solid var(--input-border, rgba(148,163,184,0.2));
}

.auth-btn--secondary:hover {
  background: rgba(148,163,184,0.1);
  color: var(--text-primary, #f1f5f9);
}

.auth-link {
  font-size: 14px;
  color: var(--accent, #34d399);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.2s;
}

.auth-link:hover {
  opacity: 0.8;
  text-decoration: underline;
}

/* Resend timer */
.auth-resend {
  text-align: center;
  font-size: 14px;
  color: var(--text-tertiary, #64748b);
  min-height: 24px;
}

#auth-resend-btn[hidden] {
  display: none !important;
}

/* Light theme adjustments */
html[data-app-theme="light"] .auth-overlay {
  background: #f8fafc;
}

html[data-app-theme="light"] .auth-container {
  background: #fff;
  box-shadow: 0 25px 80px rgba(0,0,0,0.1), 0 0 0 1px rgba(0,0,0,0.05);
}

html[data-app-theme="light"] .auth-title,
html[data-app-theme="light"] .auth-step-title {
  color: #0f172a;
}

html[data-app-theme="light"] .auth-subtitle,
html[data-app-theme="light"] .auth-step-hint {
  color: #64748b;
}

html[data-app-theme="light"] .auth-spam-notice {
  color: #713f12;
  background: rgba(251, 191, 36, 0.16);
  border-color: rgba(180, 83, 9, 0.28);
}

html[data-app-theme="light"] .auth-input,
html[data-app-theme="light"] .auth-phone-input,
html[data-app-theme="light"] .auth-tag-input {
  background: #f1f5f9;
  border-color: #e2e8f0;
  color: #0f172a;
}

html[data-app-theme="light"] .auth-input::placeholder {
  color: #94a3b8;
}

html[data-app-theme="light"] .auth-code-digit {
  background: #f1f5f9;
  border-color: #e2e8f0;
  color: #0f172a;
}

html[data-app-theme="light"] .auth-avatar-preview {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

html[data-app-theme="light"] .auth-label {
  color: #64748b;
}

html[data-app-theme="light"] .auth-hint {
  color: #94a3b8;
}

html[data-app-theme="light"] .auth-btn--secondary {
  border-color: #e2e8f0;
  color: #64748b;
}

html[data-app-theme="light"] .auth-resend {
  color: #94a3b8;
}

/* Mobile adjustments */
@media (max-width: 480px) {
  .auth-container {
    width: 100%;
    height: 100%;
    border-radius: 0;
    padding: 32px 24px;
  }
  
  .auth-code-digit {
    width: 44px;
    height: 52px;
    font-size: 22px;
  }
  
  .auth-code-inputs {
    gap: 8px;
  }
}
/**
 * Noda — основной UI мессенджера (сетка, сайдбар, диалог, композер).
 * Восстановлено: ранее эти правила были в styles.css до добавления блока регистрации.
 */

:root {
  --bg-app: #0b1220;
  --panel-bg: #121a2a;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-tertiary: #64748b;
  --accent: #34d399;
  --border-subtle: rgba(148, 163, 184, 0.12);
  --sidebar-w: min(360px, 100%);
  --header-h: 56px;
  --composer-h: auto;
  /* Оценка высоты композера: max-height модалки как у ленты сообщений в диалоге */
  --profile-modal-composer-est: 72px;
  --profile-modal-backdrop-pad: 40px;
  /* Список чатов в сайдбаре — как Telegram: имя / превью / время */
  --chat-title-font-size: 0.9375rem;
  --chat-title-font-weight: 600;
  --chat-preview-font-size: 0.8125rem;
  --chat-preview-color: #b19aa7;
  --chat-time-font-size: 0.75rem;
  --chat-time-color: #707579;
  --sidebar-icon-toner: rgba(0, 0, 0, 0.62);
  /* Пузыри: ориентир — Telegram dark (входящие серо-синие, исходящие зеленоватые) */
  --msg-in-bg: #2b333e;
  --msg-out-bg: #3d8f6a;
  --msg-fg: #f1f5f9;
  --msg-time-fg: rgba(148, 163, 184, 0.72);
  /* Галочки доставки: 1✓ и 2✓ — бледно-серый; прочитано — Tiffany (градиент) */
  --msg-receipt-muted: #d8e4ef;
  --msg-receipt-read-a: #9ef0e8;
  --msg-receipt-read-b: #40d9ce;
  --msg-receipt-read-c: #1db5a6;
  /* Тема чата (chatTheme.js → documentElement); до init — как статическая палитра */
  --app-gradient: linear-gradient(
    165deg,
    hsl(215, 12%, 9%) 0%,
    hsl(220, 10%, 8%) 50%,
    hsl(212, 11%, 9%) 100%
  );
  --theme-sidebar-bg: var(--panel-bg);
  --theme-dialog-bg: var(--bg-app);
  --theme-feed-bg: var(--bg-app);
  --theme-search-bg: rgba(11, 18, 32, 0.6);
  --theme-composer-bg: var(--panel-bg);
  --theme-bubble-in: var(--msg-in-bg);
  --theme-bubble-out: var(--msg-out-bg);
  --theme-border-sidebar: var(--border-subtle);
  --theme-border-subtle: rgba(148, 163, 184, 0.12);
  --theme-accent-dot: var(--accent);
  /*
   * iOS-like «стекло»: полупрозрачная заливка + blur на хроме UI.
   * Цвета тянутся из --theme-* (в т.ч. пресеты чата на <html>).
   */
  --ui-glass-blur: 24px;
  --ui-glass-saturate: 185%;
  --ui-glass-sidebar-fill: color-mix(
    in srgb,
    var(--theme-sidebar-bg, var(--panel-bg)) 64%,
    transparent
  );
  --ui-glass-composer-fill: color-mix(
    in srgb,
    var(--theme-composer-bg, var(--panel-bg)) 62%,
    transparent
  );
  --ui-glass-header-fill: color-mix(
    in srgb,
    var(--theme-dialog-bg, var(--panel-bg)) 57%,
    transparent
  );
  --ui-glass-stroke-outer: rgba(255, 255, 255, 0.13);
  --ui-glass-stroke-inner: rgba(255, 255, 255, 0.09);
  --ui-glass-highlight-top: rgba(255, 255, 255, 0.16);
  --ui-glass-shadow-elevated: 0 10px 40px rgba(0, 0, 0, 0.28);
  --ui-glass-control-bg: color-mix(
    in srgb,
    var(--panel-bg) 38%,
    rgba(255, 255, 255, 0.06)
  );
  --ui-bubble-fill-in: color-mix(
    in srgb,
    var(--theme-bubble-in, var(--msg-in-bg)) 81%,
    transparent
  );
  --ui-bubble-fill-out: color-mix(
    in srgb,
    var(--theme-bubble-out, var(--msg-out-bg)) 81%,
    transparent
  );
  --ui-bubble-blur: 20px;
}

html[data-app-theme="light"] {
  --bg-app: #f1f5f9;
  --panel-bg: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-tertiary: #94a3b8;
  --accent: #169c72;
  --border-subtle: rgba(15, 23, 42, 0.08);
  --msg-in-bg: #e8edf2;
  --msg-out-bg: #b8e0c8;
  --msg-fg: #0f172a;
  --msg-time-fg: rgba(71, 85, 105, 0.65);
  /* Те же роли, но контрастнее на светлом пузыре */
  --msg-receipt-muted: #5a6b7c;
  --msg-receipt-read-a: #5eead4;
  --msg-receipt-read-b: #14b8a6;
  --msg-receipt-read-c: #0d9488;
  --chat-preview-color: #9b6d86;
  --chat-time-color: #8e9398;
  --sidebar-icon-toner: rgba(255, 255, 255, 0.9);
  --app-gradient: linear-gradient(
    165deg,
    hsl(220, 14%, 97%) 0%,
    hsl(220, 10%, 98.5%) 50%,
    hsl(220, 12%, 97%) 100%
  );
  --theme-sidebar-bg: #ffffff;
  --theme-dialog-bg: #f1f5f9;
  --theme-feed-bg: #f8fafc;
  --theme-search-bg: #f1f5f9;
  --theme-composer-bg: #ffffff;
  --theme-bubble-in: var(--msg-in-bg);
  --theme-bubble-out: var(--msg-out-bg);
  --theme-border-sidebar: rgba(15, 23, 42, 0.1);
  --theme-border-subtle: rgba(15, 23, 42, 0.08);
  --ui-glass-sidebar-fill: color-mix(
    in srgb,
    var(--theme-sidebar-bg, #ffffff) 79%,
    transparent
  );
  --ui-glass-composer-fill: color-mix(
    in srgb,
    var(--theme-composer-bg, #ffffff) 77%,
    transparent
  );
  --ui-glass-header-fill: color-mix(
    in srgb,
    var(--theme-dialog-bg, #f1f5f9) 75%,
    transparent
  );
  --ui-glass-stroke-outer: rgba(255, 255, 255, 0.72);
  --ui-glass-stroke-inner: rgba(15, 23, 42, 0.06);
  --ui-glass-highlight-top: rgba(255, 255, 255, 0.92);
  --ui-glass-shadow-elevated: 0 12px 40px rgba(15, 23, 42, 0.1);
  --ui-glass-control-bg: color-mix(
    in srgb,
    #ffffff 64%,
    rgba(255, 255, 255, 0.5)
  );
  --ui-glass-blur: 29px;
  --ui-glass-saturate: 178%;
}

/*
 * Смена app theme: View Transitions (Chrome / Edge / Safari 18+).
 * Длительность согласована с themeTransition.js (fallback-оверлей ~0.26s фаза).
 */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.45s;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

::view-transition-group(root) {
  animation-duration: 0.45s;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

/* Fallback, когда document.startViewTransition нет — см. themeTransition.js */
.nodum-theme-flash-overlay {
  position: fixed;
  inset: 0;
  z-index: 200000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.nodum-theme-flash-overlay--peak {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root),
  ::view-transition-group(root) {
    animation-duration: 0.01ms !important;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  height: -webkit-fill-available;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  box-sizing: border-box;
  /* iOS Safari: не раздувать шрифт на узком экране (ломает переносы и ширину). */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html *,
html *::before,
html *::after {
  box-sizing: inherit;
}

html,
body {
  margin: 0;
  height: 100%;
}

@media (max-width: 904px) {
  html {
    overflow: hidden;
    overflow-x: clip;
    width: 100%;
    max-width: 100%;
    overscroll-behavior: none;
  }
}

body.nodum-app {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--app-gradient, var(--bg-app));
  color: var(--text-primary);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overflow-x: clip;
  overscroll-behavior: none;
  min-height: 100%;
  max-height: 100%;
  width: 100%;
  max-width: 100%;
  position: relative;
}

@media (prefers-reduced-motion: no-preference) {
  html.nodum-theme-ready body.nodum-app {
    transition: color 0.42s cubic-bezier(0.22, 1, 0.36, 1);
  }
}

#root {
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  max-height: 100vh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overflow-x: clip;
  background: transparent;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

html.vv-polyfill.vv-pinned body.nodum-app {
  min-height: var(--app-vvh, 100%);
  max-height: var(--app-vvh, 100%);
}

html.vv-polyfill.vv-pinned #root {
  height: var(--app-vvh, 100dvh);
  min-height: var(--app-vvh, 100dvh);
  max-height: var(--app-vvh, 100dvh);
}

/*
 * iOS Safari / PWA «на экран домой»: при фокусе в поле ввода visualViewport смещается
 * (offsetTop) и сужается (height). Привязываем #root к видимому прямоугольнику — иначе
 * системная панель над клавиатурой наезжает на композер.
 */
/* Порог 904/905px — см. apps/web/src/layoutBreakpoint.ts */
@media (max-width: 904px) {
  /*
   * Раньше max-height: none на body давал рост документа выше видимой области — при клавиатуре
   * скроллился весь экран. Держим body в рамках visualViewport / 100dvh.
   */
  body.nodum-app {
    overflow: hidden;
    overscroll-behavior: none;
    max-height: 100dvh;
    max-height: 100svh;
  }

  html.vv-polyfill.vv-pinned body.nodum-app {
    min-height: var(--app-vvh, 100dvh);
    max-height: var(--app-vvh, 100dvh);
    height: var(--app-vvh, 100dvh);
  }

  /*
   * Не используем visualViewport.offsetLeft для позиции: на iOS при скролле/клавиатуре
   * он даёт ненулевой left → весь UI съезжает вправо и появляется «белая полоса» / обрез.
   * Только вертикаль: top + height по --app-vvh.
   */
  html.vv-polyfill.vv-pinned #root {
    position: fixed;
    top: var(--vv-offset-top, 0px);
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    z-index: 0;
    overflow-x: clip;
  }
}

/* --- Оболочка: баннер + main в одной колонке на всю высоту --- */
.app-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  overflow-x: hidden;
  background: transparent;
}

.sync-error-banner {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(251, 191, 36, 0.12);
  color: var(--text-primary);
  font-size: 0.875rem;
}

html[data-app-theme="light"] .sync-error-banner {
  background: rgba(245, 158, 11, 0.16);
}

.sync-error-banner__text {
  min-width: 0;
}

.sync-error-banner__retry {
  flex-shrink: 0;
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-primary);
  padding: 6px 12px;
  font-size: 0.8125rem;
}

.sync-error-banner__retry:hover {
  background: rgba(148, 163, 184, 0.2);
}

/* --- Сетка: мобильный 1 колонка; десктоп — сайдбар | ресайзер | диалог --- */
.layout {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  flex: 1;
  min-height: 0;
  min-width: 0;
  height: 100%;
  max-height: 100%;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  overflow-x: hidden;
  background: transparent;
}

@media (min-width: 905px) {
  .layout {
    grid-template-columns: var(--sidebar-w) 6px minmax(0, 1fr);
  }

  /* iOS Safari: шрифт <16px в input/contenteditable вызывает автозум «к центру». */
  .composer-input,
  .search,
  .search.search--infield {
    font-size: 16px;
  }

  /* Узкий левый rail (как в Telegram): иконки разделов; на ПК при наведении расширяется с подписями */
  .layout--with-rail {
    --rail-w: 56px;
    grid-template-columns: var(--rail-w) var(--sidebar-w) 6px minmax(0, 1fr);
    transition: grid-template-columns 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  }

  .layout--with-rail:has(.app-rail:hover),
  .layout--with-rail:has(.app-rail:focus-within) {
    --rail-w: min(220px, 26vw);
  }
}

/* --- Левое боковое меню (разделы) --- */
.app-rail {
  display: none;
}

@media (min-width: 905px) {
  .app-rail {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 12px 8px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    flex-shrink: 0;
    min-height: 0;
    overflow: hidden;
    background: color-mix(
      in srgb,
      var(--theme-sidebar-bg, var(--panel-bg)) 53%,
      transparent
    );
    -webkit-backdrop-filter: blur(var(--ui-glass-blur, 24px))
      saturate(var(--ui-glass-saturate, 185%));
    backdrop-filter: blur(var(--ui-glass-blur, 24px)) saturate(var(--ui-glass-saturate, 185%));
    border-right: 1px solid var(--ui-glass-stroke-inner, var(--theme-border-sidebar, var(--border-subtle)));
    box-shadow: inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.12));
  }

  /* Развёрнутый rail: подписи категорий (hover или фокус с клавиатуры) */
  .layout--with-rail:has(.app-rail:hover) .app-rail__btn,
  .layout--with-rail:has(.app-rail:focus-within) .app-rail__btn {
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    padding: 10px 12px;
  }

  .layout--with-rail:has(.app-rail:hover) .app-rail__label,
  .layout--with-rail:has(.app-rail:focus-within) .app-rail__label {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    padding: 0;
    overflow: visible;
    clip: auto;
    white-space: nowrap;
    border: 0;
    font-size: 0.8125rem;
    font-weight: 650;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    flex: 1;
    min-width: 0;
    text-align: left;
  }

  .layout--with-rail:has(.app-rail:hover) .app-rail__icon-wrap,
  .layout--with-rail:has(.app-rail:focus-within) .app-rail__icon-wrap {
    flex-shrink: 0;
  }

  /* В свернутом desktop-rail кнопки должны быть ровно квадратными. */
  .layout--with-rail:not(:has(.app-rail:hover)):not(:has(.app-rail:focus-within)) .app-rail__btn {
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: 12px;
    align-self: center;
  }
}

@media (min-width: 905px) and (prefers-reduced-motion: reduce) {
  .layout--with-rail {
    transition: none;
  }
}

.app-rail__btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  min-height: 48px;
  padding: 8px 4px;
  border: none;
  border-radius: 14px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font: inherit;
  transition:
    background 0.15s,
    color 0.15s,
    box-shadow 0.15s,
    -webkit-backdrop-filter 0.15s,
    backdrop-filter 0.15s;
}

.app-rail__btn:hover {
  background: var(--ui-glass-control-bg, rgba(148, 163, 184, 0.1));
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  backdrop-filter: blur(10px) saturate(140%);
  color: var(--text-primary);
  box-shadow: inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.12));
}

.app-rail__btn--active {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  -webkit-backdrop-filter: blur(12px) saturate(160%);
  backdrop-filter: blur(12px) saturate(160%);
  color: var(--accent);
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent),
    inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.12));
}

.app-rail__btn--install {
  margin-top: auto;
  background: rgba(52, 211, 153, 0.1);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(52, 211, 153, 0.2);
}

.app-rail__btn--install:hover {
  background: rgba(52, 211, 153, 0.18);
}

.app-rail__icon-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--sidebar-icon-toner);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.app-rail__icon-media {
  width: 20px;
  height: 20px;
  object-fit: contain;
}

.app-rail__badge {
  position: absolute;
  top: -4px;
  right: -8px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  box-sizing: border-box;
  border-radius: 999px;
  background: var(--accent, #34d399);
  color: #042018;
  font-size: 0.625rem;
  font-weight: 800;
  line-height: 16px;
  text-align: center;
  letter-spacing: -0.02em;
  box-shadow: 0 0 0 2px var(--theme-sidebar-bg, var(--panel-bg));
}

.app-rail__icon {
  font-size: 1.35rem;
  line-height: 1;
}

.app-rail__label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Мобильный доступ к разделам rail (узкий экран): кнопка в шапке сайдбара */
.sidebar-head-leading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.sidebar-head-leading .brand-lockup {
  min-width: 0;
  flex: 1 1 0;
  overflow: hidden;
}

.btn-mobile-rail {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--ui-glass-stroke-inner, transparent);
  background: var(--ui-glass-control-bg, rgba(148, 163, 184, 0.1));
  -webkit-backdrop-filter: blur(12px) saturate(150%);
  backdrop-filter: blur(12px) saturate(150%);
  color: var(--text-primary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.1));
  transition:
    background 0.15s ease,
    color 0.15s ease,
    border-color 0.15s ease;
}

.btn-mobile-rail:hover {
  background: color-mix(in srgb, var(--ui-glass-control-bg, rgba(148, 163, 184, 0.14)) 100%, transparent);
  border-color: var(--ui-glass-stroke-inner, rgba(148, 163, 184, 0.2));
}

.btn-mobile-rail:focus-visible {
  outline: 2px solid var(--accent, #34d399);
  outline-offset: 2px;
}

.btn-mobile-rail__icon {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
  box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor;
}

/* Выезжающая панель разделов (аналог левого rail) */
.mobile-rail-dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  overflow: hidden;
}

.mobile-rail-dialog::backdrop {
  transition: opacity 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.mobile-rail-dialog::backdrop {
  background: rgba(4, 8, 18, 0.52);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
}

html[data-app-theme="light"] .mobile-rail-dialog::backdrop {
  background: rgba(15, 23, 42, 0.35);
}

.mobile-rail-dialog__panel {
  box-sizing: border-box;
  width: min(320px, calc(100% - 40px));
  height: 100%;
  max-height: 100dvh;
  margin: 0 auto 0 0;
  padding: max(12px, env(safe-area-inset-top, 0px)) max(14px, env(safe-area-inset-right, 0px))
    max(12px, env(safe-area-inset-bottom, 0px)) max(14px, env(safe-area-inset-left, 0px));
  background: var(--ui-glass-sidebar-fill, var(--theme-sidebar-bg, var(--panel-bg)));
  -webkit-backdrop-filter: blur(var(--ui-glass-blur, 22px))
    saturate(var(--ui-glass-saturate, 168%));
  backdrop-filter: blur(var(--ui-glass-blur, 22px)) saturate(var(--ui-glass-saturate, 168%));
  border-right: 1px solid var(--ui-glass-stroke-inner, var(--theme-border-sidebar, var(--border-subtle)));
  border-radius: 0 22px 22px 0;
  box-shadow:
    12px 0 48px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.12));
  display: flex;
  flex-direction: column;
  min-height: 0;
  transform: translate3d(-30px, 0, 0) scale(0.986);
  transform-origin: left center;
  opacity: 0;
  transition:
    transform 0.46s cubic-bezier(0.16, 0.84, 0.18, 1),
    opacity 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: transform, opacity;
  backface-visibility: hidden;
}

.mobile-rail-dialog.mobile-rail-dialog--open {
}

.mobile-rail-dialog.mobile-rail-dialog--open::backdrop {
  opacity: 1;
}

.mobile-rail-dialog.mobile-rail-dialog--open .mobile-rail-dialog__panel {
  transform: translate3d(0, 0, 0) scale(1);
  opacity: 1;
}

.mobile-rail-dialog.mobile-rail-dialog--closing::backdrop {
  opacity: 0;
  transition: opacity 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-rail-dialog.mobile-rail-dialog--closing .mobile-rail-dialog__panel {
  transform: translate3d(-30px, 0, 0) scale(0.986);
  opacity: 0;
  transition:
    transform 0.22s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.16s ease-out;
}

.mobile-rail-dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.mobile-rail-dialog__title {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.mobile-rail-dialog__close {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: rgba(148, 163, 184, 0.1);
  color: var(--text-secondary);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.mobile-rail-dialog__close:hover {
  color: var(--text-primary);
  background: rgba(148, 163, 184, 0.16);
}

.mobile-rail-dialog__nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  min-height: 0;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.mobile-rail-dialog__item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 12px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
  transition:
    background 0.12s ease,
    color 0.12s ease;
}

.mobile-rail-dialog__item:hover {
  background: rgba(148, 163, 184, 0.1);
}

.mobile-rail-dialog__item--active {
  background: rgba(52, 211, 153, 0.14);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(52, 211, 153, 0.25);
}

.mobile-rail-dialog__item--install {
  margin-top: 6px;
  background: rgba(52, 211, 153, 0.1);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(52, 211, 153, 0.2);
}

.mobile-rail-dialog__item--extension {
  margin-top: 6px;
  background: rgba(52, 211, 153, 0.1);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(52, 211, 153, 0.2);
}

.mobile-rail-dialog__item--extension:hover {
  background: rgba(52, 211, 153, 0.18);
}

.mobile-rail-dialog__item--install:hover {
  background: rgba(52, 211, 153, 0.18);
}

.mobile-rail-dialog__item--disabled,
.mobile-rail-dialog__item--disabled:hover {
  background: rgba(100, 116, 139, 0.18);
  color: rgba(148, 163, 184, 0.9);
  box-shadow: inset 0 0 0 1px rgba(100, 116, 139, 0.28);
  cursor: not-allowed;
  filter: saturate(0.35);
}

.mobile-rail-dialog__item-icon {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--sidebar-icon-toner);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.mobile-rail-dialog__item-icon-media {
  width: 20px;
  height: 20px;
  object-fit: contain;
}

.mobile-rail-dialog__item-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.mobile-rail-dialog__item-label {
  font-size: 0.9375rem;
  font-weight: 600;
}

.mobile-rail-dialog__item-hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.3;
}

.mobile-rail-dialog__item--active .mobile-rail-dialog__item-hint {
  color: color-mix(in srgb, var(--accent) 75%, var(--text-secondary));
}

.mobile-rail-dialog__badge {
  flex-shrink: 0;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  box-sizing: border-box;
  border-radius: 999px;
  background: var(--accent, #34d399);
  color: #042018;
  font-size: 0.6875rem;
  font-weight: 800;
  line-height: 22px;
  text-align: center;
  letter-spacing: -0.02em;
}

/*
 * PWA / «Добавить на экран домой» (display-mode: standalone): дублируем те же кривые и длительности,
 * чуть усиливаем плавность — в WebKit standalone переходы иногда выглядят суше, чем во вкладке Safari.
 */
html.nodum-standalone .mobile-rail-dialog::backdrop {
  transition: opacity 0.36s cubic-bezier(0.2, 0.8, 0.2, 1);
}

html.nodum-standalone .mobile-rail-dialog__panel {
  transition:
    transform 0.5s cubic-bezier(0.16, 0.84, 0.18, 1),
    opacity 0.42s cubic-bezier(0.2, 0.8, 0.2, 1);
}

html.nodum-standalone .mobile-rail-dialog.mobile-rail-dialog--closing::backdrop {
  opacity: 0;
  transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html.nodum-standalone .mobile-rail-dialog.mobile-rail-dialog--closing .mobile-rail-dialog__panel {
  transform: translate3d(-30px, 0, 0) scale(0.986);
  opacity: 0;
  transition:
    transform 0.24s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.18s ease-out;
}

/* Firefox (в т.ч. установленный ярлык/SWA): меньше blur, больше стабильности анимации. */
@supports (-moz-appearance: none) {
  .mobile-rail-dialog__panel {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    transition:
      transform 0.52s cubic-bezier(0.16, 0.84, 0.18, 1),
      opacity 0.44s cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  .mobile-rail-dialog.mobile-rail-dialog--closing .mobile-rail-dialog__panel {
    transition:
      transform 0.24s cubic-bezier(0.4, 0, 0.2, 1),
      opacity 0.16s ease-out;
  }
}

@media (max-width: 904px) {
  html.nodum-standalone .layout > .dialog {
    transition: transform 380ms cubic-bezier(0.32, 0.72, 0, 1);
  }

  html.nodum-standalone .layout[data-view="dialog"] .dialog-header {
    transition: padding-top 0.34s cubic-bezier(0.32, 0.72, 0, 1);
  }

  html.nodum-standalone .composer {
    transition: padding-bottom 0.34s cubic-bezier(0.32, 0.72, 0, 1);
  }
}

@media (max-width: 904px) and (prefers-reduced-motion: reduce) {
  html.nodum-standalone .layout > .dialog {
    transition: none !important;
  }

  html.nodum-standalone .layout[data-view="dialog"] .dialog-header {
    transition: none !important;
  }

  html.nodum-standalone .composer {
    transition: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  html.nodum-standalone .mobile-rail-dialog::backdrop,
  html.nodum-standalone .mobile-rail-dialog__panel,
  html.nodum-standalone .mobile-rail-dialog.mobile-rail-dialog--closing::backdrop,
  html.nodum-standalone .mobile-rail-dialog.mobile-rail-dialog--closing .mobile-rail-dialog__panel {
    transition: none !important;
  }
}

/* Полоса папок под поиском */
.folder-rail-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 12px 4px;
  border-bottom: 1px solid var(--theme-border-sidebar, var(--border-subtle));
  flex-shrink: 0;
}

.folder-rail-bar__chip {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(148, 163, 184, 0.08);
  color: var(--text-secondary);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-rail-bar__chip:hover {
  color: var(--text-primary);
  background: rgba(148, 163, 184, 0.14);
}

.folder-rail-bar__chip--active {
  border-color: rgba(52, 211, 153, 0.45);
  color: var(--accent);
  background: rgba(52, 211, 153, 0.1);
}

.folder-rail-bar__add {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px dashed var(--border-subtle);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

.folder-rail-bar__add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.rail-list-empty {
  padding: 24px 16px;
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

/* Контекстное меню чата (ПКМ / долгое нажатие) */
.chat-context-menu {
  min-width: min(268px, calc(100vw - 24px));
  max-width: min(92vw, 320px);
  padding: 6px 0;
  border-radius: 12px;
  background: rgba(30, 27, 24, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.35),
    0 20px 50px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

html[data-app-theme="light"] .chat-context-menu {
  background: rgba(255, 255, 255, 0.98);
  border-color: rgba(15, 23, 42, 0.1);
  box-shadow:
    0 0 0 1px rgba(15, 23, 42, 0.06),
    0 16px 40px rgba(15, 23, 42, 0.14);
}

/* Без dvi (старый WebView / часть Samsung Internet) остаётся vw выше. */
@supports (width: 1dvi) {
  .chat-context-menu {
    min-width: min(268px, calc(100dvi - 24px));
    max-width: min(92dvi, 320px);
  }
}

.chat-context-menu__item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 10px 12px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.875rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}

html[data-app-theme="light"] .chat-context-menu__item {
  color: var(--text-primary);
}

.chat-context-menu__item:hover,
.chat-context-menu__item:focus-visible {
  background: rgba(255, 255, 255, 0.06);
  outline: none;
}

html[data-app-theme="light"] .chat-context-menu__item:hover,
html[data-app-theme="light"] .chat-context-menu__item:focus-visible {
  background: rgba(15, 23, 42, 0.06);
}

.chat-context-menu__item--danger {
  color: #f87171;
}

html[data-app-theme="light"] .chat-context-menu__item--danger {
  color: #dc2626;
}

.chat-context-menu__item--danger:hover,
.chat-context-menu__item--danger:focus-visible {
  background: rgba(248, 113, 113, 0.12);
}

.chat-context-menu__icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.75);
}

html[data-app-theme="light"] .chat-context-menu__icon {
  color: var(--text-secondary);
}

.chat-context-menu__item--danger .chat-context-menu__icon {
  color: inherit;
}

.chat-context-menu__grow {
  flex: 1;
  min-width: 0;
}

.chat-context-menu__chevron {
  flex-shrink: 0;
  opacity: 0.55;
  display: flex;
}

.chat-context-menu__sep {
  height: 1px;
  margin: 4px 12px;
  background: rgba(255, 255, 255, 0.08);
}

html[data-app-theme="light"] .chat-context-menu__sep {
  background: rgba(15, 23, 42, 0.08);
}

.chat-context-menu__folder-block {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  margin: 4px 0;
  padding: 2px 0;
}

html[data-app-theme="light"] .chat-context-menu__folder-block {
  border-color: rgba(15, 23, 42, 0.06);
}

.chat-context-menu__item--folder-trigger.chat-context-menu__item--open {
  background: rgba(255, 255, 255, 0.05);
}

.chat-context-menu__sublist {
  padding: 2px 0 6px;
  max-height: 200px;
  overflow-y: auto;
}

.chat-context-menu__subitem {
  display: block;
  width: calc(100% - 16px);
  margin: 0 8px;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.8125rem;
  text-align: left;
  cursor: pointer;
}

html[data-app-theme="light"] .chat-context-menu__subitem {
  color: var(--text-primary);
}

.chat-context-menu__subitem:hover,
.chat-context-menu__subitem:focus-visible {
  background: rgba(52, 211, 153, 0.12);
  outline: none;
}

.chat-context-menu__subitem--active {
  color: var(--accent, #34d399);
  font-weight: 600;
}

.chat-context-menu__subitem--accent {
  color: var(--accent, #34d399);
  font-weight: 500;
}

/* --- Sidebar --- */
.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--ui-glass-stroke-inner, var(--theme-border-sidebar, var(--border-subtle)));
  background: var(--ui-glass-sidebar-fill, var(--theme-sidebar-bg, var(--panel-bg)));
  -webkit-backdrop-filter: blur(var(--ui-glass-blur, 22px))
    saturate(var(--ui-glass-saturate, 168%));
  backdrop-filter: blur(var(--ui-glass-blur, 22px)) saturate(var(--ui-glass-saturate, 168%));
  box-shadow: inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.12));
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  min-width: 0;
}

/* Шапка и поиск не сжимаются при открытой клавиатуре — иначе поля контактов «уезжают». */
.sidebar > .sidebar-head,
.sidebar > .search-wrap {
  flex-shrink: 0;
}

.chat-list {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  overscroll-behavior-x: none;
  touch-action: pan-y;
}

.chat-list[class*="chat-list--nav-"] {
  pointer-events: none;
}

.chat-list--nav-out-left > :not(.chat-list-ptr-track) {
  animation: chatListSlideOutLeft 600ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.chat-list--nav-in-left > :not(.chat-list-ptr-track) {
  animation: chatListSlideInLeft 600ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.chat-list--nav-out-right > :not(.chat-list-ptr-track) {
  animation: chatListSlideOutRight 600ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.chat-list--nav-in-right > :not(.chat-list-ptr-track) {
  animation: chatListSlideInRight 600ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes chatListSlideOutLeft {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0.44;
    transform: translateX(-34%);
  }
}

@keyframes chatListSlideInLeft {
  from {
    opacity: 0.42;
    transform: translateX(34%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes chatListSlideOutRight {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0.44;
    transform: translateX(34%);
  }
}

@keyframes chatListSlideInRight {
  from {
    opacity: 0.42;
    transform: translateX(-34%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-list--nav-out-left > :not(.chat-list-ptr-track),
  .chat-list--nav-in-left > :not(.chat-list-ptr-track),
  .chat-list--nav-out-right > :not(.chat-list-ptr-track),
  .chat-list--nav-in-right > :not(.chat-list-ptr-track) {
    animation-duration: 1ms !important;
  }
}

/* Pull-to-refresh: индикатор над списком чатов (моб.) */
.chat-list-ptr-track {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  pointer-events: none;
  transition: height 0.15s ease-out;
}

.chat-list-ptr-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--text-secondary) 45%, transparent);
  transform: scale(0.85);
  transition:
    transform 0.12s ease,
    background 0.12s ease;
}

.chat-list-ptr-dot--armed {
  transform: scale(1.15);
  background: var(--accent, #34d399);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #34d399) 25%, transparent);
  animation: chatListPtrPulse 0.85s ease-in-out infinite;
}

@keyframes chatListPtrPulse {
  50% {
    opacity: 0.65;
  }
}

.friend-incoming-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 14px 14px;
  border-bottom: 1px solid var(--theme-border-subtle, var(--border-subtle));
  background: rgba(52, 211, 153, 0.06);
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
}

.contacts-block {
  padding: 12px 14px;
  border-bottom: 1px solid var(--theme-border-subtle, var(--border-subtle));
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-margin-block: 24px;
}

.contacts-block__head {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.contacts-block__pick-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: stretch;
}

.contacts-block__pick {
  min-width: 0;
  height: 36px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 58%, transparent);
  background: color-mix(in srgb, var(--accent) 26%, transparent);
  color: var(--accent);
  padding: 0 10px;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 0.12s ease-out,
    background 0.12s ease-out,
    border-color 0.12s ease-out,
    box-shadow 0.12s ease-out;
  box-shadow: inset 0 1px 0 color-mix(in srgb, #fff 8%, transparent);
}

.contacts-block__pick:active:not(:disabled) {
  transform: scale(0.97);
  border-color: color-mix(in srgb, var(--accent) 42%, transparent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  box-shadow: none;
}

.contacts-block__pick--exit-right {
  animation: contactsPickExitRight 0.39s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  pointer-events: none;
}

.contacts-block__pick--exit-left {
  animation: contactsPickExitLeft 0.39s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  pointer-events: none;
}

@keyframes contactsPickExitRight {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(calc(100% + 12px));
    opacity: 0;
  }
}

@keyframes contactsPickExitLeft {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(calc(-100% - 12px));
    opacity: 0;
  }
}

.contacts-block__form {
  gap: 8px;
  align-items: stretch;
}

.contacts-block__form--find {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
}

.contacts-block__form--add {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
}

.contacts-block__input {
  min-width: 0;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--theme-border-subtle, var(--border-subtle));
  background: rgba(148, 163, 184, 0.08);
  color: var(--text-primary);
  padding: 0 10px;
  font: inherit;
  font-size: 0.8125rem;
}

.contacts-block__form--find .contacts-block__input {
  animation: contactsRevealFromRight 0.52s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.contacts-block__form--find .contacts-block__input:nth-of-type(1) {
  animation-delay: 0.04s;
}

.contacts-block__form--find .contacts-block__input:nth-of-type(2) {
  animation-delay: 0.11s;
}

.contacts-block__form--find .contacts-block__cta {
  animation: contactsRevealFromRight 0.48s cubic-bezier(0.22, 1, 0.36, 1) backwards;
  animation-delay: 0.02s;
}

.contacts-block__form--add .contacts-block__input {
  animation: contactsRevealFromLeft 0.52s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.contacts-block__form--add .contacts-block__input:nth-of-type(1) {
  animation-delay: 0.04s;
}

.contacts-block__form--add .contacts-block__input:nth-of-type(2) {
  animation-delay: 0.11s;
}

.contacts-block__form--add .contacts-block__cta {
  animation: contactsRevealFromLeft 0.48s cubic-bezier(0.22, 1, 0.36, 1) backwards;
  animation-delay: 0.06s;
}

@keyframes contactsRevealFromRight {
  from {
    opacity: 0;
    transform: translateX(22px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes contactsRevealFromLeft {
  from {
    opacity: 0;
    transform: translateX(-22px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.contacts-block__cta {
  height: 36px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 58%, transparent);
  background: color-mix(in srgb, var(--accent) 26%, transparent);
  color: var(--accent);
  padding: 0 12px;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 0.12s ease-out,
    background 0.12s ease-out,
    border-color 0.12s ease-out,
    box-shadow 0.12s ease-out,
    opacity 0.12s ease-out;
  box-shadow: inset 0 1px 0 color-mix(in srgb, #fff 8%, transparent);
}

.contacts-block__cta:active:not(:disabled) {
  transform: scale(0.97);
  border-color: color-mix(in srgb, var(--accent) 42%, transparent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  box-shadow: none;
}

.contacts-block__cta:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

@media (prefers-reduced-motion: reduce) {
  .contacts-block__pick--exit-right,
  .contacts-block__pick--exit-left {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }

  .contacts-block__form--find .contacts-block__input,
  .contacts-block__form--find .contacts-block__cta,
  .contacts-block__form--add .contacts-block__input,
  .contacts-block__form--add .contacts-block__cta {
    animation: none !important;
  }

  .contacts-block__pick:active:not(:disabled),
  .contacts-block__cta:active:not(:disabled) {
    transform: none;
  }
}

.contacts-block__group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.contacts-block__group-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.contacts-block__row {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  border: 1px solid var(--theme-border-subtle, var(--border-subtle));
  border-radius: 10px;
  background: rgba(148, 163, 184, 0.06);
  color: inherit;
  text-align: left;
  font: inherit;
  padding: 8px 10px;
  cursor: pointer;
}

.contacts-block__row--disabled {
  cursor: default;
  opacity: 0.55;
  background: rgba(15, 23, 42, 0.14);
}

.contacts-block__name {
  font-size: 0.825rem;
  font-weight: 600;
}

.contacts-block__meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.contacts-block__saved-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.contacts-block__saved-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.contacts-block__remove {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--theme-border-subtle, var(--border-subtle));
  background: rgba(248, 113, 113, 0.08);
  color: #fda4af;
  cursor: pointer;
}

.contacts-block__hint {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.friend-incoming-block__title {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent, #34d399);
  margin: 0 0 12px;
  text-align: center;
  width: 100%;
  max-width: 420px;
}

.friend-incoming-list {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 420px;
  min-width: 0;
}

.friend-incoming-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 12px 14px 14px;
  border-radius: 14px;
  border: 1px solid var(--theme-border-subtle, var(--border-subtle));
  background: rgba(15, 23, 42, 0.45);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0;
}

html[data-app-theme="light"] .friend-incoming-row {
  background: rgba(241, 245, 249, 0.9);
}

.friend-incoming-row__main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 0;
  width: 100%;
}

.friend-incoming-row__avatar {
  width: 40px;
  height: 40px;
  font-size: 1rem;
  flex-shrink: 0;
}

.friend-incoming-row__text {
  min-width: 0;
  flex: 1;
  text-align: center;
  max-width: 100%;
}

.friend-incoming-row__name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.friend-incoming-row__login {
  font-size: 0.8125rem;
  color: var(--accent, #34d399);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.friend-incoming-row__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  width: 100%;
}

.btn-friend-incoming {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  padding: 7px 14px;
  font-size: 0.8125rem;
  font-weight: 600;
  border: 1px solid transparent;
  transition:
    background 0.15s ease,
    opacity 0.15s ease;
  box-sizing: border-box;
  min-width: 0;
  flex: 0 1 auto;
}

.btn-friend-incoming:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-friend-incoming--accept {
  background: rgba(52, 211, 153, 0.18);
  border-color: rgba(52, 211, 153, 0.45);
  color: var(--accent, #34d399);
}

.btn-friend-incoming--accept:hover:not(:disabled) {
  background: rgba(52, 211, 153, 0.28);
}

.btn-friend-incoming--decline {
  background: transparent;
  border-color: var(--theme-border-subtle, var(--border-subtle));
  color: var(--text-secondary, #94a3b8);
}

.btn-friend-incoming--decline:hover:not(:disabled) {
  background: rgba(148, 163, 184, 0.1);
}

.friend-incoming-block--outgoing {
  background: rgba(251, 191, 36, 0.07);
  border-bottom-color: rgba(251, 191, 36, 0.12);
}

.friend-incoming-block__title--outgoing {
  color: #fbbf24;
}

.friend-incoming-row__hint {
  font-size: 0.75rem;
  color: var(--text-tertiary, #64748b);
  margin-top: 4px;
}

.friend-incoming-row__actions--single {
  justify-content: center;
}

.btn-friend-incoming--cancel {
  background: transparent;
  border-color: rgba(251, 191, 36, 0.45);
  color: #fbbf24;
  max-width: 100%;
}

.btn-friend-incoming--cancel:hover:not(:disabled) {
  background: rgba(251, 191, 36, 0.12);
}

html[data-app-theme="light"] .friend-incoming-block--outgoing {
  background: rgba(254, 243, 199, 0.45);
}

/* Вертикальный разделитель ширины списка чатов */
.layout-resizer {
  display: none;
  width: 6px;
  cursor: col-resize;
  touch-action: none;
  user-select: none;
  flex-shrink: 0;
  background: transparent;
  position: relative;
  align-self: stretch;
}

@media (min-width: 905px) {
  .layout-resizer {
    display: block;
  }
}

.layout-resizer::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--theme-border-sidebar, var(--border-subtle));
  opacity: 0.7;
  border-radius: 1px;
}

.layout-resizer:hover::after,
.layout-resizer:focus-visible::after {
  opacity: 1;
  background: var(--accent);
}

.sidebar-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 12px;
  row-gap: 8px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--ui-glass-stroke-inner, var(--border-subtle));
  min-width: 0;
  background: color-mix(
    in srgb,
    var(--theme-sidebar-bg, var(--panel-bg)) 22%,
    transparent
  );
  -webkit-backdrop-filter: blur(12px) saturate(150%);
  backdrop-filter: blur(12px) saturate(150%);
  box-shadow: inset 0 -1px 0 color-mix(in srgb, var(--ui-glass-stroke-inner) 55%, transparent);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 0;
}

.brand-lockup--home {
  border: none;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
  cursor: pointer;
}

.brand-lockup--home:focus-visible {
  outline: 2px solid var(--accent, #34d399);
  outline-offset: 2px;
  border-radius: 10px;
}

.logo-mark {
  flex-shrink: 0;
}

.logo-mark--asset {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.brand-wordmark-slot {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1 1 0;
}

/* Скрытый замер ширины подписи (тот же шрифт, что и у .brand-wordmark). */
.brand-wordmark--measure {
  position: absolute;
  left: 0;
  top: 0;
  visibility: hidden;
  pointer-events: none;
  white-space: nowrap;
  width: max-content;
  height: 0;
  overflow: hidden;
}

.brand-wordmark {
  font-weight: 700;
  font-size: 1.0625rem;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--text-primary);
  white-space: nowrap;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.wordmark {
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: -0.02em;
}

.tagline {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.sidebar-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex: 0 0 auto;
  justify-self: end;
  min-width: 0;
}

/* Ступени сжатия сайдбара (data-sidebar-tier на aside) */
.sidebar[data-sidebar-tier="1"] .btn-app-theme,
.sidebar[data-sidebar-tier="2"] .btn-app-theme,
.sidebar[data-sidebar-tier="3"] .btn-app-theme,
.sidebar[data-sidebar-tier="4"] .btn-app-theme {
  display: none;
}

.sidebar[data-sidebar-tier="2"] .brand-wordmark-slot,
.sidebar[data-sidebar-tier="3"] .brand-wordmark-slot,
.sidebar[data-sidebar-tier="4"] .brand-wordmark-slot {
  display: none;
}

/* Tier 3–4: колонка — лого, лупа, аватар входа; список — только аватары (класс .sidebar--icons-only) */
.sidebar[data-sidebar-tier="3"] .sidebar-head,
.sidebar[data-sidebar-tier="4"] .sidebar-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 10px 6px 12px;
}

.sidebar[data-sidebar-tier="3"] .sidebar-head-leading,
.sidebar[data-sidebar-tier="4"] .sidebar-head-leading {
  overflow: visible;
  max-width: 100%;
}

.sidebar[data-sidebar-tier="3"] .brand-lockup,
.sidebar[data-sidebar-tier="4"] .brand-lockup {
  width: 100%;
  justify-content: center;
  flex: none;
}

.sidebar[data-sidebar-tier="3"] .logo-mark,
.sidebar[data-sidebar-tier="4"] .logo-mark {
  display: block;
}

.sidebar[data-sidebar-tier="3"] .sidebar-head-actions,
.sidebar[data-sidebar-tier="4"] .sidebar-head-actions {
  width: 100%;
  justify-content: center;
}

/* Компактный аватар входа вместо длинной кнопки */
.btn-sidebar-user-avatar {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--theme-border-subtle, var(--border-subtle));
  background: rgba(148, 163, 184, 0.1);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
}

.btn-sidebar-user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.btn-sidebar-user-avatar--placeholder {
  color: var(--text-secondary);
}

/* Режим только аватаров в списке (tier ≥ 3, без обрезанного текста с «…») */
.sidebar.sidebar--icons-only .chat-item {
  justify-content: center;
  padding: 10px 8px;
  gap: 0;
}

.sidebar.sidebar--icons-only .chat-meta {
  display: none;
}

.sidebar.sidebar--icons-only .chat-item .avatar {
  margin: 0;
  width: 44px;
  height: 44px;
  font-size: 1.05rem;
}

.sidebar.sidebar--icons-only .chat-item.chat-item--unread .avatar::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent, #34d399);
  border: 2px solid var(--theme-sidebar-bg, var(--panel-bg));
  box-sizing: border-box;
}

.sidebar.sidebar--icons-only .chat-item.active {
  border-left-width: 2px;
}

/* Входящие заявки: как чаты — по центру колонки, в узком режиме без вылезания за край */
.sidebar.sidebar--icons-only .friend-incoming-block {
  padding: 8px 4px 10px;
  align-items: center;
}

.sidebar.sidebar--icons-only .friend-incoming-block__title {
  font-size: 0.5625rem;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
  padding: 0 4px;
  line-height: 1.25;
  max-width: 100%;
}

.sidebar.sidebar--icons-only .friend-incoming-list {
  max-width: 100%;
  gap: 8px;
}

.sidebar.sidebar--icons-only .friend-incoming-row {
  padding: 8px 4px 10px;
  gap: 8px;
  border-radius: 12px;
  border-left: none;
}

.sidebar.sidebar--icons-only .friend-incoming-row__main {
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}

.sidebar.sidebar--icons-only .friend-incoming-row__avatar {
  width: 44px;
  height: 44px;
  font-size: 1.05rem;
  margin: 0;
}

.sidebar.sidebar--icons-only .friend-incoming-row__text {
  width: 100%;
  max-width: 100%;
}

.sidebar.sidebar--icons-only .friend-incoming-row__name {
  font-size: 0.75rem;
}

.sidebar.sidebar--icons-only .friend-incoming-row__login {
  font-size: 0.6875rem;
}

.sidebar.sidebar--icons-only .friend-incoming-row__actions {
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 6px;
  max-width: 100%;
}

.sidebar.sidebar--icons-only .btn-friend-incoming {
  width: 100%;
  max-width: 100%;
  flex: none;
  padding: 6px 8px;
  font-size: 0.6875rem;
}

.btn-app-theme,
.btn-node {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: rgba(148, 163, 184, 0.08);
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: 0.875rem;
}

.btn-app-theme {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

@media (prefers-reduced-motion: no-preference) {
  html.nodum-theme-ready .btn-app-theme {
    transition:
      background-color 0.42s cubic-bezier(0.22, 1, 0.36, 1),
      border-color 0.42s cubic-bezier(0.22, 1, 0.36, 1),
      color 0.42s cubic-bezier(0.22, 1, 0.36, 1);
  }

  html.nodum-theme-ready .btn-app-theme__icon {
    display: inline-flex;
    transition:
      opacity 0.28s ease,
      transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  }

  html.nodum-theme-ready .btn-app-theme:active .btn-app-theme__icon {
    transform: scale(0.88);
    opacity: 0.75;
  }
}

.btn-node {
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Тег @login в шапке — как на старом скрине */
.btn-node--login {
  color: var(--accent);
  border-color: rgba(52, 211, 153, 0.28);
  background: rgba(52, 211, 153, 0.09);
  font-weight: 500;
  /* Долгое нажатие: не даём ОС выделять текст / показывать своё копирование */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.btn-node--login * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.btn-node--login::selection,
.btn-node--login *::selection {
  background: transparent;
}

.btn-node--login:hover {
  background: rgba(52, 211, 153, 0.16);
  border-color: rgba(52, 211, 153, 0.4);
}

/* Диалог установки приложения (iOS TestFlight + Android APK). */
.install-dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}

.install-dialog::backdrop {
  background: rgba(4, 8, 18, 0.58);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.install-dialog__panel {
  width: min(520px, calc(100% - 24px));
  margin: clamp(16px, 8vh, 72px) auto 0;
  border-radius: 16px;
  border: 1px solid var(--theme-border-subtle, var(--border-subtle));
  background: var(--panel-bg);
  box-shadow: 0 18px 56px rgba(0, 0, 0, 0.45);
  padding: 16px;
}

.install-dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.install-dialog__title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.install-dialog__close {
  width: 38px;
  height: 38px;
  border: 1px solid var(--theme-border-subtle, var(--border-subtle));
  border-radius: 10px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.install-dialog__subtitle {
  margin: 10px 0 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.install-dialog__actions {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.install-dialog__action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--theme-border-subtle, var(--border-subtle));
  background: rgba(148, 163, 184, 0.08);
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.875rem;
}

.install-dialog__action--primary {
  border-color: rgba(52, 211, 153, 0.45);
  color: var(--accent);
  background: rgba(52, 211, 153, 0.1);
}

.install-dialog__action--disabled {
  opacity: 0.45;
  pointer-events: none;
}

.install-dialog__hint {
  margin: 12px 0 0;
  color: var(--text-tertiary, #64748b);
  font-size: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  line-height: 1.35;
}

.install-dialog__hint code {
  border: 1px solid var(--theme-border-subtle, var(--border-subtle));
  border-radius: 6px;
  padding: 1px 6px;
  background: rgba(148, 163, 184, 0.08);
}

@media (max-width: 640px) {
  .install-dialog__actions {
    grid-template-columns: 1fr;
  }
}

.search-wrap {
  position: relative;
  padding: 12px 16px;
  min-width: 0;
}

/* Поле с лупой (та же иконка, что у кнопки в узком сайдбаре) */
.search-field {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 0 12px 0 14px;
  box-sizing: border-box;
  border-radius: 14px;
  border: 1px solid var(--ui-glass-stroke-inner, var(--theme-border-subtle, var(--border-subtle)));
  background: color-mix(
    in srgb,
    var(--theme-search-bg, rgba(11, 18, 32, 0.6)) 64%,
    transparent
  );
  -webkit-backdrop-filter: blur(14px) saturate(155%);
  backdrop-filter: blur(14px) saturate(155%);
  box-shadow: inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.1));
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

html[data-app-theme="light"] .search-field {
  background: color-mix(
    in srgb,
    var(--theme-search-bg, #f1f5f9) 72%,
    transparent
  );
}

.search-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.2);
}

.search-field__icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary, #64748b);
}

.search-field__icon svg {
  width: 20px;
  height: 20px;
}

.search {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--theme-border-subtle, var(--border-subtle));
  background: var(--theme-search-bg, rgba(11, 18, 32, 0.6));
  color: var(--text-primary);
  font-size: 0.8125rem;
  outline: none;
}

.search.search--infield {
  flex: 1;
  min-width: 0;
  width: auto;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.search.search--infield:focus {
  border: none;
  box-shadow: none;
  outline: none;
}

html[data-app-theme="light"] .search {
  background: var(--theme-search-bg, #f1f5f9);
}

html[data-app-theme="light"] .search.search--infield {
  background: transparent;
}

.search::placeholder {
  color: var(--text-tertiary);
}

.search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.2);
}

.search--popover {
  width: 100%;
}

/* Узкий сайдбар: кнопка поиска под логотипом */
.search-wrap--icon-only {
  display: flex;
  justify-content: center;
  width: 100%;
  flex-shrink: 0;
  padding: 0;
}

.btn-sidebar-search {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.18));
  background: rgba(148, 163, 184, 0.08);
  color: var(--text-secondary, #94a3b8);
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease;
}

.btn-sidebar-search:hover {
  color: var(--text-primary, #f1f5f9);
  border-color: rgba(52, 211, 153, 0.35);
  background: rgba(52, 211, 153, 0.08);
}

.btn-sidebar-search:focus-visible {
  outline: 2px solid var(--accent, #34d399);
  outline-offset: 2px;
}

.search-popover-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10054;
  background: rgba(4, 8, 18, 0.35);
}

.search-popover {
  position: fixed;
  z-index: 10055;
  padding: 12px;
  border-radius: 14px;
  background: var(--panel-bg, #121a2a);
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.06);
  max-height: min(70dvh, 420px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

html[data-app-theme="light"] .search-popover {
  background: #fff;
  box-shadow:
    0 24px 50px rgba(15, 23, 42, 0.12),
    0 0 0 1px rgba(15, 23, 42, 0.08);
}

html[data-app-theme="light"] .search-popover-backdrop {
  background: rgba(15, 23, 42, 0.2);
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 8px;
  max-height: 320px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--panel-bg, #121a2a);
  border-radius: 12px;
  box-shadow:
    0 10px 40px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.05);
  z-index: 100;
  padding: 8px;
}

.search-popover .search-results {
  position: relative;
  top: auto;
  left: auto;
  right: auto;
  margin-top: 0;
  flex: 1;
  min-height: 0;
  max-height: min(52dvh, 320px);
  box-shadow: none;
}

.search-results[hidden] {
  display: none !important;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin: 0;
  padding: 12px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  text-align: left;
  color: inherit;
  background: transparent;
  transition: background 0.2s;
}

.search-result-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.search-result-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(11, 18, 32, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.search-result-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.search-result-avatar span {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent, #34d399);
}

.search-result-info {
  flex: 1;
  min-width: 0;
}

.search-result-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary, #f1f5f9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-username {
  font-size: 13px;
  color: var(--accent, #34d399);
  margin-top: 2px;
}

.search-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-secondary, #94a3b8);
  font-size: 14px;
}

html[data-app-theme="light"] .search-results {
  background: #fff;
  box-shadow:
    0 10px 40px rgba(0, 0, 0, 0.1),
    0 0 0 1px rgba(0, 0, 0, 0.05);
}

html[data-app-theme="light"] .search-popover .search-results {
  box-shadow: none;
}

html[data-app-theme="light"] .search-result-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

html[data-app-theme="light"] .search-result-avatar {
  background: #f1f5f9;
}

html[data-app-theme="light"] .search-result-name {
  color: #0f172a;
}

html[data-app-theme="light"] .search-empty {
  color: #64748b;
}

/* FitWordsText: якорь для абсолютного measure, иначе строки чатов наезжают друг на друга */
.fit-words {
  min-width: 0;
  display: block;
  position: relative;
  overflow: hidden;
}

/* Chat list item (button или div[role="button"], без вложенных <button>) */
.chat-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin: 0;
  padding: 12px 16px;
  cursor: pointer;
  border: none;
  border-left: 3px solid transparent;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  transition: background 0.15s;
  box-sizing: border-box;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.chat-item--muted .chat-item-preview-line {
  opacity: 0.72;
}

.chat-item[role="button"]:focus {
  outline: none;
}

.chat-item[role="button"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.chat-item:hover {
  background: rgba(148, 163, 184, 0.08);
  -webkit-backdrop-filter: blur(8px) saturate(140%);
  backdrop-filter: blur(8px) saturate(140%);
}

.chat-item.active {
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  -webkit-backdrop-filter: blur(10px) saturate(150%);
  backdrop-filter: blur(10px) saturate(150%);
  box-shadow: inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.08));
}

/* Избранное: без свечения, только золотое имя контакта. */
.chat-item.chat-item--starred {
  isolation: isolate;
}

.chat-item.chat-item--starred::before {
  content: none;
}

.chat-item.chat-item--starred .chat-item-title {
  color: rgb(214, 167, 84);
}

html[data-app-theme="light"] .chat-item.chat-item--starred .chat-item-title {
  color: rgb(154, 111, 18);
}

.chat-item.chat-item--starred.active {
  border-left-color: var(--accent);
}

/* Закреплённый чат: значок по центру верхней границы строки */
.chat-item--pinned {
  padding-top: 15px;
}

.chat-item-pin-badge {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--theme-sidebar-bg, var(--panel-bg, #121a2a));
  border: 1px solid rgba(148, 163, 184, 0.4);
  color: var(--accent, #34d399);
  z-index: 2;
  pointer-events: none;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.22);
}

.chat-item-pin-icon {
  flex-shrink: 0;
  color: inherit;
}

.chat-item.active .chat-item-pin-badge {
  border-color: rgba(52, 211, 153, 0.5);
}

html[data-app-theme="light"] .chat-item-pin-badge {
  background: var(--theme-sidebar-bg, #f8fafc);
  border-color: rgba(100, 116, 139, 0.35);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.08);
}

.sidebar.sidebar--icons-only .chat-item--pinned {
  padding-top: 13px;
}

.sidebar.sidebar--icons-only .chat-item-pin-badge {
  width: 20px;
  height: 20px;
  transform: translate(-50%, -42%);
}

.sidebar.sidebar--icons-only .chat-item-pin-icon {
  width: 13px;
  height: 13px;
}

.avatar {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.125rem;
  flex-shrink: 0;
  background: linear-gradient(145deg, #1e293b, #0f172a);
  color: var(--accent);
}

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

.avatar--assistant {
  background: linear-gradient(145deg, #1e3a5f, #0f172a);
}

.avatar-theme-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--theme-accent-dot, var(--accent));
  border: 2px solid var(--theme-sidebar-bg, var(--panel-bg));
}

/* Тема чата может задавать --theme-accent-dot не зелёным; для статуса «в сети» фиксируем цвет. */
.avatar-theme-dot--online {
  background: #22c55e;
}
.avatar-theme-dot--offline {
  background: #64748b;
}
.avatar--assistant .avatar-theme-dot {
  background: #22c55e;
}

.dialog-header-presence {
  font-size: 0.8125rem;
  color: var(--text-secondary, #94a3b8);
  margin: 4px 0 0;
  line-height: 1.3;
}

.chat-meta {
  min-width: 0;
  flex: 1;
}

.chat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.chat-item-title {
  min-width: 0;
  flex: 1;
  font-size: var(--chat-title-font-size);
  font-weight: var(--chat-title-font-weight);
  letter-spacing: -0.01em;
  line-height: 1.25;
  color: var(--text-primary);
}

.chat-top-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  padding-top: 1px;
}

/*
 * Строка превью: текст слева на всю ширину, кружок непрочитанных — у правого края
 * (как в Telegram), а не сразу после текста.
 */
.chat-preview-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  width: 100%;
  margin-top: 3px;
}

.chat-preview-row .chat-item-preview-line {
  flex: 1 1 auto;
  min-width: 0;
  margin-top: 0;
}

.chat-item-unread {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 6px;
  border-radius: 999px;
  background: #3390ec;
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

html[data-app-theme="light"] .chat-item-unread {
  background: #3390ec;
  color: #fff;
}

.chat-item-time {
  font-size: var(--chat-time-font-size);
  font-weight: 400;
  line-height: 1.2;
  color: var(--chat-time-color);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chat-item-avatar-slot {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  min-width: 0;
}

.chat-item-time-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 2px;
  flex-shrink: 0;
  min-width: 0;
}

.chat-item-muted-bell {
  flex-shrink: 0;
  color: var(--text-tertiary, #64748b);
  opacity: 0.95;
}

.delete-chat-dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 10080;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.52);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.delete-chat-dialog {
  width: min(400px, 100%);
  max-height: min(90dvh, 520px);
  overflow: auto;
  background: color-mix(in srgb, var(--panel-bg, #121a2a) 72%, transparent);
  -webkit-backdrop-filter: blur(24px) saturate(170%);
  backdrop-filter: blur(24px) saturate(170%);
  color: var(--text-primary);
  border-radius: 22px;
  padding: 22px 20px 18px;
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.12));
  border: 1px solid var(--ui-glass-stroke-inner, var(--border-subtle, rgba(148, 163, 184, 0.15)));
}

.delete-chat-dialog__title {
  margin: 0 0 10px;
  font-size: 1.125rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.delete-chat-dialog__text {
  margin: 0 0 18px;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--text-secondary, #94a3b8);
}

.delete-chat-dialog__text--warning {
  color: #fca5a5;
}

html[data-app-theme="light"] .delete-chat-dialog__text--warning {
  color: #b91c1c;
}

.delete-chat-dialog__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.delete-chat-dialog__btn {
  font: inherit;
  cursor: pointer;
  border-radius: 11px;
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.25));
  background: rgba(52, 211, 153, 0.12);
  color: var(--accent, #34d399);
  padding: 9px 14px;
  font-size: 0.875rem;
  font-weight: 500;
}

.delete-chat-dialog__btn:hover:not(:disabled) {
  background: rgba(52, 211, 153, 0.2);
}

.delete-chat-dialog__btn--secondary {
  background: rgba(148, 163, 184, 0.1);
  color: var(--text-primary);
}

.delete-chat-dialog__btn--secondary:hover:not(:disabled) {
  background: rgba(148, 163, 184, 0.16);
}

.delete-chat-dialog__btn--danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.35);
  color: #f87171;
}

.delete-chat-dialog__btn--danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.22);
}

.delete-chat-dialog__btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chat-item-preview-line,
.chat-meta > p {
  margin: 0;
  font-size: var(--chat-preview-font-size);
  font-weight: 400;
  line-height: 1.35;
  letter-spacing: -0.01em;
  color: var(--chat-preview-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Dialog --- */
.dialog {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  min-width: 0;
  overflow: hidden;
  background: var(--theme-dialog-bg, var(--bg-app));
}

.dialog-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--header-h);
  flex-shrink: 0;
  padding: 8px 12px 8px 8px;
  border-bottom: 1px solid var(--ui-glass-stroke-inner, var(--theme-border-subtle, var(--border-subtle)));
  background: var(--ui-glass-header-fill, var(--theme-dialog-bg, var(--panel-bg)));
  -webkit-backdrop-filter: blur(var(--ui-glass-blur, 22px))
    saturate(var(--ui-glass-saturate, 168%));
  backdrop-filter: blur(var(--ui-glass-blur, 22px)) saturate(var(--ui-glass-saturate, 168%));
  /* Чуть отличаем шапку от ленты; пресеты чата задают --theme-dialog-bg */
  box-shadow:
    inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.1)),
    inset 0 -1px 0 rgba(148, 163, 184, 0.05);
  position: relative;
  z-index: 2;
}

.btn-icon {
  font: inherit;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-primary);
  padding: 8px 10px;
  border-radius: 12px;
}

.btn-icon:hover {
  background: var(--ui-glass-control-bg, rgba(148, 163, 184, 0.1));
  -webkit-backdrop-filter: blur(8px) saturate(140%);
  backdrop-filter: blur(8px) saturate(140%);
  box-shadow: inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.1));
}

.btn-back {
  display: none;
}

.dialog-header-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.dialog-header-text {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.dialog-header .avatar {
  width: 40px;
  height: 40px;
  font-size: 1rem;
}

.dialog-header-text strong {
  display: block;
  font-size: 0.9375rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialog-header-text p {
  margin: 2px 0 0;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.dialog-header-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.dialog-header-text--assistant .dialog-header-title-row strong {
  display: inline;
  font-size: 0.9375rem;
}

.dialog-header-assistant-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.12);
  color: var(--accent);
  border: 1px solid rgba(52, 211, 153, 0.28);
  flex-shrink: 0;
  line-height: 1.2;
}

html[data-app-theme="light"] .dialog-header-assistant-badge {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.3);
}

.dialog-header-actions {
  margin-left: auto;
}

/* Закреплённые под шапкой чата — тап ведёт к сообщению в ленте */
.dialog-pinned-bar {
  flex-shrink: 0;
  /* В колонке .dialog без min-width:0 горизонтальный скролл не срабатывает */
  min-width: 0;
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  padding: 6px 12px 8px;
  border-bottom: 1px solid
    var(--ui-glass-stroke-inner, var(--theme-border-subtle, var(--border-subtle)));
  background: color-mix(
    in srgb,
    var(--theme-dialog-bg, var(--panel-bg)) 92%,
    transparent
  );
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  scrollbar-width: thin;
  z-index: 1;
}

.dialog-pinned-bar__chip {
  flex: 0 0 auto;
  max-width: min(280px, 72vw);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 42%, transparent);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.1s ease;
}

.dialog-pinned-bar__chip:hover {
  background: color-mix(in srgb, var(--accent) 24%, transparent);
}

.dialog-pinned-bar__chip:active {
  transform: scale(0.98);
}

.dialog-pinned-bar__pin {
  flex-shrink: 0;
  font-size: 0.75rem;
  line-height: 1;
  opacity: 0.92;
}

.dialog-pinned-bar__text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html[data-app-theme="light"] .dialog-pinned-bar {
  background: color-mix(in srgb, var(--theme-dialog-bg, #fff) 94%, transparent);
}

.btn-chat-preset {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--ui-glass-stroke-inner, var(--theme-border-subtle, var(--border-subtle)));
  background: var(--ui-glass-control-bg, rgba(148, 163, 184, 0.08));
  -webkit-backdrop-filter: blur(12px) saturate(150%);
  backdrop-filter: blur(12px) saturate(150%);
  color: var(--text-primary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.1));
}

/* --- Feed --- */
.feed-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  isolation: isolate;
  background: var(--theme-feed-bg, var(--bg-app));
}

/* Матовый «атмосферный» слой из chatTheme (--app-gradient), поверх фона ленты */
.feed-pane::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: var(--app-gradient);
  opacity: 0.58;
  mix-blend-mode: soft-light;
  transition: opacity 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}

/* Лёгкий «техно»-переход справа налево поверх темы чата */
.feed-pane::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: linear-gradient(
    270deg,
    rgba(255, 255, 255, 0.055) 0%,
    transparent 42%,
    transparent 100%
  );
  opacity: 0.85;
  transition: opacity 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}

html[data-app-theme="light"] .feed-pane::before {
  opacity: 0.38;
  mix-blend-mode: soft-light;
}

html[data-app-theme="light"] .feed-pane::after {
  background: linear-gradient(
    270deg,
    rgba(15, 23, 42, 0.06) 0%,
    transparent 45%,
    transparent 100%
  );
  opacity: 0.9;
}

/* Режим контекстного меню: затемняем фон ленты (не трогаем шапку и композер) */
.feed-pane.feed-pane--ctx-open::before {
  opacity: 0.62;
}

html[data-app-theme="light"] .feed-pane.feed-pane--ctx-open::before {
  opacity: 0.46;
}

.feed-pane.feed-pane--ctx-open::after {
  background: rgba(4, 8, 18, 0.62);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  opacity: 1;
}

.feed-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 32px 24px;
  text-align: center;
  color: var(--text-secondary);
  position: relative;
  z-index: 1;
}

.feed-empty-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.feed-empty-hint {
  font-size: 0.875rem;
  max-width: 280px;
}

.feed {
  list-style: none;
  margin: 0;
  padding: 12px 14px;
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: none;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  z-index: 1;
}

/*
 * Строка сообщения на всю ширину ленты, иначе % max-width у пузыря считается от
 * узкого flex-элемента — все пузыри становятся «колонкой слева» и слишком узкими.
 */
.message {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  align-items: flex-start;
}

.message.message--out,
.message.self {
  align-items: flex-end;
}

.message-bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: min(78%, 520px);
  width: fit-content;
}

.message-bubble-wrap--menu {
  cursor: context-menu;
}

.message-bubble {
  display: block;
  width: fit-content;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow: visible;
}

/* Цитата при ответе (Telegram) */
.message-reply {
  display: flex;
  gap: 8px;
  margin: 0 0 8px;
  min-width: 0;
  text-align: left;
}

.message-reply-accent {
  width: 3px;
  flex-shrink: 0;
  border-radius: 2px;
  background: #5eb3f7;
}

.message.message--out .message-reply-accent {
  background: #8ab4e8;
}

.message-reply-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.message-reply-author {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #6ec8ff;
  line-height: 1.2;
}

.message.message--out .message-reply-author {
  color: #c8e0ff;
}

.message-reply-text {
  font-size: 0.8125rem;
  line-height: 1.25;
  color: color-mix(in srgb, var(--msg-fg) 58%, transparent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-edited-flag {
  font-size: 0.625rem;
  line-height: 1;
  color: color-mix(in srgb, var(--msg-time-fg) 80%, transparent);
  text-transform: lowercase;
  font-style: italic;
  user-select: none;
}

/*
 * Контекстное меню сообщения: блюр только остальных пузырей в области ленты;
 * выбранное сообщение и выпадающее меню (портал) остаются чёткими.
 */
.feed-pane--ctx-open .message {
  position: relative;
  transition:
    filter 0.32s cubic-bezier(0.32, 0.72, 0, 1),
    opacity 0.32s cubic-bezier(0.32, 0.72, 0, 1),
    transform 0.32s cubic-bezier(0.32, 0.72, 0, 1),
    box-shadow 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}

.feed-pane--ctx-open .message:not(.message--ctx-active) {
  filter: blur(10px);
  opacity: 0.72;
}

.feed-pane--ctx-open .message.message--ctx-active {
  z-index: 30;
  filter: none !important;
  opacity: 1 !important;
  transform: scale(1.018);
  box-shadow: 0 12px 44px rgba(0, 0, 0, 0.38);
}

html[data-app-theme="light"] .feed-pane--ctx-open .message.message--ctx-active {
  box-shadow:
    0 12px 40px rgba(15, 23, 42, 0.14),
    0 0 0 1px rgba(15, 23, 42, 0.06);
}

@media (max-width: 900px) {
  .feed-pane--ctx-open .message:not(.message--ctx-active) {
    filter: blur(8px);
    opacity: 0.74;
  }
}

@media (prefers-reduced-motion: reduce) {
  .feed-pane--ctx-open .message {
    transition-duration: 0.01ms;
  }

  .feed-pane--ctx-open .message:not(.message--ctx-active) {
    filter: none;
    opacity: 0.96;
  }

  .feed-pane--ctx-open .message.message--ctx-active {
    transform: none;
  }

  .feed-pane.feed-pane--ctx-open::before,
  .feed-pane.feed-pane--ctx-open::after {
    transition-duration: 0.01ms;
  }
}

/* Контекстное меню сообщения */
.message-ctx-menu {
  position: fixed;
  z-index: 10070;
  min-width: 200px;
  padding: 6px 0;
  border-radius: 16px;
  background: color-mix(in srgb, var(--panel-bg, #18222d) 68%, transparent);
  -webkit-backdrop-filter: blur(22px) saturate(175%);
  backdrop-filter: blur(22px) saturate(175%);
  border: 1px solid var(--ui-glass-stroke-inner, rgba(255, 255, 255, 0.1));
  box-shadow:
    0 20px 50px rgba(0, 0, 0, 0.42),
    inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.1));
}

.message-ctx-menu__item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: #e8edf3;
  font: inherit;
  font-size: 0.9375rem;
  text-align: left;
  cursor: pointer;
}

.message-ctx-menu__item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.message-ctx-menu__item--danger {
  color: #f87171;
}

.message-ctx-menu__item--danger:hover {
  background: rgba(248, 113, 113, 0.12);
}

.message-ctx-menu__ico {
  display: inline-flex;
  width: 1.25rem;
  justify-content: center;
  opacity: 0.9;
  font-size: 1rem;
}

html[data-app-theme="light"] .message-ctx-menu {
  background: color-mix(in srgb, #ffffff 74%, transparent);
  -webkit-backdrop-filter: blur(22px) saturate(175%);
  backdrop-filter: blur(22px) saturate(175%);
  border-color: var(--ui-glass-stroke-inner, rgba(15, 23, 42, 0.1));
  box-shadow:
    0 18px 48px rgba(15, 23, 42, 0.12),
    inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.85));
}

html[data-app-theme="light"] .message-ctx-menu__item {
  color: #0f172a;
}

html[data-app-theme="light"] .message-ctx-menu__item:hover {
  background: rgba(15, 23, 42, 0.06);
}

/* Баннер ответа / редактирования над полем ввода */
.composer-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 8px;
  padding: 8px 12px;
  border-radius: 14px;
  border: 1px solid var(--ui-glass-stroke-inner, rgba(148, 163, 184, 0.22));
  background: color-mix(
    in srgb,
    var(--theme-composer-bg, rgba(15, 23, 42, 0.85)) 38%,
    transparent
  );
  -webkit-backdrop-filter: blur(14px) saturate(155%);
  backdrop-filter: blur(14px) saturate(155%);
  box-shadow: inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.08));
  font-size: 0.8125rem;
  line-height: 1.35;
  color: var(--text-secondary);
}

.composer-banner--edit {
  border-color: rgba(96, 165, 250, 0.35);
  background: rgba(59, 130, 246, 0.12);
}

.composer-banner--reply {
  border-color: rgba(52, 211, 153, 0.28);
  background: rgba(52, 211, 153, 0.1);
}

.composer-banner__label {
  flex-shrink: 0;
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.composer-banner__snippet {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
}

.composer-banner__close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.composer-banner__close:hover {
  background: rgba(148, 163, 184, 0.28);
  color: var(--text-primary);
}

html[data-app-theme="light"] .composer-banner {
  background: color-mix(in srgb, #f8fafc 78%, transparent);
  border-color: rgba(15, 23, 42, 0.08);
}

/*
 * Как в Telegram: текст с отступом справа под полосу «галочки + время»;
 * мета position:absolute внизу справа (галочки слева от времени, узкий зазор).
 */
.message-line {
  display: block;
  padding: 8px 11px 7px 12px;
  border-radius: 18px;
  background: var(--ui-bubble-fill-in, var(--theme-bubble-in, var(--msg-in-bg)));
  color: var(--msg-fg);
  border: 1px solid var(--theme-border-subtle, rgba(148, 163, 184, 0.08));
  position: relative;
  -webkit-backdrop-filter: blur(var(--ui-bubble-blur, 18px)) saturate(155%);
  backdrop-filter: blur(var(--ui-bubble-blur, 18px)) saturate(155%);
  box-shadow:
    0 2px 12px rgba(0, 0, 0, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  overflow: visible;
}

/* Как в Telegram / WhatsApp: компактное превью в пузыре, полный размер — по тапу (оверлей). */
.message-image-link {
  display: block;
  max-width: 200px;
  max-height: 200px;
  width: auto;
  height: auto;
  margin: 0 0 6px;
  padding: 0;
  /* Невидимая рамка: визуально незаметна, но даёт стабильный контур фото-блока. */
  border: 1px solid transparent;
  border-radius: 12px;
  overflow: hidden;
  outline: none;
  background: rgba(0, 0, 0, 0.14);
  cursor: zoom-in;
  -webkit-tap-highlight-color: transparent;
}

.message-image {
  display: block;
  width: auto;
  height: auto;
  max-width: 200px;
  max-height: 200px;
  object-fit: contain;
  vertical-align: middle;
  background: transparent;
}

.message-photo-lightbox {
  position: fixed;
  inset: 0;
  z-index: 10090;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  margin: 0;
  border: none;
  background: rgba(0, 0, 0, 0.88);
  cursor: zoom-out;
  box-sizing: border-box;
  overscroll-behavior: contain;
}

.message-photo-lightbox__stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
  position: relative;
  touch-action: none;
}

.message-photo-lightbox__zoom {
  transform-origin: center center;
  will-change: transform;
}

.message-photo-lightbox .message-photo-lightbox__zoom img {
  max-width: min(100%, 96vw);
  max-height: min(100%, 96vh);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.55);
  cursor: zoom-in;
  pointer-events: auto;
  user-select: none;
  -webkit-user-drag: none;
}

.message-photo-lightbox__reset {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 2;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(28, 28, 32, 0.45);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  backdrop-filter: blur(16px) saturate(160%);
  color: rgba(255, 255, 255, 0.94);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 6px 20px rgba(0, 0, 0, 0.35);
}

.message-photo-lightbox__reset:hover {
  background: rgba(40, 40, 46, 0.52);
}

.message.message--pinned .message-line {
  border-color: rgba(250, 204, 21, 0.36);
  box-shadow:
    0 2px 14px rgba(0, 0, 0, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 0 0 1px rgba(250, 204, 21, 0.18);
}

.chat-explore-overlay {
  position: fixed;
  inset: 0;
  z-index: 10085;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  background: rgba(5, 10, 20, 0.46);
  -webkit-backdrop-filter: blur(9px);
  backdrop-filter: blur(9px);
}

.chat-explore {
  width: min(540px, 100%);
  max-height: min(86dvh, 740px);
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  border: 1px solid var(--ui-glass-stroke-inner, rgba(148, 163, 184, 0.2));
  background: color-mix(in srgb, var(--panel-bg, #121a2a) 74%, transparent);
  -webkit-backdrop-filter: blur(22px) saturate(170%);
  backdrop-filter: blur(22px) saturate(170%);
  box-shadow:
    0 28px 70px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.12));
  overflow: hidden;
}

.chat-explore__head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--theme-border-subtle, rgba(148, 163, 184, 0.18));
}

.chat-explore__nav {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.chat-explore__nav-title {
  min-width: 168px;
  text-align: center;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 34%, rgba(148, 163, 184, 0.25));
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  -webkit-backdrop-filter: blur(16px) saturate(165%);
  backdrop-filter: blur(16px) saturate(165%);
  box-shadow:
    0 10px 20px rgba(2, 6, 23, 0.35),
    0 0 0 1px rgba(52, 211, 153, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.chat-explore__nav-arrow {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 24%, rgba(148, 163, 184, 0.24));
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  -webkit-backdrop-filter: blur(13px) saturate(145%);
  backdrop-filter: blur(13px) saturate(145%);
  color: color-mix(in srgb, var(--text-primary) 84%, var(--accent) 16%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    inset 0 -1px 4px rgba(2, 6, 23, 0.32),
    0 8px 16px rgba(2, 6, 23, 0.32),
    0 0 0 1px rgba(52, 211, 153, 0.08);
  transition:
    transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.3s ease,
    filter 0.3s ease;
}

.chat-explore__nav-arrow span {
  font-size: 1rem;
  font-weight: 800;
  text-shadow: 0 1px 3px rgba(2, 6, 23, 0.6);
}

.chat-explore__nav-arrow:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    inset 0 -1px 4px rgba(2, 6, 23, 0.32),
    0 12px 20px rgba(2, 6, 23, 0.38),
    0 0 0 1px rgba(52, 211, 153, 0.16);
}

.chat-explore__nav-arrow:active {
  transform: translateY(1px) scale(0.95);
  box-shadow:
    inset 0 2px 4px rgba(2, 6, 23, 0.4),
    inset 0 -1px 2px rgba(255, 255, 255, 0.16),
    0 5px 10px rgba(2, 6, 23, 0.3);
}

.chat-explore__body {
  position: relative;
  padding: 18px;
  overflow: auto;
  min-height: 180px;
}

.chat-explore__stage {
  position: relative;
  min-height: 180px;
  overflow: hidden;
  isolation: isolate;
}

.chat-explore__pane {
  width: 100%;
}

.chat-explore__pane--in,
.chat-explore__pane--out {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  box-sizing: border-box;
}

.chat-explore__pane--out {
  z-index: 1;
  pointer-events: none;
}

.chat-explore__pane--in {
  z-index: 2;
  pointer-events: auto;
}

.chat-explore__pane--left.chat-explore__pane--out {
  animation: chatExploreSlideOutLeft 1200ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.chat-explore__pane--left.chat-explore__pane--in {
  animation: chatExploreSlideInLeft 1200ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.chat-explore__pane--right.chat-explore__pane--out {
  animation: chatExploreSlideOutRight 1200ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.chat-explore__pane--right.chat-explore__pane--in {
  animation: chatExploreSlideInRight 1200ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes chatExploreSlideInLeft {
  from {
    opacity: 0;
    transform: translateX(108%) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

@keyframes chatExploreSlideOutLeft {
  from {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateX(-58%) scale(0.985);
  }
}

@keyframes chatExploreSlideInRight {
  from {
    opacity: 0;
    transform: translateX(-108%) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

@keyframes chatExploreSlideOutRight {
  from {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateX(58%) scale(0.985);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-explore__pane--in,
  .chat-explore__pane--out {
    animation-duration: 1ms !important;
  }

  .chat-explore__nav-arrow {
    transition: none;
  }
}

.chat-explore-media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(124px, 1fr));
  gap: 12px;
}

.chat-explore-media-grid__item {
  padding: 0;
  border: 1px solid var(--theme-border-subtle, rgba(148, 163, 184, 0.2));
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.2);
}

.chat-explore-media-grid__item img {
  display: block;
  width: 100%;
  height: 124px;
  object-fit: cover;
}

.chat-explore-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-explore-list__row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 13px;
  border-radius: 12px;
  border: 1px solid var(--theme-border-subtle, rgba(148, 163, 184, 0.18));
  background: rgba(148, 163, 184, 0.06);
  color: inherit;
  text-decoration: none;
}

.chat-explore-list__row--button {
  cursor: pointer;
  font: inherit;
}

.chat-explore-list__url {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.chat-explore-list__meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.chat-explore-empty {
  color: color-mix(in srgb, var(--text-secondary) 86%, transparent);
  font-size: 0.84rem;
  line-height: 1.38;
  padding: 16px 18px 14px;
  margin: 6px 2px 0;
  text-align: center;
  border-radius: 12px;
  border: 1px dashed color-mix(in srgb, var(--theme-border-subtle, rgba(148, 163, 184, 0.2)) 78%, transparent);
  background: color-mix(in srgb, var(--panel-bg, #0f172a) 72%, transparent);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  backdrop-filter: blur(12px) saturate(140%);
}

.message-text-row {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 1.15em;
}

.message-text-row--has-image:not(:has(.message-text)) {
  min-height: 0;
}

/* Исходящие: шире под полосу «лоадер / галочки + время» */
.message.message--out .message-text-row--meta-wide .message-text {
  padding-right: 4.5rem;
}

.message.message--out .message-text-row:not(.message-text-row--meta-wide) .message-text {
  padding-right: 3.35rem;
}

.message.message--in .message-text {
  padding-right: 3.35rem;
}

/* «Хвост» у края, как в Telegram */
.message.message--in .message-line,
.message.peer .message-line {
  border-radius: 18px 18px 18px 5px;
}

.message.message--in .message-line::after {
  content: "";
  position: absolute;
  left: -5px;
  bottom: 0;
  width: 10px;
  height: 14px;
  background: var(--ui-bubble-fill-in, var(--theme-bubble-in, var(--msg-in-bg)));
  border-radius: 0 0 0 3px;
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  z-index: 0;
  pointer-events: none;
}

.message.message--out .message-line,
.message.self .message-line {
  background: var(--ui-bubble-fill-out, var(--theme-bubble-out, var(--msg-out-bg)));
  border-color: var(--theme-border-subtle, rgba(148, 163, 184, 0.12));
  border-radius: 18px 18px 5px 18px;
  box-shadow:
    0 2px 14px rgba(0, 0, 0, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.message.message--out .message-line::after,
.message.self .message-line::after {
  content: "";
  position: absolute;
  right: -5px;
  bottom: 0;
  width: 10px;
  height: 14px;
  background: var(--ui-bubble-fill-out, var(--theme-bubble-out, var(--msg-out-bg)));
  border-radius: 0 0 3px 0;
  clip-path: polygon(0 0, 100% 100%, 0 100%);
  z-index: 0;
  pointer-events: none;
}

html[data-app-theme="light"] .message-line {
  box-shadow:
    0 2px 10px rgba(15, 23, 42, 0.07),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.message-text {
  position: relative;
  z-index: 1;
  font-size: 0.9375rem;
  line-height: 1.45;
  font-weight: 400;
  letter-spacing: 0.01em;
  font-variant-ligatures: common-ligatures;
  word-break: normal;
  overflow-wrap: break-word;
  overflow-wrap: anywhere; /* длинные URL / строки без пробелов — без горизонтального скролла */
  white-space: pre-wrap;
  hyphens: manual;
  min-width: 0;
  max-width: 100%;
}

.message-footer {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: inline-flex;
  flex-direction: row;
  align-items: baseline;
  flex-wrap: nowrap;
  /* Время слева в полосе меты, справа — лоадер или галочки */
  gap: 6px;
  margin: 0;
  padding: 0;
  line-height: 1;
  pointer-events: none;
}

.message-footer time {
  font-size: 0.6875rem;
  line-height: 1.15;
  color: var(--msg-time-fg);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Галочки доставки: цвета из --msg-receipt-* (тёмная/светлая тема в :root) */
.message-status {
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.1em;
  user-select: none;
  color: var(--msg-receipt-muted);
  -webkit-text-stroke: 0.45px color-mix(in srgb, var(--msg-receipt-muted) 55%, transparent);
  paint-order: stroke fill;
}

/* Доставлено (1✓) — бледно-серый; прочитано (2✓) — Tiffany ниже */
.message-status--delivered {
  color: var(--msg-receipt-muted);
  -webkit-text-stroke: 0.45px color-mix(in srgb, var(--msg-receipt-muted) 55%, transparent);
}

.message-status--read {
  -webkit-text-stroke: 0;
  background: linear-gradient(
    145deg,
    var(--msg-receipt-read-a) 0%,
    var(--msg-receipt-read-b) 48%,
    var(--msg-receipt-read-c) 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}

/* Лоадер только на время отправки на сервер (POST) */
.message-send-loader {
  display: inline-block;
  width: 0.8125rem;
  height: 0.8125rem;
  flex-shrink: 0;
  border: 2px solid color-mix(in srgb, var(--msg-receipt-muted) 32%, transparent);
  border-top-color: var(--msg-receipt-muted);
  border-radius: 50%;
  vertical-align: -0.12em;
  opacity: 0.95;
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--msg-receipt-muted) 28%, transparent);
  animation:
    message-send-spin 0.7s linear infinite,
    message-send-loader-glow 1.5s ease-in-out infinite;
}

html[data-app-theme="light"] .message-send-loader {
  border-color: color-mix(in srgb, var(--msg-receipt-muted) 40%, transparent);
  border-top-color: var(--msg-receipt-muted);
}

@keyframes message-send-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes message-send-loader-glow {
  0%,
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--msg-receipt-muted) 15%, transparent);
  }
  50% {
    box-shadow: 0 0 8px 1px color-mix(in srgb, var(--msg-receipt-muted) 28%, transparent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .message-send-loader {
    animation: none;
    border-color: var(--msg-receipt-muted);
    opacity: 0.88;
    box-shadow: none;
  }
}

/*
 * Появление сообщения: направление от собеседника / от себя,
 * лёгкий blur→sharp, масштаб с коротким «перелётом» (spring-ощущение).
 */
@keyframes message-enter-in {
  0% {
    opacity: 0;
    transform: translate3d(-36px, 16px, 0) scale(0.88) rotate(-0.35deg);
    filter: blur(8px);
  }
  38% {
    opacity: 0.92;
    filter: blur(1px);
  }
  58% {
    opacity: 1;
    transform: translate3d(5px, -4px, 0) scale(1.03) rotate(0deg);
    filter: blur(0);
  }
  78% {
    transform: translate3d(-2px, 2px, 0) scale(0.995);
  }
  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1) rotate(0deg);
    filter: blur(0);
  }
}

@keyframes message-enter-out {
  0% {
    opacity: 0;
    transform: translate3d(36px, 16px, 0) scale(0.88) rotate(0.35deg);
    filter: blur(8px);
  }
  38% {
    opacity: 0.92;
    filter: blur(1px);
  }
  58% {
    opacity: 1;
    transform: translate3d(-5px, -4px, 0) scale(1.03) rotate(0deg);
    filter: blur(0);
  }
  78% {
    transform: translate3d(2px, 2px, 0) scale(0.995);
  }
  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1) rotate(0deg);
    filter: blur(0);
  }
}

@keyframes message-enter-reduced {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .message.message--enter--in .message-bubble {
    transform-origin: left center;
    backface-visibility: hidden;
    animation: message-enter-in 0.68s cubic-bezier(0.22, 0.82, 0.24, 1) both;
  }

  .message.message--enter--out .message-bubble {
    transform-origin: right center;
    backface-visibility: hidden;
    animation: message-enter-out 0.68s cubic-bezier(0.22, 0.82, 0.24, 1) both;
  }
}

@media (prefers-reduced-motion: reduce) {
  .message.message--enter--in .message-bubble,
  .message.message--enter--out .message-bubble {
    animation: message-enter-reduced 0.22s ease-out both;
  }
}

/* Совместимость со старой разметкой */
.message-body {
  padding: 8px 10px 7px 11px;
  border-radius: 16px;
  background: var(--ui-bubble-fill-in, var(--theme-bubble-in, var(--msg-in-bg)));
  color: var(--msg-fg);
  font-size: 0.9375rem;
  border: 1px solid var(--theme-border-subtle, rgba(148, 163, 184, 0.06));
  -webkit-backdrop-filter: blur(var(--ui-bubble-blur, 18px)) saturate(155%);
  backdrop-filter: blur(var(--ui-bubble-blur, 18px)) saturate(155%);
  box-shadow:
    0 2px 10px rgba(0, 0, 0, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.message.self .message-body {
  background: var(--ui-bubble-fill-out, var(--theme-bubble-out, var(--msg-out-bg)));
  border-color: var(--theme-border-subtle, rgba(148, 163, 184, 0.1));
}

/* --- Composer --- */
.composer {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  flex-shrink: 0;
  padding: 12px 16px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--ui-glass-stroke-inner, var(--theme-border-subtle, var(--border-subtle)));
  background: var(--ui-glass-composer-fill, var(--theme-composer-bg, var(--panel-bg)));
  -webkit-backdrop-filter: blur(var(--ui-glass-blur, 22px))
    saturate(var(--ui-glass-saturate, 168%));
  backdrop-filter: blur(var(--ui-glass-blur, 22px)) saturate(var(--ui-glass-saturate, 168%));
  box-shadow:
    inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.12)),
    0 -8px 32px rgba(0, 0, 0, 0.12);
  /* Нижний край = низ видимого окна (visualViewport); без лишнего зазора над клавиатурой */
  transition: padding-bottom 0.22s ease;
}

@media (prefers-reduced-motion: reduce) {
  .composer {
    transition: none;
  }
}

.composer-error {
  font-size: 0.8125rem;
  color: #fca5a5;
  padding: 0 2px;
}

.composer-row {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 10px;
  max-width: 100%;
  min-width: 0;
  position: relative;
  /* Меньше задержка тапа и лишних жестов масштаба при клике по вложениям/отправке */
  touch-action: manipulation;
}

.composer-attachment-input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.composer-attach-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--ui-glass-stroke-inner, var(--border-subtle));
  background: var(--ui-glass-control-bg, rgba(15, 23, 42, 0.35));
  -webkit-backdrop-filter: blur(12px) saturate(150%);
  backdrop-filter: blur(12px) saturate(150%);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.1));
  transition:
    background 0.15s ease,
    color 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.composer-attach-btn:hover {
  color: var(--accent);
  border-color: rgba(52, 211, 153, 0.35);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

html[data-app-theme="light"] .composer-attach-btn {
  background: color-mix(in srgb, #f1f5f9 72%, transparent);
}

.composer-banner--photo {
  align-items: center;
}

.composer-banner__thumb {
  width: 96px;
  height: 96px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
}

.composer-banner__photo-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.composer-banner__hint {
  font-size: 0.72rem;
  line-height: 1.3;
  color: var(--text-tertiary);
}

.composer-input-wrap {
  flex: 1;
  min-width: 0;
}

.composer-input {
  width: 100%;
  min-height: 44px;
  max-height: 160px;
  resize: none;
  padding: 10px 14px;
  border-radius: 16px;
  border: 1px solid var(--ui-glass-stroke-inner, var(--border-subtle));
  background: color-mix(
    in srgb,
    var(--theme-composer-bg, rgba(11, 18, 32, 0.85)) 42%,
    transparent
  );
  -webkit-backdrop-filter: blur(14px) saturate(155%);
  backdrop-filter: blur(14px) saturate(155%);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.9375rem;
  outline: none;
  vertical-align: top;
  box-sizing: border-box;
  box-shadow: inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.08));
}

html[data-app-theme="light"] .composer-input {
  background: color-mix(in srgb, #ffffff 58%, transparent);
}

.composer-input::placeholder {
  color: var(--text-tertiary);
}

.composer-input:focus {
  border-color: var(--accent);
}

/* Узкий экран: 16px — как у системных полей (prompt), без автозума iOS и ближе к «нормальной» клавиатуре */
@media (max-width: 904px) {
  .composer-input {
    font-size: 16px;
    line-height: 1.38;
  }

  .contacts-block__input {
    font-size: 16px;
    line-height: 1.38;
    min-height: 44px;
    height: auto;
    touch-action: manipulation;
  }

  .search.search--infield,
  .search.search--infield.search--popover {
    font-size: 16px;
    line-height: 1.38;
  }

  html.vv-keyboard .layout[data-view="sidebar"] .search-wrap {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  html.vv-keyboard .layout[data-view="sidebar"] .sidebar-head {
    padding-top: 10px;
    padding-bottom: 8px;
  }
}

/* Резерв: contenteditable, если когда-нибудь включат useTextarea={false} */
.composer-input--contenteditable {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  min-height: 44px;
  max-height: 160px;
  overflow-y: auto;
  cursor: text;
  -webkit-user-select: text;
  user-select: text;
  /* plaintext-only — меньше «форменного» оформления WebKit у contenteditable */
  -webkit-user-modify: read-write-plaintext-only;
}

.composer-input--contenteditable:empty::before {
  content: attr(data-placeholder);
  color: var(--text-tertiary);
  pointer-events: none;
}

html[data-app-theme="light"] .composer-input--contenteditable:empty::before {
  color: var(--text-tertiary);
}

.composer-send {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--theme-btn-send-bg, var(--accent)) 55%, rgba(255, 255, 255, 0.35));
  cursor: pointer;
  touch-action: manipulation;
  background: var(--theme-btn-send-bg, var(--accent));
  color: var(--theme-btn-send-fg, #0b1220);
  font-size: 1.125rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    0 4px 14px color-mix(in srgb, var(--theme-btn-send-bg, var(--accent)) 42%, transparent);
  transition: filter 0.15s ease, background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.composer-send:hover {
  background: var(--theme-btn-send-bg-hover, var(--accent));
  color: var(--theme-btn-send-fg-hover, #0b1220);
  filter: brightness(1.04);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.32),
    0 6px 18px color-mix(in srgb, var(--theme-btn-send-bg-hover, var(--accent)) 48%, transparent);
}

.send-actions-popover {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  width: min(92vw, 360px);
  padding: 10px;
  border-radius: 5%;
  border: 1px solid rgba(148, 163, 184, 0.32);
  background: color-mix(in oklab, var(--panel-bg) 74%, transparent);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.28);
  display: grid;
  gap: 8px;
  z-index: 40;
  animation: send-actions-fade-in 170ms ease-out;
  overflow: hidden;
}

.send-actions-slider {
  width: 200%;
  display: flex;
  transform: translateX(0);
  transition: transform 240ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

.send-actions-slider--schedule {
  transform: translateX(-50%);
}

.send-actions-page {
  width: 50%;
  display: grid;
  gap: 8px;
  padding-right: 8px;
}

.send-actions-page--schedule {
  padding-left: 8px;
  padding-right: 0;
}

.send-actions-item,
.send-actions-close,
.send-actions-apply {
  width: 100%;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.36);
  color: var(--text-primary);
  padding: 10px 12px;
  text-align: left;
}

.send-actions-item--schedule {
  display: grid;
  gap: 8px;
}

.send-actions-datetime {
  width: 100%;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.4);
  color: var(--text-primary);
  padding: 10px 12px;
  min-height: 42px;
}

@keyframes send-actions-fade-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* --- Mobile: список чатов + диалог — общая ячейка сетки, диалог «выплывает» справа --- */
/* Порог 904/905px — см. apps/web/src/layoutBreakpoint.ts */
@media (max-width: 904px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    position: relative;
    overflow: hidden;
    overflow-x: clip;
    overscroll-behavior-x: none;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .layout > .sidebar {
    grid-area: 1 / 1;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 0;
    z-index: 1;
    pointer-events: auto;
    overflow-x: hidden;
    transform: translateX(0) scale(1);
    transform-origin: left center;
    opacity: 1;
    filter: blur(0);
    transition:
      transform 320ms cubic-bezier(0.22, 0.7, 0, 1),
      opacity 260ms ease,
      filter 320ms cubic-bezier(0.22, 0.7, 0, 1);
    will-change: transform, opacity, filter;
  }

  .layout > .dialog {
    grid-area: 1 / 1;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 0;
    position: relative;
    z-index: 2;
    transform: translateX(100%);
    transition: transform 320ms cubic-bezier(0.32, 0.72, 0, 1);
    pointer-events: none;
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.18);
    will-change: transform;
    overflow-x: hidden;
  }

  .layout[data-view="dialog"] > .dialog {
    transform: translateX(0);
    pointer-events: auto;
  }

  .layout[data-view="dialog"] > .sidebar {
    pointer-events: none;
    transform: translateX(-1.8%) scale(0.992);
    opacity: 0.78;
    filter: blur(1.5px);
  }

  .layout[data-view="sidebar"] > .dialog {
    pointer-events: none;
  }

  /*
   * Открытый чат: колонка на всю высоту #root (--app-vvh). Шапка и композер не сжимаются,
   * сжимается только .feed-pane (лента с прокруткой) — при клавиатуре остаётся «как в Telegram».
   */
  .layout[data-view="dialog"] > .dialog {
    height: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    overscroll-behavior: none;
  }

  /* Шапка чата: центр — собеседник, по краям — назад и тема (как в референсе) */
  .layout[data-view="dialog"] .dialog-header {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    transition: padding-top 0.28s cubic-bezier(0.32, 0.72, 0, 1);
    /* Не sticky: родитель .dialog с overflow:hidden — sticky не даёт выигрыша и даёт артефакты при IME.
       Порядок flex-колонки [шапка | лента | композер] уже фиксирует шапку сверху. */
    position: relative;
    z-index: 8;
    /* Чуть больше воздуха при IME: iOS иногда сдвигает слой так, что контент прижимается к статус-бару */
    padding: calc(8px + env(safe-area-inset-top, 0px))
      max(8px, env(safe-area-inset-right, 0px)) 6px
      max(8px, env(safe-area-inset-left, 0px));
    min-height: 52px;
    background: var(
      --ui-glass-header-fill,
      color-mix(in srgb, var(--theme-dialog-bg, var(--panel-bg)) 58%, transparent)
    );
    -webkit-backdrop-filter: blur(var(--ui-glass-blur, 22px))
      saturate(var(--ui-glass-saturate, 168%));
    backdrop-filter: blur(var(--ui-glass-blur, 22px)) saturate(var(--ui-glass-saturate, 168%));
    border-bottom: 1px solid var(--ui-glass-stroke-inner, rgba(148, 163, 184, 0.08));
    box-shadow:
      inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.12)),
      inset 0 -1px 0 rgba(148, 163, 184, 0.06),
      0 4px 24px rgba(0, 0, 0, 0.12);
  }

  html.vv-keyboard .layout[data-view="dialog"] .dialog-header {
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
  }

  .layout[data-view="dialog"] .dialog-header .btn-back {
    grid-column: 1;
    justify-self: start;
    width: 40px;
    height: 40px;
    border-radius: 999px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--ui-glass-stroke-inner, rgba(148, 163, 184, 0.14));
    background: var(--ui-glass-control-bg, rgba(148, 163, 184, 0.1));
    -webkit-backdrop-filter: blur(12px) saturate(150%);
    backdrop-filter: blur(12px) saturate(150%);
    box-shadow: inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.12));
  }

  .layout[data-view="dialog"] .dialog-header .dialog-header-main,
  .layout[data-view="dialog"] .dialog-header .dialog-header-main--peer {
    grid-column: 2;
    justify-self: center;
    margin: 0;
    flex: none;
    max-width: 100%;
    min-width: 0;
  }

  .layout[data-view="dialog"] .dialog-header .dialog-header-main--peer {
    justify-content: center;
    border: none;
    background: transparent;
    width: auto;
  }

  .layout[data-view="dialog"] .dialog-header .dialog-header-title-row {
    justify-content: center;
  }

  .layout[data-view="dialog"] .dialog-header .dialog-header-text {
    text-align: center;
  }

  .layout[data-view="dialog"] .dialog-header .dialog-header-text strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .layout[data-view="dialog"] .dialog-header .dialog-header-text p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .layout[data-view="dialog"] .dialog-header .dialog-header-presence--peer-mobile {
    display: block;
    margin-top: 2px;
  }

  .layout[data-view="dialog"] .dialog-header .dialog-header-actions {
    grid-column: 3;
    margin-left: 0;
    justify-self: end;
  }

  .layout[data-view="dialog"] .btn-chat-preset {
    border-radius: 999px;
    width: 40px;
    height: 40px;
    border: 1px solid var(--ui-glass-stroke-inner, rgba(148, 163, 184, 0.14));
    background: var(--ui-glass-control-bg, rgba(148, 163, 184, 0.12));
    -webkit-backdrop-filter: blur(12px) saturate(155%);
    backdrop-filter: blur(12px) saturate(155%);
    box-shadow: inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.12));
  }

  /* Композер: стекло + без вылезания за край экрана (safe area + % вместо vw) */
  .layout[data-view="dialog"] .composer {
    flex-shrink: 0;
    position: relative;
    z-index: 6;
    padding: 8px max(10px, env(safe-area-inset-left)) 10px
      max(10px, env(safe-area-inset-right));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    background: var(
      --ui-glass-composer-fill,
      color-mix(in srgb, var(--theme-composer-bg, var(--panel-bg)) 62%, transparent)
    );
    -webkit-backdrop-filter: blur(var(--ui-glass-blur, 22px))
      saturate(var(--ui-glass-saturate, 168%));
    backdrop-filter: blur(var(--ui-glass-blur, 22px)) saturate(var(--ui-glass-saturate, 168%));
    border-top: 1px solid var(--ui-glass-stroke-inner, rgba(148, 163, 184, 0.12));
    box-shadow:
      inset 0 1px 0 var(--ui-glass-highlight-top, rgba(255, 255, 255, 0.1)),
      0 -6px 28px rgba(0, 0, 0, 0.1);
  }

  html[data-app-theme="light"] .layout[data-view="dialog"] .composer {
    background: color-mix(in srgb, #ffffff 78%, transparent);
  }

  html.vv-keyboard .layout[data-view="dialog"] .composer {
    padding-bottom: max(4px, env(safe-area-inset-bottom));
  }

  /* Интерактивный свайп: без transition, transform задаётся из JS */
  .layout.layout--narrow-drag > .dialog {
    transition: none !important;
  }

  @media (prefers-reduced-motion: reduce) {
    .layout > .dialog {
      transition: none !important;
    }

    .layout[data-view="dialog"] .dialog-header {
      transition: none !important;
    }
  }

  .btn-back {
    display: inline-flex;
  }

  .sidebar-head {
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
  }
}

@media (min-width: 905px) {
  .btn-back {
    display: none;
  }
}

/* --- Тост «тег скопирован» --- */
.tag-copied-toast {
  position: fixed;
  /* Выше бэкдропа профиля (10040) и вложенных меню; тосты порталятся в body */
  z-index: 10100;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--border-subtle);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  animation: tagCopiedIn 0.2s ease-out;
}

/* Длинные подсказки (PWA): прямоугольник и переносы строк, не «овал». */
.tag-copied-toast.tag-copied-toast--pwa {
  width: min(calc(100vw - 32px), 420px);
  max-width: min(calc(100vw - 32px), 420px);
  box-sizing: border-box;
  padding: 14px 16px;
  border-radius: 12px;
  text-align: start;
  line-height: 1.45;
  font-weight: 500;
  overflow-wrap: break-word;
}

html[data-app-theme="light"] .tag-copied-toast {
  background: rgba(255, 255, 255, 0.96);
}

@keyframes tagCopiedIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Тост после заявки в друзья / взаимного принятия (выше «Тег скопирован», чтобы не пересекались) */
.friend-action-toast {
  position: fixed;
  z-index: 10100;
  left: 50%;
  bottom: max(88px, calc(env(safe-area-inset-bottom) + 64px));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(92vw, 360px);
  padding: 12px 18px 12px 14px;
  border-radius: 14px;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid color-mix(in srgb, var(--accent, #34d399) 55%, transparent);
  box-shadow:
    0 0 0 1px rgba(52, 211, 153, 0.12),
    0 16px 48px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  animation: friendActionToastIn 0.45s cubic-bezier(0.22, 1, 0.36, 1) both,
    friendActionToastGlow 2.2s ease-in-out 0.15s 1 both;
}

html[data-app-theme="light"] .friend-action-toast {
  background: rgba(255, 255, 255, 0.97);
  box-shadow:
    0 0 0 1px rgba(52, 211, 153, 0.2),
    0 16px 40px rgba(15, 23, 42, 0.12);
}

.friend-action-toast__icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 0.95rem;
  font-weight: 700;
  color: #022c22;
  background: var(--accent, #34d399);
  animation: friendActionCheckPop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) 0.08s both;
}

.friend-action-toast__text {
  text-align: left;
}

@keyframes friendActionToastIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(18px) scale(0.94);
  }
  55% {
    opacity: 1;
    transform: translateX(-50%) translateY(-3px) scale(1.02);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
}

@keyframes friendActionCheckPop {
  from {
    opacity: 0;
    transform: scale(0.35);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes friendActionToastGlow {
  0%,
  100% {
    box-shadow:
      0 0 0 1px rgba(52, 211, 153, 0.12),
      0 16px 48px rgba(0, 0, 0, 0.4);
  }
  40% {
    box-shadow:
      0 0 0 1px rgba(52, 211, 153, 0.35),
      0 16px 52px rgba(52, 211, 153, 0.18);
  }
}

/* --- Модалка профиля (ПКМ / долгое нажатие на логин) --- */
.user-profile-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10040;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  box-sizing: border-box;
  background: rgba(2, 6, 23, 0.62);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.38s cubic-bezier(0.22, 1, 0.36, 1);
}

.user-profile-backdrop--open {
  opacity: 1;
  pointer-events: auto;
}

.user-profile-modal {
  position: relative;
  /* 100% — внутри паддингов backdrop (flex); без 100vw → меньше горизонтального вылезания */
  width: min(440px, 100%);
  max-width: 100%;
  box-sizing: border-box;
  /* Высота как у блока переписки: вся колонка диалога минус шапка и поле ввода */
  max-height: calc(
    100dvh - var(--header-h) - var(--profile-modal-composer-est) -
      var(--profile-modal-backdrop-pad)
  );
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  /* Было 20px; «полуквадратные» углы без сильного скругления */
  border-radius: 10px;
  background: var(--panel-bg);
  box-shadow:
    0 28px 90px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(148, 163, 184, 0.12);
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  transition:
    opacity 0.38s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
}

.user-profile-backdrop--open .user-profile-modal {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .user-profile-backdrop {
    transition: none;
  }

  .user-profile-modal {
    transition: none;
  }
}

/* Телефоны: высота окна — 2/3 экрана, с учётом safe-area */
/* Порог 904/905px — см. apps/web/src/layoutBreakpoint.ts */
@media (max-width: 904px) {
  .user-profile-modal {
    max-height: calc(
      (100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) * 3 / 4
    );
  }
}

.user-profile-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--text-secondary);
  background: rgba(15, 23, 42, 0.45);
}

.user-profile-close:hover {
  color: var(--text-primary);
  background: rgba(148, 163, 184, 0.15);
}

html[data-app-theme="light"] .user-profile-close {
  background: rgba(241, 245, 249, 0.9);
}

.user-profile-header {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  padding: 28px 24px 20px;
  background: linear-gradient(
    180deg,
    rgba(52, 211, 153, 0.14) 0%,
    rgba(18, 26, 42, 0.4) 100%
  );
}

html[data-app-theme="light"] .user-profile-header {
  background: linear-gradient(
    180deg,
    rgba(52, 211, 153, 0.12) 0%,
    rgba(255, 255, 255, 0.5) 100%
  );
}

/* Темы карточки профиля (свои + чужие) */
.user-profile-modal--theme-forest .user-profile-header {
  background: linear-gradient(
    180deg,
    rgba(34, 197, 94, 0.2) 0%,
    rgba(15, 23, 42, 0.55) 100%
  );
}

html[data-app-theme="light"] .user-profile-modal--theme-forest .user-profile-header {
  background: linear-gradient(
    180deg,
    rgba(34, 197, 94, 0.18) 0%,
    rgba(255, 255, 255, 0.55) 100%
  );
}

.user-profile-modal--theme-ocean .user-profile-header {
  background: linear-gradient(
    180deg,
    rgba(56, 189, 248, 0.22) 0%,
    rgba(15, 23, 42, 0.55) 100%
  );
}

html[data-app-theme="light"] .user-profile-modal--theme-ocean .user-profile-header {
  background: linear-gradient(
    180deg,
    rgba(56, 189, 248, 0.16) 0%,
    rgba(255, 255, 255, 0.55) 100%
  );
}

.user-profile-modal--theme-sunset .user-profile-header {
  background: linear-gradient(
    180deg,
    rgba(251, 146, 60, 0.22) 0%,
    rgba(15, 23, 42, 0.55) 100%
  );
}

html[data-app-theme="light"] .user-profile-modal--theme-sunset .user-profile-header {
  background: linear-gradient(
    180deg,
    rgba(251, 146, 60, 0.18) 0%,
    rgba(255, 255, 255, 0.55) 100%
  );
}

.user-profile-modal--theme-mono .user-profile-header {
  background: linear-gradient(
    180deg,
    rgba(148, 163, 184, 0.18) 0%,
    rgba(15, 23, 42, 0.6) 100%
  );
}

html[data-app-theme="light"] .user-profile-modal--theme-mono .user-profile-header {
  background: linear-gradient(
    180deg,
    rgba(100, 116, 139, 0.14) 0%,
    rgba(255, 255, 255, 0.55) 100%
  );
}

.user-profile-modal--theme-aurora .user-profile-header {
  background: linear-gradient(
    180deg,
    rgba(167, 139, 250, 0.24) 0%,
    rgba(15, 23, 42, 0.55) 100%
  );
}

html[data-app-theme="light"] .user-profile-modal--theme-aurora .user-profile-header {
  background: linear-gradient(
    180deg,
    rgba(167, 139, 250, 0.18) 0%,
    rgba(255, 255, 255, 0.55) 100%
  );
}

.user-profile-theme-block {
  margin: 0 0 14px;
  text-align: left;
}

.user-profile-theme-block__title {
  margin-bottom: 4px;
}

.user-profile-theme-hint {
  margin: 0 0 10px;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--text-tertiary);
  text-align: center;
}

.user-profile-notify-grid {
  display: grid;
  gap: 14px;
}

.user-profile-notify-volume-wrap {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(15, 23, 42, 0.28);
}

.user-profile-notify-volume-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 0.875rem;
  color: var(--text-primary);
}

.user-profile-notify-volume-value {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}

.user-profile-notify-volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    rgba(148, 163, 184, 0.35) 0%,
    rgba(52, 211, 153, 0.45) 100%
  );
  outline: none;
  cursor: pointer;
}

.user-profile-notify-volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid rgba(15, 23, 42, 0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  cursor: grab;
}

.user-profile-notify-volume-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid rgba(15, 23, 42, 0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  cursor: grab;
}

.user-profile-notify-volume-slider::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: transparent;
}

.user-profile-notify-volume-hint {
  margin: 10px 0 0;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--text-tertiary);
}

.user-profile-notify-popup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.875rem;
  color: var(--text-primary);
}

.user-profile-notify-switch {
  position: relative;
  flex-shrink: 0;
  width: 44px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.28);
  cursor: pointer;
  transition: background 0.18s ease;
}

.user-profile-notify-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #f8fafc;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s ease;
}

.user-profile-notify-switch--on {
  background: rgba(52, 211, 153, 0.55);
}

.user-profile-notify-switch--on::after {
  transform: translateX(18px);
}

.user-profile-sound-menu {
  position: fixed;
  z-index: 10060;
  min-width: 220px;
  max-width: min(280px, calc(100vw - 16px));
  padding: 10px 0 8px;
  border-radius: 14px;
  background: var(--panel-bg);
  border: 1px solid rgba(148, 163, 184, 0.22);
  box-shadow:
    0 18px 48px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(0, 0, 0, 0.2);
}

.user-profile-sound-menu__title {
  padding: 0 14px 8px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.user-profile-sound-menu__list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}

.user-profile-sound-menu__item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 0.875rem;
  text-align: left;
  cursor: pointer;
}

.user-profile-sound-menu__item:hover {
  background: rgba(52, 211, 153, 0.1);
}

.user-profile-sound-menu__item--active {
  color: var(--accent);
  font-weight: 600;
}

.user-profile-sound-menu__preview {
  display: block;
  width: calc(100% - 24px);
  margin: 8px 12px 4px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(15, 23, 42, 0.35);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
}

.user-profile-sound-menu__preview:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

html[data-app-theme="light"] .user-profile-notify-volume-wrap {
  background: rgba(241, 245, 249, 0.85);
}

.user-profile-theme-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  justify-content: center;
  width: 100%;
  min-width: 0;
}

.user-profile-theme-chip {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  min-width: 30px;
  min-height: 30px;
  padding: 2px;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(148, 163, 184, 0.08);
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s ease;
}

.user-profile-theme-chip:hover:not(:disabled) {
  background: rgba(52, 211, 153, 0.1);
  border-color: rgba(52, 211, 153, 0.35);
}

.user-profile-theme-chip--active {
  background: rgba(15, 23, 42, 0.34);
  border-color: rgba(52, 211, 153, 0.75);
  box-shadow:
    0 0 0 1px rgba(52, 211, 153, 0.55),
    0 4px 18px rgba(52, 211, 153, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

html[data-app-theme="light"] .user-profile-theme-chip--active {
  background: rgba(255, 255, 255, 0.75);
  border-color: rgba(5, 150, 105, 0.55);
  box-shadow:
    0 0 0 1px rgba(16, 185, 129, 0.45),
    0 4px 14px rgba(16, 185, 129, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.user-profile-theme-chip__swatch {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    0 1px 4px rgba(0, 0, 0, 0.22);
}

.user-profile-theme-chip__swatch--nodum {
  background: linear-gradient(135deg, #64748b 0%, #0f172a 100%);
}

.user-profile-theme-chip__swatch--forest {
  background: linear-gradient(135deg, #22c55e 0%, #14532d 100%);
}

.user-profile-theme-chip__swatch--ocean {
  background: linear-gradient(135deg, #38bdf8 0%, #1e3a8a 100%);
}

.user-profile-theme-chip__swatch--sunset {
  background: linear-gradient(135deg, #fb7185 0%, #f59e0b 100%);
}

.user-profile-theme-chip__swatch--mono {
  background: linear-gradient(135deg, #e2e8f0 0%, #475569 100%);
}

.user-profile-theme-chip__swatch--custom {
  background: linear-gradient(
    90deg,
    #ef4444 0%,
    #f59e0b 20%,
    #eab308 40%,
    #22c55e 60%,
    #3b82f6 80%,
    #8b5cf6 100%
  );
}

.user-profile-theme-chip:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.user-profile-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* Камера привязана к кругу аватара, а не ко всему блоку — не наезжает на «Удалить фото». */
.user-profile-avatar-stack {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-profile-avatar-input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.user-profile-avatar-wrap--editable .user-profile-avatar {
  cursor: pointer;
}

.user-profile-avatar-stack .user-profile-avatar-fab {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(15, 23, 42, 0.9);
  background: linear-gradient(145deg, #34d399, #059669);
  color: #022c22;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.user-profile-avatar-stack .user-profile-avatar-fab:hover {
  transform: scale(1.06);
  filter: brightness(1.05);
}

.user-profile-avatar-stack .user-profile-avatar-fab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

html[data-app-theme="light"] .user-profile-avatar-stack .user-profile-avatar-fab {
  border-color: #fff;
}

.user-profile-avatar-remove {
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-tertiary);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.user-profile-avatar-remove:hover {
  color: var(--accent);
}

.user-profile-avatar-error {
  margin: 0;
  max-width: 260px;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: #fecaca;
  text-align: center;
}

html[data-app-theme="light"] .user-profile-avatar-error {
  color: #b91c1c;
}

.user-profile-avatar {
  width: 96px;
  height: 96px;
  aspect-ratio: 1;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 2.25rem;
  line-height: 1;
  background: linear-gradient(145deg, #1e3a5f, #0f172a);
  color: var(--accent);
  border: 3px solid rgba(148, 163, 184, 0.2);
}

.user-profile-avatar > span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.user-profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-profile-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 12px 24px max(28px, calc(16px + env(safe-area-inset-bottom, 0px)));
  text-align: center;
}

.user-profile-name {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.user-profile-name-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 4px;
}

.user-profile-name-row .user-profile-name {
  margin: 0;
}

.user-profile-icon-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 9px;
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-secondary, #94a3b8);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.user-profile-icon-btn svg {
  width: 15px;
  height: 15px;
}

.user-profile-icon-btn:hover {
  background: rgba(52, 211, 153, 0.15);
  color: var(--accent, #34d399);
}

.user-profile-icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.user-profile-name-edit {
  width: 100%;
  max-width: 320px;
  margin: 0 auto 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.user-profile-name-edit label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.user-profile-name-edit input {
  font: inherit;
  font-size: 0.9375rem;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.45);
  color: var(--text-primary);
}

html[data-app-theme="light"] .user-profile-name-edit input {
  background: rgba(255, 255, 255, 0.85);
}

.user-profile-username-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 12px;
  width: 100%;
}

.user-profile-username-field {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
  max-width: min(280px, 100%);
}

.user-profile-username-prefix {
  color: var(--accent);
  font-weight: 600;
  font-size: 1.0625rem;
  flex-shrink: 0;
}

.user-profile-username-input {
  min-width: 0;
  flex: 1;
  font: inherit;
  font-size: 1.0625rem;
  font-weight: 600;
  text-transform: none;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.5);
  color: var(--accent);
}

html[data-app-theme="light"] .user-profile-username-input {
  background: rgba(255, 255, 255, 0.9);
}

.user-profile-username-hint,
.user-profile-username-error {
  width: 100%;
  margin: 4px 0 0;
  font-size: 0.75rem;
  line-height: 1.35;
  text-align: center;
}

.user-profile-username-hint {
  color: var(--text-tertiary);
}

.user-profile-username-error {
  color: #fecaca;
}

html[data-app-theme="light"] .user-profile-username-error {
  color: #b91c1c;
}

.user-profile-username {
  margin: 8px 0 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--accent);
  display: inline-block;
  border: none;
  background: none;
  padding: 0;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  width: 100%;
  line-height: 1.35;
  /* Показываем логин так, как сохранён на сервере (AdMin ≠ admin) */
  text-transform: none;
  font-variant: normal;
}

.user-profile-username--in-row {
  margin: 0;
  width: auto;
  flex: 0 1 auto;
  min-width: 0;
  text-align: center;
  font-size: 1.35rem;
  font-weight: 600;
}

.user-profile-username:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.user-profile-username:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

.user-profile-hint {
  margin: 14px 0 0;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--text-secondary);
}

.user-profile-actions {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.user-profile-btn {
  width: 100%;
  font: inherit;
  cursor: pointer;
  border-radius: 999px;
  padding: 12px 18px;
  font-size: 0.9375rem;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}

.user-profile-btn--primary {
  border: 1px solid var(--border-subtle);
  background: rgba(52, 211, 153, 0.12);
  color: var(--text-primary);
}

.user-profile-btn--primary:hover {
  background: rgba(52, 211, 153, 0.2);
}

.user-profile-btn--logout {
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: transparent;
  color: var(--text-secondary);
}

.user-profile-btn--logout:hover {
  border-color: rgba(248, 113, 113, 0.55);
  color: var(--text-primary);
  background: rgba(248, 113, 113, 0.08);
}

.user-profile-btn--secondary {
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-secondary);
}

.user-profile-btn--secondary:hover {
  color: var(--text-primary);
  background: rgba(148, 163, 184, 0.08);
}

.user-profile-chat-nav-wrap {
  display: flex;
  justify-content: center;
  margin: 10px 0 4px;
}

.user-profile-chat-nav-wrap--compact {
  margin-top: 10px;
}

.user-profile-btn--chat-nav {
  width: auto;
  min-width: 0;
  max-width: 100%;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  border: 1px solid rgba(52, 211, 153, 0.34);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
}

.user-profile-btn--chat-nav:hover {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border-color: rgba(52, 211, 153, 0.48);
}

.user-profile-bio-label {
  display: block;
  margin: 14px 0 8px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  text-align: left;
}

.user-profile-bio-label--contact {
  margin-top: 4px;
}

.user-profile-bio-input {
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.35);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.45;
  resize: none;
  min-height: 96px;
  max-height: 160px;
  text-align: left;
  vertical-align: top;
}

.user-profile-contact-input {
  min-height: 0;
  max-height: none;
  resize: none;
  margin: 0 0 12px;
  padding: 8px 2px 7px;
  border: none;
  border-bottom: 1px solid rgba(148, 163, 184, 0.55);
  border-radius: 0;
  background: transparent;
  color: var(--text-primary);
  font-size: 1rem;
}

.user-profile-contact-input::placeholder {
  color: color-mix(in srgb, var(--text-secondary) 82%, white 18%);
  opacity: 1;
}

.user-profile-contact-input:focus-visible {
  outline: none;
  border-bottom-color: var(--accent);
  box-shadow: 0 1px 0 0 var(--accent);
}

html[data-app-theme="light"] .user-profile-bio-input {
  background: #f8fafc;
}

html[data-app-theme="light"] .user-profile-contact-input {
  background: transparent;
  border-bottom-color: rgba(100, 116, 139, 0.55);
}

.user-profile-bio {
  margin: 14px 0 0;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

.user-profile-bio--contact {
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 500;
}

.user-profile-bio--empty {
  font-style: italic;
  opacity: 0.85;
}

.user-profile-bio-actions {
  margin-top: 6px;
  margin-bottom: 2px;
}

.user-profile-btn--save {
  transition:
    background 0.45s cubic-bezier(0.4, 0, 0.2, 1),
    border-color 0.45s ease,
    color 0.45s ease,
    transform 0.4s cubic-bezier(0.34, 1.4, 0.64, 1),
    box-shadow 0.4s ease;
}

.user-profile-btn--save-pending {
  opacity: 0.88;
  pointer-events: none;
}

.user-profile-btn--save-succeeded {
  background: linear-gradient(135deg, #047857, #34d399) !important;
  border-color: rgba(52, 211, 153, 0.45) !important;
  color: #ecfdf5 !important;
  box-shadow: 0 8px 28px rgba(52, 211, 153, 0.25);
  animation: userProfileSaveSuccess 0.55s cubic-bezier(0.34, 1.3, 0.64, 1) both;
}

@keyframes userProfileSaveSuccess {
  0% {
    transform: scale(0.94);
    opacity: 0.85;
  }
  55% {
    transform: scale(1.03);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.user-profile-save-error {
  margin: 10px 0 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: #fecaca;
  text-align: center;
}

html[data-app-theme="light"] .user-profile-save-error {
  color: #b91c1c;
}

.user-profile-peer-error {
  margin: 18px 0 0;
  padding: 12px 14px;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: #fecaca;
  text-align: left;
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.22);
  border-radius: 12px;
}

.user-profile-bio--empty + .user-profile-peer-error {
  margin-top: 14px;
}

.user-profile-peer-error + .user-profile-actions--friend {
  margin-top: 16px;
}

.user-profile-actions--friend {
  margin-top: 16px;
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.user-profile-actions--friend .user-profile-btn {
  padding: 10px 22px;
  max-width: min(100%, 320px);
  margin-left: auto;
  margin-right: auto;
}

.user-profile-actions--friend .user-profile-btn--secondary {
  max-width: min(100%, 320px);
}

.user-profile-actions--friend .user-profile-btn--remove-friend {
  max-width: none;
  width: auto;
}

.user-profile-friend-row-wrap {
  display: flex;
  justify-content: center;
  width: 100%;
}

.user-profile-friend-row {
  display: inline-flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  max-width: 100%;
}

@media (max-width: 480px) {
  .user-profile-friend-row {
    flex-direction: column;
    align-items: center;
  }
}

.user-profile-friend-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.25);
}

.user-profile-btn--remove-friend {
  width: auto;
  padding: 8px 14px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: rgba(248, 113, 113, 0.75);
  background: rgba(248, 113, 113, 0.05);
  border: 1px solid rgba(248, 113, 113, 0.18);
  border-radius: 999px;
  max-width: none;
  margin: 0;
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease;
}

.user-profile-btn--remove-friend:hover:not(:disabled) {
  color: rgba(248, 113, 113, 0.95);
  background: rgba(248, 113, 113, 0.09);
  border-color: rgba(248, 113, 113, 0.28);
}

.user-profile-btn--remove-friend:focus-visible {
  outline: 2px solid rgba(248, 113, 113, 0.45);
  outline-offset: 2px;
}

.user-profile-btn--remove-friend:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

html[data-app-theme="light"] .user-profile-btn--remove-friend {
  color: rgba(185, 28, 28, 0.85);
  background: rgba(248, 113, 113, 0.08);
  border-color: rgba(248, 113, 113, 0.22);
}

html[data-app-theme="light"] .user-profile-btn--remove-friend:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.32);
}

/* Кликабельная шапка диалога с собеседником */
.dialog-header-main--peer {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 4px 8px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.dialog-header-main--peer:hover {
  background: rgba(148, 163, 184, 0.08);
}

.dialog-header-main--peer:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Модалка «Тема этого чата» (раньше стили жили в ios/styles; в бандл идёт app-ui) --- */

.sheet.sheet--chat-theme {
  z-index: 10050;
  margin: auto;
  padding: 0;
  border: none;
  border-radius: 22px;
  width: min(460px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  max-height: min(92dvh, 760px);
  overflow: hidden;
  color: var(--text-primary, #f1f5f9);
  background: linear-gradient(
      155deg,
      color-mix(in srgb, var(--panel-bg, #121a2a) 92%, #34d399) 0%,
      var(--panel-bg, #121a2a) 42%,
      color-mix(in srgb, var(--panel-bg, #121a2a) 88%, #0f172a) 100%
    ),
    var(--panel-bg, #121a2a);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.07),
    0 28px 90px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

/* Без dvi — остаётся vw в блоке .sheet.sheet--chat-theme выше. */
@supports (width: 1dvi) {
  .sheet.sheet--chat-theme {
    width: min(460px, calc(100dvi - 24px));
    max-width: calc(100dvi - 24px);
  }
}

.sheet.sheet--chat-theme::backdrop {
  background: rgba(4, 8, 18, 0.62);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

html[data-app-theme="light"] .sheet.sheet--chat-theme {
  background: linear-gradient(
      155deg,
      #ffffff 0%,
      #f8fafc 45%,
      #f1f5f9 100%
    );
  color: #0f172a;
  box-shadow:
    0 0 0 1px rgba(15, 23, 42, 0.08),
    0 28px 70px rgba(15, 23, 42, 0.12);
}

.sheet.sheet--chat-theme .sheet__inner {
  max-height: min(92dvh, 760px);
  padding: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sheet.sheet--chat-theme .sheet__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-shrink: 0;
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.12));
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.03) 0%,
    transparent 100%
  );
}

html[data-app-theme="light"] .sheet.sheet--chat-theme .sheet__head {
  border-bottom-color: rgba(15, 23, 42, 0.08);
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.85) 0%,
    transparent 100%
  );
}

.sheet__head-main {
  min-width: 0;
  flex: 1;
}

.sheet__kicker {
  margin: 0 0 4px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-tertiary, #64748b);
}

.sheet.sheet--chat-theme .sheet__title {
  margin: 0;
  font-size: 1.1875rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.25;
}

.sheet__close {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.18));
  background: rgba(148, 163, 184, 0.08);
  color: inherit;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.12s ease;
}

.sheet__close:hover {
  background: rgba(148, 163, 184, 0.14);
  border-color: rgba(52, 211, 153, 0.35);
}

.sheet__close:focus-visible {
  outline: 2px solid var(--accent, #34d399);
  outline-offset: 2px;
}

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

.sheet__lead-box {
  flex-shrink: 0;
  padding: 14px 20px 16px;
}

.sheet__lead {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--text-secondary, #94a3b8);
}

html[data-app-theme="light"] .sheet__lead {
  color: #64748b;
}

.sheet.sheet--chat-theme .theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 10px;
  padding: 4px 20px 8px;
  margin: 0;
}

.sheet.sheet--chat-theme .theme-custom-panel {
  border-top: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.12));
  padding: 16px 20px 22px;
  background: rgba(0, 0, 0, 0.12);
}

html[data-app-theme="light"] .sheet.sheet--chat-theme .theme-custom-panel {
  background: rgba(241, 245, 249, 0.65);
  border-top-color: rgba(15, 23, 42, 0.08);
}

.theme-preset {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  min-height: 118px;
  padding: 14px 10px 12px;
  border-radius: 16px;
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.14));
  background: rgba(148, 163, 184, 0.06);
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: center;
  transition:
    box-shadow 0.18s ease,
    border-color 0.18s ease,
    transform 0.15s ease,
    background 0.18s ease;
}

.theme-preset:hover {
  border-color: rgba(52, 211, 153, 0.38);
  background: rgba(52, 211, 153, 0.06);
  transform: translateY(-1px);
}

.theme-preset:focus-visible {
  outline: 2px solid var(--accent, #34d399);
  outline-offset: 2px;
}

.theme-preset.is-active {
  border-color: var(--accent, #34d399);
  box-shadow:
    0 0 0 2px rgba(52, 211, 153, 0.22),
    0 12px 28px rgba(0, 0, 0, 0.25);
  background: rgba(52, 211, 153, 0.08);
}

.theme-preset__ring {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  box-shadow:
    0 10px 26px rgba(0, 0, 0, 0.42),
    0 2px 8px rgba(0, 0, 0, 0.2),
    inset 0 2px 0 rgba(255, 255, 255, 0.22),
    inset 0 -10px 22px rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

.theme-preset__ring--custom {
  background: conic-gradient(
    from 210deg,
    #34d399,
    #38bdf8,
    #a78bfa,
    #f472b6,
    #fbbf24,
    #34d399
  );
}

.theme-preset__name {
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.3;
}

.theme-custom-panel[hidden] {
  display: none !important;
}

.theme-custom-panel__hint {
  margin: 0 0 12px;
  font-size: 0.8125rem;
  color: var(--text-secondary, #94a3b8);
  line-height: 1.45;
}

html[data-app-theme="light"] .theme-custom-panel__hint {
  color: #64748b;
}

.theme-custom-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
  margin-bottom: 12px;
}

.theme-custom-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-secondary, #94a3b8);
}

html[data-app-theme="light"] .theme-custom-field {
  color: #64748b;
}

.theme-custom-field input[type="color"] {
  width: 100%;
  height: 42px;
  padding: 3px;
  border-radius: 11px;
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.22));
  background: rgba(0, 0, 0, 0.22);
  cursor: pointer;
}

html[data-app-theme="light"] .theme-custom-field input[type="color"] {
  background: #e2e8f0;
}

.theme-custom-reset {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.22));
  background: rgba(148, 163, 184, 0.08);
  color: inherit;
  font: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.theme-custom-reset:hover {
  border-color: rgba(52, 211, 153, 0.45);
  background: rgba(52, 211, 153, 0.1);
}

@media (prefers-reduced-motion: reduce) {
  .theme-preset {
    transition: none;
  }

  .theme-preset:hover {
    transform: none;
  }

  @media (max-width: 904px) {
    .layout > .sidebar,
    .layout > .dialog {
      transition: none;
    }

    .layout[data-view="dialog"] > .sidebar {
      transform: none;
      opacity: 1;
      filter: none;
    }
  }
}

/* Уважение prefers-reduced-transparency: убираем blur «материала», оставляем полупрозрачные заливки */
@media (prefers-reduced-transparency: reduce) {
  .sidebar,
  .app-rail,
  .sidebar-head,
  .dialog-header,
  .composer,
  .layout[data-view="dialog"] .dialog-header,
  .layout[data-view="dialog"] .composer,
  .search-field,
  .composer-input,
  .composer-attach-btn,
  .composer-send,
  .btn-chat-preset,
  .btn-mobile-rail,
  .layout[data-view="dialog"] .dialog-header .btn-back,
  .mobile-rail-dialog__panel,
  .delete-chat-dialog,
  .message-ctx-menu,
  .message-line,
  .message-body,
  .composer-banner,
  .chat-item:hover,
  .chat-item.active,
  .app-rail__btn:hover,
  .app-rail__btn--active,
  .btn-icon:hover,
  .message-photo-lightbox__reset {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
  }
}
