/* Semantic palette shared by admin, publisher, authentication and document chrome.
   Component adapters live in theme-components.css. Email/creative proofs stay literal. */
:root {
    --theme-bg: #f5f7ff;
    --theme-surface: #ffffff;
    --theme-navbar: #ffffff;
    --theme-raised: #eef2fa;
    --theme-input: #ffffff;
    --theme-text: #1e293b;
    --theme-secondary: #465773;
    --theme-muted: #52627b;
    --theme-disabled: #65748b;
    --theme-border: #cbd5e1;
    --theme-border-subtle: #e2e8f0;
    --theme-control-border: #7889a2;
    --theme-hover: #e8edfa;
    --theme-active: #e1e5ff;
    --theme-focus: #4b49ac;
    --theme-link: #4b49ac;
    --theme-link-hover: #323080;
    --theme-primary: #5755d9;
    --theme-primary-hover: #4442bd;
    --theme-on-primary: #ffffff;
    --theme-on-brand: #ffffff;
    --theme-success: #176341;
    --theme-success-bg: #e5f5ed;
    --theme-success-border: #439576;
    --theme-warning: #805008;
    --theme-warning-bg: #fff3db;
    --theme-warning-border: #ad8032;
    --theme-error: #a32140;
    --theme-error-bg: #fce8ed;
    --theme-error-border: #bd596f;
    --theme-info: #20528e;
    --theme-info-bg: #e7f1ff;
    --theme-info-border: #537eac;
    --theme-purple: #6141a2;
    --theme-purple-bg: #f0eafa;
    --theme-overlay: rgba(9, 15, 27, 0.6);
    --theme-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
    --theme-shadow-raised: 0 16px 40px rgba(15, 23, 42, 0.2);
    --theme-focus-ring: 0 0 0 3px rgba(75, 73, 172, 0.22);
    --theme-chart-1: #2563eb;
    --theme-chart-2: #168348;
    --theme-chart-3: #c65310;
    --theme-chart-4: #8550cf;
    --theme-chart-5: #0f766e;
    --theme-chart-cyan: #087e95;
    --theme-chart-indigo: #5659cf;
    --theme-dropdown: var(--theme-surface);
    --theme-modal: var(--theme-surface);
    --theme-tooltip: var(--theme-raised);
    --theme-placeholder: var(--theme-muted);
    --theme-icon: var(--theme-secondary);
    --theme-divider: var(--theme-border-subtle);
    color-scheme: light;
}
html[data-theme='dark'] {
    --theme-bg: #000000;
    --theme-surface: #0c0c0c;
    --theme-navbar: #000000;
    --theme-raised: #1a1a1a;
    --theme-input: #080808;
    --theme-text: #f5f5f5;
    --theme-secondary: #d4d4d4;
    --theme-muted: #b0b0b0;
    --theme-disabled: #949494;
    --theme-border: #404040;
    --theme-border-subtle: #2a2a2a;
    --theme-control-border: #787878;
    --theme-hover: #242424;
    --theme-active: #303030;
    --theme-focus: #b8bdff;
    --theme-link: #b8bdff;
    --theme-link-hover: #d4d7ff;
    --theme-primary: #6664e4;
    --theme-primary-hover: #5956d8;
    --theme-success: #a4e5c5;
    --theme-success-bg: #173d32;
    --theme-success-border: #397761;
    --theme-warning: #ffcf94;
    --theme-warning-bg: #44331e;
    --theme-warning-border: #85663a;
    --theme-error: #ffb1bb;
    --theme-error-bg: #492431;
    --theme-error-border: #8a4359;
    --theme-info: #b7deff;
    --theme-info-bg: #183350;
    --theme-info-border: #3b658d;
    --theme-purple: #d3c1ff;
    --theme-purple-bg: #342c52;
    --theme-overlay: rgba(0, 0, 0, 0.72);
    --theme-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    --theme-shadow-raised: 0 16px 40px rgba(0, 0, 0, 0.4);
    --theme-focus-ring: 0 0 0 3px rgba(184, 189, 255, 0.25);
    --theme-chart-1: #82b4ff;
    --theme-chart-2: #6bdb9d;
    --theme-chart-3: #ffbd83;
    --theme-chart-4: #c4a3ff;
    --theme-chart-5: #63d8cc;
    --theme-chart-cyan: #22d3ee;
    --theme-chart-indigo: #a3a5ff;
    color-scheme: dark;
}

html[data-theme='dark'] {
    /* Shared dashboard tokens. */
    --bg-main: var(--theme-bg);
    --card-bg: var(--theme-surface);
    --text-dark: var(--theme-text);
    --text-muted: var(--theme-muted);
    --border-color: var(--theme-border);
    --c-blue-bg: var(--theme-info-bg);
    --c-blue-text: var(--theme-info);
    --c-green-bg: var(--theme-success-bg);
    --c-green-text: var(--theme-success);
    --c-purple-bg: var(--theme-purple-bg);
    --c-purple-text: var(--theme-purple);
    --c-orange-bg: var(--theme-warning-bg);
    --c-orange-text: var(--theme-warning);
}
.theme-toggle {
    align-items: center;
    background: var(--theme-surface);
    border: 1px solid var(--theme-border);
    border-radius: 8px;
    color: var(--theme-text);
    display: inline-flex;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    gap: 8px;
    justify-content: center;
    margin: 0 12px;
    min-height: 44px;
    min-width: 116px;
    padding: 8px 12px;
    white-space: nowrap;
}
.theme-toggle:hover {
    background: var(--theme-hover);
}
.theme-toggle:focus-visible {
    outline: 3px solid var(--theme-link);
    outline-offset: 3px;
}
.theme-toggle .theme-sun {
    display: none;
}

/* Both appearances own the entire header, including legacy navbar/sidebar
   variants. Switch its colors together instead of animating separate pieces. */
