/* =========================================
   1. BASE, SPA & RESET
   ========================================= */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: #f4f6f8;
    margin: 0;
    padding-top: 70px;
    padding-bottom: 80px;
    font-size: 16px;
}

/* Sistema de Vistas (SPA) */
.app-view {
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
    transform: translateY(10px);
}

.app-view.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.tela-central {
    max-width: 90%;
    margin: 20px auto;
    background: white;
    padding: 25px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

.hidden {
    display: none !important;
}

input,
select {
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 1rem;
    background: white;
}

#toast-container {
    position: fixed;
    top: 76px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2147483647;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(92vw, 420px);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-radius: 8px;
    background: #2c3e50;
    color: white;
    font-size: 0.92rem;
    font-weight: 600;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.toast.sucesso {
    background: #1f8f55;
}

.toast.erro {
    background: #c0392b;
}

.toast.info {
    background: #21618c;
}

/* =========================================
   2. LAYOUT & GRID (SISTEMA DE COLUNAS)
   ========================================= */

/* Aplicamos o grid diretamente ao ID onde os cartões são gerados */
#lista-territorios {
    display: grid !important;
    gap: 10px;
    padding: 0 15px;
    max-width: 1200px;
    margin: 0 auto;

    /* MOBILE (Padrão): Força 2 colunas iguais em qualquer celular */
    grid-template-columns: repeat(2, 1fr) !important;
}

/* DESKTOP: Ajuste para tablets e computadores (acima de 768px) */
@media (min-width: 768px) {
    #lista-territorios {
        gap: 15px;
        /* Cartões de no mínimo 300px, preenchendo o espaço (3 ou mais colunas) */
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)) !important;
    }
}

/* =========================================
   3. HEADER & FOOTER
   ========================================= */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    z-index: 1000;
}

.app-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: white;
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid #eee;
    z-index: 1000;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: #999;
    font-size: 0.7rem;
    gap: 4px;
    padding: 5px 0;
    margin: 0;
    width: 33%;
    cursor: pointer;
}

.nav-item.active {
    color: #3498db;
}

.nav-item .material-icons {
    font-size: 24px;
    margin-bottom: 0;
    line-height: 1;
}

#nav-gestao {
    color: #e67e22;
}

#nav-gestao.active {
    color: #d35400;
    font-weight: bold;
}

#nav-gestao .material-icons {
    margin-bottom: 2px;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    position: relative;
    color: #555;
    padding: 5px;
}

.badge {
    position: absolute;
    top: 0;
    right: 0;
    background: #e74c3c;
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    border: 2px solid white;
}

/* =========================================
   4. CARTÕES & BOTÕES
   ========================================= */
.card {
    background: white;
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    text-align: left;
    border-left: 5px solid #ccc;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.status-Livre {
    border-left-color: #27ae60;
}

.status-Ocupado {
    border-left-color: #e74c3c;
    opacity: 0.9;
}

.status-Meu {
    border-left-color: #3498db;
    background-color: #f0f8ff;
    border: 2px solid #3498db;
}

button {
    cursor: pointer;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 1rem;
    margin-top: 10px;
    transition: transform 0.1s;
}

.btn-pedir,
.btn-verde {
    background-color: #27ae60;
    color: white;
}

.btn-designar {
    background-color: #f39c12;
    color: white;
}

.btn-azul {
    background-color: #3498db;
    color: white;
}

.btn-vermelho {
    background-color: #fff0f0;
    color: #e74c3c;
    border: 1px solid #ffcccc;
}

/* =========================================
   5. MODAIS & Z-INDEX (MANTIDO) 🛠️
   ========================================= */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: stretch;
    padding: 10px 0;
}

.modal-content {
    background: #fff;
    width: 95%;
    max-width: 720px;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 40px);
    overflow: hidden;
    padding: 0;
}


