/* Screen-only, neutral dark-mode typography. Semantic status/action colors,
   document paper, light mode, dimensions and application behavior stay intact. */
@media screen {
  html[data-theme="dark"] body.bb-app-active {
    --dark-text-primary: #ededed;
    --dark-text-secondary: #d4d4d4;
    --dark-text-muted: #b8b8b8;
    --dark-text-disabled: #969696;
    --ink: var(--dark-text-primary);
    --ink2: var(--dark-text-secondary);
    --ink3: var(--dark-text-muted);
    --muted: var(--dark-text-muted);
    --pro-ink: var(--dark-text-primary);
    --pro-ink-soft: var(--dark-text-secondary);
    --pro-muted: var(--dark-text-muted);
    --pro-muted-soft: var(--dark-text-muted);
    --human-ink: var(--dark-text-primary);
    --human-copy: var(--dark-text-secondary);
    --human-muted: var(--dark-text-muted);
    --ui-ink: var(--dark-text-primary);
    --ui-copy: var(--dark-text-secondary);
    --ui-muted: var(--dark-text-muted);
    --ui-faint: var(--dark-text-muted);
    --phone-ink: var(--dark-text-primary);
    --phone-muted: var(--dark-text-muted);
    --mobile-app-muted: var(--dark-text-muted);
    --signature-muted: var(--dark-text-muted);
    --legacy-dark-copy: var(--dark-text-primary);
    --legacy-dark-muted: var(--dark-text-secondary);
    color: var(--dark-text-primary);
  }

  /* These workspaces define their own tokens, so update at the same scope. */
  html[data-theme="dark"] body.bb-app-active #app-shell {
    --app-heading: var(--dark-text-primary);
    --app-copy: var(--dark-text-secondary);
    --app-subtle: var(--dark-text-muted);
  }
  html[data-theme="dark"] body.bb-app-active #settings,
  html[data-theme="dark"] body.bb-app-active #settings .stg-hub {
    --stg-ink: var(--dark-text-primary);
    --stg-copy: var(--dark-text-secondary);
    --stg-muted: var(--dark-text-muted);
    --hub-ink: var(--dark-text-primary);
    --hub-copy: var(--dark-text-secondary);
    --hub-muted: var(--dark-text-muted);
  }
  html[data-theme="dark"] body.bb-app-active #reports {
    --reports-ink: var(--dark-text-primary);
    --reports-copy: var(--dark-text-secondary);
    --reports-muted: var(--dark-text-muted);
    --reports-faint: var(--dark-text-muted);
    --report-muted: var(--dark-text-muted);
  }
  html[data-theme="dark"] body.bb-app-active #journal {
    --journal-ink: var(--dark-text-primary);
    --journal-muted: var(--dark-text-secondary);
    --journal-faint: var(--dark-text-muted);
  }
  html[data-theme="dark"] body.bb-app-active #pos .pos-workspace {
    --pw-ink: var(--dark-text-primary);
    --pw-muted: var(--dark-text-muted);
  }
  html[data-theme="dark"] body.bb-app-active :is(#customers, #vendors) {
    --customer-muted: var(--dark-text-muted);
  }
  html[data-theme="dark"] body.bb-app-active #purchaseorders .po-line-items {
    --po-line-muted: var(--dark-text-muted);
  }
  html[data-theme="dark"] body.bb-app-active[data-industry="logistics"] #projects {
    --logistics-ink: var(--dark-text-primary);
    --logistics-muted: var(--dark-text-muted);
  }

  /* Override legacy literal foregrounds by text role, never by wildcard.
     Exclusions also apply to descendants, protecting white document previews. */
  html[data-theme="dark"] body.bb-app-active :is(#app-shell, .modal, .modal-overlay, [role="dialog"], #advance-modal, #payroll-run-modal)
  :is(h1, h2, h3, .page-title, .panel-title, .section-title, .item-section-hd-title):not(:where(.invoice-preview-paper, .invoice-preview-paper *, .customer-statement-pdf, .customer-statement-pdf *, .bbd-document, .bbd-document *, .bbd-report, .bbd-report *, .bbd-pdf-export-source *)) {
    color: var(--dark-text-primary) !important;
  }

  html[data-theme="dark"] body.bb-app-active :is(#app-shell, .modal, .modal-overlay, [role="dialog"], #advance-modal, #payroll-run-modal)
  :is(label, legend, th, .field-label, .form-label, .bill-inline-label, .bill-ctrl-label, .po-warehouse-label, .stg-nav-group-label, .inv-kpi-label):not(:where(.invoice-preview-paper *, .customer-statement-pdf *, .bbd-document *, .bbd-report *, .bbd-pdf-export-source *, .error, .text-danger, .required, .badge *, .status-badge *)) {
    color: var(--dark-text-secondary) !important;
  }

  html[data-theme="dark"] body.bb-app-active :is(#app-shell, .modal, .modal-overlay, [role="dialog"], #advance-modal, #payroll-run-modal)
  :is(input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="color"]), select, textarea):not(:where(.invoice-preview-paper *, .customer-statement-pdf *, .bbd-document *, .bbd-report *, .bbd-pdf-export-source *)) {
    color: var(--dark-text-primary) !important;
  }

  html[data-theme="dark"] body.bb-app-active :is(#app-shell, .modal, .modal-overlay, [role="dialog"], #advance-modal, #payroll-run-modal)
  :is(input, textarea):not(:where(.invoice-preview-paper *, .customer-statement-pdf *, .bbd-document *, .bbd-report *, .bbd-pdf-export-source *))::placeholder {
    color: var(--dark-text-muted) !important;
    opacity: 1;
  }

  html[data-theme="dark"] body.bb-app-active #app-shell :is(
    .eyebrow, .mini-stat-label, .sidebar-account-label, .topbar-search-shortcut,
    .stg-sidebar-copy, .stg-content-desc, .stg-avatar-sub, .stg-hint, .stg-optional,
    .stg-org-brand-use, .item-section-hd-note,
    .quote-help-text, .customer-file-note, .last-saved-note--empty,
    .bill-notes-hint, .bill-attach-hint, .bill-discount-pct,
    .rpt-cat-count, .rpt-group-count, .inv-list-sub, .inv-kpi-sub, .pr-empty-sub,
    .bk-date-filter, .bk-legend-item, .bk-active-count, .bk-account-card-sub,
    .bk-account-card-label, .pos-empty-catalog, .empty-state p, .empty-state small
  ) { color: var(--dark-text-muted) !important; }

  html[data-theme="dark"] body.bb-app-active #app-shell :is(
    .nav-item:not(.active), .nav-subitem:not(.active), .nav-group-label,
    .item-type-btn:not(.active), .pr-tab:not(.active), .customer-tab-button:not(.active)
  ) { color: var(--dark-text-secondary) !important; }

  /* Older workspaces include literal text colors on nested copy elements. */
  html[data-theme="dark"] body.bb-app-active #app-shell :is(
    .sidebar-mini-grid > span, .sidebar-mini-grid > b, .dash-greeting,
    .wh-kpi-val, .empty-title, .re-tab > b, .health-suite-status > span,
    .coa-account-type > span, .line-item-copy > span
  ) { color: var(--dark-text-secondary) !important; }

  html[data-theme="dark"] body.bb-app-active #app-shell :is(
    .table-empty-state p, .section-header p, .dashboard-setup-copy small,
    .health-suite-eyebrow, .health-suite-title p, .health-kpi-copy > span,
    .health-kpi-copy small, .health-card-kicker, .fx-kpi-label, .fx-kpi-sub,
    .re-page-header p, .re-tab > small, .empty-copy, .wh-header-sub, .wh-kpi-lbl,
    .tr-date-field > span, .tr-date-filter-heading small, .bk-reconcile-card > span,
    .bk-reconcile-card small, .landed-cost-heading p, .signature-signer-field > span,
    .coa-register-heading p, .coa-register-counts > span, .coa-amount-dash,
    .re-field-hint, .re-form-divider small, .fa-field-hint, .pmt-list-note,
    .appear-theme-sub
  ) { color: var(--dark-text-muted) !important; }

  html[data-theme="dark"] body.bb-app-active #app-shell #settings :is(
    .stg-detail-search-launch kbd, .stg-hub-search kbd, .stg-hub-group-heading > span,
    .stg-org-card-titleblock small, .stg-org-section-heading p, .stg-org-save-note small
  ) { color: var(--dark-text-muted) !important; }
  html[data-theme="dark"] body.bb-app-active #app-shell #settings .stg-breadcrumb-sep {
    color: var(--dark-text-disabled) !important;
  }
  /* This existing record chip has a white fill, even in dark mode. Give it
     neutral dark ink instead of white-on-white text; do not change its fill. */
  html[data-theme="dark"] body.bb-app-active #app-shell #settings .stg-org-record-label {
    color: #404040 !important;
  }
  html[data-theme="dark"] body.bb-app-active #app-shell :is(#po-create-panel, #inv-create-panel, #so-create-panel, #quote-create-panel, #retainer-create-panel) .field:has(> .signature-pad-wrap) > .quote-help-text,
  html[data-theme="dark"] body.bb-app-active #app-shell :is(#po-create-panel, #inv-create-panel, #so-create-panel, #quote-create-panel, #retainer-create-panel) .field:has(> .signature-pad-wrap) > label span:not([class]) {
    color: var(--dark-text-muted) !important;
  }
  html[data-theme="dark"] body.bb-app-active #app-shell #accounts .coa-register-table th {
    color: var(--dark-text-secondary) !important;
  }
  html[data-theme="dark"] body.bb-app-active #app-shell #students .edu-tab b {
    color: var(--dark-text-secondary) !important;
  }
  html[data-theme="dark"] body.bb-app-active #app-shell #pos .pos-catalog-help kbd {
    color: var(--dark-text-muted) !important;
  }
  html[data-theme="dark"] body.bb-app-active #app-shell #forex .fx-rate-board > div:not([class]) > div:last-child {
    color: var(--dark-text-muted) !important;
  }
}
