/* Avisos temporários: camada separada dos clusters, sem bloquear o mapa. */
.mapa-aviso { position: relative; pointer-events: none; }
.mapa-aviso__balao {
    position: absolute;
    bottom: 48px;
    left: 17px;
    transform: translateX(-50%);
    width: 260px;
    max-width: 65vw;
    padding: 10px 12px;
    border: 2px solid var(--cor);
    border-radius: 12px;
    background: #fff;
    color: #1e293b;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .2);
    animation: mapa-aviso-pulso 1.6s ease-in-out infinite;
}
.mapa-aviso__balao::after {
    content: '';
    position: absolute;
    bottom: -9px;
    left: calc(50% - 7px);
    width: 12px;
    height: 12px;
    background: #fff;
    border-right: 2px solid var(--cor);
    border-bottom: 2px solid var(--cor);
    transform: rotate(45deg);
}
.mapa-aviso__balao strong { display: block; color: var(--cor); font-size: 13px; }
.mapa-aviso__balao span { display: block; font-size: 14px; font-weight: 600; margin-top: 4px; }
.mapa-aviso__balao small { display: block; font-size: 12px; margin-top: 4px; }
.mapa-aviso__ponto { animation: mapa-aviso-ponto 1.6s ease-in-out infinite; }
@keyframes mapa-aviso-pulso { 50% { opacity: .65; } }
@keyframes mapa-aviso-ponto {
    50% { box-shadow: 0 0 0 3px #fff, 0 0 0 12px var(--cor); }
}
@media (prefers-reduced-motion: reduce) {
    .mapa-aviso__balao, .mapa-aviso__ponto { animation: none; }
}

.mapa-solicitacao-tooltip {
    min-width: 230px;
    padding: 0;
    border-radius: .5rem;
    overflow: hidden;
    border: none;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
    background: #fff;
    /* O CSS padrão do Leaflet usa pointer-events:none no tooltip, o que impede o
       mouse de entrar no popover. Reativamos com especificidade maior. */
    pointer-events: auto;
}
.mapa-solicitacao-tooltip::before {
    display: none;
}
.mapa-tooltip-img {
    display: block;
    width: 100%;
    height: 96px;
    object-fit: cover;
    background: #e9ecef;
}
.mapa-tooltip-body {
    padding: .5rem .65rem .6rem;
}
.mapa-tooltip-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: .6rem;
    font-size: .72rem;
    margin-bottom: 2px;
}
.mapa-tooltip-row strong {
    text-align: right;
}
.mapa-servico-marcador {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--cor, #1565c0);
    color: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .35), 0 0 0 2px #fff;
    cursor: pointer;
}
.mapa-servico-marcador svg {
    width: 18px;
    height: 18px;
}
/* Enquanto um popover está aberto, os marcadores ao fundo ficam não-interativos.
   O marcador-fonte (cujo popover está aberto) é EXCLUÍDO via :not(.mapa-marcador-fonte):
   se ele fosse desabilitado, o browser dispararia mouseout nele -> fecharia o popover
   -> reativaria tudo -> mouseover -> abriria de novo (loop de piscação). */
.mapa-popover-aberto .leaflet-marker-pane .leaflet-marker-icon:not(.mapa-marcador-fonte) {
    pointer-events: none;
}

.mapa-calor-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: .75rem;
    font-weight: 600;
    color: #334155;
    background: #fff;
    padding: 7px 10px;
    border-radius: 6px;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}
.mapa-calor-btn:hover {
    color: #0f172a;
}
.mapa-calor-btn.active {
    background: #0f172a;
    color: #fff;
}
.mapa-calor-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    background: linear-gradient(135deg, #3b82f6, #ef4444);
    flex-shrink: 0;
}

/* ── Painel de camadas (opt-in) ───────────────────────────────────────────── */
.mapa-camadas {
    position: absolute;
    top: 10px;
    left: 50px;
    z-index: 800;
    width: 210px;
    max-height: calc(100% - 120px);
    overflow-y: auto;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 6px rgba(0, 0, 0, .25);
    font-size: .78rem;
}
.mapa-camadas__titulo {
    padding: 8px 12px;
    font-weight: 700;
    font-size: .8rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
}
.mapa-camadas__titulo::before {
    content: '▾';
    font-size: .7rem;
    color: #64748b;
}
.mapa-camadas--recolhido .mapa-camadas__titulo::before {
    content: '▸';
}
.mapa-camadas--recolhido .mapa-camadas__corpo {
    display: none;
}
.mapa-camadas__corpo {
    padding: 4px 8px 8px;
}
.mapa-camadas__grupo {
    margin-top: 8px;
}
.mapa-camadas__grupo-titulo {
    font-weight: 700;
    text-transform: uppercase;
    font-size: .66rem;
    letter-spacing: .04em;
    color: #64748b;
    margin-bottom: 4px;
}
.mapa-camadas__item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 4px;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
}
.mapa-camadas__item:hover {
    background: #f1f5f9;
}
.mapa-camadas__item input {
    flex-shrink: 0;
    accent-color: #0d6efd;
}
.mapa-camadas__item span {
    overflow: hidden;
    text-overflow: ellipsis;
}
.mapa-camadas__qtd {
    margin-left: auto;
    color: #94a3b8;
    font-size: .7rem;
}

