/* Dark theme is active when data-theme="dark" is set on the html element.
   Screen-only rules preserve the existing print appearance. */
@media screen {
    .theme-toggle-light,
    html[data-theme="dark"] .theme-toggle-dark {
        display: none;
    }

    html[data-theme="dark"] .theme-toggle-light {
        display: inline;
    }

    html[data-theme="dark"] {
        color-scheme: dark;
        --lightBlue: #263958;
        --lightBlue2: #304467;
        --lightGray: #20252e;
        --lightGray2: #303744;
        --gray: #252b35;
        --dark-bg: #171a21;
        --dark-surface: #20252e;
        --dark-input: #272d38;
        --dark-border: #414958;
        --dark-text: #e4e8ef;
        --dark-muted: #a5afbf;
        --page-bg: var(--dark-bg);
        --surface: var(--dark-surface);
        --surface-alt: #252b35;
        --surface-header: var(--dark-input);
        --text-color: var(--dark-text);
        --text-secondary: var(--dark-muted);
        --text-heading: var(--dark-text);
        --border-color: var(--dark-border);
        --border-subtle: var(--dark-border);
        --hover-overlay: rgba(255, 255, 255, .08);
        --selected-bg: rgba(66, 133, 244, .2);
        --overlay-bg: rgba(23, 26, 33, .6);
        --primary-text: #8ab4f8;
        --blue: #8ab4f8;
        --title-color: var(--dark-text);
        --icon-color: var(--dark-text);
        --text-disabled: rgba(255, 255, 255, .4);
    }

    html[data-theme="dark"] body {
        color: var(--dark-text);
    }

    html[data-theme="dark"] pre {
        color: inherit;
    }


    html[data-theme="dark"] .card,
    html[data-theme="dark"] .list-group-item,
    html[data-theme="dark"] .modal-content,
    html[data-theme="dark"] .dropdown-menu,
    html[data-theme="dark"] .popover,
    html[data-theme="dark"] .sheet-card {
        background-color: var(--dark-surface);
        color: var(--dark-text);
        border-color: var(--dark-border);
    }

    html[data-theme="dark"] .bg-white,
    html[data-theme="dark"] .bg-light {
        background-color: var(--dark-surface) !important;
    }

    html[data-theme="dark"] .text-dark,
    html[data-theme="dark"] .text-body {
        color: var(--dark-text) !important;
    }

    html[data-theme="dark"] .text-muted,
    html[data-theme="dark"] .text-black-50 {
        color: var(--dark-muted) !important;
    }

    html[data-theme="dark"] .border,
    html[data-theme="dark"] .border-top,
    html[data-theme="dark"] .border-bottom,
    html[data-theme="dark"] .border-left,
    html[data-theme="dark"] .border-right {
        border-color: var(--dark-border) !important;
    }

    html[data-theme="dark"] hr,
    html[data-theme="dark"] .modal-header,
    html[data-theme="dark"] .modal-footer,
    html[data-theme="dark"] .dropdown-divider {
        border-color: var(--dark-border);
    }

    html[data-theme="dark"] .card-header,
    html[data-theme="dark"] .card-footer,
    html[data-theme="dark"] .popover-header {
        background-color: var(--dark-input);
        color: var(--dark-text);
        border-color: var(--dark-border);
    }

    html[data-theme="dark"] .form-control,
    html[data-theme="dark"] .custom-select,
    html[data-theme="dark"] .input-group-text,
    html[data-theme="dark"] .custom-file-label,
    html[data-theme="dark"] .bootstrap-select button.dropdown-toggle {
        background-color: var(--dark-input) !important;
        color: var(--dark-text);
        border-color: var(--dark-border) !important;
    }

    html[data-theme="dark"] .custom-file-label::after {
        background-color: var(--lightGray2);
        color: var(--dark-text);
    }

    html[data-theme="dark"] .form-control::placeholder {
        color: var(--dark-muted);
        opacity: 1;
    }

    html[data-theme="dark"] .form-control:focus,
    html[data-theme="dark"] .custom-select:focus {
        border-color: #80bdff !important;
        box-shadow: 0 0 0 .2rem rgba(0, 123, 255, .25);
    }

    html[data-theme="dark"] .form-control:disabled,
    html[data-theme="dark"] .form-control[readonly],
    html[data-theme="dark"] .custom-select:disabled,
    html[data-theme="dark"] .bootstrap-select > .dropdown-toggle.disabled {
        background-color: var(--dark-surface) !important;
        color: var(--dark-muted);
    }

    html[data-theme="dark"] .input-validation-error {
        border-color: #f0808c !important;
    }

    html[data-theme="dark"] .dropdown-item,
    html[data-theme="dark"] .dropdown-header,
    html[data-theme="dark"] .popover-body {
        color: var(--dark-text);
    }

    html[data-theme="dark"] .dropdown-item:hover,
    html[data-theme="dark"] .dropdown-item:focus {
        background-color: #303b4d;
        color: var(--dark-text);
    }

    html[data-theme="dark"] .dropdown-item.active,
    html[data-theme="dark"] .dropdown-item:active,
    html[data-theme="dark"] .page-item.active .page-link {
        background-color: #007bff;
        color: #fff;
        border-color: #007bff;
    }

    html[data-theme="dark"] .dropdown-item.disabled,
    html[data-theme="dark"] .page-item.disabled .page-link {
        color: var(--dark-muted);
        background-color: var(--dark-surface);
    }

    html[data-theme="dark"] .table {
        color: var(--dark-text);
    }

    html[data-theme="dark"] .table th,
    html[data-theme="dark"] .table td {
        border-color: #353d49;
    }

    html[data-theme="dark"] .table .border-left,
    html[data-theme="dark"] .table .border-right {
        border-color: #353d49 !important;
    }

    html[data-theme="dark"] .table thead,
    html[data-theme="dark"] .table .thead-light th,
    html[data-theme="dark"] table.dataTable.fixedHeader-floating {
        background-color: var(--dark-surface);
        color: var(--dark-text);
    }

    html[data-theme="dark"] .table-striped tbody tr:nth-of-type(odd):not(.selected) {
        background-color: #252b35;
    }

    html[data-theme="dark"] .table-hover tbody tr:not(.selected):hover {
        background-color: #303b4d;
        color: var(--dark-text);
    }

    html[data-theme="dark"] .order-child-grid-header,
    html[data-theme="dark"] .order-child-grid-row {
        color: var(--dark-text);
        border-bottom-color: var(--dark-border);
    }

    html[data-theme="dark"] .order-child-grid-header {
        background-color: var(--surface-header);
    }

    html[data-theme="dark"] .order-child-grid-row {
        background-color: var(--dark-surface);
    }

    html[data-theme="dark"] .order-child-grid-row:nth-child(odd) {
        background-color: var(--surface-alt);
    }

    html[data-theme="dark"] #workflowTable .workflow-status .material-icons,
    html[data-theme="dark"] #workflowTable .workflow-status .material-icons-outlined,
    html[data-theme="dark"] #clearWorkflowFilters .material-icons-outlined {
        color: var(--dark-text) !important;
    }

    html[data-theme="dark"] table.dataTable thead .sorting:before,
    html[data-theme="dark"] table.dataTable thead .sorting:after,
    html[data-theme="dark"] table.dataTable thead .sorting_asc:before,
    html[data-theme="dark"] table.dataTable thead .sorting_asc:after,
    html[data-theme="dark"] table.dataTable thead .sorting_desc:before,
    html[data-theme="dark"] table.dataTable thead .sorting_desc:after,
    html[data-theme="dark"] table.dataTable thead .sorting_asc_disabled:before,
    html[data-theme="dark"] table.dataTable thead .sorting_asc_disabled:after,
    html[data-theme="dark"] table.dataTable thead .sorting_desc_disabled:before,
    html[data-theme="dark"] table.dataTable thead .sorting_desc_disabled:after {
        color: var(--dark-text);
    }

    html[data-theme="dark"] .page-link,
    html[data-theme="dark"] .btn-next-step:not(:hover):not(:active):not(:focus),
    html[data-theme="dark"] .btn-light,
    html[data-theme="dark"] .btn-outline-secondary,
    html[data-theme="dark"] .btn-outline-dark {
        background-color: var(--dark-input);
        border-color: var(--dark-border);
    }

    html[data-theme="dark"] .btn-outline-secondary,
    html[data-theme="dark"] .btn-outline-dark {
        color: var(--dark-text);
    }

    html[data-theme="dark"] .btn-light:hover,
    html[data-theme="dark"] .btn-outline-secondary:hover,
    html[data-theme="dark"] .btn-outline-dark:hover {
        background-color: #303b4d;
        color: #fff;
    }

    html[data-theme="dark"] .alert-primary {
        background-color: rgba(0, 123, 255, .15);
        border-color: rgba(0, 123, 255, .4);
        color: #a8cfff;
    }

    html[data-theme="dark"] .alert-info {
        background-color: rgba(23, 162, 184, .15);
        border-color: rgba(23, 162, 184, .4);
        color: #9fe3ee;
    }

    html[data-theme="dark"] .alert-success {
        background-color: rgba(40, 167, 69, .15);
        border-color: rgba(40, 167, 69, .4);
        color: #a3e6b4;
    }

    html[data-theme="dark"] .alert-warning {
        background-color: rgba(255, 193, 7, .12);
        border-color: rgba(255, 193, 7, .4);
        color: #ffe08a;
    }

    html[data-theme="dark"] .alert-danger {
        background-color: rgba(220, 53, 69, .15);
        border-color: rgba(220, 53, 69, .4);
        color: #f5a8b0;
    }

    html[data-theme="dark"] .alert-secondary {
        background-color: rgba(108, 117, 125, .2);
        border-color: var(--dark-border);
        color: var(--dark-text);
    }

    html[data-theme="dark"] .alert .alert-link {
        color: inherit;
    }

    html[data-theme="dark"] .btn.lightBlueBackground,
    html[data-theme="dark"] .alert.lightBlueBackground {
        color: var(--dark-text);
        border-color: var(--dark-border);
    }

    /* Status and priority badges keep their pastel backgrounds, so they need dark text. */
    html[data-theme="dark"] .sheet-status:is(.status-0, .status-5, .status-10, .status-12, .status-15, .status-17, .status-20, .status--1),
    html[data-theme="dark"] .offer-status:is(.status-1, .status-2, .status-3, .status-4, .status-5, .status-6, .status-7, .status-8, .status-9, .status-10),
    html[data-theme="dark"] span.sheet-refrigerant,
    html[data-theme="dark"] span.sheet-priority,
    html[data-theme="dark"] span:is(.priority-A, .priority-B, .priority-C, .priority-D),
    html[data-theme="dark"] .tag-badge--success,
    html[data-theme="dark"] .tag-badge--danger,
    html[data-theme="dark"] a.tag-sheet-link:not(.lightBlueBackground) {
        color: #212529;
    }

    html[data-theme="dark"] .custom-control-label::before {
        background-color: var(--dark-input);
        border-color: #6c7a8f;
    }

    html[data-theme="dark"] .custom-switch .custom-control-label::after {
        background-color: var(--dark-muted);
    }

    html[data-theme="dark"] .custom-radio .custom-control-input:checked ~ .custom-control-label::before {
        background-color: #6c7a8f !important;
        border-color: #6c7a8f !important;
    }

    html[data-theme="dark"] .sheet-preview-header,
    html[data-theme="dark"] .sheet-preview-header h4,
    html[data-theme="dark"] .sheet-preview-header a.circle-button,
    html[data-theme="dark"] .sheet-preview-header button.circle-button {
        color: var(--dark-text) !important;
    }

    html[data-theme="dark"] .sheet-preview-footer {
        color: var(--dark-muted);
    }

    html[data-theme="dark"] .sheet-note-visibility-pill {
        border-color: var(--dark-border);
    }

    html[data-theme="dark"] .sheet-note-visibility-pill--readonly,
    html[data-theme="dark"] .sheet-note-visibility-button {
        color: var(--dark-text);
    }

    html[data-theme="dark"] .img-float-btn:not(.blue):hover {
        background-color: #303b4d !important;
    }

    html[data-theme="dark"] .circle-button:not(.highlight) {
        color: var(--dark-text) !important;
    }

    html[data-theme="dark"] .btn.bg-transparent:not([class*="btn-"]) {
        color: var(--dark-text);
    }

    html[data-theme="dark"] .ui-autocomplete.ui-widget-content {
        background: var(--dark-surface);
        border-color: var(--dark-border);
        color: var(--dark-text);
    }

    html[data-theme="dark"] .ui-autocomplete .ui-menu-item-wrapper {
        color: var(--dark-text);
    }

    html[data-theme="dark"] .ui-autocomplete .ui-state-active,
    html[data-theme="dark"] .ui-autocomplete .ui-state-focus {
        background: var(--hover-overlay);
        border-color: transparent;
        color: #fff;
    }

    html[data-theme="dark"] .close {
        color: var(--dark-text);
        text-shadow: none;
    }

    html[data-theme="dark"] .navbar a,
    html[data-theme="dark"] .navbar .circle-button,
    html[data-theme="dark"] a.btn-primary,
    html[data-theme="dark"] a.btn-danger,
    html[data-theme="dark"] a.btn-success {
        color: #fff !important;
    }

    /* Call center calendar */
    html[data-theme="dark"] #mainSettings .bootstrap-select .no-results {
        background-color: var(--surface-header);
        color: var(--text-color);
    }

    html[data-theme="dark"] .calendar-tech-col .text-primary {
        color: var(--primary-text) !important;
    }

    html[data-theme="dark"] .calendar-week .text-danger,
    html[data-theme="dark"] .calendar-month .text-danger {
        color: #f0808c !important;
    }

    html[data-theme="dark"] .calendar-navigation-button {
        color: var(--text-color);
    }

    html[data-theme="dark"] .calendar-day-header,
    html[data-theme="dark"] .calendar-day-cell {
        background: var(--dark-surface);
        border-right-color: var(--dark-border);
    }

    html[data-theme="dark"] .calendar-row.calendar-row-even .calendar-day-cell {
        background-color: var(--surface-alt);
    }

    html[data-theme="dark"] .calendar-row.calendar-row-even .calendar-tech-col {
        background-color: var(--surface-alt) !important;
    }

    html[data-theme="dark"] .calendar-repair-badge {
        --calendar-repair-highlight-bg: #1c2c46;
        border-color: var(--lightBlue2);
        color: var(--dark-text);
    }

    html[data-theme="dark"] .calendar-repair-badge .material-icons,
    html[data-theme="dark"] .calendar-repair-badge .material-icons-outlined {
        color: var(--dark-muted);
    }

    html[data-theme="dark"] .calendar-repair-title,
    html[data-theme="dark"] .calendar-repair-link {
        color: var(--primary-text) !important;
    }

    html[data-theme="dark"] .calendar-event-badge {
        --calendar-event-bg: rgba(40, 167, 69, .15);
        --calendar-event-highlight-bg: rgba(40, 167, 69, .32);
        background-color: var(--calendar-event-bg);
        border-color: rgba(40, 167, 69, .4);
        color: #a3e6b4;
    }

    html[data-theme="dark"] .calendar-today-pill {
        background-color: var(--lightBlue2);
        color: var(--dark-text);
    }

    html[data-theme="dark"] .uniformBorder {
        border-color: var(--dark-border) !important;
    }

    html[data-theme="dark"] #smsStatisticsTable thead {
        background-color: transparent;
    }

    html[data-theme="dark"] .sms-statistics-summary {
        background-color: var(--surface-header);
    }

    /* Workflow partner repair approval (partner prices) */
    html[data-theme="dark"] .partner-prices-actions,
    html[data-theme="dark"] .partner-prices-section,
    html[data-theme="dark"] .partner-prices-side-panel {
        background-color: var(--dark-surface);
        border-color: var(--dark-border);
    }

    html[data-theme="dark"] .partner-prices-section-header {
        border-bottom-color: var(--dark-border);
    }

    html[data-theme="dark"] .partner-prices-section .material-container ~ .material-container,
    html[data-theme="dark"] .partner-prices-section .refrigerant-container ~ .refrigerant-container,
    html[data-theme="dark"] .partner-prices-section .worktime-container ~ .worktime-container,
    html[data-theme="dark"] .partner-prices-section .fare-container ~ .fare-container {
        border-top-color: var(--dark-border);
    }

    html[data-theme="dark"] #partnerPricesConfirmationsContainer .grid-file-item img.icon {
        filter: invert(1);
    }

    html[data-theme="dark"] .signature-pad {
        background-color: var(--dark-input);
        border-color: var(--dark-border);
    }

    html[data-theme="dark"] .signature-pad--body {
        border-color: var(--dark-border);
    }

    /* Display-only inversion: strokes are still stored black via toDataURL(). */
    html[data-theme="dark"] .signature-pad--body canvas,
    html[data-theme="dark"] #signatureImage {
        filter: invert(1);
    }

    /* Account detail: transparent signature/stamp previews get a white background so black ink and colored stamps stay visible. */
    html[data-theme="dark"] #signaturePhoto,
    html[data-theme="dark"] #stampPhoto {
        background-color: #fff;
        border-radius: 4px;
    }
}
