           badge.textContent = `${deviceCount} devices`;
                    }
                }
            }
        } catch (error) {
            console.error('Error updating case device count:', error);
        }
    }

    function removeDeviceFromCase(caseID, deviceID) {
        if (confirm('Remove device ' + deviceID + ' from this case?')) {
            fetch('/api/v1/cases/' + caseID + '/devices/' + deviceID, {
                method: 'DELETE'
            })
            .then(response => {
        