/* =============================================================================
   Dark appearance layer  —  html[data-appearance="dark"]

   Loaded LAST from App.razor so it can win over dynamics365.css, cmf-shared.css,
   ui-form-themes.css, d365-editable-grid.css and the per-page scoped bundles.

   Why this file exists
   --------------------
   Light / Dark / System used to only re-declare the --d365-* shell tokens. Everything
   above the shell still painted itself from light values: the form tokens (--ui-*) are
   written inline on <html> by ui-theme.js from the admin Form Theme settings, and the
   form / grid sheets (cmf-*, d365-input-grid, editable grid, tabs, cards, popups)
   hard-code #fff / #323130 / #8b7355. The result was brown labels on a near-black page
   and dark text on dark fields.

   Two rules for maintaining this file
   -----------------------------------
   1. Tokens the admin theme also sets inline (--ui-*, --d365-link) MUST be marked
      !important — an inline custom-property declaration outranks a normal one.
   2. Everything else is normal-weight but scoped through html[data-appearance="dark"],
      which gives it the extra attribute specificity needed to beat the base sheets.
      !important is used on paint (background/color/border) where a scoped .razor.css
      rule of unknown specificity would otherwise win.
   ============================================================================= */

/* Generated companion sheet: every hard-coded light literal in the page-scoped
   component CSS (quotation, CRO, comparative, tariff, audit log, multi-select,
   trial balance, tracker, ...) answered with a --dk token. Imported here so the
   dark layer stays a single <link> and the import still cascades last, above all
   other sheets. Its rules land before this file's own rules, so the curated
   sections below always win where both speak. */
@import url("appearance-dark-legacy.css?v=5");

/* ── 1. Tokens ─────────────────────────────────────────────────────────────── */
html[data-appearance="dark"] {
    color-scheme: dark;

    /* Raw dark surfaces, so every rule below references one place. */
    --dk-0: #141414;   /* page */
    --dk-1: #1b1a19;   /* card / panel */
    --dk-2: #232221;   /* raised: toolbars, table headers */
    --dk-3: #2b2a29;   /* hover */
    --dk-4: #33322f;   /* selected row */
    --dk-border: #3b3a39;
    --dk-border-strong: #52514f;
    --dk-text: #f3f2f1;
    --dk-text-2: #c8c6c4;
    --dk-text-3: #a19f9d;
    --dk-accent-text: #7cb3ff;
    --dk-accent-soft: rgba(56, 139, 253, 0.22);
    --dk-danger-soft: rgba(248, 81, 73, 0.18);
    --dk-warn-soft: rgba(210, 153, 34, 0.2);
    --dk-success-soft: rgba(63, 185, 80, 0.18);
    --dk-system-bg: #3a3315;
    --dk-system-text: #ffd76e;
    --dk-system-border: #6b5c1f;

    /* Form tokens — ui-theme.js sets these inline, so !important is mandatory. */
    --ui-label-color: #c8c6c4 !important;
    --ui-field-text-color: #f3f2f1 !important;
    --ui-field-border-color: #52514f !important;
    --ui-field-bg-color: transparent !important;
    --ui-grid-header-bg: #232221 !important;
    --ui-grid-header-text: #f3f2f1 !important;
    --ui-grid-row-hover: #33322f !important;
    --ui-grid-border-color: #3b3a39 !important;
    --ui-field-focus-glow: 0 3px 10px -8px rgba(124, 179, 255, 0.55) !important;
    --ui-accent-color: #7cb3ff !important;

    /* Shell tokens the App.razor pre-paint script / ui-theme.js also write inline. */
    --d365-link: #7cb3ff !important;
    --d365-primary-lighter: #1e3552 !important;
    --d365-form-heading-color: #f3f2f1 !important;
    /* Page background comes straight from the admin Form Theme picker (inline), so it needs
       !important or every dark page would keep painting #faf9f8. */
    --d365-bg-page: #141414 !important;

    /* cmf-* tokens used by a few newer components. */
    --cmf-field-bg: #232221;
    --cmf-field-text: #f3f2f1;
    --cmf-label-color: #c8c6c4;
}

html[data-appearance="dark"] body {
    background-color: var(--dk-0);
    color: var(--dk-text);
}

html[data-appearance="dark"] ::selection {
    background: var(--dk-accent-soft);
    color: var(--dk-text);
}

/* ── 2. Shell: content area, command bar, page heading ─────────────────────── */
html[data-appearance="dark"] .d365-main-content,
html[data-appearance="dark"] .d365-page {
    background-color: var(--dk-0);
}

html[data-appearance="dark"] .d365-command-bar {
    background-color: var(--dk-1) !important;
    border-bottom-color: var(--dk-border) !important;
}

