/*
 * MN 2.0 shared colour theme.
 *
 * Page modules inject their own styles after this file is loaded. Dark-theme
 * selectors therefore deliberately include the document theme, #contentHost
 * and the module root so they keep precedence without changing the light UI.
 */

/* Scale the entire interface so fixed-pixel text, controls and dialogs grow
   together. Printed documents retain their original dimensions. */
@media screen {
  html { zoom: var(--mn-display-scale, 1); }
}
.mn-display-size { display: grid; gap: 6px; font-size: 14px; color: var(--mn-theme-text); }
.mn-display-size select {
  width: 100%; min-width: 0; padding: 10px; border-radius: 8px;
  border: 1px solid var(--mn-theme-border-strong);
  background: var(--mn-theme-input); color: var(--mn-theme-text); font: inherit;
}
@media print { .mn-display-size { display: none !important; } }

:root {
  color-scheme: light;
  --mn-theme-bg: #f3f7fb;
  --mn-theme-surface: #ffffff;
  --mn-theme-surface-soft: #f8fbff;
  --mn-theme-surface-raised: #ffffff;
  --mn-theme-border: #d9e2ef;
  --mn-theme-border-strong: #b9c8da;
  --mn-theme-text: #0f172a;
  --mn-theme-muted: #475467;
  --mn-theme-link: #1368d6;
  --mn-theme-primary-soft: #eef4ff;
  --mn-theme-input: #ffffff;
  --mn-theme-shadow: 0 12px 34px rgb(15 23 42 / 8%);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --mn-theme-bg: #08111f;
  --mn-theme-surface: #101b2c;
  --mn-theme-surface-soft: #152237;
  --mn-theme-surface-raised: #19273b;
  --mn-theme-border: #304158;
  --mn-theme-border-strong: #465b75;
  --mn-theme-text: #edf3fb;
  --mn-theme-muted: #bdcadd;
  --mn-theme-link: #7db8ff;
  --mn-theme-primary-soft: #172c49;
  --mn-theme-input: #0d1828;
  --mn-theme-shadow: 0 16px 42px rgb(0 0 0 / 34%);
  --bg: var(--mn-theme-bg);
  --surface: var(--mn-theme-surface);
  --surface-soft: var(--mn-theme-surface-soft);
  --border: var(--mn-theme-border);
  --text: var(--mn-theme-text);
  --muted: var(--mn-theme-muted);
  --primary: var(--mn-theme-link);
  --primary-soft: var(--mn-theme-primary-soft);
  --shadow: var(--mn-theme-shadow);
  scrollbar-color: #4b607a #0b1626;
}

