/* mapa.css - Map page specific styles, updated */
/* Layout general de la página de mapa */
.map-page {
    padding-top: 8px;
    padding-bottom: 0;
}


/* Barra superior */
.map-toolbar {
    padding-block: 10px 6px;
}

.map-toolbar-inner {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.map-title {
    font-family: "Playfair Display", Georgia, serif;
    font-size: 20px;
    margin: 0 0 4px;
}

.map-subtitle {
    margin: 0;
    font-size: 13px;
    color: var(--color-muted);
    max-width: 520px;
}

/* Botones modo gasolina / eléctrico */
.btn-pill {
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 13px;
    border: 1px solid var(--color-border);
    background-color: #ffffff;
    cursor: pointer;
    transition: background-color var(--transition-main), transform var(--transition-main), box-shadow var(--transition-main), border-color var(--transition-main);
}

.btn-pill:hover {
    background-color: var(--color-accent);
    border-color: transparent;
    transform: translateY(-2px);
    box-shadow: var(--shadow-soft);
}

.btn-pill.is-active {
    background-color: var(--color-accent-strong);
    color: var(--color-ink);
    border-color: var(--color-accent-strong);
}

.btn-pill[data-mode="gasolina"].is-active {
    background-color: #2a9d8f;
    color: #ffffff;
    border-color: #2a9d8f;
}

.btn-pill[data-mode="electrico"].is-active {
    background-color: #264653;
    color: #ffffff;
    border-color: #264653;
}

.map-toolbar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* Layout mapa + panel lateral */
.map-layout {
    padding-top: 6px;
}

.map-layout-inner {
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 12px;
    padding-inline: 16px;
}

/* Panel lateral reusando estilo "card" de la home */
.map-sidebar {
    background-color: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-soft);
    padding: 14px;
    max-height: calc(100vh - 180px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.map-sidebar .sidebar-header.desktop-only {
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    margin-bottom: 10px;
}

@media (max-width: 900px) {
    .map-sidebar .sidebar-header.desktop-only {
        display: none;
    }
}

.map-sidebar .sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
}

/* Search within sidebar */
.search-input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.search-input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.search-input-wrapper span {
    position: absolute;
    left: 10px;
    color: var(--color-muted);
    font-size: 14px;
}

.search-input-wrapper input {
    width: 100%;
    padding: 9px 10px 9px 32px;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    font-size: 13px;
    transition: border-color var(--transition-main), box-shadow var(--transition-main);
}

.search-input-wrapper input:focus {
    outline: none;
    border-color: var(--color-accent-strong);
    box-shadow: 0 0 0 3px rgba(244, 162, 97, 0.15);
}

.btn-search {
    border-radius: 999px;
    border: none;
    padding: 9px 16px;
    font-size: 13px;
    font-weight: 500;
    background-color: var(--color-accent-strong);
    color: var(--color-ink);
    cursor: pointer;
    transition: transform var(--transition-main), box-shadow var(--transition-main), background-color var(--transition-main);
    box-shadow: var(--shadow-soft);
}

.btn-search:hover {
    transform: scale(1.05) translateY(-1px);
    box-shadow: var(--shadow-hover);
    background-color: var(--color-accent);
}

/* Filter chips row */
.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.filter-chip {
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 12px;
    background-color: #ffffff;
    border: 1px solid #e0e0e0;
    cursor: pointer;
    transition: transform var(--transition-main), box-shadow var(--transition-main), background-color var(--transition-main);
}

.filter-chip:hover {
    background-color: var(--color-accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow-soft);
}

.filter-chip.is-active {
    background-color: var(--color-ink);
    color: #fff;
    border-color: var(--color-ink);
}

/* Stats panel */
.stats-panel {
    background-color: var(--color-bg-alt);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    margin-bottom: 8px;
}


.stats-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-muted);
    margin-bottom: 6px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin-bottom: 4px;
}

.stat-val {
    font-weight: 600;
    color: var(--color-ink);
}

