        if (checkbox) {
                checkbox.checked = window.selectedDevicesForCase.includes(deviceId);
            }
            
            if (window.selectedDevicesForCase.includes(deviceId)) {
                deviceElement.classList.add('selected');
            } else {
                deviceElement.classList.remove('selected');
            }
        }
        
        // Update selection counter
        updateModalSelectionCounter();
        
        // Update footer button state
        updateA