body,
.mobile-topbar,
.sidebar,
.panel,
.mn-cars-shell-widget {
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

.theme-toggle,
.mn-theme-toggle-float {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  border: 1px solid var(--mn-theme-border);
  border-radius: 9px;
  background: var(--mn-theme-surface);
  color: var(--mn-theme-text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.theme-toggle:hover,
.theme-toggle:focus-visible,
.mn-theme-toggle-float:hover,
.mn-theme-toggle-float:focus-visible {
  border-color: var(--mn-theme-link);
  background: var(--mn-theme-primary-soft);
  color: var(--mn-theme-link);
  outline: 3px solid color-mix(in srgb, var(--mn-theme-link) 25%, transparent);
  outline-offset: 2px;
}

.theme-toggle--compact {
  flex: 0 0 auto;
  min-width: 44px;
  padding: 8px 10px;
}

.mn-theme-toggle-float {
  position: fixed;
  inset-block-start: 16px;
  inset-inline-end: 16px;
  z-index: 1000;
  padding: 9px 13px;
  box-shadow: var(--mn-theme-shadow);
}

/* Shell chrome and the simple, server-rendered pages. */
html[data-theme="dark"] body {
  background: linear-gradient(180deg, #0c1728 0%, var(--mn-theme-bg) 100%);
  color: var(--mn-theme-text);
}

html[data-theme="dark"] body .mobile-topbar,
html[data-theme="dark"] body .sidebar {
  background: rgb(12 23 39 / 96%);
  border-color: var(--mn-theme-border);
}

html[data-theme="dark"] body .brand {
  border-color: var(--mn-theme-border);
}

html[data-theme="dark"] body .shell-company-logo,
html[data-theme="dark"] body .mobile-company-logo {
  border-radius: 10px;
  background: rgb(255 255 255 / 92%);
  padding: 5px;
}

html[data-theme="dark"] body .shortcut-card {
  border-color: var(--mn-theme-border);
  background: linear-gradient(180deg, #17253a 0%, #101b2c 100%);
}

html[data-theme="dark"] body .group-title,
html[data-theme="dark"] body .hero p,
html[data-theme="dark"] body .menu-search svg,
html[data-theme="dark"] body .menu-child::before {
  color: var(--mn-theme-muted);
}

html[data-theme="dark"] body .menu-search {
  border-color: var(--mn-theme-border);
  background: rgb(16 27 44 / 97%);
}

html[data-theme="dark"] body .menu-section,
html[data-theme="dark"] body .menu-section > summary,
html[data-theme="dark"] body .menu-direct,
html[data-theme="dark"] body .menu-child {
  border-color: var(--mn-theme-border);
  background-color: var(--mn-theme-surface);
  color: var(--mn-theme-text);
}

html[data-theme="dark"] body .menu-section > summary:hover,
html[data-theme="dark"] body .menu-child:hover,
html[data-theme="dark"] body .menu-direct:hover {
  background-color: var(--mn-theme-surface-raised);
}

html[data-theme="dark"] body .panel,
html[data-theme="dark"] body .shell,
html[data-theme="dark"] body .card,
html[data-theme="dark"] body .box,
html[data-theme="dark"] body > main > section,
html[data-theme="dark"] body > .page > section.panel {
  border-color: var(--mn-theme-border);
  background-color: var(--mn-theme-surface);
  color: var(--mn-theme-text);
  box-shadow: var(--mn-theme-shadow);
}

html[data-theme="dark"] body .company,
html[data-theme="dark"] body .chip {
  border-color: #35577f;
  background: var(--mn-theme-primary-soft);
  color: #9bc8ff;
}

html[data-theme="dark"] body input,
html[data-theme="dark"] body select,
html[data-theme="dark"] body textarea {
  border-color: var(--mn-theme-border-strong);
  background-color: var(--mn-theme-input);
  color: var(--mn-theme-text);
}

html[data-theme="dark"] body input::placeholder,
html[data-theme="dark"] body textarea::placeholder {
  color: #8190a4;
  opacity: 1;
}

html[data-theme="dark"] body .secondary,
html[data-theme="dark"] body .link-button,
html[data-theme="dark"] body .button:not(.primary):not(.danger) {
  border-color: var(--mn-theme-border-strong);
  background: var(--mn-theme-surface-raised);
  color: var(--mn-theme-link);
}

html[data-theme="dark"] body > .page :is(.status, .muted, .shell p),
html[data-theme="dark"] body > .box p {
  color: var(--mn-theme-muted) !important;
}

html[data-theme="dark"] body .topbar .theme-toggle {
  border-color: var(--mn-theme-border-strong);
  background: var(--mn-theme-surface);
  color: var(--mn-theme-text);
}

html[data-theme="dark"] body > main .status {
  border-color: var(--mn-theme-border-strong);
  background: var(--mn-theme-primary-soft);
}

html[data-theme="dark"] body > main th {
  border-color: var(--mn-theme-border);
  background: #17253a;
  color: var(--mn-theme-text);
}

html[data-theme="dark"] body .button.danger {
  border-color: #7b3c42;
  background: var(--danger-soft);
  color: var(--danger);
}

html[data-theme="dark"] body .notice.info {
  border-color: #35577f;
  background: var(--mn-theme-primary-soft);
  color: #9bc8ff;
}

html[data-theme="dark"] body .table-wrap {
  border-color: var(--mn-theme-border);
  background: var(--mn-theme-surface-soft);
}

html[data-theme="dark"] body .table-wrap table th:not([class*="bg-"]),
html[data-theme="dark"] body .table-wrap table tfoot th:not([class*="bg-"]) {
  border-color: var(--mn-theme-border);
  background: #17253a;
  color: var(--mn-theme-text);
}

html[data-theme="dark"] body .table-wrap table td:not([class*="bg-"]) {
  border-color: var(--mn-theme-border);
  color: var(--mn-theme-text);
}

html[data-theme="dark"] body .available-location-table tbody tr:nth-child(even):not(.damage-flag) {
  background: #132033;
}

html[data-theme="dark"] body .available-location-table tbody tr:hover:not(.damage-flag) {
  background: #1b2d46;
}

html[data-theme="dark"] body tr.sold {
  background: rgb(22 101 52 / 34%);
}

/* Access-control page. Semantic notice and badge palettes continue to use
   their success/warning/danger variables. */
html[data-theme="dark"] body {
  --success-soft: #102c25;
  --danger-soft: #321b20;
  --warning-soft: #332816;
  --success: #62d6a7;
  --danger: #ff9891;
  --warning: #f7c66b;
}

html[data-theme="dark"] body .hero.card,
html[data-theme="dark"] body .metric.card,
html[data-theme="dark"] body .directory.card,
html[data-theme="dark"] body .editor.card,
html[data-theme="dark"] body .create-card,
html[data-theme="dark"] body .devices-card {
  border-color: var(--mn-theme-border);
  background: var(--mn-theme-surface);
}

html[data-theme="dark"] body .user-item,
html[data-theme="dark"] body .setting,
html[data-theme="dark"] body .role-chip,
html[data-theme="dark"] body .create-body,
html[data-theme="dark"] body .devices-table-wrap {
  border-color: var(--mn-theme-border);
  background: var(--mn-theme-surface-soft);
  color: var(--mn-theme-text);
}

html[data-theme="dark"] body .user-item.selected {
  border-color: var(--mn-theme-link);
  background: var(--mn-theme-primary-soft);
}

html[data-theme="dark"] body .devices-table th {
  background: #17253a;
  color: var(--mn-theme-text);
}

html[data-theme="dark"] body .devices-table td {
  border-color: var(--mn-theme-border);
}

/* Cars.Master floating widgets. */
html[data-theme="dark"] body .mn-cars-shell-widget,
html[data-theme="dark"] body .mn-cars-shell-widget[data-widget="performance"] .mn-cars-shell-widget__header,
html[data-theme="dark"] body .mn-cars-shell-widget__header {
  border-color: var(--mn-theme-border);
  background: var(--mn-theme-surface);
  color: var(--mn-theme-text);
}

html[data-theme="dark"] body .mn-cars-shell-widget[data-widget="statistics"] .mn-cars-shell-widget__header {
  background: #175fbd;
  color: #ffffff;
}

html[data-theme="dark"] body .mn-cars-shell-widget__state,
html[data-theme="dark"] body .mn-cars-shell-call-count,
html[data-theme="dark"] body .mn-cars-shell-missed-calls,
html[data-theme="dark"] body .mn-cars-shell-performance__summary {
  border-color: var(--mn-theme-border);
  background: var(--mn-theme-surface-soft);
  color: var(--mn-theme-text);
}

html[data-theme="dark"] body .mn-cars-shell-stat-row + .mn-cars-shell-stat-row,
html[data-theme="dark"] body .mn-cars-shell-missed-call {
  border-color: var(--mn-theme-border);
}

html[data-theme="dark"] body .mn-cars-shell-stat-row__count,
html[data-theme="dark"] body .mn-cars-shell-stat-row__numbers,
html[data-theme="dark"] body .mn-cars-shell-call-count span,
html[data-theme="dark"] body .mn-cars-shell-missed-calls__title,
html[data-theme="dark"] body .mn-cars-shell-missed-calls__message,
html[data-theme="dark"] body .mn-cars-shell-missed-call__number,
html[data-theme="dark"] body .mn-cars-shell-missed-call__time,
html[data-theme="dark"] body .mn-cars-shell-call-note,
html[data-theme="dark"] body .mn-cars-shell-performance__date {
  color: var(--mn-theme-muted);
}

html[data-theme="dark"] body .mn-cars-shell-stat-row__bar,
html[data-theme="dark"] body .mn-cars-shell-performance__progress {
  background: #314157;
}

html[data-theme="dark"] body .mn-cars-shell-performance__chart {
  background: conic-gradient(#e94a5b var(--mn-performance-percent), #314157 0);
}

html[data-theme="dark"] body .mn-cars-shell-performance__chart::before {
  background: var(--mn-theme-surface);
}

html[data-theme="dark"] body .mn-cars-shell-performance__chart strong {
  color: var(--mn-theme-text);
}

/* Module-owned variables: keep their brand/status colours, replace only the
   neutral ink, border and surface tokens. The #contentHost qualifier wins
   against CSS injected by the module after initial page load. */
html[data-theme="dark"] body #contentHost .customer-sales-report-page {
  --csr-ink: var(--mn-theme-text);
  --csr-muted: var(--mn-theme-muted);
  --csr-line: var(--mn-theme-border);
  --csr-soft: var(--mn-theme-surface-soft);
  --csr-blue: #5aa5ff;
  --csr-blue-dark: #8fc4ff;
}

html[data-theme="dark"] body #contentHost .psp-page {
  --ink: var(--mn-theme-text);
  --muted: var(--mn-theme-muted);
  --line: var(--mn-theme-border);
  --soft: var(--mn-theme-surface-soft);
}

html[data-theme="dark"] body #contentHost .vsm-page {
  --vsm-ink: var(--mn-theme-text);
  --vsm-muted: var(--mn-theme-muted);
  --vsm-line: var(--mn-theme-border);
  --vsm-soft: var(--mn-theme-surface-soft);
}

html[data-theme="dark"] body #contentHost .sbpq-root {
  --ink: var(--mn-theme-text);
  --muted: var(--mn-theme-muted);
  --line: var(--mn-theme-border);
  --blue: #72afff;
}

html[data-theme="dark"] body #contentHost .sbr-page {
  --sbr-ink: var(--mn-theme-text);
  --sbr-muted: var(--mn-theme-muted);
  --sbr-line: var(--mn-theme-border);
  --sbr-soft: var(--mn-theme-surface-soft);
}

html[data-theme="dark"] body #contentHost .sbb-page {
  --sbb-ink: var(--mn-theme-text);
  --sbb-muted: var(--mn-theme-muted);
  --sbb-line: var(--mn-theme-border);
  --sbb-soft: var(--mn-theme-surface-soft);
}