.price-range-bar {
    height: 6px;
    background: linear-gradient(90deg, #22c55e 0%, #eab308 50%, #ef4444 100%);
    border-radius: 3px;
    margin-top: 6px;
    position: relative;
}

.avg-marker {
    position: absolute;
    top: -4px;
    width: 2px;
    height: 14px;
    background: #000;
    transform: translateX(-50%);
}

/* Station list */
.stations-list-header {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-muted);
    padding: 8px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    margin-bottom: 6px;
}

.station-item {
    padding: 10px 8px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.station-item:hover {
    background-color: var(--color-bg-alt);
}

.station-item.is-active {
    background: linear-gradient(135deg, #f0fdf4, #dcfce7);
    border-left: 4px solid #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2), 0 4px 15px rgba(34, 197, 94, 0.15);
    transform: scale(1.02);
    position: relative;
    z-index: 5;
}

.station-item.is-active::after {
    content: '📍';
    position: absolute;
    top: -6px;
    right: 8px;
    font-size: 16px;
    animation: evBadgeBounce 0.4s ease;
}

@keyframes evBadgeBounce {
    0% {
        transform: scale(0) translateY(10px);
        opacity: 0;
    }

    60% {
        transform: scale(1.3) translateY(-2px);
    }

    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.station-item .st-info h4 {
    margin: 0 0 2px;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-ink);
}

.station-item .st-info .brand {
    font-size: 11px;
    color: var(--color-muted);
    text-transform: uppercase;
    font-weight: 700;
}

.station-item .st-info .addr {
    font-size: 12px;
    color: var(--color-muted);
}

.station-item .st-price {
    text-align: right;
}

.station-item .price-tag {
    font-size: 16px;
    font-weight: 700;
    color: var(--color-ink);
}

.station-item .price-diff {
    font-size: 11px;
    border-radius: 4px;
    padding: 2px 6px;
    display: inline-block;
    margin-top: 2px;
    font-weight: 600;
}

.price-diff.diff-good {
    background: #dcfce7;
    color: #166534;
}

.price-diff.diff-avg {
    background: #fef9c3;
    color: #854d0e;
}

.price-diff.diff-bad {
    background: #fee2e2;
    color: #991b1b;
}

/* Contenedor del mapa */
.map-canvas-wrapper {
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
    background-color: #dce1e7;
    position: relative;
}

.map-canvas {
    width: 100%;
    height: calc(100vh - 180px);
    min-height: 400px;
}

/* Floating Search Bar on Map */
.map-search-floating {
    position: absolute;
    top: 16px;
    left: 16px;
    right: 16px;
    z-index: 1001;
    /* Por encima de Leaflet */
    pointer-events: none;
    /* Permite que los clics pasen al mapa si no es en los elementos hijos */
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 500px;
}

.map-search-floating .search-input-row,
.map-search-floating .filter-chips {
    pointer-events: auto;
    /* Reactiva clics para el buscador y botones */
}

.map-search-floating .search-input-row {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    padding: 6px;
    border-radius: 999px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.3);
    margin-bottom: 0;
}

.map-search-floating .search-input-wrapper input {
    background: transparent;
    border: none;
    box-shadow: none;
}

.map-search-floating .search-input-wrapper input:focus {
    box-shadow: none;
}

.map-search-floating .filter-chips {
    justify-content: flex-start;
    margin-bottom: 0;
}

.map-search-floating .filter-chip {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

/* Loading overlay */
.loading-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 12px 20px;
    border-radius: 999px;
    box-shadow: var(--shadow-hover);
    z-index: 1000;
    font-weight: 600;
    font-size: 13px;
    display: none;
    align-items: center;
    gap: 8px;
}

.loading-overlay.visible {
    display: flex;
}

/* Floating filters on map */
.map-filters-overlay {
    position: absolute;
    top: 14px;
    left: 14px;
    right: 14px;
    display: flex;
    justify-content: center;
    gap: 8px;
    z-index: 500;
    pointer-events: none;
}

.filter-group {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    padding: 4px;
    border-radius: 999px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    pointer-events: auto;
    display: flex;
    gap: 4px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.filter-group.scrollable {
    overflow-x: auto;
    max-width: 600px;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-inline: 4px;
}

.filter-group.scrollable::-webkit-scrollbar {
    display: none;
}

.filter-btn {
    border: none;
    background: transparent;
    padding: 7px 14px;
    border-radius: 999px;
    font-weight: 600;
    color: var(--color-muted);
    cursor: pointer;
    transition: all var(--transition-main);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-btn:hover {
    background: var(--color-bg-alt);
    color: var(--color-ink);
}

.filter-btn.active {
    background: var(--color-ink);
    color: white;
}

.filter-btn.active.green {
    background: #16a34a;
}

.filter-btn.active.orange {
    background: #1e40af;
    color: white;
}

/* Brand filter select */
.brand-select {
    border: none;
    background: transparent;
    font-weight: 600;
    color: var(--color-muted);
    padding: 7px 10px;
    outline: none;
    cursor: pointer;
    font-size: 13px;
}

/* Ajuste del control de Leaflet */
.leaflet-control-container .leaflet-top.leaflet-left,
.leaflet-control-container .leaflet-top.leaflet-right {
    margin-top: 130px;
    /* Aumentado para dejar espacio al buscador flotante y chips */
    /* espacio para los filtros flotantes */
}

@media (max-width: 640px) {

    .leaflet-control-container .leaflet-top.leaflet-left,
    .leaflet-control-container .leaflet-top.leaflet-right {
        margin-top: 140px;
    }

    .map-search-floating {
        left: 10px;
        right: 10px;
        top: 10px;
        max-width: none;
    }
}




.leaflet-control-zoom a {
    border-radius: 8px !important;
    box-shadow: var(--shadow-soft);
}

/* Leaflet popup styling - Completely Redesigned */
.leaflet-popup-content-wrapper, 
.leaflet-popup-content-wrapper * {
    box-sizing: border-box;
}

div.leaflet-popup-content-wrapper {
    border-radius: 28px !important;
    padding: 0 !important;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25) !important;
    border: 1px solid rgba(255, 255, 255, 0.4);
    background: #f7efea !important; /* Specific warm background from image */
}

div.leaflet-popup-content {
    margin: 0 !important;
    width: 300px !important;
    font-family: "Outfit", "Inter", system-ui, sans-serif !important;
}

.popup-container {
    padding: 20px;
}

.popup-brand-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: #dee5f3; /* Light blue background like image */
    border-radius: 99px;
    font-size: 12px;
    font-weight: 700;
    color: #436edb; /* Darker blue text */
    text-transform: uppercase;
    margin-bottom: 16px;
}

.popup-title {
    font-size: 22px;
    font-weight: 800;
    line-height: 1.1;
    color: #111827;
    margin-bottom: 12px;
    display: block;
    letter-spacing: -0.02em;
}

.popup-address-row {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #4b5563;
    font-size: 14px;
    margin-bottom: 24px;
    opacity: 0.8;
}

.popup-address-row i {
    font-size: 16px;
}

.popup-price-card {
    background: #fffcf9;
    border-radius: 24px;
    padding: 20px;
    margin-bottom: 24px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
}

.popup-price-label {
    font-size: 12px;
    font-weight: 700;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    display: block;
    margin-bottom: 6px;
}

.popup-price-value {
    font-size: 52px;
    font-weight: 900;
    line-height: 1;
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.popup-price-value .unit {
    font-size: 18px;
    font-weight: 700;
    color: currentColor;
    opacity: 0.8;
}

.popup-actions {
    display: flex;
    gap: 12px;
}

.btn-popup-ir, .btn-popup-ficha {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px;
    border-radius: 18px;
    font-size: 15px;
    font-weight: 700;
    text-decoration: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-popup-ir {
    background: white;
    color: #1e293b;
    border: 1px solid #e2e8f0;
}

.btn-popup-ir:hover {
    background: #f8fafc;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.btn-popup-ficha {
    background: #111827;
    color: white;
}

.btn-popup-ficha:hover {
    background: #0f172a;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.leaflet-popup-tip-container {
    display: none;
}

/* Close button - matching image */
.leaflet-container a.leaflet-popup-close-button {
    top: 12px !important;
    right: 12px !important;
    padding: 8px !important;
    width: 32px !important;
    height: 32px !important;
    background: rgba(0, 0, 0, 0.05) !important;
    border-radius: 50% !important;
    color: #1e293b !important;
    font-size: 18px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border: none !important;
    transition: all 0.2s ease !important;
}

.leaflet-container a.leaflet-popup-close-button:hover {
    background: rgba(0, 0, 0, 0.1) !important;
    color: #000 !important;
}

/* Responsive */
@media (max-width: 900px) {
    .map-toolbar-inner {
        flex-direction: column;
        align-items: flex-start;
    }

    .map-layout-inner {
        grid-template-columns: minmax(0, 1fr);
        padding-inline: 0;
    }

    .map-sidebar {
        max-height: none;
        order: 2;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .map-canvas-wrapper {
        border-radius: 0;
    }

    .map-canvas {
        height: 50vh;
        min-height: 300px;
    }

    .map-filters-overlay {
        top: 10px;
        left: 10px;
        right: 10px;
        overflow-x: auto;
        justify-content: flex-start;
        padding-bottom: 4px;
    }
}

@media (max-width: 640px) {
    .map-title {
        font-size: 18px;
    }

    .filter-group {
        flex-wrap: nowrap;
    }

    .filter-btn {
        padding: 6px 10px;
        font-size: 12px;
    }
}

/* ============================================   AUTOCOMPLETE STYLES   ============================================ */
.autocomplete-container {
    flex: 1;
    position: relative;
}

.autocomplete-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-hover);
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    margin-top: 4px;
    display: none;
}

.autocomplete-item {
    padding: 10px 12px;
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    transition: background-color 0.15s ease;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover {
    background-color: var(--color-bg-alt);
}

.autocomplete-item i {
    color: var(--color-accent-strong);
    font-size: 14px;
    margin-top: 2px;
    flex-shrink: 0;
}

.autocomplete-text {
    flex: 1;
    min-width: 0;
}

.autocomplete-name {
    font-size: 13px;
    color: var(--color-ink);
    font-weight: 500;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-clamp: 2;
}


.autocomplete-item.no-results {
    color: var(--color-muted);
    font-size: 13px;
    cursor: default;
    justify-content: center;
}

.autocomplete-item.no-results:hover {
    background-color: transparent;
}

.marker-pulse {
    pointer-events: none;
    z-index: 1000;
}

/* ============================================
   AUTOCOMPLETE DROPDOWN STYLES (Modern)
   ============================================ */
.autocomplete-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.2);
    max-height: 320px;
    overflow-y: auto;
    z-index: 2000;
    display: none;
    animation: autocompleteSlideIn 0.2s ease-out;
}

.autocomplete-dropdown.visible {
    display: block;
}

@keyframes autocompleteSlideIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.autocomplete-item {
    padding: 12px 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    transition: all 0.15s ease;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.active {
    background: linear-gradient(90deg, rgba(244, 162, 97, 0.08), rgba(244, 162, 97, 0.04));
    transform: translateX(2px);
}

.autocomplete-item .icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, #f4a261, #e76f51);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    flex-shrink: 0;
    box-shadow: 0 4px 12px -4px rgba(244, 162, 97, 0.5);
}

.autocomplete-item .info {
    flex: 1;
    min-width: 0;
}

.autocomplete-item .locality-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-ink);
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.autocomplete-item .locality-meta {
    font-size: 12px;
    color: var(--color-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.autocomplete-item .station-count {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: rgba(244, 162, 97, 0.1);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    color: #e76f51;
}

.autocomplete-loading {
    padding: 16px;
    text-align: center;
    color: var(--color-muted);
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.autocomplete-loading i {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.autocomplete-no-results {
    padding: 20px;
    text-align: center;
    color: var(--color-muted);
    font-size: 13px;
}

/* Scrollbar styling for autocomplete */
.autocomplete-dropdown::-webkit-scrollbar {
    width: 6px;
}

.autocomplete-dropdown::-webkit-scrollbar-track {
    background: transparent;
}

.autocomplete-dropdown::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.autocomplete-dropdown::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}