/* Camada comum de cores. Componentes com cores de status mantêm seu significado. */
:root {
    color-scheme: light;
    --theme-page: #f3f5f8;
    --theme-surface: #ffffff;
    --theme-surface-muted: #f8fafc;
    --theme-text: #263238;
    --theme-muted: #64748b;
    --theme-border: #dce2e8;
    --theme-shadow: 0 4px 16px rgba(15, 23, 42, .08);
    --theme-input: #ffffff;
    --theme-table-head: #f1f5f9;
    --theme-link: #4659a8;
    --theme-focus: rgba(70, 89, 168, .25);

}

:root[data-bs-theme="dark"] {
    color-scheme: dark;
    --brand: #c98bd0;
    --brand-hover: #e0b5e5;
    --brand-soft: #38263d;
    --brand-green: #85c970;
    --brand-green-light: #9bd782;
    --brand-green-strong: #85c970;
    --theme-page: #111827;
    --theme-surface: #1f2937;
    --theme-surface-muted: #273449;
    --theme-text: #e5e7eb;
    --theme-muted: #a7b2c2;
    --theme-border: #3b4758;
    --theme-shadow: 0 4px 18px rgba(0, 0, 0, .24);
    --theme-input: #172131;
    --theme-table-head: #273449;
    --theme-link: #c6a0e8;
    --theme-focus: rgba(201, 139, 208, .4);
    --bg-color: #111827;
    --panel-color: #1f2937;
    --surface-green: #1d3326;
    --surface-purple: #38263d;
    --border-color: #3b4758;
    --text-primary: #e5e7eb;
    --text-secondary: #c0cad7;
    --text-tertiary: #a7b2c2;
    --header-grad-from: #38263d;
    --header-grad-to: #51355a;
    --separator: rgba(203, 213, 225, .18);
    --fill-hover: #273449;
    --fill-pressed: #344256;
    --fill-segment: #273449;
    --focus-ring: 0 0 0 3px rgba(201, 139, 208, .4);
    --header-action-bg: #51355a;
    --header-action-hover: #604066;
    --header-primary-hover: #e0b5e5;
    --bs-body-bg: var(--theme-page);
    --bs-body-color: var(--theme-text);
    --bs-secondary-color: var(--theme-muted);
    --bs-tertiary-color: var(--theme-muted);
    --bs-secondary-bg: var(--theme-surface-muted);
    --bs-tertiary-bg: var(--theme-surface-muted);
    --bs-border-color: var(--theme-border);
    --bs-border-color-translucent: rgba(203, 213, 225, .18);
    --bs-link-color: var(--theme-link);
    --bs-link-hover-color: #e0b5e5;
    --bs-emphasis-color: var(--theme-text);
}

/* Alguns portais BI redeclaram tokens no body para adequar a identidade local. */
html[data-bs-theme="dark"] :is(body.portal-bi, body:has(.portal-bi-nav)) {
    --brand: #c98bd0;
    --brand-hover: #e0b5e5;
    --brand-soft: #38263d;
    --bg-color: #111827;
    --panel-color: #1f2937;
    --text-primary: #e5e7eb;
    --text-secondary: #c0cad7;
    --border-color: #3b4758;
    --separator: rgba(203, 213, 225, .18);
    --fill-hover: #273449;
    --fill-pressed: #344256;
    --fill-segment: #273449;
    --focus-ring: 0 0 0 3px rgba(201, 139, 208, .4);
    --header-action-bg: #51355a;
    --header-action-hover: #604066;
    --header-primary-hover: #e0b5e5;
}

html[data-bs-theme="dark"] body {
    background-color: var(--theme-page) !important;
    color: var(--theme-text);
}

html[data-bs-theme="dark"] :is(.card, .modal-content, .dropdown-menu, .list-group-item, .offcanvas, .popover, .toast) {
    background-color: var(--theme-surface);
    color: var(--theme-text);
    border-color: var(--theme-border);
}

html[data-bs-theme="dark"] :is(.card-header, .card-footer, .modal-header, .modal-footer, .dropdown-item:hover, .list-group-item-action:hover) {
    background-color: var(--theme-surface-muted);
    color: var(--theme-text);
    border-color: var(--theme-border);
}

