Error('Some devices could not be added');
            }
            
        } catch (error) {
            console.error('Error adding selected devices:', error);
            alert('Error adding devices to case: ' + error.message);
            
            // Restore button
            addBtn.innerHTML = originalText;
            addBtn.disabled = false;
        }
    }


    function addDeviceToCase(caseID, deviceID) {
        if (confirm('Add device ' + deviceID + ' to this case?')) {
            fetch('/