/* =========================================================
   MindZ 27175 — Noite Executiva / contrato visual final
   Camada carregada por último em todas as páginas.
   Objetivo: eliminar superfícies claras residuais e manter a mesma
   linguagem visual em desktop, laptop, tablet e mobile/PWA.
   ========================================================= */

:root[data-theme="dark"],
:root[data-theme-mode="dark"] {
    /* aliases para módulos legados que ainda não usam os tokens oficiais */
    --surface-primary: var(--surface);
    --surface-secondary: var(--surface-alt);
    --surface-tertiary: var(--surface-soft);
    --surface-card: var(--card-bg);
    --surface-panel: var(--surface-elevated);
    --background-primary: var(--app-bg);
    --background-secondary: var(--surface-alt);
    --background-card: var(--card-bg);
    --panel-bg: var(--surface-elevated);
    --panel-border: var(--card-border);
    --field-bg: var(--input-bg);
    --field-border: var(--input-border);
    --field-text: var(--input-text);
    --table-surface: var(--table-bg);
    --table-surface-header: var(--table-header-bg);
    --mindz-mobile-surface: var(--surface);
    --mindz-mobile-card-bg: var(--card-bg);
    --mindz-mobile-field-bg: var(--input-bg);
    --mindz-noite-hover-blue: #79A8FF;
}

:root[data-theme="dark"] body,
:root[data-theme-mode="dark"] body {
    background-color: var(--app-bg) !important;
    color: var(--text) !important;
}

:root[data-theme="dark"] body :where(
    .app-area,
    .app-content,
    .content-page,
    .main-content,
    .page-content,
    .shell-main,
    .page,
    .page-body,
    .view,
    .view-content
),
:root[data-theme-mode="dark"] body :where(
    .app-area,
    .app-content,
    .content-page,
    .main-content,
    .page-content,
    .shell-main,
    .page,
    .page-body,
    .view,
    .view-content
) {
    background-color: var(--app-bg) !important;
    color: var(--text) !important;
}

/* Superfícies operacionais — background-color preserva gradientes premium. */
:root[data-theme="dark"] body :where(
    .card,
    .app-card,
    .content-card,
    .section-card,
    .dashboard-card,
    .summary-card,
    .metric-card,
    .kpi-card,
    .filter-card,
    .filters-card,
    .form-card,
    .table-card,
    .panel,
    .app-panel,
    .home-card,
    .mindz-card,
    .mindz-mobile-card,
    .mindz-responsive-card,
    .mindz-table-card,
    .mindz-mobile-record
),
:root[data-theme-mode="dark"] body :where(
    .card,
    .app-card,
    .content-card,
    .section-card,
    .dashboard-card,
    .summary-card,
    .metric-card,
    .kpi-card,
    .filter-card,
    .filters-card,
    .form-card,
    .table-card,
    .panel,
    .app-panel,
    .home-card,
    .mindz-card,
    .mindz-mobile-card,
    .mindz-responsive-card,
    .mindz-table-card,
    .mindz-mobile-record
) {
    background-color: var(--card-bg) !important;
    border-color: var(--card-border) !important;
    color: var(--text) !important;
}

/* Campos e seletores. */
:root[data-theme="dark"] body :where(
    input:not([type="checkbox"]):not([type="radio"]),
    select,
    textarea,
    .feedback-combobox,
    .mindz-person-selector__control,
    .mindz-person-selector__combobox
),
:root[data-theme-mode="dark"] body :where(
    input:not([type="checkbox"]):not([type="radio"]),
    select,
    textarea,
    .feedback-combobox,
    .mindz-person-selector__control,
    .mindz-person-selector__combobox
) {
    background-color: var(--input-bg) !important;
    border-color: var(--input-border) !important;
    color: var(--input-text) !important;
}

:root[data-theme="dark"] body :where(input, textarea)::placeholder,
:root[data-theme-mode="dark"] body :where(input, textarea)::placeholder {
    color: var(--placeholder) !important;
    opacity: 1 !important;
}

/* Tabelas e calendários que ainda trazem branco fixo de módulos antigos. */
:root[data-theme="dark"] body :where(
    .table-wrapper,
    .table-container,
    .data-table-wrapper,
    .calendar-container,
    .calendar-grid,
    .calendar-shell,
    table
),
:root[data-theme-mode="dark"] body :where(
    .table-wrapper,
    .table-container,
    .data-table-wrapper,
    .calendar-container,
    .calendar-grid,
    .calendar-shell,
    table
) {
    background-color: var(--table-bg) !important;
    border-color: var(--table-border) !important;
    color: var(--table-text) !important;
}

:root[data-theme="dark"] body :where(thead, thead tr, th),
:root[data-theme-mode="dark"] body :where(thead, thead tr, th) {
    background-color: var(--table-header-bg) !important;
    border-color: var(--table-border) !important;
    color: var(--table-header-text) !important;
}

:root[data-theme="dark"] body :where(tbody, tbody tr, td),
:root[data-theme-mode="dark"] body :where(tbody, tbody tr, td) {
    border-color: var(--table-row-border) !important;
    color: var(--table-record-text) !important;
}

