/* Final dark-mode recovery layer. Loaded after page CSS so hard-coded light utilities cannot win. */
html[data-bs-theme="dark"] {
    color-scheme: dark;
    --crm-shell-bg: #0b1020;
    --crm-surface-0: #0f172a;
    --crm-surface-1: #151f32;
    --crm-surface-2: #182235;
    --crm-surface-strong: #1d2939;
    --crm-border-subtle: #2f3b52;
    --crm-border-strong: #475467;
    --crm-text-strong: #f8fafc;
    --crm-text-base: #d0d5dd;
    --crm-text-soft: #98a2b3;
    --bs-body-bg: var(--crm-shell-bg);
    --bs-body-color: var(--crm-text-base);
    --bs-heading-color: var(--crm-text-strong);
    --bs-border-color: var(--crm-border-subtle);
}

html[data-bs-theme="dark"] body,
html[data-bs-theme="dark"] body.admin-layout,
html[data-bs-theme="dark"] body.auth-layout,
html[data-bs-theme="dark"] body.portal-shell,
html[data-bs-theme="dark"] .main-content,
html[data-bs-theme="dark"] .container-fluid,
html[data-bs-theme="dark"] .portal-page,
html[data-bs-theme="dark"] .auth-layout,
html[data-bs-theme="dark"] .installer-layout {
    background: var(--crm-shell-bg) !important;
    color: var(--crm-text-base) !important;
}

html[data-bs-theme="dark"] .card,
html[data-bs-theme="dark"] .modal-content,
html[data-bs-theme="dark"] .offcanvas,
html[data-bs-theme="dark"] .dropdown-menu,
html[data-bs-theme="dark"] .list-group-item,
html[data-bs-theme="dark"] .accordion-item,
html[data-bs-theme="dark"] .toast,
html[data-bs-theme="dark"] .alert,
html[data-bs-theme="dark"] .tbl-panel,
html[data-bs-theme="dark"] .mcc,
html[data-bs-theme="dark"] .mkpi,
html[data-bs-theme="dark"] .op-depth,
html[data-bs-theme="dark"] .mphb,
html[data-bs-theme="dark"] .crm-data-panel,
html[data-bs-theme="dark"] .crm-executive-panel,
html[data-bs-theme="dark"] .crm-command-rail,
html[data-bs-theme="dark"] .crm-filter-bar,
html[data-bs-theme="dark"] .crm-table-shell,
html[data-bs-theme="dark"] .crm-list-panel,
html[data-bs-theme="dark"] .crm-story-panel,
html[data-bs-theme="dark"] .crm-panel,
html[data-bs-theme="dark"] .portal-panel,
html[data-bs-theme="dark"] .portal-shell__nav,
html[data-bs-theme="dark"] .portal-workspace-hero,
html[data-bs-theme="dark"] .portal-access-card,
html[data-bs-theme="dark"] .portal-login-intro,
html[data-bs-theme="dark"] .auth-executive-shell,
html[data-bs-theme="dark"] .auth-access-pane,
html[data-bs-theme="dark"] .auth-brand-pane,
html[data-bs-theme="dark"] .rp-card,
html[data-bs-theme="dark"] .survey-card,
html[data-bs-theme="dark"] .estimate-card {
    background: var(--crm-surface-2) !important;
    border-color: var(--crm-border-subtle) !important;
    color: var(--crm-text-base) !important;
    box-shadow: none !important;
}

html[data-bs-theme="dark"] .card-header,
html[data-bs-theme="dark"] .card-footer,
html[data-bs-theme="dark"] .modal-header,
html[data-bs-theme="dark"] .modal-footer,
html[data-bs-theme="dark"] .dropdown-divider,
html[data-bs-theme="dark"] .tbl-panel__head,
html[data-bs-theme="dark"] .mcc__chart,
html[data-bs-theme="dark"] .crm-dashboard-list__item,
html[data-bs-theme="dark"] .crm-story-list__item,
html[data-bs-theme="dark"] .crm-mini-card,
html[data-bs-theme="dark"] .crm-insight-card,
html[data-bs-theme="dark"] .crm-report-diagnostic,
html[data-bs-theme="dark"] .crm-report-segment,
html[data-bs-theme="dark"] .crm-empty-state,
html[data-bs-theme="dark"] .portal-login-proof-card,
html[data-bs-theme="dark"] .portal-login-note,
html[data-bs-theme="dark"] .portal-demo-credential,
html[data-bs-theme="dark"] .rp-metric {
    background: var(--crm-surface-1) !important;
    border-color: var(--crm-border-subtle) !important;
    color: var(--crm-text-base) !important;
    box-shadow: none !important;
}

