const API_BASE = window.location.origin.includes('hf.space') ? '' : 'https://kush26-toneforge.hf.space'; document.addEventListener('DOMContentLoaded', () => { switchTab('formalize'); }); // --- Theme Management --- function toggleTheme() { const isDark = document.documentElement.classList.toggle('dark'); localStorage.setItem('theme', isDark ? 'dark' : 'light'); if (window.lucide) lucide.createIcons(); } function switchTab(tabId) { document.querySelectorAll('.tab-content').forEach(el => { el.classList.add('hidden'); }); const targetContent = document.getElementById(tabId); if (targetContent) { targetContent.classList.remove('hidden'); } // Toggle corresponding output container document.querySelectorAll('.task-output').forEach(el => el.classList.add('hidden')); const targetOutput = document.getElementById(`output-${tabId}`); if (targetOutput) { targetOutput.classList.remove('hidden'); // Re-calculate heights for hidden-then-visible textareas setTimeout(() => { targetOutput.querySelectorAll('textarea[oninput="autoResize(this)"]').forEach(ta => autoResize(ta)); }, 50); } document.querySelectorAll('.nav-link').forEach(el => { el.classList.remove('active'); }); const targetLink = document.getElementById(`tab-${tabId}`); if (targetLink) { targetLink.classList.add('active'); } } // --- Loading State --- function setLoading(type, isLoading) { const btn = document.getElementById(`btn-${type}`); const originalText = btn.dataset.originalText || btn.innerText; if (isLoading) { btn.disabled = true; btn.dataset.originalText = originalText; btn.innerHTML = `