html[data-theme] .navbar,
html[data-theme] .navbar :is(.navbar-brand-wrapper, .navbar-menu-wrapper) {
    background: var(--theme-navbar) !important;
    color: var(--theme-text) !important;
    border-color: var(--theme-border);
    transition-property: box-shadow;
}
html[data-theme]
    .navbar
    :is(.navbar-brand, .navbar-toggler, .navbar-text, .nav-link) {
    color: var(--theme-text) !important;
}
html[data-theme='dark'] .theme-toggle .theme-sun {
    display: block;
}
html[data-theme='dark'] .theme-toggle .theme-moon {
    display: none;
}

html[data-theme='dark'] body,
html[data-theme='dark']
    :is(
        .container-scroller,
        .container-fluid.page-body-wrapper,
        .main-panel,
        .content-wrapper,
        .footer
    ) {
    background: var(--theme-bg);
    color: var(--theme-text);
}
html[data-theme='dark']
    :is(
        .navbar,
        .navbar-brand-wrapper,
        .navbar-menu-wrapper,
        .sidebar,
        .card,
        .modal-content,
        .dropdown-menu,
        .list-group-item,
        .swal-modal,
        .popover,
        .popover-header,
        .popover-body,
        .settings-panel
    ) {
    background-color: var(--theme-surface);
    color: var(--theme-text);
    border-color: var(--theme-border);
}
html[data-theme='dark']
    :is(
        .navbar-brand,
        .navbar-toggler,
        .sidebar .nav .nav-link,
        .sidebar .nav .menu-icon,
        .sidebar .nav .menu-title,
        .dropdown-item,
        .close,
        .swal-title,
        .swal-text
    ) {
    color: var(--theme-text);
}
html[data-theme='dark'] .close {
    text-shadow: none;
    opacity: 1;
}
html[data-theme='dark']
    :is(
        .sidebar .nav > .nav-item:hover > .nav-link,
        .sidebar .nav > .nav-item.active > .nav-link,
        .sidebar .nav .nav-link.active,
        .sidebar .nav .sub-menu,
        .sidebar .nav .collapse,
        .dropdown-item:hover,
        .dropdown-item:focus,
        .navbar-toggler:hover
    ) {
    background: var(--theme-raised);
    color: var(--theme-link);
}
html[data-theme='dark'] .sidebar .nav .sub-menu .nav-item::before {
    background: var(--theme-muted);
}
html[data-theme='dark']
    :is(h1, h2, h3, h4, h5, h6, legend, label, .card-title, .modal-title):not(
        [data-theme-preserve] *
    ) {
    color: var(--theme-text);
}
html[data-theme='dark']
    :is(.text-muted, .text-secondary, .card-description, .form-text, .footer) {
    color: var(--theme-muted) !important;
}
html[data-theme='dark'] :is(.text-dark, .text-black, .text-body) {
    color: var(--theme-text) !important;
}
html[data-theme='dark'] .text-primary {
    color: var(--theme-link) !important;
}
html[data-theme='dark'] .text-danger {
    color: var(--theme-error) !important;
}
html[data-theme='dark'] .text-success {
    color: var(--theme-success) !important;
}
html[data-theme='dark'] .text-warning {
    color: var(--theme-warning) !important;
}
html[data-theme='dark'] .text-info {
    color: var(--theme-info) !important;
}
html[data-theme='dark']
    a:not([data-theme-preserve] *):not(.btn):not(.nav-link):not(
        .navbar-brand
    ):not(.dropdown-item):not(.page-link) {
    color: var(--theme-link);
}
html[data-theme='dark'] :is(.bg-white, .bg-light) {
    background-color: var(--theme-surface) !important;
    color: var(--theme-text);
}
html[data-theme='dark']
    :is(.border, .border-top, .border-bottom, .border-left, .border-right) {
    border-color: var(--theme-border) !important;
}
html[data-theme='dark']
    :is(
        hr,
        .modal-header,
        .modal-footer,
        .card-header,
        .card-footer,
        .dropdown-divider
    ) {
    border-color: var(--theme-border);
}
html[data-theme='dark'] :is(.card-header, .card-footer) {
    background-color: var(--theme-raised);
}

