/* =====================================================================
   tema-escuro.css — Tema escuro GLOBAL do ERP FLUIR.
   Ativo quando <html data-theme="dark"> (botão lua/sol no topo; preferência
   por navegador em localStorage 'fluir_tema'; aplicado no <head> sem piscar).
   Estratégia: redefinir os tokens --fx-* (o que segue o Design System muda
   sozinho) + cobrir as classes do SB Admin 2/Bootstrap que têm cor cravada.
   Telas com cor cravada inline podem precisar de ajuste pontual.
   Carregar DEPOIS de tema-premium.css e densidade.css.
   ===================================================================== */

html[data-theme="dark"] {
  color-scheme: dark;
  --fx-ink:      #e7e9f0;
  --fx-ink-2:    #c3c8d4;
  --fx-muted:    #8f98ad;
  --fx-faint:    #626a7e;
  --fx-line:     #2e3446;
  --fx-line-2:   #262b3b;
  --fx-surface:  #1a1e2b;
  --fx-surface-2:#141824;
  --fx-tint:     color-mix(in srgb, var(--fx-primary) 18%, #1a1e2b);
  --fx-shadow:    0 1px 2px rgba(0,0,0,.35), 0 4px 14px rgba(0,0,0,.25);
  --fx-shadow-md: 0 8px 24px rgba(0,0,0,.45);
  --fx-shadow-lg: 0 24px 70px rgba(0,0,0,.6);
  --fx-bg:       #0f121b;
}

/* Fundo da página e topo */
html[data-theme="dark"] body,
html[data-theme="dark"] #content-wrapper,
html[data-theme="dark"] #content { background: var(--fx-bg) !important; color: var(--fx-ink-2); }
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .navbar.bg-white { background: var(--fx-surface) !important; border-bottom: 1px solid var(--fx-line); box-shadow: none !important; }
html[data-theme="dark"] .topbar .topbar-divider { border-right-color: var(--fx-line); }
html[data-theme="dark"] .sticky-footer,
html[data-theme="dark"] footer.bg-white { background: var(--fx-surface) !important; color: var(--fx-muted); }

/* Texto */
html[data-theme="dark"] h1, html[data-theme="dark"] h2, html[data-theme="dark"] h3,
html[data-theme="dark"] h4, html[data-theme="dark"] h5, html[data-theme="dark"] h6 { color: var(--fx-ink); }
html[data-theme="dark"] .text-dark, html[data-theme="dark"] .text-gray-900,
html[data-theme="dark"] .text-gray-800 { color: var(--fx-ink) !important; }
html[data-theme="dark"] .text-gray-700, html[data-theme="dark"] .text-gray-600 { color: var(--fx-ink-2) !important; }
html[data-theme="dark"] .text-gray-500, html[data-theme="dark"] .text-gray-400,
html[data-theme="dark"] .text-muted, html[data-theme="dark"] .text-black-50 { color: var(--fx-muted) !important; }
html[data-theme="dark"] a:not(.btn):not(.nav-link):not(.dropdown-item):not(.collapse-item) { color: color-mix(in srgb, var(--fx-primary) 55%, #fff); }
html[data-theme="dark"] hr { border-top-color: var(--fx-line); }

/* Superfícies */
html[data-theme="dark"] .bg-white, html[data-theme="dark"] .bg-light,
html[data-theme="dark"] .bg-gray-100, html[data-theme="dark"] .bg-gray-200 { background-color: var(--fx-surface) !important; }
html[data-theme="dark"] .card, html[data-theme="dark"] .list-group-item,
html[data-theme="dark"] .modal-content, html[data-theme="dark"] .popover,
html[data-theme="dark"] .toast { background-color: var(--fx-surface); border-color: var(--fx-line); color: var(--fx-ink-2); }
html[data-theme="dark"] .card-header, html[data-theme="dark"] .card-footer,
html[data-theme="dark"] .modal-header, html[data-theme="dark"] .modal-footer { background-color: var(--fx-surface-2); border-color: var(--fx-line); }
html[data-theme="dark"] .border, html[data-theme="dark"] .border-top, html[data-theme="dark"] .border-bottom,
html[data-theme="dark"] .border-left, html[data-theme="dark"] .border-right { border-color: var(--fx-line) !important; }
html[data-theme="dark"] .close { color: var(--fx-ink); text-shadow: none; }
html[data-theme="dark"] .shadow, html[data-theme="dark"] .shadow-sm { box-shadow: var(--fx-shadow) !important; }

/* Tabelas */
html[data-theme="dark"] .table { color: var(--fx-ink-2); }
html[data-theme="dark"] .table th, html[data-theme="dark"] .table td,
html[data-theme="dark"] .table thead th { border-color: var(--fx-line); }
html[data-theme="dark"] .table thead th, html[data-theme="dark"] .thead-light th { background: var(--fx-surface-2); color: var(--fx-muted); }
html[data-theme="dark"] .table-striped tbody tr:nth-of-type(odd) { background-color: rgba(255,255,255,.025); }
html[data-theme="dark"] .table-hover tbody tr:hover,
html[data-theme="dark"] .fx-table tbody tr:hover { background-color: rgba(255,255,255,.04); color: var(--fx-ink); }

/* Formulários */
html[data-theme="dark"] .form-control, html[data-theme="dark"] .custom-select,
html[data-theme="dark"] select, html[data-theme="dark"] textarea,
html[data-theme="dark"] input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]) {
  background-color: var(--fx-surface-2); color: var(--fx-ink); border-color: var(--fx-line);
}
html[data-theme="dark"] .form-control:focus { background-color: var(--fx-surface-2); color: var(--fx-ink); }
html[data-theme="dark"] .form-control:disabled, html[data-theme="dark"] .form-control[readonly] { background-color: var(--fx-line-2); color: var(--fx-muted); }
html[data-theme="dark"] .input-group-text { background: var(--fx-line-2); border-color: var(--fx-line); color: var(--fx-muted); }
html[data-theme="dark"] ::placeholder { color: var(--fx-faint) !important; }
html[data-theme="dark"] label, html[data-theme="dark"] .col-form-label { color: var(--fx-ink-2); }

/* Botões e menus */
html[data-theme="dark"] .btn-light, html[data-theme="dark"] .btn-white,
html[data-theme="dark"] .btn-outline-secondary { background: var(--fx-surface-2); border-color: var(--fx-line); color: var(--fx-ink-2); }
html[data-theme="dark"] .btn-light:hover { background: var(--fx-line-2); color: var(--fx-ink); }
html[data-theme="dark"] .dropdown-menu { background: var(--fx-surface); border-color: var(--fx-line); }
html[data-theme="dark"] .dropdown-item { color: var(--fx-ink-2); }
html[data-theme="dark"] .dropdown-item:hover, html[data-theme="dark"] .dropdown-item:focus { background: var(--fx-line-2); color: var(--fx-ink); }
html[data-theme="dark"] .dropdown-divider { border-top-color: var(--fx-line); }
html[data-theme="dark"] .dropdown-header { background: var(--fx-surface-2) !important; }
html[data-theme="dark"] .nav-tabs { border-color: var(--fx-line); }
html[data-theme="dark"] .nav-tabs .nav-link.active { background: var(--fx-surface); border-color: var(--fx-line) var(--fx-line) var(--fx-surface); color: var(--fx-ink); }
html[data-theme="dark"] .page-link { background: var(--fx-surface); border-color: var(--fx-line); color: var(--fx-ink-2); }
html[data-theme="dark"] .modal-backdrop.show { opacity: .7; }

/* Avisos (mantém a semântica: âmbar = aviso, vermelho = erro) */
html[data-theme="dark"] .alert-warning { background: #3a2e12; border-color: #5c4719; color: #f3d48a; }
html[data-theme="dark"] .alert-danger  { background: #3a1a1e; border-color: #5e2930; color: #f2a9b1; }
html[data-theme="dark"] .alert-success { background: #12301f; border-color: #1e4d33; color: #9fe0bb; }
html[data-theme="dark"] .alert-info    { background: #10283a; border-color: #1b4260; color: #9cd1f5; }

/* Select2 */
html[data-theme="dark"] .select2-container--default .select2-selection--single,
html[data-theme="dark"] .select2-container--default .select2-selection--multiple,
html[data-theme="dark"] .select2-dropdown { background: var(--fx-surface-2); border-color: var(--fx-line); }
html[data-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__rendered { color: var(--fx-ink); }
html[data-theme="dark"] .select2-container--default .select2-search--dropdown .select2-search__field { background: var(--fx-surface); color: var(--fx-ink); border-color: var(--fx-line); }
html[data-theme="dark"] .select2-container--default .select2-results__option[aria-selected=true] { background: var(--fx-line-2); }
html[data-theme="dark"] .select2-results__option { color: var(--fx-ink-2); }

/* Imagens de ilustração muito claras perdem o brilho */
html[data-theme="dark"] img.img-profile { filter: none; }

/* Botão de tema no topo */
.fx-tema-btn { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--fx-line); border-radius: var(--fx-radius-sm); background: var(--fx-surface); color: var(--fx-ink-2); cursor: pointer; margin: auto .35rem; }
.fx-tema-btn:hover { border-color: var(--fx-primary); color: var(--fx-primary); }
.fx-tema-btn .fa-sun { display: none; }
html[data-theme="dark"] .fx-tema-btn .fa-sun { display: inline-block; color: #f3c25b; }
html[data-theme="dark"] .fx-tema-btn .fa-moon { display: none; }

/* Service Desk (ficha e workspace clássico usam tokens próprios) */
html[data-theme="dark"] .itsm-ws {
  --ink: var(--fx-ink); --muted: var(--fx-muted); --faint: var(--fx-faint);
  --line: var(--fx-line); --line-soft: var(--fx-line-2);
  --ok-bg: #12301f; --warn-bg: #3a2e12; --crit-bg: #3a1a1e; --info-bg: #10283a;
}
html[data-theme="dark"] .itsm-ws .msg .body { background: var(--fx-surface); border-color: var(--fx-line); }
html[data-theme="dark"] .itsm-ws .msg p { color: var(--fx-ink-2); }
html[data-theme="dark"] .itsm-ws .msg.staff .body { background: color-mix(in srgb, var(--fx-primary) 16%, var(--fx-surface)); border-color: color-mix(in srgb, var(--fx-primary) 30%, var(--fx-line)); }
html[data-theme="dark"] .itsm-ws .msg.internal .body { background: #2e2614; border-color: #4d3f1c; }
html[data-theme="dark"] .itsm-ws .tag-int { background: #4d3f1c; color: #f3d48a; }
html[data-theme="dark"] .itsm-ws .sysline { background: var(--fx-surface); border-color: var(--fx-line); color: var(--fx-muted); }
html[data-theme="dark"] .itsm-ws .composer, html[data-theme="dark"] .itsm-ws .rm-card,
html[data-theme="dark"] .itsm-ws .ci, html[data-theme="dark"] .itsm-ws .qsel { background: var(--fx-surface); color: var(--fx-ink); }
html[data-theme="dark"] .itsm-ws .cbox.int { background: #241f12; border-color: #4d3f1c; }
html[data-theme="dark"] .itsm-ws .att, html[data-theme="dark"] .itsm-ws .filechip { background: var(--fx-surface-2); border-color: var(--fx-line); color: color-mix(in srgb, var(--fx-primary) 55%, #fff); }
html[data-theme="dark"] .itsm-ws .rm-ta, html[data-theme="dark"] .itsm-ws .rm-sel,
html[data-theme="dark"] .itsm-ws .task-add input, html[data-theme="dark"] .itsm-ws .task-add select,
html[data-theme="dark"] .itsm-ws .cc-in, html[data-theme="dark"] .itsm-ws .cob-add input,
html[data-theme="dark"] .itsm-ws .rel-add input { background: var(--fx-surface-2); color: var(--fx-ink); }

/* Modais premium (.fmodal — modal-premium.css tem branco fixo) */
html[data-theme="dark"] .fmodal {
  --fm-ink: var(--fx-ink); --fm-muted: var(--fx-muted);
  --fm-line: var(--fx-line); --fm-surface: var(--fx-surface-2);
  background: var(--fx-surface);
}
html[data-theme="dark"] .fmodal__body,
html[data-theme="dark"] .fmodal__footer { background: var(--fx-surface) !important; }
html[data-theme="dark"] .fmodal .form-control:focus, html[data-theme="dark"] .fmodal .form-select:focus,
html[data-theme="dark"] .fmodal select:focus, html[data-theme="dark"] .fmodal textarea:focus,
html[data-theme="dark"] .fmodal .select2-container--focus .select2-selection { background: var(--fx-surface-2) !important; }
html[data-theme="dark"] .fmodal__money .form-control, html[data-theme="dark"] .fmodal__money input { background: color-mix(in srgb, var(--fx-primary) 14%, var(--fx-surface-2)) !important; }
html[data-theme="dark"] .fmodal .invalid-feedback, html[data-theme="dark"] .fmodal .text-danger { color: #f2939d !important; }
html[data-theme="dark"] .fmodal .is-invalid { background: #2a171b !important; }
html[data-theme="dark"] .fmodal__btn--ghost:hover { background: var(--fx-line-2); }
html[data-theme="dark"] .fmodal__step, html[data-theme="dark"] .fmodal__steps { background: var(--fx-surface-2); }

/* Selos, chips e notas do design system (cores claras fixas no tema-premium) */
html[data-theme="dark"] .fx-chip--muted { background: var(--fx-line-2); color: var(--fx-ink-2); }
html[data-theme="dark"] .fx-badge--success { background: #12301f; color: #7fd6a6; }
html[data-theme="dark"] .fx-badge--info    { background: #10283a; color: #8cc8f5; }
html[data-theme="dark"] .fx-badge--warning { background: #3a2e12; color: #f3d48a; }
html[data-theme="dark"] .fx-badge--danger  { background: #3a1a1e; color: #f2a9b1; }
html[data-theme="dark"] .fx-note           { background: var(--fx-surface-2); color: var(--fx-ink-2); }
html[data-theme="dark"] .fx-note--danger   { background: #2a171b; color: #f2a9b1; }
html[data-theme="dark"] .fx-note--warning  { background: #2e2614; color: #f3d48a; }
html[data-theme="dark"] .fx-note--info     { background: #10222f; color: #9cd1f5; }
html[data-theme="dark"] .fx-iconbtn--danger:hover { background: #3a1a1e; }

/* Destaque de campo obrigatório (partials/required_fields.html usa bege claro) */
html[data-theme="dark"] .campo-obrigatorio { background-color: #2a2516 !important; }
html[data-theme="dark"] .campo-obrigatorio:focus { background-color: var(--fx-surface-2) !important; }