html[data-theme="dark"] body #contentHost .scbq-page {
  --scbq-ink: var(--mn-theme-text);
  --scbq-muted: var(--mn-theme-muted);
  --scbq-line: var(--mn-theme-border);
  --scbq-soft: var(--mn-theme-surface-soft);
}

html[data-theme="dark"] body #contentHost .wca-page {
  --wca-ink: var(--mn-theme-text);
  --wca-muted: var(--mn-theme-muted);
  --wca-line: var(--mn-theme-border);
  --wca-soft: var(--mn-theme-surface-soft);
}

html[data-theme="dark"] body #contentHost .so-page {
  --border: var(--mn-theme-border);
  --muted: var(--mn-theme-muted);
  color: var(--mn-theme-text);
}

/* Neutral surfaces in custom report modules. Status-specific classes are
   intentionally omitted so success, warning and danger remain recognisable. */
html[data-theme="dark"] body #contentHost :is(
  .customer-sales-report-filter,
  .customer-sales-report-results-head,
  .customer-sales-report-card,
  .customer-sales-report-table-wrap,
  .customer-sales-report-option,
  .psp-panel,
  .psp-card,
  .psp-card-month,
  .vsm-panel,
  .vsm-results-panel,
  .vsm-card,
  .sbr-panel,
  .sbr-card,
  .sbr-attachment-panel,
  .sbr-mobile-vehicle,
  .sbb-panel,
  .sbb-card,
  .wca-panel,
  .wca-section,
  .wca-chart,
  .wca-details,
  .wca-rank,
  .wca-breakdown-item,
  .sbpq-panel,
  .sbpq-kpi:not(.good):not(.warn):not(.danger),
  .sbpq-mobile-card,
  .sbpq-dialog,
  .sbpq-section-card,
  .sbpq-movement-card:not(.invalid),
  .so-summary article,
  .so-card,
  .so-customer,
  .so-dialog,
  .so-detail-grid > div,
  .so-file
) {
  border-color: var(--mn-theme-border) !important;
  background: var(--mn-theme-surface) !important;
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost :is(
  .customer-sales-report-input,
  .psp-field input,
  .psp-field select,
  .psp-search,
  .vsm-field input,
  .vsm-search,
  .sbr-field input,
  .sbb-field input,
  .sbb-field select,
  .wca-field input,
  .sbpq-field input,
  .sbpq-field select,
  .sbpq-form-grid input,
  .sbpq-form-grid select,
  .sbpq-form-grid textarea,
  .sbpq-allocation-table input,
  .so-field input,
  .so-field select,
  .so-field textarea,
  .so-inline-select,
  .so-order-search input
) {
  border-color: var(--mn-theme-border-strong) !important;
  background: var(--mn-theme-input) !important;
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost :is(
  .psp-table caption,
  .psp-table th,
  .psp-table td,
  .vsm-table th,
  .vsm-table td,
  .sbr-table caption,
  .sbr-table th,
  .sbr-table td,
  .sbb-table caption,
  .sbb-table th,
  .sbb-table td,
  .wca-table th,
  .wca-table td,
  .sbpq-table th,
  .sbpq-table td,
  .sbpq-movement-table th,
  .sbpq-movement-table td,
  .sbpq-allocation-table th,
  .sbpq-allocation-table td,
  .so-orders-table th,
  .so-orders-table td
) {
  border-color: var(--mn-theme-border) !important;
  background-color: var(--mn-theme-surface) !important;
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost :is(
  .psp-table thead th,
  .vsm-table thead th,
  .sbr-table thead th,
  .sbb-table thead th,
  .wca-table thead th,
  .sbpq-table th,
  .sbpq-movement-table th,
  .sbpq-allocation-table th,
  .so-orders-table th
) {
  background-color: #17253a !important;
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost :is(
  .psp-table .psp-group-cell,
  .psp-card-month,
  .vsm-kpi,
  .sbr-kpi,
  .sbr-card-value,
  .sbb-kpi,
  .wca-kpi,
  .sbpq-dialog-summary > div,
  .sbpq-distributed-totals > div,
  .so-tabs,
  .so-detail-grid > div
) {
  border-color: var(--mn-theme-border) !important;
  background: var(--mn-theme-surface-soft) !important;
}

html[data-theme="dark"] body #contentHost :is(
  .psp-btn:not(.primary),
  .vsm-btn:not(.primary),
  .sbr-btn:not(.primary),
  .sbb-btn:not(.primary),
  .wca-btn:not(.primary),
  .sbpq-btn.secondary,
  .so-secondary,
  .so-mini-btn,
  .so-icon-btn,
  .so-status-tab,
  .so-pagination button
) {
  border-color: var(--mn-theme-border-strong) !important;
  background: var(--mn-theme-surface-raised) !important;
  color: var(--mn-theme-link) !important;
}

html[data-theme="dark"] body #contentHost .so-tab.active,
html[data-theme="dark"] body #contentHost .so-customer.active,
html[data-theme="dark"] body #contentHost .so-selected,
html[data-theme="dark"] body #contentHost .so-readonly-notice {
  border-color: #355b88 !important;
  background: var(--mn-theme-primary-soft) !important;
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost .so-orders-table tr {
  border-color: var(--mn-theme-border);
}

html[data-theme="dark"] body #contentHost .sbpq-dialog-actions,
html[data-theme="dark"] body #contentHost .sbpq-workspace-actions {
  border-color: var(--mn-theme-border);
  background: var(--mn-theme-surface);
}

html[data-theme="dark"] body #contentHost .wca-chart-grid {
  stroke: #34465c;
}

html[data-theme="dark"] body #contentHost .wca-chart-label {
  fill: var(--mn-theme-muted);
}

