/**
 * 🚨 CORREÇÃO EMERGENCIAL - Z-INDEX
 * Versão: v8.0.18
 * Data: 19/03/2026
 * 
 * Problema: Elementos aparecendo em camadas erradas
 * Solução: Hierarquia organizada de z-index
 */

/* ========================================
   HIERARQUIA DE Z-INDEX (do menor ao maior)
   ======================================== */

/* CAMADA 0: Conteúdo base */
.section {
    z-index: 1 !important;
    position: relative;
}

/* CAMADA 1: Header fixo */
.header {
    z-index: 100 !important;
    position: sticky;
}

/* CAMADA 2: Menu mobile inferior */
.bottom-nav-mobile {
    z-index: 200 !important;
    position: fixed;
    bottom: 0;
}

/* CAMADA 3: Notificações toast */
.toast,
.notification-toast {
    z-index: 300 !important;
    position: fixed;
}

/* CAMADA 4: Dropdowns e tooltips */
.dropdown,
.tooltip,
.popover {
    z-index: 400 !important;
    position: absolute;
}

/* CAMADA 5: Sidebars e painéis deslizantes */
.sidebar,
.panel-slide,
.mobile-menu {
    z-index: 500 !important;
    position: fixed;
}

/* CAMADA 6: Modais de formulário */
.modal {
    z-index: 900 !important;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
}

.modal.active {
    display: flex !important;
}

.modal-content {
    z-index: 901 !important;
    position: relative;
}

/* CAMADA 7: Indicadores de carregamento */
.loading-overlay,
.spinner-overlay {
    z-index: 950 !important;
    position: fixed;
}

/* CAMADA 8: Preloader (máxima prioridade no carregamento) */
#preloader {
    z-index: 9999 !important;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* CAMADA 9: Alertas críticos do sistema */
.alert-critical,
.system-message {
    z-index: 10000 !important;
    position: fixed;
}

/* ========================================
   CORREÇÕES ESPECÍFICAS
   ======================================== */

/* Garantir que o conteúdo do modal fique acima do overlay */
.modal-content > * {
    z-index: auto;
    position: relative;
}

/* Garantir que botões de fechar modal fiquem acessíveis */
.modal .close-btn,
.modal .btn-close {
    z-index: 902 !important;
    position: relative;
}

/* Corrigir sobreposição de menu mobile com modal */
@media (max-width: 768px) {
    body.modal-open .bottom-nav-mobile {
        opacity: 0;
        pointer-events: none;
    }
}

/* Corrigir elementos flutuantes dentro de seções */
.section .floating-btn,
.section .fab-btn {
    z-index: 50 !important;
    position: fixed;
}

/* Garantir que cards não fiquem acima de modais */
.card,
.card-container {
    z-index: auto !important;
}

/* Corrigir calendários e datepickers */
.calendar-popup,
.datepicker,
.timepicker {
    z-index: 850 !important;
    position: absolute;
}

/* ========================================
   DEPURAÇÃO (remover em produção)
   ======================================== */

/* Adicionar borda vermelha em elementos com z-index muito alto */
[style*="z-index: 999999"],
[style*="z-index: 9999999"] {
    outline: 2px solid red !important;
    outline-offset: -2px;
}

/* ========================================
   CORREÇÃO DE BUGS ESPECÍFICOS
   ======================================== */

/* BUG FIX: Modal de novo lançamento sobrepondo tudo */
#modal-novo-lancamento {
    z-index: 900 !important;
}

#modal-novo-lancamento .modal-content {
    z-index: 901 !important;
}

/* BUG FIX: Modal de importação */
#modal-importar-notas {
    z-index: 900 !important;
}

#modal-importar-notas .modal-content {
    z-index: 901 !important;
}

/* BUG FIX: Overlay de background */
.modal-overlay,
.backdrop {
    z-index: 899 !important;
    position: fixed;
}

/* BUG FIX: Menu mobile não deve aparecer em desktop */
@media (min-width: 769px) {
    .bottom-nav-mobile {
        display: none !important;
    }
}

/* BUG FIX: Botões flutuantes não devem sobrepor modais */
.floating-action-btn,
.fab {
    z-index: 50 !important;
}

body.modal-open .floating-action-btn,
body.modal-open .fab {
    opacity: 0;
    pointer-events: none;
}

/* ========================================
   RESET DE Z-INDEX INLINE
   ======================================== */

/* Remover z-index inline que causam problemas */
.section[style*="z-index"] {
    z-index: 1 !important;
}

.card[style*="z-index"] {
    z-index: auto !important;
}

/* ========================================
   GARANTIAS FINAIS
   ======================================== */

/* Garantir que nada fique acima do preloader */
body:has(#preloader[style*="display: flex"]) * {
    z-index: 1 !important;
}

body:has(#preloader[style*="display: flex"]) #preloader {
    z-index: 9999 !important;
}

/* Garantir visibilidade do modal quando ativo */
.modal.active {
    z-index: 900 !important;
    display: flex !important;
}

/* Forçar modal acima de tudo exceto preloader */
.modal.active ~ * {
    z-index: 1 !important;
}

/* ========================================
   FIXES MOBILE
   ======================================== */

@media (max-width: 768px) {
    /* Menu mobile sempre visível em mobile, exceto quando modal aberto */
    .bottom-nav-mobile {
        z-index: 200 !important;
    }
    
    body.modal-open .bottom-nav-mobile {
        z-index: -1 !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }
    
    /* Header menor em mobile */
    .header {
        z-index: 100 !important;
    }
    
    body.modal-open .header {
        z-index: 50 !important;
    }
}

/* ========================================
   LOG DE DEPURAÇÃO
   ======================================== */

/* Este CSS será carregado por último e terá prioridade */
/* Versão: v8.0.18 */
/* Data: 19/03/2026, 23:55 */
