:root {
    /* Day Theme Variables (Default) */
    --bg-color: #f8f9fa;
    --card-bg: rgba(255, 255, 255, 0.75);
    --card-border: rgba(0, 0, 0, 0.08);
    --text-color: #001F3F;
    --text-muted: #6c757d;
    --navbar-bg: rgba(255, 255, 255, 0.75);
    --navbar-type: light;
    --glass-blur: 2.65px;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

[data-theme="dark"] {
    /* Night Theme Variables */
    --bg-color: transparent;
    --card-bg: rgba(255, 255, 255, 0.1);
    --card-border: rgba(255, 255, 255, 0.18);
    --text-color: #fffde6;
    /* Creamy White */
    --text-muted: #e0e0d1;
    /* Muted Creamy White */
    --navbar-bg: rgba(0, 31, 63, 0.2);
    --navbar-type: dark;
    --glass-blur: 2.65px;
}

#galaxy-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    background: radial-gradient(circle at center, #ffffff 0%, #fffefb 100%);
    transition: opacity 0.5s ease, background 0.5s ease;
}

[data-theme="dark"] #galaxy-bg {
    background: radial-gradient(circle at center, #002a54 0%, #001F3F 100%);
}

body {
    background-color: var(--bg-color) !important;
    color: var(--text-color);
    transition: background-color 0.5s ease, color 0.5s ease;
}

/* Universal Glassmorphism Selector */
/* We target standard UI blocks globally without forcing layout changes (padding/margin) */
.glass-effect,
.navbar,
.main-footer,
.card,
.post-item,
.list-group-item,
.modal-content,
.dropdown-menu,
.cms-plugin,
[class*="plugin-"],
[class*="djangocms_"] {
    background: var(--card-bg) !important;
    backdrop-filter: blur(var(--glass-blur)) !important;
    -webkit-backdrop-filter: blur(var(--glass-blur)) !important;
    border: 1px solid var(--card-border) !important;
    color: var(--text-color) !important;
    transition: background 0.3s ease, backdrop-filter 0.3s ease;
}

/* Ensure sub-containers in CMS plugins don't have solid backgrounds */
.card-header,
.card-body,
.card-footer,
.list-group,
/* Universal Reset for Nested Glass: anything glassy inside something glassy should be transparent */
.card .card,
.card .post-item,
.card .list-group-item,
.card .cms-plugin,
.card [class*="plugin-"],
.card [class*="djangocms_"],
.cms-plugin .cms-plugin,
.cms-plugin .card,
.cms-plugin .post-item,
.cms-plugin .list-group-item,
[class*="plugin-"] .card,
[class*="plugin-"] .post-item,
[class*="plugin-"] [class*="plugin-"],
[class*="djangocms_"] .card,
[class*="djangocms_"] .post-item,
.glass-effect .card,
.glass-effect .post-item,
.glass-effect .cms-plugin,
.glass-effect [class*="plugin-"],
.glass-effect [class*="djangocms_"] {
    background: transparent !important;
    border: none !important;
    color: inherit !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: none !important;
}