/* Forms, tables, navigation and states share the same dark surfaces. */
html[data-theme='dark']
    :is(
        .form-control,
        .custom-select,
        .input-group-text,
        .select2-container--default .select2-selection--single,
        .select2-container--default .select2-selection--multiple,
        .select2-dropdown,
        .select2-search__field
    ) {
    background-color: var(--theme-input);
    border-color: var(--theme-border);
    color: var(--theme-text);
}
html[data-theme='dark']
    .select2-container--default
    .select2-selection--single
    .select2-selection__rendered {
    color: var(--theme-text);
}
html[data-theme='dark'] .form-control::placeholder {
    color: var(--theme-muted);
    opacity: 1;
}
html[data-theme='dark'] :is(.form-control:disabled, .form-control[readonly]) {
    background-color: var(--theme-raised);
    color: var(--theme-muted);
}
html[data-theme='dark'] .form-control:focus {
    border-color: var(--theme-link);
    box-shadow: var(--theme-focus-ring);
}
html[data-theme='dark'] input:is([type='checkbox'], [type='radio']) {
    accent-color: #777ef0;
}
html[data-theme='dark'] .table {
    color: var(--theme-text);
}
html[data-theme='dark'] .table :is(th, td) {
    border-color: var(--theme-border);
}
html[data-theme='dark']
    :is(
        .table thead th,
        .table .thead-light th,
        .modern-table th,
        .heatmap-table th
    ) {
    background: var(--theme-raised);
    color: var(--theme-text);
}
html[data-theme='dark'] .table-striped tbody tr:nth-of-type(odd) {
    background: rgba(176, 191, 212, 0.055);
}
html[data-theme='dark']
    :is(.table-hover tbody tr:hover, .modern-table tbody tr:hover) {
    background: var(--theme-raised);
    color: var(--theme-text);
}
html[data-theme='dark']
    :is(
        .page-link,
        .nav-tabs .nav-link,
        .btn-light,
        .btn-outline-secondary,
        .btn-outline-dark
    ) {
    background: var(--theme-surface);
    border-color: var(--theme-border);
    color: var(--theme-text);
}
html[data-theme='dark']
    :is(
        .nav-tabs,
        .nav-tabs .nav-link.active,
        .nav-tabs .nav-link:hover,
        .nav-tabs .nav-item.show .nav-link
    ) {
    border-color: var(--theme-border);
}
html[data-theme='dark']
    :is(
        .nav-tabs .nav-link.active,
        .page-item.active .page-link,
        .btn-light:hover,
        .btn-outline-secondary:hover,
        .btn-outline-dark:hover
    ) {
    background: var(--theme-raised);
    color: var(--theme-link);
}
html[data-theme='dark'] .page-item.disabled .page-link {
    background: var(--theme-surface);
    border-color: var(--theme-border);
    color: var(--theme-muted);
}
html[data-theme='dark'] .btn-outline-primary {
    border-color: var(--theme-link);
    color: var(--theme-link);
}
html[data-theme='dark'] .btn-outline-danger {
    border-color: var(--theme-error);
    color: var(--theme-error);
}
html[data-theme='dark'] .btn-outline-success {
    border-color: var(--theme-success);
    color: var(--theme-success);
}
html[data-theme='dark'] .btn-outline-info {
    border-color: var(--theme-info);
    color: var(--theme-info);
}
html[data-theme='dark'] .btn-outline-warning {
    border-color: var(--theme-warning);
    color: var(--theme-warning);
}
html[data-theme='dark']
    :is(
        .btn-outline-primary,
        .btn-outline-danger,
        .btn-outline-success,
        .btn-outline-info,
        .btn-outline-warning
    ):hover {
    background: var(--theme-raised);
}
html[data-theme='dark'] .btn-link {
    color: var(--theme-link);
}
html[data-theme='dark'] .alert-info {
    background: var(--theme-info-bg);
    border-color: var(--theme-info-border);
    color: var(--theme-info);
}
html[data-theme='dark'] .alert-success {
    background: var(--theme-success-bg);
    border-color: var(--theme-success-border);
    color: var(--theme-success);
}
html[data-theme='dark'] .alert-warning {
    background: var(--theme-warning-bg);
    border-color: var(--theme-warning-border);
    color: var(--theme-warning);
}
html[data-theme='dark'] .alert-danger {
    background: var(--theme-error-bg);
    border-color: var(--theme-error-border);
    color: var(--theme-error);
}
html[data-theme='dark'] .alert-secondary {
    background: var(--theme-raised);
    border-color: var(--theme-border);
    color: var(--theme-text);
}
html[data-theme='dark'] code {
    color: var(--theme-purple);
    background-color: var(--theme-input);
}
html[data-theme='dark'] pre {
    color: var(--theme-text);
    background-color: var(--theme-input);
}

/* Existing custom admin cards and detail panels. */
html[data-theme='dark']
    :is(
        .affiliate-detail-card,
        .affiliate-detail-metric,
        .affiliate-manager-summary,
        .affiliate-manager-empty,
        .affiliate-selection-toolbar,
        .manager-profile-summary,
        .banner-layout-card,
        .banner-selected-publishers,
        .banner-search-result,
        .kpi-card,
        .insight-row,
        .system-pill,
        .empty-state,
        .quick-action-icon,
        .chart-legend span,
        .heatmap-toggle button,
        .crm-card,
        .crm-kpi,
        .crm-example,
        .crm-drop,
        .crm-recipient,
        .crm-modal-panel,
        .crm-confirm-summary,
        .crm-action-menu-list,
        .crm-clean-tabs button
    ) {
    background: var(--theme-surface);
    border-color: var(--theme-border);
    color: var(--theme-text);
}
html[data-theme='dark']
    :is(
        .affiliate-detail-card h6,
        .affiliate-detail-field dd,
        .affiliate-detail-metric strong,
        .affiliate-manager-summary strong,
        .affiliate-manager-summary span,
        .affiliate-manager-assignment-name
    ) {
    color: var(--theme-text);
}
html[data-theme='dark']
    :is(
        .affiliate-detail-field dt,
        .affiliate-detail-metric span,
        .affiliate-detail-empty,
        .affiliate-manager-empty,
        .affiliate-form-hint
    ) {
    color: var(--theme-muted);
}
html[data-theme='dark']
    :is(
        .dashboard-date-select,
        .dashboard-date-input,
        .heatmap-table td:first-child,
        .heatmap-cell.is-empty,
        .btn-premium,
        .banner-editor-modal .modal-body,
        .banner-editor-modal .modal-header,
        .banner-editor-modal .modal-footer
    ) {
    background: var(--theme-surface);
    border-color: var(--theme-border);
    color: var(--theme-text);
}
html[data-theme='dark']
    :is(
        .quick-action-item:hover,
        .banner-search-result:hover,
        .crm-clean-tabs button.active
    ) {
    background: var(--theme-raised);
}
html[data-theme='dark']
    :is(
        .crm-table th,
        .crm-table tbody tr:nth-child(even) td,
        .crm-table tbody tr:hover td
    ) {
    background: var(--theme-raised);
    color: var(--theme-text);
}