html[data-bs-theme="dark"] .bg-white,
html[data-bs-theme="dark"] .bg-light,
html[data-bs-theme="dark"] .bg-gray-100,
html[data-bs-theme="dark"] .bg-gray-200,
html[data-bs-theme="dark"] .bg-gradient-light,
html[data-bs-theme="dark"] pre.bg-light {
    background: var(--crm-surface-1) !important;
    color: var(--crm-text-base) !important;
    border-color: var(--crm-border-subtle) !important;
}

html[data-bs-theme="dark"] h1,
html[data-bs-theme="dark"] h2,
html[data-bs-theme="dark"] h3,
html[data-bs-theme="dark"] h4,
html[data-bs-theme="dark"] h5,
html[data-bs-theme="dark"] h6,
html[data-bs-theme="dark"] .h1,
html[data-bs-theme="dark"] .h2,
html[data-bs-theme="dark"] .h3,
html[data-bs-theme="dark"] .h4,
html[data-bs-theme="dark"] .h5,
html[data-bs-theme="dark"] .h6,
html[data-bs-theme="dark"] .text-dark,
html[data-bs-theme="dark"] .fw-bold,
html[data-bs-theme="dark"] .fw-semibold,
html[data-bs-theme="dark"] .dropdown-item,
html[data-bs-theme="dark"] .mkpi__value,
html[data-bs-theme="dark"] .mcc__title,
html[data-bs-theme="dark"] .mphb__title,
html[data-bs-theme="dark"] .crm-section-heading__title,
html[data-bs-theme="dark"] .portal-workspace-hero__title,
html[data-bs-theme="dark"] .portal-brand,
html[data-bs-theme="dark"] .portal-access-card__header h2,
html[data-bs-theme="dark"] .portal-login-copy h1,
html[data-bs-theme="dark"] .portal-login-note strong,
html[data-bs-theme="dark"] .rp-card strong,
html[data-bs-theme="dark"] .rp-card label,
html[data-bs-theme="dark"] .survey-card label,
html[data-bs-theme="dark"] .estimate-card label {
    color: var(--crm-text-strong) !important;
}

html[data-bs-theme="dark"] .text-muted,
html[data-bs-theme="dark"] .text-secondary,
html[data-bs-theme="dark"] .small,
html[data-bs-theme="dark"] small,
html[data-bs-theme="dark"] .mkpi__title,
html[data-bs-theme="dark"] .mkpi__subtitle,
html[data-bs-theme="dark"] .mcc__subtitle,
html[data-bs-theme="dark"] .mphb__subtitle,
html[data-bs-theme="dark"] .crm-section-heading__body,
html[data-bs-theme="dark"] .crm-inline-metric,
html[data-bs-theme="dark"] .portal-workspace-hero__subtitle,
html[data-bs-theme="dark"] .portal-login-proof-card p,
html[data-bs-theme="dark"] .portal-login-note span,
html[data-bs-theme="dark"] .portal-demo-credential,
html[data-bs-theme="dark"] .rp-metric span,
html[data-bs-theme="dark"] .rp-note {
    color: var(--crm-text-soft) !important;
}

