/* MSBA Controle v1.19.18 — camada isolada de aparência revisada.
   Este arquivo altera somente cores/contraste. Layout, medidas e regras de negócio
   permanecem no app.css. */

:root {
  --theme-surface-elevated: #ffffff;
  --theme-surface-soft: #f7fafc;
  --theme-surface-muted: #eef3f6;
  --theme-input: #ffffff;
  --theme-hover: #f8fbfd;
  --theme-strong-border: #c9d6df;
  --theme-focus-ring: rgba(23, 95, 147, .14);
  --theme-chart-text: #6d7a87;
  --theme-chart-grid: rgba(219, 227, 234, .78);
  --theme-chart-surface: #ffffff;
  --theme-scrollbar: #c8d5de;
  --theme-scrollbar-track: #edf2f5;
}

html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

html[data-theme="dark"] {
  /* A paleta navy permanece sendo a identidade/ação da MSBA.
     Texto e superfícies usam tokens próprios para não perder contraste. */
  --blue-100: #1b3749;
  --blue-50: #132b3b;
  --ink-900: #eef4f8;
  --ink-700: #c5d1da;
  --ink-500: #9aabb8;
  --ink-600: #aebcc7;
  --slate-400: #a8b7c2;
  --slate-500: #9aabb8;
  --slate-600: #c3d0d9;
  --line: #2a3d4b;
  --line-soft: #22333f;
  --line-strong: #39505f;
  --border: #2a3d4b;
  --surface: #131f28;
  --surface-soft: #172630;
  --surface-muted: #1b2a35;
  --surface-hover: #182934;
  --surface-accent-soft: #142b3a;
  --surface-accent-hover: #152631;
  --theme-strong-text: #f2f7fa;
  --theme-brand-text: #c8e5f6;
  --theme-accent-text: #8fd0f7;
  --theme-link-text: #69bde9;
  --text-color: #eef4f8;
  --muted-color: #9aabb8;
  --primary-700: #69bde9;
  --primary-600: #4d99ca;
  --text-muted: #9aabb8;
  --background: #0b141b;
  --success: #69d3a8;
  --success-bg: #102a21;
  --danger: #ff8794;
  --danger-bg: #35171d;
  --warning: #f6c66d;
  --warning-bg: #34270f;
  --shadow: 0 16px 38px rgba(0, 0, 0, .24);
  --theme-surface-elevated: #131f28;
  --theme-surface-soft: #172630;
  --theme-surface-muted: #1b2a35;
  --theme-input: #0f1a22;
  --theme-hover: #182934;
  --theme-strong-border: #39505f;
  --theme-focus-ring: rgba(106, 178, 223, .18);
  --theme-chart-text: #a9b9c5;
  --theme-chart-grid: rgba(78, 101, 117, .58);
  --theme-chart-surface: #131f28;
  --theme-scrollbar: #4b6272;
  --theme-scrollbar-track: #101b23;
}

html[data-theme="dark"],
html[data-theme="dark"] body {
  background: var(--background);
  color: var(--ink-900);
}

html[data-theme="dark"] body {
  accent-color: #4d99ca;
}

html[data-theme="dark"] ::selection {
  background: rgba(106, 178, 223, .32);
  color: #fff;
}

html[data-theme="dark"] * {
  scrollbar-color: var(--theme-scrollbar) var(--theme-scrollbar-track);
}

html[data-theme="dark"] .topbar {
  background: rgba(14, 25, 33, .92);
  border-bottom-color: var(--line);
  box-shadow: 0 8px 30px rgba(0,0,0,.12);
}

