    </main>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/Sortable/1.15.2/Sortable.min.js"></script>
<script>
const APP_URL = '<?= url('') ?>';

function showToast(message, type, duration) {
    type = type || 'info'; duration = duration || 4000;
    var container = document.getElementById('toastContainer');
    var icons = { success:'fa-check-circle', error:'fa-times-circle', info:'fa-info-circle' };
    var toast = document.createElement('div');
    toast.className = 'toast ' + type;
    toast.innerHTML = '<i class="fas ' + (icons[type]||icons.info) + '"></i><span style="flex:1">' + message + '</span><button onclick="this.parentElement.remove()" style="background:none;border:none;cursor:pointer;opacity:.6;font-size:.9rem"><i class="fas fa-times"></i></button>';
    container.appendChild(toast);
    setTimeout(function(){ toast.style.opacity='0'; toast.style.transition='opacity .3s'; setTimeout(function(){ toast.remove(); }, 300); }, duration);
}

function copyToClipboard(text) {
    if (navigator.clipboard) {
        navigator.clipboard.writeText(text).then(function(){ showToast('Copied to clipboard!','success'); });
    } else {
        var ta = document.createElement('textarea');
        ta.value = text; document.body.appendChild(ta); ta.select(); document.execCommand('copy'); document.body.removeChild(ta);
        showToast('Copied!','success');
    }
}

function confirmDelete(message, callback) {
    if (confirm(message || 'Are you sure you want to delete this?')) callback();
}

async function apiPost(url, data) {
    var res = await fetch(APP_URL + url, {
        method:'POST',
        headers:{'Content-Type':'application/json','X-Requested-With':'XMLHttpRequest'},
        body:JSON.stringify(data)
    });
    return res.json();
}

async function apiGet(url) {
    var res = await fetch(APP_URL + url, { headers:{'X-Requested-With':'XMLHttpRequest'} });
    return res.json();
}

function openModal(id) { document.getElementById(id).classList.remove('hidden'); document.body.style.overflow='hidden'; }
function closeModal(id) { document.getElementById(id).classList.add('hidden'); document.body.style.overflow=''; }
document.addEventListener('keydown', function(e){ if(e.key==='Escape') document.querySelectorAll('.modal-overlay').forEach(function(m){ m.classList.add('hidden'); }); document.body.style.overflow=''; });
</script>
</body>
</html>
