// Theme handling: "undefined mode" defaults to system unless explicitly toggled (function initTheme() { const root = document.documentElement; const saved = localStorage.getItem('theme-mode'); // 'light' | 'dark' const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; const apply = (mode) => { root.classList.toggle('dark', mode === 'dark'); }; if (saved === 'light' || saved === 'dark') { apply(saved); } else { apply(prefersDark ? 'dark' : 'light'); } })(); const themeToggle = document.getElementById('themeToggle'); if (themeToggle) { themeToggle.addEventListener('click', () => { const root = document.documentElement; const isDark = root.classList.toggle('dark'); localStorage.setItem('theme-mode', isDark ? 'dark' : 'light'); }); } // Elements const chatBox = document.getElementById('chatBox'); const composerForm = document.getElementById('composerForm'); const messageInput = document.getElementById('messageInput'); const sendBtn = document.getElementById('sendBtn'); const imageInput = document.getElementById('imageInput'); const codeInput = document.getElementById('codeInput'); const uploadImageBtn = document.getElementById('uploadImageBtn'); const uploadCodeBtn = document.getElementById('uploadCodeBtn'); const connectGitHubBtn = document.getElementById('connectGitHubBtn'); const githubConnectHeaderBtn = document.getElementById('githubConnectBtn'); const attachmentPreview = document.getElementById('attachmentPreview'); const modeIndicator = document.getElementById('modeIndicator'); const modeButtons = document.querySelectorAll('.mode-btn'); let currentMode = 'code'; updateModeIndicator(); // Helpers function formatTime(date = new Date()) { return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); } function scrollToBottom() { chatBox.scrollTop = chatBox.scrollHeight; } function createAvatar(initials, seed = 0) { const palette = ['bg-undefined-500', 'bg-blue-500', 'bg-teal-500', 'bg-violet-500', 'bg-rose-500']; const color = palette[seed % palette.length]; return `
${escapeHtml(message)}
` : ''} ${attachments.length ? `${escapeHtml(message)}
` : ''} ${attachments.length ? `