/* Page title / subtitle / breadcrumb block are hard-coded navy on the light sheet. */
html[data-appearance="dark"] .d365-page-heading-title,
html[data-appearance="dark"] .d365-page-heading-title-icon {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-page-heading-subtitle,
html[data-appearance="dark"] .d365-page-heading-action-label {
    color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .d365-page-heading-action-btn {
    color: var(--dk-text-2) !important;
    border-color: var(--dk-border) !important;
    background: var(--dk-2) !important;
}

html[data-appearance="dark"] .d365-page-heading-action-btn:hover {
    color: var(--dk-text) !important;
    background: var(--dk-3) !important;
}

html[data-appearance="dark"] .d365-page-heading-action-divider {
    background: var(--dk-border) !important;
}

html[data-appearance="dark"] .d365-page-heading-dropdown,
html[data-appearance="dark"] .d365-header-recent-dropdown,
html[data-appearance="dark"] .d365-header-user-menu {
    background: var(--dk-2) !important;
    border-color: var(--dk-border) !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55) !important;
}

/* Sticky breadcrumb bar (store / terminal / accounts sub-headers). */
html[data-appearance="dark"] .d365-header-breadcrumb-bar {
    background: linear-gradient(180deg, var(--dk-1) 0%, var(--dk-0) 100%) !important;
    border-bottom-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .d365-header-breadcrumb-bar:not(.is-store) .d365-header-breadcrumb-link,
html[data-appearance="dark"] .d365-header-breadcrumb-bar:not(.is-store) .d365-header-breadcrumb-text,
html[data-appearance="dark"] .d365-header-breadcrumb-bar:not(.is-store) .d365-header-breadcrumb-current,
html[data-appearance="dark"] .d365-header-breadcrumb-bar:not(.is-store) .d365-header-breadcrumb-root {
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .d365-header-breadcrumb-bar:not(.is-store) .d365-header-breadcrumb-link:hover,
html[data-appearance="dark"] .d365-header-breadcrumb-bar:not(.is-store) .d365-header-breadcrumb-home-link:hover {
    color: var(--dk-accent-text) !important;
}

html[data-appearance="dark"] .d365-page-heading-dropdown-header {
    border-bottom-color: var(--dk-border) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-page-heading-dropdown-item {
    background: transparent;
    border-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .d365-page-heading-dropdown-item:hover {
    background: var(--dk-3) !important;
}

html[data-appearance="dark"] .d365-page-heading-dropdown-item strong,
html[data-appearance="dark"] .d365-page-heading-dropdown-item span,
html[data-appearance="dark"] .d365-header-user-name {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-page-heading-dropdown-item small,
html[data-appearance="dark"] .d365-page-heading-action-label {
    color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .d365-header-user-theme-btn.is-selected {
    color: var(--dk-accent-text) !important;
    border-color: var(--dk-border-strong) !important;
}

html[data-appearance="dark"] .d365-header-user-theme-label,
html[data-appearance="dark"] .d365-header-user-name {
    color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .d365-header-user-signout {
    color: var(--dk-text) !important;
}

/* ── 3. Sidebar: a white nav panel turns dark; navy / custom panels are kept ─ */
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"],
html[data-appearance="dark"][data-nav-panel="white"] .d365-sidebar {
    background-color: var(--dk-1) !important;
    border-right-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .d365-sidebar-shell::after {
    background: var(--dk-border) !important;
}

html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-item,
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-group-header,
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-top-home,
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-chevron,
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-footer-name,
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-icon i {
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-section-header,
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-search-hint {
    color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-item:hover,
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-group-header:hover,
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-top-home:hover {
    background: var(--dk-3) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-search {
    background: var(--dk-2) !important;
    border-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-search-input {
    color: var(--dk-text) !important;
    caret-color: var(--dk-text);
}

html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-search-input::placeholder {
    color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-icon {
    /* No tile behind nav glyphs in either appearance — keep the slot transparent. */
    background: transparent !important;
}

html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-item.active,
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-group-header.active {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-footer,
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-top-rail {
    border-color: var(--dk-border) !important;
    background: transparent !important;
}

html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-lock-btn,
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-brand,
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-collapse-btn {
    background: var(--dk-2) !important;
    border-color: var(--dk-border) !important;
    color: var(--dk-text-2) !important;
}

/* ── 4. Surfaces: cards, tiles, tabs, toolbars ────────────────────────────── */
html[data-appearance="dark"] .d365-card,
html[data-appearance="dark"] .store-module-page .d365-card,
html[data-appearance="dark"] .d365-tile,
html[data-appearance="dark"] .card {
    background-color: var(--dk-1) !important;
    border-color: var(--dk-border) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-card-header,
html[data-appearance="dark"] .d365-card-footer,
html[data-appearance="dark"] .card-header,
html[data-appearance="dark"] .card-footer {
    background-color: var(--dk-2) !important;
    border-color: var(--dk-border) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-card-title,
html[data-appearance="dark"] .d365-tile-title {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-tile-subtitle,
html[data-appearance="dark"] .d365-text-muted,
html[data-appearance="dark"] .text-muted {
    color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .d365-tabs {
    background-color: var(--dk-2) !important;
    border-bottom-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .d365-tab {
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .d365-tab.active {
    background-color: var(--dk-1) !important;
    color: var(--dk-accent-text) !important;
}

html[data-appearance="dark"] .d365-empty-state {
    color: var(--dk-text-2);
}

html[data-appearance="dark"] .d365-empty-state-title {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-empty-state-text,
html[data-appearance="dark"] .d365-empty-state-icon {
    color: var(--dk-text-3) !important;
}

/* ── 5. Forms: d365 controls, cmf underline fields, lookups, dates ────────── */
html[data-appearance="dark"] .d365-form-label {
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .d365-form-control,
html[data-appearance="dark"] .d365-form-control:disabled,
html[data-appearance="dark"] .d365-search-input,
html[data-appearance="dark"] .d365-picker-search input,
html[data-appearance="dark"] select,
html[data-appearance="dark"] textarea,
html[data-appearance="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]) {
    color: var(--dk-text) !important;
    caret-color: var(--dk-text);
}

html[data-appearance="dark"] .d365-form-control::placeholder,
html[data-appearance="dark"] .d365-search-input::placeholder {
    color: var(--dk-text-3) !important;
    opacity: 1;
}

html[data-appearance="dark"] .d365-form-control {
    background-color: var(--dk-2) !important;
    border-color: var(--dk-border-strong) !important;
}

html[data-appearance="dark"] .d365-form-control:disabled {
    background-color: var(--dk-3) !important;
    color: var(--dk-text-3) !important;
}

/* The cmf underline baseline (cmf-shared.css) - labels, values, disabled, readonly. */
html[data-appearance="dark"] .cmf-label,
html[data-appearance="dark"] .cmf-form .d365-form-label {
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .cmf-field,
html[data-appearance="dark"] .cmf-form input.d365-form-control:not(.autocomplete-input),
html[data-appearance="dark"] .cmf-form select.d365-form-control,
html[data-appearance="dark"] .cmf-form textarea.d365-form-control,
html[data-appearance="dark"] .cmf-form .autocomplete-select .autocomplete-input,
html[data-appearance="dark"] .cmf-form .autosuggest-input .d365-form-control {
    color: var(--dk-text) !important;
    background: transparent !important;
    border-bottom-color: var(--dk-border-strong) !important;
    caret-color: var(--dk-text);
}

html[data-appearance="dark"] .cmf-field:disabled,
html[data-appearance="dark"] .cmf-form input.d365-form-control:disabled,
html[data-appearance="dark"] .cmf-form select.d365-form-control:disabled,
html[data-appearance="dark"] .cmf-form textarea.d365-form-control:disabled,
html[data-appearance="dark"] .cmf-form .autosuggest-input .d365-form-control:disabled,
html[data-appearance="dark"] .cmf-form .autocomplete-select .autocomplete-input:disabled {
    color: var(--dk-text-2) !important;
    border-bottom-color: var(--dk-border) !important;
    opacity: 1;
}

html[data-appearance="dark"] .cmf-field::placeholder,
html[data-appearance="dark"] .cmf-field:disabled::placeholder,
html[data-appearance="dark"] .cmf-form .autosuggest-input .d365-form-control:disabled::placeholder {
    color: var(--dk-text-3) !important;
    opacity: 1;
}

html[data-appearance="dark"] .cmf-field-readonly,
html[data-appearance="dark"] .cmf-form .autosuggest-input .d365-form-control.cmf-field-readonly {
    color: var(--dk-text-2) !important;
    border-bottom-color: var(--dk-border) !important;
}

/* System numbers (Trans #, Code) keep their amber identity, tuned for a dark surface. */
html[data-appearance="dark"] .cmf-field-id,
html[data-appearance="dark"] .cmf-field-id:disabled,
html[data-appearance="dark"] .trans-no-input,
html[data-appearance="dark"] .stock-trans-no,
html[data-appearance="dark"] .transport-toolbar .trans-no-input,
html[data-appearance="dark"] .stock-toolbar .stock-trans-no {
    background-color: var(--dk-system-bg) !important;
    color: var(--dk-system-text) !important;
    border-color: var(--dk-system-border) !important;
}

html[data-appearance="dark"] .cmf-value-display {
    color: var(--dk-text) !important;
    border-bottom-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .cmf-section-divider {
    border-top-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .cmf-fieldset {
    background: var(--dk-2) !important;
    border-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .cmf-fieldset-legend {
    color: var(--dk-accent-text) !important;
    background: var(--dk-1);
}

/* Read-back tally beside the Departure / Arrival fields. */
html[data-appearance="dark"] .cmf-tally-card {
    background: var(--dk-2) !important;
    box-shadow: inset 0 0 0 1px var(--dk-border), 0 1px 2px rgba(0, 0, 0, 0.35) !important;
}

html[data-appearance="dark"] .cmf-tally-title,
html[data-appearance="dark"] .cmf-tally-line > strong {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .cmf-tally-label,
html[data-appearance="dark"] .cmf-tally-line > span {
    color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .cmf-tally-line {
    border-bottom-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .cmf-picker-refresh:hover:not(:disabled) {
    background: var(--dk-3) !important;
}

/* Validation, error text, required marker. */
html[data-appearance="dark"] .d365-form-control.validation-error,
html[data-appearance="dark"] .validation-message,
html[data-appearance="dark"] .text-danger {
    color: #ff9a94 !important;
}

html[data-appearance="dark"] .d365-form-control.validation-error {
    background-color: var(--dk-danger-soft) !important;
    border-color: #f85149 !important;
}

html[data-appearance="dark"] .invalid-feedback,
html[data-appearance="dark"] .field-validation-error {
    color: #ff9a94 !important;
}

/* ── 6. Grids: read-only grids, editable input grids, container grids ─────── */
html[data-appearance="dark"] .d365-grid-scroll {
    border-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .d365-grid thead {
    background-color: var(--dk-2) !important;
}

html[data-appearance="dark"] .d365-grid th {
    color: var(--dk-text-2) !important;
    border-bottom-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .d365-grid td {
    color: var(--dk-text) !important;
    border-bottom-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .d365-grid tbody tr:hover {
    background-color: var(--dk-3) !important;
}

html[data-appearance="dark"] .d365-grid tbody tr.selected {
    background-color: var(--dk-accent-soft) !important;
}

html[data-appearance="dark"] .d365-grid-empty,
html[data-appearance="dark"] .d365-grid td.d365-grid-empty {
    color: var(--dk-text-3) !important;
}

/* Editable input grid (d365-editable-grid.css) — all hard-coded light. */
html[data-appearance="dark"] .d365-editable-grid-container {
    background: var(--dk-1) !important;
    border-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .d365-editable-grid-toolbar {
    background: var(--dk-2) !important;
    border-bottom-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .d365-editable-grid-toolbar button {
    color: var(--dk-accent-text) !important;
}

html[data-appearance="dark"] .d365-editable-grid-toolbar button:hover:not(:disabled),
html[data-appearance="dark"] .d365-editable-grid-toolbar button:focus {
    background: var(--dk-accent-soft) !important;
    border-color: transparent !important;
}

html[data-appearance="dark"] .d365-editable-grid-toolbar button:disabled {
    color: #6e6c6a !important;
}

html[data-appearance="dark"] .d365-editable-grid-toolbar span,
html[data-appearance="dark"] .d365-editable-grid-toolbar select {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-editable-grid-toolbar .separator {
    background: var(--dk-border-strong) !important;
}

html[data-appearance="dark"] .d365-input-grid th {
    background: var(--dk-2) !important;
    border-color: var(--dk-border) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-input-grid td {
    border-color: var(--dk-border) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-input-grid tr:hover {
    background: var(--dk-3) !important;
}

html[data-appearance="dark"] .d365-input-grid tr.selected {
    background: var(--dk-accent-soft) !important;
}

html[data-appearance="dark"] .d365-input-grid tr.editing {
    background: var(--dk-warn-soft) !important;
}

html[data-appearance="dark"] .d365-grid-cell input[type="text"],
html[data-appearance="dark"] .d365-grid-cell input[type="number"],
html[data-appearance="dark"] .d365-grid-cell input[type="date"] {
    background: transparent !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-grid-cell input:focus,
html[data-appearance="dark"] .d365-input-grid select:focus {
    background: var(--dk-2) !important;
    box-shadow: inset 0 0 0 1px var(--dk-accent-text) !important;
}

html[data-appearance="dark"] .d365-grid-cell-editable:hover,
html[data-appearance="dark"] .d365-input-grid select:hover {
    background: var(--dk-3) !important;
}

html[data-appearance="dark"] .d365-input-grid select,
html[data-appearance="dark"] .d365-grid-cell select {
    background-color: transparent !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-input-grid select option,
html[data-appearance="dark"] .d365-grid-cell select option,
html[data-appearance="dark"] option {
    background-color: var(--dk-2) !important;
    color: var(--dk-text) !important;
}

/* Lookup grid cell popup */
html[data-appearance="dark"] .d365-grid-lookup-dropdown {
    background: var(--dk-2) !important;
    border-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .d365-grid-lookup-dropdown th {
    background: var(--dk-3) !important;
    border-bottom-color: var(--dk-border) !important;
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .d365-grid-lookup-dropdown td {
    border-bottom-color: var(--dk-border) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-grid-lookup-dropdown tr:hover {
    background: var(--dk-accent-soft) !important;
}

/* Container / repair detail grid chrome around the editable grid. */
html[data-appearance="dark"] .cmf-container-detail-grid,
html[data-appearance="dark"] .cmf-container-detail-grid-scroll,
html[data-appearance="dark"] .repair-estimate-detail-grid-scroll {
    border-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .cmf-container-detail-footer {
    background: var(--dk-2) !important;
    border-top-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .cmf-container-detail-count {
    color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .cmf-container-detail-total {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .cmf-list-row-btn {
    background: var(--dk-2) !important;
    border-color: var(--dk-border) !important;
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .cmf-list-row-btn:hover:not(:disabled) {
    background: var(--dk-3) !important;
}

/* ── 7. Popups / menus / dialogs ──────────────────────────────────────────── */
html[data-appearance="dark"] .autocomplete-dropdown,
html[data-appearance="dark"] .autosuggest-dropdown,
html[data-appearance="dark"] .autocomplete-select .autocomplete-dropdown {
    background: var(--dk-2) !important;
    border-color: var(--dk-border-strong) !important;
}

html[data-appearance="dark"] .autocomplete-item,
html[data-appearance="dark"] .autosuggest-item {
    border-bottom-color: var(--dk-border) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .autocomplete-item:hover,
html[data-appearance="dark"] .autocomplete-item.highlighted,
html[data-appearance="dark"] .autosuggest-item:hover,
html[data-appearance="dark"] .autosuggest-item.highlighted {
    background-color: var(--dk-3) !important;
}

html[data-appearance="dark"] .autocomplete-item.selected,
html[data-appearance="dark"] .autosuggest-item.selected {
    background-color: var(--dk-accent-soft) !important;
}

html[data-appearance="dark"] .autocomplete-no-results {
    color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .autocomplete-item-two-line .secondary {
    color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .d365-new-split-menu,
html[data-appearance="dark"] .store-print-split-menu {
    background-color: var(--dk-2) !important;
    border-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .d365-new-split-item {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-new-split-item:hover {
    background: var(--dk-3) !important;
}

/* Bootstrap dialogs (Get Data pickers, audit log, search, approval). */
html[data-appearance="dark"] .modal-content {
    background-color: var(--dk-1) !important;
    border-color: var(--dk-border) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .modal-header,
html[data-appearance="dark"] .modal-footer {
    border-color: var(--dk-border) !important;
    background-color: var(--dk-2) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .modal-title,
html[data-appearance="dark"] .modal-body {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .modal-backdrop.show {
    opacity: 0.72;
}

html[data-appearance="dark"] .btn-close {
    filter: invert(1) grayscale(1) brightness(1.8);
}

html[data-appearance="dark"] .form-control,
html[data-appearance="dark"] .form-select {
    background-color: var(--dk-2) !important;
    border-color: var(--dk-border-strong) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .form-control::placeholder {
    color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .form-control:disabled,
html[data-appearance="dark"] .form-select:disabled {
    background-color: var(--dk-3) !important;
    color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .table {
    color: var(--dk-text) !important;
    --bs-table-bg: transparent;
    --bs-table-color: var(--dk-text);
}

html[data-appearance="dark"] .table > :not(caption) > * > * {
    border-bottom-color: var(--dk-border) !important;
    background-color: transparent !important;
    color: var(--dk-text);
}

html[data-appearance="dark"] .table-light,
html[data-appearance="dark"] .table > thead.table-light > tr > th {
    background-color: var(--dk-2) !important;
    color: var(--dk-text) !important;
}

/* Flyout / side pane shared by the container and party pickers. */
html[data-appearance="dark"] .cmf-party-flyout,
html[data-appearance="dark"] .cmf-party-flyout-header,
html[data-appearance="dark"] .cmf-party-flyout-footer {
    background: var(--dk-1) !important;
    border-color: var(--dk-border) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .cmf-party-flyout-title {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .cmf-party-flyout-close {
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .cmf-party-flyout-close:hover {
    background: var(--dk-3) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .cmf-party-flyout-section {
    border-bottom-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .cmf-party-flyout-section-chevron {
    color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .cmf-party-flyout .cmf-field.cmf-field-readonly {
    background: var(--dk-3) !important;
    border-color: var(--dk-border) !important;
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .cmf-party-flyout-field.is-focus-target {
    background: var(--dk-2) !important;
    border-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .cmf-flyout-btn-cancel {
    background: var(--dk-2) !important;
    border-color: var(--dk-border-strong) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .cmf-flyout-btn-cancel:hover {
    background: var(--dk-3) !important;
    border-color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .cmf-party-flyout-backdrop {
    background: rgba(0, 0, 0, 0.65) !important;
}

html[data-appearance="dark"] .cmf-add-client-btn {
    background: var(--dk-2) !important;
    border-color: var(--dk-border-strong) !important;
    color: var(--dk-accent-text) !important;
}

html[data-appearance="dark"] .cmf-payby-label {
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .cmf-payby-badge {
    background: var(--dk-accent-soft) !important;
    color: var(--dk-accent-text) !important;
}

/* ── 8. Badges, pills, status ─────────────────────────────────────────────── */
html[data-appearance="dark"] .d365-badge-primary {
    background-color: var(--dk-accent-soft) !important;
    color: var(--dk-accent-text) !important;
}

html[data-appearance="dark"] .d365-badge-success {
    background-color: var(--dk-success-soft) !important;
    color: #7ee787 !important;
}

html[data-appearance="dark"] .d365-badge-warning {
    background-color: var(--dk-warn-soft) !important;
    color: #ffd76e !important;
}

html[data-appearance="dark"] .d365-badge-danger {
    background-color: var(--dk-danger-soft) !important;
    color: #ff9a94 !important;
}

/* ── 9. CFS / Store process trail band ────────────────────────────────────── */
html[data-appearance="dark"] .cfs-bpf-trail,
html[data-appearance="dark"] .store-bpf-trail {
    background: linear-gradient(180deg, var(--dk-2) 0%, var(--dk-1) 100%) !important;
    border-color: var(--dk-border) !important;
    --cfs-bpf-track: #3b3a39;
}

html[data-appearance="dark"] .cfs-bpf-node,
html[data-appearance="dark"] .store-bpf-node {
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .cfs-bpf-label,
html[data-appearance="dark"] .store-bpf-label,
html[data-appearance="dark"] .cfs-bpf-collapsed-stage,
html[data-appearance="dark"] .store-bpf-collapsed-stage {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .cfs-bpf-stage.state-pending .cfs-bpf-label,
html[data-appearance="dark"] .cfs-bpf-stage.state-skipped .cfs-bpf-label,
html[data-appearance="dark"] .store-bpf-stage.state-pending .store-bpf-label,
html[data-appearance="dark"] .store-bpf-stage.state-skipped .store-bpf-label,
html[data-appearance="dark"] .cfs-bpf-loading,
html[data-appearance="dark"] .store-bpf-loading {
    color: var(--dk-text-3) !important;
}

/* Hollow markers are filled #fff so the band border cannot show through them. */
html[data-appearance="dark"] .cfs-bpf-marker-pending,
html[data-appearance="dark"] .cfs-bpf-marker-skipped,
html[data-appearance="dark"] .cfs-bpf-bullseye-core,
html[data-appearance="dark"] .store-bpf-marker-pending,
html[data-appearance="dark"] .store-bpf-marker-skipped,
html[data-appearance="dark"] .store-bpf-bullseye-core {
    background: var(--dk-1) !important;
    border-color: var(--dk-border-strong) !important;
}

html[data-appearance="dark"] .cfs-bpf-actions {
    border-top-color: var(--dk-border) !important;
    background: rgba(255, 255, 255, 0.04) !important;
}

html[data-appearance="dark"] .cfs-bpf-action {
    background: var(--dk-2) !important;
    border-color: var(--dk-border-strong) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .cfs-bpf-back {
    background: #4a2f2d !important;
    color: #ffb3ad !important;
}

/* ── 9b. Dashboard widgets (dashboard.css is almost entirely hard-coded light) ─ */
html[data-appearance="dark"] .dashboard-fancy-card,
html[data-appearance="dark"] .pbi-kpi-card,
html[data-appearance="dark"] .pbi-slicer-bar,
html[data-appearance="dark"] .legacy-shortcut-widget,
html[data-appearance="dark"] .kpi-style-dialog-content {
    background: var(--dk-1) !important;
    border-color: var(--dk-border) !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .pbi-kpi-face-back {
    background: var(--dk-2) !important;
}

html[data-appearance="dark"] .pbi-kpi-report-value,
html[data-appearance="dark"] .dashboard-fancy-primary,
html[data-appearance="dark"] .dashboard-fancy-secondary,
html[data-appearance="dark"] .dashboard-fancy-eyebrow .is-strong,
html[data-appearance="dark"] .dashboard-fancy-caption.strong,
html[data-appearance="dark"] .legacy-shortcut-widget__title {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .dashboard-fancy-eyebrow,
html[data-appearance="dark"] .pbi-kpi-label,
html[data-appearance="dark"] .pbi-refresh-time {
    color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .pbi-save-state,
html[data-appearance="dark"] .pbi-btn-refresh,
html[data-appearance="dark"] .pbi-btn-customize,
html[data-appearance="dark"] .pbi-btn-secondary,
html[data-appearance="dark"] .pbi-slicer-pill,
html[data-appearance="dark"] .pbi-slicer-select,
html[data-appearance="dark"] .legacy-shortcut-widget__link,
html[data-appearance="dark"] .legacy-shortcut-widget__layout-btn,
html[data-appearance="dark"] .pbi-widget-toolbar-btn {
    background: var(--dk-2) !important;
    border-color: var(--dk-border-strong) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .pbi-btn-refresh:hover:not(:disabled),
html[data-appearance="dark"] .pbi-btn-secondary:hover:not(:disabled),
html[data-appearance="dark"] .pbi-btn-customize:hover:not(:disabled),
html[data-appearance="dark"] .legacy-shortcut-widget__link:hover,
html[data-appearance="dark"] .pbi-widget-toolbar-btn:hover {
    background: var(--dk-3) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .pbi-slicer-label {
    background: rgba(99, 102, 241, 0.2) !important;
    color: #b9b5ff !important;
}

html[data-appearance="dark"] .pbi-slicer-group + .pbi-slicer-group,
html[data-appearance="dark"] .pbi-slicer-bar > .pbi-slicer-custom-range {
    border-left-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .hrm-calendar-month-popover {
    background: var(--dk-2) !important;
    border-color: var(--dk-border) !important;
    color: var(--dk-text) !important;
}

/* ── 10. Utilities, links, misc ───────────────────────────────────────────── */
html[data-appearance="dark"] a {
    color: var(--dk-accent-text);
}

html[data-appearance="dark"] hr {
    border-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .bg-white,
html[data-appearance="dark"] .bg-light,
html[data-appearance="dark"] .bg-body,
html[data-appearance="dark"] .bg-body-tertiary {
    background-color: var(--dk-1) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .text-dark,
html[data-appearance="dark"] .text-body {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .border,
html[data-appearance="dark"] .border-top,
html[data-appearance="dark"] .border-bottom,
html[data-appearance="dark"] .border-start,
html[data-appearance="dark"] .border-end {
    border-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .list-group-item {
    background-color: var(--dk-1) !important;
    border-color: var(--dk-border) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .dropdown-menu {
    background-color: var(--dk-2) !important;
    border-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .dropdown-item {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .dropdown-item:hover,
html[data-appearance="dark"] .dropdown-item:focus {
    background-color: var(--dk-3) !important;
}

/* Non-primary buttons keep a dark surface; primary / success / danger stay branded. */
html[data-appearance="dark"] .d365-btn:not(.d365-btn-primary):not(.d365-btn-success):not(.d365-btn-danger):not(.d365-btn-warning),
html[data-appearance="dark"] .d365-btn-primary,
html[data-appearance="dark"] .d365-btn-success,
html[data-appearance="dark"] .d365-btn-receipt {
    background-color: var(--dk-2) !important;
    border-color: var(--dk-border-strong) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-btn:not(.d365-btn-primary):not(.d365-btn-success):not(.d365-btn-danger):not(.d365-btn-warning):hover:not(:disabled),
html[data-appearance="dark"] .d365-btn-primary:hover:not(:disabled),
html[data-appearance="dark"] .d365-btn-success:hover:not(:disabled) {
    background-color: var(--dk-3) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-btn-danger {
    background-color: var(--dk-danger-soft) !important;
    border-color: #6d2a2a !important;
    color: #ff9a94 !important;
}

html[data-appearance="dark"] .d365-btn-warning {
    background-color: var(--dk-warn-soft) !important;
    border-color: #6b5c1f !important;
    color: #ffd76e !important;
}

/* Command-bar glyphs default to #6b7280, which is too dim on a dark bar. */
html[data-appearance="dark"] .d365-btn:not(.d365-btn-primary) i,
html[data-appearance="dark"] .d365-btn:not(.d365-btn-primary):hover:not(:disabled) i {
    color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .d365-btn:disabled {
    opacity: 0.45;
}

html[data-appearance="dark"] .d365-search-input {
    background-color: var(--dk-2) !important;
    border-color: var(--dk-border-strong) !important;
}

html[data-appearance="dark"] .btn-outline-secondary,
html[data-appearance="dark"] .btn-outline-dark {
    color: var(--dk-text) !important;
    border-color: var(--dk-border-strong) !important;
}

html[data-appearance="dark"] .btn-outline-secondary:hover,
html[data-appearance="dark"] .btn-outline-dark:hover {
    background-color: var(--dk-3) !important;
    color: var(--dk-text) !important;
}

/* Toast notifications (app.css) paint a white header/body regardless of theme. */
html[data-appearance="dark"] .apple-toast {
    border-color: var(--dk-border) !important;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.6) !important;
}

html[data-appearance="dark"] .apple-toast-header,
html[data-appearance="dark"] .apple-toast-body {
    background: var(--dk-2) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .apple-toast-datetime {
    color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .apple-toast-close {
    background: var(--dk-3) !important;
    color: var(--dk-text-2) !important;
}

/* ── 11. Login screen ──────────────────────────────────────────────────────
   Exempt on purpose. The sign-in page keeps its own photo backdrop and glass
   card in both themes: tmsUiTheme.applyAppearance() resolves Light while the
   route is /login, so the dark shell never reaches it. Do not add .login-*,
   .brand-* or .welcome-* overrides back into this file. */

/* ── 12. CFS Live Tracking: the page owns a token set on .trk-root ─────────── */
html[data-appearance="dark"] .trk-root {
    --trk-card: #1b1a19;
    --trk-card-2: #232221;
    --trk-line: #3b3a39;
    --trk-line-strong: #52514f;
    --trk-ink: #f3f2f1;
    --trk-ink-2: #c8c6c4;
    --trk-ink-3: #a19f9d;
    --trk-blue: #7cb3ff;
    --trk-blue-soft: rgba(56, 139, 253, 0.2);
    --trk-green: #7ee787;
    --trk-green-soft: rgba(63, 185, 80, 0.18);
    --trk-amber: #ffd76e;
    --trk-amber-soft: rgba(210, 153, 34, 0.2);
    --trk-red: #ff9a94;
    --trk-red-soft: rgba(248, 81, 73, 0.18);
    --trk-violet: #c4a9f5;
    --trk-shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 10px 28px -18px rgba(0, 0, 0, 0.8);
}

html[data-appearance="dark"] .trk-tool {
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .trk-switch-label {
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .trk-field-select option {
    color: var(--dk-text) !important;
    background: var(--dk-2) !important;
}

html[data-appearance="dark"] .trk-node-dot,
html[data-appearance="dark"] .trk-node-tick,
html[data-appearance="dark"] .trk-ring::after,
html[data-appearance="dark"] .trk-switch-dot {
    background: var(--dk-1) !important;
}

/* ── 13. CFS Rail Request ─────────────────────────────────────────────────── */
html[data-appearance="dark"] .rail-flag,
html[data-appearance="dark"] .trip-toggle-btn.is-active,
html[data-appearance="dark"] .rail-inhand-select:focus-visible,
html[data-appearance="dark"] .rail-request-grid tr:hover .rail-inhand-select {
    background: var(--dk-2) !important;
    border-color: var(--dk-border-strong) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .rail-flag:hover:not(:has(input:disabled)),
html[data-appearance="dark"] .trip-toggle-btn:hover:not(:disabled):not(.is-active) {
    background: var(--dk-3) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .trip-toggle,
html[data-appearance="dark"] .rail-status-card,
html[data-appearance="dark"] .rail-wagon-info-summary {
    background: var(--dk-2) !important;
    border-color: var(--dk-border) !important;
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .rail-status-card-title,
html[data-appearance="dark"] .rail-status-card-line b,
html[data-appearance="dark"] .rail-wagon-info-summary b {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .cfs-rail-status.is-void {
    background: var(--dk-3) !important;
    color: var(--dk-text-2) !important;
}

/* ── 14. CFS Booking: plan strip, flags, side flyout ──────────────────────── */
html[data-appearance="dark"] .booking-plan-empty,
html[data-appearance="dark"] .booking-plan-row,
html[data-appearance="dark"] .booking-plan-process-waiting,
html[data-appearance="dark"] .booking-plan-footer,
html[data-appearance="dark"] .booking-plan-containers,
html[data-appearance="dark"] .booking-flag-group,
html[data-appearance="dark"] .booking-flag-box,
html[data-appearance="dark"] .booking-charge-fields,
html[data-appearance="dark"] .booking-flyout,
html[data-appearance="dark"] .booking-flyout-header,
html[data-appearance="dark"] .booking-flyout-footer {
    background: var(--dk-1) !important;
    border-color: var(--dk-border) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .booking-plan-chip,
html[data-appearance="dark"] .booking-plan-container-chip.is-pending,
html[data-appearance="dark"] .booking-flag-option {
    background: var(--dk-2) !important;
    border-color: var(--dk-border) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .booking-flag-option:hover:not(:has(input:disabled)),
html[data-appearance="dark"] .booking-flyout-close:hover,
html[data-appearance="dark"] .booking-rail-meta-row:hover:not(:disabled) {
    background: var(--dk-3) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .booking-plan-empty,
html[data-appearance="dark"] .booking-plan-route,
html[data-appearance="dark"] .booking-plan-process-pending,
html[data-appearance="dark"] .booking-flyout .booking-label,
html[data-appearance="dark"] .booking-flyout-hint,
html[data-appearance="dark"] .booking-flyout-close,
html[data-appearance="dark"] .booking-charge-chevron,
html[data-appearance="dark"] .cmf-party-flyout-hint,
html[data-appearance="dark"] .booking-detail-grid-footer .repair-estimate-detail-total-label {
    color: var(--dk-text-3) !important;
}

html[data-appearance="dark"] .booking-flyout-title,
html[data-appearance="dark"] .booking-flyout-section-title {
    color: var(--dk-text) !important;
}

/* Booking's Book-by lookup forces a light field with !important inside the flyout;
   the [class] token adds the specificity needed to answer it. */
html[data-appearance="dark"] [class] .cmf-party-flyout .booking-bookby .autocomplete-input,
html[data-appearance="dark"] [class] .booking-detail-grid .autosuggest-input .d365-form-control {
    background: var(--dk-2) !important;
    color: var(--dk-text) !important;
    border-color: var(--dk-border-strong) !important;
}

html[data-appearance="dark"] [class] .cmf-party-flyout .booking-bookby .autocomplete-input:disabled,
html[data-appearance="dark"] [class] .booking-detail-grid input.autocomplete-input:disabled,
html[data-appearance="dark"] [class] .cmf-party-flyout .autosuggest-input .d365-form-control:disabled {
    background: var(--dk-3) !important;
    color: var(--dk-text-2) !important;
}

/* ── 15. Legacy literal sweep ─────────────────────────────────────────────────
   The light sheets (cmf-shared.css, dashboard.css, dynamics365.css,
   ui-form-themes.css) hard-code hundreds of skin literals - #323130 ink on
   #ffffff surfaces, #8b7355 label brown, #f3f2f1 toolbars. Design tokens never
   reached those rules, so they are answered class by class here. Every rule is
   scoped to dark, so the light theme is untouched.
   ──────────────────────────────────────────────────────────────────────────── */

/* 15a. Primary ink: headings, values, table headers, tile titles. */
html[data-appearance="dark"] .tms-card-header h3,
html[data-appearance="dark"] .tms-dashboard-title h1,
html[data-appearance="dark"] .tms-section-header h2,
html[data-appearance="dark"] .tms-kpi-value,
html[data-appearance="dark"] .tms-tile-title,
html[data-appearance="dark"] .tms-table th,
html[data-appearance="dark"] .tms-status-row,
html[data-appearance="dark"] .repair-estimate-list-header,
html[data-appearance="dark"] .container-info-value,
html[data-appearance="dark"] .container-info-remarks-value,
html[data-appearance="dark"] .currency-audit-value,
html[data-appearance="dark"] .currency-grid-code,
html[data-appearance="dark"] .currency-grid-foreign,
html[data-appearance="dark"] .currency-head-code,
html[data-appearance="dark"] .currency-head-name,
html[data-appearance="dark"] .currency-tile-value,
html[data-appearance="dark"] .eir-item-primary,
html[data-appearance="dark"] .print-label,
html[data-appearance="dark"] .cmf-party-flyout-section-title,
html[data-appearance="dark"] .excel-grid-title,
html[data-appearance="dark"] .excel-grid-filter-value,
html[data-appearance="dark"] .movements-grid-compact .label,
html[data-appearance="dark"] .readonly-display,
html[data-appearance="dark"] .group-ref,
html[data-appearance="dark"] .nav-tabs .nav-link,
html[data-appearance="dark"] .dashboard-fancy-metric,
html[data-appearance="dark"] .dashboard-fancy-performance-title,
html[data-appearance="dark"] .dashboard-fancy-live,
html[data-appearance="dark"] .hrm-calendar-title,
html[data-appearance="dark"] .hrm-calendar-task-list h4,
html[data-appearance="dark"] .hrm-calendar-task-row,
html[data-appearance="dark"] .hrm-calendar-week-nav,
html[data-appearance="dark"] .hrm-calendar-weekdays span,
html[data-appearance="dark"] .hrm-calendar-selected-head h3,
html[data-appearance="dark"] .hrm-map-header h3,
html[data-appearance="dark"] .hrm-notification-header h3,
html[data-appearance="dark"] .hrm-preview-calendar-head,
html[data-appearance="dark"] .hrm-preview-announcement-main strong,
html[data-appearance="dark"] .hrm-preview-note strong,
html[data-appearance="dark"] .hrm-preview-table th,
html[data-appearance="dark"] .kpi-style-dialog-header h5,
html[data-appearance="dark"] .pbi-chart-header h3,
html[data-appearance="dark"] .pbi-kpi-value,
html[data-appearance="dark"] .pbi-title,
html[data-appearance="dark"] .pbi-slicer-reset,
html[data-appearance="dark"] .widget-color-field span {
    color: var(--dk-text) !important;
}

/* 15b. Secondary ink: labels, helper text, metric captions. */
html[data-appearance="dark"] .tms-kpi-label,
html[data-appearance="dark"] .tms-kpi-subtext,
html[data-appearance="dark"] .tms-tile-subtitle,
html[data-appearance="dark"] .tms-card-header p,
html[data-appearance="dark"] .tms-dashboard-title p,
html[data-appearance="dark"] .currency-audit,
html[data-appearance="dark"] .currency-grid-meta,
html[data-appearance="dark"] .currency-head-default-text,
html[data-appearance="dark"] .currency-rate-help,
html[data-appearance="dark"] .currency-rate-unit,
html[data-appearance="dark"] .currency-tile-label,
html[data-appearance="dark"] .container-info-label,
html[data-appearance="dark"] .container-info-remarks-label,
html[data-appearance="dark"] .eir-item-secondary,
html[data-appearance="dark"] .eir-dropdown-hint,
html[data-appearance="dark"] .excel-grid-filter-action,
html[data-appearance="dark"] .layoff-grounding-container-meta,
html[data-appearance="dark"] .layoff-grounding-hint,
html[data-appearance="dark"] .layoff-grounding-list-card-meta,
html[data-appearance="dark"] .layoff-grounding-list-card-stats,
html[data-appearance="dark"] .layoff-grounding-list-no,
html[data-appearance="dark"] .layoff-grounding-ocr-box pre,
html[data-appearance="dark"] .layoff-grounding-stats .stat-num,
html[data-appearance="dark"] .repair-estimate-additional-remarks-label,
html[data-appearance="dark"] .cmf-ro-ref-field-icon,
html[data-appearance="dark"] .cmf-compact-pager-btn,
html[data-appearance="dark"] .setup-coding-list-pager,
html[data-appearance="dark"] .hrm-calendar-subtitle,
html[data-appearance="dark"] .hrm-preview-announcement-main small,
html[data-appearance="dark"] .hrm-preview-announcement-meta span:first-child,
html[data-appearance="dark"] .hrm-preview-note small,
html[data-appearance="dark"] .hrm-preview-note-time,
html[data-appearance="dark"] .hrm-preview-note.detailed small,
html[data-appearance="dark"] .hrm-preview-team-legend,
html[data-appearance="dark"] .hrm-widget-ctrl-btn,
html[data-appearance="dark"] .kpi-style-dialog-header span,
html[data-appearance="dark"] .pbi-gauge-meta,
html[data-appearance="dark"] .pbi-kpi-sub,
html[data-appearance="dark"] .pbi-loading,
html[data-appearance="dark"] .pbi-subtitle,
html[data-appearance="dark"] .pbi-widget-drag-handle,
html[data-appearance="dark"] .widget-color-reset,
html[data-appearance="dark"] .dashboard-fancy-bar-track small {
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .dashboard-fancy-bar-row span,
html[data-appearance="dark"] .dashboard-fancy-score-ring {
    color: var(--dk-text-3) !important;
}

/* 15c. Light surfaces: cards, tiles, panels, popovers, list shells. */
html[data-appearance="dark"] .tms-card,
html[data-appearance="dark"] .tms-kpi-card,
html[data-appearance="dark"] .tms-tile,
html[data-appearance="dark"] .currency-tile,
html[data-appearance="dark"] .eir-dropdown,
html[data-appearance="dark"] .excel-grid-filter-panel,
html[data-appearance="dark"] .layoff-grounding-confirm-card,
html[data-appearance="dark"] .layoff-grounding-file-btn,
html[data-appearance="dark"] .layoff-grounding-list-card,
html[data-appearance="dark"] .layoff-grounding-container-card,
html[data-appearance="dark"] .layoff-grounding-ocr-box,
html[data-appearance="dark"] .layoff-grounding-stats > div,
html[data-appearance="dark"] .layoff-pool-container-search,
html[data-appearance="dark"] .print-options-bar,
html[data-appearance="dark"] .repair-estimate-approval-panel,
html[data-appearance="dark"] .repair-estimate-list-grid,
html[data-appearance="dark"] .approval-picker-menu,
html[data-appearance="dark"] .cmf-compact-pager,
html[data-appearance="dark"] .cmf-party-flyout-btn,
html[data-appearance="dark"] .cmf-record-list-panel .cmf-movements-list-search,
html[data-appearance="dark"] .hrm-announcement-form-popover,
html[data-appearance="dark"] .hrm-calendar-month-picker,
html[data-appearance="dark"] .hrm-calendar-selected-tasks,
html[data-appearance="dark"] .hrm-calendar-task-popover,
html[data-appearance="dark"] .hrm-preview-note.detailed,
html[data-appearance="dark"] .hrm-corner-popup,
html[data-appearance="dark"] .kpi-style-option,
html[data-appearance="dark"] .pbi-widget-shell:not(.is-kpi-widget),
html[data-appearance="dark"] .widget-color-dialog-content {
    background: var(--dk-1) !important;
    border-color: var(--dk-border) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .hrm-calendar-week-card,
html[data-appearance="dark"] .hrm-calendar-selected-row,
html[data-appearance="dark"] .hrm-preview-calendar-grid > div,
html[data-appearance="dark"] .hrm-preview-announcement-dates span,
html[data-appearance="dark"] .dashboard-fancy-mini-track,
html[data-appearance="dark"] .ops-progress-bar,
html[data-appearance="dark"] .approval-picker-option:hover,
html[data-appearance="dark"] .context-menu-item:hover,
html[data-appearance="dark"] .excel-grid-filter-action:hover,
html[data-appearance="dark"] .layoff-not-grounded-btn:hover,
html[data-appearance="dark"] .hrm-calendar-task-row:hover,
html[data-appearance="dark"] .ui-theme-appearance-btn:hover,
html[data-appearance="dark"] .ui-theme-preset-option:hover {
    background: var(--dk-2) !important;
    border-color: var(--dk-border) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .hrm-preview-note.detailed.announcement {
    background: var(--dk-accent-soft) !important;
    border-color: #3d6ea8 !important;
    color: var(--dk-text) !important;
}

/* Grid headers that live inside those shells. */
html[data-appearance="dark"] .repair-estimate-list-grid .d365-grid-fo thead,
html[data-appearance="dark"] .repair-estimate-list-grid .d365-grid-fo thead th,
html[data-appearance="dark"] .repair-estimate-detail-grid .d365-grid-fo-editable thead th,
html[data-appearance="dark"] .mnr-job-picker-modal .ro-grid-table thead th {
    background: var(--dk-2) !important;
    color: var(--dk-text) !important;
    border-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .repair-estimate-list-grid .d365-grid-fo tbody tr:hover,
html[data-appearance="dark"] .repair-estimate-list-grid .d365-grid-fo tbody td {
    background: var(--dk-1) !important;
    color: var(--dk-text) !important;
    border-color: var(--dk-border) !important;
}

/* 15d. Outline / chip / pill controls that sit on a light chip. */
html[data-appearance="dark"] .cmf-flag-chip,
html[data-appearance="dark"] .cmf-inline-icon-btn,
html[data-appearance="dark"] .cro-header-status,
html[data-appearance="dark"] .currency-chip-foreign,
html[data-appearance="dark"] .currency-grid-symbol,
html[data-appearance="dark"] .layoff-grounding-secondary-btn,
html[data-appearance="dark"] .layoff-grounding-tab,
html[data-appearance="dark"] .layoff-not-grounded-btn,
html[data-appearance="dark"] .ops-work-status--queued,
html[data-appearance="dark"] .tms-action-btn,
html[data-appearance="dark"] .tms-btn-outline,
html[data-appearance="dark"] .approval-pill,
html[data-appearance="dark"] .approval-picker-option,
html[data-appearance="dark"] .movements-grid-compact .serial-badge,
html[data-appearance="dark"] .ui-theme-appearance-btn,
html[data-appearance="dark"] .ui-theme-preview-card {
    background: var(--dk-2) !important;
    border-color: var(--dk-border-strong) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .approval-pill:hover:not(:disabled),
html[data-appearance="dark"] .layoff-grounding-tab:hover:not(:disabled) {
    border-color: var(--dk-accent-text) !important;
    color: var(--dk-text) !important;
}

/* 15e. Editable controls inside legacy popovers. */
html[data-appearance="dark"] .hrm-announcement-form-popover input,
html[data-appearance="dark"] .hrm-announcement-form-popover select,
html[data-appearance="dark"] .hrm-announcement-form-popover textarea,
html[data-appearance="dark"] .cmf-record-list-panel .cmf-movements-list-search input,
html[data-appearance="dark"] .layoff-pool-container-search input,
html[data-appearance="dark"] .widget-color-input-row input[type="color"] {
    background: var(--dk-2) !important;
    border-color: var(--dk-border-strong) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .cmf-record-list-panel .cmf-movements-list-search input::placeholder {
    color: var(--dk-text-3) !important;
    opacity: 1;
}

html[data-appearance="dark"] .cmf-record-list-panel .cmf-movements-list-search-clear,
html[data-appearance="dark"] .cmf-record-list-panel .cmf-movements-list-search-clear:hover {
    color: var(--dk-text-2) !important;
    background: transparent !important;
}

/* 15f. Dividers, arrows and switch knobs that used to be white. */
html[data-appearance="dark"] .cmf-party-flyout-inner-divider,
html[data-appearance="dark"] .container-eir-divider,
html[data-appearance="dark"] .excel-grid-filter-divider {
    background: var(--dk-border) !important;
    border-color: var(--dk-border) !important;
}

html[data-appearance="dark"] .cmf-switch-slider::before,
html[data-appearance="dark"] .hrm-preview-team-donut::after {
    background: var(--dk-1) !important;
}

html[data-appearance="dark"] .hrm-corner-popup::after,
html[data-appearance="dark"] .hrm-corner-popup.is-below::after {
    background: var(--dk-1) !important;
    border-color: var(--dk-border) !important;
}

/* 15g. Nav leftovers (brand, search clear, footer, record nav). White panels
   were flipped in section 3; these are the literals that sat outside it. */
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-subheader,
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-segment,
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-segment:hover,
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-search-icon,
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-search-clear,
html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-footer-logout {
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-brand-text {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-footer-logout:hover {
    background: var(--dk-danger-soft) !important;
    color: #ff9a94 !important;
}

html[data-appearance="dark"] .d365-sidebar[data-nav-panel="white"] .d365-nav-dashboard-wrap,
html[data-appearance="dark"] .d365-record-nav-header,
html[data-appearance="dark"] .d365-page-heading-dropdown-close {
    background: var(--dk-2) !important;
    border-color: var(--dk-border) !important;
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .d365-header-breadcrumb-sep {
    color: var(--dk-text-3) !important;
}

/* 15h. Appearance picker itself (user menu > THEME). */
html[data-appearance="dark"] .ui-theme-appearance-btn-title,
html[data-appearance="dark"] .ui-theme-preset-option-title,
html[data-appearance="dark"] .ui-theme-fluent-preview-title {
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .ui-theme-appearance-btn-desc,
html[data-appearance="dark"] .ui-theme-preset-option-desc,
html[data-appearance="dark"] .ui-theme-appearance-btn i {
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .ui-theme-appearance-btn[aria-pressed="true"],
html[data-appearance="dark"] .ui-theme-appearance-btn.is-active {
    background: var(--dk-accent-soft) !important;
    border-color: var(--dk-accent-text) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .ui-theme-preview-sidebar {
    color: var(--dk-text-2) !important;
}

/* 15i. Remaining tracker headers, edit bar, dashboard header. */
html[data-appearance="dark"] .re-header-tracker .tracker-label,
html[data-appearance="dark"] .ro-header-tracker .tracker-label,
html[data-appearance="dark"] .currency-rate-offline {
    color: var(--dk-text-2) !important;
}

html[data-appearance="dark"] .re-header-tracker .tracker-icon,
html[data-appearance="dark"] .ro-header-tracker .tracker-icon,
html[data-appearance="dark"] .hrm-edit-bar-btn,
html[data-appearance="dark"] .hrm-edit-bar-btn-reset,
html[data-appearance="dark"] .hrm-preview-status-tile,
html[data-appearance="dark"] .hrm-widget-size-badge,
html[data-appearance="dark"] .tms-dashboard-header {
    background: var(--dk-2) !important;
    border-color: var(--dk-border) !important;
    color: var(--dk-text) !important;
}

html[data-appearance="dark"] .hrm-preview-status-tile span,
html[data-appearance="dark"] .hrm-edit-bar-btn-reset:hover:not(:disabled) {
    color: var(--dk-text-2) !important;
}

/* Scrollbars follow --dk surfaces instead of the light OS default. */
html[data-appearance="dark"] {
    scrollbar-color: #4a4846 var(--dk-1);
}

html[data-appearance="dark"] ::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

html[data-appearance="dark"] ::-webkit-scrollbar-track {
    background: var(--dk-1);
}

html[data-appearance="dark"] ::-webkit-scrollbar-thumb {
    background: #4a4846;
    border: 3px solid var(--dk-1);
    border-radius: 8px;
}

html[data-appearance="dark"] ::-webkit-scrollbar-thumb:hover {
    background: #5d5b58;
}