/* ── Consulta por área (opt-in) ───────────────────────────────────────────── */
.mapa-area-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: .75rem;
    font-weight: 600;
    color: #334155;
    background: #fff;
    padding: 7px 10px;
    border-radius: 6px;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}
.mapa-area-btn:hover {
    color: #0f172a;
}
.mapa-area-btn.active {
    background: #2563eb;
    color: #fff;
}
.mapa-mod-area {
    cursor: crosshair;
}
.mapa-mod-area .leaflet-marker-icon {
    cursor: crosshair !important;
}
.mapa-area-banner {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 900;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #1e293b;
    color: #fff;
    font-size: .8rem;
    padding: 8px 14px;
    border-radius: 999px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
    white-space: nowrap;
}
.mapa-area-banner strong {
    font-size: .95rem;
}
.mapa-area-banner button {
    color: #bfdbfe !important;
    text-decoration: underline;
}

/* ── Painel de detalhes lateral (opt-in) ──────────────────────────────────── */
.mapa-detalhe-painel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 850;
    width: 330px;
    max-width: 92vw;
    background: #fff;
    box-shadow: -4px 0 16px rgba(0, 0, 0, .18);
    display: flex;
    flex-direction: column;
    transform: translateX(105%);
    transition: transform .22s ease;
}
.mapa-detalhe-painel--aberto {
    transform: translateX(0);
}
.mapa-detalhe-painel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid #e2e8f0;
}
.mapa-detalhe-painel__protocolo {
    font-size: .95rem;
    color: #0f172a;
}
.mapa-detalhe-painel__fechar {
    border: none;
    background: transparent;
    font-size: 1.4rem;
    line-height: 1;
    color: #64748b;
    cursor: pointer;
    padding: 0 4px;
}
.mapa-detalhe-painel__fechar:hover {
    color: #0f172a;
}
.mapa-detalhe-painel__body {
    overflow-y: auto;
    padding: 14px 16px;
    flex: 1;
}
.mapa-detalhe-painel__carregando {
    color: #64748b;
    font-size: .85rem;
    text-align: center;
    padding: 24px 0;
}
.mapa-detalhe-painel__status {
    display: inline-block;
    color: #fff;
    font-size: .72rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 999px;
    margin-bottom: 12px;
}
.mapa-detalhe-painel__fotos {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    margin-bottom: 12px;
}
.mapa-detalhe-painel__fotos img {
    width: 100%;
    height: 90px;
    object-fit: cover;
    border-radius: 6px;
    background: #e9ecef;
}
.mapa-detalhe-painel__secao {
    margin-bottom: 14px;
}
.mapa-detalhe-painel__secao h6 {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #64748b;
    margin-bottom: 6px;
}
.mapa-detalhe-painel__linha {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    font-size: .8rem;
    padding: 3px 0;
    border-bottom: 1px dashed #f1f5f9;
}
.mapa-detalhe-painel__linha span {
    color: #64748b;
    flex-shrink: 0;
}
.mapa-detalhe-painel__linha strong {
    text-align: right;
}
.mapa-detalhe-painel__descricao {
    font-size: .8rem;
    color: #475569;
    margin: 4px 0 8px;
}

/* Legenda dentro do mapa: visível no modo normal e em tela cheia. */
.mapa-legenda {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
    max-width: min(640px, calc(100vw - 60px));
    max-height: 25vh;
    overflow-y: auto;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, .96);
    color: #334155;
    box-shadow: 0 1px 6px rgba(0, 0, 0, .2);
    font-size: 12px;
    line-height: 1.4;
}
.mapa-legenda__item { display: inline-flex; align-items: center; gap: 5px; }
.mapa-legenda__icone {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    color: #fff;
    flex-shrink: 0;
}
.mapa-legenda__icone svg { width: 12px; height: 12px; }

/* ── Tela cheia (opt-in) — 100% da tela para exibição em TV/painel ────────── */
.mapa-tela-cheia-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    color: #334155;
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}
.mapa-tela-cheia-btn:hover {
    color: #0f172a;
}
.mapa-tela-cheia-btn.active {
    background: #0f172a;
    color: #fff;
}

/* Fallback (sem Fullscreen API) e reforço no modo nativo: o container do mapa
   passa a ocupar a tela inteira, por cima de tudo. */
.mapa-tela-cheia {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    z-index: 3000;
    border-radius: 0 !important;
}
.mapa-tela-cheia:fullscreen {
    width: 100vw;
    height: 100vh;
}

/* ── Clusters (leaflet.markercluster) ─────────────────────────────────────── */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
    background: rgba(13, 110, 253, .14);
}
.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
    background: #0d6efd;
    color: #fff;
    font-weight: 700;
    font-size: .78rem;
}
.marker-cluster div {
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 576px) {
    .mapa-camadas {
        left: 10px;
        width: 190px;
    }
    .mapa-detalhe-painel {
        width: 100%;
        max-width: 100vw;
    }
    #mapaPrefeito,
    #mapaSolicitacoes {
        height: 90vh;
    }
}
