/*
 * Dark-mode corrections loaded after every page-specific stylesheet.
 * Several modules define white surfaces inside their own bundles, so these
 * selectors intentionally have final precedence.
 */
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) {
    --module-dark-bg: #0b111b;
    --module-dark-surface: #111b2a;
    --module-dark-surface-2: #162235;
    --module-dark-border: #2a3a4f;
    --module-dark-text: #e8eef7;
    --module-dark-muted: #9eacc0;
}

/* Central Fiscal */
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager,
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager .nf-toolbar,
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager .nf-filter,
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager .nf-table-wrap,
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager .nf-kpi,
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager .nf-panel,
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager .nf-detail-panel {
    color: var(--module-dark-text) !important;
    background: var(--module-dark-surface) !important;
    border-color: var(--module-dark-border) !important;
}
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager .nf-title,
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager .nf-company,
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager .nf-metric,
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager .nf-kpi-value,
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager h3,
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager label {
    color: var(--module-dark-text) !important;
}
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager .nf-sub,
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager .nf-cnpj,
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager .nf-note-date,
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager .nf-kpi-label {
    color: var(--module-dark-muted) !important;
}
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager :is(.nf-table, .nf-detail-table, table, tbody, tr, td) {
    --bs-table-bg: var(--module-dark-surface) !important;
    --bs-table-color: var(--module-dark-text) !important;
    --bs-table-border-color: var(--module-dark-border) !important;
    color: var(--module-dark-text) !important;
    background-color: var(--module-dark-surface) !important;
    border-color: var(--module-dark-border) !important;
}
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .nf-manager :is(th, thead) {
    color: #b7c3d4 !important;
    background-color: var(--module-dark-surface-2) !important;
    border-color: var(--module-dark-border) !important;
}

/* Download de NFS-e */
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .download-manual-page :is(
    .download-card, .card, .card-body, .card-header, .download-form-column,
    .filter-panel, .form-check, .instructions-card, .download-info-alert
) {
    color: var(--module-dark-text) !important;
    background: var(--module-dark-surface) !important;
    border-color: var(--module-dark-border) !important;
}
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .download-manual-page :is(
    h1, h2, h3, strong, label, .form-label, .download-section-title strong
) { color: var(--module-dark-text) !important; }
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .download-manual-page :is(
    p, small, .form-text, .text-muted, .download-section-title small
) { color: var(--module-dark-muted) !important; }

/* CRM */
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .crm-page :is(
    .crm-toolbar, .crm-column, .crm-card, .crm-detail, .crm-modal,
    .crm-section, .crm-list-item, .ui-panel
) {
    color: var(--module-dark-text) !important;
    background: var(--module-dark-surface) !important;
    border-color: var(--module-dark-border) !important;
}
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .crm-page :is(
    .crm-column-header, .crm-detail-header, .crm-modal-header
) { border-color: var(--module-dark-border) !important; }
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .crm-page :is(
    .crm-column-title, .crm-card-name, .crm-detail-title, .crm-timeline-type,
    .crm-modal-header h2, .crm-field, label
) { color: var(--module-dark-text) !important; }
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .crm-page :is(
    .crm-filter, .crm-status, .crm-card-company, .crm-card-score,
    .crm-timeline-item, .crm-list-meta
) { color: var(--module-dark-muted) !important; }

/* Kanban de conversas */
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .ck-page :is(
    .ck-column, .ck-card, .ck-menu, .ck-modal, .ck-automation-item,
    .ck-qr-item, .ui-panel
) {
    color: var(--module-dark-text) !important;
    background: var(--module-dark-surface) !important;
    border-color: var(--module-dark-border) !important;
}
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .ck-page :is(
    .ck-column-title, .ck-card-name, .ck-modal-header h2,
    .ck-automation-item-title, .ck-qr-item-title, .ck-field, label
) { color: var(--module-dark-text) !important; }
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) .ck-page :is(
    .ck-status, .ck-card-sub, .ck-checkbox-field,
    .ck-automation-item-sub, .ck-qr-item-content
) { color: var(--module-dark-muted) !important; }

/* Fluxos de bot */
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) :is(#botflow-list-root, #botflow-editor-root) :is(
    .ui-panel, .table-responsive, .botflow-node-card, .botflow-edge-row,
    .botflow-modal-card
) {
    color: var(--module-dark-text) !important;
    background: var(--module-dark-surface) !important;
    border-color: var(--module-dark-border) !important;
}
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) #botflow-list-root :is(table, thead, tbody, tr, th, td),
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) #botflow-editor-root :is(.botflow-node-card-head, input, select, textarea) {
    color: var(--module-dark-text) !important;
    background-color: var(--module-dark-surface) !important;
    border-color: var(--module-dark-border) !important;
}

/* Inputs shared by these modules */
:is(body.dark-mode, html.dark-mode body, html[data-bs-theme="dark"] body) :is(
    .nf-manager, .download-manual-page, .crm-page, .ck-page,
    #botflow-list-root, #botflow-editor-root
) :is(input, select, textarea, .form-control, .form-select) {
    color: var(--module-dark-text) !important;
    background-color: var(--module-dark-surface-2) !important;
    border-color: #3a4b62 !important;
}
