diff --git a/admin/index.php b/admin/index.php index d4ebae2..9083579 100644 --- a/admin/index.php +++ b/admin/index.php @@ -198,7 +198,7 @@ function sidebarDropdownLink($url, $nome) { } echo ""; // Fechar Navbar no HTML, e passar o conteúdo para baixo - echo "
"; + echo "
"; $csrfTokenHtml = htmlspecialchars(generate_csrf_token(), ENT_QUOTES, 'UTF-8'); echo ""; diff --git a/assets/theme-switcher.js b/assets/theme-switcher.js index f410f56..972d7fa 100644 --- a/assets/theme-switcher.js +++ b/assets/theme-switcher.js @@ -2,29 +2,44 @@ (function() { const htmlElement = document.documentElement; const darkModeQuery = window.matchMedia('(prefers-color-scheme: dark)'); - - // Function to apply theme - function applyTheme(isDark) { - htmlElement.setAttribute('data-bs-theme', isDark ? 'dark' : 'light'); - - // Handle admin navbar specifically + + // Set data-bs-theme immediately (before DOM is ready) to avoid flash of wrong theme + htmlElement.setAttribute('data-bs-theme', darkModeQuery.matches ? 'dark' : 'light'); + + // Handle admin navbar class switching + function applyNavbarTheme(isDark) { const adminNavbar = document.getElementById('admin-navbar'); - if (adminNavbar) { - if (isDark) { - adminNavbar.classList.remove('navbar-light', 'bg-light'); - adminNavbar.classList.add('navbar-dark', 'bg-dark'); - } else { - adminNavbar.classList.remove('navbar-dark', 'bg-dark'); - adminNavbar.classList.add('navbar-light', 'bg-light'); - } + if (!adminNavbar) return; + if (isDark) { + adminNavbar.classList.remove('navbar-light', 'bg-light'); + adminNavbar.classList.add('navbar-dark', 'bg-dark'); + } else { + adminNavbar.classList.remove('navbar-dark', 'bg-dark'); + adminNavbar.classList.add('navbar-light', 'bg-light'); } } - - // Set initial theme based on system preference - applyTheme(darkModeQuery.matches); - - // Listen for changes in system theme preference - darkModeQuery.addEventListener('change', e => { + + // Exposed for inline