        if (index > -1) {
            window.selectedDevicesForCase.splice(index, 1);
        } else {
            window.selectedDevicesForCase.push(deviceID);
        }
        
        renderAvailableDevicesForCase();
    }

    function selectAllVisibleDevices() {
        const visibleDevices = document.querySelectorAll('.device-card:not([style*="display: none"])');
        visibleDevices.forEach(card => {
            const deviceID = card.getAttribute('data-device-id');
            if (!window.selected