@media (max-width: 1024px) {

  /* Сам popup */
  #form1.t-popup {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    background: #fff !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    z-index: 999999 !important;
    padding-top: calc(env(safe-area-inset-top, 20px) + 40px) !important;
  }

  /* Контейнер формы */
  #form1 .t-popup__container {
    min-height: calc(100dvh - 60px) !important;
    margin: 0 auto !important;
    padding-bottom: 40px !important;
  }

  /* КРЕСТИК — принудительно */
  #form1 .t-popup__close {
    position: fixed !important;
    top: env(safe-area-inset-top, 12px) !important;
    right: env(safe-area-inset-right, 12px) !important;
    z-index: 1000000 !important;
    background: rgba(255,255,255,0.9);
    border-radius: 50%;
    pointer-events: auto !important;
  }
}



(function () {

  function fixForm1() {
    if (window.innerWidth > 1024) return;

    const popup = document.getElementById('form1');
    if (!popup || !popup.classList.contains('t-popup_show')) return;

    const vh = window.innerHeight;

    popup.style.height = vh + 'px';

    const container = popup.querySelector('.t-popup__container');
    if (container) {
      container.style.minHeight = (vh - 60) + 'px';
    }

    const close = popup.querySelector('.t-popup__close');
    if (close) {
      close.style.display = 'block';
      close.style.pointerEvents = 'auto';
    }
  }

  document.addEventListener('click', function (e) {
    if (e.target.closest('[href="#form1"], [data-popup="#form1"]')) {
      setTimeout(fixForm1, 50);
      setTimeout(fixForm1, 150);
      setTimeout(fixForm1, 300);
      setTimeout(fixForm1, 600);
    }
  });
  
(function () {
  let scrollTop = 0;

  function lockBody() {
    scrollTop = window.scrollY || document.documentElement.scrollTop;
    document.body.style.position = 'fixed';
    document.body.style.top = `-${scrollTop}px`;
    document.body.style.width = '100%';
  }

  function unlockBody() {
    document.body.style.position = '';
    document.body.style.top = '';
    document.body.style.width = '';
    window.scrollTo(0, scrollTop);
  }

  function isForm1Open() {
    const popup = document.getElementById('form1');
    return popup && popup.classList.contains('t-popup_show');
  }

  // при открытии
  document.addEventListener('click', function (e) {
    if (e.target.closest('[href="#form1"], [data-popup="#form1"]')) {
      setTimeout(() => {
        if (isForm1Open()) lockBody();
      }, 80);
    }
  });

  // при закрытии (крестик + клик по фону)
  document.addEventListener('click', function (e) {
    if (e.target.closest('#form1 .t-popup__close, #form1 .t-popup__bg')) {
      setTimeout(unlockBody, 50);
    }
  });

})();



  window.addEventListener('resize', fixForm1);
})();

