/* ═══════════════════════════════════════════════════════════
   responsive-layout.css
   Адаптивность для основного интерфейса мессенджера
   ═══════════════════════════════════════════════════════════ */

/* 1. Общие исправления для мобильных */
@media (max-width: 768px) {
  #main-chat {
    padding: 0 !important; /* Убираем отступы на мобилках */
    gap: 0 !important;
  }

  .left-panel, #view-chat, #info-panel {
    border-radius: 0 !important; /* На фулл-скрине не нужны скругления */
    border: none !important;
    box-shadow: none !important;
  }
}

/* 2. Логика переключения панелей (Чаты vs Сообщения) */
@media (max-width: 768px) {
  /* По умолчанию на мобилках показываем только одну панель */

  /* Если открыт чат, стена или просмотр медиа (есть соответствующие классы у body) */
  body.chat-open #left-panel,
  body.wall-open #left-panel,
  body.comments-view-open #left-panel {
    display: none !important;
  }

  body:not(.chat-open):not(.wall-open):not(.comments-view-open):not(.feed-open) #view-chat {
    display: none !important;
  }

  body.wall-open #view-chat,
  body.comments-view-open #view-chat,
  body.feed-open #view-chat {
    display: none !important;
  }

  #left-panel {
    width: 100% !important;
    flex-basis: 100% !important;
  }

  #view-chat {
    width: 100% !important;
    flex-basis: 100% !important;
  }

  /* Инфо-панель на мобилках должна быть поверх или на весь экран */
  #info-panel:not(.hidden) {
    position: fixed;
    top: 0;
    left: 0;
    width: 100% !important;
    max-width: 100% !important;
    height: 100%;
    z-index: 100;
    flex-basis: 100% !important;
  }
}

/* 3. Landing Page Исправления */
@media (max-width: 640px) {
  #logo-wrap {
    width: 280px !important;
    height: 280px !important;
    margin-left: -110px !important;
    margin-top: -110px !important;
  }

  .home-hero-title {
    font-size: 1.5rem !important;
  }

  #landing-page .p-12 {
    padding: 1.5rem !important;
  }
}

/* 4. Bottom Dock Адаптация */
@media (max-width: 640px) {
  #bottom-dock {
    bottom: 10px;
    padding: 4px 8px;
    border-radius: 16px;
    gap: 0;
  }

  .dock-btn {
    width: 40px;
    height: 40px;
  }
}

/* 5. Убираем горизонтальный скролл везде */
html, body {
  overflow-x: hidden;
  width: 100%;
  position: relative;
}

/* Исправляем слишком широкие элементы в чате */
#messages-container {
  padding: 1rem !important;
}

.message-bubble {
  max-width: 85% !important;
}

/* 6. Адаптация кнопок и инпутов */
@media (max-width: 480px) {
  .nc-result-item {
    padding: 10px !important;
  }

  #chat-header {
    padding: 0.75rem !important;
  }

  #active-chat-name {
    font-size: 0.95rem !important;
  }
}

@media (max-width: 400px) {
  /* Мелкие правки для очень узких экранов */
}

/* 7. Исправление media-sidebar в просмотре медиа */
@media (min-width: 769px) {
  #media-sidebar {
    height: 100% !important;
  }
}