html[data-theme="dark"] body #contentHost .wca-line-total {
  stroke: #e6eef8;
}

html[data-theme="dark"] body #contentHost a {
  color: var(--mn-theme-link);
}

/* The three primary Cars screens are deliberately covered explicitly. Their
   module CSS is injected after this stylesheet and historically used fixed
   light colours. Price bands and business-state classes are not neutralised. */
html[data-theme="dark"] body #contentHost :is(
  .cars-summary span,
  .mini-link,
  .legacy-summary-card,
  .cars-table-wrap,
  .details-row td,
  .detail-item,
  .sold-chart-panel,
  .sold-chart-summary span,
  .sold-chart-empty,
  .car-details-shell,
  .car-detail-gallery,
  .car-detail-no-image,
  .car-detail-meta span,
  .car-detail-feature,
  .mn20-dialog,
  .sold-prices-dialog,
  .dialog-topbar
) {
  border-color: var(--mn-theme-border) !important;
  background: var(--mn-theme-surface) !important;
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost :where(
  .legacy-summary-table th,
  .legacy-summary-table td,
  .cars-price-table th:not(.bg-cost):not(.bg-broker):not(.bg-cash):not(.bg-bank):not(.bg-gold),
  .cars-price-table td:not(.bg-cost):not(.bg-broker):not(.bg-cash):not(.bg-bank):not(.bg-gold),
  .sold-prices-table th,
  .sold-prices-table td
) {
  border-color: var(--mn-theme-border) !important;
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost :where(
  .legacy-summary-table thead th,
  .cars-price-table th:not(.bg-cost):not(.bg-broker):not(.bg-cash):not(.bg-bank):not(.bg-gold),
  .sold-prices-table th
) {
  background: #17253a !important;
}

html[data-theme="dark"] body #contentHost .cars-price-table thead th.bg-cost {
  background: #3b2028 !important;
  color: #ffd7dc !important;
  border-color: var(--mn-theme-border) !important;
}

html[data-theme="dark"] body #contentHost .cars-price-table thead th.bg-broker {
  background: #15372c !important;
  color: #c9f9df !important;
  border-color: var(--mn-theme-border) !important;
}

html[data-theme="dark"] body #contentHost .cars-price-table thead th.bg-cash {
  background: #0f4939 !important;
  color: #d2ffec !important;
  border-color: var(--mn-theme-border) !important;
}

