/* Мобильный стек навигации: все экраны выезжают справа (Telegram / WhatsApp). */

body.mobile-nav-stack .container,
body.mobile-chat-stack .container {
  position: relative;
  overflow: hidden;
  max-width: 100% !important;
  overscroll-behavior-x: none;
}

body.mobile-nav-stack #chatListScreen,
body.mobile-chat-stack #chatListScreen {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  max-height: 100vh;
  flex: none !important;
  z-index: 1;
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform;
  backface-visibility: hidden;
  transform: translateX(0);
}

body.mobile-nav-stack #chatScreen,
body.mobile-nav-stack #searchScreen,
body.mobile-nav-stack #contactInfoScreen,
body.mobile-nav-stack #mediaGalleryScreen,
body.mobile-nav-stack #callsScreen,
body.mobile-nav-stack #blockedListScreen,
body.mobile-chat-stack #chatScreen {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  max-height: 100vh;
  flex: none !important;
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform;
  backface-visibility: hidden;
  transform: translateX(100%);
  box-shadow: -2px 0 12px rgba(0, 0, 0, 0.08);
}

/* —— Уровень 1: чат / поиск / звонки / чёрный список —— */
body.mobile-nav-stack[data-mobile-screen='chatScreen'] #chatListScreen,
body.mobile-chat-stack[data-mobile-screen='chatScreen'] #chatListScreen,
body.mobile-nav-stack[data-mobile-screen='chatScreen'] #chatListScreen {
  transform: translateX(-18%);
}

body.mobile-nav-stack[data-mobile-screen='chatScreen'] #chatScreen,
body.mobile-chat-stack.mobile-chat-open #chatScreen,
body.mobile-nav-stack[data-mobile-screen='chatScreen'] #chatScreen {
  transform: translateX(0);
  z-index: 2;
}

body.mobile-nav-stack[data-mobile-screen='searchScreen'] #chatListScreen {
  transform: translateX(-18%);
}

body.mobile-nav-stack[data-mobile-screen='searchScreen'] #searchScreen {
  transform: translateX(0);
  z-index: 2;
}

body.mobile-nav-stack[data-mobile-screen='callsScreen'] #chatListScreen {
  transform: translateX(-18%);
}

body.mobile-nav-stack[data-mobile-screen='callsScreen'] #callsScreen {
  transform: translateX(0);
  z-index: 2;
}

body.mobile-nav-stack[data-mobile-screen='blockedListScreen'] #chatListScreen {
  transform: translateX(-18%);
}

body.mobile-nav-stack[data-mobile-screen='blockedListScreen'] #blockedListScreen {
  transform: translateX(0);
  z-index: 2;
}

/* —— Профиль: уровень 1 (из списка) или 2 (из чата) —— */
body.mobile-nav-stack[data-mobile-screen='contactInfoScreen']:not([data-mobile-has-chat]) #chatListScreen {
  transform: translateX(-18%);
}

body.mobile-nav-stack[data-mobile-screen='contactInfoScreen']:not([data-mobile-has-chat]) #contactInfoScreen {
  transform: translateX(0);
  z-index: 2;
}

body.mobile-nav-stack[data-mobile-screen='contactInfoScreen'][data-mobile-has-chat] #chatListScreen {
  transform: translateX(-36%);
}

body.mobile-nav-stack[data-mobile-screen='contactInfoScreen'][data-mobile-has-chat] #chatScreen {
  transform: translateX(-18%);
  z-index: 2;
}

body.mobile-nav-stack[data-mobile-screen='contactInfoScreen'][data-mobile-has-chat] #contactInfoScreen {
  transform: translateX(0);
  z-index: 3;
}

/* —— Медиа-галерея —— */
body.mobile-nav-stack[data-mobile-screen='mediaGalleryScreen']:not([data-mobile-has-profile]):not([data-mobile-has-chat]) #chatListScreen {
  transform: translateX(-18%);
}

body.mobile-nav-stack[data-mobile-screen='mediaGalleryScreen']:not([data-mobile-has-profile]):not([data-mobile-has-chat]) #mediaGalleryScreen {
  transform: translateX(0);
  z-index: 2;
}

