/**
 * Correções para widgets do Elementor
 * Especialmente para ocultar seções de notícias quando não há posts com a tag selecionada
 */

/* Ocultar completamente o widget de posts quando não há resultados */
.elementor-widget-posts:not(:has(.elementor-post)),
.elementor-widget-archive-posts:not(:has(.elementor-post)),
.elementor-widget-loop-grid:not(:has(.elementor-loop-item)) {
    display: none !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Ocultar mensagens de "nenhum post encontrado" */
.elementor-posts-nothing-found,
.elementor-loop-message,
.elementor-posts__no-posts {
    display: none !important;
}

/* Ocultar container de posts vazio */
.elementor-posts-container:empty,
.elementor-loop-container:empty {
    display: none !important;
}

/* Ocultar posts individuais vazios */
.elementor-post:empty,
.elementor-loop-item:empty {
    display: none !important;
}

/* Ocultar seção inteira quando o widget de posts está vazio */
.elementor-section:has(.elementor-widget-posts:not(:has(.elementor-post))),
.elementor-section:has(.elementor-widget-loop-grid:not(:has(.elementor-loop-item))) {
    display: none !important;
}

/* Ocultar coluna quando o widget de posts está vazio */
.elementor-column:has(.elementor-widget-posts:not(:has(.elementor-post))),
.elementor-column:has(.elementor-widget-loop-grid:not(:has(.elementor-loop-item))) {
    display: none !important;
}

/* Ocultar widget wrap quando o widget de posts está vazio */
.elementor-widget-wrap:has(.elementor-widget-posts:not(:has(.elementor-post))),
.elementor-widget-wrap:has(.elementor-widget-loop-grid:not(:has(.elementor-loop-item))) {
    display: none !important;
}

/* Garantir que títulos de seção também sejam ocultados quando não há posts */
.elementor-widget-heading + .elementor-widget-posts:not(:has(.elementor-post)),
.elementor-widget-heading + .elementor-widget-loop-grid:not(:has(.elementor-loop-item)) {
    display: none !important;
}

/* Ocultar o título se o próximo elemento (posts) estiver vazio */
.elementor-widget-heading:has(+ .elementor-widget-posts:not(:has(.elementor-post))),
.elementor-widget-heading:has(+ .elementor-widget-loop-grid:not(:has(.elementor-loop-item))) {
    display: none !important;
}

/* Fallback: ocultar qualquer elemento com classe de "vazio" */
.elementor-widget-empty,
.elementor-posts--empty,
.elementor-loop--empty {
    display: none !important;
}

/* Garantir que seções seguintes mantenham posicionamento normal */
.elementor-section {
    position: relative !important;
    z-index: auto !important;
}

/* Prevenir margin-top negativo ou position absolute em seções */
.elementor-section.gallery-section,
.single-espaco .gallery-section,
.single-espaco section.gallery-section {
    position: relative !important;
    margin-top: 0 !important;
    z-index: 1 !important;
    clear: both !important;
}

/* Garantir que a seção de acervo não sobreponha outras seções */
.single-espaco .elementor-section:has(.gallery-section) {
    position: relative !important;
    margin-top: 0 !important;
    z-index: 1 !important;
}

/* CORREÇÃO: Remover qualquer margin negativo da seção de Acervo */
.single-espaco .elementor-section:has(.gallery-section),
.single-espaco section:has(.gallery-section),
.elementor-section:has(.gallery-section),
section.elementor-section:has(.gallery-section) {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}

/* Forçar remoção de margin negativo em qualquer elemento da seção de Acervo */
.elementor-section .gallery-section,
.elementor-section:has(h2:contains("ACERVO")),
.elementor-section:has(.section-title:contains("ACERVO")) {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}

/* Garantir que seção de notícias não deixe espaço quando oculta */
.elementor-section:has(.elementor-widget-posts:not(:has(.elementor-post))),
.elementor-section:has(.elementor-widget-loop-grid:not(:has(.elementor-loop-item))) {
    margin: 0 !important;
    padding: 0 !important;
    height: 0 !important;
    min-height: 0 !important;
    overflow: hidden !important;
}

/* Quando notícias estiver visível, garantir espaçamento adequado */
.elementor-section:has(.elementor-widget-posts:has(.elementor-post)),
.elementor-section:has(.elementor-widget-loop-grid:has(.elementor-loop-item)) {
    padding-top: 2.5rem !important;
    padding-bottom: 2.5rem !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}

/* Forçar que a seção seguinte à de notícias não tenha margin negativo */
.elementor-section:has(.elementor-widget-posts) + .elementor-section,
.elementor-section:has(.elementor-widget-loop-grid) + .elementor-section {
    margin-top: 0 !important;
}