/* --- CABEÇALHO DO MODAL (ATUALIZADO) --- */
.modal-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 15px;
    /* Mais compacto */
    border-bottom: 1px solid #eee;
    min-height: 50px;
    background-color: #fff;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: #333;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* --- BOTÃO FECHAR 'X' (ADICIONAR ISSO) --- */
.btn-close {
    width: 30px !important;
    height: 30px !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #f2f2f2 !important;
    /* Cinza claro */
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-close:hover {
    background-color: #e0e0e0 !important;
    color: #000;
}

.btn-close .material-icons {
    font-size: 18px;
}


/* Botão Fullscreen Estilo Nativo Maps */
.btn-fullscreen {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1000;

    background: #fff;
    color: #333;
    /* Ícone preto */
    border: none;
    border-radius: 4px;
    /* Cantos levemente arredondados (padrão Google) */
    width: 40px;
    height: 40px;

    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    /* Sombra suave */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-fullscreen:active {
    background: #f1f1f1;
}

/* Quando estiver em tela cheia, destaque o botão */
.mapa-fullscreen .btn-fullscreen {
    background: #333;
    color: #fff;
}

/* --- CORREÇÃO MAPA FULLSCREEN (Global) --- */

/* Quando a classe está no body, o mapa ignora o modal e cobre a tela */
body.mapa-fullscreen-active #leaflet-map-container {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 99999 !important;
    /* Z-Index máximo */
    background: white;
    border-radius: 0 !important;
    margin: 0 !important;
}

/* Ajuste do Botão quando em Fullscreen */
body.mapa-fullscreen-active .btn-fullscreen {
    background-color: #e74c3c !important;
    /* Vermelho para destaque (Sair) */
    color: white !important;
    border: 2px solid white !important;
    top: 20px !important;
    /* Mais espaço do topo */
    right: 20px !important;
    /* Mais espaço da direita */
    width: 45px;
    height: 45px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4) !important;
}

/* Opcional: Esconde a barra de rolagem do fundo quando o mapa está aberto */
body.mapa-fullscreen-active {
    overflow: hidden;
}

/* Hierarquia de Z-Index */
/* O modal de detalhes (padrão) deve ficar acima do overlay (2000) */
#modal-detalhes {
    z-index: 2100 !important;
}

/* O modal de endereço/edição fica no mesmo nível do de detalhes */
#modal-endereco {
    z-index: 2100 !important;
}

/* O modal de seleção (designar) deve ficar ACIMA de tudo */
#modal-selecao {
    z-index: 3500 !important;
}

/* O modal de confirmação também precisa ser muito alto */
#modal-confirmacao {
    z-index: 3600 !important;
}


/* --- UI/UX: MODAL DE CONFIRMAÇÃO MODERNO --- */
#modal-confirmacao .modal-content {
    /* Layout */
    width: 90%;
    max-width: 320px !important;
    /* Trava a largura para ficar compacto */
    margin: 0 auto;
    /* Garante centralização */

    /* Estilo Visual (O SEU MANTIDO) */
    border-radius: 16px;
    padding: 25px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    border: none;
}

#modal-confirmacao h3 {
    color: #2c3e50;
    font-size: 1.25rem;
    margin-bottom: 10px;
}

#modal-confirmacao p {
    color: #7f8c8d;
    font-size: 1rem;
    margin-bottom: 25px;
    line-height: 1.5;
}

/* Botões do Modal de Confirmação */
#modal-confirmacao .acoes-confirmacao {
    display: flex;
    gap: 12px;
    justify-content: center;
}

#modal-confirmacao .btn-azul {
    /* Botão NÃO (Cinza Escuro) */
    background-color: #95a5a6 !important;
    color: white !important;
    border-radius: 8px;
    font-weight: 600;
    flex: 1;
}

#confirm-sim {
    /* Botão SIM (Verde Sucesso) */
    background-color: #27ae60 !important;
    color: white !important;
    border-radius: 8px;
    font-weight: 600;
    flex: 1;
    box-shadow: 0 4px 6px rgba(39, 174, 96, 0.2);
}