/* Navigation & Footer specific overlays */
.navbar,
.main-footer {
    background: var(--navbar-bg) !important;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

.navbar {
}

footer {
    margin-top: 50px;
}

/* Logo contrast fix */
.logo-bg-wrapper {
    background: white;
    padding: 10px;
    border-radius: 8px;
    display: inline-block;
}

/* Theme Toggle Button */
.theme-toggle {
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-color);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.theme-toggle i {
    line-height: 1;
}

.theme-toggle:hover {
    transform: scale(1.1) rotate(15deg);
}

/* Global Typography */
h1,
h2,
h3,
h4,
h5,
h6,
.page-header,
p,
span,
li {
    color: var(--text-color) !important;
}

.text-muted {
    color: var(--text-muted) !important;
}

.btn-primary {
    background-color: #EA7B1C !important;
    border-color: #EA7B1C !important;
}

[data-theme="dark"] .btn-primary {
    background-color: #EA7B1C !important;
    border-color: #fff !important;
    color: #fff !important;
}

.btn-outline-primary {
    color: #EA7B1C !important;
    border-color: #EA7B1C !important;
}

.btn-outline-primary:hover {
    background-color: #EA7B1C !important;
    color: white !important;
}

[data-theme="dark"] .btn-outline-primary {
    color: #fff !important;
    border-color: #fff !important;
}

[data-theme="dark"] .btn-outline-primary:hover {
    background-color: #EA7B1C !important;
    color: white !important;
    border-color: #EA7B1C !important;
}

.page-item.active .page-link {
    background-color: #EA7B1C !important;
    border-color: #EA7B1C !important;
    color: white !important;
}

.page-link:hover {
    color: #EA7B1C !important;
}

/* Search results and pagination: transparent with no border */
.search-results .list-group-item {
    background: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border: none !important;
}

.pagenav {
    background: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border: none !important;
}

/* Ensure pagination links are always readable against the theme background */
.page-link {
    color: var(--text-color) !important;
    background: var(--card-bg) !important;
    border-color: var(--card-border) !important;
}

/* Blurrier, more opaque navbar submenus */
.dropdown-menu {
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
}

:root .dropdown-menu {
    background-color: rgba(255, 255, 255, 0.82) !important;
}

[data-theme="dark"] .dropdown-menu {
    background-color: rgba(0, 20, 60, 0.88) !important;
}

/* Dropdown menu item hover in dark mode */
[data-theme="dark"] .dropdown-item:hover,
[data-theme="dark"] .dropdown-item:focus {
    background-color: rgba(0, 40, 90, 0.6) !important;
    color: #fffde6 !important;
}

/* Bootstrap Accordion - Dark Mode */
[data-theme="dark"] .accordion-item {
    background-color: rgba(0, 20, 60, 0.7) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
}

[data-theme="dark"] .accordion-button {
    background-color: rgba(0, 20, 60, 0.8) !important;
    color: #fffde6 !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
}

[data-theme="dark"] .accordion-button:not(.collapsed) {
    background-color: rgba(0, 30, 80, 0.9) !important;
    color: #fffde6 !important;
}

[data-theme="dark"] .accordion-button::after {
    filter: invert(1) brightness(2);
}

[data-theme="dark"] .accordion-body {
    background-color: rgba(0, 20, 60, 0.7) !important;
    color: #fffde6 !important;
}

/* Bootstrap Alert - Dark Mode */
[data-theme="dark"] .alert {
    background-color: rgba(0, 20, 60, 0.8) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #fffde6 !important;
}

[data-theme="dark"] .alert-primary {
    background-color: rgba(0, 40, 90, 0.8) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #fffde6 !important;
}

[data-theme="dark"] .alert-secondary {
    background-color: rgba(0, 30, 70, 0.8) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #fffde6 !important;
}

[data-theme="dark"] .alert-info {
    background-color: rgba(0, 40, 80, 0.8) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #fffde6 !important;
}

/* Bootstrap Tables - Dark Mode */
[data-theme="dark"] .table {
    color: #fffde6 !important;
}

[data-theme="dark"] .table thead th {
    background-color: rgba(0, 30, 80, 0.9) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #fffde6 !important;
}

[data-theme="dark"] .table tbody tr {
    background-color: rgba(0, 20, 60, 0.5) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}

[data-theme="dark"] .table td,
[data-theme="dark"] .table th {
    border-color: rgba(255, 255, 255, 0.1) !important;
}

[data-theme="dark"] .table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(0, 20, 60, 0.6) !important;
}

[data-theme="dark"] .table-hover tbody tr:hover {
    background-color: rgba(0, 30, 80, 0.7) !important;
}

/* Navbar Search Bar - Dark Mode */
[data-theme="dark"] #id_q {
    background-color: rgba(0, 30, 80, 0.8) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #fffde6 !important;
}

