window.tmTotp = {
    renderQr: function (containerId, otpauthUri) {
        const el = document.getElementById(containerId);
        if (!el || typeof window.qrcode !== 'function') return;
        try {
            // Reset
            el.innerHTML = '';
            const qr = window.qrcode(0, 'M');
            qr.addData(otpauthUri);
            qr.make();
            // Module-image at 5px per cell with 2px margin
            el.innerHTML = qr.createImgTag(5, 12);
            const img = el.querySelector('img');
            if (img) {
                img.style.borderRadius = '8px';
                img.style.background = '#fff';
                img.style.padding = '8px';
                img.style.boxShadow = '0 2px 12px rgba(15,23,42,0.10)';
                img.alt = 'TOTP QR';
            }
        } catch (e) {
            console.error('[totp] qr render failed', e);
            el.textContent = 'QR generation failed. Use the manual entry secret below.';
        }
    }
};
