<script>
function openModal(id) {
    const modal = document.getElementById(id);
    if (!modal) return;

    modal.classList.add("active");
    const box = modal.querySelector(".gx-modal");
    if (box) box.classList.add("active");

    document.body.style.overflow = "hidden";
}

function closeModal(id) {
    const modal = document.getElementById(id);
    if (!modal) return;

    modal.classList.remove("active");
    const box = modal.querySelector(".gx-modal");
    if (box) box.classList.remove("active");

    document.body.style.overflow = "";
}

/* Close with ESC */
document.addEventListener("keydown", (e) => {
    if (e.key === "Escape") {
        document
            .querySelectorAll(".gx-modal-backdrop.active")
            .forEach(m => closeModal(m.id));
    }
});
</script>