@media (max-width: 768px) {
  #wall-comments-overlay {
    padding: 0 !important;
    align-items: stretch !important;
  }

  .wall-comments-panel {
    display: flex !important;
    flex-direction: column !important;
    height: 100dvh !important;        /* dynamic viewport — iOS Safari учитывает адресную строку */
    height: 100vh !important;         /* fallback для старых браузеров */
    max-height: 100dvh !important;
    border-radius: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
  }

  /* Панель кнопок — ВВЕРХУ на мобилке */
  #media-sidebar {
    order: 1 !important;
    width: 100% !important;
    height: auto !important;
    min-height: 52px !important;
    flex-shrink: 0 !important;
    display: flex !important;
    flex-direction: row !important;
    padding: 6px 8px !important;
    border-right: none !important;
    border-top: none !important;
    border-bottom: 1px solid rgba(255,255,255,0.1) !important;
    justify-content: space-around !important;
    align-items: center !important;
    gap: 0 !important;
    background: rgba(0,0,0,0.85) !important;
    z-index: 10 !important;
  }

  .media-sidebar-btn {
    width: auto !important;
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    padding: 4px 0 !important;
  }

  .media-sidebar-btn span:last-child {
    display: none !important; /* Прячем подписи на мобилках */
  }

  #wall-comments-media-container {
    order: 2 !important;
    flex: 1 1 0% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: calc(100dvh - 52px);
    display: flex !important;
  }

  #comments-right-panel {
    order: 3 !important;
    width: 100% !important;
    min-width: 100% !important;
    flex: 0 0 auto !important;
    display: flex !important;
    height: 0;
    max-height: none !important;
    opacity: 0;
    overflow: hidden !important;
    border-left: none !important;
    border-top: 1px solid rgba(255,255,255,0.1) !important;
    transition: height 0.3s ease, opacity 0.3s ease !important;
  }

  /* Скрываем разделители в горизонтальном режиме */
  #media-sidebar div[style*="height:0.5px"] {
    display: none !important;
  }
}

@media (max-width: 640px) {
  .wall-comments-panel {
    /* Уже обработано выше в 768px, но можно добавить специфику если надо */
  }
}

/* Компактный лайк */
.like-sidebar-count {
  min-height: 0 !important;
  position: absolute;
  bottom: -2px;
  right: -2px;
  background: var(--accent-color);
  color: white;
  padding: 1px 4px;
  border-radius: 6px;
  font-size: 8px !important;
}


/* ── iOS Safari safe-area (навигационная панель снизу) ── */
@supports (padding: env(safe-area-inset-bottom)) {
  @media (max-width: 768px) {

    /* Инпут в чате — поднимаем над панелью Safari */
    #input-area {
      padding-bottom: calc(12px + env(safe-area-inset-bottom)) !important;
    }

    /* Bottom dock — тоже поднимаем */
    #bottom-dock {
      bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    }

    /* Заголовок чата — отступ сверху (notch/dynamic island) */
    #chat-header {
      padding-top: calc(0.75rem + env(safe-area-inset-top)) !important;
    }
  }
}

/* ── Кнопки лендинга на мобилке ── */
@media (max-width: 640px) {
  #btn-register,
  #btn-login {
    width: auto !important;
    padding: 10px 32px !important;
    font-size: 0.9rem !important;
  }
}

/* ── Auth modal на мобилке ── */
@media (max-width: 640px) {
  #auth-modal {
    max-width: 320px !important;
    border-radius: 20px !important;
  }

  #auth-modal input {
    padding: 10px 14px !important;
    font-size: 0.875rem !important;
  }

  #auth-modal h2 {
    font-size: 1.25rem !important;
  }
}

/* ── Toast уведомления на мобилке ── */
@media (max-width: 640px) {
  #notification-center {
    top: 10px !important;
    right: 10px !important;
    left: 10px !important;
  }

  .app-toast {
    min-width: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    padding: 7px 14px !important;
    font-size: 11px !important;
  }
}

/* ── Wall (профиль) на мобилке ── */
@media (max-width: 640px) {

  /* Модал на весь экран */
  #wall-overlay {
    padding: 0 !important;
    align-items: flex-start !important;
    overflow-y: auto !important;
  }

  #wall-modal {
    height: auto !important;
    min-height: 100dvh !important;
    max-height: none !important;
    border-radius: 0 !important;
    overflow: visible !important;
  }

  /* Контент: вертикально, без лишнего отступа */
  #wall-modal > .flex-grow {
    flex-direction: column !important;
    overflow: visible !important;
    padding: 12px !important;
    margin-top: 36px !important;
    gap: 12px !important;
  }

  /* Уменьшаем баннер на мобилке */
  .wall-header-section {
    height: 120px !important;
    flex-shrink: 0 !important;
  }

  /* Аватарка + имя — подтягиваем */
  .wall-header-section .absolute.-bottom-12 {
    bottom: -32px !important;
  }

  #wall-avatar {
    width: 64px !important;
    height: 64px !important;
  }

  #wall-username {
    font-size: 1.2rem !important;
  }

  /* Левый сайдбар — компактный, показывается над постами */
  #wall-left-sidebar {
    display: block !important;
    width: 100% !important;
    order: 0 !important;
  }

  #wall-info-sidebar-box {
    padding: 8px 12px !important;
  }

  #wall-left-sidebar.wall-sidebar-hidden {
    display: none !important;
  }
  display: none !important;
}