/* Outreach chrome uses dark surfaces; email and creative previews retain their actual colors. */
html[data-theme='dark'] .outreach {
    --reach-ink: var(--theme-text);
    --reach-muted: var(--theme-muted);
    --reach-border: var(--theme-border);
    --reach-accent: var(--theme-link);
    color: var(--theme-text);
}
html[data-theme='dark']
    :is(
        .outreach-quick button,
        .outreach-manager-card,
        .outreach-selection,
        .outreach-metrics div,
        .outreach-review-summary div,
        .outreach-message-meta,
        .outreach-preview-header,
        .outreach-skeleton
    ) {
    background: var(--theme-surface);
    border-color: var(--theme-border);
    color: var(--theme-text);
}
html[data-theme='dark']
    :is(.outreach-table th, .outreach-table tbody tr:nth-child(even)) {
    background: var(--theme-raised);
    color: var(--theme-text);
}
html[data-theme='dark'] .outreach-table :is(th, td) {
    border-color: var(--theme-border);
}
html[data-theme='dark']
    :is(.outreach-table strong, .outreach-manager-details strong) {
    color: var(--theme-text);
}
html[data-theme='dark']
    :is(
        .outreach-eyebrow,
        .outreach-manager-details small,
        .outreach-preview-meta,
        .outreach-recommendation
    ) {
    color: var(--theme-muted);
}
html[data-theme='dark']
    :is(
        .tox .tox-toolbar,
        .tox .tox-toolbar__primary,
        .tox .tox-toolbar-overlord,
        .tox .tox-statusbar,
        .tox .tox-editor-header
    ) {
    background: var(--theme-raised);
    border-color: var(--theme-border);
    color: var(--theme-text);
}
html[data-theme='dark'] .tox .tox-tbtn {
    color: var(--theme-text);
}
html[data-theme='dark'] .tox .tox-tbtn svg {
    fill: var(--theme-text);
}
html[data-theme='dark']
    :is(
        #emailPreview,
        #sentMessagePreview,
        .tox-edit-area__iframe,
        .crm-mail-preview-body
    ) {
    color-scheme: light;
}

@media print {
    .theme-toggle {
        display: none;
    }
}

html[data-theme='dark'] .affiliate-bulk-bar {
    background: var(--theme-raised);
    border-color: var(--theme-border);
}
html[data-theme='dark']
    :is(
        .affiliate-bulk-copy,
        .affiliate-manager-row strong,
        .affiliate-checkbox-label
    ) {
    color: var(--theme-text);
}
html[data-theme='dark']
    :is(.affiliate-bulk-copy small, .affiliate-manager-row small) {
    color: var(--theme-muted);
}
html[data-theme='dark'] .affiliate-manager-row {
    border-color: var(--theme-border);
}
html[data-theme='dark'] .kpi-icon {
    background: var(--c-blue-bg);
    color: var(--c-blue-text);
}
html[data-theme='dark'] .navbar {
    box-shadow: 0 1px 0 var(--theme-border);
}
html[data-theme='dark'] .outreach-note {
    background: var(--theme-raised);
    color: var(--theme-muted);
}
html[data-theme='dark'] .outreach-notice {
    background: var(--theme-success-bg);
    color: var(--theme-success);
}
html[data-theme='dark'] .kpi-meta {
    color: var(--theme-success);
}
html[data-theme='dark'] .page-skeleton-bar {
    background: var(--theme-bg);
    border-color: var(--theme-border);
}
html[data-theme='dark'] .page-skeleton-line {
    background: var(--theme-raised);
}
@media (prefers-reduced-motion: reduce) {
    html[data-theme]
        :is(
            .card,
            .navbar,
            .navbar-brand-wrapper,
            .navbar-menu-wrapper,
            .sidebar,
            .footer,
            .theme-toggle,
            .modal,
            .modal-dialog
        ) {
        transition: none !important;
    }
}