/* Modais, dropdowns e seletor padrão MindZ. */
:root[data-theme="dark"] body :where(
    .mindz-modal,
    .app-modal,
    .modal,
    .modal-content,
    .feedback-modal,
    .solicitacoes-modal,
    .app-dialog-modal,
    .mindz-person-selector__list,
    .feedback-dropdown,
    .dropdown-menu,
    .popover
),
:root[data-theme-mode="dark"] body :where(
    .mindz-modal,
    .app-modal,
    .modal,
    .modal-content,
    .feedback-modal,
    .solicitacoes-modal,
    .app-dialog-modal,
    .mindz-person-selector__list,
    .feedback-dropdown,
    .dropdown-menu,
    .popover
) {
    background-color: var(--surface-elevated) !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
}

:root[data-theme="dark"] body .mindz-person-selector__option,
:root[data-theme-mode="dark"] body .mindz-person-selector__option {
    background-color: transparent !important;
    border-color: var(--border-soft) !important;
    color: var(--text) !important;
}

:root[data-theme="dark"] body .mindz-person-selector__option:is(:hover, :focus-visible, .is-active, [aria-selected="true"]),
:root[data-theme-mode="dark"] body .mindz-person-selector__option:is(:hover, :focus-visible, .is-active, [aria-selected="true"]) {
    background-color: var(--table-row-hover) !important;
    color: var(--title-color) !important;
}

/* Noite Executiva — nomes do menu ficam azuis no hover. */
:root[data-theme="dark"] #appSidebar.sidebar :is(.sidebar-link, .sidebar-submenu-trigger):hover :is(.sidebar-link-label, .sidebar-submenu-label),
:root[data-theme="dark"] #appSidebar.sidebar :is(.sidebar-link, .sidebar-submenu-trigger):focus-visible :is(.sidebar-link-label, .sidebar-submenu-label),
:root[data-theme-mode="dark"] #appSidebar.sidebar :is(.sidebar-link, .sidebar-submenu-trigger):hover :is(.sidebar-link-label, .sidebar-submenu-label),
:root[data-theme-mode="dark"] #appSidebar.sidebar :is(.sidebar-link, .sidebar-submenu-trigger):focus-visible :is(.sidebar-link-label, .sidebar-submenu-label),
:root[data-theme="dark"] body > .sidebar-submenu-portal :is(.sidebar-submenu-link, .sidebar-submenu-trigger):hover :is(.sidebar-link-label, .sidebar-submenu-label),
:root[data-theme="dark"] body > .sidebar-submenu-portal :is(.sidebar-submenu-link, .sidebar-submenu-trigger):focus-visible :is(.sidebar-link-label, .sidebar-submenu-label) {
    color: var(--mindz-noite-hover-blue) !important;
}

/* Noite Executiva — botão Visual/Temas nunca volta ao cartão branco. */
:root[data-theme="dark"] #appSidebar #btnAlternarTemaSidebar,
:root[data-theme="dark"] #appSidebar .sidebar-footer .sidebar-theme-button[data-theme-customizer-open="true"],
:root[data-theme-mode="dark"] #appSidebar #btnAlternarTemaSidebar,
:root[data-theme-mode="dark"] #appSidebar .sidebar-footer .sidebar-theme-button[data-theme-customizer-open="true"] {
    background: linear-gradient(145deg, #172231, #101821) !important;
    border-color: #31445d !important;
    color: var(--mindz-noite-hover-blue) !important;
    box-shadow: 0 10px 24px rgba(0, 0, 0, .24) !important;
}

:root[data-theme="dark"] #appSidebar #btnAlternarTemaSidebar:hover,
:root[data-theme="dark"] #appSidebar .sidebar-footer .sidebar-theme-button[data-theme-customizer-open="true"]:hover,
:root[data-theme-mode="dark"] #appSidebar #btnAlternarTemaSidebar:hover,
:root[data-theme-mode="dark"] #appSidebar .sidebar-footer .sidebar-theme-button[data-theme-customizer-open="true"]:hover {
    background: linear-gradient(145deg, #1c2b3d, #142033) !important;
    border-color: color-mix(in srgb, var(--mindz-noite-hover-blue) 42%, #31445d 58%) !important;
    color: #9bbdff !important;
}

/* Mantém o contrato também no app/PWA e touch tablets. */
@media (max-width: 1024px), (pointer: coarse) {
    :root[data-theme="dark"] body :where(
        .mindz-mobile-app-card,
        .mindz-mobile-section,
        .mindz-mobile-sheet,
        .mindz-mobile-toolbar,
        .mindz-mobile-filter,
        .mindz-mobile-record,
        .mindz-responsive-table-card
    ),
    :root[data-theme-mode="dark"] body :where(
        .mindz-mobile-app-card,
        .mindz-mobile-section,
        .mindz-mobile-sheet,
        .mindz-mobile-toolbar,
        .mindz-mobile-filter,
        .mindz-mobile-record,
        .mindz-responsive-table-card
    ) {
        background-color: var(--card-bg) !important;
        border-color: var(--card-border) !important;
        color: var(--text) !important;
    }
}