html[data-bs-theme="dark"] a:not(.btn):not(.nav-link):not(.dropdown-item):not(.mui-btn) {
    color: color-mix(in srgb, var(--bs-primary, #0f5da8) 68%, #ffffff) !important;
}

html[data-bs-theme="dark"] .border,
html[data-bs-theme="dark"] .border-top,
html[data-bs-theme="dark"] .border-end,
html[data-bs-theme="dark"] .border-bottom,
html[data-bs-theme="dark"] .border-start,
html[data-bs-theme="dark"] hr,
html[data-bs-theme="dark"] .dropdown-divider {
    border-color: var(--crm-border-subtle) !important;
}

html[data-bs-theme="dark"] .form-control,
html[data-bs-theme="dark"] .form-select,
html[data-bs-theme="dark"] textarea,
html[data-bs-theme="dark"] input,
html[data-bs-theme="dark"] select,
html[data-bs-theme="dark"] .input-group-text,
html[data-bs-theme="dark"] .mui-input,
html[data-bs-theme="dark"] .mut-textarea,
html[data-bs-theme="dark"] .mdp-input,
html[data-bs-theme="dark"] .mun-input,
html[data-bs-theme="dark"] .mps-input,
html[data-bs-theme="dark"] .mcl-input,
html[data-bs-theme="dark"] .mti-box,
html[data-bs-theme="dark"] .mfu-dropzone,
html[data-bs-theme="dark"] .miu-dropzone,
html[data-bs-theme="dark"] .mus-switch-card,
html[data-bs-theme="dark"] .mdc-check-card,
html[data-bs-theme="dark"] .mrc-radio-card,
html[data-bs-theme="dark"] .select2-container--default .select2-selection--single,
html[data-bs-theme="dark"] .select2-container--default .select2-selection--multiple {
    background: var(--crm-surface-1) !important;
    border-color: var(--crm-border-subtle) !important;
    color: var(--crm-text-strong) !important;
    box-shadow: none !important;
}

html[data-bs-theme="dark"] .form-control:focus,
html[data-bs-theme="dark"] .form-select:focus,
html[data-bs-theme="dark"] textarea:focus,
html[data-bs-theme="dark"] input:focus,
html[data-bs-theme="dark"] select:focus,
html[data-bs-theme="dark"] .mui-input:focus,
html[data-bs-theme="dark"] .mut-textarea:focus,
html[data-bs-theme="dark"] .mdp-input:focus,
html[data-bs-theme="dark"] .mun-input:focus,
html[data-bs-theme="dark"] .mps-input:focus {
    background: var(--crm-surface-1) !important;
    border-color: color-mix(in srgb, var(--bs-primary, #0f5da8) 44%, var(--crm-border-subtle)) !important;
    color: var(--crm-text-strong) !important;
    box-shadow: 0 0 0 0.2rem rgba(var(--app-primary-rgb, 15, 93, 168), 0.18) !important;
}

html[data-bs-theme="dark"] ::placeholder,
html[data-bs-theme="dark"] .select2-selection__placeholder,
html[data-bs-theme="dark"] .select2-selection__rendered,
html[data-bs-theme="dark"] .mui-label,
html[data-bs-theme="dark"] .mui-hint,
html[data-bs-theme="dark"] .mut-label,
html[data-bs-theme="dark"] .mdp-label,
html[data-bs-theme="dark"] .mun-label,
html[data-bs-theme="dark"] .mps-label,
html[data-bs-theme="dark"] .mcl-label,
html[data-bs-theme="dark"] .mus-switch-card__description {
    color: var(--crm-text-soft) !important;
}

html[data-bs-theme="dark"] .table,
html[data-bs-theme="dark"] .tbl-table {
    --bs-table-color: var(--crm-text-base);
    --bs-table-bg: var(--crm-surface-2);
    --bs-table-border-color: var(--crm-border-subtle);
    --bs-table-striped-bg: var(--crm-surface-1);
    --bs-table-hover-bg: color-mix(in srgb, var(--bs-primary, #0f5da8) 10%, var(--crm-surface-2));
    color: var(--crm-text-base) !important;
}

html[data-bs-theme="dark"] .table thead th,
html[data-bs-theme="dark"] .tbl-table thead th {
    background: var(--crm-surface-1) !important;
    border-color: var(--crm-border-subtle) !important;
    color: var(--crm-text-soft) !important;
}

html[data-bs-theme="dark"] .table tbody td,
html[data-bs-theme="dark"] .tbl-table tbody td {
    border-color: var(--crm-border-subtle) !important;
    color: var(--crm-text-base) !important;
}

html[data-bs-theme="dark"] .btn-light,
html[data-bs-theme="dark"] .btn-outline-dark,
html[data-bs-theme="dark"] .btn-outline-secondary,
html[data-bs-theme="dark"] .btn-outline-primary,
html[data-bs-theme="dark"] .mui-btn--outline-primary,
html[data-bs-theme="dark"] .mui-btn--outline-secondary,
html[data-bs-theme="dark"] .rp-btn--ghost {
    background: var(--crm-surface-1) !important;
    border-color: var(--crm-border-subtle) !important;
    color: var(--crm-text-strong) !important;
    box-shadow: none !important;
}

html[data-bs-theme="dark"] .btn-light:hover,
html[data-bs-theme="dark"] .btn-outline-dark:hover,
html[data-bs-theme="dark"] .btn-outline-secondary:hover,
html[data-bs-theme="dark"] .btn-outline-primary:hover,
html[data-bs-theme="dark"] .mui-btn--outline-primary:hover,
html[data-bs-theme="dark"] .mui-btn--outline-secondary:hover,
html[data-bs-theme="dark"] .rp-btn--ghost:hover {
    background: color-mix(in srgb, var(--bs-primary, #0f5da8) 18%, var(--crm-surface-1)) !important;
    border-color: color-mix(in srgb, var(--bs-primary, #0f5da8) 42%, var(--crm-border-subtle)) !important;
    color: #ffffff !important;
}

html[data-bs-theme="dark"] .alert-warning.text-dark,
html[data-bs-theme="dark"] .alert-warning {
    background: rgba(181, 71, 8, 0.16) !important;
    border-color: rgba(251, 191, 36, 0.24) !important;
    color: #fcd34d !important;
}

html[data-bs-theme="dark"] .alert-success,
html[data-bs-theme="dark"] .rp-alert {
    background: rgba(6, 118, 71, 0.18) !important;
    border-color: rgba(117, 224, 167, 0.22) !important;
    color: #a7f3d0 !important;
}

html[data-bs-theme="dark"] .badge.bg-light,
html[data-bs-theme="dark"] .crm-chip,
html[data-bs-theme="dark"] .tbl-pill,
html[data-bs-theme="dark"] .tbl-status,
html[data-bs-theme="dark"] .mphb__badge,
html[data-bs-theme="dark"] .crm-section-heading__eyebrow,
html[data-bs-theme="dark"] .portal-access-card__badge {
    background: rgba(255, 255, 255, 0.06) !important;
    border-color: var(--crm-border-subtle) !important;
    color: var(--crm-text-base) !important;
}

html[data-bs-theme="dark"] .dropdown-item:hover,
html[data-bs-theme="dark"] .dropdown-item:focus,
html[data-bs-theme="dark"] .dropdown-item.active {
    background: color-mix(in srgb, var(--bs-primary, #0f5da8) 16%, var(--crm-surface-1)) !important;
    color: #ffffff !important;
}

html[data-bs-theme="dark"] .app-navbar,
html[data-bs-theme="dark"] .navbar {
    background: rgba(15, 23, 42, 0.84) !important;
    border-color: rgba(148, 163, 184, 0.18) !important;
    color: var(--crm-text-base) !important;
}

html[data-bs-theme="dark"] .sidenav.app-sidenav,
html[data-bs-theme="dark"] .sidenav.app-sidenav.theme-sidebar-transparent,
html[data-bs-theme="dark"] .sidenav.app-sidenav.theme-sidebar-light,
html[data-bs-theme="dark"] .sidenav.app-sidenav.theme-sidebar-dark,
html[data-bs-theme="dark"] .sidenav.app-sidenav.bg-white,
html[data-bs-theme="dark"] .sidenav.app-sidenav.bg-gradient-dark {
    --app-sidenav-footer-bg: linear-gradient(
        180deg,
        rgba(15, 23, 42, 0) 0%,
        rgba(15, 23, 42, 0.86) 24%,
        rgba(15, 23, 42, 0.98) 100%
    );
    background:
        linear-gradient(180deg, rgba(15, 23, 42, 0.86), rgba(15, 23, 42, 0.7)),
        rgba(15, 23, 42, 0.74) !important;
    border-color: rgba(148, 163, 184, 0.18) !important;
    color: var(--crm-text-base) !important;
    box-shadow: 0 20px 50px rgba(2, 6, 23, 0.28) !important;
    backdrop-filter: blur(18px);
}

html[data-bs-theme="dark"] .app-sidenav .navbar-nav .nav-link,
html[data-bs-theme="dark"] .app-sidenav .navbar-nav .nav-link .nav-link-text,
html[data-bs-theme="dark"] .app-sidenav .navbar-nav .nav-link i,
html[data-bs-theme="dark"] .app-sidenav .material-symbols-rounded,
html[data-bs-theme="dark"] .app-sidenav .sidebar-brand-name,
html[data-bs-theme="dark"] .app-sidenav .sidebar-brand-tagline,
html[data-bs-theme="dark"] .app-sidenav .btn,
html[data-bs-theme="dark"] .app-sidenav .sidebar-close-icon {
    color: var(--crm-text-base) !important;
}

html[data-bs-theme="dark"] .app-sidenav .navbar-nav .nav-link.active,
html[data-bs-theme="dark"] .app-sidenav .navbar-nav .nav-link:hover {
    background: color-mix(in srgb, var(--bs-primary, #0f5da8) 16%, rgba(255, 255, 255, 0.06)) !important;
    color: #ffffff !important;
}

html[data-bs-theme="dark"] .app-sidenav__workspace,
html[data-bs-theme="dark"] .app-sidenav__submenu,
html[data-bs-theme="dark"] .app-sidenav__empty {
    background: rgba(255, 255, 255, 0.04) !important;
    border-color: rgba(148, 163, 184, 0.16) !important;
    color: var(--crm-text-base) !important;
}

html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .app-sidenav__footer {
    background: var(--app-sidenav-footer-bg) !important;
    border-top-color: rgba(148, 163, 184, 0.18) !important;
}

html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .sidebar-footprint {
    background: rgba(255, 255, 255, 0.05) !important;
    border-color: rgba(148, 163, 184, 0.18) !important;
}

html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .text-dark,
html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .navbar-nav .nav-link,
html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .navbar-nav .nav-link.text-dark,
html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .nav-link-text,
html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .sidenav-normal,
html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .app-sidenav__caret,
html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .material-symbols-rounded {
    color: var(--crm-text-base, #d0d5dd) !important;
}

html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .sidebar-brand-name {
    color: var(--crm-text-strong, #f8fafc) !important;
}

html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .sidebar-brand-tagline,
html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .app-sidenav__section {
    color: var(--crm-text-soft, #98a2b3) !important;
}

html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .navbar-nav .nav-link.active,
html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .navbar-nav .nav-link.active.text-dark,
html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .navbar-nav .nav-link.bg-gray-200 {
    background: color-mix(in srgb, var(--bs-primary, #0f5da8) 18%, rgba(255, 255, 255, 0.07)) !important;
    border-color: rgba(148, 163, 184, 0.18) !important;
    color: #ffffff !important;
}

html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .navbar-nav .nav-link.active .nav-link-text,
html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .navbar-nav .nav-link.active .material-symbols-rounded {
    color: #ffffff !important;
}

html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .navbar-nav .nav-link.text-dark:not(.active) .nav-link-text,
html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .navbar-nav .nav-link.text-dark:not(.active) .material-symbols-rounded,
html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .navbar-nav .nav-link.text-dark:not(.active) > i {
    color: var(--crm-text-base, #d0d5dd) !important;
}

html[data-bs-theme="dark"] .sidenav.app-sidenav.crm-shell-sidenav .navbar-nav .nav-link .opacity-5 {
    opacity: 0.78 !important;
}