[data-theme="dark"] #id_q::placeholder {
    color: rgba(255, 255, 255, 0.6) !important;
}

[data-theme="dark"] #id_q:focus {
    background-color: rgba(0, 40, 100, 0.9) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
    color: #fffde6 !important;
}

/* Search autocomplete dropdown - Dark Mode */
[data-theme="dark"] .autocomplete-dropdown {
    background-color: rgba(0, 20, 60, 0.95) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
}

[data-theme="dark"] .autocomplete-item {
    color: #fffde6 !important;
}

[data-theme="dark"] .autocomplete-item:hover,
[data-theme="dark"] .autocomplete-item:focus {
    background-color: rgba(0, 40, 90, 0.6) !important;
}

[data-theme="dark"] .autocomplete-title {
    color: #EA7B1C !important;
}

/* Leaflet map controls: night mode override */
[data-theme="dark"] .leaflet-bar,
[data-theme="dark"] .leaflet-bar a,
[data-theme="dark"] .leaflet-bar a:hover,
[data-theme="dark"] .leaflet-control-zoom a,
[data-theme="dark"] .leaflet-control-attribution,
[data-theme="dark"] .leaflet-popup-content-wrapper,
[data-theme="dark"] .leaflet-popup-tip,
[data-theme="dark"] .leaflet-control-layers,
[data-theme="dark"] .leaflet-control-layers-expanded {
    background: rgba(0, 20, 50, 0.85) !important;
    color: #fffde6 !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
}

[data-theme="dark"] .leaflet-bar a {
    color: #fffde6 !important;
    border-bottom-color: rgba(255, 255, 255, 0.2) !important;
}

[data-theme="dark"] .leaflet-bar a:hover {
    background: rgba(0, 40, 90, 0.9) !important;
}

[data-theme="dark"] .leaflet-control-attribution a {
    color: #EA7B1C !important;
}

/* Leaflet TimeDimension player controls: night mode */
[data-theme="dark"] .leaflet-bar-timecontrol,
[data-theme="dark"] .leaflet-bar-timecontrol .timecontrol-date,
[data-theme="dark"] .leaflet-bar-timecontrol .timecontrol-slider,
[data-theme="dark"] .leaflet-bar-timecontrol .timecontrol-play,
[data-theme="dark"] .leaflet-bar-timecontrol .timecontrol-backward,
[data-theme="dark"] .leaflet-bar-timecontrol .timecontrol-forward,
[data-theme="dark"] .leaflet-bar-timecontrol .timecontrol-loop,
[data-theme="dark"] .leaflet-bar-timecontrol .timecontrol-speed,
[data-theme="darks"] .leaflet-bar-timecontrol a,
[data-theme="dark"] .timecontrol-datalist {
    background: rgba(0, 20, 50, 0.85) !important;
    color: #fffde6 !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
}

[data-theme="dark"] .leaflet-bar-timecontrol a:hover {
    background: rgba(0, 40, 90, 0.9) !important;
}

[data-theme="dark"] .timecontrol-slider input[type="range"] {
    accent-color: #EA7B1C;
}

/* Leaflet Fullscreen plugin: night mode — high specificity to beat plugin CSS */
body[data-theme="dark"] .leaflet-control-fullscreen a,
body[data-theme="dark"] .leaflet-control-fullscreen a:hover {
    background-color: rgba(0, 20, 50, 0.92) !important;
    color: #fffde6 !important;
    border-color: rgba(255, 255, 255, 0.25) !important;
}

/* Invert the SVG background-image icon (dark arrow → white arrow) */
body[data-theme="dark"] .leaflet-fullscreen-icon,
body[data-theme="dark"] .leaflet-control-fullscreen .leaflet-fullscreen-icon {
    filter: invert(1) brightness(2) !important;
}

