/* =====================================================================
 * v6.8 — «Localizar no Mapa» (OpenStreetMap + Leaflet).
 * Lista lateral + mapa, marcadores com nome, balões estilo Google Maps,
 * patrocinados a roxo (apenas texto) e modo noite.
 * ===================================================================== */

.mapsec { padding: 18px 0 40px; }
.mapsec__head { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; justify-content: space-between; margin-bottom: 14px; }
.mapsec__title { font-size: 1.5rem; margin: 0 0 4px; }
.mapsec__filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.mapsec__filters .input { min-width: 170px; }
.mapsec__open-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #16a34a; }
.mapsec__ad-tag { background: var(--brand-600); color: #fff; border-radius: 6px; padding: 1px 7px; font-size: .72rem; font-weight: 700; }

.mapsec__body { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 16px; align-items: stretch; }
.mapsec__list { max-height: 74vh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 4px; }
.mapsec__empty { padding: 20px; }
.mapsec__canvas { position: relative; min-height: 74vh; border-radius: var(--radius-lg, 18px); overflow: hidden; border: 1px solid var(--border); }
#map-canvas { position: absolute; inset: 0; }

/* Cartões da coluna esquerda --------------------------------------------- */
.mapcard {
    display: flex; gap: 12px; padding: 12px; cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
    transition: border-color .2s ease, transform .2s ease, box-shadow .2s ease;
}
.mapcard:hover, .mapcard.is-active { border-color: var(--brand-500); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.mapcard--ad { display: block; border-left: 4px solid var(--brand-600); background: linear-gradient(180deg, rgba(124, 58, 237, .07), transparent); }
.mapcard__ad { display: inline-block; font-size: .68rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--brand-700); margin-bottom: 4px; }
.mapcard__thumb { flex: 0 0 64px; width: 64px; height: 64px; border-radius: 12px; overflow: hidden; display: grid; place-items: center; background: var(--brand-50, #f5f3ff); color: var(--brand-600); font-weight: 800; font-size: 1.4rem; }
.mapcard__thumb img { width: 100%; height: 100%; object-fit: cover; }
.mapcard__body { min-width: 0; }
.mapcard__name { margin: 0 0 2px; font-size: 1rem; }
.mapcard__meta { margin: 0; font-size: .82rem; color: var(--muted); }
.mapcard__meta.is-open { color: #16a34a; font-weight: 600; }
.mapcard__meta.is-closed { color: #dc2626; }
.mapcard__actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

/* Marcadores -------------------------------------------------------------- */
.mappin-wrap { background: none !important; border: 0 !important; }
.mappin { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; transform: translate(-9px, -9px); }
.mappin__dot { width: 18px; height: 18px; border-radius: 50%; background: var(--brand-600, #6d28d9); border: 3px solid #fff; box-shadow: 0 1px 6px rgba(0, 0, 0, .35); display: block; }
.mappin--open .mappin__dot { background: #16a34a; }
.mappin--ad .mappin__dot { background: #7c3aed; width: 20px; height: 20px; }
.mappin__label { background: rgba(255, 255, 255, .94); color: #1f2937; font-size: .76rem; font-weight: 700; padding: 2px 7px; border-radius: 7px; box-shadow: 0 1px 4px rgba(0, 0, 0, .25); }
.mappin--ad .mappin__label { background: var(--brand-600, #6d28d9); color: #fff; }

/* Balão ------------------------------------------------------------------- */
.leaflet-popup-content { margin: 0; width: auto !important; }
.leaflet-popup-content-wrapper { border-radius: 14px; padding: 0; overflow: hidden; }
.mappop { width: 270px; padding: 12px; font-size: .86rem; }
.mappop--ad { border-left: 4px solid var(--brand-600); }
.mappop__ad { display: inline-block; font-size: .66rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--brand-700); margin-bottom: 4px; }
.mappop__cover { display: block; width: calc(100% + 24px); margin: -12px -12px 10px; height: 110px; object-fit: cover; }
.mappop__head { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.mappop__logo { width: 46px; height: 46px; border-radius: 12px; object-fit: cover; }
.mappop__logo--letter { display: grid; place-items: center; background: var(--brand-50, #f5f3ff); color: var(--brand-600); font-weight: 800; }
.mappop__name { margin: 0; font-size: .98rem; }
.mappop__meta { margin: 2px 0; color: #6b7280; font-size: .8rem; }
.mappop__meta.is-open { color: #16a34a; font-weight: 600; }
.mappop__meta.is-closed { color: #dc2626; }
.mappop__services { margin: 6px 0; font-size: .8rem; }
.mappop__services-list { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 3px; }
.mappop__services-list li { display: flex; justify-content: space-between; gap: 8px; font-size: .8rem; border-bottom: 1px dashed rgba(0, 0, 0, .08); padding-bottom: 3px; }
.mappop__actions { display: flex; gap: 6px; margin-top: 10px; }
.mappop__btn { margin-top: 8px; }

/* Link na página inicial --------------------------------------------------- */
.home-maplink {
    display: inline-flex; align-items: center; gap: 8px; font-weight: 700;
    padding: 10px 16px; border-radius: 999px; border: 1px solid var(--brand-500);
    color: var(--brand-700); background: rgba(124, 58, 237, .08);
    transition: background .2s ease, transform .2s ease;
}
.home-maplink:hover { background: rgba(124, 58, 237, .16); transform: translateY(-1px); }
.home-geobar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 10px 0 0; font-size: .9rem; }

/* v6.9 — campos da pesquisa com ícone (Bootstrap Icons) à esquerda. */
.mapsec__main, .mapsec__extra { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.mapsec__field { position: relative; display: flex; align-items: center; margin: 0; }
.mapsec__field > .bi { position: absolute; left: 10px; font-size: .95rem; color: var(--brand-600, #6d28d9); pointer-events: none; }
.mapsec__field .input { padding-left: 32px; width: 100%; }
html[data-theme="dark"] .mapsec__field > .bi { color: #c4b5fd; }

@media (max-width: 900px) {
    .mapsec__body { grid-template-columns: 1fr; }
    .mapsec__list { max-height: 42vh; }
    .mapsec__canvas { min-height: 52vh; }
}

/* =====================================================================
 * v6.9 — VERSÃO RESPONSIVA do «Encontrar no Mapa».
 *
 * Pedido: no telemóvel mostrar SOMENTE a pesquisa acima da localidade e o
 * mapa por baixo, com as empresas a seguir. Por isso:
 *   · o título/contadores (.mapsec__intro) desaparecem;
 *   · os filtros avançados (categoria e «Perto de mim») desaparecem;
 *   · a pesquisa (q) fica por cima da localidade (place), cada uma em linha
 *     própria e a ocupar a largura toda, com o botão por baixo;
 *   · o MAPA vem antes da LISTA de empresas.
 * ===================================================================== */
@media (max-width: 760px) {
    .mapsec { padding: 10px 0 28px; }
    .mapsec__head { display: block; margin-bottom: 10px; }
    .mapsec__intro { display: none; }
    .mapsec__filters { display: block; width: 100%; }
    .mapsec__main { display: flex; flex-direction: column; align-items: stretch; gap: 8px; width: 100%; }
    .mapsec__main .mapsec__field { width: 100%; }
    .mapsec__main .input { min-width: 0; width: 100%; }
    .mapsec__main .btn { width: 100%; justify-content: center; }
    .mapsec__extra { display: none; }

    /* Mapa primeiro, empresas depois. */
    .mapsec__body { display: grid; grid-template-columns: 1fr; gap: 12px; }
    .mapsec__canvas { order: 1; min-height: 58vh; }
    .mapsec__list { order: 2; max-height: none; overflow: visible; padding-right: 0; }
}

html[data-theme="dark"] .mappin__label { background: rgba(24, 18, 43, .92); color: #ede9fe; }
html[data-theme="dark"] .mappop { background: #1a1433; color: #e9e6f5; }
html[data-theme="dark"] .mappop__meta { color: #b6aee0; }
html[data-theme="dark"] .leaflet-popup-content-wrapper, html[data-theme="dark"] .leaflet-popup-tip { background: #1a1433; color: #e9e6f5; }
html[data-theme="dark"] .home-maplink { color: #c4b5fd; border-color: #7c3aed; background: rgba(124, 58, 237, .18); }


/* =====================================================================
 * v7.1 — botão flutuante discreto «Atualizar empresas nesta área»
 * Aparece apenas depois de terminar o arrasto/zoom/touch.
 * ===================================================================== */
.mapsec__canvas {
    position: relative;
}

.map-update-area {
    position: absolute;
    right: max(12px, env(safe-area-inset-right));
    bottom: max(28px, env(safe-area-inset-bottom));
    z-index: 650;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: calc(100% - 24px);
    padding: 8px 13px;
    border: 1px solid rgba(20, 33, 42, 0.14);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.97);
    color: #14212a;
    font: 600 12.5px/1.2 system-ui, -apple-system, "Segoe UI", sans-serif;
    box-shadow: 0 14px 30px -16px rgba(20, 33, 42, 0.65);
    cursor: pointer;
    backdrop-filter: blur(6px);
    transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.map-update-area:hover {
    border-color: #0e6f63;
    color: #0a4f47;
    transform: translateY(-1px);
}

.map-update-area:focus-visible {
    outline: 3px solid rgba(14, 111, 99, 0.35);
    outline-offset: 2px;
}

.map-update-area[hidden] {
    display: none;
}

.map-update-area .bi {
    font-size: 14px;
}

.map-update-area.is-busy .bi {
    animation: map-update-spin 900ms linear infinite;
}

@keyframes map-update-spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .map-update-area,
    .map-update-area.is-busy .bi {
        transition: none;
        animation: none;
    }
}

@media (max-width: 640px) {
    .map-update-area {
        right: 10px;
        bottom: 18px;
        font-size: 12px;
        padding: 7px 11px;
    }
}
