diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 07671a0..6259715 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -50,56 +50,44 @@ export default function RootLayout({ return (
- diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsx index 3146f9c..051b278 100644 --- a/src/components/SettingsPage.tsx +++ b/src/components/SettingsPage.tsx @@ -24,42 +24,70 @@ export default function SettingsPage({ userEmail }: SettingsPageProps) { } }, []); + const injectThemeStyles = (theme: string) => { + let styleId = 'theme-override-styles'; + let styleTag = document.getElementById(styleId) as HTMLStyleElement; + + if (!styleTag) { + styleTag = document.createElement('style'); + styleTag.id = styleId; + styleTag.setAttribute('data-theme-injected', 'true'); + document.head.appendChild(styleTag); + } + + if (theme === 'dark') { + styleTag.textContent = ` + * { color-scheme: dark !important; } + html, body { background-color: #0f172a !important; color: #f1f5f9 !important; } + .dark\\:from-slate-900, .from-slate-50, .from-slate-100 { background-color: #0f172a !important; } + .dark\\:to-slate-800, .to-slate-100 { background-color: #1e293b !important; } + div, section, main { background-color: inherit !important; } + p, span, h1, h2, h3, h4, h5, h6 { color: #f1f5f9 !important; } + input, textarea, button { background-color: #1e293b !important; color: #f1f5f9 !important; border-color: #334155 !important; } + button { background-color: #334155 !important; color: #f1f5f9 !important; } + button:hover { background-color: #475569 !important; } + `; + } else if (theme === 'light') { + styleTag.textContent = ` + * { color-scheme: light !important; } + html, body { background-color: #f8fafc !important; color: #1e293b !important; } + .from-slate-50, .from-slate-100, .dark\\:from-slate-900 { background-color: #f8fafc !important; } + .to-slate-100, .dark\\:to-slate-800 { background-color: #f1f5f9 !important; } + div, section, main { background-color: inherit !important; } + p, span, h1, h2, h3, h4, h5, h6 { color: #1e293b !important; } + input, textarea, button { background-color: #e2e8f0 !important; color: #1e293b !important; border-color: #cbd5e1 !important; } + button { background-color: #cbd5e1 !important; color: #1e293b !important; } + button:hover { background-color: #bfdbfe !important; } + `; + } + }; + const handleThemeChange = (newTheme: string) => { setCurrentTheme(newTheme); localStorage.setItem('theme-mode', newTheme); const html = document.documentElement; - const body = document.body; if (newTheme === 'dark') { - html.classList.add('dark-mode', 'dark'); - html.style.colorScheme = 'dark'; - body.style.backgroundColor = '#0f172a'; - body.style.color = '#f1f5f9'; - document.querySelectorAll('[class*="bg-"]').forEach(el => { - if (el.classList.toString().includes('bg-slate') || el.classList.toString().includes('bg-white')) { - el.style.backgroundColor = ''; - } - }); + html.classList.add('dark'); + html.setAttribute('data-theme', 'dark'); + injectThemeStyles('dark'); toast.success('🌙 Switched to dark theme'); } else if (newTheme === 'light') { - html.classList.remove('dark-mode', 'dark'); - html.style.colorScheme = 'light'; - body.style.backgroundColor = '#f8fafc'; - body.style.color = '#1e293b'; + html.classList.remove('dark'); + html.setAttribute('data-theme', 'light'); + injectThemeStyles('light'); toast.success('☀️ Switched to light theme'); } else if (newTheme === 'system') { const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches; if (prefersDark) { - html.classList.add('dark-mode', 'dark'); - html.style.colorScheme = 'dark'; - body.style.backgroundColor = '#0f172a'; - body.style.color = '#f1f5f9'; + html.classList.add('dark'); + html.setAttribute('data-theme', 'dark'); + injectThemeStyles('dark'); } else { - html.classList.remove('dark-mode', 'dark'); - html.style.colorScheme = 'light'; - body.style.backgroundColor = '#f8fafc'; - body.style.color = '#1e293b'; + html.classList.remove('dark'); + html.setAttribute('data-theme', 'light'); + injectThemeStyles('light'); } toast.success('🔄 Using system preference'); }