/* ==========================================================================
   Vegenergy Finder — Map Background Styles
   Nur aktiv wenn body.has-map gesetzt ist (Performance-Detection bestanden)
   ========================================================================== */

/* --- Karten-Container (fixed, hinter allem) --- */
#map-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    z-index: 0;
    opacity: 0;
    transition: opacity 1.5s ease;
    pointer-events: none !important;
    touch-action: auto !important;
    overflow: clip !important;
    background-color: #163a16;
    /* CHROME-SCROLL-FIX v0.5.4.24:
     * contain:strict isoliert dieses Element vollständig vom Compositor.
     * Chrome erstellt für position:fixed einen eigenen Compositor-Layer.
     * Ohne contain:strict routet Chrome Scroll-Events an diesen Layer
     * statt an den Viewport — obwohl pointer-events:none gesetzt ist.
     * contain:strict sagt dem Compositor: "Dieses Element ist komplett
     * unabhängig, ignoriere es für Scroll-Hit-Testing." */
    contain: strict;
}

/*
 * CHROME-SCROLL-FIX: Leaflet.css setzt .leaflet-container { overflow: hidden },
 * was Chrome's Compositor als Scroll-Layer behandelt und Wheel-Events verschluckt.
 * overflow:clip (oben) behebt das. Zusätzlich pointer-events:none + touch-action:auto
 * auf ALLEN Kinder-Elementen als Sicherheitsnetz.
 */
#map-background,
#map-background *,
#map-background .leaflet-container,
#map-background .leaflet-container * {
    pointer-events: none !important;
    touch-action: auto !important;
}

/* Leaflet Container: overflow:clip statt hidden — kein Scroll-Container */
#map-background .leaflet-container {
    background-color: #163a16 !important;
    overflow: clip !important;
}

/* Karte einblenden wenn bereit */
.has-map #map-background {
    opacity: 1;
}

/* --- Grüner Tile-Filter (CartoDB Dark Matter → Vegenergy Green) --- */
#map-background .leaflet-tile-pane {
    filter: brightness(0.65) sepia(0.30) hue-rotate(75deg) saturate(1.6);
    transition: filter 0.8s ease;
}

/* Leicht heller beim Hover / Interaktion */
.has-map #map-background.map-interactive .leaflet-tile-pane {
    filter: brightness(0.72) sepia(0.25) hue-rotate(75deg) saturate(1.5);
}

/* --- Gradient-Overlay über der Karte --- */
#map-background::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background:
        /* Oben: stärker abdunkeln für Header-Lesbarkeit */
        linear-gradient(180deg,
            rgba(22, 58, 22, 0.82) 0%,
            rgba(28, 74, 28, 0.58) 25%,
            rgba(34, 112, 74, 0.40) 50%,
            rgba(28, 74, 28, 0.58) 75%,
            rgba(22, 58, 22, 0.82) 100%
        );
    transition: opacity 0.8s ease;
}

/* Stärker abdunkeln wenn Ergebnisse sichtbar sind */
#map-background.map-results-visible::after {
    background:
        linear-gradient(180deg,
            rgba(22, 58, 22, 0.86) 0%,
            rgba(28, 74, 28, 0.65) 20%,
            rgba(34, 112, 74, 0.48) 45%,
            rgba(28, 74, 28, 0.65) 70%,
            rgba(22, 58, 22, 0.86) 100%
        );
}

/* --- Content über der Karte anheben --- */
.has-map header {
    position: relative;
    z-index: 10;
}

.has-map .hero-section {
    position: relative;
    z-index: 2;
}

.has-map .hero-content {
    position: relative;
    z-index: 3;
}

.has-map main {
    position: relative;
    z-index: 2;
}

