// filters.js
(function() {
  const filterBtns = document.querySelectorAll('.filter-btn');
  const feedList = document.getElementById('articles-feed');
  const cards = feedList ? feedList.querySelectorAll('.post-card') : [];

  if (!filterBtns.length || !cards.length) return;

  filterBtns.forEach(btn => {
    btn.addEventListener('click', function() {
      const filter = this.dataset.filter;

      // Update active button
      filterBtns.forEach(b => b.classList.remove('active'));
      this.classList.add('active');

      // Filter cards
      cards.forEach(card => {
        const cardType = card.querySelector('.post-type-badge')?.classList[1];
        const matches = filter === 'all' || cardType === filter;
        card.style.display = matches ? '' : 'none';
      });

      // Scroll to top
      window.scrollTo({ top: 0, behavior: 'smooth' });
    });
  });
})();