html[data-bs-theme="dark"] :is(.navbar, .navbar-custom, .navbar-estoque, .navbar-qa, .navbar-forms, .inno-navbar) {
    background-color: var(--theme-surface) !important;
    color: var(--theme-text);
    border-color: var(--theme-border);
}

html[data-bs-theme="dark"] :is(.navbar, .navbar-custom, .navbar-estoque, .navbar-qa, .navbar-forms) :is(.nav-link, .navbar-brand, .dropdown-toggle) {
    color: var(--theme-text);
}

html[data-bs-theme="dark"] :is(.form-control, .form-select, .input-group-text) {
    background-color: var(--theme-input);
    color: var(--theme-text);
    border-color: var(--theme-border);
}

html[data-bs-theme="dark"] :is(.form-control, .form-select)::placeholder { color: #94a3b8; }
html[data-bs-theme="dark"] .table {
    --bs-table-color: var(--theme-text);
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--theme-border);
    --bs-table-striped-color: var(--theme-text);
    --bs-table-striped-bg: rgba(255, 255, 255, .035);
    --bs-table-hover-color: var(--theme-text);
    --bs-table-hover-bg: rgba(255, 255, 255, .06);
}
html[data-bs-theme="dark"] .table thead th,
html[data-bs-theme="dark"] .table .table-light > *,
html[data-bs-theme="dark"] .table-light {
    --bs-table-color: var(--theme-text);
    --bs-table-bg: var(--theme-table-head);
    --bs-table-border-color: var(--theme-border);
}
html[data-bs-theme="dark"] .table-dark {
    --bs-table-color: #f8fafc;
    --bs-table-bg: #111827;
    --bs-table-border-color: var(--theme-border);
}
/* Explicit surface utilities only; status badges and buttons keep their colors. */
html[data-bs-theme="dark"] :is(.card, .modal-content, .offcanvas, .dropdown-menu) :is(.bg-white, .bg-light):not(.badge):not(.btn):not(.alert) {
    background-color: var(--theme-surface-muted) !important;
    color: var(--theme-text);
}
html[data-bs-theme="dark"] :is(.card, .modal-content, .offcanvas, .dropdown-menu) :is(.text-dark, .text-body):not(.badge):not(.btn-warning):not(.btn-info) {
    color: var(--theme-text) !important;
}
html[data-bs-theme="dark"] .text-muted { color: var(--theme-muted) !important; }
html[data-bs-theme="dark"] :is(hr, .border, .border-top, .border-bottom) { border-color: var(--theme-border) !important; }
html[data-bs-theme="dark"] a:not(.btn):not(.nav-link) { color: var(--theme-link); }
html[data-bs-theme="dark"] :is(.form-control, .form-select):focus {
    border-color: #9b70a5;
    box-shadow: 0 0 0 .25rem var(--theme-focus);
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    margin-inline-start: .5rem;
    border: 1px solid var(--theme-border);
    color: var(--theme-text);
    background: var(--theme-surface);
    white-space: nowrap;
}
.theme-toggle:hover, .theme-toggle:focus-visible { color: var(--theme-text); background: var(--theme-surface-muted); }
.theme-toggle-icon { display: block; width: 1.125rem; height: 1.125rem; flex: 0 0 1.125rem; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle-float { position: fixed; inset: 1rem 1rem auto auto; z-index: 1080; box-shadow: var(--theme-shadow); }
@media (max-width: 575.98px) { .theme-toggle-label { display: none; } }

html[data-bs-theme="dark"] .btn-bi-primary,
html[data-bs-theme="dark"] .btn-bi-primary:hover:not(:disabled) {
    color: #251b28;
}

@media print {
    html[data-bs-theme="dark"] {
        color-scheme: light !important;
        --bg-color: #fff;
        --panel-color: #fff;
        --text-primary: #222;
        --text-secondary: #444;
        --border-color: #bbb;
        --separator: #bbb;
        --theme-page: #fff;
        --theme-surface: #fff;
        --theme-text: #222;
        --theme-border: #bbb;
    }
    html[data-bs-theme="dark"] body,
    html[data-bs-theme="dark"] :is(.card, .modal-content, .table-responsive) {
        background: #fff !important;
        color: #222 !important;
    }
    .theme-toggle { display: none !important; }
}
