/**
 * Layout e estilos para a página de seleção de município
 */

.selection-page-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 80px); /* Desconto da altura da header */
    background-color: #ffffff;
}

.search-container-center {
    width: 100%;
    max-width: 550px;
    padding: 0 20px;
}

.municipio-search-widget {
    background: #f8f9fa;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 32px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.05);
}

.widget-title {
    font-family: 'Inter', sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    color: #103758;
    margin-bottom: 24px;
    text-align: center;
}

/* Estrutura do Input */
.search-input-container {
    position: relative;
    width: 100%;
}

#muni-search-input {
    width: 100%;
    padding: 16px 20px 16px 48px;
    border: 2px solid #cbd5e1;
    border-radius: 10px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#muni-search-input:focus {
    border-color: #103758;
    box-shadow: 0 0 0 4px rgba(16, 55, 88, 0.1);
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    color: #94a3b8;
}

/* Autocomplete Dropdown */
.autocomplete-items {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-top: none;
    border-radius: 0 0 10px 10px;
    max-height: 280px;
    overflow-y: auto;
    box-shadow: 0 12px 20px rgba(0,0,0,0.1);
}

.autocomplete-suggestion {
    padding: 12px 20px;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
    font-family: 'Inter', sans-serif;
    color: #334155;
    transition: background 0.2s;
}

.autocomplete-suggestion:hover {
    background-color: #f1f5f9;
}

.hidden {
    display: none;
}

/* ==========================================================================
   MOBILE: AJUSTE DE SELEÇÃO DE MUNICÍPIO (ANTI-CORTE)
   ========================================================================== */
@media (max-width: 575.98px) {
    /* Mudamos para flex-start para o conteúdo não "sumir" no topo em telas pequenas */
    body .selection-page-wrapper {
        align-items: flex-start;
        padding-top: 10vh;
        min-height: calc(100vh - 60px);
    }

    /* Reduzimos o respiro lateral para o widget ocupar melhor a largura */
    body .search-container-center {
        padding: 0 12px;
    }

    /* Diminuímos o padding interno de 32px para 20px para ganhar espaço útil */
    body .municipio-search-widget {
        padding: 24px 20px;
        border-radius: 10px;
    }

    /* Ajuste de escala do título e ícone */
    body .widget-title {
        font-size: 1.1rem;
        margin-bottom: 20px;
    }

    body #muni-search-input {
        padding: 14px 16px 14px 44px;
        font-size: 0.95rem;
    }

    body .search-icon {
        left: 14px;
        width: 18px;
        height: 18px;
    }
}

/* ==========================================================================
   DASHBOARD: TABELAS RESPONSIVAS (PREVINE O CORTE DA 5ª COLUNA)
   ========================================================================== */
body .table-card .table-responsive,
body .metric-card .table-container {
    overflow-x: auto;
    display: block;
    width: 100%;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 12px;
}

/* Garante um tamanho mínimo para os dados não "encavalarem" */
body .table-card table {
    min-width: 600px;
    font-size: 0.875rem;
}

/* ==========================================================================
   MOBILE: AJUSTE DO CABEÇALHO DO MUNICÍPIO (AZUL)
   ========================================================================== */
@media (max-width: 767.98px) {
    /* Reduz o título para não empurrar os elementos para fora */
    body .mun-header h2 {
        font-size: 1.4rem;
        line-height: 1.2;
    }

    /* Stack de botões Nacional/Estadual para não sumirem na direita */
    body .comparison-toggle-container {
        flex-direction: column;
        width: 100%;
        gap: 10px;
    }

    body .btn-comparison {
        width: 100%;
        text-align: center;
    }
}

/* ==========================================================================
   ESTRUTURA: ANTI-VAZAMENTO GLOBAL
   ========================================================================== */
html, body {
    max-width: 100vw;
    overflow-x: hidden;
}

body .content-wrapper,
body .dashboard-content {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    padding: 10px; /* Respiro nas bordas do celular */
}