/* Shared interaction states. Existing light component geometry and colors stay intact. */
html[data-theme] {
    background: var(--theme-bg);
}
.theme-floating-toggle {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 1031;
}
html[data-theme-page='bill-index'] .theme-floating-toggle {
    right: auto;
    left: 12px;
}
.theme-toggle {
    cursor: pointer;
    transition:
        background-color 0.15s,
        border-color 0.15s,
        color 0.15s;
}
.theme-toggle:active {
    background: var(--theme-active);
}
html[data-theme] .btn-outline-primary:not(:disabled):not(.disabled):active,
html[data-theme] .btn-outline-primary:not(:disabled):not(.disabled).active {
    background: var(--theme-primary);
    border-color: var(--theme-primary);
    color: var(--theme-on-primary);
}
.theme-toggle:disabled {
    color: var(--theme-disabled);
    cursor: not-allowed;
}
html[data-theme]
    :is(
        a,
        button,
        input,
        select,
        textarea,
        [tabindex],
        [contenteditable='true']
    ):focus-visible {
    outline: 2px solid var(--theme-focus);
    outline-offset: 3px;
}
html[data-theme] input:is([type='checkbox'], [type='radio']) {
    accent-color: var(--theme-primary);
}
html[data-theme='dark'] {
    --crm-primary: var(--theme-link);
    --crm-primary-2: var(--theme-primary);
    --crm-ink: var(--theme-text);
    --crm-muted: var(--theme-muted);
    --crm-line: var(--theme-border);
    --crm-green: var(--theme-success);
    --crm-red: var(--theme-error);
    --crm-orange: var(--theme-warning);
    --cc-ink: var(--theme-text);
    --cc-muted: var(--theme-muted);
    --cc-line: var(--theme-border);
    --cc-primary: var(--theme-link);
    --cc-green: var(--theme-success);
    --cc-red: var(--theme-error);
    --cc-orange: var(--theme-warning);
    --shadow-sm: var(--theme-shadow);
    --shadow-md: var(--theme-shadow-raised);
}
html[data-theme='dark'] .profile-page {
    --profile-ink: var(--theme-text);
    --profile-muted: var(--theme-muted);
    --profile-surface: var(--theme-surface);
    --profile-line: var(--theme-border);
    --profile-accent: var(--theme-link);
}
html[data-theme='dark'] :is(.content-wrapper, .profile-content-wrapper) {
    background: var(--theme-bg) !important;
}
html[data-theme='dark']
    :is(.card, .modal-content, .dropdown-menu, .popover, .swal-modal) {
    box-shadow: var(--theme-shadow);
}
html[data-theme='dark']
    :is(
        .form-control,
        .form-select,
        .custom-select,
        .input-group-text,
        .crm-input,
        .crm-select,
        .cc-input,
        .cc-select,
        .cc-textarea,
        input:not([type='checkbox']):not([type='radio']):not(
                [type='submit']
            ):not([type='button']):not([type='color']):not([type='range']),
        select,
        textarea
    ) {
    background-color: var(--theme-input);
    color: var(--theme-text);
    border-color: var(--theme-control-border);
}
html[data-theme='dark'] :is(input, textarea)::placeholder {
    color: var(--theme-placeholder);
    opacity: 1;
}
html[data-theme='dark'] :is(input, textarea, select):hover:not(:disabled) {
    border-color: var(--theme-focus);
}
html[data-theme='dark'] :is(input, textarea, select):focus {
    background-color: var(--theme-input);
    color: var(--theme-text);
    border-color: var(--theme-focus);
    box-shadow: var(--theme-focus-ring);
}
html[data-theme='dark'] :is(input, textarea, select):is(:disabled, [readonly]),
html[data-theme='dark'] fieldset:disabled :is(input, textarea, select) {
    background-color: var(--theme-raised);
    color: var(--theme-disabled);
    opacity: 1;
}
html[data-theme='dark'] :is(.is-invalid, [aria-invalid='true']) {
    border-color: var(--theme-error) !important;
}
html[data-theme='dark'] .is-valid {
    border-color: var(--theme-success) !important;
}
html[data-theme='dark'] .invalid-feedback {
    color: var(--theme-error);
}
html[data-theme='dark'] .valid-feedback {
    color: var(--theme-success);
}
html[data-theme='dark'] input:-webkit-autofill {
    -webkit-text-fill-color: var(--theme-text);
    caret-color: var(--theme-text);
    -webkit-box-shadow: 0 0 0 1000px var(--theme-input) inset;
}
html[data-theme='dark']
    :is(.custom-control-label::before, .form-check-label::before) {
    background-color: var(--theme-input);
    border: 1px solid var(--theme-control-border);
}
html[data-theme='dark']
    :is(
        .custom-control-input:checked ~ .custom-control-label::before,
        .form-check-input:checked ~ .form-check-label::before
    ) {
    background-color: var(--theme-primary);
}
html[data-theme='dark'] .custom-control-input:disabled ~ .custom-control-label {
    color: var(--theme-disabled);
}
html[data-theme='dark']
    .custom-control-input:disabled
    ~ .custom-control-label::before {
    background-color: var(--theme-raised);
}
html[data-theme='dark'] .custom-switch .custom-control-label::after {
    background-color: var(--theme-muted);
}
html[data-theme='dark'] input[type='file']::file-selector-button {
    background: var(--theme-raised);
    color: var(--theme-text);
    border: 1px solid var(--theme-control-border);
}
html[data-theme='dark'] :is(.table, .modern-table, .crm-table, .cc-table) {
    --bs-table-color: var(--theme-text);
    --bs-table-bg: var(--theme-surface);
    --bs-table-striped-color: var(--theme-text);
    --bs-table-striped-bg: var(--theme-raised);
    --bs-table-hover-color: var(--theme-text);
    --bs-table-hover-bg: var(--theme-hover);
    --bs-table-active-color: var(--theme-text);
    --bs-table-active-bg: var(--theme-active);
    color: var(--theme-text);
    border-color: var(--theme-border);
}
html[data-theme='dark'] .table :is(thead, tfoot) {
    color: var(--theme-text);
    background: var(--theme-raised);
}
html[data-theme='dark']
    :is(.table-hover, .modern-table, .crm-table, .cc-table)
    tbody
    tr:hover
    > * {
    background: var(--theme-hover);
    color: var(--theme-text);
}
html[data-theme='dark']
    .table
    :is(.selected, .table-active, [aria-selected='true'])
    > * {
    background: var(--theme-active);
    color: var(--theme-text);
}
html[data-theme='dark']
    :is(
        .expanded-row,
        .row-bg,
        .list-group-item-action:hover,
        .list-group-item-action:focus
    ) {
    background: var(--theme-raised);
    color: var(--theme-text);
}
html[data-theme='dark']
    :is(
        .pagination .page-link,
        .nav-tabs .nav-link,
        .nav-pills .nav-link,
        .dropdown-item
    ):is(:hover, :focus, :active) {
    color: var(--theme-link);
    background: var(--theme-hover);
    border-color: var(--theme-border);
}
html[data-theme='dark']
    :is(
        .pagination .page-item.active .page-link,
        .nav-pills .nav-link.active,
        .dropdown-item.active
    ) {
    color: var(--theme-link);
    background: var(--theme-active);
    border-color: var(--theme-border);
}
html[data-theme='dark']
    :is(.dropdown-item.disabled, .page-item.disabled .page-link) {
    color: var(--theme-disabled);
    background: var(--theme-surface);
}
html[data-theme='dark']
    :is(
        .btn-light,
        .btn-secondary,
        .btn-outline-secondary,
        .btn-dark,
        .btn-outline-dark
    ) {
    background: var(--theme-raised);
    color: var(--theme-text);
    border-color: var(--theme-control-border);
}
html[data-theme='dark']
    :is(
        .btn-light,
        .btn-secondary,
        .btn-outline-secondary,
        .btn-dark,
        .btn-outline-dark
    ):is(:hover, :focus, :active, .active) {
    background: var(--theme-hover);
    color: var(--theme-text);
    border-color: var(--theme-focus);
}
html[data-theme] .btn-primary {
    background-color: var(--theme-primary);
    border-color: var(--theme-primary);
    color: var(--theme-on-primary);
}
html[data-theme] .btn-primary:is(:hover, :active, .active) {
    background-color: var(--theme-primary-hover);
    border-color: var(--theme-primary-hover);
    color: var(--theme-on-primary);
}
html[data-theme='dark']
    :is(
        .btn-outline-primary,
        .btn-outline-success,
        .btn-outline-info,
        .btn-outline-warning,
        .btn-outline-danger
    ):is(:hover, :focus, :active, .active) {
    background: var(--theme-hover);
    box-shadow: none;
}
html[data-theme='dark']
    .btn-outline-primary:is(:hover, :focus, :active, .active) {
    color: var(--theme-link);
}
html[data-theme='dark']
    .btn-outline-success:is(:hover, :focus, :active, .active) {
    color: var(--theme-success);
}
html[data-theme='dark']
    .btn-outline-danger:is(:hover, :focus, :active, .active) {
    color: var(--theme-error);
}
html[data-theme='dark']
    .btn-outline-warning:is(:hover, :focus, :active, .active) {
    color: var(--theme-warning);
}
html[data-theme='dark'] .btn-outline-info:is(:hover, :focus, :active, .active) {
    color: var(--theme-info);
}
html[data-theme='dark'] .btn:is(:disabled, .disabled) {
    opacity: 0.55;
    box-shadow: none;
    cursor: not-allowed;
}
html[data-theme='dark']
    :is(.badge-light, .badge-secondary, .alert-light, .alert-dark) {
    background: var(--theme-raised);
    color: var(--theme-text);
    border-color: var(--theme-border);
}
html[data-theme='dark']
    :is(.badge-success, .badge-outline-success, .badge-soft-success) {
    background: var(--theme-success-bg);
    color: var(--theme-success);
    border-color: var(--theme-success-border);
}
html[data-theme='dark']
    :is(.badge-warning, .badge-outline-warning, .badge-soft-warning) {
    background: var(--theme-warning-bg);
    color: var(--theme-warning);
    border-color: var(--theme-warning-border);
}
html[data-theme='dark']
    :is(.badge-danger, .badge-outline-danger, .badge-soft-danger) {
    background: var(--theme-error-bg);
    color: var(--theme-error);
    border-color: var(--theme-error-border);
}
html[data-theme='dark']
    :is(.badge-primary, .badge-info, .badge-outline-info, .badge-soft-primary) {
    background: var(--theme-info-bg);
    color: var(--theme-info);
    border-color: var(--theme-info-border);
}
html[data-theme='dark'] .alert a {
    color: inherit;
    text-decoration: underline;
}
html[data-theme='dark']
    :is(
        .accordion .card-header,
        .accordion-button,
        .accordion-button:not(.collapsed),
        .accordion-body,
        .offcanvas
    ) {
    background: var(--theme-surface);
    color: var(--theme-text);
    border-color: var(--theme-border);
}
html[data-theme='dark'] :is(.modal-backdrop, .offcanvas-backdrop) {
    background-color: var(--theme-overlay);
}
html[data-theme='dark'] .swal-overlay {
    background: var(--theme-overlay);
}
html[data-theme='dark']
    :is(.swal-footer, .swal-content__input, .swal-content__textarea) {
    background: var(--theme-surface);
    color: var(--theme-text);
    border-color: var(--theme-border);
}
html[data-theme='dark'] .swal-button--cancel {
    background: var(--theme-raised);
    color: var(--theme-text);
}
html[data-theme='dark'] .swal-icon--success::before,
html[data-theme='dark'] .swal-icon--success::after,
html[data-theme='dark'] .swal-icon--success__hide-corners {
    background: var(--theme-surface);
}
html[data-theme='dark'] .tooltip-inner {
    background: var(--theme-tooltip);
    color: var(--theme-text);
    border: 1px solid var(--theme-border);
    box-shadow: var(--theme-shadow);
}
html[data-theme='dark'] .bs-tooltip-top .arrow::before {
    border-top-color: var(--theme-border);
}
html[data-theme='dark'] .bs-tooltip-bottom .arrow::before {
    border-bottom-color: var(--theme-border);
}
html[data-theme='dark'] .bs-tooltip-left .arrow::before {
    border-left-color: var(--theme-border);
}
html[data-theme='dark'] .bs-tooltip-right .arrow::before {
    border-right-color: var(--theme-border);
}
html[data-theme='dark'] .popover .arrow::after {
    border-bottom-color: var(--theme-surface);
    border-top-color: var(--theme-surface);
}
html[data-theme='dark'] .toast-notification {
    background: var(--theme-surface);
    color: var(--theme-text);
    border-color: var(--theme-border);
    box-shadow: var(--theme-shadow-raised);
}
html[data-theme='dark'] .toast-close {
    color: var(--theme-muted);
}
html[data-theme='dark'] .toast-close:hover {
    color: var(--theme-text);
}
html[data-theme='dark'] .toast-success {
    border-left-color: var(--theme-success);
}
html[data-theme='dark'] .toast-error {
    border-left-color: var(--theme-error);
}
html[data-theme='dark'] .toast-warning {
    border-left-color: var(--theme-warning);
}
html[data-theme='dark'] .toast-info {
    border-left-color: var(--theme-info);
}