/* Hero-Beschreibung und SEO-Stores: solider Hintergrund statt transparenter Karte */
.has-map .hero-description {
    background: rgba(28, 74, 28, 0.40);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.has-map .seo-stores-fallback {
    position: relative;
    z-index: 2;
    max-width: 800px;
    margin: 2rem auto;
    padding: 2rem;
    background: rgba(28, 74, 28, 0.40);
    border: 1px solid rgba(255, 255, 255, 0.20);
    border-radius: 12px;
    text-align: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.has-map main {
    position: relative;
    z-index: 2;
}

.has-map .results-section {
    position: relative;
    z-index: 2;
}

.has-map .footer {
    position: relative;
    z-index: 2;
    background-color: #1c4a1c;
    background: linear-gradient(180deg, #1c4a1c 0%, #256e32 50%, #163a16 100%);
}

/* FAQ-Sektion: Karte verdecken, grüner Hintergrund */
.has-map .faq-section {
    position: relative;
    z-index: 2;
    max-width: 800px;
    margin: 0 auto;
}

.has-map .faq-section::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100vw;
    background: linear-gradient(180deg, #163a16 0%, #1c4a1c 50%, #163a16 100%);
    z-index: -1;
}

/* Error/GPS-Fehlermeldungen: solider Hintergrund über der Karte */
.has-map .error-message {
    background: rgba(255, 107, 107, 0.15);
    border-color: rgba(255, 107, 107, 0.35);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.has-map .gps-loading-message,
.has-map .ios-location-help {
    background: rgba(28, 74, 28, 0.88);
    border-color: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.has-map .initial-tip {
    background: rgba(28, 74, 28, 0.40);
    border-color: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.has-map .cookie-settings-toggler {
    z-index: 11;
}

/* --- Leaflet UI verstecken (keine Controls sichtbar) --- */
#map-background .leaflet-control-container {
    display: none !important;
}

/* --- Custom Marker --- */

/* Leaflet-Standard-Icon-Styles überschreiben (sonst eckig + weißer Hintergrund) */
.leaflet-div-icon {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
}

.map-marker-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    /* Leaflet setzt width/height — nicht vererben */
    background: none !important;
    border: none !important;
}

.map-marker {
    width: 14px;
    height: 14px;
    aspect-ratio: 1;
    border-radius: 50%;
    background: var(--vegaenergy-bright, #80cc28);
    border: 2px solid rgba(255, 255, 255, 0.6);
    box-shadow:
        0 0 10px rgba(128, 204, 40, 0.5),
        0 0 24px rgba(128, 204, 40, 0.25);
    animation: marker-appear 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    position: relative;
    z-index: 5;
}

/* Pulsierender Glow-Ring */
.map-marker::after {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 1.5px solid rgba(128, 204, 40, 0.35);
    animation: marker-pulse 2.5s ease-in-out infinite;
}

/* Erster Marker (nächste Verkaufsstelle) etwas größer */
.map-marker-primary {
    width: 18px;
    height: 18px;
    background: var(--vegaenergy-bright, #80cc28);
    border: 2.5px solid rgba(255, 255, 255, 0.8);
    box-shadow:
        0 0 14px rgba(128, 204, 40, 0.6),
        0 0 32px rgba(128, 204, 40, 0.3);
}

.map-marker-primary::after {
    inset: -8px;
    border: 2px solid rgba(128, 204, 40, 0.45);
}

/* User-Standort Marker */
.map-marker-user {
    width: 12px;
    height: 12px;
    background: #ffffff;
    border: 2.5px solid rgba(128, 204, 40, 0.9);
    box-shadow:
        0 0 10px rgba(255, 255, 255, 0.4),
        0 0 20px rgba(128, 204, 40, 0.3);
}

.map-marker-user::after {
    inset: -8px;
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    animation: marker-pulse 2s ease-in-out infinite;
}

/* --- Marker-Animationen --- */
@keyframes marker-appear {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    60% {
        transform: scale(1.3);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes marker-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.6;
    }
    50% {
        transform: scale(1.6);
        opacity: 0;
    }
}

/* Gestaffelte Einblendung */
.map-marker-delay-1 { animation-delay: 0.15s; }
.map-marker-delay-2 { animation-delay: 0.30s; }
.map-marker-delay-3 { animation-delay: 0.45s; }
.map-marker-delay-4 { animation-delay: 0.60s; }

/* --- Karten-Transition beim Fliegen --- */
#map-background.map-flying .leaflet-tile-pane {
    filter: brightness(0.5) sepia(0.4) hue-rotate(75deg) saturate(1.6) blur(1px);
}

/* --- Attribution (rechtlich erforderlich, dezent) --- */
.map-attribution {
    position: fixed;
    bottom: 4px;
    right: 8px;
    z-index: 1;
    font-size: 9px;
    color: rgba(255, 255, 255, 0.2);
    pointer-events: none;
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    letter-spacing: 0.02em;
    transition: opacity 0.3s ease;
}

.has-map .map-attribution {
    display: block;
}

body:not(.has-map) .map-attribution {
    display: none;
}

.map-attribution:hover {
    color: rgba(255, 255, 255, 0.5);
    pointer-events: auto;
}

.map-attribution a {
    color: inherit;
    text-decoration: none;
}

.map-attribution a:hover {
    text-decoration: underline;
}

/* ==========================================================================
   Responsive Anpassungen
   ========================================================================== */

/* Tablet */
@media (max-width: 768px) {
    #map-background::after {
        background:
            linear-gradient(180deg,
                rgba(22, 58, 22, 0.78) 0%,
                rgba(28, 74, 28, 0.55) 30%,
                rgba(34, 112, 74, 0.38) 50%,
                rgba(28, 74, 28, 0.55) 70%,
                rgba(22, 58, 22, 0.80) 100%
            );
    }

    #map-background .leaflet-tile-pane {
        filter: brightness(0.60) sepia(0.30) hue-rotate(75deg) saturate(1.5);
    }

    .map-marker {
        width: 11px;
        height: 11px;
    }

    .map-marker-primary {
        width: 14px;
        height: 14px;
    }
}

/* Mobile */
@media (max-width: 480px) {
    #map-background::after {
        background:
            linear-gradient(180deg,
                rgba(22, 58, 22, 0.82) 0%,
                rgba(28, 74, 28, 0.60) 30%,
                rgba(34, 112, 74, 0.42) 50%,
                rgba(28, 74, 28, 0.60) 70%,
                rgba(22, 58, 22, 0.84) 100%
            );
    }

    #map-background .leaflet-tile-pane {
        filter: brightness(0.55) sepia(0.30) hue-rotate(75deg) saturate(1.4);
    }

    .map-marker {
        width: 9px;
        height: 9px;
        border-width: 1.5px;
    }

    .map-marker-primary {
        width: 12px;
        height: 12px;
    }

    .map-marker::after {
        inset: -4px;
    }

    .map-attribution {
        font-size: 8px;
        bottom: 2px;
        right: 4px;
    }
}

/* ==========================================================================
   Reduced Motion — Animationen deaktivieren
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    #map-background {
        transition: opacity 0.3s ease;
    }

    #map-background .leaflet-tile-pane {
        transition: filter 0.2s ease;
    }

    #map-background::after {
        transition: none;
    }

    .map-marker {
        animation: none !important;
        opacity: 1;
        transform: scale(1);
    }

    .map-marker::after {
        animation: none !important;
        opacity: 0.4;
    }

    #map-background.map-flying .leaflet-tile-pane {
        filter: brightness(0.65) sepia(0.30) hue-rotate(75deg) saturate(1.6);
    }
}
