document.addEventListener('turbo:load', () => {
  const flashMessages = document.querySelectorAll('.alert');
  flashMessages.forEach(flash => {
    // Add fade-out class after 3 seconds
    setTimeout(() => {
      flash.classList.add('fade-out');
      // Remove element after animation completes
      setTimeout(() => {
        flash.remove();
      }, 500); // matches the CSS transition duration
    }, 3000);

    // Optional: Allow clicking to dismiss
    flash.addEventListener('click', () => {
      flash.classList.add('fade-out');
      setTimeout(() => {
        flash.remove();
      }, 500);
    });
  });
});