      </div>
    </main>
  </div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.getElementById('btnSidebar')?.addEventListener('click', function() {
  document.getElementById('adminSidebar').classList.toggle('show');
  document.getElementById('sidebarBackdrop').classList.toggle('show');
});

// Realtime slug generation for admin forms (title -> slug).
(function () {
  function slugify(text) {
    return (text || '')
      .toString()
      .toLowerCase()
      .trim()
      .replace(/[^a-z0-9]+/g, '-')
      .replace(/^-+|-+$/g, '');
  }

  const forms = document.querySelectorAll('form');
  forms.forEach((form) => {
    const titleInput = form.querySelector('input[name="title"]');
    const slugInput = form.querySelector('input[name="slug"]');
    if (!titleInput || !slugInput) return;

    const initialSlug = (slugInput.value || '').trim();
    let manualSlugEdit = initialSlug !== '';

    // If slug was auto-generated style value, keep auto mode.
    if (initialSlug !== '' && initialSlug === slugify(titleInput.value)) {
      manualSlugEdit = false;
    }

    const syncSlug = () => {
      if (manualSlugEdit) return;
      slugInput.value = slugify(titleInput.value);
    };

    titleInput.addEventListener('input', syncSlug);
    titleInput.addEventListener('change', syncSlug);

    slugInput.addEventListener('input', () => {
      const current = slugInput.value.trim();
      if (current === '' || current === slugify(titleInput.value)) {
        manualSlugEdit = false;
        return;
      }
      manualSlugEdit = true;
    });
  });
})();
</script>
</body>
</html>