/* Кнопка Медиа — скрываем, она есть в табах */
#wall-media-preview-box {
  display: none !important;
}

/* Bio и инфо-строки — мелкий шрифт в одну строку */
#wall-info-sidebar-box .space-y-2 {
  display: flex !important;
  flex-wrap: wrap !important;
  gap: 4px 12px !important;
}

#wall-info-sidebar-box .space-y-2 > div {
  margin: 0 !important;
}

#wall-info-sidebar-box {
  padding: 12px !important;
}

/* Правая колонка — занимает всё оставшееся место */
#wall-modal > .flex-grow > .flex-grow {
  overflow: visible !important;
  min-height: 0 !important;
}

/* Scrollable area внутри постов — не обрезать */
#wall-modal .scrollbar-hide {
  overflow: visible !important;
  flex-grow: 0 !important;
}

/* ── Скрываем скроллбар у wall на мобилке ── */
@media (max-width: 640px) {
  #wall-overlay,
  #wall-modal {
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
  }
  #wall-overlay::-webkit-scrollbar,
  #wall-modal::-webkit-scrollbar {
    display: none !important;
  }
}

/* ── iOS Safari: фикс высоты основного layout ── */
@media (max-width: 768px) {

  /* body и html на полный динамический viewport */
  html, body {
    height: 100dvh !important;
    height: 100vh !important; /* fallback */
    overflow: hidden !important;
  }

  /* Корневой контейнер приложения */
  #main-chat {
    height: 100dvh !important;
    height: 100vh !important;
    max-height: 100dvh !important;
  }

  /* left-panel и view-chat — полная высота */
  .left-panel,
  #view-chat {
    height: 100dvh !important;
    height: 100vh !important;
    max-height: 100dvh !important;
  }

  #messages-container {
    width: 100% !important;
    padding: 12px 10px !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }

  /* Все строки сообщений — не шире контейнера, но не обрезаем кнопки голосования */
  #messages-container [data-msg-id] {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Пузырьки */
  .message-bubble {
    max-width: 65vw !important;
    min-width: 60px !important;
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
  }
}

/* ── iOS клавиатура и input area ── */
@media (max-width: 768px) {

  /* Убираем overflow:hidden с body — иначе iOS не поднимает экран при клавиатуре */
  html, body {
    overflow: hidden auto !important;
  }

  /* Input area — компактнее */
  #input-area {
    padding: 8px 10px !important;
  }

  #message-form {
    gap: 6px !important;
    align-items: center !important;
  }

  /* AI кнопка — меньше на мобилке */
  #ai-btn {
    transform: scale(0.75) !important;
    flex-shrink: 0 !important;
    margin: 0 -4px !important;
  }

  /* Кнопка прикрепить — меньше */
  #attach-btn {
    padding: 8px !important;
    flex-shrink: 0 !important;
  }

  /* Кнопка отправить — меньше, не обрезается */
  #send-btn {
    padding: 8px 12px !important;
    flex-shrink: 0 !important;
    border-radius: 14px !important;
  }

  #send-btn svg {
    width: 20px !important;
    height: 20px !important;
  }
}

/* ── Кнопки голосования на мобилке — не вылезают за экран ── */
@media (max-width: 768px) {
  [data-msg-id]:hover .msg-votes:not(.msg-votes-hidden),
  .msg-votes.has-active:not(.msg-votes-hidden) {
    right: -36px !important;
  }

  .vote-btn {
    width: 26px !important;
    height: 26px !important;
    font-size: 13px !important;
  }
}

.gooey-vote-container {
  filter: none !important;
  inset: 0 !important;
}