/* --- ADICIONE ESTE BLOCO --- */

#modal-admin .modal-content {
    width: 90%;
    max-width: 400px !important;
    /* Largura ideal para aprovar cadastros */
    margin: 0 auto;
}



/* =========================================
   UI: GERENCIAR USUÁRIOS (MODERNIZADO)
   ========================================= */

/* Cada item de usuário na lista */
.item-usuario {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    margin-bottom: 12px;
    background-color: #fff;
    border-radius: 10px;
    border: 1px solid #edf2f7;
    transition: all 0.2s ease;
}

.item-usuario:hover {
    border-color: #3498db;
    background-color: #f8fafc;
}

/* Informações de texto */
.item-usuario div b {
    display: block;
    font-size: 1.1rem;
    color: #1a202c;
    /* Preto mais forte */
    margin-bottom: 2px;
}

.item-usuario small {
    display: block;
    font-size: 0.9rem;
    color: #4a5568;
    /* Cinza médio legível */
    margin-bottom: 8px;
}

/* Estilo para as Funções (Tags) */
.tags-roles span {
    display: inline-block;
    background-color: #ebf8ff;
    /* Azul bem clarinho */
    color: #2b6cb0;
    /* Azul escuro */
    font-size: 0.75rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
    margin-right: 5px;
    text-transform: uppercase;
    border: 1px solid #bee3f8;
}

/* Botão de Edição (Lápis) */
.item-usuario .icon-btn {
    background-color: #f7fafc;
    color: #3498db;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.item-usuario .icon-btn:hover {
    background-color: #3498db;
    color: white;
}

/* --- ESTILO ESPECIAL PARA O MODAL DE GESTÃO (MOBILE FIRST) --- */
#modal-gestao-lista .modal-content {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    border-radius: 0 !important;
    display: flex;
    flex-direction: column;
}

#modal-gestao-lista .modal-body {
    background-color: #f0f2f5;
    padding: 10px;
    flex: 1;
    overflow-y: auto;
    /* Permite rolar o conteúdo */
}

/* Inputs Grandes para Dedo */
.form-gestao-group {
    background: white;
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 15px;
}

.form-gestao-group label {
    font-size: 0.85rem;
    color: #7f8c8d;
    font-weight: bold;
    text-transform: uppercase;
    display: block;
    margin-bottom: 5px;
}

.form-gestao-group input,
.form-gestao-group select {
    font-size: 1.1rem;
    /* Letra grande */
    padding: 12px;
    height: 50px;
    /* Altura boa para toque */
    background: #f9f9f9;
    border: 1px solid #ddd;
}

.form-gestao-group input:focus {
    background: #fff;
    border-color: #3498db;
}

/* Card de Endereço na Lista */
.card-endereco-gestao {
    background: white;
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 10px;
    border-left: 5px solid #bdc3c7;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.card-endereco-gestao.cheio {
    border-left-color: #e74c3c;
}

/* Se o território tiver 6 */
.card-endereco-gestao.vaga {
    border-left-color: #27ae60;
}

.badge-contagem {
    background: #34495e;
    color: white;
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: bold;
}

/* =========================================
   6. COMPONENTES EXTRAS (MANTIDO)
   ========================================= */
.box-registro-visita {
    background: #f0f8ff;
    border: 1px solid #cceeff;
    border-radius: 8px;
    padding: 15px;
    margin-top: 15px;
}

.card-aprovacao {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    border-left: 5px solid #3498db;
    margin-bottom: 10px;
    overflow: hidden;
}

.aprovacao-detalhes.aberto {
    display: block;
    animation: slideDown 0.3s ease;
}

/* Estilo Endereço */
.end-meta {
    font-size: 0.85rem;
    color: #7f8c8d;
    margin-bottom: 2px;
    text-transform: uppercase;
}

