/* Screen appearance only. Document bytes, photographs, maps and print colors are unchanged. */
@media screen {
    .cms-theme-control {
        display: inline-flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 6px;
        margin: 4px 0 4px 10px;
        font-size: 14px;
    }

    .cms-theme-toggle {
        min-height: 32px;
        padding: 4px 10px;
        border: 1px solid #687787;
        border-radius: 4px;
        background: #fff;
        color: #263442;
        font: inherit;
        cursor: pointer;
    }

    .cms-theme-toggle:focus-visible {
        outline: 2px solid #276ca7;
        outline-offset: 2px;
    }

    .cms-theme-error .cms-theme-status {
        color: #a52121;
    }

    html[data-cms-theme="dark"] {
        color-scheme: dark;
        --cms-page: #141c25;
        --cms-surface: #202c39;
        --cms-surface-alt: #263544;
        --cms-raised: #304256;
        --cms-input: #172330;
        --cms-text: #e8eef5;
        --cms-muted: #bac8d8;
        --cms-border: #63778e;
        --cms-link: #9bcfff;
        --cms-focus: #afd8ff;
        --cms-danger: #ffb9b3;
        --cms-danger-bg: #592e36;
        --cms-warning: #ffe2a0;
        --cms-warning-bg: #554621;
        --cms-success: #b5e8c3;
        --cms-success-bg: #254b39;
        background-color: var(--cms-page);
        color: var(--cms-text);
    }

    html[data-cms-theme="dark"] body {
        background-color: var(--cms-page);
        color: var(--cms-text);
    }

    html[data-cms-theme="dark"] .gm-style {
        color-scheme: light;
    }

    html[data-cms-theme="dark"] :where(a):not(.gm-style *) {
        color: var(--cms-link);
    }

    html[data-cms-theme="dark"] a:not(.gm-style *):hover {
        color: #c6e5ff;
    }

    html[data-cms-theme="dark"] hr:not(.gm-style *),
    html[data-cms-theme="dark"] fieldset:not(.gm-style *) {
        border-color: var(--cms-border);
    }

    /* Do not assign a blanket cell text color: duplicate-cell deliberately hides text. */
    html[data-cms-theme="dark"] table:not(.gm-style *) {
        background-color: var(--cms-surface);
        color: var(--cms-text);
        border-color: var(--cms-border);
    }

    html[data-cms-theme="dark"] th:not(.gm-style *),
    html[data-cms-theme="dark"] td:not(.gm-style *) {
        border-color: var(--cms-border);
    }

    html[data-cms-theme="dark"] th:not(.gm-style *) {
        background-color: var(--cms-raised);
        color: var(--cms-text);
    }

    html[data-cms-theme="dark"] td:not(.gm-style *) {
        background-color: var(--cms-surface);
    }

    html[data-cms-theme="dark"] .table_header_color th,
    html[data-cms-theme="dark"] .table_header_debit th {
        background-color: var(--cms-raised) !important;
        color: var(--cms-text);
        border-color: var(--cms-border);
    }

    html[data-cms-theme="dark"] .table_footer_total td {
        background-color: var(--cms-success-bg) !important;
        color: var(--cms-text);
    }

    html[data-cms-theme="dark"] .homeallotment_apply_color {
        background-color: var(--cms-success-bg);
        color: var(--cms-success);
        border-color: var(--cms-border);
    }

    /* Tablesorter loads after the shared head and can clone headers while scrolling. */
    html[data-cms-theme="dark"] .tablesorter-default,
    html[data-cms-theme="dark"] .tablesorter-default tbody td,
    html[data-cms-theme="dark"] .tablesorter-default tfoot td {
        background-color: var(--cms-surface);
        color: var(--cms-text);
        border-color: var(--cms-border);
    }

    html[data-cms-theme="dark"] .tablesorter-default tbody tr.odd > td {
        background-color: var(--cms-surface-alt);
    }

    html[data-cms-theme="dark"] .tablesorter-default .tablesorter-filter-row td,
    html[data-cms-theme="dark"] .tablesorter-default .header,
    html[data-cms-theme="dark"] .tablesorter-default .tablesorter-header {
        background-color: var(--cms-raised);
        color: var(--cms-text);
        border-color: var(--cms-border);
    }

    html[data-cms-theme="dark"] .tablesorter-default .header,
    html[data-cms-theme="dark"] .tablesorter-default .tablesorter-header {
        background-image: none;
    }

    html[data-cms-theme="dark"] .tablesorter-header:not(.sorter-false)::after {
        content: " \2195";
        color: var(--cms-muted);
    }

    html[data-cms-theme="dark"] .tablesorter-headerAsc:not(.sorter-false)::after {
        content: " \25b2";
    }

    html[data-cms-theme="dark"] .tablesorter-headerDesc:not(.sorter-false)::after {
        content: " \25bc";
    }

    html[data-cms-theme="dark"] :where(input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not([type="image"]):not([type="range"]):not([type="color"]):not([type="file"]), select, textarea, .form-control):not(.gm-style *) {
        background-color: var(--cms-input);
        color: var(--cms-text);
        border-color: var(--cms-border);
    }

    html[data-cms-theme="dark"] input:not(.gm-style *)::placeholder,
    html[data-cms-theme="dark"] textarea:not(.gm-style *)::placeholder {
        color: #a9b9cc;
        opacity: 1;
    }

    html[data-cms-theme="dark"] input[readonly]:not(.gm-style *),
    html[data-cms-theme="dark"] textarea[readonly]:not(.gm-style *),
    html[data-cms-theme="dark"] .audit-item-input[readonly],
    html[data-cms-theme="dark"] .boa-dialog .form-control:disabled,
    html[data-cms-theme="dark"] input:disabled:not(.gm-style *),
    html[data-cms-theme="dark"] select:disabled:not(.gm-style *),
    html[data-cms-theme="dark"] textarea:disabled:not(.gm-style *) {
        background-color: var(--cms-surface-alt);
        color: var(--cms-muted);
        border-color: var(--cms-border);
    }

    html[data-cms-theme="dark"] input[type="checkbox"]:not(.gm-style *),
    html[data-cms-theme="dark"] input[type="radio"]:not(.gm-style *) {
        accent-color: #79b9ee;
    }

    html[data-cms-theme="dark"] :where(button, input[type="button"], input[type="submit"], input[type="reset"], .btn):not(.gm-style *),
    html[data-cms-theme="dark"] input[type="file"]:not(.gm-style *)::file-selector-button {
        background-color: var(--cms-raised);
        color: var(--cms-text);
        border-color: var(--cms-border);
    }

    html[data-cms-theme="dark"] .btn-primary,
    html[data-cms-theme="dark"] .label-primary {
        background-color: #235c8c;
        color: #f1f7ff;
    }

    html[data-cms-theme="dark"] .btn-success,
    html[data-cms-theme="dark"] .label-success {
        background-color: #285840;
        color: #d7f7e1;
    }

    html[data-cms-theme="dark"] .btn-danger,
    html[data-cms-theme="dark"] .label-danger {
        background-color: #823f49;
        color: #fff0ee;
    }

    html[data-cms-theme="dark"] .btn-warning,
    html[data-cms-theme="dark"] .label-warning {
        background-color: var(--cms-warning-bg);
        color: var(--cms-warning);
    }

    html[data-cms-theme="dark"] .btn:disabled:not(.gm-style *),
    html[data-cms-theme="dark"] button:disabled:not(.gm-style *),
    html[data-cms-theme="dark"] input[type="submit"]:disabled:not(.gm-style *) {
        background-color: var(--cms-surface-alt);
        color: var(--cms-muted);
    }

    html[data-cms-theme="dark"] :focus-visible:not(.gm-style *) {
        outline: 2px solid var(--cms-focus);
        outline-offset: 2px;
    }

    /* Status hues remain distinct, including cells recolored by Tablesorter JavaScript. */
    html[data-cms-theme="dark"] .date-warn,
    html[data-cms-theme="dark"] .date-actionRequired {
        background-color: var(--cms-warning-bg) !important;
        color: var(--cms-warning) !important;
    }

    html[data-cms-theme="dark"] .date-lightwarn {
        background-color: #3b4b2e !important;
        color: #d8edc5 !important;
    }

    html[data-cms-theme="dark"] .data-orange {
        background-color: #613f23 !important;
        color: #ffddb3 !important;
    }

    html[data-cms-theme="dark"] .date-expire,
    html[data-cms-theme="dark"] .data-important,
    html[data-cms-theme="dark"] .text-danger-bgred {
        background-color: var(--cms-danger-bg) !important;
        color: var(--cms-danger) !important;
    }

    html[data-cms-theme="dark"] :is(.date-warn, .date-actionRequired, .date-expire, .data-important, .data-orange, .date-lightwarn) :is(input, select, textarea) {
        background-color: transparent !important;
        color: inherit;
    }

    html[data-cms-theme="dark"] .text-danger,
    html[data-cms-theme="dark"] .boa-dialog .text-danger,
    html[data-cms-theme="dark"] .vsc-negative,
    html[data-cms-theme="dark"] .vbl-map-message,
    html[data-cms-theme="dark"] .vbl-allocation-empty,
    html[data-cms-theme="dark"] .fishing-cell-status[data-error="true"],
    html[data-cms-theme="dark"] .fishing-delete-status[data-error="true"] {
        color: var(--cms-danger);
    }

    html[data-cms-theme="dark"] .text-success,
    html[data-cms-theme="dark"] .boa-dialog .text-success {
        color: var(--cms-success);
    }

    html[data-cms-theme="dark"] .text-warning,
    html[data-cms-theme="dark"] .boa-dialog .text-warning,
    html[data-cms-theme="dark"] #vscBillOneExpenseWarnings {
        color: var(--cms-warning);
    }

    html[data-cms-theme="dark"] .text-muted,
    html[data-cms-theme="dark"] .boa-dialog .text-muted,
    html[data-cms-theme="dark"] .boa-source dt,
    html[data-cms-theme="dark"] .boa-help-panel [lang="en"],
    html[data-cms-theme="dark"] .vsc-charter-hire-period,
    html[data-cms-theme="dark"] .vbl-map-note,
    html[data-cms-theme="dark"] .vbl-allocation-summary,
    html[data-cms-theme="dark"] .boa-partner-results small,
    html[data-cms-theme="dark"] .vbl-fishing-results small {
        color: var(--cms-muted);
    }

    html[data-cms-theme="dark"] .alert-danger {
        background-color: var(--cms-danger-bg);
        color: var(--cms-danger);
        border-color: #b96f78;
    }

    html[data-cms-theme="dark"] .alert-warning,
    html[data-cms-theme="dark"] .boa-source-ack {
        background-color: var(--cms-warning-bg);
        color: var(--cms-warning);
        border-color: #b69b55;
    }

    html[data-cms-theme="dark"] .alert-success {
        background-color: var(--cms-success-bg);
        color: var(--cms-success);
        border-color: #679b7a;
    }

    html[data-cms-theme="dark"] .alert-info {
        background-color: #25445b;
        color: #c6e4ff;
        border-color: #6f9ebf;
    }

    /* Schedule / Balance use page-local colors after the shared styles. */
    html[data-cms-theme="dark"] .vsc-detail-table tbody tr:nth-child(odd) td,
    html[data-cms-theme="dark"] #vscBillOneInvoiceTable tbody tr:nth-child(odd) > td,
    html[data-cms-theme="dark"] #boaLinesTable tbody tr:nth-child(odd) td {
        background-color: var(--cms-surface-alt);
    }

    html[data-cms-theme="dark"] .vsc-detail-table tbody tr:nth-child(even) td,
    html[data-cms-theme="dark"] #vscBillOneInvoiceTable tbody tr:nth-child(even) > td,
    html[data-cms-theme="dark"] .vbl-detail-table > tbody > tr.vbl-main-row td {
        background-color: var(--cms-surface);
    }

    html[data-cms-theme="dark"] #vscBillOneInvoiceTable tbody tr:hover > td,
    html[data-cms-theme="dark"] .vbl-detail-table > tbody > tr.vbl-main-row:hover > td,
    html[data-cms-theme="dark"] .vbl-detail-table > tbody > tr.vbl-main-row:hover > td > .form-control {
        background-color: #2a4359;
        color: var(--cms-text);
    }

    html[data-cms-theme="dark"] .vbl-detail-table > tbody > tr.vbl-main-row.vbl-row-selected > td,
    html[data-cms-theme="dark"] .vbl-detail-table > tbody > tr.vbl-main-row.vbl-row-selected > td > .form-control {
        background-color: #514522;
    }

    html[data-cms-theme="dark"] .vbl-detail-table > tbody > tr.vbl-main-row.vbl-row-selected:hover > td,
    html[data-cms-theme="dark"] .vbl-detail-table > tbody > tr.vbl-main-row.vbl-row-selected:hover > td > .form-control {
        background-color: #65552b;
    }

    html[data-cms-theme="dark"] .vsc-filter-row td,
    html[data-cms-theme="dark"] .vbl-filter-row td,
    html[data-cms-theme="dark"] .vbl-detail-table thead .vbl-summary-cell,
    html[data-cms-theme="dark"] .vbl-detail-table thead .vbl-toolbar-cell,
    html[data-cms-theme="dark"] .vsc-plan-title,
    html[data-cms-theme="dark"] .vsc-detail-table tbody tr.vsc-drag-placeholder td,
    html[data-cms-theme="dark"] .vbl-detail-table tbody tr.vbl-drag-placeholder td {
        background-color: var(--cms-surface-alt);
    }

    html[data-cms-theme="dark"] .vsc-detail-table tfoot th,
    html[data-cms-theme="dark"] .vsc-detail-table tfoot td,
    html[data-cms-theme="dark"] .vbl-detail-table > tfoot > tr.vbl-total-row > th,
    html[data-cms-theme="dark"] .vbl-detail-table > tfoot > tr.vbl-total-row > td,
    html[data-cms-theme="dark"] #vscBillOneInvoiceTable thead th,
    html[data-cms-theme="dark"] #boaLinesTable thead th {
        background-color: #2c465e;
        color: var(--cms-text);
        border-color: var(--cms-border);
    }

    html[data-cms-theme="dark"] .vsc-billone-auto-expense {
        color: #b1d8fa;
    }

    html[data-cms-theme="dark"] .oilr-movement-sub-row > td,
    html[data-cms-theme="dark"] .oilr-summary-group-a > td {
        background-color: #25394b;
    }

    html[data-cms-theme="dark"] .oilr-summary-group-b > td {
        background-color: #413b2b;
    }

    html[data-cms-theme="dark"] .oilr-summary-subtotal-row > td,
    html[data-cms-theme="dark"] td[style*="background:#f7fbff"] {
        background-color: var(--cms-raised) !important;
    }

    html[data-cms-theme="dark"] .oilr-error-cell,
    html[data-cms-theme="dark"] .oilr-error-input {
        background-color: var(--cms-danger-bg) !important;
        color: var(--cms-danger);
        border-color: #d38e96 !important;
    }

    html[data-cms-theme="dark"] .oilr-summary-status-badge {
        color: var(--cms-success);
    }

    html[data-cms-theme="dark"] .oilr-copy-bill-one-url-button,
    html[data-cms-theme="dark"] .oilr-copy-bill-one-url-button .oilr-copy-icon::after,
    html[data-cms-theme="dark"] .oilr-copy-bill-one-url-button:hover .oilr-copy-icon::after,
    html[data-cms-theme="dark"] .oilr-copy-bill-one-url-button:focus .oilr-copy-icon::after {
        background-color: var(--cms-raised);
        color: var(--cms-link);
    }

    html[data-cms-theme="dark"] .oilr-copy-bill-one-url-button.oilr-copied {
        background-color: var(--cms-success-bg);
        color: var(--cms-success);
        border-color: #87b99a;
    }

    /* Dialog/help palettes; layout, visibility, z-index and document previews are untouched. */
    html[data-cms-theme="dark"] .boa-dialog,
    html[data-cms-theme="dark"] .boa-help-panel,
    html[data-cms-theme="dark"] .boa-partner-results,
    html[data-cms-theme="dark"] .vbl-fishing-detail-dialog,
    html[data-cms-theme="dark"] .vbl-fishing-results,
    html[data-cms-theme="dark"] .vbl-spd-tooltip,
    html[data-cms-theme="dark"] .vbl-allocation-tooltip,
    html[data-cms-theme="dark"] .vbl-allocation-data,
    html[data-cms-theme="dark"] .vsc-current-forecast-tooltip,
    html[data-cms-theme="dark"] .vessel-fuel-help [role="tooltip"],
    html[data-cms-theme="dark"] .audit-crew-tooltip,
    html[data-cms-theme="dark"] .audit-tooltip,
    html[data-cms-theme="dark"] .report-tooltip {
        background-color: var(--cms-surface);
        color: var(--cms-text);
        border-color: var(--cms-border);
    }

    html[data-cms-theme="dark"] .boa-header,
    html[data-cms-theme="dark"] .boa-footer,
    html[data-cms-theme="dark"] .boa-source,
    html[data-cms-theme="dark"] .vbl-fishing-detail-header,
    html[data-cms-theme="dark"] .vbl-fishing-detail-footer,
    html[data-cms-theme="dark"] .vbl-allocation-modal-header,
    html[data-cms-theme="dark"] .vbl-allocation-modal-footer {
        background-color: var(--cms-surface-alt);
        color: var(--cms-text);
        border-color: var(--cms-border);
    }

    html[data-cms-theme="dark"] .vbl-allocation-title,
    html[data-cms-theme="dark"] .boa-partner-results button,
    html[data-cms-theme="dark"] .vbl-fishing-results button {
        color: var(--cms-text);
    }

    html[data-cms-theme="dark"] .boa-partner-results button,
    html[data-cms-theme="dark"] .vbl-fishing-results button {
        background-color: var(--cms-surface);
    }

    html[data-cms-theme="dark"] .boa-partner-results button[aria-selected="true"],
    html[data-cms-theme="dark"] .boa-partner-results button:hover,
    html[data-cms-theme="dark"] .vbl-fishing-results button[aria-selected="true"],
    html[data-cms-theme="dark"] .vbl-fishing-results button:hover {
        background-color: var(--cms-raised);
    }

    html[data-cms-theme="dark"] .boa-help-trigger,
    html[data-cms-theme="dark"] .vessel-fuel-help button,
    html[data-cms-theme="dark"] .audit-crew-help-button,
    html[data-cms-theme="dark"] .audit-help button,
    html[data-cms-theme="dark"] .report-help button {
        background-color: var(--cms-raised);
        color: var(--cms-link);
        border-color: var(--cms-border);
    }

    html[data-cms-theme="dark"] .vbl-spd-help button {
        color: var(--cms-link);
    }

    html[data-cms-theme="dark"] .vbl-allocation-table,
    html[data-cms-theme="dark"] .vbl-allocation-table td,
    html[data-cms-theme="dark"] .vbl-allocation-tooltip-table td {
        background-color: var(--cms-surface) !important;
    }

    html[data-cms-theme="dark"] .vbl-allocation-table th,
    html[data-cms-theme="dark"] .vbl-allocation-tooltip-table th {
        background-color: var(--cms-raised) !important;
        color: var(--cms-text);
    }

    html[data-cms-theme="dark"] #fishingVesselTable thead th,
    html[data-cms-theme="dark"] #fishingVesselTable-sticky thead th {
        background-color: var(--cms-raised);
        color: var(--cms-text);
    }

    html[data-cms-theme="dark"] .fishing-horizontal-scroll {
        background-color: var(--cms-surface);
    }

    html[data-cms-theme="dark"] .fishing-horizontal-scroll::-webkit-scrollbar-track {
        background-color: var(--cms-surface);
    }

    html[data-cms-theme="dark"] .fishing-horizontal-scroll::-webkit-scrollbar-thumb {
        background-color: #8398af;
        border-color: var(--cms-surface);
    }

    /* Datepicker keeps its real controls and selected/today/hover distinctions. */
    html[data-cms-theme="dark"] .ui-datepicker,
    html[data-cms-theme="dark"] .ui-datepicker.ui-widget-content {
        background: var(--cms-surface);
        color: var(--cms-text);
        border-color: var(--cms-border);
    }

    html[data-cms-theme="dark"] .ui-datepicker .ui-datepicker-header,
    html[data-cms-theme="dark"] .ui-datepicker table,
    html[data-cms-theme="dark"] .ui-datepicker th,
    html[data-cms-theme="dark"] .ui-datepicker td {
        background: var(--cms-surface);
        color: var(--cms-text);
    }

    html[data-cms-theme="dark"] .ui-datepicker .ui-state-default {
        background: var(--cms-surface-alt);
        color: var(--cms-text);
        border-color: var(--cms-border);
    }

    html[data-cms-theme="dark"] .ui-datepicker .ui-state-highlight {
        background: var(--cms-warning-bg);
        color: var(--cms-warning);
        border-color: #c8a75b;
    }

    html[data-cms-theme="dark"] .ui-datepicker .ui-state-active,
    html[data-cms-theme="dark"] .ui-datepicker .ui-state-hover {
        background: #315f85;
        color: #fff;
        border-color: #a5d2f5;
    }

    html[data-cms-theme="dark"] .ui-datepicker :is(.ui-datepicker-prev, .ui-datepicker-next) .ui-icon {
        background-image: none;
        text-indent: 0;
        font-size: 0;
    }

    html[data-cms-theme="dark"] .ui-datepicker .ui-datepicker-prev .ui-icon::after,
    html[data-cms-theme="dark"] .ui-datepicker .ui-datepicker-next .ui-icon::after {
        display: block;
        color: var(--cms-text);
        font-size: 22px;
        line-height: 14px;
        text-align: center;
    }

    html[data-cms-theme="dark"] .ui-datepicker .ui-datepicker-prev .ui-icon::after { content: "\2039"; }
    html[data-cms-theme="dark"] .ui-datepicker .ui-datepicker-next .ui-icon::after { content: "\203a"; }

    html[data-cms-theme="dark"] #topcolor-ut {
        background-color: #19445b;
        color: #d4efff;
    }

    html[data-cms-theme="dark"] #topcolor-st {
        background-color: var(--cms-warning-bg);
        color: var(--cms-warning);
    }

    html[data-cms-theme="dark"] .cms-theme-toggle {
        background-color: var(--cms-raised);
        color: var(--cms-text);
        border-color: var(--cms-border);
    }

    html[data-cms-theme="dark"] .cms-theme-error .cms-theme-status {
        color: var(--cms-danger);
    }

    /* Preserve hidden repeated values even when their cells also carry a status hue. */
    html[data-cms-theme="dark"] .tablesorter-default .duplicate-cell,
    html[data-cms-theme="dark"] .duplicate-cell {
        color: transparent !important;
    }

    html[data-cms-theme="dark"] .table-sorted .duplicate-cell {
        color: inherit !important;
    }
}

@media print {
    .cms-theme-control { display: none !important; }
}
