/* V18-CV — Corrige cards/painéis antigos com background branco inline no tema escuro.
   Não altera DANFE/print fiscal. */

:root {
  --flow-inline-bg: var(--bg-card, #ffffff);
  --flow-inline-bg-soft: var(--bg-secondary, #f8fafc);
  --flow-inline-input-bg: var(--bg-card, #ffffff);
  --flow-inline-text: var(--text-primary, #0f172a);
  --flow-inline-muted: var(--text-secondary, #64748b);
  --flow-inline-border: var(--border, #e5e7eb);
}

html[data-theme="dark"],
html[data-flow-theme="dark"],
body.dark,
body.dark-mode,
body.flow-theme-dark,
body.theme-dark {
  --flow-inline-bg: #111827;
  --flow-inline-bg-soft: #0b1220;
  --flow-inline-input-bg: #0b1220;
  --flow-inline-text: #f9fafb;
  --flow-inline-muted: #cbd5e1;
  --flow-inline-border: rgba(148, 163, 184, .22);
}

/* Corrige HTML antigo que recebeu style="background:#fff" dentro do app. */
html[data-theme="dark"] #app [style*="background:#fff"]:not([id*="danfe" i]):not([class*="danfe" i]),
html[data-flow-theme="dark"] #app [style*="background:#fff"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.dark #app [style*="background:#fff"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.dark-mode #app [style*="background:#fff"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.flow-theme-dark #app [style*="background:#fff"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.theme-dark #app [style*="background:#fff"]:not([id*="danfe" i]):not([class*="danfe" i]),
html[data-theme="dark"] #app [style*="background: #fff"]:not([id*="danfe" i]):not([class*="danfe" i]),
html[data-flow-theme="dark"] #app [style*="background: #fff"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.dark #app [style*="background: #fff"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.dark-mode #app [style*="background: #fff"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.flow-theme-dark #app [style*="background: #fff"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.theme-dark #app [style*="background: #fff"]:not([id*="danfe" i]):not([class*="danfe" i]),
html[data-theme="dark"] #app [style*="background:#ffffff"]:not([id*="danfe" i]):not([class*="danfe" i]),
html[data-flow-theme="dark"] #app [style*="background:#ffffff"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.dark #app [style*="background:#ffffff"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.dark-mode #app [style*="background:#ffffff"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.flow-theme-dark #app [style*="background:#ffffff"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.theme-dark #app [style*="background:#ffffff"]:not([id*="danfe" i]):not([class*="danfe" i]),
html[data-theme="dark"] #app [style*="background: #ffffff"]:not([id*="danfe" i]):not([class*="danfe" i]),
html[data-flow-theme="dark"] #app [style*="background: #ffffff"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.dark #app [style*="background: #ffffff"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.dark-mode #app [style*="background: #ffffff"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.flow-theme-dark #app [style*="background: #ffffff"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.theme-dark #app [style*="background: #ffffff"]:not([id*="danfe" i]):not([class*="danfe" i]),
html[data-theme="dark"] #app [style*="background:white"]:not([id*="danfe" i]):not([class*="danfe" i]),
html[data-flow-theme="dark"] #app [style*="background:white"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.dark #app [style*="background:white"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.dark-mode #app [style*="background:white"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.flow-theme-dark #app [style*="background:white"]:not([id*="danfe" i]):not([class*="danfe" i]),
body.theme-dark #app [style*="background:white"]:not([id*="danfe" i]):not([class*="danfe" i]) {
  background: var(--flow-inline-bg) !important;
  color: var(--flow-inline-text) !important;
  border-color: var(--flow-inline-border) !important;
}

/* Inputs/select/buttons antigos com background branco inline. */
html[data-theme="dark"] #app input[style*="background"],
html[data-theme="dark"] #app select[style*="background"],
html[data-theme="dark"] #app textarea[style*="background"],
html[data-flow-theme="dark"] #app input[style*="background"],
html[data-flow-theme="dark"] #app select[style*="background"],
html[data-flow-theme="dark"] #app textarea[style*="background"],
body.flow-theme-dark #app input[style*="background"],
body.flow-theme-dark #app select[style*="background"],
body.flow-theme-dark #app textarea[style*="background"],
body.dark #app input[style*="background"],
body.dark #app select[style*="background"],
body.dark #app textarea[style*="background"] {
  background: var(--flow-inline-input-bg) !important;
  color: var(--flow-inline-text) !important;
  border-color: var(--flow-inline-border) !important;
}

html[data-theme="dark"] #app button[style*="background:#fff"],
html[data-theme="dark"] #app button[style*="background: #fff"],
html[data-theme="dark"] #app button[style*="background:#ffffff"],
html[data-theme="dark"] #app button[style*="background: #ffffff"],
html[data-flow-theme="dark"] #app button[style*="background:#fff"],
html[data-flow-theme="dark"] #app button[style*="background: #fff"],
html[data-flow-theme="dark"] #app button[style*="background:#ffffff"],
html[data-flow-theme="dark"] #app button[style*="background: #ffffff"],
body.flow-theme-dark #app button[style*="background:#fff"],
body.flow-theme-dark #app button[style*="background: #fff"],
body.flow-theme-dark #app button[style*="background:#ffffff"],
body.flow-theme-dark #app button[style*="background: #ffffff"] {
  background: var(--flow-inline-bg-soft) !important;
  color: var(--flow-inline-text) !important;
  border-color: var(--flow-inline-border) !important;
}

/* Textos cinza escuros hardcoded em cards antigos. */
html[data-theme="dark"] #app [style*="color:#0f172a"],
html[data-flow-theme="dark"] #app [style*="color:#0f172a"],
body.flow-theme-dark #app [style*="color:#0f172a"],
body.dark #app [style*="color:#0f172a"] {
  color: var(--flow-inline-text) !important;
}

html[data-theme="dark"] #app [style*="color:#64748b"],
html[data-flow-theme="dark"] #app [style*="color:#64748b"],
body.flow-theme-dark #app [style*="color:#64748b"],
body.dark #app [style*="color:#64748b"] {
  color: var(--flow-inline-muted) !important;
}

/* Print/DANFE continua branco. */
@media print {
  [style*="background:#fff"],
  [style*="background: #fff"],
  [style*="background:#ffffff"],
  [style*="background: #ffffff"] {
    background: #fff !important;
    color: #111827 !important;
  }
}
