/* Semantic text colors are distinct from filled button/chart colors. */
:root {
    color-scheme: light;
    --accent-text: #4c7b0f;
    --success-text: #237a45;
    --warning-text: #855600;
    --danger-text: #b42339;
    --info-text: #4c7b0f;
    --text-tertiary: #6b7280;
}
[data-bs-theme="dark"] {
    color-scheme: dark;
    --background-gray: #202733;
    --surface-white: #2b3543;
    --surface-raised: #354254;
    --field-bg: #354254;
    --border-color: #66768b;
    --hover-bg: #3c4b5f;
    --active-bg: #405438;
    --active-text: #b6df7d;
    --text-primary: #f3f6fa;
    --text-tertiary: #c2ccda;
    --text-secondary: #dde5ef;
    --bs-body-bg: var(--background-gray);
    --bs-body-color: var(--text-primary);
    --bs-app-bg-color: var(--background-gray);
    --bs-app-header-base-bg-color: var(--surface-white);
    --bs-app-sidebar-base-bg-color: var(--surface-white);
    --bs-card-bg: var(--surface-white);
    --bs-border-color: var(--border-color);
    --bs-gray-100: #354254;
    --bs-gray-200: #405065;
    --bs-gray-300: #66768b;
    --bs-gray-400: #aab8ca;
    --bs-gray-500: #c2ccda;
    --bs-gray-600: #c2ccda;
    --bs-gray-700: #dde5ef;
    --bs-gray-800: #e7edf5;
    --bs-gray-900: #f3f6fa;
    --primary-light: #354634;
    --status-success-light: #30493f;
    --status-warning-light: #4c4334;
    --status-danger-light: #4e3942;
    --status-info-light: #354634;
    --gradient-blue: linear-gradient(135deg, #304153, #364a60);
    --gradient-green: linear-gradient(135deg, #30483f, #3b5349);
    --gradient-red: linear-gradient(135deg, #49373f, #59434a);
    --gradient-orange: linear-gradient(135deg, #494135, #574d3c);
    --accent-text: #b6df7d;
    --success-text: #79d7a0;
    --warning-text: #f5c967;
    --danger-text: #ff9aaa;
    --info-text: #b6df7d;
}

/* Comfortable dark surfaces: explicit layers also cover vendor and page-level colors. */
html[data-bs-theme="dark"] body,
html[data-bs-theme="dark"] .app-page,
html[data-bs-theme="dark"] .app-wrapper,
html[data-bs-theme="dark"] .app-main,
html[data-bs-theme="dark"] .app-content { background-color: var(--background-gray) !important; color: var(--text-primary); }
html[data-bs-theme="dark"] :is(.card, .card-clean, .modal-content, .swal2-popup, .menu-sub-dropdown, .select2-dropdown, .app-header, .app-sidebar, .app-toolbar) {
    background-color: var(--surface-white) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}
html[data-bs-theme="dark"] :is(.card, .card-clean, .modal-content, .swal2-popup, .menu-sub-dropdown, .select2-dropdown) {
    border: 1px solid var(--border-color) !important;
    box-shadow: 0 5px 16px rgb(10 18 28 / 14%) !important;
}
html[data-bs-theme="dark"] :is(.card-gradient-blue, .card-gradient-purple) { background: var(--gradient-blue) !important; }
html[data-bs-theme="dark"] .card-gradient-green { background: var(--gradient-green) !important; }
html[data-bs-theme="dark"] .card-gradient-red { background: var(--gradient-red) !important; }
html[data-bs-theme="dark"] .card-gradient-orange { background: var(--gradient-orange) !important; }
html[data-bs-theme="dark"] :is(.form-control, .form-select, .form-control-clean, .form-select-clean, .select2-container .select2-selection, .select2-search__field, .e-input-group, .e-input-group input, .e-search, .e-toolbar .e-input) {
    background-color: var(--field-bg) !important;
    color: var(--text-primary) !important;
    border-color: #8596ad !important;
}
html[data-bs-theme="dark"] .select2-container .select2-selection__rendered,
html[data-bs-theme="dark"] :is(.table, .table td, .table th, .e-grid .e-rowcell, .e-grid .e-headercelldiv) { color: var(--text-primary) !important; }
html[data-bs-theme="dark"] :is(.form-control, .form-select):disabled {
    background-color: #29323f !important; color: #aab8ca !important; opacity: 1;
}
html[data-bs-theme="dark"] :is(input, textarea)::placeholder { color: var(--text-tertiary) !important; opacity: 1; }
html[data-bs-theme="dark"] :is(.text-gray-700, .text-gray-800, .text-body, .text-dark, .swal2-title, .swal2-html-container) { color: var(--text-primary) !important; }
html[data-bs-theme="dark"] :is(.text-gray-400, .text-gray-500, .text-gray-600, .text-muted, .form-text, .select2-selection__placeholder) { color: var(--text-tertiary) !important; }
html[data-bs-theme="dark"] :is(.collapse-toggle, .btn-light, .btn-icon.btn-light, .e-grid .e-toolbar .e-tbar-btn, .e-grid .e-toolbar .e-btn) {
    background-color: var(--surface-raised) !important; color: var(--text-primary) !important; border-color: var(--border-color) !important;
}
html[data-bs-theme="dark"] .collapse-toggle i { color: inherit !important; }
html[data-bs-theme="dark"] :is(.app-sidebar .menu-icon, .app-sidebar .menu-icon i, .modal-header .btn-icon i, .e-grid .e-icons, .e-grid .e-btn-icon) { color: var(--text-tertiary) !important; }
html[data-bs-theme="dark"] .required::after { color: var(--danger-text) !important; }
html[data-bs-theme="dark"] .btn.btn-icon i { color: inherit !important; }
html[data-bs-theme="dark"] .crm-action-btn { background-color: var(--surface-raised) !important; border-color: #8596ad !important; color: var(--text-primary) !important; }
html[data-bs-theme="dark"] :is(.crm-filter-card, .crm-split-block).bg-light-danger { background-color: var(--status-danger-light) !important; }
html[data-bs-theme="dark"] :is(.crm-filter-card, .crm-split-block).bg-light-warning { background-color: var(--status-warning-light) !important; }
html[data-bs-theme="dark"] :is(.crm-filter-card, .crm-split-block).bg-light-success { background-color: var(--status-success-light) !important; }
html[data-bs-theme="dark"] :is(.crm-filter-card, .crm-split-block).bg-light-primary { background-color: var(--primary-light) !important; }
/* Keep labels readable instead of letting dense CRM headings collide. */
html[data-bs-theme="dark"] .crm-data-table { min-width: 1280px; }
html[data-bs-theme="dark"] .crm-data-table th { white-space: nowrap; }
html[data-bs-theme="dark"] .form-select option { background-color: var(--field-bg); color: var(--text-primary); }
html[data-bs-theme="dark"] :is(.e-gridheader, .e-grid .e-headercell, .e-toolbar, .e-pager, .e-grid .e-content) {
    background-color: var(--surface-white) !important; border-color: var(--border-color) !important; color: var(--text-primary) !important;
}
html[data-bs-theme="dark"] .e-grid .e-headercell { background-color: var(--surface-raised) !important; }
html[data-bs-theme="dark"] .e-grid .e-rowcell { background-color: var(--surface-white) !important; }
html[data-bs-theme="dark"] :is(.select2-results__option--highlighted, .e-grid .e-row:hover .e-rowcell, .e-dropdown-popup .e-item.e-hover) {
    background-color: var(--hover-bg) !important; color: var(--text-primary) !important;
}
html[data-bs-theme="dark"] :is(.e-grid .e-rowcell.e-selectionbackground, .e-grid .e-row.e-active .e-rowcell, .select2-results__option[aria-selected="true"]) {
    background-color: var(--active-bg) !important; color: var(--text-primary) !important;
}
html[data-bs-theme="dark"] :is(.form-check-input, .e-checkbox-wrapper .e-frame) { border: 1px solid #aab8ca !important; }
html[data-bs-theme="dark"] :is(button, a, input, select, textarea, [tabindex]):focus-visible {
    outline: 3px solid #b6df7d !important; outline-offset: 3px;
}
.text-primary, .text-info { color: var(--accent-text) !important; }
.text-success { color: var(--success-text) !important; }
.text-warning { color: var(--warning-text) !important; }
.text-danger { color: var(--danger-text) !important; }
.text-gray-400, .text-gray-500, .text-muted, .form-text { color: var(--text-tertiary) !important; }
.nav-link:not(.active) { color: var(--text-tertiary) !important; }
.nav-link.active { color: var(--accent-text) !important; }
.select2-selection__placeholder, .select2-search__field::placeholder { color: var(--text-tertiary) !important; }
html .select2-container .select2-selection .select2-selection__placeholder { color: var(--text-tertiary) !important; }
.btn.btn-success { background-color: #237a45 !important; border-color: #237a45 !important; color: #fff !important; }
.btn.btn-success:hover { background-color: #1b5e35 !important; border-color: #1b5e35 !important; }
[data-bs-theme] .btn.btn-primary:not(:disabled):is(:hover, :focus, :active) {
    background-color: var(--primary-hover, #3d6209) !important;
    border-color: var(--primary-hover, #3d6209) !important;
    color: #fff !important;
}
[data-bs-theme] .btn.btn-success:not(:disabled):is(:hover, :focus, :active) {
    background-color: #1b5e35 !important;
    border-color: #1b5e35 !important;
    color: #fff !important;
}
.btn.btn-danger { background-color: #b42339 !important; border-color: #b42339 !important; color: #fff !important; }
.btn.btn-danger:hover { background-color: #921c2e !important; border-color: #921c2e !important; }
.btn-light-warning { color: var(--warning-text) !important; }
.btn-light-danger { color: var(--danger-text) !important; }
.btn-light-success { color: var(--success-text) !important; }
.btn-light-primary, .btn-light-info { color: var(--accent-text) !important; }
/* Filled interaction states must switch their text together with the background. */
[data-bs-theme] .btn:is(.btn-light-primary, .btn-light-info):not(:disabled):is(:hover, :focus, :active) {
    background-color: #3d6209 !important;
    border-color: #3d6209 !important;
    color: #fff !important;
}
[data-bs-theme] .btn.btn-light-warning:not(:disabled):is(:hover, :focus, :active) {
    background-color: #855600 !important;
    border-color: #855600 !important;
    color: #fff !important;
}
[data-bs-theme] .btn.btn-light-danger:not(:disabled):is(:hover, :focus, :active) {
    background-color: #b42339 !important;
    border-color: #b42339 !important;
    color: #fff !important;
}
[data-bs-theme] .btn.btn-light-success:not(:disabled):is(:hover, :focus, :active) {
    background-color: #237a45 !important;
    border-color: #237a45 !important;
    color: #fff !important;
}
.btn:is(.btn-light-warning, .btn-light-danger, .btn-light-success, .btn-light-primary, .btn-light-info) i { color: inherit !important; }
.btn.btn-primary .indicator-label, .btn.btn-danger .indicator-label { color: #fff !important; }
.app-header-logo.logo-dark { display: none !important; }
[data-bs-theme="dark"] .app-header-logo.logo-light { display: none !important; }
[data-bs-theme="dark"] .app-header-logo.logo-dark { display: block !important; }
[data-bs-theme="dark"] .text-gray-600 { color: var(--text-tertiary) !important; }
[data-bs-theme="dark"] .text-gray-800 { color: var(--text-secondary) !important; }
[data-bs-theme="dark"] .text-gray-900 { color: var(--text-primary) !important; }
[data-bs-theme="dark"] .form-text { color: #b5bac6 !important; }
[data-bs-theme="dark"] .btn.btn-light { color: #d4d7df !important; }
[data-bs-theme="dark"] .nav-link:not(.active) { color: #b5bac6 !important; }
[data-bs-theme="dark"] .nav-link.active { color: var(--accent-text) !important; }
[data-bs-theme="dark"] .app-sidebar-menu .menu-link:is(.active, :hover),
[data-bs-theme="dark"] .app-sidebar-menu .menu-item.here > .menu-link {
    background-color: #2b2b40 !important;
    color: var(--accent-text) !important;
}
[data-bs-theme="dark"] .app-sidebar-menu .menu-link:is(.active, :hover) :is(.menu-icon, .menu-title, i),
[data-bs-theme="dark"] .app-sidebar-menu .menu-item.here > .menu-link :is(.menu-icon, .menu-title, i) { color: inherit !important; }
[data-bs-theme="dark"] #kt_app_sidebar_mobile_toggle,
[data-bs-theme="dark"] #kt_app_sidebar_mobile_toggle i {
    background-color: #2b2b40 !important;
    color: var(--accent-text) !important;
}
[data-bs-theme="dark"] .e-grid .e-row:hover .e-rowcell,
[data-bs-theme="dark"] .e-dropdown-popup .e-item:is(:hover, .e-hover) {
    background-color: #2b2b40 !important;
    color: #f3f4f6 !important;
}
[data-bs-theme="dark"] .e-grid .e-rowcell.e-selectionbackground,
[data-bs-theme="dark"] .e-grid .e-row.e-active .e-rowcell,
[data-bs-theme="dark"] .e-dropdown-popup .e-item:is(.e-active, .e-selected) {
    background-color: #304020 !important;
    color: #f3f4f6 !important;
}
[data-bs-theme="dark"] .e-grid .e-pager .e-currentitem { color: #b6df7d !important; }
[data-bs-theme="dark"] .form-select option { color: #f3f4f6; background-color: #1e1e2d; }
/* Map tiles retain their source colors; controls and attribution stay legible. */
.leaflet-control-zoom a, .leaflet-control-attribution {
    color: #111827 !important;
}
.leaflet-control-zoom a span { color: inherit !important; }
.leaflet-control-attribution a { color: #175a8c !important; }
.badge.bg-warning { background-color: #f5c967 !important; color: #182119 !important; }
.badge.bg-success { background-color: #79d7a0 !important; color: #182119 !important; }
.badge-light-success { color: var(--success-text) !important; }
.badge-light-warning { color: var(--warning-text) !important; }
.badge-light-danger { color: var(--danger-text) !important; }
.badge-light-primary, .badge-light-info { color: var(--accent-text) !important; }
.badge.bg-danger { background-color: #b42339 !important; color: #fff !important; }
.badge:is(.bg-warning, .bg-success) i { color: inherit !important; }
.theme-toggle-login { display: flex; align-items: center; justify-content: center; }
[data-bs-theme="light"] .theme-toggle-login { color: #1d4ed8; }
[data-bs-theme="dark"] .select2-selection__placeholder,
[data-bs-theme="dark"] .select2-search__field::placeholder { color: #b5bac6 !important; }
