/* Carte des chantiers — /search/?view=map
   Design system : tokens --vefa-* (tokens.css chargé globalement par base.html).
   Composants : pins par phase, clusters brandés, popup card, légende,
   « Rechercher dans cette zone », compteur, contrôles nav, POI. */

/* =====================================================
   Container + états
   ===================================================== */
#search-programs-map {
    position: relative;
    background: #eef1f4;
}

#search-programs-map.is-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 800;
    background: rgba(255, 255, 255, 0.45);
    pointer-events: none;
}

/* =====================================================
   Marqueurs (pin teardrop coloré par phase)
   ===================================================== */
.map-pin-el { cursor: pointer; }

.map-pin {
    --pin-color: #3498db;
    width: 30px;
    height: 30px;
    background: var(--pin-color);
    border: 2px solid #fff;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    box-shadow: 0 3px 8px rgba(15, 23, 42, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.map-pin i {
    transform: rotate(45deg);
    color: #fff;
    font-size: 12px;
    line-height: 1;
}

.map-pin-el:hover .map-pin {
    transform: rotate(-45deg) scale(1.15);
    box-shadow: 0 5px 14px rgba(15, 23, 42, 0.45);
}

/* Halo « communauté active » (followers ou questions > 0) */
.map-pin--active::after {
    content: '';
    position: absolute;
    inset: -7px;
    border-radius: 50% 50% 50% 0;
    border: 2px solid var(--pin-color);
    opacity: 0.55;
    animation: map-pin-pulse 2.2s ease-out infinite;
    pointer-events: none;
}

