<!-- JAVASCRIPT HELPERS & FLOATING MUSIC ENGINE                        -->
    <!-- ================================================================= -->
    <script>
        // Live Countdown Timer Engine
        (function() {
            const targetISO = "<?= $countdownTargetISO ?>";
            const targetTime = new Date(targetISO).getTime();

            function updateCountdown() {
                const now = new Date().getTime();
                const diff = targetTime - now;

                const activeBox = document.getElementById('countdown-active-box');
                const arrivedBox = document.getElementById('countdown-arrived-box');

                if (diff <= 0) {
                    if (activeBox) activeBox.style.display = 'none';
                    if (arrivedBox) arrivedBox.classList.remove('hidden');
                    return;
                }

                const days = Math.floor(diff / (1000 * 60 * 60 * 24));
                const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                const mins = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
                const secs = Math.floor((diff % (1000 * 60)) / 1000);

                const dEl = document.getElementById('cd-days');
                const hEl = document.getElementById('cd-hours');
                const mEl = document.getElementById('cd-mins');
                const sEl = document.getElementById('cd-secs');

                if (dEl) dEl.innerText = String(days).padStart(2, '0');
                if (hEl) hEl.innerText = String(hours).padStart(2, '0');
                if (mEl) mEl.innerText = String(mins).padStart(2, '0');
                if (sEl) sEl.innerText = String(secs).padStart(2, '0');
            }

            updateCountdown();
            setInterval(updateCountdown, 1000);
        })();

        function copyToClipboard(text, successMsg) {
            if (navigator.clipboard && window.isSecureContext) {
                navigator.clipboard.writeText(text).then(() => {
                    showToast(successMsg || 'Copied to clipboard!');
                });
            } else {
                const input = document.createElement('input');
                input.value = text;
                document.body.appendChild(input);
                input.select();
                document.execCommand('copy');
                document.body.removeChild(input);
                showToast(successMsg || 'Copied to clipboard!');
            }
        }

        function showToast(msg) {
            let container = document.getElementById('toast-container');
            if (!container) {
                container = document.createElement('div');
                container.id = 'toast-container';
                container.className = 'fixed top-6 right-6 z-50 flex flex-col gap-2 pointer-events-none';
                document.body.appendChild(container);
            }
            const t = document.createElement('div');
            t.className = 'bg-slate-900/90 text-white text-xs font-semibold px-4 py-2.5 rounded-xl shadow-lg border border-slate-700/50 backdrop-blur-md transition-all duration-300 transform translate-y-2 opacity-0 pointer-events-auto flex items-center gap-2';
            t.innerHTML = '<span>📋</span> <span>' + msg + '</span>';
            container.appendChild(t);
            setTimeout(() => {
                t.classList.remove('translate-y-2', 'opacity-0');
            }, 10);
            setTimeout(() => {
                t.classList.add('opacity-0', 'translate-y-2');
                setTimeout(() => t.remove(), 300);
            }, 3000);
        }

        function openPassModal() {
            const modal = document.getElementById('pass-modal');
            const mp = document.getElementById('music-player-container');
            if (modal) modal.classList.remove('hidden');
            if (mp) mp.style.setProperty('display', 'none', 'important');
        }
        function closePassModal() {
            const modal = document.getElementById('pass-modal');
            const mp = document.getElementById('music-player-container');
            if (modal) modal.classList.add('hidden');
            if (mp) mp.style.setProperty('display', 'block', 'important');
        }

        function openQrisModal(imgUrl) {
            const modal = document.getElementById('qris-modal');
            const qrisImg = document.getElementById('modal-qris-img');
            const dlBtn = document.getElementById('modal-qris-download');
            const mp = document.getElementById('music-player-container');
            if (qrisImg && imgUrl) qrisImg.src = imgUrl;
            if (dlBtn && imgUrl) dlBtn.href = imgUrl;
            if (modal) modal.classList.remove('hidden');
            if (mp) mp.style.setProperty('display', 'none', 'important');
        }
        function closeQrisModal() {
            const modal = document.getElementById('qris-modal');
            const mp = document.getElementById('music-player-container');
            if (modal) modal.classList.add('hidden');
            if (mp) mp.style.setProperty('display', 'block', 'important');
        }

        function toggleWishEdit(showForm) {
            const displayCard = document.getElementById('wish-display-card');
            const formCard = document.getElementById('wish-form-card');
            if (showForm) {
                if (displayCard) displayCard.classList.add('hidden');
                if (formCard) formCard.classList.remove('hidden');
            } else {
                if (displayCard) displayCard.classList.remove('hidden');
                if (formCard) formCard.classList.add('hidden');
            }
        }

        function togglePaxInputEvent(evtId) {
            const responseSelect = document.getElementById('rsvp_response_' + evtId);
            const paxContainer = document.getElementById('pax-container-' + evtId);
            if (responseSelect && paxContainer) {
                if (responseSelect.value === 'attending') {
                    paxContainer.classList.remove('hidden');
                } else {
                    paxContainer.classList.add('hidden');
                }
            }
        }
    </script>

    <!-- Reusable Floating Music Player (G007) -->
                const secs = Math.floor((diff % (1000 * 60)) / 1000);

                const dEl = document.getElementById('cd-days');
                const hEl = document.getElementById('cd-hours');
                const mEl = document.getElementById('cd-mins');
                const sEl = document.getElementById('cd-secs');

                if (dEl) dEl.innerText = String(days).padStart(2, '0');
                if (hEl) hEl.innerText = String(hours).padStart(2, '0');
                if (mEl) mEl.innerText = String(mins).padStart(2, '0');
                if (sEl) sEl.innerText = String(secs).padStart(2, '0');
            }

            updateCountdown();
            setInterval(updateCountdown, 1000);
        })();

        function copyToClipboard(text, successMsg) {
            if (navigator.clipboard && window.isSecureContext) {
                navigator.clipboard.writeText(text).then(() => {
                    showToast(successMsg || 'Copied to clipboard!');
                });
            } else {
                const input = document.createElement('input');
                input.value = text;
                document.body.appendChild(input);
                input.select();
                document.execCommand('copy');
                document.body.removeChild(input);
                showToast(successMsg || 'Copied to clipboard!');
            }
        }

        function showToast(msg) {
            let container = document.getElementById('toast-container');
            if (!container) {
                container = document.createElement('div');
                container.id = 'toast-container';
                container.className = 'fixed top-6 right-6 z-50 flex flex-col gap-2 pointer-events-none';
                document.body.appendChild(container);
            }
            const t = document.createElement('div');
            t.className = 'bg-slate-900/90 text-white text-xs font-semibold px-4 py-2.5 rounded-xl shadow-lg border border-slate-700/50 backdrop-blur-md transition-all duration-300 transform translate-y-2 opacity-0 pointer-events-auto flex items-center gap-2';
            t.innerHTML = '<span>📋</span> <span>' + msg + '</span>';
            container.appendChild(t);
            setTimeout(() => {
                t.classList.remove('translate-y-2', 'opacity-0');
            }, 10);
            setTimeout(() => {
                t.classList.add('opacity-0', 'translate-y-2');
                setTimeout(() => t.remove(), 300);
            }, 3000);
        }

        function openPassModal() {
            const modal = document.getElementById('pass-modal');
            const mp = document.getElementById('music-player-container');
            if (modal) modal.classList.remove('hidden');
            if (mp) mp.style.setProperty('display', 'none', 'important');
        }
        function closePassModal() {
            const modal = document.getElementById('pass-modal');
            const mp = document.getElementById('music-player-container');
            if (modal) modal.classList.add('hidden');
            if (mp) mp.style.setProperty('display', 'block', 'important');
        }

        function openQrisModal(imgUrl) {
            const modal = document.getElementById('qris-modal');
            const qrisImg = document.getElementById('modal-qris-img');
            const dlBtn = document.getElementById('modal-qris-download');
            const mp = document.getElementById('music-player-container');
            if (qrisImg && imgUrl) qrisImg.src = imgUrl;
            if (dlBtn && imgUrl) dlBtn.href = imgUrl;
            if (modal) modal.classList.remove('hidden');
            if (mp) mp.style.setProperty('display', 'none', 'important');
        }
        function closeQrisModal() {
            const modal = document.getElementById('qris-modal');
            const mp = document.getElementById('music-player-container');
            if (modal) modal.classList.add('hidden');
            if (mp) mp.style.setProperty('display', 'block', 'important');
        }

        function toggleWishEdit(showForm) {
            const displayCard = document.getElementById('wish-display-card');
            const formCard = document.getElementById('wish-form-card');
            if (showForm) {
                if (displayCard) displayCard.classList.add('hidden');
                if (formCard) formCard.classList.remove('hidden');
            } else {
                if (displayCard) displayCard.classList.remove('hidden');
                if (formCard) formCard.classList.add('hidden');
            }
        }

        function togglePaxInputEvent(evtId) {
            const responseSelect = document.getElementById('rsvp_response_' + evtId);
            const paxContainer = document.getElementById('pax-container-' + evtId);
            if (responseSelect && paxContainer) {
                if (responseSelect.value === 'attending') {
                    paxContainer.classList.remove('hidden');
                } else {
                    paxContainer.classList.add('hidden');
                }
            }
        }
    </script>

    <!-- Reusable Floating Music Player (G007) -->
    <?php if ($musicEnabled && !empty($musicFileUrl)): ?>
        <?php require ROOT_PATH . '/app/views/components/music_player.php'; ?>
    <?php endif; ?>
