function updateSummary() {
    const checkboxes = document.querySelectorAll('.orderCheckbox');
    const selectedCount = document.getElementById('selectedCount');
    const selectedTotal = document.getElementById('selectedTotal');
    const payBtn = document.getElementById('paySelectedBtn');

    if (!payBtn) return;

    let count = 0;
    let total = 0;
    checkboxes.forEach(function (cb) {
        if (cb.checked) {
            count++;
            total += parseFloat(cb.dataset.amount) || 0;
        }
    });

    if (selectedCount) selectedCount.textContent = count;
    if (selectedTotal) selectedTotal.textContent = '\u00a3' + total.toFixed(2);
    payBtn.disabled = count === 0;
}

document.addEventListener('change', function (e) {
    if (e.target.id === 'selectAll') {
        document.querySelectorAll('.orderCheckbox').forEach(function (cb) {
            cb.checked = e.target.checked;
        });
        updateSummary();
    } else if (e.target.classList.contains('orderCheckbox')) {
        updateSummary();
    }
});
