/* ==========================================================================
   AVISTAMIENTOS COMUNITARIOS — mapa con lista lateral
   Paleta del sitio: negro #0f0f0f, tarjetas #161616, bordes #262626, verde #4ade80 / esmeralda #059669.
   ========================================================================== */

.sm {
    --card: #161616;
    --card-hi: #1c1c1c;
    --line: #262626;
    --text: #f7fafc;
    --muted: #9ca3af;
    --soft: #cbd5e1;
    --green: #4ade80;
    --emerald: #059669;
    --spring: cubic-bezier(0.23, 1, 0.32, 1);

    max-width: 1440px;
    margin: 0 auto;
    padding: 28px 5% 64px;
    background: #0f0f0f;
    color: var(--text);
    font-family: 'Matter', 'Inter', 'DM Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    box-sizing: border-box;
}
.sm *, .sm *::before, .sm *::after { box-sizing: border-box; }

/* ---------- Encabezado ---------- */
.sm-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 18px; }
.sm-title { margin: 0 0 10px; font-size: clamp(2rem, 4vw, 2.8rem); font-weight: 300; line-height: 1.1; letter-spacing: -0.02em; }
.sm-sub { margin: 0; max-width: 62ch; font-size: 15px; line-height: 1.6; color: var(--muted); }
.sm-cta { flex: none; display: inline-flex; align-items: center; gap: 10px; padding: 11px 20px; border-radius: 50px; background: var(--emerald); color: #fff; font-size: 14px; font-weight: 600; text-decoration: none; transition: background-color 0.2s ease, transform 0.35s var(--spring); }
.sm-cta i { font-size: 12px; transition: transform 0.35s var(--spring); }
.sm-cta:hover { background: #047857; transform: translateY(-1px); }
.sm-cta:hover i { transform: translateX(4px); }
.sm-cta:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }

/* ---------- Cifras ---------- */
.sm-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.sm-stat { display: flex; flex-direction: column; gap: 2px; padding: 12px 18px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); }
.sm-stat strong { font-size: 24px; font-weight: 500; line-height: 1; color: var(--green); font-variant-numeric: tabular-nums; }
.sm-stat span { font-size: 13px; color: var(--muted); }

/* ---------- Mapa + lista ---------- */
.sm-shell { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 16px; height: clamp(580px, 82vh, 900px); }

.sm-side { display: flex; flex-direction: column; min-height: 0; padding: 12px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); }
.sm-search { position: relative; margin-bottom: 12px; }
.sm-search i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-size: 13px; color: #6b7280; pointer-events: none; }
.sm-search input { width: 100%; height: 44px; padding: 0 14px 0 38px; border-radius: 12px; border: 1px solid #2f2f2f; background: #101010; color: #fff; font: inherit; font-size: 14px; outline: none; transition: border-color 0.2s ease, box-shadow 0.2s ease; }
.sm-search input::placeholder { color: #5b6068; }
.sm-search input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.14); }

