/* ================= ESTRUTURA GERAL ================= */
html, body {
    margin: 0;
    height: 100%;
    font-family: Arial, sans-serif;
}

#map {
    height: 100vh;
    width: 100%;
    z-index: 1;
}

/* ================= TOOLBAR (BOTTOM) ================= */
#toolbar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    background: rgba(255,255,255,0.95);
    padding: 10px 15px;
    border-radius: 40px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    z-index: 3;
}

.tool-btn {
    position: relative;
    border: none;
    background: #f0f0f0;
    padding: 10px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
}

.tool-btn:hover { background: #5dade2; color: white; }
.tool-btn.active { background: #5dade2; color: white; transform: scale(1.1); }

.tool-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 120%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 5px 8px;
    border-radius: 5px;
    font-size: 11px;
    opacity: 0;
    transition: 0.2s;
    white-space: nowrap;
}

.tool-btn:hover::after { opacity: 1; }

/* ================= BARRA DE PESQUISA (TOP) ================= */
#search-container {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 650px;
    padding: 0 20px;
    z-index: 5;
    box-sizing: border-box;
    display: flex;
    align-items: center;
}

#pac-input {
    width: 100%;
    padding: 12px 80px 12px 20px;
    font-size: 14px;
    border: none;
    border-radius: 25px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    outline: none;
    background: white;
}

#btn-filtro-busca {
    position: absolute;
    right: 35px;
    background: none;
    border: none;
    color: #2c3e50;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}

#btn-filtro-busca:hover { color: #3498db; }

#btn-clear-search {
    position: absolute;
    right: 65px;
    background: none;
    border: none;
    font-size: 16px;
    color: #95a5a6;
    cursor: pointer;
    padding: 5px;
    transition: 0.2s;
}

#btn-clear-search:hover { color: #e74c3c; }

/* ================= BARRA LATERAL ESQUERDA (AGRUPADOR) ================= */
#barra-lateral-esquerda {
    position: absolute;
    top: 90px;
    left: 10px;
    width: 320px;
    max-height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 2;
    pointer-events: none;
}

#barra-lateral-esquerda > * {
    pointer-events: auto;
    width: 100%;
}

/* ================= PAINEL DE CAMADAS ================= */
#painel-camadas {
    max-height: 45vh;
    background: rgba(255,255,255,0.97);
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#painel-camadas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #2c3e50;
    color: white;
    padding: 10px;
    font-weight: bold;
}

#painel-camadas-body {
    overflow-y: auto;
    max-height: calc(45vh - 44px);
}

.camada-categoria {
    padding: 8px 10px;
    background: #ecf0f1;
    font-weight: bold;
    font-size: 13px;
    border-bottom: 1px solid #ccc;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.camada-categoria-titulo { display: flex; align-items: center; gap: 6px; }
.camada-categoria-seta { font-size: 12px; width: 14px; display: inline-block; }
.camada-item { padding: 10px; border-bottom: 1px solid #ddd; font-size: 13px; }
.camada-topo { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.camada-nome { flex: 1; word-break: break-word; }
.camada-opacidade { display: flex; align-items: center; gap: 8px; }
.camada-opacidade input[type="range"] { flex: 1; }
.camada-opacidade-valor { min-width: 38px; text-align: right; color: #555; font-size: 12px; }

/* ================= PAINEL DE FILTRO AVANÇADO ================= */
#painel-filtro {
    max-height: 60vh;
    background: rgba(255,255,255,0.97);
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#painel-filtro-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #2c3e50;
    color: white;
    padding: 10px;
    font-weight: bold;
    flex-shrink: 0;
}

#painel-filtro-body {
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow-y: auto;
}

#painel-filtro-body .form-group:first-child {
    margin-bottom: 5px;
}

#regras-chips-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 2px;
    max-height: 145px;
    overflow-y: auto;
    padding-right: 5px;
}

.chip-regra {
    display: flex;
    align-items: center;
    background: #ecf0f1;
    border-left: 4px solid #3498db;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    justify-content: space-between;
    word-break: break-word;
}

.chip-logica-badge {
    background: #e67e22;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: bold;
    margin-right: 6px;
}

.chip-texto { flex: 1; color: #2c3e50; font-weight: bold; }
.btn-remover-chip { background: none; border: none; color: #e74c3c; cursor: pointer; font-weight: bold; font-size: 14px; }
.btn-remover-chip:hover { color: #c0392b; }

#btn-nova-condicao {
    background: transparent;
    border: 2px dashed #bdc3c7;
    color: #7f8c8d;
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: 0.2s;
    margin-top: 8px;
}
#btn-nova-condicao:hover { background: #ecf0f1; color: #2c3e50; border-color: #95a5a6; }

#painel-filtro-footer {
    padding: 10px 15px;
    border-top: 1px solid #ddd;
    display: flex;
    gap: 10px;
    background: #fafafa;
    flex-shrink: 0;
}

#painel-filtro-footer button {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: 0.2s;
}

