/* Shared screen theme repairs. The existing body class remains the single switch.
 * Keep semantic RGB colors unchanged: Bootstrap also uses them for solid badges.
 * Document canvases, images, print output and branded hero surfaces are excluded.
 */
@media screen {
    body.admin-dark-mode {
        --theme-panel: #0c1728;
        --theme-raised: #14263b;
        --theme-hover: #1a344e;
        --theme-line: #35516e;
        --theme-ink: #e2edf8;
        --theme-muted: #a6bbd0;
        --theme-link: #86caff;
        --theme-success: #86dfb5;
        --theme-warning: #f4d189;
        --theme-danger: #ffabb8;
        --bs-body-color: var(--theme-ink);
        --bs-body-color-rgb: 226, 237, 248;
        --bs-body-bg: var(--theme-panel);
        --bs-body-bg-rgb: 12, 23, 40;
        --bs-emphasis-color: #f2f7fc;
        --bs-emphasis-color-rgb: 242, 247, 252;
        --bs-secondary-color: var(--theme-muted);
        --bs-secondary-color-rgb: 166, 187, 208;
        --bs-secondary-bg: var(--theme-raised);
        --bs-secondary-bg-rgb: 20, 38, 59;
        --bs-tertiary-color: #9fb4c9;
        --bs-tertiary-color-rgb: 159, 180, 201;
        --bs-tertiary-bg: #102136;
        --bs-tertiary-bg-rgb: 16, 33, 54;
        --bs-border-color: var(--theme-line);
        --bs-border-color-translucent: rgba(166, 187, 208, .24);
        --bs-heading-color: inherit;
        --bs-link-color: var(--theme-link);
        --bs-link-color-rgb: 134, 202, 255;
        --bs-link-hover-color: #b9e0ff;
        --bs-link-hover-color-rgb: 185, 224, 255;
        --bs-primary-text-emphasis: #b4d7ff;
        --bs-primary-bg-subtle: #132e4b;
        --bs-primary-border-subtle: #335d87;
        --bs-secondary-text-emphasis: #c8d5e1;
        --bs-secondary-bg-subtle: #213146;
        --bs-secondary-border-subtle: #475d73;
        --bs-success-text-emphasis: var(--theme-success);
        --bs-success-bg-subtle: #15392e;
        --bs-success-border-subtle: #346851;
        --bs-info-text-emphasis: #95dfe9;
        --bs-info-bg-subtle: #12333f;
        --bs-info-border-subtle: #366878;
        --bs-warning-text-emphasis: var(--theme-warning);
        --bs-warning-bg-subtle: #3b2e19;
        --bs-warning-border-subtle: #79623b;
        --bs-danger-text-emphasis: var(--theme-danger);
        --bs-danger-bg-subtle: #40222d;
        --bs-danger-border-subtle: #855064;
        --bs-light-text-emphasis: #d5e2ee;
        --bs-light-bg-subtle: var(--theme-raised);
        --bs-light-border-subtle: var(--theme-line);
        --bs-dark-text-emphasis: #d5e2ee;
        --bs-dark-bg-subtle: #111e2d;
        --bs-dark-border-subtle: #35485c;
        --bs-form-valid-color: var(--theme-success);
        --bs-form-valid-border-color: #57ab83;
        --bs-form-invalid-color: var(--theme-danger);
        --bs-form-invalid-border-color: #de8295;
    }

    /* Component-local Bootstrap variables do not inherit a color-mode setting. */
    body.admin-dark-mode .accordion {
        --bs-accordion-color: var(--theme-ink);
        --bs-accordion-bg: var(--theme-panel);
        --bs-accordion-border-color: var(--theme-line);
        --bs-accordion-btn-color: var(--theme-ink);
        --bs-accordion-btn-bg: var(--theme-raised);
        --bs-accordion-active-color: #c8e6ff;
        --bs-accordion-active-bg: #183b59;
    }
    body.admin-dark-mode .accordion-button::after { filter: brightness(0) invert(1); }
    body.admin-dark-mode .popover {
        --bs-popover-bg: var(--theme-panel);
        --bs-popover-border-color: var(--theme-line);
        --bs-popover-header-bg: var(--theme-raised);
        --bs-popover-header-color: var(--theme-ink);
        --bs-popover-body-color: var(--theme-ink);
    }
    body.admin-dark-mode .dropdown-menu {
        --bs-dropdown-divider-bg: var(--theme-line);
        --bs-dropdown-link-disabled-color: #8aa1b8;
    }
    body.admin-dark-mode .dropdown-item.disabled,
    body.admin-dark-mode .dropdown-item:disabled { color: #8aa1b8 !important; }
    body.admin-dark-mode .dropdown-item.active,
    body.admin-dark-mode .dropdown-item:active { background: #1d5074 !important; }
    body.admin-dark-mode .list-group {
        --bs-list-group-action-color: var(--theme-ink);
        --bs-list-group-action-hover-color: #f2f7fc;
        --bs-list-group-action-hover-bg: var(--theme-hover);
        --bs-list-group-action-active-color: #f2f7fc;
        --bs-list-group-action-active-bg: #1d5074;
    }
    body.admin-dark-mode .list-group-item-action:hover,
    body.admin-dark-mode .list-group-item-action:focus { background: var(--theme-hover) !important; }
    body.admin-dark-mode .list-group-item.active { background: #1d5074 !important; }
    body.admin-dark-mode .progress { --bs-progress-bg: #263d53; }
    body.admin-dark-mode .form-select {
        --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23c8d9e9' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    }
    body.admin-dark-mode :is(.form-select, .items-table select) option,
    body.admin-dark-mode :is(.form-select, .items-table select) optgroup {
        color: var(--theme-ink);
        background: var(--theme-panel);
    }
    body.admin-dark-mode .form-control::file-selector-button {
        color: var(--theme-ink);
        background: var(--theme-raised);
    }
    body.admin-dark-mode .form-control:hover:not(:disabled):not([readonly])::file-selector-button {
        background: var(--theme-hover);
    }
    body.admin-dark-mode .form-text { color: var(--theme-muted); }
    body.admin-dark-mode .form-floating > label::after { background: var(--theme-panel) !important; }
    body.admin-dark-mode .form-floating > label { color: var(--theme-muted) !important; }

    /* Readable semantic text, without changing the palette of filled controls. */
    body.admin-dark-mode .text-primary:not(.badge):not(.btn) { color: var(--theme-link) !important; }
    body.admin-dark-mode .text-success:not(.badge):not(.btn) { color: var(--theme-success) !important; }
    body.admin-dark-mode .text-danger:not(.badge):not(.btn) { color: var(--theme-danger) !important; }
    body.admin-dark-mode .text-warning:not(.badge):not(.btn) { color: var(--theme-warning) !important; }
    body.admin-dark-mode .alert .alert-link { color: inherit; text-decoration: underline; }
    body.admin-dark-mode .btn-primary {
        color: #fff;
        background: linear-gradient(135deg, #155ba2, #11647e);
        border-color: #428bbd;
    }
    body.admin-dark-mode .btn-primary:hover,
    body.admin-dark-mode .btn-primary:focus-visible {
        color: #fff;
        background: linear-gradient(135deg, #1c67ac, #17728d);
        border-color: #91c9f0;
    }
    body.admin-dark-mode .btn-outline-primary:hover,
    body.admin-dark-mode .btn-outline-primary:focus-visible,
    body.admin-dark-mode .btn-outline-primary:active {
        color: #071d2d;
        background: #86caff;
        border-color: #86caff;
    }
    body.admin-dark-mode .btn-outline-primary:is(:hover, :focus-visible, :active) :is(strong, small, .small, .text-dark) {
        color: #071d2d !important;
    }
    body.admin-dark-mode .btn-outline-dark {
        --bs-btn-color: #d4e1ee;
        --bs-btn-border-color: #718ca5;
        --bs-btn-hover-color: #fff;
        --bs-btn-hover-bg: #274561;
        --bs-btn-hover-border-color: #96b5d0;
        --bs-btn-active-color: #fff;
        --bs-btn-active-bg: #274561;
        --bs-btn-active-border-color: #96b5d0;
        --bs-btn-disabled-color: #91a7bd;
        --bs-btn-disabled-border-color: #526b84;
    }
    body.admin-dark-mode .btn-outline-success {
        --bs-btn-color: #86dfb5;
        --bs-btn-border-color: #57ab83;
        --bs-btn-hover-bg: #206648;
        --bs-btn-active-bg: #206648;
    }
    body.admin-dark-mode .btn-outline-danger {
        --bs-btn-color: #ffabb8;
        --bs-btn-border-color: #cc7087;
        --bs-btn-hover-bg: #a53249;
        --bs-btn-active-bg: #a53249;
    }
    /* Legacy .text-dark !important otherwise turns yellow/cyan status text white. */
    body.admin-dark-mode .badge:is(.bg-warning, .bg-info, .text-bg-warning, .text-bg-info),
    body.admin-dark-mode .badge:is(.bg-warning, .bg-info, .text-bg-warning, .text-bg-info) :is(.text-dark, strong, .small),
    body.admin-dark-mode .btn:is(.btn-warning, .btn-info, .btn-light).text-dark,
    body.admin-dark-mode .btn:is(.btn-warning, .btn-info, .btn-light) :is(strong, small, .small, .text-dark) {
        color: #102333 !important;
    }
    body.admin-dark-mode .table-light {
        --bs-table-bg: var(--theme-raised);
        --bs-table-color: var(--theme-ink);
        --bs-table-border-color: var(--theme-line);
        --bs-table-striped-bg: #1a3047;
        --bs-table-striped-color: var(--theme-ink);
        --bs-table-active-bg: #203e59;
        --bs-table-active-color: var(--theme-ink);
        --bs-table-hover-bg: #203e59;
        --bs-table-hover-color: var(--theme-ink);
    }

    /* Request history labels were still using fixed navy text on dark panels. */
    body.admin-dark-mode .request-form :is(.approval-history-name, .approval-history-time-main, .request-change-actor) {
        color: var(--theme-ink);
    }
    body.admin-dark-mode .request-form .request-change-time { color: var(--theme-muted); }
    body.admin-dark-mode .request-form .items-table .urgency-acil,
    body.admin-dark-mode .request-form .items-table select.urgency-select-acil {
        color: #ff9cae !important;
    }
    /* Upload controls also occur outside the request form. Never recolor previews. */
    body.admin-dark-mode .file-dropzone {
        background: #10243b;
        border-color: #577c9e;
        color: #cfe6ff;
    }
    body.admin-dark-mode .file-dropzone.dragover { background: #163352; border-color: #86caff; }
    body.admin-dark-mode .file-dropzone .file-preview-item {
        color: var(--theme-ink);
        background: var(--theme-panel);
        border-color: var(--theme-line);
    }
    body.admin-dark-mode .file-dropzone .file-preview-name { color: var(--theme-ink); }
    body.admin-dark-mode .file-dropzone :is(.file-list, .file-preview-meta) { color: var(--theme-muted); }

    /* These workspaces have local light styles after the shared layout stylesheet. */
    body.admin-dark-mode :is(.ugur-workspace, .intake-workspace) {
        --uw-ink: var(--theme-ink);
        background: #0a1624;
        color: var(--theme-ink);
    }
    body.admin-dark-mode :is(.ugur-metric, .ugur-panel, .intake-stat, .intake-tabs, .intake-card, .intake-empty) {
        color: var(--theme-ink);
        background: var(--theme-panel);
        border-color: var(--theme-line);
    }
    body.admin-dark-mode :is(.ugur-panel-head, .ugur-record, .intake-card-head) { border-color: var(--theme-line); }
    body.admin-dark-mode :is(.ugur-record-no, .intake-request-no) { color: #c5e5ff; }
    body.admin-dark-mode :is(.ugur-metric small, .ugur-record-meta, .ugur-empty, .intake-stat small, .intake-meta, .intake-data small, .intake-empty) {
        color: var(--theme-muted);
    }
    body.admin-dark-mode :is(.ugur-flow-step, .intake-data, .intake-decision) {
        color: var(--theme-ink);
        background: var(--theme-raised);
        border-color: var(--theme-line);
    }
    body.admin-dark-mode :is(.ugur-metric .icon, .invoice-exempt-badge, .intake-stat i, .ugur-flow-step:first-child, .ugur-flow-step:nth-child(2), .intake-route span:first-child) {
        color: #8ce0c4;
        background: #173b35;
    }
    body.admin-dark-mode .intake-route span { background: #1c354a; color: #bdd7e8; }
    body.admin-dark-mode .intake-tab { color: #bfd0e0; }
    body.admin-dark-mode .intake-tab:hover { background: #1a344e; color: #fff; }
    body.admin-dark-mode .intake-tab.active { background: #1b5679; color: #fff; }

    /* Conversation authors retain distinct, readable semantic backgrounds. */
    body.admin-dark-mode .support-layout .message { color: var(--theme-ink); background: #183148; }
    body.admin-dark-mode .support-layout .message.mine { background: #163c34; }
    body.admin-dark-mode .support-layout .message.admin { background: #193756; border-color: #69b6ee; }
    body.admin-dark-mode .support-layout .message.internal { background: #3b311d; border-color: #bca365; }
    body.admin-dark-mode .ticket-row { border-color: var(--theme-line); }
    body.admin-dark-mode .ticket-row:hover,
    body.admin-dark-mode .ticket-row.active { border-color: #74bdcf; }
    body.admin-dark-mode .accessibility-option { border-color: var(--theme-line); }
    body.admin-dark-mode .scale-value { color: #b4dfff; background: #173e58; }
    body.admin-dark-mode .account-icon { color: #8fe1df; background: #153c43; }
    body.admin-dark-mode .card:is(.support-hero, .accessibility-hero) {
        background: linear-gradient(125deg, #113553, #12556a 62%, #165a57) !important;
        color: #fff !important;
    }
    html[data-high-contrast="1"] body.admin-dark-mode {
        --theme-muted: #c6d8ea;
        --theme-line: #7793b0;
    }
}
