
document.addEventListener("DOMContentLoaded", function() {
  const header = document.querySelector('.t-header'); // класс шапки Tilda
  let headerHeight = header ? header.offsetHeight : 110; // если шапка не найдена, ставим 110px

  // Переопределяем клики по якорям
  document.querySelectorAll('a[href^="#"]').forEach(anchor => {
    anchor.addEventListener('click', function(e) {
      const targetID = this.getAttribute('href').substring(1);
      const targetElement = document.getElementById(targetID);
      if (targetElement) {
        e.preventDefault();

        // Корректное смещение под фиксированную шапку
        const elementPosition = targetElement.getBoundingClientRect().top + window.pageYOffset;
        window.scrollTo({
          top: elementPosition - headerHeight,
          behavior: 'smooth'
        });
      }
    });
  });
});

