jQuery(document).ready(function($) {
  // Initialize Isotope on team grid
  var $grid = $('.team-grid').isotope({
    itemSelector: '.team-member',
    layoutMode: 'fitRows',
  });

  // Filter buttons
  $('.team-category-filter-btn').on('click', function() {
    $('.team-category-filter-btn').removeClass('active');
    $(this).addClass('active');
    var filterValue = $(this).attr('data-filter');
    $grid.isotope({ filter: filterValue });
  });

  // Open bio panel on click
  $('.team-member').on('click', function() {
    var id = $(this).data('member');
    $('.bio-panel').removeClass('active');
    $('#bio-' + id).addClass('active');
    $('.overlay').addClass('active');
	  lockBodyScroll();
  });

  // Close bio panel on close button or overlay click
  $('.close-btn, .overlay').on('click', function() {
    $('.bio-panel').removeClass('active');
    $('.overlay').removeClass('active');
	  unlockBodyScroll();
  });
});
function lockBodyScroll() {
  const scrollY = window.scrollY;
  document.body.style.position = 'fixed';
  document.body.style.top = `-${scrollY}px`;
  document.body.style.width = '100%';
  document.body.dataset.scrollY = scrollY;
}

function unlockBodyScroll() {
  const scrollY = document.body.dataset.scrollY;
  document.body.style.position = '';
  document.body.style.top = '';
  document.body.style.width = '';
  window.scrollTo(0, parseInt(scrollY || '0'));
}