/* Third-party controls, including body-mounted dropdowns and editor dialogs. */
html[data-theme='dark']
    :is(
        .choices__inner,
        .choices__list--dropdown,
        .choices__list[aria-expanded],
        .choices__input,
        .select2-dropdown,
        .select2-search__field,
        .select2-selection,
        .select2-selection__choice,
        .datepicker-dropdown,
        .datepicker .datepicker-switch,
        .tt-menu,
        .tt-suggestion,
        .dataTables_wrapper select
    ) {
    background: var(--theme-input);
    color: var(--theme-text);
    border-color: var(--theme-control-border);
}
html[data-theme='dark']
    :is(
        .choices__list--dropdown .choices__item--selectable.is-highlighted,
        .select2-results__option--highlighted[aria-selected],
        .select2-results__option[aria-selected='true'],
        .datepicker table tr td.day:hover,
        .datepicker table tr td span:hover,
        .tt-suggestion:hover
    ) {
    background: var(--theme-hover);
    color: var(--theme-text);
}
html[data-theme='dark'] .choices__list--multiple .choices__item {
    background: var(--theme-active);
    color: var(--theme-link);
    border-color: var(--theme-border);
}
html[data-theme='dark'] .choices[data-type*='select-one']::after {
    border-top-color: var(--theme-muted);
}
html[data-theme='dark'] .choices[data-type*='select-one'].is-open::after {
    border-bottom-color: var(--theme-muted);
}
html[data-theme='dark'] .choices.is-disabled .choices__inner {
    background: var(--theme-raised);
    color: var(--theme-disabled);
}
html[data-theme='dark'] .datepicker table tr td:is(.active, .selected, .today) {
    background: var(--theme-active);
    color: var(--theme-link);
}
html[data-theme='dark'] .datepicker table tr td:is(.disabled, .old, .new) {
    color: var(--theme-disabled);
}
html[data-theme='dark']
    .select2-container--default
    .select2-selection--multiple
    .select2-selection__choice__remove {
    color: var(--theme-muted);
}
html[data-theme='dark']
    .select2-container--default
    .select2-selection--single
    .select2-selection__arrow
    b {
    border-top-color: var(--theme-muted);
}
html[data-theme='dark']
    .tox
    :is(
        .tox-dialog,
        .tox-dialog__header,
        .tox-dialog__footer,
        .tox-dialog__body,
        .tox-menu,
        .tox-collection__item,
        .tox-listboxfield .tox-listbox--select,
        .tox-textfield,
        .tox-textarea,
        .tox-selectfield select,
        .tox-toolbar-textfield
    ) {
    background: var(--theme-surface);
    color: var(--theme-text);
    border-color: var(--theme-border);
}
html[data-theme='dark']
    .tox
    :is(
        .tox-label,
        .tox-statusbar__path-item,
        .tox-statusbar a,
        .tox-dialog__title,
        .tox-collection__item-label,
        .tox-collection__item-accessory
    ) {
    color: var(--theme-text);
}
html[data-theme='dark']
    .tox
    :is(
        .tox-tbtn:hover,
        .tox-tbtn:focus,
        .tox-tbtn--enabled,
        .tox-collection__item--active,
        .tox-collection__item--enabled
    ) {
    background: var(--theme-hover);
    color: var(--theme-text);
}
html[data-theme='dark']
    .tox
    :is(.tox-icon svg, .tox-collection__item-icon svg, .tox-button--icon svg) {
    fill: var(--theme-text);
}
html[data-theme='dark']
    :is(
        .tox-tinymce,
        .tox .tox-toolbar__group,
        .tox .tox-dialog__footer,
        .tox .tox-collection__group
    ) {
    border-color: var(--theme-border);
}
html[data-theme='dark'] .tox .tox-dialog-wrap__backdrop {
    background: var(--theme-overlay);
}
html[data-theme='dark'] .tox .tox-button--secondary {
    background: var(--theme-raised);
    color: var(--theme-text);
    border-color: var(--theme-control-border);
}
html[data-theme='dark'] .tox .tox-button--secondary:hover {
    background: var(--theme-hover);
}
html[data-theme='light'] .badge-primary {
    background: var(--theme-primary);
    color: var(--theme-on-primary);
}
html[data-theme] .select2-container .select2-selection__placeholder {
    color: var(--theme-muted);
}
html[data-theme] .outreach {
    --reach-ink: var(--theme-text);
    --reach-muted: var(--theme-muted);
    --reach-accent: var(--theme-link);
}
html[data-theme] .outreach-back {
    color: var(--theme-link);
}
html[data-theme] .outreach-skeleton {
    color: var(--theme-muted);
}
html[data-theme][data-theme-page='bill-index'] .download-button {
    background: var(--theme-success);
    color: var(--theme-on-primary);
}
html[data-theme][data-theme-page='bill-index'] .download-button:hover {
    background: var(--theme-success);
    filter: brightness(0.9);
}
html[data-theme='light'][data-theme-page='public-dashboard'] .badge-pill {
    color: var(--theme-success);
}

