document.addEventListener("DOMContentLoaded", () => {
  const buttons    = document.querySelectorAll(".toc-btn");
  const containers = document.querySelectorAll(".toc-container");

  buttons.forEach(btn => {
    btn.addEventListener("click", () => {
      const target = btn.dataset.target;          // id del contenedor propio
      buttons.forEach(b => {
        const c = document.getElementById(b.dataset.target);

        if (b === btn) {                          // • botón clicado
          const isOpen = !b.classList.contains("collapsed");
          b.classList.toggle("collapsed",  isOpen);  // abre/cierra
          c.classList.toggle("visible",   !isOpen);
        } else {                                  // • los otros se cierran
          b.classList.add("collapsed");
          c.classList.remove("visible");
        }
      });
    });
  });
});

