/* The preference affects the workspace, never public pages or printed documents. */
.workspace-theme-switch { position:relative; display:inline-flex; align-items:center; flex:0 0 auto; gap:7px; min-height:44px; margin:0; color:#53615c; font-size:12px; font-weight:600; cursor:pointer; white-space:nowrap; }
.workspace-theme-switch input { position:absolute; left:29px; width:38px; height:24px; margin:0; opacity:0; cursor:pointer; }
.workspace-theme-track { position:relative; flex:0 0 38px; width:38px; height:22px; border:1px solid #87968f; border-radius:12px; background:#e6ece8; pointer-events:none; }
.workspace-theme-track::after { content:""; position:absolute; top:3px; left:3px; width:14px; height:14px; border-radius:50%; background:#52625a; }
.workspace-theme-switch input:checked + .workspace-theme-track { border-color:#bb84c5; background:#643182; }
.workspace-theme-switch input:checked + .workspace-theme-track::after { left:19px; background:#fff; }
.workspace-theme-switch input:focus-visible + .workspace-theme-track { outline:3px solid #a66ab2; outline-offset:3px; }
.login-panel > .workspace-theme-switch { display:flex; width:max-content; margin:18px auto 0; }
body[data-experience="workspace"] .global-search { flex:1; min-width:0; width:auto; max-width:650px; }
body[data-experience="workspace"] .top-actions { flex:0 0 auto; }
@media (max-width:1300px) { body[data-experience="workspace"] .connection { display:none; } }
@media (max-width:680px) {
  body[data-experience="workspace"] .topbar { gap:8px; padding-inline:12px; }
  body[data-experience="workspace"] .dashboard-grid { grid-template-columns:minmax(0,1fr); }
  body[data-experience="workspace"] .dashboard-grid>div { min-width:0; }
  body[data-experience="workspace"] .dashboard-grid .panel { overflow:auto; }
  .workspace-theme-switch { gap:4px; font-size:11px; }
  .workspace-theme-switch input { left:25px; }
}
@media print { .workspace-theme-switch { display:none!important; } }

/* Screen-only tokens leave light mode and print output on the original palette. */
@media screen {
  html[data-workspace-theme="dark"] { color-scheme:dark; background:#17191b; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] {
    --surface:#222628; --soft:#2b3032; --line:#42494c; --muted:#acb8b6;
    --sidebar:#202426; --sidebar-muted:#acb8b6; --danger:#f19b96; --warning:#e9c27b; --success:#99d5b3;
    --baumann-ink:#ecf0ee; --baumann-muted:#acb8b6; --baumann-line:#42494c;
    --theme-text:#ecf0ee; --theme-muted:#acb8b6; --theme-accent:#ddb0e6;
    --theme-soft:#303536; --theme-input:#1b1f21; --theme-tint:#372b3d;
    color:var(--theme-text); background:#17191b;
  }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(
    .sidebar,.topbar,.panel,.metric,.table-toolbar,.table-wrap,.record-workspace,.record-workspace-head,.record-workspace-foot,
    .case-tabs,[data-case-section],[data-preneed-section],.modal,.login-panel,.notification-panel,.global-search-results,
    .kanban-card,.kanban-case-stage,.action-item,.mail-layout,.mail-item,.calendar-week,.document-gallery-card,
    .service-line-block,.service-group-detail,.certificate-order,.record-note-entry,.signature-editor,.designer-sidebar,
    .case-document-list,.case-template-picker,.case-transfer-card,.case-transfer-empty,.flower-order-card,.flower-catalog,
    .flower-order-overview,.archive-print-group,.archive-print-row,.dunning-row,.dunning-overview>div,.monitoring-check,
    .billing-tariff-grid>article,.vehicle-damage-row,.placeholder-list button
  ) { background:var(--surface); color:var(--theme-text); border-color:var(--line); box-shadow:none; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(
    .branch-switcher,.user-card,.panel-head,.modal-foot,.experience-jump,.case-summary,.case-health,.preneed-amount,
    .record-section-lead,.case-data-sheet-toolbar,.case-care-editor,.case-care-editor>header,.record-notes,
    .certificate-order>header,.certificate-order-summary,.service-line-block>header,.service-group-detail>header,
    .service-line-assignment,.billing-line-row,.billing-editor-summary,.billing-summary,.billing-tariff-import,
    .billing-tariff-grid>article>header,.billing-tariff-grid>article>footer,.billing-existing-invoice,
    .flower-order-card>header,.flower-order-schedule,.flower-schedule-head,.flower-catalog>header,.flower-catalog>footer,
    .flower-order-notes,.flower-ribbon-config,.flower-line-ribbon,.archive-print-group>header,
    .scanner-inbox-panel,.kanban-column,.kanban-stage-reason,.mail-folders,.document-gallery,
    .calendar-time-axis,.calendar-week-toolbar,.calendar-date-search-field,.signature-editor>header,
    .signature-field-note,.signature-security-note,.designer-template-context,.designer-statusbar,.placeholder-search,
    .case-template-group>header,.case-transfer-office,.vehicle-device-assign,.vehicle-damage-metrics,.segmented-control,
    .monitoring-hero,.family-admin-response,.document-scope-tabs,.mourning-print-preview-pane,.mourning-print-preview-pane>header
  ) { background:var(--theme-soft); color:var(--theme-text); border-color:var(--line); }

  /* Explicit UI text selectors avoid recoloring PDF/template content. */
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(
    .page-head,.panel-head,.metric,.case-summary,.case-health,.record-workspace-head,.record-section-lead,
    .case-data-sheet-toolbar,.record-notes,.certificate-order,.service-line-block,.service-group-detail,
    .billing-editor-summary,.billing-tariff-grid,.flower-order-card,.flower-order-schedule,.flower-catalog,
    .dunning-overview,.monitoring-hero,.monitoring-check,.case-transfer-card,.login-brand,.login-panel,.signature-editor>header,
    .vehicle-damage-row,.scanner-inbox-panel
  ) :is(h1,h2,h3,h4,strong,p,dt,dd) { color:var(--theme-text); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(
    .brand strong,.brand span,.nav-label,.nav-button,.nav-subitem,.user-card div span,.branch-switcher>span,
    .case-summary-meta>span,.case-summary-meta svg,.case-health span,.record-section-lead-facts span,.record-note-entry header,
    .record-note-entry header strong,.record-note-entry p,.form-section,.field label,.calendar-agenda-main,
    .calendar-day-head span,.calendar-time-axis span,.folder-button,.record-owner,.workspace-theme-switch,
    .service-line-assignment>span,.service-line-assignment>label,.calendar-date-search,.billing-line-row>small
  ) { color:var(--theme-text); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(
    .panel small,.metric small,.record-workspace small,.modal small,.login-panel small,.experience-search output,
    .record-note-entry header,.record-section-lead-facts span,.case-health span,.kanban-meta,.placeholder-list code,
    .nav-label,.brand span,.user-card div span,.branch-switcher>span
  ):not(:where(.mourning-print-sheet *,.pdf-stage *,.signature-preview *,.mourning-rich-editor *)) { color:var(--theme-muted); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.record-section-lead-copy>small,.case-data-sheet-toolbar small) { color:var(--theme-accent)!important; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(
    .record-number,.text-link,.document-mark,.field-service-label,.explicit-unknown-option,.placeholder-group h4,
    .case-document-group-icon,.case-data-sheet-icon,.case-summary h3,.case-health strong,.certificate-order output,
    .service-group-detail>header b,.billing-tariff-fees b,.billing-tariff-fees strong,.billing-tariff-grid footer strong
  ) { color:var(--theme-accent); }

  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(input,select,textarea):not(:where([type="checkbox"],[type="radio"],[type="range"],[type="color"],.mourning-print-sheet *,.pdf-stage *)) {
    color:var(--theme-text); background:var(--theme-input); border-color:#62716c; color-scheme:dark;
  }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(input,textarea)::placeholder { color:#9daaa5; opacity:1; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(input,select,textarea):disabled { color:#a1aaa7; background:#303536; border-color:#48514e; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(input,select,textarea):focus-visible { outline:2px solid #cc92d7; outline-offset:2px; box-shadow:none; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is([type="checkbox"],[type="radio"]) { accent-color:#ad6cba; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.button:not(.primary),.icon-button,.branch-switcher button,.input-with-unit>span,.segmented-control button) {
    background:var(--theme-soft); color:var(--theme-text); border-color:#59645f;
  }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] .button.primary { color:#fff; background:#643182; border-color:#a065ab; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] .button.primary:hover { background:#894394; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] .button.danger { color:#f5aba5; border-color:#a56863; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.nav-button:hover,.button:not(.primary):hover,.icon-button:hover,.action-item:hover,.mail-item:hover,.mail-item.active,.placeholder-list button:hover,.archive-print-row:hover) { background:#3b4143; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.nav-button.active,.tab.active,.folder-button.active,.segmented-control button.active,.calendar-day-head.today,.calendar-day-head.selected-date) {
    background:var(--theme-tint); color:var(--theme-accent); border-color:#906297;
  }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] .case-tabs .tab { color:var(--theme-muted); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] .case-tabs .tab.active { background:#643182; color:#fff; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.nav-button .badge,.tab span,.record-note-entry header em,.avatar,.user-card .avatar,.record-note-mark,.action-icon,.folder-button b) { background:#403347; color:#e4c5eb; border-color:#705476; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] .brand { border-color:var(--line); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] .record-workspace .form-section::after { background:var(--line); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.record-note-entry,.activity-list li,.action-item,.certificate-order-item,.record-section-lead-facts,.record-section-lead-facts>div,.calendar-day-head,.dunning-list) { border-color:var(--line); }

  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(table,tbody tr):not(:where(.mourning-print-sheet *,.pdf-stage *)) { background:var(--surface); color:var(--theme-text); border-color:var(--line); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] th:not(:where(.mourning-print-sheet *,.pdf-stage *)) { background:var(--theme-soft); color:#c5d4ce; border-color:var(--line); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] td:not(:where(.mourning-print-sheet *,.pdf-stage *)) { border-color:var(--line); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] tbody tr:nth-child(even):not(:where(.mourning-print-sheet *,.pdf-stage *)) { background:#272c2e; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] tbody tr:hover:not(:where(.mourning-print-sheet *,.pdf-stage *)) { background:#3b3040; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.status,.status.purple,[data-record-status] .status,.kanban-automation-state.automatic) { color:#ebc5f1; background:#49314f; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.status.success,[data-record-status="Abgeschlossen"] .status,.branch-chip,.family-admin-response,.flower-order-document,.case-template-compatibility) { background:#223d32; color:#a6dfbe; border-color:#466c59; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.status.warning,.flower-order-document.stale,.flower-line-ribbon,.flower-ribbon-config,.burial-guidance>div,.case-transfer-safety,.monitoring-hero.warning) { background:#403728; color:#efcf92; border-color:#7b6745; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.status.danger,.monitoring-hero.error) { background:#4b2e2d; color:#f6b9b2; border-color:#875851; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.status.neutral,.kanban-automation-state.manual) { background:#3c4444; color:#d3ded8; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] .calendar-day-column { border-color:var(--line); background-image:repeating-linear-gradient(to bottom,transparent 0,transparent calc(var(--calendar-hour-height) / 2 - 1px),#38403e calc(var(--calendar-hour-height) / 2 - 1px),#38403e calc(var(--calendar-hour-height) / 2)); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.calendar-day-column.today,.calendar-day-column.selected-date) { background-color:#2f2834; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] .login-screen { background:#17191b; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.pdf-workbench,.pdf-viewer-body,.pdf-viewer-foot,.pdf-viewer-loading) { background:#262a2d; color:var(--theme-text); border-color:var(--line); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] .pdf-viewer-head .button { background:#503757; border-color:#96709c; color:#fff; }

  /* Module-specific lists and editors share the same surface hierarchy. */
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(
    .quick-action,.quick-contact-dialog,.admin-metrics,.admin-tabs,.approval-safeguards,.panel-actions,.document-bulk-toolbar,
    .quality-overview,.work-queue-overview,.work-queue-content,.work-queue-list,.work-queue-row,.payment-journal,.fleet-card,
    .master-choice-grid,.civil-register-evidence-panel,.registry-data-sheet-panel,.death-notice-progress,
    .death-notice-columns>section,.international-evidence-panel,.international-evidence-row,.urn-arrival-panel,
    .case-transfer-overview,.case-event-editor,.bereavement-notification,.flower-order-empty,.custody-overview,.custody-list,
    .custody-release-history,.mourning-print-overview,.mourning-print-list,.deregistration-overview,.deregistration-list,
    .music-plan-notes,.contract-dashboard,.contract-line-group,.contract-confirmations label,.contract-history article,
    .case-check,.case-billing-overview,.case-billing-document,.case-access-overview,.case-access-users label,.portal-option,
    .memorial-admin-section,.memorial-public-toggle,.dunning-overview,.preneed-overview,.finance-overview
  ) { background:var(--surface); color:var(--theme-text); border-color:var(--line); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(
    .work-queue-group-head,.quick-contact-dialog>header,.quick-contact-dialog>footer,.payment-journal>header,
    .fleet-card-image,.fleet-card-app,.fleet-card-damages,.death-time-fields,.death-administrative-fields,
    .institution-preview,.civil-register-evidence-panel>header,.registry-data-sheet-panel>header,.registry-data-sheet-panel>footer,
    .death-notice-columns>section>header,.international-evidence-summary,.death-notice-legal,
    .urn-arrival-panel>header,.urn-arrival-panel>footer,.crematorium-case-fields,.grave-location-fields,.case-event-editor>header,
    .case-event-decoration-bar,.bereavement-notification>header,.contract-contact-section>header,.contract-line-group>header,
    .contract-review-note,.contract-readonly-grid section,.case-billing-document>header,.case-billing-document>footer,
    .operation-note,.case-access-action,.memorial-admin-section>header,.memorial-portrait-editor,.memorial-portrait-preview,
    .case-check-group>h3,.scanner-inbox-main code,.case-event-editor output,.global-search kbd,
    .international-evidence-panel>header,.international-evidence-row>header,.vehicle-deadline,.toggle-row
  ) { background:var(--theme-soft); color:var(--theme-text); border-color:var(--line); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(
    .work-queue-dashboard-alert,.quality-dashboard-alert,.contract-prerequisite
  ) { background:#403728; color:#efcf92; border-color:#7b6745; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.quick-action:hover,.work-queue-row:hover,.master-choice-grid label:hover,.contract-contact-choice:hover) { background:#3b3040; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(
    .record-edit-section,.panel,.modal,.quick-contact-dialog,.admin-metrics,.work-queue-overview,.work-queue-list,
    .quality-overview,.approval-safeguards,.fleet-card,.payment-journal,.contract-history,.case-checklist
  ) :is(h1,h2,h3,h4,strong,p,dt,dd,label):not(:where(.mourning-print-sheet *,.pdf-stage *,.signature-preview *,.mourning-rich-editor *)) { color:var(--theme-text); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(
    .connection,.civil-register-evidence-row span,.contract-line-group>div>span,.contract-line-group>header span,
    .record-workspace :is(.custody-overview,.case-billing-overview,.memorial-admin-facts,.deregistration-overview,.case-closure-overview,.case-access-overview,.checklist-facts,.billing-editor-summary,.billing-summary,.preneed-overview,.finance-overview) span
  ) { color:var(--theme-muted); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.quick-action svg,.calendar-agenda-main time strong,.document-mark,.case-data-sheet-icon,.case-document-group-icon) { color:var(--theme-accent); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.metric,.work-queue-overview>div) { border-left-color:var(--metric-color,var(--line)); }
  html[data-workspace-theme="dark"] :is(#content,#modal-root) :is(h1,h2,h3,h4,strong,p,legend,dt,dd,label):not(:where(.mourning-print-sheet *,.pdf-stage *,.signature-preview *,.mourning-rich-editor *,.mail-body *,.status *,.text-danger,.text-warning)) { color:var(--theme-text); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] .toggle-row { color:var(--theme-text)!important; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(
    .tab:not(.active),.document-bulk-toolbar,.document-bulk-toolbar span,.work-queue-dashboard-alert small,
    .approval-safeguards code,.document-bulk-preview small,.scanner-inbox-action small,.mail-folder-heading,
    .ticket-number,.fleet-card b,.registry-data-sheet-panel p,.registry-data-sheet-panel span,.registry-data-sheet-panel small,
    .international-evidence-summary span,.urn-arrival-panel>header span,.mourning-print-row-main span,
    .deregistration-main span,.deregistration-document span,.contract-dashboard span,.case-billing-document>header span,
    .case-billing-document td,.memorial-admin-section>header span,.memorial-portrait-controls output
  ) { color:var(--theme-muted); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] .portal-access-state.active { background:#223d32; color:#a6dfbe; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.data-table code,.quality-table td:nth-child(4),.scanner-inbox-main span,.scanner-inbox-stats small,.scanner-inbox-stats b) { color:var(--theme-muted); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] .fleet-card-app>b { background:#403347; color:#e4c5eb; }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.mourning-placeholder-picker,.mourning-rich-toolbar,.mourning-print-page-label,.mourning-print-motif-option) { background:var(--theme-soft); color:var(--theme-text); border-color:var(--line); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.mourning-rich-toolbar button,.mourning-print-color output) { color:var(--theme-text); }
  html[data-workspace-theme="dark"] body[data-experience="workspace"] .mourning-rich-toolbar button:hover { background:#49314f; }

  /* These are document surfaces, not application controls. Keep their own artwork. */
  html[data-workspace-theme="dark"] body[data-experience="workspace"] :is(.mourning-print-sheet,.mourning-rich-editor,.pdf-stage,.signature-preview,#signature-canvas) {
    color-scheme:light; --muted:#69777d; --line:#ded8df; --surface:#fff; --soft:#f5f7f8;
  }
}