@keyframes map-pin-pulse {
    0% { transform: scale(0.85); opacity: 0.55; }
    70% { transform: scale(1.18); opacity: 0; }
    100% { transform: scale(1.18); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .map-pin--active::after { animation: none; opacity: 0.4; }
}

/* =====================================================
   Clusters donut — composition par phase de chantier
   ===================================================== */
.map-donut {
    cursor: pointer;
    filter: drop-shadow(0 3px 8px rgba(15, 23, 42, 0.28));
    transition: transform 0.15s ease;
}

.map-donut:hover { transform: scale(1.08); }

.map-donut text {
    font-weight: 700;
    font-size: 12px;
    fill: var(--vefa-text, #1f2d3d);
    font-family: inherit;
}

/* Pilule nominative au zoom quartier (data-zoomband posé par le JS) */
.map-pin-el { position: relative; }

.map-pin__label {
    display: none;
    position: absolute;
    left: 34px;
    top: 1px;
    background: rgba(255, 255, 255, 0.96);
    color: var(--vefa-text, #1f2d3d);
    font-size: 0.74rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 999px;
    white-space: nowrap;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.22);
    pointer-events: none;
}

[data-zoomband="near"] .map-pin__label { display: block; }

/* =====================================================
   Popup card
   ===================================================== */
.map-popup-anchor .maplibregl-popup-content {
    border-radius: 14px;
    padding: 0;
    overflow: hidden;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
    line-height: 1.4;
}

.map-popup-anchor .maplibregl-popup-close-button {
    z-index: 5;
    font-size: 18px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    color: var(--vefa-text, #1f2d3d);
    top: 6px;
    right: 6px;
}

.map-popup { width: 280px; max-width: 100%; }

.map-popup__media {
    position: relative;
    height: 130px;
    background: linear-gradient(135deg, #dfe7ef, #c8d4e0);
    overflow: hidden;
}

.map-popup__media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.map-popup__media--empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #8aa0b5;
    font-size: 2rem;
}

.map-popup__chips {
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.map-popup__chip {
    --chip-color: #3498db;
    background: var(--chip-color);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 999px;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.3);
    white-space: nowrap;
}

.map-popup__chip--new { background: #198754; }
.map-popup__chip--soon { background: #b57e00; }

.map-popup__body { padding: 12px 14px 14px; }

.map-popup__title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--vefa-text, #1f2d3d);
    margin: 0 0 6px;
}

.map-popup__meta {
    font-size: 0.8rem;
    color: #64748b;
    margin-bottom: 3px;
}

.map-popup__meta i { width: 14px; text-align: center; margin-right: 2px; }
.map-popup__sep { opacity: 0.5; }

.map-popup__community {
    display: flex;
    gap: 12px;
    font-size: 0.8rem;
    color: #475569;
    background: #f6f8fa;
    border-radius: 8px;
    padding: 6px 10px;
    margin: 8px 0 10px;
}

.map-popup__community i { color: var(--vefa-accent, #ff4000); margin-right: 3px; }

.map-popup__actions { display: flex; gap: 6px; }

.map-popup__btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 7px 10px;
    border: 0;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    white-space: nowrap;
}

.map-popup__btn--primary {
    background: var(--vefa-accent, #ff4000);
    color: #fff !important;
}

.map-popup__btn--primary:hover {
    background: #e63a00;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(255, 64, 0, 0.3);
}

.map-popup__btn--ghost {
    background: #fff;
    color: var(--vefa-text, #1f2d3d) !important;
    border: 1px solid #d7dee6;
}

.map-popup__btn--ghost:hover {
    border-color: var(--vefa-accent, #ff4000);
    color: var(--vefa-accent, #ff4000) !important;
}

.map-popup__btn--ghost.is-following {
    background: #198754;
    border-color: #198754;
    color: #fff !important;
}

/* =====================================================
   Légende (contrôle Leaflet bas-gauche)
   ===================================================== */
.map-legend {
    background: rgba(255, 255, 255, 0.96);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.16);
    overflow: hidden;
    max-width: 220px;
    font-family: inherit;
}

.map-legend__head {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    background: transparent;
    border: 0;
    padding: 8px 12px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--vefa-text, #1f2d3d);
    cursor: pointer;
}

.map-legend__caret { margin-left: auto; font-size: 0.7rem; opacity: 0.5; transition: transform 0.2s ease; }
.map-legend__head[aria-expanded="false"] .map-legend__caret { transform: rotate(-90deg); }

.map-legend__body { padding: 0 10px 10px; }
.map-legend__body.is-collapsed { display: none; }

.map-legend__label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #94a3b8;
    margin: 8px 0 4px;
    font-weight: 700;
}

.map-legend__label small {
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
}

.map-legend__phase {
    display: flex;
    align-items: center;
    gap: 7px;
    width: 100%;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 7px;
    padding: 4px 6px;
    font-size: 0.78rem;
    color: var(--vefa-text, #1f2d3d);
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease, opacity 0.15s ease;
}

.map-legend__phase:hover { background: #f1f5f9; }
.map-legend__phase.is-inactive { opacity: 0.35; }
.map-legend__phase.is-inactive .map-legend__dot { background: #cbd5e1 !important; }

.map-legend__dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.15);
    flex-shrink: 0;
}

.map-legend__row {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.75rem;
    color: #475569;
    padding: 3px 6px;
}

.map-legend__glyph {
    width: 16px;
    text-align: center;
    color: #64748b;
    font-size: 0.7rem;
    flex-shrink: 0;
}

.map-legend__glyph--pulse {
    width: 10px;
    height: 10px;
    margin: 0 3px;
    border-radius: 50%;
    border: 2px solid var(--vefa-accent, #ff4000);
    opacity: 0.6;
}

/* Chips POI (« Autour des chantiers ») */
.map-legend__pois {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 2px 4px 4px;
}

.map-legend__poi {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.72rem;
    font-weight: 600;
    color: #475569;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.map-legend__poi:hover { border-color: var(--vefa-accent, #ff4000); }

.map-legend__poi.is-active {
    background: var(--vefa-accent, #ff4000);
    border-color: var(--vefa-accent, #ff4000);
    color: #fff;
}

/* =====================================================
   « Rechercher dans cette zone » + toast + compteur
   ===================================================== */
.map-zone-search {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 900;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #fff;
    color: var(--vefa-text, #1f2d3d);
    border: 0;
    border-radius: 999px;
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.22);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.map-zone-search:hover {
    transform: translateX(-50%) translateY(-1px);
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.28);
    color: var(--vefa-accent, #ff4000);
}

.map-zone-search i { color: var(--vefa-accent, #ff4000); }

.map-toast {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 950;
    background: rgba(31, 45, 61, 0.92);
    color: #fff;
    border-radius: 999px;
    padding: 7px 14px;
    font-size: 0.8rem;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.3);
    animation: map-toast-in 0.25s ease;
    pointer-events: none;
}

@keyframes map-toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(-6px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.search-map-counter {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    font-size: 0.82rem;
    color: #64748b;
    border-top: 1px solid #eef2f7;
    background: #fff;
    min-height: 40px;
}

.search-map-counter i { color: var(--vefa-accent, #ff4000); }
.search-map-counter strong { color: var(--vefa-text, #1f2d3d); }

.map-counter-muted { color: #94a3b8; }
.map-counter-muted i { color: #94a3b8; }

.map-counter-link {
    background: transparent;
    border: 0;
    padding: 0;
    color: var(--vefa-primary, #3498db);
    font-size: 0.8rem;
    cursor: pointer;
    text-decoration: underline;
}

.map-zone-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 64, 0, 0.08);
    color: var(--vefa-accent, #ff4000);
    border: 1px solid rgba(255, 64, 0, 0.25);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.map-zone-chip:hover { background: rgba(255, 64, 0, 0.14); }
.map-zone-chip__x { opacity: 0.7; }
.map-zone-chip i { color: var(--vefa-accent, #ff4000); }

/* =====================================================
   Contrôles (Autour de moi / France / 3D / Satellite) + MapLibre
   ===================================================== */
.map-ctl { overflow: hidden; }

.map-ctl-btn {
    display: block;
    width: 30px;
    height: 30px;
    background: #fff;
    border: 0;
    border-bottom: 1px solid #e2e8f0;
    color: var(--vefa-text, #1f2d3d);
    font-size: 13px;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.map-ctl-btn:last-child { border-bottom: 0; }

.map-ctl-btn:hover {
    background: #f8fafc;
    color: var(--vefa-accent, #ff4000);
}

.map-ctl-btn.is-active {
    background: var(--vefa-accent, #ff4000);
    color: #fff;
}

#search-programs-map .maplibregl-ctrl-group {
    border-radius: 10px;
    box-shadow: 0 3px 12px rgba(15, 23, 42, 0.18);
    overflow: hidden;
}

.map-me-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--vefa-primary, #3498db);
    border: 3px solid #fff;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.35);
}

/* =====================================================
   POI — badges colorés par catégorie + tooltip
   ===================================================== */
.poi-badge {
    display: flex !important;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #fff;
    font-size: 11px;
    border: 2px solid rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.28);
    transition: transform 0.12s ease;
}

.poi-badge:hover { transform: scale(1.18); z-index: 700 !important; }

.poi-badge--transport { background: #0d6efd; }
.poi-badge--school { background: #198754; }
.poi-badge--health { background: #dc3545; }
.poi-badge--shop { background: #b57e00; }

.map-poi-loading {
    position: absolute;
    bottom: 12px;
    right: 12px;
    z-index: 900;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.95);
    color: #475569;
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    box-shadow: 0 3px 10px rgba(15, 23, 42, 0.18);
    pointer-events: none;
}

.map-poi-loading i { color: var(--vefa-accent, #ff4000); }

/* =====================================================
   Responsive
   ===================================================== */
@media (max-width: 767px) {
    .map-popup { width: 240px; }
    .map-popup__media { height: 110px; }
    .map-legend { max-width: 180px; }
    .map-zone-search { font-size: 0.78rem; padding: 7px 12px; }
}
