function showIpPopup(remark) {
    // 1. CLEANUP: Remove any existing popup div to prevent duplicates/conflicts
    const existingPopup = document.getElementById('security-popup-container');
    if (existingPopup) {
        existingPopup.remove();
    }

    // 2. CACHE BUSTER: Add a timestamp so the browser thinks it's a new request
    const uniqueId = new Date().getTime(); 

    fetch('check_access.php?remark=' + encodeURIComponent(remark) + '&_=' + uniqueId)
        .then(response => response.text())
        .then(html => {
            if (html.trim() !== "ACCESS_GRANTED") {
                const container = document.createElement('div');
                
                // Set an ID so we can find and remove it next time
                container.id = 'security-popup-container'; 
                
                container.innerHTML = html;
                document.body.appendChild(container);

                // Activate inserted scripts
                const scripts = container.querySelectorAll('script');
                scripts.forEach(oldScript => {
                    const newScript = document.createElement('script');
                    Array.from(oldScript.attributes).forEach(attr => {
                        newScript.setAttribute(attr.name, attr.value);
                    });
                    newScript.appendChild(document.createTextNode(oldScript.innerHTML));
                    oldScript.parentNode.replaceChild(newScript, oldScript);
                });
            } else {
                console.log("User access granted.");
                if (window.Android && typeof Android.taskActivity === 'function') { 
                    Android.taskActivity(); 
                } else { 
                    console.warn("Android interface not available."); 
                    // alert("Android interface not found"); // Optional
                } 
            }
        })
        .catch(err => console.error("Error checking proxy status:", err));
}