html[data-theme="dark"] body #contentHost .cars-price-table thead th.bg-bank {
  background: #123b68 !important;
  color: #d9ecff !important;
  border-color: var(--mn-theme-border) !important;
}

html[data-theme="dark"] body #contentHost .cars-price-table thead th.bg-gold {
  background: #4b3b16 !important;
  color: #fff1b8 !important;
  border-color: var(--mn-theme-border) !important;
}

html[data-theme="dark"] body #contentHost .legacy-summary-table tbody :is(th, td) {
  background: var(--mn-theme-surface) !important;
}

html[data-theme="dark"] body #contentHost :is(.detail-item span, .sold-chart-legend) {
  color: var(--mn-theme-muted) !important;
}

html[data-theme="dark"] body #contentHost .detail-item b,
html[data-theme="dark"] body #contentHost .car-detail-feature div {
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost :is(.mn20-price-eye, .mn20-action, .dialog-close-top) {
  border-color: var(--mn-theme-border-strong) !important;
  background: var(--mn-theme-surface-raised) !important;
  color: var(--mn-theme-link) !important;
}

html[data-theme="dark"] body #contentHost .details-toggle {
  background: var(--mn-theme-primary-soft) !important;
  color: var(--mn-theme-link) !important;
}

@media screen {
  /* Include coloured price cells: the module's light hover also targets them. */
  html[data-theme="dark"] body #contentHost .sold-price-row:hover td {
    background: #1a3150 !important;
  }

  html[data-theme="dark"] body #contentHost .sold-price-row.selected-row td {
    background: #23446a !important;
  }

  html[data-theme="dark"] body #contentHost .sold-price-row:hover td.bg-cost {
    background: #402834 !important;
  }

  html[data-theme="dark"] body #contentHost .sold-price-row.selected-row td.bg-cost {
    background: #4b303c !important;
  }

  html[data-theme="dark"] body #contentHost .sold-price-row:hover td.bg-cash {
    background: #12483e !important;
  }

  html[data-theme="dark"] body #contentHost .sold-price-row.selected-row td.bg-cash {
    background: #17584b !important;
  }

  html[data-theme="dark"] body #contentHost .sold-prices-table .ok {
    color: #4ade80 !important;
  }

  html[data-theme="dark"] body #contentHost .sold-prices-table .bad {
    color: #fda4af !important;
  }
}

html[data-theme="dark"] body #contentHost .sor-root {
  color: var(--mn-theme-text);
}