/* ══════════════════════════════════════════════════════
   ══ МОБИЛЬНЫЙ LAYOUT НАД ДОКОМ — переопределяет выше
══════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* main-chat заканчивается над доком, не на весь экран */
  #main-chat {
    height: auto !important;
    max-height: none !important;
    top: 12px !important;
    bottom: var(--panel-bottom, 96px) !important;
    position: fixed !important;
    left: 12px !important;
    right: 12px !important;
    width: auto !important;
    overflow: hidden !important;
  }

  /* left-panel и view-chat — полная высота внутри main-chat */
  .left-panel,
  #view-chat {
    height: 100% !important;
    max-height: 100% !important;
    /* НЕ 100dvh — высота берётся от родителя */
  }

  /* ── Слайд-анимация: список чатов и чат ── */
  /* Список чатов: по центру (занимает весь main-chat) */
  #left-panel {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    transform: translateX(0);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.3s ease;
    z-index: 2;
  }

  /* При открытом чате список уезжает влево */
  body.chat-open #left-panel {
    transform: translateX(-100%) !important;
    pointer-events: none;
  }

  /* Чат: изначально спрятан вправо */
  #view-chat {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.3s ease;
    z-index: 3;
  }

  /* При открытом чате — чат въезжает по центру */
  body.chat-open #view-chat {
    transform: translateX(0) !important;
    display: flex !important;
  }

  /* display:none от JS не должен перебивать анимацию */
  body.chat-open #view-chat[style*="display: none"] {
    display: flex !important;
  }
}

/* ══ ФИНАЛЬНЫЙ ОВЕРРАЙД: высоты на мобильном ══ */
@media (max-width: 768px) {
  /* Перебиваем height: 100dvh у left-panel и view-chat */
  #main-chat > #left-panel,
  #main-chat > #view-chat,
  #main-chat .left-panel,
  #main-chat #view-chat {
    height: 100% !important;
    max-height: 100% !important;
    width: 100% !important;
  }
}

/* ══ iOS-style скругления на мобильном (без изменения фона) ══ */
@media (max-width: 768px) {

  /* Скругления всегда, но рамка — только когда есть контент */
  #main-chat {
    border-radius: 28px !important;
    overflow: hidden !important;
    border: none !important;
  }

  body.panel-open #main-chat {
    border: 1px solid rgba(255, 255, 255, 0.10) !important;
  }

  /* Тёмные темы */
  body.panel-open.theme-gray #main-chat,
  body.panel-open.theme-twilight #main-chat,
  body.panel-open.theme-ocean #main-chat,
  body.panel-open.theme-dark-gold #main-chat,
  body.panel-open.theme-jungle #main-chat,
  body.panel-open.theme-blood #main-chat,
  body.panel-open.theme-cyberpunk #main-chat,
  body.panel-open.theme-cosmos #main-chat,
  body.panel-open.theme-amethyst #main-chat,
  body.panel-open.theme-volcano #main-chat {
    border: 1px solid rgba(255, 255, 255, 0.06) !important;
  }

  /* Панели внутри — скруглённые */
  #main-chat #left-panel,
  #main-chat .left-panel {
    border-radius: 28px !important;
  }

  #main-chat #view-chat {
    border-radius: 28px !important;
  }

  /* Шапка чата — скруглена сверху */
  #chat-header {
    border-radius: 28px 28px 0 0 !important;
  }

  /* Поле ввода — скруглено снизу */
  #input-area {
    border-radius: 0 0 28px 28px !important;
  }

  /* Wall и другие оверлеи */
  #wall-modal {
    border-radius: 28px 28px 0 0 !important;
    border-top: 1px solid rgba(255, 255, 255, 0.15) !important;
  }

  .new-chat-modal-card {
    border-radius: 28px 28px 0 0 !important;
    border-top: 1px solid rgba(255, 255, 255, 0.15) !important;
  }

  #auth-modal {
    border-radius: 28px !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    backdrop-filter: blur(40px) saturate(180%) !important;
    -webkit-backdrop-filter: blur(40px) saturate(180%) !important;
  }
}