/* TimeDimension date/calendar control: high specificity to beat #fff hardcode */
body[data-theme="dark"] .leaflet-bar-timecontrol a.timecontrol-date,
body[data-theme="dark"] .leaflet-bar-timecontrol a.timecontrol-date:hover,
body[data-theme="dark"] .leaflet-bar-timecontrol .leaflet-control-timecontrol,
body[data-theme="dark"] .leaflet-bar-timecontrol a.timecontrol-date.loading,
body[data-theme="dark"] .leaflet-bar-timecontrol a.timecontrol-date.loading:hover {
    background-color: rgba(0, 20, 50, 0.92) !important;
    color: #fffde6 !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
}


/* CMS Admin Login Button */
.cms-btn-action,
input.cms-btn-action[type="submit"] {
    background-color: #EA7B1C !important;
    border-color: #EA7B1C !important;
    color: #ffffff !important;
}

[data-theme="dark"] .cms-btn-action,
[data-theme="dark"] input.cms-btn-action[type="submit"] {
    background-color: #EA7B1C !important;
    border-color: #fff !important;
    color: #fff !important;
}

.cms-btn-action:hover,
input.cms-btn-action[type="submit"]:hover {
    background-color: #c96517 !important;
    border-color: #c96517 !important;
    color: #ffffff !important;
}

[data-theme="dark"] .cms-btn-action:hover,
[data-theme="dark"] input.cms-btn-action[type="submit"]:hover {
    background-color: #c96517 !important;
    border-color: #fff !important;
    color: #ffffff !important;
}

/* Image Loading Spinner - Injected Element Approach */
.img-loading-wrapper {
    position: relative;
    display: inline-block;
    background: transparent;
    min-width: 20px;
    min-height: 20px;
    vertical-align: middle;
}

.img-loading-wrapper img {
    display: block;
    position: relative;
    z-index: 2;
    margin-left: auto;
    margin-right: auto;
}

.img-loading-wrapper.mx-auto {
    display: block;
}

/* img-fluid wrapper - maintain aspect ratio */
.img-loading-wrapper.img-fluid {
    width: 100%;
    height: auto;
    display: block;
}

.img-loading-wrapper.loading {
    background: rgba(0, 0, 0, 0.03);
}

.img-loading-wrapper.loaded {
    background: transparent;
}

[data-theme="dark"] .img-loading-wrapper.loading {
    background: rgba(255, 255, 255, 0.03);
}

img.loading {
    opacity: 0;
    transition: opacity 0.4s ease-in-out;
}

img.loaded {
    opacity: 1;
}

/* Parent containers for CMS images - show subtle background while loading */
figure.loading-img-container,
.cms-plugin.loading-img-container {
    background: rgba(0, 0, 0, 0.03);
    position: relative;
}

[data-theme="dark"] figure.loading-img-container,
[data-theme="dark"] .cms-plugin.loading-img-container {
    background: rgba(255, 255, 255, 0.03);
}

/* Spinner element injected via JS */
.img-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 32px;
    height: 32px;
    border: 3px solid #e0e0e0;
    border-top-color: #0d6efd;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    z-index: 10;
    pointer-events: none;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

[data-theme="dark"] .img-spinner {
    border-color: #444;
    border-top-color: #EA7B1C;
}

/* Ensure wrapper is visible during loading */
.img-loading-wrapper.loading .img-spinner {
    display: block !important;
}

/* Carousel Image Loading */
.carousel-item {
    position: relative;
}

.carousel-item .img-loading-wrapper {
    display: block;
    width: 100%;
    position: relative;
}

.carousel-item img {
    transition: opacity 0.4s ease-in-out;
}

.carousel-item img:not(.loaded) {
    opacity: 0;
}

/* Leaflet Map Loading Overlay */
.leaflet-container {
    position: relative;
    background: rgba(0, 0, 0, 0.05);
}

.leaflet-container.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-top-color: #0d6efd;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    z-index: 1000;
    pointer-events: none;
}

[data-theme="dark"] .leaflet-container.loading::after {
    border-color: rgba(255, 255, 255, 0.1);
    border-top-color: #EA7B1C;
}