html[data-theme="dark"] body #contentHost :is(
  .sor-card,
  .sor-card-head,
  .sor-item-card,
  .sor-stat,
  .sor-sticky,
  .sor-dialog,
  .sor-dialog-head,
  .sor-dialog-body,
  .sor-print-menu,
  .sor-doc,
  .sor-doc-replace,
  .sor-doc-upload input[type="file"]
) {
  border-color: var(--mn-theme-border) !important;
  background: var(--mn-theme-surface) !important;
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost :is(
  .sor-field input,
  .sor-field select,
  .sor-field textarea,
  .sor-search input
) {
  border-color: var(--mn-theme-border-strong) !important;
  background: var(--mn-theme-input) !important;
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost :is(.sor-field label, .sor-detail strong) {
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost :is(.sor-muted, .sor-detail span, .sor-stat span, .sor-sticky span) {
  color: var(--mn-theme-muted) !important;
}

html[data-theme="dark"] body #contentHost :is(.sor-table th, .sor-table td) {
  border-color: var(--mn-theme-border) !important;
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost .sor-table th {
  background: #17253a !important;
}

html[data-theme="dark"] body #contentHost :is(.sor-total-row, .sor-tag:not(.red):not(.green):not(.gold)) {
  background: var(--mn-theme-primary-soft) !important;
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost .sor-secondary {
  background: var(--mn-theme-surface-raised) !important;
  color: var(--mn-theme-link) !important;
}

html[data-theme="dark"] body #contentHost .sor-print-menu a {
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost .sor-print-menu a:hover {
  background: var(--mn-theme-primary-soft) !important;
}

/* Qoyod posting queue: only neutral work surfaces are darkened. All ready,
   waiting, danger, success and reconciliation states retain their palettes. */
html[data-theme="dark"] body #contentHost :is(
  .scbq-panel,
  .scbq-card,
  .scbq-card-head,
  .scbq-summary-bar,
  .scbq-drawer,
  .scbq-drawer-head,
  .scbq-detail-section,
  .scbq-item-detail,
  .scbq-movement-card:not(.invalid),
  .scbq-evidence-host,
  .scbq-evidence-panel,
  .scbq-technical-disclosure,
  .scbq-financial-line:not(.excluded),
  .scbq-financial-footer,
  .scbq-sales-evidence-host,
  .scbq-sales-evidence-receipts,
  .scbq-draft-ack,
  .scbq-plate-command-grid > div,
  .scbq-primary-item:not(.blocked):not(.review),
  .scbq-item-purchase-summary:not(.blocked):not(.review),
  .scbq-sales-evidence-summary > div:not(.completion),
  .scbq-financial-footer > div:not(.plate-fees):not(.scbq-financial-total-state)
) {
  border-color: var(--mn-theme-border) !important;
  background: var(--mn-theme-surface) !important;
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost :is(
  .scbq-field input,
  .scbq-field select,
  .scbq-toolbar input,
  .scbq-toolbar select,
  .scbq-draft-ack input[type="text"],
  .scbq-plate-unlink-reason textarea
) {
  border-color: var(--mn-theme-border-strong) !important;
  background: var(--mn-theme-input) !important;
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost :is(
  .scbq-check,
  .scbq-detail,
  .scbq-reconcile-strip,
  .scbq-reconcile-strip div,
  .scbq-technical-body,
  .scbq-financial-line:not(.excluded),
  .scbq-sales-evidence-receipt
) {
  border-color: var(--mn-theme-border) !important;
  background: var(--mn-theme-surface-soft) !important;
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost :is(
  .scbq-table th,
  .scbq-table td,
  .scbq-vehicle-table th,
  .scbq-vehicle-table td,
  .scbq-alloc-table th,
  .scbq-alloc-table td
) {
  border-color: var(--mn-theme-border) !important;
}

html[data-theme="dark"] body #contentHost :is(.scbq-table th, .scbq-alloc-table th) {
  background: #17253a;
  color: var(--mn-theme-text);
}

/* Posting status panels need paired dark surfaces/text, including nested labels. */
html[data-theme="dark"] body #contentHost .scbq-page :is(
  .scbq-plate-settlement, .scbq-financial-footer .plate-fees,
  .scbq-financial-total-state.short, .scbq-sales-sequence.waiting,
  .scbq-draft-panel.warning, .scbq-plate-command.warning, .scbq-plate-command.confirm,
  .scbq-alloc-gate
) {
  --scbq-muted: #dfcba6;
  background: #302719 !important;
  border-color: #846b38 !important;
  color: #ffe0a3 !important;
}
html[data-theme="dark"] body #contentHost .scbq-page :is(
  .scbq-plate-settlement.posted, .scbq-financial-total-state.matched,
  .scbq-sales-sequence.complete, .scbq-draft-panel.ready, .scbq-draft-panel.success,
  .scbq-plate-command.success
) {
  --scbq-muted: #b1d6c4;
  background: #17382e !important;
  border-color: #39795f !important;
  color: #a5efd0 !important;
}
html[data-theme="dark"] body #contentHost .scbq-page :is(
  .scbq-sales-sequence.review, .scbq-financial-total-state.review
) {
  --scbq-muted: #d0c4ed;
  background: #2b2544 !important;
  border-color: #6e5b96 !important;
  color: #e3d5ff !important;
}
html[data-theme="dark"] body #contentHost .scbq-page :is(
  .scbq-plate-settlement.ambiguous, .scbq-plate-settlement.configurationMissing,
  .scbq-financial-total-state.over, .scbq-sales-sequence.action,
  .scbq-draft-panel.danger, .scbq-plate-command.danger
) {
  --scbq-muted: #e8c0c3;
  background: #40252b !important;
  border-color: #a65d68 !important;
  color: #ffd0d5 !important;
}
html[data-theme="dark"] body #contentHost .scbq-page :is(
  .scbq-draft-panel.progress, .scbq-plate-command.progress, .scbq-plate-command:not(.success):not(.danger):not(.warning):not(.confirm)
) {
  --scbq-muted: #b9d6ed;
  background: #193449 !important;
  border-color: #467b9b !important;
  color: #d1edff !important;
}
html[data-theme="dark"] body #contentHost .scbq-page .scbq-draft-panel.warning > :is(h3,p) {
  color: #ffe0a3 !important;
}
html[data-theme="dark"] body #contentHost .scbq-page .scbq-primary-purchase.natural { color: #d8beff; }
html[data-theme="dark"] body #contentHost .scbq-page .scbq-primary-purchase.ok { color: #9de6bd; }
html[data-theme="dark"] body #contentHost .scbq-page .scbq-primary-purchase.blocked { color: #ffb4bd; }
html[data-theme="dark"] body #contentHost .scbq-page .scbq-primary-purchase.review { color: #ffda94; }
html[data-theme="dark"] body #contentHost .scbq-page .scbq-card-section h4 {
  color: #c5d6e8; font-size: .95rem;
}
html[data-theme="dark"] body #contentHost .scbq-page :is(
  .scbq-plate-settlement small, .scbq-financial-footer small, .scbq-sales-sequence small,
  .scbq-primary-purchase small, .scbq-primary-vin small
) { color: var(--scbq-muted); font-size: .82rem; line-height: 1.6; }
html[data-theme="dark"] body #contentHost .scbq-page .scbq-btn:not(.primary):not(.danger) {
  background: #23364e !important;
  border-color: #65809d !important;
  color: #edf5ff !important;
}

