(function () { if (window.toast) return; const rootId = 'toast-root'; function ensureRoot() { let el = document.getElementById(rootId); if (!el) { el = document.createElement('div'); el.id = rootId; el.setAttribute('data-toast-root', '1'); el.className = 'fixed right-3 z-[10050] flex w-[min(340px,calc(100vw-1.5rem))] flex-col gap-2 hidden'; el.style.top = 'calc(var(--bar-height, 56px) + 0.75rem)'; document.body.appendChild(el); } return el; } function create(type, message, opts = {}) { const root = ensureRoot(); const ttl = opts.duration ?? 4800; const title = opts.title || { info: 'Info', success: 'Success', warn: 'Warning', error: 'Error' }[type] || 'Notice'; const accent = { info: 'var(--color-info)', success: 'var(--color-success)', warn: 'var(--color-warning)', error: 'var(--color-danger)', }[type] || 'var(--color-accent)'; const el = document.createElement('div'); el.setAttribute('data-toast-item', '1'); el.className = 'relative isolate flex items-start gap-3 overflow-hidden rounded-md border border-[var(--color-border)] border-l-4 bg-[var(--color-surface)] px-4 py-3 text-[var(--font-size-sm)] leading-[1.3] text-[var(--color-text)] shadow-[var(--shadow-lg)]'; el.style.setProperty('--_accent', accent); el.style.borderLeftColor = 'var(--_accent)'; el.setAttribute('role', 'status'); el.setAttribute('aria-live', 'polite'); el.innerHTML = `

${title}

${message}
`; el.style.setProperty('--toast-ttl', `${ttl}ms`); const progress = el.querySelector('[data-toast-progress]'); if (progress) { progress.className = 'absolute bottom-0 left-0 h-[3px] w-full origin-left bg-[var(--_accent)]'; progress.style.animation = 'toast-progress linear forwards'; progress.style.animationDuration = `${ttl}ms`; } const closeBtn = el.querySelector('[data-toast-close]'); let closed = false; function remove() { if (closed) return; closed = true; el.style.animation = 'toast-out .35s forwards'; setTimeout(() => { el.remove(); if (root.childElementCount === 0) root.classList.add('hidden'); }, 340); } closeBtn.addEventListener('click', remove); if (ttl > 0) { setTimeout(remove, ttl); } root.classList.remove('hidden'); root.appendChild(el); return { remove }; } window.toast = { info: (m, o) => create('info', m, o), success: (m, o) => create('success', m, o), warn: (m, o) => create('warn', m, o), error: (m, o) => create('error', m, o), }; })();