  if (result.error) {
                    throw new Error(result.error);
                }
                window.location.reload();
            })
            .catch(error => {
                alert('Error deleting case: ' + error.message);
            });
        }
    }

    // Close modals on Escape key
    document.addEventListener('keydown', function(e) {
        if (e.key === 'Escape') {
            closeCaseModal();
            closeEditCaseModal();
            closeCaseDevicesModal();
            c