      `;
        });
        
        container.innerHTML = html;
        
        // Re-apply search filter if there is one
        const searchInput = document.getElementById('deviceSearchInput');
        if (searchInput && searchInput.value.trim()) {
            filterAvailableDevices();
        }
        
        updateSelectionCounter();
        updateAddSelectedButton();
    }

    function toggleDeviceSelectionForCase(deviceID) {
        const index = window.selectedDevicesForCase.indexOf(deviceID);
