/*
 * Archivo: assets/css/mapa-style.css
 * Descripción: Estilos del plugin Mapa Trekking Parque.
 * Estética outdoor moderna: paleta verde bosque, tarjetas glassmorphism,
 * marcador GPS pulsante y seguimiento de ruta resaltado.
 */

/* =====================================================
   PALETA Y TOKENS DE DISEÑO
   ===================================================== */
.mtp-wrapper {
    --mtp-verde-900: #14532d;
    --mtp-verde-800: #166534;
    --mtp-verde-700: #15803d;
    --mtp-verde-600: #16a34a;
    --mtp-verde-500: #22c55e;
    --mtp-verde-300: #86efac;
    --mtp-lima: #a3e635;

    --mtp-tinta:   #0f2417; /* texto principal, verde muy oscuro */
    --mtp-gris:    #5b6b60; /* texto secundario */
    --mtp-crema:   #f4f7f2; /* fondo suave */
    --mtp-superficie: rgba(255, 255, 255, 0.92);
    --mtp-borde:   rgba(20, 83, 45, 0.10);

    --mtp-radio:   18px;
    --mtp-radio-sm: 12px;
    --mtp-sombra:  0 14px 30px -14px rgba(15, 36, 23, 0.35), 0 3px 8px -3px rgba(15, 36, 23, 0.12);
    --mtp-sombra-sm: 0 6px 16px -8px rgba(15, 36, 23, 0.30);

    --mtp-fuente: 'Poppins', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* =====================================================
   LAYOUT: MAPA + PANEL DE RUTAS
   ===================================================== */
.mtp-wrapper {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    font-family: var(--mtp-fuente);
    color: var(--mtp-tinta);
}

/* Contenedor principal del mapa */
#parque-trekking-map {
    position: relative;
    width: 100%;
    height: 60vh;
    min-height: 420px;
    border-radius: var(--mtp-radio);
    border: 1px solid var(--mtp-borde);
    box-shadow: var(--mtp-sombra);
    background:
        linear-gradient(135deg, #eaf3e6 0%, #dcefe0 100%);
    font-family: inherit;
    overflow: hidden;
}

/* Tinte outdoor: enriquece los verdes de las teselas sin arruinar la lectura */
#parque-trekking-map .leaflet-tile-pane {
    filter: saturate(1.12) contrast(1.03) brightness(1.01);
}

/* =====================================================
   ESTADOS: CARGANDO / FUERA DE RANGO / ERROR
   ===================================================== */