/* Common legacy-parity modules which still define light neutrals locally. */
html[data-theme="dark"] body #contentHost :is(
  .as-page,
  .em-page,
  .fr-page,
  .fin-page,
  .ci-root,
  .customer-vat-page,
  .order-report-page,
  .damage-management-page,
  .invoice-dates-page,
  .movement-date-page,
  .movement-ledger-page,
  .inventory-qr-page,
  .vehicle-details-page,
  .price-analysis-page,
  .vehicle-plates-page,
  .vehicle-search-page,
  .sales-undispatched-page
) {
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost :is(
  .as-card, .as-stat, .as-filter,
  .em-card, .em-stat, .em-dialog,
  .fr-card, .fr-hero, .fr-field,
  .fin-card, .fin-stat, .fin-dialog,
  .ci-card, .ci-stat, .ci-hero,
  .customer-vat-card, .customer-vat-panel, .customer-vat-hero,
  .order-report-hero, .order-report-item-card, .order-report-summary,
  .damage-management-evidence-card, .damage-management-evidence-panel,
  .invoice-dates-hero, .invoice-dates-stat,
  .movement-date-card, .movement-ledger-card, .movement-ledger-hero, .movement-ledger-stat,
  .inventory-qr-card, .inventory-qr-hero, .inventory-qr-preview-card,
  .vehicle-details-card, .price-analysis-card, .price-analysis-panel, .price-analysis-hero,
  .vehicle-plates-card, .vehicle-plates-hero, .vehicle-plates-search-panel,
  .vehicle-search-card
) {
  border-color: var(--mn-theme-border) !important;
  background: var(--mn-theme-surface) !important;
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost :is(
  .as-field input, .as-field select,
  .em-field input, .em-field select, .em-tools input, .em-tools select,
  .fr-form input, .fr-form select,
  .fin-field input, .fin-field select, .fin-field textarea,
  .ci-field input, .ci-field select, .ci-field textarea,
  .customer-vat-field input, .customer-vat-field select,
  .order-report-field input, .order-report-field select,
  .invoice-dates-field input, .invoice-dates-field select,
  .movement-date-field input, .movement-date-field select,
  .movement-ledger-field input, .movement-ledger-field select,
  .inventory-qr-field input, .inventory-qr-field select,
  .price-analysis-field input, .price-analysis-field select,
  .vehicle-plates-field input, .vehicle-plates-field select,
  .vehicle-search-field input, .vehicle-search-field select
) {
  border-color: var(--mn-theme-border-strong) !important;
  background: var(--mn-theme-input) !important;
  color: var(--mn-theme-text) !important;
}

html[data-theme="dark"] body #contentHost :is(
  .as-table th, .as-table td,
  .em-table th, .em-table td,
  .fr-table th, .fr-table td,
  .fin-table th, .fin-table td,
  .ci-table th, .ci-table td,
  .customer-vat-table th, .customer-vat-table td,
  .order-report-table th, .order-report-table td,
  .damage-management-table th, .damage-management-table td,
  .invoice-dates-table th, .invoice-dates-table td,
  .movement-date-table th, .movement-date-table td,
  .movement-ledger-table th, .movement-ledger-table td,
  .inventory-qr-table th, .inventory-qr-table td,
  .vehicle-details-table th, .vehicle-details-table td,
  .price-analysis-table th, .price-analysis-table td,
  .vehicle-plates-table th, .vehicle-plates-table td,
  .vehicle-search-table th, .vehicle-search-table td,
  .sales-undispatched-table th, .sales-undispatched-table td
) {
  border-color: var(--mn-theme-border) !important;
}

html[data-theme="dark"] body #contentHost :is(
  .as-table th, .em-table th, .fr-table th, .fin-table th, .ci-table th,
  .customer-vat-table th, .order-report-table th, .damage-management-table th,
  .invoice-dates-table th, .movement-date-table th, .movement-ledger-table th,
  .inventory-qr-table th, .vehicle-details-table th, .price-analysis-table th,
  .vehicle-plates-table th, .vehicle-search-table th, .sales-undispatched-table th
) {
  background: #17253a !important;
  color: var(--mn-theme-text) !important;
}

/* Customer edit labels and section headings need the same theme as their cards. */
html[data-theme="dark"] body #contentHost .ci-root .ci-card-head {
  background: var(--mn-theme-surface-raised);
  border-color: var(--mn-theme-border);
  color: var(--mn-theme-text);
}

html[data-theme="dark"] body #contentHost .ci-root :is(.ci-card-head h3, .ci-field label) {
  color: var(--mn-theme-text);
}

html[data-theme="dark"] body #contentHost .ci-root :is(.ci-stat span, .ci-field small, .ci-empty) {
  color: var(--mn-theme-muted);
}

html[data-theme="dark"] body #contentHost .ci-root .ci-line {
  border-color: var(--mn-theme-border-strong);
}

html[data-theme="dark"] body #contentHost .ci-root .ci-positive {
  color: #6ee7b7;
}

html[data-theme="dark"] body #contentHost .ci-root .ci-negative {
  color: #fda4af;
}

html[data-theme="dark"] body #contentHost .ci-root .ci-table a {
  color: var(--mn-theme-link);
}

@media (prefers-reduced-motion: reduce) {
  body,
  .mobile-topbar,
  .sidebar,
  .panel,
  .mn-cars-shell-widget {
    transition: none;
  }
}