/* ==========================================================================
   DASHBOARD MUNICÍPIO: AJUSTE DE ENQUADRAMENTO MOBILE
   ========================================================================== */
@media (max-width: 768px) {
    /* Ajusta o cabeçalho azul para não cortar o nome da cidade */
    body .mun-header-bg {
        padding: 20px 15px !important;
        width: 100%;
    }

    body .mun-header-bg h2 {
        font-size: 1.5rem;
        word-wrap: break-word;
    }

    /* Os botões Nacional/Estadual devem ocupar a largura toda para não ficarem espremidos */
    body .comparison-toggle {
        display: flex;
        width: 100%;
        margin-top: 15px;
    }

    body .btn-comparison {
        flex: 1;
        text-align: center;
        font-size: 0.9rem;
    }

    /* Faz os cards de População/Receita empilharem 1 por linha */
    body .summary-cards-row {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    body .summary-card {
        width: 100%;
        min-width: 0;
    }
}

/* ==========================================================================
   DASHBOARD: DETALHAMENTO DE RECEITAS (ANTI-CORTE image_6fb6ab.png)
   ========================================================================== */
@media (max-width: 575.98px) {
    /* 1. Força os blocos de Valor e Média Nacional a ficarem um embaixo do outro */
    body .metric-card .flex.justify-between.mt-4,
    body .metric-card .grid.grid-cols-2,
    body .revenue-item-wrapper .flex.justify-between {
        flex-direction: column !important; /* Exceção temporária para teste: se não funcionar, use o caminho abaixo */
        display: flex;
        align-items: flex-start;
        gap: 12px;
    }

    /* Versão sem !important (resolvendo na raiz pela especificidade) */
    body .dashboard-content .metric-card .revenue-item-wrapper .flex {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    /* 2. Permite que o texto de comparação quebre a linha em vez de vazar */
    body .metric-card p, 
    body .metric-card span {
        white-space: normal;
        overflow-wrap: break-word;
        display: block;
    }

    /* 3. Ajusta o recuo lateral dos sub-itens para ganhar área útil */
    body .revenue-item-wrapper {
        padding-left: 10px;
        padding-right: 10px;
    }
}

/* ==========================================================================
   DASHBOARD: AJUSTE FINO ESTRUTURA DE RECEITAS (image_6fb6ab.png)
   ========================================================================== */
@media (max-width: 768px) {
    /* 1. Força a quebra de linha no texto que você circulou em vermelho */
    body .metric-card .revenue-item-wrapper p, 
    body .metric-card .revenue-item-wrapper span,
    body .metric-card .revenue-item-wrapper h6 {
        white-space: normal !important;
        overflow-wrap: break-word !important;
        word-wrap: break-word !important;
        display: block !important;
        max-width: 100% !important;
    }

    /* 2. Garante que o container interno não tenha largura fixa */
    body .revenue-item-wrapper .flex.flex-col {
        min-width: 0 !important;
        flex: 1 !important;
    }

    /* 3. Ajusta o grid de valores (Habitante vs Nacional) para não encavalar */
    body .metric-card .revenue-item-wrapper .grid-cols-2,
    body .metric-card .revenue-item-wrapper .flex.justify-between.mt-2 {
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px !important;
        background-color: #f8fafc;
        padding: 10px;
        border-radius: 6px;
    }
}

/* ==========================================================================
   DASHBOARD: AJUSTE DE GRÁFICOS (image_6fafe0.png)
   ========================================================================== */
@media (max-width: 768px) {
    /* 1. Reduz o padding lateral do card de gráfico para ganhar espaço */
    body #chart-card.metric-card,
    body .chart-section {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    /* 2. Garante que o canvas do gráfico não force a largura da tela */
    body .chart-slot {
        width: 100% !important;
        max-width: 100% !important;
        overflow: hidden !important;
    }

    canvas {
        max-width: 100% !important;
        height: auto !important;
    }
}