.end-main {
    font-size: 1.4rem;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 8px;
}

.end-ref-box {
    background-color: #fff3cd;
    color: #856404;
    border-left: 4px solid #ffc107;
    padding: 10px;
    border-radius: 4px;
    font-size: 0.95rem;
    margin-bottom: 15px;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =========================================
   ESTILOS DO MODAL DE CONFIRMAÇÃO (CORRIGIDO)
   ========================================= */

#modal-confirmacao {
    /* REMOVIDO O !important DAQUI PARA O .hidden FUNCIONAR */
    display: flex;

    align-items: center !important;
    justify-content: center !important;
    padding: 20px;
    z-index: 9999 !important;
    background: rgba(0, 0, 0, 0.6) !important;

    /* Garante que comece invisível se tiver a classe hidden */
    transition: opacity 0.3s ease;
}

/* Reforço para garantir que ele suma quando tiver a classe hidden */
#modal-confirmacao.hidden {
    display: none !important;
}

/* A caixa branca interna */
#modal-confirmacao .modal-content {
    position: relative !important;
    margin: 0 !important;
    top: 0 !important;
    left: 0 !important;
    transform: none !important;

    width: 100% !important;
    max-width: 400px !important;

    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    padding: 20px;
    animation: surgirSuave 0.3s ease-out;
}

/* Área dos botões (Sim/Não) */
#modal-confirmacao .acoes-confirmacao {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

#modal-confirmacao .acoes-confirmacao button {
    flex: 1;
    padding: 12px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
}

@keyframes surgirSuave {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}



/* --- CORREÇÃO DE SOBREPOSIÇÃO (PORTAL) --- */
#modal-config-locais {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 2147483647 !important;
    /* Máximo possível */
    background: rgba(0, 0, 0, 0.6) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;

    /* Remove heranças que prendem a janela atrás */
    transform: none !important;
    filter: none !important;
    backdrop-filter: none !important;
    isolation: isolate !important;
}

#modal-config-locais.hidden {
    display: none !important;
}

.custom-marker {
    background: #3498db;
    color: #fff;
    font-weight: bold;
    border-radius: 50%;
    text-align: center;
    line-height: 30px;
    font-size: 14px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.custom-marker .marker-number {
    font-size: 14px;
    font-weight: bold;
    color: #fff;
    text-align: center;
    line-height: 30px;
}


.modal-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    /* Evita corte nas bordas */
}

.modal-body {
    max-height: 90vh;
    /* Limita altura ao tamanho da tela */
    overflow-y: auto;
    /* Ativa rolagem interna */
    box-sizing: border-box;
}



#modal-confirmacao .modal-content {
    max-height: 90vh;
    /* Limita altura ao tamanho da tela */
    overflow-y: auto;
    /* Ativa rolagem interna */
    display: flex;
    flex-direction: column;
}

#modal-confirmacao .modal-body {
    flex: 1;
    overflow-y: auto;
}



/* --- MELHORIA VISUAL PARA MODAL DE CONFIRMAÇÃO --- */
#modal-confirmacao .modal-content {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    animation: surgirSuave 0.3s ease-out;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#modal-confirmacao h3 {
    font-size: 1.3rem;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 15px;
}

#modal-confirmacao p {
    font-size: 1rem;
    color: #7f8c8d;
    margin-bottom: 20px;
    text-align: center;
}

/* Botão fechar no canto superior direito */
#modal-confirmacao .btn-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #f2f2f2;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

#modal-confirmacao .btn-close:hover {
    background: #e0e0e0;
}

/* Botões de ação */
#modal-confirmacao .acoes-confirmacao button {
    flex: 1;
    padding: 12px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.1s;
}

#modal-confirmacao .acoes-confirmacao button:hover {
    transform: scale(1.03);
}



/* --- SPINNER DE CARREGAMENTO --- */
.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    animation: spin 1s linear infinite;
    margin: 15px auto;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}