body.mobile-nav-stack[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-chat]:not([data-mobile-has-profile]) #chatListScreen {
  transform: translateX(-36%);
}

body.mobile-nav-stack[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-chat]:not([data-mobile-has-profile]) #chatScreen {
  transform: translateX(-18%);
  z-index: 2;
}

body.mobile-nav-stack[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-chat]:not([data-mobile-has-profile]) #mediaGalleryScreen {
  transform: translateX(0);
  z-index: 3;
}

body.mobile-nav-stack[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-profile]:not([data-mobile-has-chat]) #chatListScreen {
  transform: translateX(-36%);
}

body.mobile-nav-stack[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-profile]:not([data-mobile-has-chat]) #contactInfoScreen {
  transform: translateX(-18%);
  z-index: 2;
}

body.mobile-nav-stack[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-profile]:not([data-mobile-has-chat]) #mediaGalleryScreen {
  transform: translateX(0);
  z-index: 3;
}

body.mobile-nav-stack[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-chat][data-mobile-has-profile] #chatListScreen {
  transform: translateX(-54%);
}

body.mobile-nav-stack[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-chat][data-mobile-has-profile] #chatScreen {
  transform: translateX(-36%);
  z-index: 2;
}

body.mobile-nav-stack[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-chat][data-mobile-has-profile] #contactInfoScreen {
  transform: translateX(-18%);
  z-index: 3;
}

body.mobile-nav-stack[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-chat][data-mobile-has-profile] #mediaGalleryScreen {
  transform: translateX(0);
  z-index: 4;
}

/* —— Жест «назад» —— */
body.mobile-nav-back-drag #chatScreen,
body.mobile-nav-back-drag #searchScreen,
body.mobile-nav-back-drag #contactInfoScreen,
body.mobile-nav-back-drag #mediaGalleryScreen,
body.mobile-nav-back-drag #callsScreen,
body.mobile-nav-back-drag #blockedListScreen,
body.mobile-chat-back-drag #chatScreen {
  transition: none;
}

body.mobile-nav-back-drag #chatListScreen,
body.mobile-chat-back-drag #chatListScreen {
  transition: none;
}

body.mobile-nav-back-drag[data-mobile-screen='chatScreen'] #chatScreen,
body.mobile-chat-back-drag[data-mobile-screen='chatScreen'] #chatScreen {
  transform: translateX(calc(var(--mobile-nav-dismiss-progress, var(--mobile-chat-dismiss-progress, 0)) * 100%));
}

body.mobile-nav-back-drag[data-mobile-screen='chatScreen'] #chatListScreen,
body.mobile-chat-back-drag[data-mobile-screen='chatScreen'] #chatListScreen {
  transform: translateX(calc(-18% * (1 - var(--mobile-nav-dismiss-progress, var(--mobile-chat-dismiss-progress, 0)))));
}

body.mobile-nav-back-drag[data-mobile-screen='searchScreen'] #searchScreen {
  transform: translateX(calc(var(--mobile-nav-dismiss-progress, 0) * 100%));
}

body.mobile-nav-back-drag[data-mobile-screen='searchScreen'] #chatListScreen {
  transform: translateX(calc(-18% + var(--mobile-nav-dismiss-progress, 0) * 18%));
}

body.mobile-nav-back-drag[data-mobile-screen='callsScreen'] #callsScreen {
  transform: translateX(calc(var(--mobile-nav-dismiss-progress, 0) * 100%));
}

body.mobile-nav-back-drag[data-mobile-screen='callsScreen'] #chatListScreen {
  transform: translateX(calc(-18% + var(--mobile-nav-dismiss-progress, 0) * 18%));
}

body.mobile-nav-back-drag[data-mobile-screen='blockedListScreen'] #blockedListScreen {
  transform: translateX(calc(var(--mobile-nav-dismiss-progress, 0) * 100%));
}

body.mobile-nav-back-drag[data-mobile-screen='blockedListScreen'] #chatListScreen {
  transform: translateX(calc(-18% + var(--mobile-nav-dismiss-progress, 0) * 18%));
}

