electedDevicesForCase.indexOf(deviceId);
        if (index > -1) {
            window.selectedDevicesForCase.splice(index, 1);
        } else {
            window.selectedDevicesForCase.push(deviceId);
        }
        
        // Update visual state for tree view
        const deviceElement = document.querySelector(`[onclick*="toggleModalTreeDeviceSelection('${deviceId}')"]`);
        if (deviceElement) {
            const checkbox = deviceElement.querySelector('input[type="checkbox"]');
            
    