/* Reports, tax forms, invoices and any browser print preview remain white. */
@media print {
  :root,
  html[data-theme="dark"] {
    color-scheme: light !important;
    --mn-theme-bg: #ffffff !important;
    --mn-theme-surface: #ffffff !important;
    --mn-theme-surface-soft: #f8fafc !important;
    --mn-theme-surface-raised: #ffffff !important;
    --mn-theme-border: #d9e2ef !important;
    --mn-theme-border-strong: #b9c8da !important;
    --mn-theme-text: #111827 !important;
    --mn-theme-muted: #667085 !important;
    --mn-theme-link: #1368d6 !important;
    --mn-theme-primary-soft: #eef4ff !important;
    --mn-theme-input: #ffffff !important;
    --mn-theme-shadow: none !important;
    --bg: #ffffff !important;
    --surface: #ffffff !important;
    --surface-soft: #ffffff !important;
    --border: #d9e2ef !important;
    --text: #111827 !important;
    --muted: #667085 !important;
  }

  html,
  html[data-theme="dark"] body,
  html[data-theme="dark"] body #contentHost,
  html[data-theme="dark"] body #contentHost * {
    color-scheme: light !important;
  }

  html[data-theme="dark"] body {
    --success: #087a55 !important;
    --success-soft: #eaf8f1 !important;
    --warning: #9a5b00 !important;
    --warning-soft: #fff7e8 !important;
    --danger: #b42318 !important;
    --danger-soft: #fff0ef !important;
    background: #ffffff !important;
    color: #111827 !important;
  }

  html[data-theme="dark"] body #contentHost :is(
    .table-wrap table th:not([class*="bg-"]),
    .psp-table thead th,
    .vsm-table thead th,
    .sbr-table thead th,
    .sbb-table thead th,
    .wca-table thead th,
    .sbpq-table th,
    .sbpq-movement-table th,
    .sbpq-allocation-table th,
    .so-orders-table th,
    .legacy-summary-table thead th,
    .cars-price-table th:not([class*="bg-"]),
    .sold-prices-table th,
    .sor-table th,
    .scbq-table th,
    .scbq-alloc-table th,
    .as-table th,
    .em-table th,
    .fr-table th,
    .fin-table th,
    .ci-table th,
    .customer-vat-table th,
    .order-report-table th,
    .damage-management-table th,
    .invoice-dates-table th,
    .movement-date-table th,
    .movement-ledger-table th,
    .inventory-qr-table th,
    .vehicle-details-table th,
    .price-analysis-table th,
    .vehicle-plates-table th,
    .vehicle-search-table th,
    .sales-undispatched-table th
  ) {
    background: #f8fafc !important;
    color: #111827 !important;
    border-color: #d9e2ef !important;
    text-shadow: none !important;
  }

  html[data-theme="dark"] body :is(
    .table-wrap table th:not([class*="bg-"]),
    .devices-table th
  ) {
    background: #f8fafc !important;
    color: #111827 !important;
    border-color: #d9e2ef !important;
  }

  html[data-theme="dark"] body #contentHost :is(
    .sold-price-row:hover td:not([class*="bg-"]),
    .sold-price-row.selected-row td:not([class*="bg-"]),
    .legacy-summary-table tbody th,
    .legacy-summary-table tbody td
  ) {
    background: #ffffff !important;
    color: #111827 !important;
  }

  html[data-theme="dark"] body .available-location-table tbody tr:nth-child(even):not(.damage-flag),
  html[data-theme="dark"] body .available-location-table tbody tr:hover:not(.damage-flag) {
    background: #ffffff !important;
    color: #111827 !important;
  }

  html[data-theme="dark"] body :is(
    .mn-cars-shell-stat-row__bar,
    .mn-cars-shell-performance__progress
  ) {
    background: #e5e7eb !important;
  }

  html[data-theme="dark"] body .mn-cars-shell-performance__chart {
    background: conic-gradient(
      #e52b3f var(--mn-performance-percent),
      #e5e7eb 0
    ) !important;
  }

  html[data-theme="dark"] body .mn-cars-shell-performance__chart::before {
    background: #ffffff !important;
  }

  .theme-toggle,
  .mn-theme-toggle-float {
    display: none !important;
  }
}

/* Shared readable text and inventory price bands (screen only). */
@media screen {
  html[data-theme] { --muted: var(--mn-theme-muted); }
  html[data-theme] body :is(.muted, .text-muted) { color: var(--mn-theme-muted); }
  html[data-theme] body input::placeholder,
  html[data-theme] body textarea::placeholder { color: var(--mn-theme-muted); opacity: 1; }
  html[data-theme] body #contentHost :is(.cars-price-table, .legacy-summary-table) {
    color: var(--mn-theme-text); font-size: 15px; line-height: 1.6;
  }
  html[data-theme] body #contentHost .cars-price-table th { font-weight: 700; }
  html[data-theme] body #contentHost .cars-price-table td { color: var(--mn-theme-text); }
  html[data-theme] body #contentHost :is(.cars-price-table, .legacy-summary-table) .muted {
    color: var(--mn-theme-muted) !important;
  }
  html[data-theme] body #contentHost .legacy-summary-updated {
    color: var(--mn-theme-muted); background: var(--mn-theme-surface); font-size: 13px;
  }
  html[data-theme="light"] body #contentHost .legacy-summary-table :is(th, td) { color: #1d2939; }
  html[data-theme] body #contentHost .legacy-summary-table .summary-total {
    background: #147d4e !important; color: #fff !important;
  }
  html[data-theme] body #contentHost .legacy-summary-table .summary-need {
    background: #bd2039 !important; color: #fff !important;
  }
  html[data-theme="light"] body #contentHost .legacy-summary-table :is(.summary-cost, .summary-warning) { color: #b42318 !important; }
  html[data-theme="light"] body #contentHost .legacy-summary-table .summary-link { color: #175cd3 !important; }
  html[data-theme="dark"] body #contentHost .legacy-summary-table :is(.summary-cost, .summary-warning) { color: #ffaaa2 !important; }
  html[data-theme="dark"] body #contentHost .legacy-summary-table .summary-link { color: #91c4ff !important; }
  html[data-theme="light"] body #contentHost :is(.cars-price-table, .legacy-summary-table) .ok { color: #027a48 !important; }
  html[data-theme="light"] body #contentHost :is(.cars-price-table, .legacy-summary-table) .bad { color: #b42318 !important; }
  html[data-theme="dark"] body #contentHost :is(.cars-price-table, .legacy-summary-table) .ok { color: #75e0b0 !important; }
  html[data-theme="dark"] body #contentHost :is(.cars-price-table, .legacy-summary-table) .bad { color: #ffaaa2 !important; }
  html[data-theme="dark"] body #contentHost .cars-price-table :is(th, td).bg-cost { background: #3b2028 !important; color: #ffe4e8 !important; }
  html[data-theme="dark"] body #contentHost .cars-price-table :is(th, td).bg-broker { background: #15372c !important; color: #dcfce7 !important; }
  html[data-theme="dark"] body #contentHost .cars-price-table :is(th, td).bg-cash { background: #0f4939 !important; color: #dcfce7 !important; }
  html[data-theme="dark"] body #contentHost .cars-price-table :is(th, td).bg-bank { background: #123b68 !important; color: #e0efff !important; }
  html[data-theme="dark"] body #contentHost .cars-price-table :is(th, td).bg-gold { background: #4b3b16 !important; color: #fff1b8 !important; }
}
