/* Legacy page components share the same palette as the workspace.
 * Loaded after page CSS and theme.css. Keep all overrides screen-only: print
 * output, photographs, QR pixels and saturated action colours are not inverted.
 * data-rd-page is the bounded server script name, not a URL/query-string match.
 */
@media screen {
  :root {
    --rd-link: #1d4ed8; --rd-info-bg: #eff6ff; --rd-info-text: #1e40af;
    --rd-success-bg: #ecfdf5; --rd-success-text: #065f46;
    --rd-warning-bg: #fffbeb; --rd-warning-text: #92400e;
    --rd-danger-bg: #fef2f2; --rd-danger-text: #991b1b;
  }
  html[data-rd-theme="dark"] {
    --rd-link: #bfdbfe; --rd-info-bg: #172e52; --rd-info-text: #bfdbfe;
    --rd-success-bg: #153d35; --rd-success-text: #a7f3d0;
    --rd-warning-bg: #49321b; --rd-warning-text: #fde68a;
    --rd-danger-bg: #4b2529; --rd-danger-text: #fecaca;
  }

  /* DataTables page-local labels/inputs and !important pagination beat the
   * original low-specificity form theme. Preserve disabled/current states. */
  html[data-rd-theme] .dataTables_wrapper :is(.dataTables_filter, .dataTables_length) label,
  html[data-rd-theme] .dataTables_wrapper .dataTables_info { color: var(--rd-muted); }
  html[data-rd-theme] .dataTables_wrapper .dataTables_filter input,
  html[data-rd-theme] .dataTables_wrapper .dataTables_length select {
    color: var(--rd-text); background: var(--rd-surface); border-color: var(--rd-border);
    min-height: 44px; max-width: 100%;
  }
  html[data-rd-theme] .dataTables_wrapper .dataTables_filter input:disabled,
  html[data-rd-theme] .dataTables_wrapper .dataTables_length select:disabled {
    background: var(--rd-raised); color: var(--rd-muted);
  }
  html[data-rd-theme] .dataTables_wrapper .dataTables_paginate .paginate_button {
    background: var(--rd-surface) !important; color: var(--rd-text) !important;
    border-color: var(--rd-border) !important; min-width: 44px; min-height: 44px;
    display: inline-flex; align-items: center; justify-content: center;
  }
  html[data-rd-theme] .dataTables_wrapper .dataTables_paginate .paginate_button:is(.current, :hover, :focus-visible) {
    background: var(--rd-raised) !important; color: var(--rd-text) !important;
  }
  html[data-rd-theme] .dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
    background: var(--rd-surface) !important; color: var(--rd-muted) !important;
  }
  html[data-rd-theme] .dataTables_wrapper :is(input, select, .paginate_button):focus-visible {
    outline: 2px solid var(--rd-focus); outline-offset: 2px;
  }
  html[data-rd-theme="dark"] :is(.data-table, .history-table) thead :is(tr, th) {
    background: var(--rd-raised); color: var(--rd-text); border-color: var(--rd-border);
  }
  html[data-rd-theme="dark"] .data-table tbody tr:not([class*="bg-"]):not([style*="background"]) {
    background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border);
  }
  html[data-rd-theme="dark"] .data-table tbody tr:nth-child(even):not([class*="bg-"]):not([style*="background"]) { background: var(--rd-canvas); }
  html[data-rd-theme="dark"] .data-table tbody tr:hover:not([class*="bg-"]):not([style*="background"]) { background: var(--rd-raised); }

  /* Controls/edit/history and equipment/search/history: neutral surfaces only.
   * Scope generic names (.chip/.meta) so other modules keep semantic variants. */
  html:is([data-rd-page="controls"], [data-rd-page="controls_edit"], [data-rd-page="controls_history"], [data-rd-page="equipment"], [data-rd-page="equipment_edit"], [data-rd-page="equipment_history"]) :is(.panel-card, .search-card, .gallery-card, .subnav) {
    background: var(--rd-surface); color: var(--rd-text); border: 1px solid var(--rd-border); border-radius: .5rem;
  }
  html:is([data-rd-page="controls_edit"], [data-rd-page="controls_history"]) .panel-header { border-bottom: 1px solid var(--rd-border); }
  html:is([data-rd-page="controls"], [data-rd-page="equipment"], [data-rd-page="equipment_history"]) :is(.muted, .meta, .img-meta) { color: var(--rd-muted); }
  html:is([data-rd-page="controls"], [data-rd-page="equipment"], [data-rd-page="equipment_history"]) :is(.action-link, .result-link) { color: var(--rd-link); }
  html:is([data-rd-page="controls"], [data-rd-page="equipment_history"]) :is(.chip, .chip-link, .subnav a) {
    background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border);
    min-height: 44px; align-items: center; overflow-wrap: anywhere;
  }
  html[data-rd-page="controls"] .chip.active { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }
  html[data-rd-page="equipment_history"] :is(.chip-link, .subnav a):hover { background: var(--rd-raised); }
  html[data-rd-page="equipment_history"] .subnav a { display: inline-flex; }
  html:is([data-rd-page="controls"], [data-rd-page="equipment_history"]) .badge-green { background: var(--rd-success-bg); color: var(--rd-success-text); border-color: currentColor; }
  html:is([data-rd-page="controls"], [data-rd-page="equipment_history"]) .badge-red { background: var(--rd-danger-bg); color: var(--rd-danger-text); border-color: currentColor; }
  html[data-rd-page="equipment_history"] .badge-blue { background: var(--rd-info-bg); color: var(--rd-info-text); border-color: currentColor; }
  html[data-rd-page="equipment"] :is(.equip-thumb, .search-thumb),
  html[data-rd-page="equipment_history"] .gallery-img { background: var(--rd-canvas); border-color: var(--rd-border); }
  html[data-rd-page="equipment"] .search-item { border-color: var(--rd-border); flex-wrap: wrap; }
  html[data-rd-page="equipment"] .search-item > * { min-width: 0; max-width: 100%; }
  html[data-rd-page="equipment"] #equipSearchForm { flex-wrap: wrap; }
  html[data-rd-page="equipment"] #equipSearchInput { flex: 1 1 14rem; width: auto; min-width: 0; max-width: 100%; min-height: 44px; }
  html[data-rd-page="equipment"] #equipSearchBtn { min-height: 44px; }
  html:is([data-rd-page="controls_edit"], [data-rd-page="change_password"]) form :is(input:not([type="checkbox"]):not([type="hidden"]), select, textarea, button) { min-height: 44px; font-size: 1rem; }
  .ctrl-icon-opt {
    border: 1px solid var(--rd-border); background: var(--rd-surface); color: var(--rd-text);
    border-radius: 6px; padding: 4px 6px; font-size: 1rem; cursor: pointer; min-width: 44px; min-height: 44px;
  }
  .ctrl-icon-opt[aria-pressed="true"] { border-color: var(--rd-focus); background: var(--rd-info-bg); }
  .ctrl-icon-opt:focus-visible { outline: 2px solid var(--rd-focus); outline-offset: 2px; }

  /* Accelerated/conditions pages used an independent light-only palette. Keep
   * the module's orange identity and semantic due/overdue hues, share neutrals. */
  html[data-rd-page="stability"] {
    --st-ink: var(--rd-text); --st-ink-soft: var(--rd-text);
    --st-muted: var(--rd-muted); --st-muted-light: var(--rd-muted);
    --st-border: var(--rd-border); --st-panel: var(--rd-surface);
    --st-panel-soft: var(--rd-canvas); --st-panel-soft-2: var(--rd-raised);
    --st-accent: #c2410c; --st-accent-strong: #9a3412;
    --st-accent-soft: var(--rd-warning-bg); --st-chip-text: var(--rd-warning-text);
    --st-danger: var(--rd-danger-text); --st-danger-soft: var(--rd-danger-bg);
    --st-warn: var(--rd-warning-text); --st-warn-soft: var(--rd-warning-bg);
  }
  html[data-rd-theme="dark"][data-rd-page="stability"] { --st-accent-strong: #fed7aa; }
  html[data-rd-page="stability"] :is(.attention-item, .condition-card, .empty-state, .sample-table-wrap, .qr-card, .panel-toggle, .sample-action, .btn-secondary) {
    background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border);
  }
  html[data-rd-page="stability"] :is(.toolbar, .condition-form, .sample-table-wrap) :is(input, select, textarea) {
    background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border); min-height: 44px; max-width: 100%;
  }
  html[data-rd-page="stability"] :is(.toolbar, .condition-form, .sample-table-wrap) :is(input, select, textarea):disabled { background: var(--rd-raised); color: var(--rd-muted); }
  html[data-rd-page="stability"] .toolbar :is(.search-input, .select-input) { min-width: 0; }
  html[data-rd-page="stability"] .sample-table tbody :is(td, tr) { border-color: var(--rd-border); }
  html[data-rd-page="stability"] .sample-table tbody tr:hover { background: var(--rd-raised); }
  html[data-rd-page="stability"] .sample-thumb--placeholder { background: var(--rd-raised); }
  html[data-rd-page="stability"] :is(.chip--emerald, .badge--emerald, .badge--amber, .notice) { background: var(--rd-warning-bg); color: var(--rd-warning-text); border-color: currentColor; }
  html[data-rd-page="stability"] :is(.flash, .badge--green) { background: var(--rd-success-bg); color: var(--rd-success-text); border-color: currentColor; }
  html[data-rd-page="stability"] .badge--rose { background: var(--rd-danger-bg); color: var(--rd-danger-text); }
  html[data-rd-page="stability"] .btn-primary:hover { background: #9a3412; color: #fff; }
  html[data-rd-page="stability"] :is(.panel-toggle, .sample-action, .attention-link, .btn-primary, .btn-secondary) { min-height: 44px; }
  html[data-rd-page="stability"] .panel-toggle { min-width: 44px; }
  html[data-rd-page="stability"] .qr-card { max-height: calc(100vh - 36px); max-height: calc(100dvh - 36px); overflow-y: auto; overscroll-behavior: contain; }
  html[data-rd-page="stability"] .qr-card__head { position: sticky; top: 0; z-index: 1; background: var(--rd-surface); }

  /* Formulation editor, copy/new and public read-only variants share these
   * unique roots. Do not depend on the wrapper script name for their palette. */
  html[data-rd-theme] #partsMainWrap { background: var(--rd-canvas); border-color: var(--rd-border); }
  html[data-rd-theme] #partsMainWrap :is(.part-card, .part-section, .equip-card, .equip-chip, .equip-picker, .equip-readonly, .video-chip, .ctrl-chip, .metric-tile, .readonly-note) {
    background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border);
  }
  html[data-rd-theme] #partsMainWrap :is(.part-header, .col-composition, .step-attach-previews) { border-color: var(--rd-border); }
  html[data-rd-theme] #partsMainWrap :is(.part-badge, .metric-value, .equip-card .nm, .equip-none) { color: var(--rd-text); }
  html[data-rd-theme] #partsMainWrap :is(.ie-label, .equip-placeholder, .ctrl-chip .lbl, .drag-handle) { color: var(--rd-muted); }
  html[data-rd-theme] #partsMainWrap :is(.step-attach-previews, .equip-card .ph) { background: var(--rd-canvas); }
  html[data-rd-theme] #partsMainWrap :is(.steps-table, .part-items) thead th { background: var(--rd-raised); color: var(--rd-text); }
  html[data-rd-theme="dark"] #partsContainer .part-card:nth-child(6n+1) { --accent-50: #172e52; --accent-200: #60a5fa; }
  html[data-rd-theme="dark"] #partsContainer .part-card:nth-child(6n+2) { --accent-50: #153d35; --accent-200: #34d399; }
  html[data-rd-theme="dark"] #partsContainer .part-card:nth-child(6n+3) { --accent-50: #27264f; --accent-200: #a78bfa; }
  html[data-rd-theme="dark"] #partsContainer .part-card:nth-child(6n+4) { --accent-50: #49321b; --accent-200: #fbbf24; }
  html[data-rd-theme="dark"] #partsContainer .part-card:nth-child(6n+5) { --accent-50: #4b2529; --accent-200: #fb7185; }
  html[data-rd-theme="dark"] #partsContainer .part-card:nth-child(6n+6) { --accent-50: #27264f; --accent-200: #818cf8; }
  html[data-rd-theme] #partsMainWrap :is(input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]), textarea, select) {
    background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border);
  }
  html[data-rd-theme] #partsMainWrap :is(input, textarea, select):disabled { background: var(--rd-raised); color: var(--rd-muted); }
  html[data-rd-theme] #partsMainWrap :is(.action-btn, .batch-step-btn) { background: var(--rd-raised); color: var(--rd-text); border-color: var(--rd-border); }
  html[data-rd-theme] #partsMainWrap :is(.btn-delete, .att-remove, .ctrl-chip .rm) { background: var(--rd-danger-bg); color: var(--rd-danger-text); border-color: currentColor; }
  html[data-rd-theme] #partsMainWrap :is(.btn-delete, .att-remove, .ctrl-chip .rm):hover { background: var(--rd-danger-bg); color: var(--rd-danger-text); }
  html[data-rd-theme] :is(#equipPickerModal, #ingrPickerModal) .sheet {
    background: var(--rd-surface); color: var(--rd-text); width: calc(100% - 2rem); margin: 1rem auto;
    max-height: calc(100vh - 2rem); max-height: calc(100dvh - 2rem);
  }
  html[data-rd-theme] :is(#equipPickerModal, #ingrPickerModal) .sheet .hd { border-color: var(--rd-border); flex: 0 0 auto; flex-wrap: wrap; gap: .5rem; }
  html[data-rd-theme] :is(#equipPickerModal, #ingrPickerModal) .sheet .bd { min-height: 0; overflow: auto; overscroll-behavior: contain; }
  html[data-rd-theme] :is(#equipPickerModal, #ingrPickerModal) .sheet .hd button { min-height: 44px; min-width: 44px; }
  html[data-rd-theme] #ingrSearchBox { width: min(340px, 100%); min-width: 0; max-width: 100%; box-sizing: border-box; min-height: 44px; }
  html[data-rd-theme] #equipPickerModal .equip-card, html[data-rd-theme] #equipHoverPreview { background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border); }
  html[data-rd-theme] #equipPickerModal .equip-card .ph { background: var(--rd-canvas); }
  html[data-rd-theme] #equipPickerModal .equip-card .nm { color: var(--rd-text); }
  html[data-rd-theme] #ingrResultsTable thead th { color: var(--rd-text); background: var(--rd-raised); border-color: var(--rd-border); }
  html[data-rd-theme] #ingrResultsTable tbody tr:nth-child(even) { background: var(--rd-canvas); }
  html[data-rd-theme] #ingrResultsTable tbody tr:hover { background: var(--rd-raised); }
  html[data-rd-theme] #ingrResultsTable tbody tr.has-stock td { background: var(--rd-success-bg); color: var(--rd-success-text); }
  html[data-rd-theme] #ingrResultsTable tbody tr.is-current td,
  html[data-rd-theme] #ingrResultsTable tbody tr.has-stock.is-current:hover td { background: var(--rd-warning-bg); color: var(--rd-warning-text); }
  html[data-rd-theme] #ingrResultsTable :is(.ingredient-select-name, .shop-link) { color: inherit; }
  html[data-rd-theme] #ingrResultsTable .shop-link { background: var(--rd-surface); color: var(--rd-link); border-color: var(--rd-border); min-width: 44px; min-height: 44px; }
  html[data-rd-theme] #ingrResultsTable .current-badge { background: var(--rd-success-bg); color: var(--rd-success-text); border-color: currentColor; }
  html[data-rd-theme] #ingrPickerModal .ingr-overlay { background: rgb(var(--rd-surface-rgb) / .7); }
  html[data-rd-theme] #ingrPickerModal .ingr-status { background: var(--rd-warning-bg); color: var(--rd-warning-text); border-color: currentColor; }
  html[data-rd-theme] #ingrPickerModal .ingr-loading { color: var(--rd-muted); }
  html[data-rd-theme] #final_composition_table thead th { background: var(--rd-raised); color: var(--rd-text); }
  html[data-rd-theme] #final_composition_table.striped tbody tr:nth-child(odd) { background: var(--rd-canvas); }
  html[data-rd-theme] #final_composition_table.clickable tbody tr:hover { background: var(--rd-raised); }
  html[data-rd-theme] :is(#partsOutlineWrap .outline-item, #editorCard .parts-nav-wrap, #editorCard .parts-pill, #processCanvas .proc-node, .proc-hover) { background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border); }
  html[data-rd-theme] :is(#partsOutlineWrap .nm, #processCanvas .proc-node .nm, .proc-hover .title, .proc-hover .sub) { color: var(--rd-text); }
  html[data-rd-theme] :is(#partsOutlineWrap .hdr, #partsOutlineWrap .sum, #editorCard .parts-pill .meta, #processCanvas .proc-node .meta, #processCanvas .proc-node .bd) { color: var(--rd-muted); }
  html[data-rd-theme] :is(#partsOutlineWrap .outline-item.active, #editorCard .parts-pill.active) { background: var(--rd-info-bg); border-color: var(--rd-focus); }
  html[data-rd-theme] :is(#partsOutlineWrap .sum.ok, #editorCard .parts-pill .sum-ok) { color: var(--rd-success-text); }
  html[data-rd-theme] :is(#partsOutlineWrap .sum.warn, #editorCard .parts-pill .sum-warn) { color: var(--rd-danger-text); }
  html[data-rd-theme] :is(#partsMainWrap .rd-premix-notice, #partsMainWrap .rd-premix-title, #partsMainWrap .rd-premix-copy, #partsMainWrap .premix-highlight-badge, #editorCard .pill-warn) { background: var(--rd-warning-bg); color: var(--rd-warning-text); border-color: currentColor; }
  html[data-rd-theme="dark"] .premix-highlight-row, html[data-rd-theme="dark"] .premix-highlight-row:hover { background: var(--rd-warning-bg) !important; }
  html:is([data-rd-page="view_formulation"], [data-rd-page="new_formulation"]) :is(.panel-card, .panel-meta, .chip) { background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border); }
  html:is([data-rd-page="view_formulation"], [data-rd-page="new_formulation"]) .panel-header { background: var(--rd-info-bg); border-color: var(--rd-border); }
  html:is([data-rd-page="view_formulation"], [data-rd-page="new_formulation"]) .chip:is(.success, .state-released) { background: var(--rd-success-bg); color: var(--rd-success-text); }
  html:is([data-rd-page="view_formulation"], [data-rd-page="new_formulation"]) .chip:is(.warn, .state-testing, .state-hold) { background: var(--rd-warning-bg); color: var(--rd-warning-text); }
  html:is([data-rd-page="view_formulation"], [data-rd-page="new_formulation"]) .chip.state-dev { background: var(--rd-info-bg); color: var(--rd-info-text); }
  html:is([data-rd-page="view_formulation"], [data-rd-page="new_formulation"]) .chip.state-blocked { background: var(--rd-danger-bg); color: var(--rd-danger-text); }

  /* Project detail keeps literal light cards in its page stylesheet. Dark theme
   * already recolors the Tailwind text and native fields, which left light
   * labels on white cards and dark fields inside them. */
  html[data-rd-theme="dark"][data-rd-page="project_view"] :is(.panel-card, .section-card) {
    background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border);
  }
  html[data-rd-theme="dark"][data-rd-page="project_view"] .section-card { background: var(--rd-canvas); }
  html[data-rd-theme="dark"][data-rd-page="project_view"] .panel-header {
    background: var(--rd-info-bg); color: var(--rd-text); border-bottom-color: var(--rd-border);
  }
  html[data-rd-theme="dark"][data-rd-page="project_view"] .panel-meta { color: var(--rd-muted); }
  html[data-rd-theme="dark"][data-rd-page="project_view"] :is(.chip, .thumb) {
    background: var(--rd-raised); color: var(--rd-text); border-color: var(--rd-border);
  }
  html[data-rd-theme="dark"][data-rd-page="project_view"] .chip.success,
  html[data-rd-theme="dark"][data-rd-page="project_view"] .section-saved-note {
    background: var(--rd-success-bg); color: var(--rd-success-text); border-color: currentColor;
  }
  html[data-rd-theme="dark"][data-rd-page="project_view"] .chip.warn {
    background: var(--rd-warning-bg); color: var(--rd-warning-text); border-color: currentColor;
  }
  html[data-rd-theme="dark"][data-rd-page="project_view"] .chip.muted { color: var(--rd-muted); }
  html[data-rd-theme="dark"][data-rd-page="project_view"] input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="image"]),
  html[data-rd-theme="dark"][data-rd-page="project_view"] textarea,
  html[data-rd-theme="dark"][data-rd-page="project_view"] select {
    background-color: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border);
  }
  html[data-rd-theme="dark"][data-rd-page="project_view"] input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="image"]):disabled,
  html[data-rd-theme="dark"][data-rd-page="project_view"] textarea:disabled,
  html[data-rd-theme="dark"][data-rd-page="project_view"] select:disabled {
    background-color: var(--rd-raised); color: var(--rd-muted); opacity: 1;
  }
  @media (pointer: coarse) {
    html[data-rd-theme] #partsMainWrap :is(.action-btn, .equip-picker, .att-remove, .ctrl-chip .rm, .batch-step-btn) { min-height: 44px; min-width: 44px; }
    html[data-rd-theme] #partsMainWrap :is(.btn-attach-open, .btn-upload-attach, .btn-qr-upload-attach, .btn-upload-video, .btn-add-ctrl) { min-height: 44px; }
    html[data-rd-theme] #partsMainWrap :is(.ctrls-add, .ctrl-chip) { flex-wrap: wrap; }
  }

  /* Formula lab-scope review, linked services and body-portaled picker. The
   * provider's approval/rejection controls retain distinct semantic colours. */
  html[data-rd-theme] .rd-scope-card { --rd-scope-ink: var(--rd-text); --rd-scope-muted: var(--rd-muted); }
  html[data-rd-theme] :is(.rd-scope-card, .rd-scope-card__header, .rd-scope-suggestion, .rd-scope-link-row, .rd-scope-picker__dialog, .rd-scope-picker-item) { background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border); }
  html[data-rd-theme] :is(.rd-scope-count, .rd-scope-confidence-review, .rd-scope-note, .rd-scope-meta-chip, .rd-scope-links__count, .rd-scope-picker__search) { background: var(--rd-raised); color: var(--rd-muted); border-color: var(--rd-border); }
  html[data-rd-theme] :is(.rd-scope-suggestion__reason, .rd-scope-detail h4, .rd-scope-confidence-review h4) { color: var(--rd-muted); }
  html[data-rd-theme] :is(.rd-scope-card h2, .rd-scope-card h3, .rd-scope-count strong, .rd-scope-picker__header h2, .rd-scope-picker__header h3) { color: var(--rd-text); }
  html[data-rd-theme] .rd-scope-status { background: var(--rd-raised); color: var(--rd-muted); border-color: var(--rd-border); }
  html[data-rd-theme] :is(.rd-scope-card__icon, .rd-scope-status[data-status="queued"], .rd-scope-status[data-status="running"], .rd-scope-notifications [data-pending="true"], .rd-scope-meta-chip--service) { background: var(--rd-info-bg); color: var(--rd-info-text); border-color: currentColor; }
  html[data-rd-theme] :is(.rd-scope-alert--success, .rd-scope-status[data-status="finished"], .rd-scope-count[data-tone="approved"]) { background: var(--rd-success-bg); color: var(--rd-success-text); border-color: currentColor; }
  html[data-rd-theme] :is(.rd-scope-alert--error, .rd-scope-status[data-status="failed"], .rd-scope-status[data-status="outdated"], .rd-scope-count[data-tone="rejected"]) { background: var(--rd-danger-bg); color: var(--rd-danger-text); border-color: currentColor; }
  html[data-rd-theme] :is(.rd-scope-alert--warning, .rd-scope-count[data-tone="pending"]) { background: var(--rd-warning-bg); color: var(--rd-warning-text); border-color: currentColor; }
  html[data-rd-theme] .rd-scope-count[data-tone] strong { color: inherit; }
  html[data-rd-theme] .rd-scope-meta a { color: var(--rd-link); }
  html[data-rd-theme] :is(.rd-scope-button--secondary, .rd-scope-button--ghost) { background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border); }
  html[data-rd-theme] :is(.rd-scope-button--secondary, .rd-scope-button--ghost, .rd-scope-close):hover:not(:disabled) { background: var(--rd-raised); color: var(--rd-text); border-color: var(--rd-border); }
  html[data-rd-theme] .rd-scope-button--approve { background: var(--rd-success-bg); color: var(--rd-success-text); border-color: currentColor; }
  html[data-rd-theme] .rd-scope-button--reject { background: var(--rd-danger-bg); color: var(--rd-danger-text); border-color: currentColor; }
  html[data-rd-theme] .rd-scope-button--service { background: var(--rd-info-bg); color: var(--rd-info-text); border-color: currentColor; }
  html[data-rd-theme] .rd-scope-button--approve:hover:not(:disabled) { background: var(--rd-success-bg); color: var(--rd-success-text); }
  html[data-rd-theme] .rd-scope-button--reject:hover:not(:disabled) { background: var(--rd-danger-bg); color: var(--rd-danger-text); }
  html[data-rd-theme] :is(.rd-scope-button--service, .rd-scope-meta-chip--service):hover { background: var(--rd-info-bg); color: var(--rd-info-text); }
  html[data-rd-theme] :is(.rd-scope-button, .rd-scope-close, .rd-scope-notification__close) { min-width: 44px; min-height: 44px; }
  html[data-rd-theme] :is(.rd-scope-close, .rd-scope-notification__close) { flex-basis: 44px; color: inherit; }
  html[data-rd-theme] :is(.rd-scope-button, .rd-scope-close, .rd-scope-meta-chip--service, .rd-scope-picker__search input):focus-visible { outline: 2px solid var(--rd-focus); outline-offset: 2px; }
  html[data-rd-theme] :is(.rd-scope-card__header, .rd-scope-links__header, .rd-scope-link-row, .rd-scope-picker-item, .rd-scope-suggestion__actions) { flex-wrap: wrap; }
  html[data-rd-theme] .rd-scope-picker__dialog { margin-top: 1rem; max-height: calc(100vh - 2rem); max-height: calc(100dvh - 2rem); }
  html[data-rd-theme] .rd-scope-picker__header { flex: 0 0 auto; }
  html[data-rd-theme] .rd-scope-picker__search { flex: 0 0 auto; flex-wrap: wrap; }
  html[data-rd-theme] .rd-scope-picker__search input { min-width: 0; min-height: 44px; max-width: 100%; font-size: 1rem; background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border); }

  /* AI Chat is a separate custom stylesheet. Explicit component roles avoid
   * recolouring user bubbles, photographs or green approval / blue send buttons. */
  html[data-rd-theme] .rd-codex-page { background: var(--rd-canvas); }
  html[data-rd-theme] :is(.rd-codex-shell, .rd-codex-header, .rd-codex-brand, .rd-codex-form, .rd-codex-starter, .rd-codex-attachment) { background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border); }
  html[data-rd-theme] :is(.rd-codex-history, .rd-codex-conversation, .rd-codex-messages, .rd-codex-composer, .rd-codex-capabilities) { background: var(--rd-canvas); color: var(--rd-text); border-color: var(--rd-border); }
  html[data-rd-theme] :is(.rd-codex-brand h1, .rd-codex-session-heading > div:first-child, .rd-codex-history__title, .rd-codex-empty-state h2, .rd-codex-form textarea) { color: var(--rd-text); }
  html[data-rd-theme] :is(.rd-codex-brand p, .rd-codex-session-heading > div:last-child, .rd-codex-runtime, .rd-codex-runtime svg, .rd-codex-history__date, .rd-codex-history__empty, .rd-codex-history__loading, .rd-codex-bootstrap, .rd-codex-message__meta, .rd-codex-empty-state, .rd-codex-starter small, .rd-codex-starter > svg, .rd-codex-message-history-loading, .rd-codex-attachment__name, .rd-codex-attachment__size, .rd-codex-attachment__file-icon, .rd-codex-composer__note, .rd-codex-progress, .rd-codex-proposal__subtitle) { color: var(--rd-muted); }
  html[data-rd-theme] .rd-codex-form textarea::placeholder { color: var(--rd-muted); opacity: 1; }
  html[data-rd-theme] :is(.rd-codex-icon-button, .rd-codex-history .rd-codex-icon-button, .rd-codex-history__archive, .rd-codex-new-chat, .rd-codex-attach, .rd-codex-attachment button) { color: var(--rd-muted); border-color: var(--rd-border); }
  html[data-rd-theme] :is(.rd-codex-icon-button, .rd-codex-history .rd-codex-icon-button, .rd-codex-new-chat, .rd-codex-starter, .rd-codex-attach, .rd-codex-attachment button):hover:not(:disabled),
  html[data-rd-theme] .rd-codex-history__item:hover { background: var(--rd-raised); color: var(--rd-text); border-color: var(--rd-border); }
  html[data-rd-theme] :is(.rd-codex-brand__mark, .rd-codex-empty-state__mark, .rd-codex-history__item[aria-current="true"]) { background: var(--rd-info-bg); color: var(--rd-info-text); border-color: var(--rd-focus); }
  html[data-rd-theme] :is(.rd-codex-empty-state__eyebrow, .rd-codex-new-chat svg) { color: var(--rd-link); }
  html[data-rd-theme] .rd-codex-runtime { background: var(--rd-raised); border-color: var(--rd-border); }
  html[data-rd-theme] .rd-codex-status-wrap { background: var(--rd-info-bg); color: var(--rd-info-text); border-color: currentColor; }
  html[data-rd-theme] .rd-codex-status-wrap[data-tone="success"],
  html[data-rd-theme] .rd-codex-proposal__prompt-icon { background: var(--rd-success-bg); color: var(--rd-success-text); }
  html[data-rd-theme] .rd-codex-status-wrap[data-tone="warning"],
  html[data-rd-theme] .rd-codex-resume { background: var(--rd-warning-bg); color: var(--rd-warning-text); border-color: currentColor; }
  html[data-rd-theme] .rd-codex-status-wrap[data-tone="danger"],
  html[data-rd-theme] :is(.rd-codex-alert, .rd-codex-send--stop, .rd-codex-send--stop:hover:not(:disabled), .rd-codex-history__archive:hover) { background: var(--rd-danger-bg); color: var(--rd-danger-text); border-color: currentColor; }
  html[data-rd-theme] .rd-codex-status-wrap[data-tone="neutral"] { background: var(--rd-raised); color: var(--rd-muted); border-color: var(--rd-border); }
  html[data-rd-theme] .rd-codex-message:not(.rd-codex-message--user) .rd-codex-message__bubble { background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border); }
  html[data-rd-theme] .rd-codex-message:not(.rd-codex-message--user) .rd-codex-message__bubble a { color: var(--rd-link); }
  html[data-rd-theme] .rd-codex-message--user .rd-codex-message__bubble a { color: #fff; }
  html[data-rd-theme] :is(.rd-codex-session-heading, .rd-codex-form:focus-within) { border-color: var(--rd-border); }
  html[data-rd-theme] .rd-codex-form:focus-within { border-color: var(--rd-focus); }
  html[data-rd-theme] .rd-codex-attachment__thumbnail { background: var(--rd-raised); }
  html[data-rd-theme] .rd-codex-proposal { background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-warning-text); }
  html[data-rd-theme] .rd-codex-proposal__reject { background: var(--rd-raised); color: var(--rd-text); border-color: var(--rd-border); }
  html[data-rd-theme] .rd-codex-shell :is(button, a, textarea):focus-visible { outline: 2px solid var(--rd-focus); outline-offset: 2px; }
  html[data-rd-theme] :is(.rd-codex-history__list, .rd-codex-messages) { scrollbar-color: var(--rd-border) transparent; }
  html[data-rd-theme] :is(.rd-codex-icon-button, .rd-codex-new-chat, .rd-codex-attach, .rd-codex-send, .rd-codex-proposal button) { min-width: 44px; min-height: 44px; }
  html[data-rd-theme] :is(.rd-codex-attach, .rd-codex-send) { flex-basis: 44px; }
  html[data-rd-theme] .rd-codex-header { min-width: 0; }
  html[data-rd-theme] .rd-codex-proposal { flex-wrap: wrap; }
  @media (pointer: coarse) {
    .rd-codex-history__archive { opacity: 1; width: 44px; height: 44px; }
    .rd-codex-history__item { padding-right: 3rem; }
    .rd-codex-history__date { display: none; }
  }
  @media (max-width: 639px) {
    html[data-rd-theme] .dataTables_wrapper .dataTables_filter { float: none; margin: .5rem 0; text-align: start; }
    html[data-rd-theme] .dataTables_wrapper .dataTables_filter label { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
    html[data-rd-theme] .dataTables_wrapper .dataTables_filter input { flex: 1 1 10rem; min-width: 0; margin-left: 0; font-size: 1rem; }
    html[data-rd-theme] .dataTables_wrapper .dataTables_length select { font-size: 1rem; }
    html[data-rd-page="stability"] .attention-item { grid-template-columns: auto minmax(0, 1fr); }
    html[data-rd-page="stability"] .attention-link { grid-column: 2; justify-self: start; }
    html[data-rd-theme] .rd-codex-form textarea { font-size: 1rem; }
  }
  @media (prefers-reduced-motion: reduce) {
    .rd-codex-shell *, .rd-codex-shell *::before, .rd-codex-shell *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  }

  /* Pages whose own styles keep a light surface while dark mode recolors
   * Tailwind text and native fields. Paper preview (#pdfBody) stays light. */
  html[data-rd-theme="dark"][data-rd-page="projects"] :is(.staff-card, .project-thumb, .project-thumb-placeholder) {
    background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border);
  }
  html[data-rd-theme="dark"][data-rd-page="projects"] :is(.staff-card__name, .staff-card__main) { color: var(--rd-text); }
  html[data-rd-theme="dark"][data-rd-page="projects"] :is(.staff-card__main span, .staff-card__meta, .muted) { color: var(--rd-muted); }
  html[data-rd-theme="dark"][data-rd-page="projects"] .pipe-chip--form { background: var(--rd-info-bg); color: var(--rd-info-text); border-color: var(--rd-focus); }
  html[data-rd-theme="dark"][data-rd-page="projects"] .pipe-chip--test { background: #27264f; color: #ddd6fe; border-color: #a78bfa; }
  html[data-rd-theme="dark"][data-rd-page="projects"] .pipe-chip--stab { background: #153d35; color: #a7f3d0; border-color: #34d399; }
  html[data-rd-theme="dark"][data-rd-page="projects"] .pipe-chip--off { background: var(--rd-raised); color: var(--rd-muted); border-color: var(--rd-border); }
  html[data-rd-theme="dark"][data-rd-page="projects"] :is(.badge--unassigned, .badge--idle) { background: var(--rd-warning-bg); color: var(--rd-warning-text); }
  html[data-rd-theme="dark"][data-rd-page="projects"] .badge--completed { background: var(--rd-success-bg); color: var(--rd-success-text); }
  html[data-rd-theme="dark"][data-rd-page="projects"] .badge--status { background: var(--rd-info-bg); color: var(--rd-info-text); }
  html[data-rd-theme="dark"][data-rd-page="projects"] .badge--notif { background: var(--rd-danger-bg); color: var(--rd-danger-text); border-color: currentColor; }
  html[data-rd-theme="dark"][data-rd-page="projects"] .project-filter-heading:hover { color: var(--rd-link); }

  html[data-rd-theme="dark"][data-rd-page="replace_ingredient"] :is(.table-wrap, #replaceResults) { background: var(--rd-surface); color: var(--rd-text); }
  html[data-rd-theme="dark"][data-rd-page="replace_ingredient"] #replaceResults thead th { background: var(--rd-raised); color: var(--rd-text); border-color: var(--rd-border); }
  html[data-rd-theme="dark"][data-rd-page="replace_ingredient"] #replaceResults tbody td { color: var(--rd-text); border-color: var(--rd-border); }
  html[data-rd-theme="dark"][data-rd-page="replace_ingredient"] #replaceResults tbody tr:nth-child(even) { background: var(--rd-canvas); }
  html[data-rd-theme="dark"][data-rd-page="replace_ingredient"] #replaceResults tbody tr:hover { background: var(--rd-raised); }
  html[data-rd-theme="dark"][data-rd-page="replace_ingredient"] .linked-badge.old { background: var(--rd-raised); color: var(--rd-muted); border-color: var(--rd-border); }

  html[data-rd-theme="dark"][data-rd-page="stability_edit"] {
    --st-ink: var(--rd-text); --st-ink-soft: var(--rd-text); --st-muted: var(--rd-muted); --st-muted-light: var(--rd-muted);
    --st-border: var(--rd-border); --st-panel: var(--rd-surface); --st-panel-soft: var(--rd-canvas); --st-panel-soft-2: var(--rd-raised);
    --st-accent-soft: var(--rd-warning-bg); --st-chip-text: var(--rd-warning-text);
    --st-danger: var(--rd-danger-text); --st-danger-soft: var(--rd-danger-bg);
    --st-warn: var(--rd-warning-text); --st-warn-soft: var(--rd-warning-bg);
  }
  html[data-rd-theme="dark"][data-rd-page="stability_edit"] :is(.panel, .side-card, .chip-btn, .preview-card, .image-card, .preview-card__meta, .image-card__meta, .history-item, .btn-secondary, .qr-card, .form-actions--sticky, .stat, .quickset, .dropzone) {
    background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border);
  }
  html[data-rd-theme="dark"][data-rd-page="stability_edit"] .select2-container--default .select2-selection--single {
    background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border);
  }
  html[data-rd-theme="dark"][data-rd-page="stability_edit"] :is(.field input, .field select, .field textarea, .select2-search--dropdown .select2-search__field) {
    background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border);
  }
  html[data-rd-theme="dark"][data-rd-page="stability_edit"] .field label { color: var(--rd-text); }
  html[data-rd-theme="dark"][data-rd-page="stability_edit"] :is(.panel-title, .side-title, .page-title, .due-strong, .stat__value, .history-item__action) { color: var(--rd-text); }
  html[data-rd-theme="dark"][data-rd-page="stability_edit"] .due-strong--overdue { color: var(--rd-danger-text); }
  html[data-rd-theme="dark"][data-rd-page="stability_edit"] .due-strong--soon { color: var(--rd-warning-text); }
  html[data-rd-theme="dark"][data-rd-page="stability_edit"] .chip-btn--primary { background: var(--rd-warning-bg); color: var(--rd-warning-text); border-color: currentColor; }
  html[data-rd-theme="dark"][data-rd-page="stability_edit"] .image-card__coverpick { background: var(--rd-surface); color: var(--rd-text); }
  html[data-rd-theme="dark"][data-rd-page="stability_edit"] .image-card__coverpick:has(input:checked) { background: var(--rd-warning-bg); color: var(--rd-warning-text); }
  html[data-rd-theme="dark"][data-rd-page="stability"] .qr-code-box,
  html[data-rd-theme="dark"][data-rd-page="stability_edit"] .qr-code-box { background: #fff; color: #0f172a; }
  html[data-rd-theme="dark"][data-rd-page="stability_edit"] :is(.panel-copy, .side-copy, .page-meta__text, .stat__label, .quickset__label, .history-item__top, .history-item__details) { color: var(--rd-muted); }
  html[data-rd-theme="dark"][data-rd-page="stability_edit"] :is(.notice, .badge--amber, .badge--emerald) { background: var(--rd-warning-bg); color: var(--rd-warning-text); border-color: currentColor; }
  html[data-rd-theme="dark"][data-rd-page="stability_edit"] :is(.success, .badge--green) { background: var(--rd-success-bg); color: var(--rd-success-text); border-color: currentColor; }
  html[data-rd-theme="dark"][data-rd-page="stability_edit"] .badge--rose { background: var(--rd-danger-bg); color: var(--rd-danger-text); }
  html[data-rd-theme="dark"][data-rd-page="stability_edit"] .qr-card__head { background: var(--rd-surface); border-color: var(--rd-border); }

  html[data-rd-theme="dark"][data-rd-page="equipment_edit"] :is(.equip-section-title, .img-meta) { color: var(--rd-text); }
  html[data-rd-theme="dark"][data-rd-page="equipment_edit"] :is(.equip-help, .img-handle) { color: var(--rd-muted); }
  html[data-rd-theme="dark"][data-rd-page="equipment_edit"] :is(.equip-dropzone, .equip-preview, .img-card, .sticky-actions) {
    background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border);
  }
  html[data-rd-theme="dark"][data-rd-page="equipment_edit"] .equip-dropzone:hover { background: var(--rd-raised); }
  html[data-rd-theme="dark"] .ctrl-icon-opt { background: var(--rd-surface) !important; color: var(--rd-text); border-color: var(--rd-border); }
  html[data-rd-theme="dark"] .ctrl-icon-opt[aria-pressed="true"] { background: var(--rd-info-bg) !important; color: var(--rd-info-text); border-color: var(--rd-focus); }
  html[data-rd-theme="dark"][data-rd-page="equipment_edit"] .equip-dropzone svg path { stroke: var(--rd-muted); }

  html[data-rd-theme="dark"][data-rd-page="qr_mobile_upload"] :is(.card, .btn-secondary, .uploaded__item) {
    background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border);
  }
  html[data-rd-theme="dark"][data-rd-page="qr_mobile_upload"] :is(h1, .brand) { color: var(--rd-text); }
  html[data-rd-theme="dark"][data-rd-page="qr_mobile_upload"] :is(.copy, .hint, .uploaded__title, .busy) { color: var(--rd-muted); }

  html[data-rd-theme="dark"] .rd-oauth-error-body { background: var(--rd-canvas); color: var(--rd-text); }
  html[data-rd-theme="dark"] .rd-oauth-error-card { background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border); }
  html[data-rd-theme="dark"] .rd-oauth-error-card :is(h1, p) { color: var(--rd-text); }
  html[data-rd-theme="dark"] .rd-oauth-error-card p,
  html[data-rd-theme="dark"] .rd-oauth-error-help { color: var(--rd-muted); }
  html[data-rd-theme="dark"] .rd-oauth-error-help { background: var(--rd-canvas); }
  html[data-rd-theme="dark"] .rd-oauth-error-secondary { background: var(--rd-surface); color: var(--rd-link); border-color: var(--rd-border); }
  html[data-rd-theme="dark"] .rd-oauth-error-secondary:hover { background: var(--rd-raised); }

  html[data-rd-theme="dark"][data-rd-page="formulation"] :is(.sync-queue-tabs button, .sync-queue-button, .sync-queue-footer) {
    background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border);
  }
  html[data-rd-theme="dark"][data-rd-page="formulation"] .sync-queue-tabs button[aria-selected="true"] { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }
  html[data-rd-theme="dark"][data-rd-page="formulation"] :is(.sync-queue-results, .bulk-sync-item__outcomes) { background: var(--rd-canvas); color: var(--rd-text); border-color: var(--rd-border); }
  html[data-rd-theme="dark"][data-rd-page="formulation"] .bulk-sync-toolbar { background: var(--rd-info-bg); color: var(--rd-info-text); border-color: var(--rd-focus); }
  html[data-rd-theme="dark"][data-rd-page="formulation"] .bulk-sync-item summary { color: var(--rd-link); }
  html[data-rd-theme="dark"][data-rd-page="formulation"] .bulk-sync-toolbar__status { color: var(--rd-danger-text); }

  html[data-rd-theme="dark"][data-rd-page="admin_obfuscator"] :is(.obfuscator-modal__dialog, .ob-step, .ob-premix-optimize, .obfuscator-hover__panel) {
    background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border);
  }
  html[data-rd-theme="dark"][data-rd-page="admin_obfuscator"] #obfuscatorSuggestionsTable :is(th, td),
  html[data-rd-theme="dark"][data-rd-page="admin_obfuscator"] :is(.ob-premix-preview__item, .ob-premix-details__item, .ob-premix-optimize__option, .ob-impact-line__value, .obfuscator-hover__value) { color: var(--rd-text); }
  html[data-rd-theme="dark"][data-rd-page="admin_obfuscator"] :is(.ob-premix-preview__id, .ob-impact-line, .ob-step__chev, .obfuscator-dt .dataTables_info, .obfuscator-dt .dataTables_filter label) { color: var(--rd-muted); }
  html[data-rd-theme="dark"][data-rd-page="admin_obfuscator"] #obfuscatorSuggestionsTable thead th { background: var(--rd-raised); }
  html[data-rd-theme="dark"][data-rd-page="admin_obfuscator"] #obfuscatorSuggestionsTable tbody tr:hover,
  html[data-rd-theme="dark"][data-rd-page="admin_obfuscator"] #obfuscatorSuggestionsTable tbody tr.is-selected { background: var(--rd-raised); color: var(--rd-text); }
  html[data-rd-theme="dark"][data-rd-page="admin_obfuscator"] .ob-step--blocked { background: var(--rd-warning-bg); }
  html[data-rd-theme="dark"][data-rd-page="admin_obfuscator"] .obfuscator-dt :is(.dataTables_filter input, .dataTables_length select, .dataTables_paginate .paginate_button) {
    background: var(--rd-surface) !important; color: var(--rd-text) !important; border-color: var(--rd-border) !important;
  }
  html[data-rd-theme="dark"][data-rd-page="admin_obfuscator"] .obfuscator-dt .dataTables_paginate .paginate_button:is(.current, :hover) {
    background: var(--rd-raised) !important; color: var(--rd-text) !important;
  }
  html[data-rd-theme="dark"][data-rd-page="admin_obfuscator"] :is(.ob-premix-details > summary, .ob-premix-optimize > summary) { color: var(--rd-link); }
  html[data-rd-theme="dark"][data-rd-page="admin_obfuscator"] .obfuscator-modal__close { background: var(--rd-surface); color: var(--rd-text); border-color: var(--rd-border); }

  html[data-rd-theme="dark"][data-rd-page="lab_service_view"] .step-box,
  html[data-rd-theme="dark"][data-rd-page="lab_service_view"] .step-badge { background: var(--rd-info-bg); color: var(--rd-info-text); border-color: var(--rd-focus); }
  html[data-rd-theme="dark"][data-rd-page="lab_service_view"] .result-box,
  html[data-rd-theme="dark"][data-rd-page="lab_service_view"] .result-badge { background: var(--rd-success-bg); color: var(--rd-success-text); border-color: currentColor; }
  html[data-rd-theme="dark"] :is([data-rd-page="lab_service"], [data-rd-page="lab_service_view"]) .ck.ck-editor__main > .ck-editor__editable { background: #fff; color: #0f172a; }

  @media (max-width: 639px) {
    html[data-rd-theme="dark"][data-rd-page="project_tester"] .sticky-bar {
      background: rgb(var(--rd-surface-rgb) / .95); color: var(--rd-text); border-top-color: var(--rd-border);
    }
  }

  html[data-rd-theme="dark"] :is(#pdfExportModal, #duplicateFormulationModal, #produceOrderModal, #qrAttachModal, #attachPickerModal, #noteMediaPickerModal, #noteQrUploadModal, #ctrlTypeModal, #labServicePickerModal) :not(#pdfBody, #pdfBody *):is([style*="background:#fff;"], [style*="background:#fff "], [style*="background: #fff;"], [style*="background: #fff "], [style*="background:#ffffff"], [style*="background: #ffffff"]) {
    background-color: var(--rd-surface) !important; color: var(--rd-text);
  }
  html[data-rd-theme="dark"] :is(#pdfExportModal, #duplicateFormulationModal, #produceOrderModal, #qrAttachModal, #attachPickerModal, #noteMediaPickerModal, #noteQrUploadModal, #ctrlTypeModal, #labServicePickerModal) :not(#pdfBody, #pdfBody *):is([style*="background:#f8fafc"], [style*="background: #f8fafc"], [style*="background:#f1f5f9"], [style*="background: #f1f5f9"]) {
    background-color: var(--rd-canvas) !important; color: var(--rd-text);
  }
  html[data-rd-theme="dark"] :is(#pdfExportModal, #duplicateFormulationModal, #produceOrderModal, #qrAttachModal, #attachPickerModal, #noteMediaPickerModal, #noteQrUploadModal, #ctrlTypeModal, #labServicePickerModal) :not(#pdfBody, #pdfBody *):is([style*="color:#0f172a"], [style*="color: #0f172a"], [style*="color:#334155"], [style*="color: #334155"]) {
    color: var(--rd-text) !important;
  }
  html[data-rd-theme="dark"] #pdfBody { background-color: #ffffff !important; color: #0f172a !important; }
}