.btn-limpar-filtro { background: #95a5a6; color: white; }
.btn-aplicar-filtro { background: #27ae60; color: white; }


/* ================= BARRA LATERAL DIREITA (NOVO AGRUPADOR) ================= */
#barra-lateral-direita {
    position: absolute;
    top: 90px;
    right: 10px;
    width: 320px;
    bottom: 110px; /* 🔥 LIBERA 110px NO RODAPÉ PARA O STREET VIEW E ZOOM DO GOOGLE */
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 2;
    pointer-events: none;
}

#barra-lateral-direita > * {
    pointer-events: auto;
    width: 100%;
}

/* ================= PAINEL DE FEIÇÕES ================= */
#painel-feicoes {
    background: rgba(255,255,255,0.97);
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;

    flex: 0 1 auto;
    min-height: 60px; /* Mantém o cabeçalho visível */
    max-height: 40vh; /* 🔥 NOVO: Impede que a lista cubra a tela toda */
}

#painel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #2c3e50;
    color: white;
    padding: 10px;
    font-weight: bold;
    flex-shrink: 0;
}

/* Corpo flexível com scroll para tabela */
#painel-body {
    overflow-y: auto;
    flex: 1; /* Permite que a tabela gere scroll internamente quando atingir o limite */
}

.tabela { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabela th { background: #eee; padding: 6px; position: sticky; top: 0; z-index: 1; }
.tabela td { padding: 6px; border-bottom: 1px solid #ddd; }
.acoes button { border: none; background: transparent; cursor: pointer; }

/* ================= PAINEL DE ATRIBUTOS ================= */
#painel-atributos {
    background: rgba(255,255,255,0.98);
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.35);
    overflow: hidden;
    display: none; /* Controlado pelo JS */
    flex-direction: column;

    flex: 0 1 auto;
    min-height: 150px;
    max-height: 40vh;
    /* 🔥 Borda ciano removida para manter o padrão visual limpo */
}

#painel-atributos-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #34495e;
    color: white;
    padding: 10px;
    font-weight: bold;
    flex-shrink: 0;
}

/* Corpo flexível com scroll para os detalhes */
#painel-atributos-body {
    padding: 10px;
    overflow-y: auto;
    font-size: 13px;
    flex: 1;
}

.atributo-item { margin-bottom: 6px; border-bottom: 1px solid #eee; padding-bottom: 4px; }
.atributo-chave { font-weight: bold; color: #2c3e50; }

#painel-atributos-footer {
    padding: 10px;
    border-top: 1px solid #ddd;
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    background: #fafafa;
}

.btn-acao { flex: 1; padding: 8px; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; }
.btn-integrar { background: #27ae60; color: white; }
.btn-fechar { background: #c0392b; color: white; }

/* Classe para esconder o botão de integrar sem quebrar a lógica */
.btn-integrar.escondido {
    display: none !important;
}

/* ================= MODAIS (SISTEMA) ================= */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

#modal-alerta { z-index: 10000 !important; }

.modal-painel {
    background: rgba(255,255,255,0.98);
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.35);
    width: 340px;
    max-width: 90%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    background: #2c3e50;
    color: white;
    padding: 10px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-header h3 { margin: 0; font-size: 14px; }
.modal-body { padding: 20px; color: #333; font-size: 14px; text-align: center; }
.modal-footer { padding: 10px; border-top: 1px solid #ddd; display: flex; gap: 10px; }

.modal-footer button {
    flex: 1; padding: 8px; border: none; border-radius: 6px;
    cursor: pointer; font-weight: bold; transition: 0.2s;
}

.btn-cancelar { background: #95a5a6; color: white; }
.btn-confirmar { background: #c0392b; color: white; }
.btn-ok { background: #2980b9; color: white; }

/* ================= FORMULÁRIOS ================= */
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.form-group label { font-size: 12px; font-weight: bold; color: #555; }
.form-group select, .form-group input {
    padding: 8px; border: 1px solid #ccc; border-radius: 6px;
    font-size: 13px; outline: none; width: 100%; box-sizing: border-box;
}

/* ================= GOOGLE MAPS FIXES ================= */
.gm-style div {
    text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000 !important;
}
.gm-style span, .gm-style div { color: #fff !important; font-weight: bold !important; }

/* ================= UTILITÁRIOS ================= */
.minimizado #painel-body, .minimizado #painel-camadas-body { display: none; }
.btn-fechar-painel { background: none; border: none; color: white; cursor: pointer; font-size: 14px; }
.btn-fechar-atributos { background: none; border: none; color: white; cursor: pointer; font-size: 16px; }

/* Scrollbar Customizado */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: #bdc3c7; border-radius: 10px; }

/* ================= RESPONSIVIDADE (MOBILE) ================= */
@media (max-width: 768px) {
    #barra-lateral-esquerda, #barra-lateral-direita {
        width: calc(100% - 20px) !important;
        left: 10px;
        right: 10px;
    }

    #barra-lateral-direita {
        top: auto;
        bottom: 80px; /* Mantém acima da toolbar no celular */
        max-height: 50vh;
    }
}