body.mobile-nav-back-drag[data-mobile-screen='contactInfoScreen']:not([data-mobile-has-chat]) #contactInfoScreen {
  transform: translateX(calc(var(--mobile-nav-dismiss-progress, 0) * 100%));
}

body.mobile-nav-back-drag[data-mobile-screen='contactInfoScreen']:not([data-mobile-has-chat]) #chatListScreen {
  transform: translateX(calc(-18% + var(--mobile-nav-dismiss-progress, 0) * 18%));
}

body.mobile-nav-back-drag[data-mobile-screen='contactInfoScreen'][data-mobile-has-chat] #contactInfoScreen {
  transform: translateX(calc(var(--mobile-nav-dismiss-progress, 0) * 100%));
}

body.mobile-nav-back-drag[data-mobile-screen='contactInfoScreen'][data-mobile-has-chat] #chatScreen {
  transform: translateX(calc(-18% + var(--mobile-nav-dismiss-progress, 0) * 18%));
}

body.mobile-nav-back-drag[data-mobile-screen='contactInfoScreen'][data-mobile-has-chat] #chatListScreen {
  transform: translateX(calc(-36% + var(--mobile-nav-dismiss-progress, 0) * 18%));
}

body.mobile-nav-back-drag[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-chat][data-mobile-has-profile] #mediaGalleryScreen {
  transform: translateX(calc(var(--mobile-nav-dismiss-progress, 0) * 100%));
}

body.mobile-nav-back-drag[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-chat][data-mobile-has-profile] #contactInfoScreen {
  transform: translateX(calc(-18% + var(--mobile-nav-dismiss-progress, 0) * 18%));
}

body.mobile-nav-back-drag[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-chat][data-mobile-has-profile] #chatScreen {
  transform: translateX(calc(-36% + var(--mobile-nav-dismiss-progress, 0) * 18%));
}

body.mobile-nav-back-drag[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-chat][data-mobile-has-profile] #chatListScreen {
  transform: translateX(calc(-54% + var(--mobile-nav-dismiss-progress, 0) * 18%));
}

body.mobile-nav-back-drag[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-chat]:not([data-mobile-has-profile]) #mediaGalleryScreen {
  transform: translateX(calc(var(--mobile-nav-dismiss-progress, 0) * 100%));
}

body.mobile-nav-back-drag[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-chat]:not([data-mobile-has-profile]) #chatScreen {
  transform: translateX(calc(-18% + var(--mobile-nav-dismiss-progress, 0) * 18%));
}

body.mobile-nav-back-drag[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-chat]:not([data-mobile-has-profile]) #chatListScreen {
  transform: translateX(calc(-36% + var(--mobile-nav-dismiss-progress, 0) * 18%));
}

body.mobile-nav-back-drag[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-profile]:not([data-mobile-has-chat]) #mediaGalleryScreen {
  transform: translateX(calc(var(--mobile-nav-dismiss-progress, 0) * 100%));
}

body.mobile-nav-back-drag[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-profile]:not([data-mobile-has-chat]) #contactInfoScreen {
  transform: translateX(calc(-18% + var(--mobile-nav-dismiss-progress, 0) * 18%));
}

body.mobile-nav-back-drag[data-mobile-screen='mediaGalleryScreen'][data-mobile-has-profile]:not([data-mobile-has-chat]) #chatListScreen {
  transform: translateX(calc(-36% + var(--mobile-nav-dismiss-progress, 0) * 18%));
}

#chatScreen .chat-header-back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-right: 8px;
  padding: 8px 4px;
  min-width: 40px;
  min-height: 40px;
  cursor: pointer;
  font-size: 18px;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

.mobile-swipe-back-body {
  flex: 1 1 0%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  body.mobile-nav-stack #chatListScreen,
  body.mobile-nav-stack #chatScreen,
  body.mobile-nav-stack #searchScreen,
  body.mobile-nav-stack #contactInfoScreen,
  body.mobile-nav-stack #mediaGalleryScreen,
  body.mobile-nav-stack #callsScreen,
  body.mobile-nav-stack #blockedListScreen {
    transition: none;
  }
}