html[data-theme="dark"] .sidebar {
  background: linear-gradient(180deg, #041a2b, #082f4d);
  box-shadow: 10px 0 34px rgba(0,0,0,.24);
}

html[data-theme="dark"] .nav-link.active {
  background: rgba(105, 189, 233, .16);
  color: #eaf6fc;
  border: 1px solid rgba(105, 189, 233, .18);
  box-shadow: inset 3px 0 0 #69bde9;
}

html[data-theme="dark"] :is(.menu-toggle, .btn-secondary, .btn-icon) {
  background: var(--theme-surface-elevated);
  color: var(--ink-900);
  border-color: var(--line);
}

html[data-theme="dark"] .btn-secondary:hover,
html[data-theme="dark"] .btn-icon:hover {
  background: var(--theme-hover);
  border-color: var(--theme-strong-border);
}

html[data-theme="dark"] .btn-primary {
  background: #0b4a78;
  color: #fff;
  box-shadow: 0 8px 20px rgba(0,0,0,.22);
}
html[data-theme="dark"] .btn-primary:hover { background: #12618f; }

/* Superfícies principais. */
html[data-theme="dark"] :is(
  .panel,
  .stat-card,
  .metric-card,
  .chart-card,
  .quote-document,
  .product-status-card,
  .product-detail-meta,
  .purchase-shortcut,
  .analysis-method-chip,
  .period-tab,
  .quote-autosave-status,
  .quote-item-card,
  .supplier-offer-card,
  .supplier-comparison-item,
  .reminder-card,
  .revision-row,
  .dialog-card,
  .purchase-workflow-step,
  .topbar-user,
  .user-menu,
  .user-menu a,
  .user-menu button,
  .error-card,
  .saved-filter-card,
  .permission-preset,
  .quote-list-tabs,
  .purchase-advanced-actions,
  .purchase-advanced-actions-body,
  .purchase-order-card,
  .purchase-general-card,
  .logistics-order-card,
  .logistics-invoice-card,
  .report-kpi-card,
  .audit-log-card,
  .audit-log-entry,
  .system-maintenance-card
) {
  background: var(--theme-surface-elevated);
  color: var(--ink-900);
  border-color: var(--line);
}

/* Superfícies secundárias e cabeçalhos de cards/tabelas. */
html[data-theme="dark"] :is(
  th,
  .quote-customer,
  .dialog-card > footer,
  .quote-internal-summary > div,
  .supplier-comparison-item > header,
  .purchase-note,
  .purchase-order-summary > span,
  .readonly-field,
  .purchase-transition-form,
  .quote-batch-guide,
  .quote-detail-row > td,
  .permission-context-note,
  .purchase-logistics-summary > div,
  .purchase-summary-card,
  .audit-info-grid,
  .audit-log-details,
  .report-total-actions
) {
  background: var(--theme-surface-soft);
  border-color: var(--line);
  color: var(--ink-900);
}

html[data-theme="dark"] .dashboard-filter-panel {
  background: rgba(19,31,40,.94);
  border-color: var(--line);
  box-shadow: var(--shadow);
}

/* Campos e controles nativos. */
html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] .field input,
html[data-theme="dark"] .field select,
html[data-theme="dark"] .field textarea,
html[data-theme="dark"] .quote-items-table input,
html[data-theme="dark"] .quote-items-table select,
html[data-theme="dark"] .purchase-receipt-table input,
html[data-theme="dark"] .purchase-transition-form input,
html[data-theme="dark"] .filter-bar > input,
html[data-theme="dark"] .filter-bar > select,
html[data-theme="dark"] .search-field,
html[data-theme="dark"] .topbar-search > input {
  background: var(--theme-input) !important;
  color: var(--ink-900) !important;
  border-color: var(--theme-strong-border) !important;
}

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

html[data-theme="dark"] :is(input, select, textarea):focus,
html[data-theme="dark"] .topbar-search > input:focus {
  border-color: #5ea9d8 !important;
  box-shadow: 0 0 0 4px var(--theme-focus-ring) !important;
}

html[data-theme="dark"] :is(input[readonly], input:disabled, select:disabled, textarea:disabled),
html[data-theme="dark"] .purchase-general-form .field input[readonly] {
  background: #16232c !important;
  color: #9fb0bc !important;
  opacity: 1;
}

html[data-theme="dark"] option { background: #101b23; color: var(--ink-900); }

/* Tabelas, listas e separadores. */
html[data-theme="dark"] th { background: #172630 !important; color: #9eafbb; }
html[data-theme="dark"] td { border-bottom-color: #243541; }
html[data-theme="dark"] tbody tr:hover { background: #162630; }
html[data-theme="dark"] :is(
  .list-row,
  .profile-summary-list div,
  .search-result-row,
  .workspace-notification,
  .workspace-link-row,
  .user-menu a,
  .user-menu button,
  .product-history-row,
  .purchase-advanced-actions-body
) { border-color: #243541; }

html[data-theme="dark"] :is(.search-result-row:hover, .product-history-row:hover) { background: var(--theme-hover); }

/* Dropdowns, sugestões, notificações e modais. */
html[data-theme="dark"] :is(
  .global-search-suggestions,
  .notification-panel,
  .product-history-results,
  .quote-stage-more-menu,
  .actions-menu,
  .dropdown-menu
) {
  background: #111e27;
  color: var(--ink-900);
  border-color: var(--line);
  box-shadow: 0 24px 70px rgba(0,0,0,.38);
}

html[data-theme="dark"] .notification-panel header,
html[data-theme="dark"] .notification-panel footer,
html[data-theme="dark"] .global-search-suggestions header {
  background: #162630;
  border-color: var(--line);
}

html[data-theme="dark"] dialog::backdrop { background: rgba(2, 8, 13, .72); }

/* Estados semânticos: mantêm o significado sem usar fundos claros agressivos. */
html[data-theme="dark"] .notice.info,
html[data-theme="dark"] .badge-info { background: #102b3b; border-color: #28536b; color: #8fd2fa; }
html[data-theme="dark"] .notice.success { background: #102a21; border-color: #265542; color: #83dfb9; }
html[data-theme="dark"] .notice.warning,
html[data-theme="dark"] .workflow-locked-banner,
html[data-theme="dark"] .filter-result-note { background: #34270f; border-color: #685322; color: #f7cf82; }
html[data-theme="dark"] .notice.danger { background: #35171d; border-color: #6a3039; color: #ff9aa5; }
html[data-theme="dark"] .reminder-card.overdue,
html[data-theme="dark"] .purchase-row-late,
html[data-theme="dark"] .purchase-row-late:hover { background: #2e171b; border-color: #63313a; }

html[data-theme="dark"] .metric-trend.neutral,
html[data-theme="dark"] .metric-badge.neutral,
html[data-theme="dark"] .comparison-change.neutral { background: #22313b; color: #aab8c2; }

/* Compras / logística. */
html[data-theme="dark"] .purchase-workflow-step.is-current {
  background: linear-gradient(145deg, #152631, #13222c);
  border-color: #4b90ba;
  box-shadow: 0 14px 30px rgba(0,0,0,.2);
}
html[data-theme="dark"] .purchase-list-tabs a.active span { background: #dcebf4; color: #073c69; }
html[data-theme="dark"] .purchase-logistics-summary > .is-success { background: #102a21; border-color: #2c5b47; }
html[data-theme="dark"] .purchase-logistics-summary > .is-warning { background: #34270f; border-color: #685322; }
html[data-theme="dark"] .purchase-advanced-actions > summary:hover { background: var(--theme-hover); }

/* Cotações. */
html[data-theme="dark"] .quote-summary-values .grand { background: #062b47; }
html[data-theme="dark"] .quote-detail-observation,
html[data-theme="dark"] .supplier-empty-hint { background: var(--theme-surface-soft); border-color: var(--line); }
html[data-theme="dark"] .quote-stage-more-menu .quote-direct-manager-action { color: #f6bd75; background: #35240f; }
html[data-theme="dark"] .quote-stage-more-menu .quote-direct-manager-action:hover { background: #443014; }

/* Relatórios e dashboards. */
html[data-theme="dark"] :is(.report-user-table td.report-user-total, .comparison-table thead th) { background: #172630; }
html[data-theme="dark"] :is(.sales-podium-empty, .sales-podium-badges, .sales-podium-metrics) { color: var(--ink-900); }
html[data-theme="dark"] :is(.sales-podium-header h2, .sales-podium-badges strong, .sales-podium-metrics b) { color: #dceaf3; }

/* Auditoria. */
html[data-theme="dark"] .audit-impact-warning .audit-log-icon,
html[data-theme="dark"] .audit-impact-warning .audit-impact-badge { background: #34270f; color: #f5c46b; border-color: #685322; }
html[data-theme="dark"] .audit-impact-danger .audit-log-icon,
html[data-theme="dark"] .audit-impact-danger .audit-impact-badge { background: #35171d; color: #ff8e9a; border-color: #6a3039; }

/* Login segue o dispositivo, já que ainda não há usuário autenticado. */
html[data-theme="dark"] .login-body { background: var(--background); }
html[data-theme="dark"] .login-panel { background: #0d171f; }
html[data-theme="dark"] .login-card { color: var(--ink-900); }
html[data-theme="dark"] .login-logo { box-shadow: 0 18px 40px rgba(0,0,0,.3); }

/* Tela de perfil — seletor de aparência. */
.profile-section-divider {
  height: 1px;
  margin: 26px 0;
  background: var(--line);
}
.profile-appearance { display: grid; gap: 15px; }
.profile-appearance-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.profile-appearance-heading h2 { margin: 3px 0 4px; font-size: 1.05rem; }
.profile-appearance-heading p { margin: 0; color: var(--ink-500); font-size: .86rem; }
.theme-save-status { min-height: 22px; color: var(--success); font-size: .74rem; font-weight: 800; white-space: nowrap; }
.theme-save-status.is-error { color: var(--danger); }
.theme-preference-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.theme-preference-option {
  min-width: 0;
  padding: 12px;
  display: grid;
  grid-template-columns: 66px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease, background .18s ease;
}
.theme-preference-option:hover { transform: translateY(-1px); border-color: #9eb9ca; }
.theme-preference-option.is-selected { border-color: var(--navy-700); box-shadow: 0 0 0 3px rgba(23,95,147,.10); background: var(--blue-50); }
.theme-preference-option:has(input:disabled) { cursor: default; opacity: .7; transform: none; }
.theme-preference-option input { position: absolute; opacity: 0; pointer-events: none; }
.theme-option-copy { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.theme-option-copy strong { font-size: .85rem; }
.theme-option-copy small { color: var(--ink-500); font-size: .68rem; line-height: 1.4; }
.theme-preview { position: relative; width: 66px; height: 48px; overflow: hidden; display: block; border: 1px solid #c9d5dd; border-radius: 9px; background: #f4f7f9; box-shadow: inset 0 0 0 1px rgba(255,255,255,.4); }
.theme-preview::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 18px; background: #073c69; }
.theme-preview i { position: absolute; left: 23px; right: 5px; top: 5px; height: 7px; border-radius: 3px; background: #fff; border: 1px solid #dbe3ea; }
.theme-preview b, .theme-preview em { position: absolute; left: 23px; height: 12px; border-radius: 4px; background: #fff; border: 1px solid #dbe3ea; }
.theme-preview b { width: 17px; bottom: 6px; }
.theme-preview em { right: 5px; bottom: 6px; left: 43px; }
.theme-preview-dark { background: #0c151c; border-color: #38505f; }
.theme-preview-dark::before { background: #041a2b; }
.theme-preview-dark i, .theme-preview-dark b, .theme-preview-dark em { background: #172630; border-color: #2a3d4b; }
.theme-preview-auto { background: linear-gradient(90deg, #f4f7f9 50%, #0c151c 50%); }
.theme-preview-auto i { background: linear-gradient(90deg, #fff 50%, #172630 50%); }
.theme-preview-auto b { background: #fff; }
.theme-preview-auto em { background: #172630; border-color: #2a3d4b; }

html[data-theme="dark"] .theme-preference-option { background: #121f28; }
html[data-theme="dark"] .theme-preference-option.is-selected { background: #142b3a; box-shadow: 0 0 0 3px rgba(106,178,223,.11); }

@media (max-width: 1050px) {
  .theme-preference-grid { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .profile-appearance-heading { flex-direction: column; }
  .theme-save-status { white-space: normal; }
}

/* Impressões e PDFs permanecem claros independentemente da preferência. */
@media print {
  html[data-theme="dark"] {
    color-scheme: light !important;
    --ink-900: #18222d;
    --ink-700: #3f4d5b;
    --ink-500: #6d7a87;
    --line: #dbe3ea;
    --border: #dbe3ea;
    --surface: #ffffff;
    --surface-soft: #f7fafc;
    --background: #ffffff;
    --success: #1c7a55;
    --success-bg: #e8f6f0;
    --danger: #b42335;
    --danger-bg: #fcecee;
    --warning: #a45f08;
    --warning-bg: #fff3dd;
  }
  html[data-theme="dark"] body,
  html[data-theme="dark"] .panel,
  html[data-theme="dark"] .quote-document,
  html[data-theme="dark"] table,
  html[data-theme="dark"] th,
  html[data-theme="dark"] td {
    background: #fff !important;
    color: #18222d !important;
    border-color: #dbe3ea !important;
  }
}

/* Compatibilidade com componentes legados que ainda possuem cores claras fixas no app.css. */
html[data-theme="dark"] :is(
  .quote-supplier-add,
  .dialog-close,
  .quick-action-grid a,
  .quote-share-option,
  .page-size-form select,
  .pagination-button,
  .procurement-context-grid > div,
  .procurement-item,
  .quote-filter-control,
  .quote-inline-status-field select,
  .quote-stage-more > summary,
  .quote-stage-more-menu,
  .quote-history-section,
  .danger-zone-summary > div,
  .smart-combo-panel,
  .purchase-seller-card-body div,
  .purchase-seller-status-main,
  .purchase-international-row,
  .seller-action-follow,
  .logistics-compact-order,
  .purchase-general-row-card,
  .purchase-control-card,
  .purchase-card-items-list li,
  .purchase-card-items-empty,
  .report-tabs a,
  .sales-detail-compact-table tr,
  .sales-detail-split-table tr,
  .purchase-bulk-select-all,
  .purchase-bulk-count,
  .permission-module-card
) {
  background: var(--theme-surface-elevated) !important;
  color: var(--ink-900);
  border-color: var(--line) !important;
}

html[data-theme="dark"] :is(
  .procurement-item-footer,
  .procurement-summary > div,
  .granular-permission-card,
  .report-period-shortcuts button,
  .quote-batch-file-box,
  .smart-combo-empty,
  .logistics-toggle-indicator,
  .purchase-general-value-chip,
  .purchase-control-value,
  .purchase-card-items,
  .financial-report-table tfoot td,
  .sales-ranking-table tfoot td,
  .sales-detail-table tfoot td,
  .sales-detail-compact-table tfoot td,
  .audit-empty-state,
  .audit-impact-badge,
  .audit-change-field,
  .audit-info-grid > div,
  .purchase-control-details > summary:hover
) {
  background: var(--theme-surface-soft) !important;
  color: var(--ink-900);
  border-color: var(--line) !important;
}

html[data-theme="dark"] .dashboard-purchase-strip,
html[data-theme="dark"] .purchase-negotiator-summary-card {
  background: linear-gradient(145deg, #162630, #111e27) !important;
  border-color: var(--line) !important;
}

html[data-theme="dark"] .dashboard-purchase-late-list a {
  background: #22171b !important;
  border-color: #63313a !important;
}

html[data-theme="dark"] .topbar-search kbd {
  background: #182630;
  color: #aebdc8;
  border-color: #39505f;
}

html[data-theme="dark"] .notification-panel-item { background: #111e27; border-color: #243541; }
html[data-theme="dark"] .notification-panel-item:not(.is-read) { background: #162a37; }
html[data-theme="dark"] .notification-panel > footer { background: #162630; }

html[data-theme="dark"] .procurement-item.is-excluded { background: #121c23 !important; opacity: .76; }
html[data-theme="dark"] .procurement-batch-metrics > div { background: rgba(19,31,40,.88); border-color: var(--line); }

html[data-theme="dark"] :is(.badge-quote-waiting-budget, .badge-quote-supplier-sent, .badge-quote-msba-price) {
  background: #34270f !important;
  color: #f3cb7c !important;
  border-color: #685322 !important;
}

html[data-theme="dark"] .quote-stage-command { background: rgba(17,30,39,.97); border-color: var(--line); }
html[data-theme="dark"] .security-notice { background: #34270f; border-color: #685322; color: #f2ca79; }
html[data-theme="dark"] .danger-confirm-check { background: #2d181c; border-color: #65343c; }
html[data-theme="dark"] .purchase-general-filters .filter-date-field input { background: var(--theme-input) !important; }

html[data-theme="dark"] :is(.delivery-forecast-warning, .purchase-logistics-summary > .is-warning) {
  background: #34270f !important;
  color: #f4ce82;
  border-color: #685322 !important;
}
html[data-theme="dark"] .delivery-forecast-danger { background: #35171d !important; color: #ff9ca6; border-color: #6a3039 !important; }
html[data-theme="dark"] .soft-danger-zone .system-maintenance-icon.danger,
html[data-theme="dark"] .purchase-advanced-actions-icon { background: #35171d; color: #ff8e9a; }
html[data-theme="dark"] .seller-action-edit { background: var(--theme-surface-soft); border-color: var(--line); color: var(--ink-900); }
html[data-theme="dark"] .purchase-international-row .purchase-item-remove-btn { background: #2d181c; border-color: #65343c; }
html[data-theme="dark"] .purchase-international-row .purchase-item-remove-btn:hover { background: #3a1b21; }

html[data-theme="dark"] .purchase-general-row-card:hover { background: var(--theme-hover) !important; }
html[data-theme="dark"] body.values-hidden .topbar-value-privacy,
html[data-theme="dark"] .topbar-value-privacy.is-active { background: #34270f; color: #f5cd7d; border-color: #685322; }

html[data-theme="dark"] .sales-podium-period { background: rgba(16,28,36,.82); border-color: var(--line); color: var(--ink-900); }
html[data-theme="dark"] .sales-podium-card { background: rgba(19,31,40,.96); border-color: var(--line); color: var(--ink-900); }
html[data-theme="dark"] .sales-podium-place-1 .sales-podium-rank { background: #342c13; color: #f2d274; }
html[data-theme="dark"] .sales-podium-place-2 .sales-podium-rank { background: #26333d; color: #cbd7df; }
html[data-theme="dark"] .sales-podium-place-3 .sales-podium-rank { background: #382416; color: #f1b27f; }
html[data-theme="dark"] .sales-podium-metrics span,
html[data-theme="dark"] .sales-podium-badges div,
html[data-theme="dark"] .sales-podium-empty { background: rgba(17,30,39,.84); border-color: var(--line); }

html[data-theme="dark"] .audit-log-meta-grid > span,
html[data-theme="dark"] .audit-readable-section { background: rgba(19,31,40,.78); border-color: var(--line); color: var(--ink-900); }
html[data-theme="dark"] .audit-change-before { background: #2d181c; border-color: #65343c; }
html[data-theme="dark"] .audit-change-after { background: #102a21; border-color: #2c5b47; }
html[data-theme="dark"] .audit-impersonation-badge { background: #34270f; color: #f5c46b; border-color: #685322; }

html[data-theme="dark"] .table-wrap::after,
html[data-theme="dark"] .logistics-inline-table-wrap::after { background: var(--theme-surface-soft); }

:root { --ink-600: #596877; }
html[data-theme="dark"] { --ink-600: #a5b4bf; }

html[data-theme="dark"] .logistics-meta-chip {
  background: var(--theme-surface-soft);
  color: #c7d4dc;
  border-color: var(--line);
}
html[data-theme="dark"] .report-tabs a { color: #cfe2ef; border-color: var(--line); }
html[data-theme="dark"] .report-tabs a.active { background: #0b4a78 !important; color: #fff; border-color: #397ea9 !important; }
html[data-theme="dark"] .financial-money { color: #b8dcf2; }
html[data-theme="dark"] .financial-material { color: #c5d1da; }
html[data-theme="dark"] .sales-rank-position { background: #142b3a; color: #8fd0f7; border-color: #315c75; }
html[data-theme="dark"] .audit-log-icon { background: #142b3a; color: #8fd0f7; box-shadow: inset 0 0 0 1px #315c75; }
html[data-theme="dark"] .audit-action-badge { background: #142b3a; color: #8fd0f7; border-color: #315c75; }
html[data-theme="dark"] :is(.audit-log-content h2, .audit-section-heading h3, .audit-change-field, .audit-info-grid strong) { color: #dbe8f0; }
html[data-theme="dark"] :is(.audit-change-before p, .audit-change-after p) { color: #edf4f8; }
html[data-theme="dark"] .user-impersonate-btn { color: #8fd0f7; border-color: #315c75; }

/* =========================================================
   MSBA Controle v1.19.18 — hardening do modo escuro
   Corrige componentes legados que misturavam paleta de marca,
   texto e superfícies claras. Somente tela; impressão segue clara.
   ========================================================= */
@media screen {
  /* Contraste crítico de números, títulos e valores. */
  html[data-theme="dark"] :is(
    .metric-card > strong,
    .stat-card strong,
    .report-kpi-card strong,
    .purchase-control-field strong,
    .purchase-control-value strong,
    .purchase-control-details > summary strong,
    .purchase-items-toolbar strong,
    .purchase-card-items-head strong,
    .purchase-card-items-list li strong,
    .purchase-bulk-toolbar strong,
    .purchase-logistics-summary strong,
    .purchase-negotiator-summary-card strong,
    .purchase-summary-row strong,
    .purchase-line-total,
    .procurement-summary strong,
    .procurement-item-title strong,
    .procurement-batch-card > header strong,
    .procurement-batch-metrics strong,
    .readonly-field strong,
    .report-chart-card .chart-card-header h2,
    .report-user-table td:not(:first-child) strong,
    .logistics-order-main strong
  ) {
    color: var(--theme-strong-text) !important;
  }

  html[data-theme="dark"] :is(
    .purchase-control-title,
    .table-link,
    .section-link,
    .panel-header > a,
    .quote-brand strong,
    .quote-number > strong,
    .financial-money,
    .sales-money,
    .text-button
  ) {
    color: var(--theme-accent-text) !important;
  }

  /* Controle de Compras: nenhuma superfície branca deve sobreviver no dark. */
  html[data-theme="dark"] :is(
    .purchase-bulk-toolbar,
    .purchase-items-toolbar,
    .purchase-control-card,
    .purchase-control-head,
    .purchase-control-details > summary,
    .purchase-control-field,
    .purchase-control-value,
    .purchase-card-items,
    .purchase-card-items-head,
    .purchase-card-items-list li,
    .purchase-card-items-empty,
    .purchase-control-select
  ) {
    border-color: var(--line) !important;
  }

  html[data-theme="dark"] .purchase-bulk-toolbar {
    background: linear-gradient(180deg, var(--surface-accent-hover), var(--surface-accent-soft)) !important;
  }
  html[data-theme="dark"] :is(.purchase-items-toolbar, .purchase-control-head, .purchase-control-details > summary, .purchase-card-items-head) {
    background: linear-gradient(180deg, var(--surface), var(--surface-hover)) !important;
  }
  html[data-theme="dark"] :is(.purchase-control-card, .purchase-card-items-list li, .purchase-card-items-empty) {
    background: var(--surface) !important;
  }
  html[data-theme="dark"] :is(.purchase-control-field, .purchase-control-value, .purchase-card-items, .purchase-control-select) {
    background: var(--surface-soft) !important;
  }
  html[data-theme="dark"] .purchase-control-select:has(.purchase-control-checkbox:checked) {
    background: #142f40 !important;
    border-color: #397ea9 !important;
    color: #9dd7f7 !important;
  }
  html[data-theme="dark"] .purchase-control-select:has(.purchase-control-checkbox:checked) span {
    color: #9dd7f7 !important;
  }
  html[data-theme="dark"] .purchase-control-section + .purchase-control-section,
  html[data-theme="dark"] .purchase-control-field {
    border-color: var(--line-soft) !important;
  }

  /* Escopos, progresso e estados da compra. */
  html[data-theme="dark"] .purchase-item-scope-national {
    background: #102a21 !important;
    color: #83dfb9 !important;
    border-color: #2c5b47 !important;
  }
  html[data-theme="dark"] .purchase-item-scope-imported,
  html[data-theme="dark"] .item-origin-chip.quote-source {
    background: #102b3b !important;
    color: #8fd2fa !important;
    border-color: #28536b !important;
  }
  html[data-theme="dark"] :is(.purchase-progress, .procurement-progress, .quote-stage-mini-track i, .quote-workflow-step:after) {
    background: #243743 !important;
  }
  html[data-theme="dark"] .delivery-forecast-success,
  html[data-theme="dark"] .logistics-completed-badge {
    background: #102a21 !important;
    color: #83dfb9 !important;
    border-color: #2c5b47 !important;
  }
  html[data-theme="dark"] .delivery-forecast-neutral {
    background: #22313b !important;
    color: #bac6cf !important;
    border-color: #3a4b57 !important;
  }

  /* Dashboard e filtros. */
  html[data-theme="dark"] .metric-card::after {
    background: rgba(106,178,223,.055);
  }
  html[data-theme="dark"] .metric-card:hover {
    border-color: var(--theme-strong-border);
    box-shadow: 0 16px 34px rgba(0,0,0,.20);
  }
  html[data-theme="dark"] .metric-icon,
  html[data-theme="dark"] :is(.global-search-suggestion-icon, .quick-action-grid a > span, .quote-share-option > span, .user-menu a > span, .user-menu button > span) {
    background: #142b3a !important;
    color: #8fd0f7 !important;
  }
  html[data-theme="dark"] .sticky-actions {
    background: rgba(19,31,40,.92) !important;
    border-color: var(--line) !important;
  }

  /* Cotações e procurement. */
  html[data-theme="dark"] :is(
    .quote-item-card-header,
    .quote-item-tax-summary,
    .procurement-item-header,
    .report-methodology > div,
    .quote-batch-preview,
    .purchase-international-items,
    .purchase-stage-inline-panel
  ) {
    background: var(--surface-soft) !important;
    border-color: var(--line) !important;
  }
  html[data-theme="dark"] .procurement-batch-card.is-outdated,
  html[data-theme="dark"] .workflow-selection-banner {
    background: #34270f !important;
    border-color: #685322 !important;
    color: #f7cf82 !important;
  }
  html[data-theme="dark"] :is(.approval-action-card, .supplier-table-choice, .supplier-comparison-table tr.selected-row, .supplier-comparison-table tr.selected-row:hover) {
    background: #102a21 !important;
    border-color: #2c5b47 !important;
  }
  html[data-theme="dark"] .badge-quote-draft,
  html[data-theme="dark"] .supplier-badge.empty {
    background: #22313b !important;
    color: #c3ced6 !important;
    border-color: #3a4b57 !important;
  }
  html[data-theme="dark"] .badge-quote-supplier-priced {
    background: #0e3036 !important;
    color: #89e3ee !important;
    border-color: #28616a !important;
  }
  html[data-theme="dark"] :is(.badge-quote-ready-client, .badge-quote-not-found) {
    background: #35171d !important;
    color: #ff9aa5 !important;
    border-color: #6a3039 !important;
  }
  html[data-theme="dark"] .quote-filter-memory-note,
  html[data-theme="dark"] .quote-batch-guide code {
    background: #142b3a !important;
    color: #9dd7f7 !important;
    border-color: #315c75 !important;
  }

  /* Comboboxes e seletores ricos. */
  html[data-theme="dark"] .smart-combo-trigger,
  html[data-theme="dark"] .smart-combo-trigger:hover,
  html[data-theme="dark"] .smart-combo-option:hover,
  html[data-theme="dark"] .smart-combo-option:focus {
    background: var(--surface-soft) !important;
    color: var(--ink-900) !important;
    border-color: var(--line) !important;
  }
  html[data-theme="dark"] .smart-combo-option > span {
    background: #142b3a !important;
    color: #8fd0f7 !important;
  }

  /* Logística: aliases antigos agora respeitam os tokens de tema. */
  html[data-theme="dark"] :is(.logistics-progress-block > div, .logistics-order-numbers span) {
    background: var(--surface-soft) !important;
    border-color: var(--line) !important;
  }
  html[data-theme="dark"] :is(.logistics-card-head p, .logistics-card-meta, .logistics-progress-block small, .logistics-items-table td small, .logistics-order-main span, .logistics-order-numbers small, .logistics-expanded-actions small) {
    color: var(--ink-500) !important;
  }

  /* Permissões e administração. */
  html[data-theme="dark"] .permission-module-count {
    background: #142b3a !important;
    color: #8fd0f7 !important;
    border-color: #315c75 !important;
  }

  /* Relatórios de compra e cards translúcidos legados. */
  html[data-theme="dark"] .purchase-report-hero {
    background:
      radial-gradient(circle at 92% -15%, rgba(32,185,201,.10), transparent 32%),
      radial-gradient(circle at 0% 100%, rgba(105,211,168,.08), transparent 35%),
      linear-gradient(135deg, #131f28, #172630 58%, #14241f) !important;
    border-color: var(--line) !important;
  }
  html[data-theme="dark"] .purchase-report-hero-metrics div,
  html[data-theme="dark"] .purchase-report-reading-card {
    background: rgba(19,31,40,.86) !important;
    border-color: var(--line) !important;
  }

  /* Personificação continua chamativa, sem faixa branca/amarela agressiva. */
  html[data-theme="dark"] .impersonation-banner,
  html[data-theme="dark"] .audit-impersonation-context {
    background: linear-gradient(90deg, #34270f, #2d2515) !important;
    color: #f7cf82 !important;
    border-color: #685322 !important;
  }
  html[data-theme="dark"] .impersonation-banner-icon,
  html[data-theme="dark"] .audit-impersonation-context-icon {
    background: rgba(246,198,109,.12) !important;
    color: #f7cf82 !important;
  }
}

@media screen {
  html[data-theme="dark"] .badge-neutral { background: #22313b; color: #c3ced6; border-color: #3a4b57; }
  html[data-theme="dark"] :is(.sales-costs-cell, .sales-costs-cell em, .sales-nfe-cell small) { color: #c5d1da !important; }
  html[data-theme="dark"] .sales-costs-cell b { color: #9aabb8 !important; }
  html[data-theme="dark"] :is(.sales-podium-base span, .sales-podium-content h3) { color: #dbe8f0 !important; }
  html[data-theme="dark"] .sales-podium-panel {
    background:
      radial-gradient(circle at 12% 16%, rgba(228,182,0,.09), transparent 26%),
      radial-gradient(circle at 88% 12%, rgba(15,118,110,.08), transparent 28%),
      linear-gradient(135deg, #131f28 0%, #172630 54%, #121d25 100%) !important;
    border-color: var(--line) !important;
  }
  html[data-theme="dark"] .audit-change-arrow { color: #9aabb8 !important; }
}


/* v1.19.18 — hardening final de contraste para componentes legados. */
@media screen {
  html[data-theme="dark"] :is(
    .report-user-role-table .report-user-resolved strong,
    .purchase-report-saving-cell strong,
    .sales-podium-money
  ) {
    color: #83dfb9 !important;
  }

  html[data-theme="dark"] :is(
    .purchase-report-audit-flag,
    .impersonation-banner-main strong,
    .impersonation-banner-main small
  ) {
    color: #f7cf82 !important;
  }

  html[data-theme="dark"] .purchase-report-hero-main strong {
    color: var(--theme-strong-text) !important;
  }

  html[data-theme="dark"] .quote-status-action:hover {
    color: #a7efca !important;
  }
}