/* Explicit proofs preserve the output's appearance, not the dashboard palette. */
[data-theme-preserve] {
    color-scheme: light;
}
.theme-proof {
    background: #ffffff;
    color: #344054;
}
@media (prefers-reduced-motion: reduce) {
    html[data-theme] *,
    html[data-theme] *::before,
    html[data-theme] *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
@media print {
    .theme-floating-toggle,
    .theme-toggle {
        display: none !important;
    }
}
html[data-theme='dark'] .btn-danger {
    background: var(--theme-error-bg);
    color: var(--theme-error);
    border-color: var(--theme-error-border);
}
html[data-theme='dark'] .btn-success {
    background: var(--theme-success-bg);
    color: var(--theme-success);
    border-color: var(--theme-success-border);
}
html[data-theme='dark'] .btn-warning {
    background: var(--theme-warning-bg);
    color: var(--theme-warning);
    border-color: var(--theme-warning-border);
}
html[data-theme='dark'] .btn-info {
    background: var(--theme-info-bg);
    color: var(--theme-info);
    border-color: var(--theme-info-border);
}
html[data-theme='dark']
    :is(.btn-danger, .btn-success, .btn-warning, .btn-info):is(
        :hover,
        :focus,
        :active,
        .active
    ) {
    filter: brightness(1.15);
}
.theme-static-slot {
    min-width: 116px;
    min-height: 44px;
    flex: 0 0 auto;
}
html[data-theme='dark']
    :is(.footer span, .text-muted span, .text-muted strong) {
    color: var(--theme-muted);
}
html[data-theme='dark']
    :is(.publisher-am-kicker span, .publisher-am-empty-text, .crm-step span) {
    color: var(--theme-muted);
}
html[data-theme='dark'] .crm-step.active span {
    color: var(--theme-on-primary);
    background: var(--theme-primary);
}
/* Readable light-theme counterparts for Bootstrap's low-contrast default states. */
html[data-theme='light'] :is(.text-muted, .form-text) {
    color: var(--theme-muted) !important;
}
html[data-theme='light'] :is(.btn-link, .btn-outline-primary) {
    color: var(--theme-link);
}
html[data-theme='light'] .btn-outline-primary {
    border-color: var(--theme-link);
}
html[data-theme='light'] .btn-outline-primary:is(:hover, :focus, :active) {
    background: var(--theme-primary);
    color: var(--theme-on-primary);
}
html[data-theme='light'] .page-item.active .page-link {
    background: var(--theme-primary);
    border-color: var(--theme-primary);
    color: var(--theme-on-primary);
}
html[data-theme='light'] :is(.alert-success, .badge-success) {
    background-color: var(--theme-success-bg);
    color: var(--theme-success);
    border-color: var(--theme-success-border);
}
html[data-theme='light'] :is(.alert-warning, .badge-warning) {
    background-color: var(--theme-warning-bg);
    color: var(--theme-warning);
    border-color: var(--theme-warning-border);
}
html[data-theme='light'] :is(.alert-danger, .badge-danger) {
    background-color: var(--theme-error-bg);
    color: var(--theme-error);
    border-color: var(--theme-error-border);
}
html[data-theme='light'] :is(.alert-info, .badge-info) {
    background-color: var(--theme-info-bg);
    color: var(--theme-info);
    border-color: var(--theme-info-border);
}
html[data-theme='light'] .error-page.bg-primary {
    background: var(--theme-primary) !important;
}
html[data-theme='dark'] .datepicker table tr th {
    background: var(--theme-surface) !important;
    color: var(--theme-text);
}
html[data-theme='dark'] .datepicker table tr th:is(:hover, :focus) {
    background: var(--theme-hover) !important;
}
html[data-theme='light'] :is(.btn-outline-secondary, .card-description) {
    color: var(--theme-muted);
}
html[data-theme='light'] .btn-outline-secondary {
    border-color: var(--theme-control-border);
}
html[data-theme='light'] .btn-outline-secondary:is(:hover, :focus, :active) {
    background: var(--theme-hover);
    color: var(--theme-text);
}
html[data-theme='light'] .btn-outline-success {
    color: var(--theme-success);
    border-color: var(--theme-success);
}
html[data-theme='light'] .btn-outline-danger {
    color: var(--theme-error);
    border-color: var(--theme-error);
}
html[data-theme='light'] .btn-outline-info {
    color: var(--theme-info);
    border-color: var(--theme-info);
}
html[data-theme='light'] .btn-success {
    background: var(--theme-success);
    border-color: var(--theme-success);
    color: var(--theme-on-primary);
}
html[data-theme='light'] .btn-danger {
    background: var(--theme-error);
    border-color: var(--theme-error);
    color: var(--theme-on-primary);
}
html[data-theme='light'] .btn-info {
    background: var(--theme-info);
    border-color: var(--theme-info);
    color: var(--theme-on-primary);
}
html[data-theme='light'] .btn-outline-success:is(:hover, :focus, :active) {
    background: var(--theme-success);
    color: var(--theme-on-primary);
}
html[data-theme='light'] .btn-outline-danger:is(:hover, :focus, :active) {
    background: var(--theme-error);
    color: var(--theme-on-primary);
}
html[data-theme='light'] .btn-outline-info:is(:hover, :focus, :active) {
    background: var(--theme-info);
    color: var(--theme-on-primary);
}
html[data-theme='light']
    :is(.text-info, .text-success, .text-danger, .text-primary) {
    color: var(--theme-text);
}
html[data-theme='light'] .text-info {
    color: var(--theme-info) !important;
}
html[data-theme='light'] .text-success {
    color: var(--theme-success) !important;
}
html[data-theme='light'] .text-danger {
    color: var(--theme-error) !important;
}
html[data-theme='light'] .text-primary {
    color: var(--theme-link) !important;
}
html[data-theme='light'] code {
    color: var(--theme-error);
}
html[data-theme='light']
    .sidebar
    .nav
    :is(
        .nav-item.active > .nav-link,
        .nav-link.active,
        .nav-item:hover > .nav-link
    ) {
    background: var(--theme-active);
    color: var(--theme-link);
}
html[data-theme='light']
    .sidebar
    .nav
    :is(
        .nav-item.active > .nav-link,
        .nav-link.active,
        .nav-item:hover > .nav-link
    )
    :is(.menu-title, .menu-icon, i) {
    color: var(--theme-link) !important;
}
html[data-theme='light'] .sidebar .nav .sub-menu .nav-link {
    background: var(--theme-raised);
    color: var(--theme-text);
}
html[data-theme='light'] :is(#offersTable, #affStatsTable) thead th {
    background: var(--theme-primary) !important;
    color: var(--theme-on-primary) !important;
}
html[data-theme='light'] :is(.crm-smart-good, .kpi-meta) {
    color: var(--theme-success);
}
html[data-theme='light'] .error-page.bg-info {
    background: var(--theme-info) !important;
}
html[data-theme='light'][data-theme-page='bill-index'] .error {
    color: var(--theme-error);
}