.mtp-estado {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 12px;
    height: 100%;
    min-height: 420px;
    padding: 40px 28px;
    font-family: var(--mtp-fuente);
    background:
        radial-gradient(120% 80% at 50% 0%, #eaf5e6 0%, #f4f7f2 60%);
}

.mtp-estado__titulo {
    margin: 0;
    font-size: 19px;
    font-weight: 600;
    color: var(--mtp-verde-900);
}

.mtp-estado__texto {
    margin: 0;
    max-width: 40ch;
    font-size: 14px;
    line-height: 1.6;
    color: var(--mtp-gris);
}

.mtp-estado__icono {
    color: var(--mtp-verde-600);
    display: inline-flex;
}

.mtp-estado--fuera .mtp-estado__icono,
.mtp-estado--fuera .mtp-estado__titulo { color: #b45309; }

.mtp-estado--error .mtp-estado__icono,
.mtp-estado--error .mtp-estado__titulo { color: #b91c1c; }

/* Spinner de carga */
.mtp-spinner {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 4px solid rgba(22, 163, 74, 0.18);
    border-top-color: var(--mtp-verde-600);
    animation: mtp-spin 0.8s linear infinite;
}

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

/* =====================================================
   PANEL DE RUTAS (CARDS) — mobile-first: fila deslizable
   ===================================================== */
.mtp-routes-panel {
    display: flex;
    flex-direction: row;
    gap: 12px;
    overflow-x: auto;
    padding: 4px 2px 12px 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scroll-snap-type: x proximity;
}

.mtp-routes-panel:empty {
    display: none;
}

.mtp-route-card {
    position: relative;
    flex: 0 0 auto;
    width: 220px;
    background: var(--mtp-superficie);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-radius: var(--mtp-radio);
    border: 1px solid var(--mtp-borde);
    box-shadow: var(--mtp-sombra-sm);
    padding: 16px 34px 16px 16px; /* margen derecho para el circulito de color */
    scroll-snap-align: start;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.mtp-route-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--mtp-sombra);
}

.mtp-route-card:focus-visible {
    outline: 2px solid var(--mtp-verde-600);
    outline-offset: 2px;
}

/* Card de la ruta seleccionada / en seguimiento:
   borde del color propio de la ruta (colorpicker), sin pestaña lateral. */
.mtp-route-card--activa {
    border-color: var(--ruta-color, var(--mtp-verde-600));
    box-shadow:
        0 0 0 2px var(--ruta-color, var(--mtp-verde-600)) inset,
        var(--mtp-sombra);
    transform: translateY(-2px);
}

/* Circulito de color de la ruta (esquina superior derecha) */
.mtp-route-card__dot {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--mtp-verde-500);
    box-shadow: 0 0 0 3px #ffffff, 0 1px 3px rgba(15, 36, 23, 0.28);
}

.mtp-route-card--activa .mtp-route-card__dot {
    animation: mtp-dot-pulse 1.6s ease-in-out infinite;
}

@keyframes mtp-dot-pulse {
    0%, 100% { box-shadow: 0 0 0 3px #fff, 0 0 0 4px rgba(22,163,74,0.0); }
    50%      { box-shadow: 0 0 0 3px #fff, 0 0 0 8px rgba(22,163,74,0.25); }
}

.mtp-route-card__nombre {
    font-family: var(--mtp-fuente);
    font-weight: 600;
    font-size: 15px;
    color: var(--mtp-tinta);
    margin: 0 0 8px 0;
    line-height: 1.3;
}

.mtp-route-card__meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.mtp-route-card__distancia {
    font-size: 13px;
    color: var(--mtp-gris);
    font-weight: 400;
}

/* Badge de dificultad */
.mtp-badge {
    display: inline-block;
    font-family: var(--mtp-fuente);
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    padding: 3px 9px;
    border-radius: 999px;
    white-space: nowrap;
}

.mtp-badge--facil   { background: #dcfce7; color: #15803d; }
.mtp-badge--media   { background: #fef9c3; color: #a16207; }
.mtp-badge--dificil { background: #fee2e2; color: #b91c1c; }
.mtp-badge--default { background: #e6efe6; color: #4b5d51; }

/* =====================================================
   DESKTOP: panel lateral fijo
   ===================================================== */
@media (min-width: 900px) {
    .mtp-wrapper {
        grid-template-columns: 1fr 290px;
        align-items: start;
    }

    #parque-trekking-map {
        height: 72vh;
        min-height: 520px;
    }

    .mtp-routes-panel {
        flex-direction: column;
        overflow-x: visible;
        overflow-y: auto;
        max-height: 72vh;
        padding: 4px;
    }

    .mtp-route-card {
        width: auto;
    }
}

/* =====================================================
   MARCADOR "ESTÁS AQUÍ" (GPS del usuario)
   ===================================================== */
.mtp-user-marker {
    position: relative;
}

.mtp-user-marker__core {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border-radius: 50%;
    background: #2563eb;
    border: 3px solid #ffffff;
    box-shadow: 0 1px 4px rgba(15, 36, 23, 0.45);
    z-index: 2;
}

.mtp-user-marker__pulse {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border-radius: 50%;
    background: rgba(37, 99, 235, 0.35);
    z-index: 1;
    animation: mtp-user-pulse 1.8s ease-out infinite;
}

@keyframes mtp-user-pulse {
    0%   { transform: scale(1);   opacity: 0.7; }
    100% { transform: scale(3.4); opacity: 0;   }
}

/* Círculo de precisión del GPS */
.mtp-accuracy-circle {
    animation: mtp-accuracy-breathe 3s ease-in-out infinite;
}

@keyframes mtp-accuracy-breathe {
    0%, 100% { fill-opacity: 0.10; }
    50%      { fill-opacity: 0.18; }
}

/* =====================================================
   TRAZO DE RUTA + PULSO DE LA RUTA ACTIVA
   ===================================================== */
.mtp-ruta-path {
    transition: stroke-width 0.2s ease;
}

/* Pulso "outdoor": halo que respira alrededor del sendero seleccionado.
   Usa filter (no lo pisa el stroke-opacity inline de Leaflet). */
.mtp-ruta-path--activa {
    animation: mtp-ruta-glow 1.8s ease-in-out infinite;
}

@keyframes mtp-ruta-glow {
    0%, 100% { filter: drop-shadow(0 0 1px var(--ruta-color, #16a34a)); }
    50%      { filter: drop-shadow(0 0 4px var(--ruta-color, #16a34a)); }
}

/* =====================================================
   MARCADORES DE INICIO / FIN DE RUTA
   ===================================================== */
.mtp-route-marker {
    background: transparent;
    border: none;
}

.mtp-route-marker__inner {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid var(--ruta-color, var(--mtp-verde-600));
    box-shadow: 0 2px 6px rgba(15, 36, 23, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
}

.mtp-route-marker--inicio .mtp-route-marker__inner {
    background: var(--ruta-color, var(--mtp-verde-600));
    border-color: #ffffff;
}

.mtp-route-marker__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ffffff;
}

.mtp-route-marker--fin .mtp-route-marker__flag {
    color: var(--ruta-color, var(--mtp-verde-600));
}

/* Tooltip "Inicio: ..." / "Meta: ..." / "Tú estás aquí" */
.leaflet-tooltip.mtp-route-tooltip {
    font-family: var(--mtp-fuente);
    font-size: 12px;
    font-weight: 600;
    color: var(--mtp-tinta);
    border: 1px solid var(--mtp-borde);
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(15, 36, 23, 0.18);
}

/* =====================================================
   CONTROLES LEAFLET (zoom, capas, recentrar)
   ===================================================== */
.leaflet-bar,
.leaflet-control-layers {
    border: 1px solid var(--mtp-borde) !important;
    border-radius: 12px !important;
    box-shadow: var(--mtp-sombra-sm) !important;
    overflow: hidden;
}

.leaflet-bar a {
    color: var(--mtp-verde-800);
}

.leaflet-bar a:hover {
    background: #eaf5e6;
    color: var(--mtp-verde-900);
}

.leaflet-control-layers {
    font-family: var(--mtp-fuente);
    padding: 4px;
}

/* Crédito de Leaflet/OSM: obligatorio por licencia, pero lo dejamos diminuto y
   translúcido para que no estorbe (se resalta al pasar el cursor). */
.leaflet-control-attribution {
    font-size: 9px;
    padding: 0 4px;
    background: rgba(255, 255, 255, 0.45);
    color: #7b8a80;
    opacity: 0.55;
    border-top-left-radius: 6px;
    transition: opacity 0.15s ease, background 0.15s ease;
}

.leaflet-control-attribution:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.9);
}

.leaflet-control-attribution a {
    color: #5b6b60;
}

.leaflet-control-layers-toggle {
    background-color: #ffffff;
}

/* Botón de recentrado personalizado */
.mtp-recenter-btn {
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    color: var(--mtp-verde-700);
    border: 1px solid var(--mtp-borde);
    border-radius: 50%;
    box-shadow: var(--mtp-sombra-sm);
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.mtp-recenter-btn:hover {
    background: var(--mtp-verde-600);
    color: #ffffff;
    transform: scale(1.06);
}

.mtp-recenter-btn:active {
    transform: scale(0.96);
}

/* =====================================================
   POPUPS DE LEAFLET
   ===================================================== */
.leaflet-popup-content-wrapper {
    border-radius: var(--mtp-radio-sm);
    box-shadow: 0 12px 26px -10px rgba(15, 36, 23, 0.30);
}

.leaflet-popup-content {
    font-family: var(--mtp-fuente);
    font-size: 14px;
    line-height: 1.6;
    color: #33443a;
    margin: 14px 18px;
}

.leaflet-popup-content b {
    display: block;
    font-size: 16px;
    color: var(--mtp-verde-900);
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--mtp-borde);
}

.leaflet-container a.leaflet-popup-close-button {
    color: #7b8a80;
    padding: 6px;
    font-weight: bold;
}

.leaflet-container a.leaflet-popup-close-button:hover {
    color: var(--mtp-verde-700);
}

/* =====================================================
   PANEL DE PROGRESO DE LA RUTA SELECCIONADA
   ===================================================== */
.mtp-progreso-panel {
    grid-column: 1 / -1;
    position: relative;
    background: var(--mtp-superficie);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: var(--mtp-radio);
    border: 1px solid var(--mtp-borde);
    box-shadow: var(--mtp-sombra);
    padding: 18px 44px 18px 20px;
    font-family: var(--mtp-fuente);
    animation: mtp-panel-in 0.3s ease;
}

@keyframes mtp-panel-in {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.mtp-progreso-panel__cerrar {
    position: absolute;
    top: 10px;
    right: 12px;
    background: transparent;
    border: none;
    font-size: 22px;
    line-height: 1;
    color: #9aa89e;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: color 0.15s ease, background 0.15s ease;
}

.mtp-progreso-panel__cerrar:hover {
    color: #b91c1c;
    background: #fee2e2;
}

.mtp-progreso-panel__nombre {
    font-weight: 600;
    font-size: 16px;
    color: var(--mtp-verde-900);
    margin: 0 0 12px 0;
    padding-left: 22px;
    position: relative;
}

/* Iconito de banderín antes del nombre */
.mtp-progreso-panel__nombre::before {
    content: "";
    position: absolute;
    left: 0;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--mtp-verde-500);
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.18);
}

.mtp-progreso-panel__barra {
    width: 100%;
    height: 10px;
    background: #e3ede0;
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 10px;
}

.mtp-progreso-panel__barra-relleno {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--mtp-verde-600), var(--mtp-lima));
    border-radius: 999px;
    transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
    position: relative;
    overflow: hidden;
}

/* Brillo que recorre la barra de progreso */
.mtp-progreso-panel__barra-relleno::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.55), transparent);
    transform: translateX(-100%);
    animation: mtp-barra-brillo 2.2s ease-in-out infinite;
}

@keyframes mtp-barra-brillo {
    0%   { transform: translateX(-100%); }
    60%, 100% { transform: translateX(200%); }
}

.mtp-progreso-panel__datos {
    font-size: 13px;
    color: var(--mtp-gris);
    margin: 0;
}

.mtp-progreso-panel__alerta {
    margin: 12px 0 0 0;
    font-size: 13px;
    font-weight: 600;
    color: #b91c1c;
    background: #fee2e2;
    padding: 9px 12px;
    border-radius: 10px;
    animation: mtp-alerta-parpadeo 1.2s ease-in-out infinite;
}

@keyframes mtp-alerta-parpadeo {
    0%, 100% { background: #fee2e2; }
    50%      { background: #fecaca; }
}

/* =====================================================
   ACCESIBILIDAD: reducir movimiento
   ===================================================== */
@media (prefers-reduced-motion: reduce) {
    .mtp-user-marker__pulse,
    .mtp-accuracy-circle,
    .mtp-ruta-path--activa,
    .mtp-route-card--activa .mtp-route-card__dot,
    .mtp-progreso-panel__barra-relleno::after,
    .mtp-progreso-panel__alerta,
    .mtp-spinner {
        animation: none !important;
    }
}
