/* ── Hero Slider ── */
(function(){
  var slides  = document.querySelectorAll('.slide');
  var dots    = document.querySelectorAll('.slider-dot');
  var current = 0;
  var total   = slides.length;
  var timer;

  function showSlide(n){
    slides.forEach(function(s){ s.classList.remove('active'); });
    dots.forEach(function(d){   d.classList.remove('active'); });
    current = (n + total) % total;
    slides[current].classList.add('active');
    if(dots[current]) dots[current].classList.add('active');
    restartProgress();
  }
  function restartProgress(){
    var bar = document.getElementById('sliderProgress');
    if(bar){
      bar.style.animation = 'none';
      bar.offsetHeight;
      bar.style.animation = 'progress-bar 5s linear forwards';
    }
  }
  window.changeSlide = function(dir){ clearInterval(timer); showSlide(current + dir); startAuto(); };
  window.goToSlide   = function(n){  clearInterval(timer); showSlide(n);             startAuto(); };
  function startAuto(){
    timer = setInterval(function(){ showSlide(current + 1); }, 5000);
  }
  startAuto();
  restartProgress();
})();