.sm-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; max-height: 64px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #333 transparent; }
.sm-chip { padding: 5px 11px; border-radius: 50px; border: 1px solid #2f2f2f; background: transparent; color: var(--soft); font: inherit; font-size: 12px; cursor: pointer; transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease; }
.sm-chip em { font-style: italic; }
.sm-chip small { margin-left: 5px; color: #6b7280; font-size: 11px; }
.sm-chip:hover { border-color: #4a4a4a; background: #1c1c1c; }
.sm-chip.is-on { border-color: rgba(74, 222, 128, 0.5); background: rgba(74, 222, 128, 0.12); color: var(--green); }
.sm-chip.is-on small { color: #86efac; }
.sm-chip:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.sm-count { padding: 0 2px 10px; font-size: 12px; color: #8b95a3; border-bottom: 1px solid var(--line); }

.sm-list { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -6px; padding: 10px 6px 0; display: flex; flex-direction: column; gap: 8px; scrollbar-width: thin; scrollbar-color: #333 transparent; }
.sm-item { display: flex; gap: 10px; align-items: center; width: 100%; padding: 8px; text-align: left; border-radius: 12px; border: 1px solid transparent; background: var(--card-hi); color: inherit; font: inherit; cursor: pointer; transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.35s var(--spring); }
.sm-item:hover { background: #222; border-color: #333; transform: translateX(2px); }
.sm-item.is-active { border-color: rgba(74, 222, 128, 0.55); background: rgba(74, 222, 128, 0.07); }
.sm-item:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.sm-item__img { flex: none; width: 48px; height: 48px; border-radius: 10px; overflow: hidden; display: flex; align-items: center; justify-content: center; background: #0f0f0f; border: 1px solid #2a2a2a; color: #4ade80; font-size: 18px; }
.sm-item__img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sm-item__txt { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.sm-item__sp { font-size: 13.5px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sm-item__sp.is-sp { font-style: italic; }
.sm-item__meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sm-item__meta i { margin-right: 5px; font-size: 11px; color: #6b7280; }
.sm-vacio { padding: 28px 12px; text-align: center; font-size: 14px; line-height: 1.5; color: var(--muted); }

.sm-mapwrap { position: relative; min-height: 0; border-radius: 16px; overflow: hidden; border: 1px solid #3a3a3a; background: #e5e3df; box-shadow: 0 10px 34px rgba(0, 0, 0, 0.45); }
.sm-map { position: absolute; inset: 0; z-index: 1; background: #e5e3df; }
.sm-loading { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; gap: 12px; background: rgba(15, 15, 15, 0.9); font-size: 14px; color: var(--muted); transition: opacity 0.4s ease, visibility 0.4s; }
.sm-loading.is-hidden { opacity: 0; visibility: hidden; }
.sm-loading span { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #333; border-top-color: var(--green); animation: sm-spin 0.8s linear infinite; }
@keyframes sm-spin { to { transform: rotate(360deg); } }

/* ---------- Animación de entrada del mapa (estilo Mapbox: emerge de la oscuridad) ---------- */
@property --sm-r { syntax: '<percentage>'; inherits: false; initial-value: 0%; }
.sm-mapwrap::after { content: ''; position: absolute; inset: 0; z-index: 4; pointer-events: none; opacity: 0; background: radial-gradient(circle at 50% 50%, transparent var(--sm-r), #0e1012 calc(var(--sm-r) + 38%)); }
.sm-mapwrap.is-revelando::after { animation: sm-emerge 4.4s cubic-bezier(0.3, 0.6, 0.25, 1) both; }
@keyframes sm-emerge { 0% { --sm-r: 0%; opacity: 1; } 70% { opacity: 1; } 100% { --sm-r: 110%; opacity: 0; } }
.sm-mapwrap.is-revelando .sm-map { animation: sm-asienta 5s cubic-bezier(0.3, 0.6, 0.25, 1) both; }
@keyframes sm-asienta { from { transform: scale(1.08); } to { transform: scale(1); } }
.sm-mapwrap.is-revelando .leaflet-control-container { animation: sm-aparece 1s ease 3.2s both; }
@keyframes sm-aparece { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------- Pines ---------- */
.sm-pin { position: relative; display: block; width: 44px; height: 59px; }
.sm-pin__cuerpo { position: absolute; inset: 0; display: block; transform-origin: 50% 100%; transition: transform 0.35s var(--spring); }
.sm-pin__svg { position: relative; display: block; overflow: visible; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.45)); }
.sm-pin__forma { fill: #e11d48; stroke: #fff; stroke-width: 2.5; stroke-linejoin: round; transition: fill 0.2s ease; }
.sm-pin__ojo { fill: #fff; }
.sm-pin__lente { fill: #059669; transition: fill 0.2s ease; }
/* Con fotografía: alfiler verde para distinguirlo a simple vista */
.sm-pin--foto .sm-pin__forma { fill: #059669; }
/* Sombra en el suelo y onda que se expande desde la punta */
.sm-pin__sombra { position: absolute; left: 50%; bottom: -2px; width: 22px; height: 7px; margin-left: -11px; border-radius: 50%; background: rgba(0, 0, 0, 0.35); filter: blur(1.5px); }
.sm-pin__pulse { position: absolute; left: 50%; bottom: -5px; width: 38px; height: 15px; margin-left: -19px; border-radius: 50%; border: 2px solid rgba(225, 29, 72, 0.7); animation: sm-pulso 2.6s ease-out infinite; }
.sm-pin--foto .sm-pin__pulse { border-color: rgba(5, 150, 105, 0.7); }
@keyframes sm-pulso { 0% { transform: scale(0.4); opacity: 0.95; } 100% { transform: scale(1.9); opacity: 0; } }
.leaflet-marker-icon:hover .sm-pin__cuerpo { transform: translateY(-5px) scale(1.1); }
.leaflet-marker-icon:hover .sm-pin__forma { fill: #be123c; }
.leaflet-marker-icon:hover .sm-pin--foto .sm-pin__forma, .leaflet-marker-icon:hover .sm-pin--foto .sm-pin__lente { fill: #047857; }
.sm-pin.is-active .sm-pin__cuerpo { transform: translateY(-6px) scale(1.25); }
.sm-pin.is-active .sm-pin__forma { fill: #be123c; }
.sm-pin--foto.is-active .sm-pin__forma, .sm-pin--foto.is-active .sm-pin__lente { fill: #047857; }

/* Los pines caen y se asientan uno tras otro, como un pin de GPS que se clava en el mapa */
.sm-mapwrap:not(.sm-listo) .sm-pin, .sm-mapwrap:not(.sm-listo) .marker-cluster div { opacity: 0; }
.sm-mapwrap.sm-listo .sm-pin { animation: sm-cae 1.1s var(--spring) both; animation-delay: var(--d, 0ms); }
@keyframes sm-cae { 0% { opacity: 0; transform: translateY(-34px) scale(0.5); } 55% { opacity: 1; } 100% { opacity: 1; transform: none; } }
.sm-mapwrap.sm-listo .marker-cluster div { animation: sm-brota 0.9s var(--spring) both; }
@keyframes sm-brota { from { opacity: 0; transform: scale(0.4); } to { opacity: 1; transform: none; } }

/* Grupos de pines */
.marker-cluster { background-clip: padding-box; border-radius: 50%; }
.marker-cluster div { width: 30px; height: 30px; margin-left: 5px; margin-top: 5px; text-align: center; border-radius: 50%; }
.marker-cluster-small, .marker-cluster-medium, .marker-cluster-large { background: rgba(74, 222, 128, 0.22) !important; }
.marker-cluster-small div, .marker-cluster-medium div, .marker-cluster-large div { background: #059669 !important; color: #fff; font: 700 13px/30px 'Inter', system-ui, sans-serif; border: 2px solid #0f0f0f; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.55); }
.marker-cluster span { line-height: 30px; }

/* ---------- Controles de Leaflet en tema oscuro ---------- */
.sm .leaflet-bar a, .sm .leaflet-bar a:hover { background: #161616; color: #e5e7eb; border-bottom: 1px solid #2a2a2a; }
.sm .leaflet-bar a:hover { background: #222; color: var(--green); }
.sm .leaflet-bar { border: 1px solid #2f2f2f; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5); border-radius: 10px; overflow: hidden; }
.sm .leaflet-control-layers { background: rgba(22, 22, 22, 0.95); color: #e5e7eb; border: 1px solid #2f2f2f; border-radius: 10px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5); }
.sm .leaflet-control-layers-toggle { background-color: #161616; border-radius: 10px; }
.sm .leaflet-control-layers-expanded { padding: 8px 12px; font-size: 13px; }
.sm .leaflet-control-attribution { background: rgba(15, 15, 15, 0.75) !important; color: #8b95a3 !important; font-size: 10px; }
.sm .leaflet-control-attribution a { color: #9ca3af !important; }
.sm-ver-todo { display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; color: #e5e7eb; cursor: pointer; }
.sm-ver-todo i { font-size: 14px; }

/* ---------- Ventana emergente ---------- */
.sm .leaflet-popup-content-wrapper { padding: 0; overflow: hidden; background: #161616 !important; color: var(--text) !important; border: 1px solid #333; border-radius: 16px; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.7); }
.sm .leaflet-popup-content { margin: 0 !important; width: 290px !important; }
/* La ventana del avistamiento emerge con un suave rebote desde el pin */
.sm .leaflet-popup-content-wrapper { animation: sm-popup 0.45s var(--spring) both; transform-origin: 50% 100%; }
@keyframes sm-popup { from { opacity: 0; transform: translateY(14px) scale(0.92); } to { opacity: 1; transform: none; } }
.sm .leaflet-popup-tip { background: #161616 !important; border: 1px solid #333; }
.sm .leaflet-container a.leaflet-popup-close-button { top: 8px; right: 8px; width: 28px; height: 28px; padding: 0; border-radius: 50%; background: rgba(15, 15, 15, 0.75); color: #fff !important; font: 18px/26px sans-serif; text-align: center; z-index: 3; }
.sm .leaflet-container a.leaflet-popup-close-button:hover { background: #dc2626; }

.smp__img { width: 100%; height: 150px; display: block; object-fit: cover; background: #0f0f0f; }
.smp__noimg { height: 74px; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, rgba(74, 222, 128, 0.16), rgba(5, 150, 105, 0.04)); color: var(--green); font-size: 24px; }
.smp__body { padding: 14px 16px 16px; }
.smp__sp { margin: 0 0 3px; font-size: 16px; font-weight: 600; line-height: 1.25; color: var(--text); }
.smp__sp.is-sp { font-style: italic; color: var(--green); }
.smp__cat { margin: 0 0 10px; font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.smp__row { display: flex; align-items: flex-start; gap: 9px; margin: 0 0 6px; font-size: 12.5px; line-height: 1.4; color: var(--soft); }
.smp__row i { flex: none; width: 14px; margin-top: 2px; text-align: center; font-size: 12px; color: var(--green); }
.smp__desc { margin: 10px 0 12px; padding-top: 10px; border-top: 1px solid #262626; font-size: 12.5px; line-height: 1.55; color: #a0aec0; display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.smp__btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 9px 14px; border-radius: 10px; background: var(--emerald); color: #fff !important; font-size: 13px; font-weight: 600; text-decoration: none; transition: background-color 0.2s ease; }
.smp__btn:hover { background: #047857; }

/* ---------- Pantallas pequeñas ---------- */
@media (max-width: 1100px) {
    .sm-shell { grid-template-columns: 260px minmax(0, 1fr); }
    .sm-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
    .sm { padding: 20px 16px 48px; }
    .sm-head { flex-direction: column; align-items: flex-start; }
    .sm-shell { grid-template-columns: 1fr; height: auto; }
    .sm-mapwrap { order: 1; height: 60vh; min-height: 380px; }
    .sm-side { order: 2; max-height: 440px; }
    .sm .leaflet-popup-content { width: 250px !important; }
}

@media (prefers-reduced-motion: reduce) {
    .sm-pin__pulse, .sm-loading span, .sm-mapwrap.sm-listo .sm-pin, .sm-mapwrap.sm-listo .marker-cluster div, .sm .leaflet-popup-content-wrapper { animation: none; }
    .sm-mapwrap::after { display: none; }
    .sm-item, .sm-cta, .sm-pin__cuerpo { transition: none; }
}
