/* ==========================================================================
   MakhiMarket - Global Map Styles
   Applies branded MapTiler dark tiles + custom markers to all maps.
   Brand colors from css/colors.css (--brand-primary, --brand-secondary, etc.)
   ========================================================================== */

/* -- Map banner (full-width hero map on store-listing) ------------------- */
.mkh-map-banner {
    position: relative;
    z-index: 1;
    isolation: isolate;
    width: 100%;
    height: 45vh;
    min-height: 360px;
    max-height: 600px;
    overflow: hidden;
}

@media (max-width: 768px) {
    .mkh-map-banner {
        height: 40vh;
        min-height: 260px;
    }

    .mkh-map-banner-title {
        font-size: 0.95rem;
        padding: 8px 18px;
        top: 10px;
    }

    .mkh-map-legend {
        width: 170px;
        max-height: 180px;
        bottom: 16px;
        right: 8px;
        border-radius: 10px;
    }

    .mkh-legend-header {
        padding: 6px 10px;
        font-size: 10px;
    }

    .mkh-legend-radius {
        padding: 5px 6px;
        gap: 2px;
    }

    .mkh-radius-btn {
        padding: 2px 6px;
        font-size: 9px;
    }

    .mkh-legend-list {
        max-height: 120px;
    }

    .mkh-legend-item {
        padding: 5px 8px;
        gap: 5px;
    }

    .mkh-legend-rank {
        width: 15px;
        height: 15px;
        font-size: 9px;
    }

    .mkh-legend-avatar {
        width: 20px;
        height: 20px;
    }

    .mkh-legend-name {
        font-size: 10px;
    }

    .mkh-legend-distance {
        font-size: 9px;
    }

    .mkh-geolocate-btn {
        bottom: 16px;
        left: 8px;
        width: 34px;
        height: 34px;
        font-size: 14px;
    }

    .leaflet-control-zoom a {
        width: 30px !important;
        height: 30px !important;
        line-height: 30px !important;
    }

    .leaflet-popup.mkh-store-popup-wrapper .leaflet-popup-content {
        padding: 12px;
        min-width: 200px;
    }

    .mkh-store-popup .mkh-popup-name {
        font-size: 12px;
    }

    .mkh-store-popup .mkh-popup-link {
        font-size: 11px;
        padding: 6px 12px;
    }
}

@media (max-width: 480px) {
    .mkh-map-legend {
        position: relative !important;
        bottom: auto !important;
        right: auto !important;
        left: auto !important;
        width: 100% !important;
        max-height: none;
        border-radius: 0px !important;
        margin-top: 0;
    }
    }

    .mkh-legend-list {
        max-height: 85px;
        display: flex;
        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
    }

    .mkh-legend-item {
        flex-shrink: 0;
        padding: 6px 10px;
        border-bottom: none;
        border-right: 1px solid rgba(255, 255, 255, 0.06);
    }

    .mkh-legend-radius {
        justify-content: center;
    }

    .mkh-geolocate-btn {
        bottom: 150px;
        left: 8px;
    }
}

/* -- MakhiMarket brand tint overlay (blue tint on all map tiles) ------ */
.mkh-map-tint {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(0, 102, 204, 0.15) 0%, rgba(0, 52, 163, 0.18) 100%);
    mix-blend-mode: color;
    pointer-events: none;
    z-index: 2;
}

/* -- Map legend (distance-ordered store list on banner) ------------------ */
.mkh-map-legend {
    position: absolute;
    bottom: 80px;
    right: 16px;
    left: auto;
    z-index: 3;
    width: 250px;
    max-height: 260px;
    background: rgba(13, 27, 42, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.mkh-legend-header {
    padding: 10px 14px;
    font-size: 12px;
    font-weight: 700;
    color: var(--brand-secondary);
    background: rgba(0, 102, 204, 0.15);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    gap: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mkh-legend-radius {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5);
}

.mkh-radius-btn {
    padding: 3px 8px;
    font-size: 10px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.mkh-radius-btn:hover {
    background: rgba(0, 102, 204, 0.25);
    color: #ffffff;
    border-color: rgba(0, 102, 204, 0.4);
}

.mkh-radius-btn.active {
    background: var(--brand-primary);
    color: #ffffff;
    border-color: var(--brand-primary);
    box-shadow: 0 2px 8px rgba(0, 102, 204, 0.4);
}

.mkh-legend-list {
    max-height: 210px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--brand-primary) transparent;
}

.mkh-legend-list::-webkit-scrollbar {
    width: 4px;
}

.mkh-legend-list::-webkit-scrollbar-thumb {
    background: var(--brand-primary);
    border-radius: 2px;
}

.mkh-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

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

.mkh-legend-item:hover,
.mkh-legend-item.active {
    background: rgba(0, 102, 204, 0.2);
}

.mkh-legend-rank {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.6);
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.mkh-legend-item:first-child .mkh-legend-rank {
    background: var(--accent-orange);
    color: #ffffff;
}

.mkh-legend-item:nth-child(2) .mkh-legend-rank {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

.mkh-legend-item:nth-child(3) .mkh-legend-rank {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.9);
}

.mkh-legend-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.2);
    object-fit: cover;
    flex-shrink: 0;
}

.mkh-legend-avatar-empty {
    background: rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.4);
    font-size: 10px;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.mkh-legend-name {
    flex: 1;
    font-size: 12px;
    font-weight: 600;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mkh-legend-distance {
    font-size: 10px;
    font-weight: 600;
    color: var(--accent-orange);
    flex-shrink: 0;
}

@media (max-width: 576px) {
    .mkh-map-legend {
        width: 200px;
        max-height: 200px;
        bottom: 70px;
        right: 8px;
    }

    .mkh-legend-list {
        max-height: 155px;
        flex-direction: column;

    }

    .mkh-legend-item {
        padding: 6px 10px;
    }
}

/* -- Glassmorphism title pill on the map banner -------------------------- */
.mkh-map-banner-title {
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 12px 28px;
    background: rgba(13, 27, 42, 0.75);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 50px;
    font-family: 'Inter', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.02em;
    white-space: nowrap;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.mkh-map-banner-title i {
    color: var(--brand-secondary);
    font-size: 1.1rem;
}

@media (max-width: 576px) {
    .mkh-map-banner-title {
        font-size: 1rem;
        padding: 10px 20px;
        top: 16px;
    }
}

/* -- Geolocation button (floating on map) --------------------------------- */
.mkh-geolocate-btn {
    position: absolute;
    bottom: 80px;
    left: 16px;
    z-index: 3;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: rgba(13, 27, 42, 0.8);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s ease;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.mkh-geolocate-btn:hover {
    background: rgba(0, 102, 204, 0.85);
    border-color: var(--brand-primary);
    transform: scale(1.05);
}

.mkh-geolocate-btn.active {
    background: var(--brand-primary);
    border-color: var(--brand-secondary);
    box-shadow: 0 0 16px rgba(0, 102, 204, 0.4);
}

/* -- Mini-map (fixed, bottom-right, appears after scrolling past banner) - */
.mkh-mini-map {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid var(--brand-primary);
    box-shadow: 0 8px 32px rgba(0, 102, 204, 0.35), 0 2px 8px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.mkh-mini-map.visible {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

.mkh-mini-map:hover {
    border-color: var(--brand-secondary);
    box-shadow: 0 12px 40px rgba(0, 102, 204, 0.5), 0 4px 12px rgba(0, 0, 0, 0.25);
    transform: scale(1.08);
}

.mkh-mini-map .leaflet-container {
    border-radius: 50%;
}

.mkh-mini-map::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 1.5px solid rgba(0, 212, 255, 0.3);
    pointer-events: none;
    animation: mkhMiniPulse 2s ease-in-out infinite;
}

@keyframes mkhMiniPulse {
    0%, 100% { border-color: rgba(0, 212, 255, 0.3); }
    50% { border-color: rgba(0, 212, 255, 0.7); }
}

@media (max-width: 768px) {
    .mkh-mini-map {
        display: none;
    }
}

/* -- Store marker (blue pin with avatar) -------------------------------- */
.mkh-store-marker {
    background: transparent !important;
    border: none !important;
}

.mkh-store-marker .mkh-store-marker-body {
    width: 44px;
    height: 44px;
    background: var(--brand-primary);
    border-radius: 50%;
    border: 3px solid #ffffff;
    box-shadow: 0 3px 12px rgba(0, 102, 204, 0.45);
    overflow: hidden;
    position: relative;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.mkh-store-marker .mkh-store-marker-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.mkh-store-marker .mkh-store-marker-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #ffffff;
    font-size: 16px;
}

.mkh-store-marker .mkh-store-marker-dot {
    width: 10px;
    height: 10px;
    background: var(--brand-primary);
    border-radius: 50%;
    margin: 2px auto 0;
    border: 2px solid #ffffff;
    box-shadow: 0 1px 4px rgba(0, 102, 204, 0.4);
}

.mkh-store-marker:hover .mkh-store-marker-body {
    transform: scale(1.2);
    box-shadow: 0 6px 20px rgba(0, 102, 204, 0.6);
    z-index: 1000;
}

/* -- Store popup (richer) ----------------------------------------------- */
.leaflet-popup.mkh-store-popup-wrapper .leaflet-popup-content-wrapper {
    border-radius: 12px !important;
    padding: 0 !important;
    overflow: hidden;
}

.leaflet-popup.mkh-store-popup-wrapper .leaflet-popup-content {
    margin: 0 !important;
    padding: 16px;
    min-width: 240px;
}

.mkh-store-popup .mkh-popup-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.mkh-store-popup .mkh-popup-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--brand-primary);
    object-fit: cover;
    flex-shrink: 0;
}

.mkh-store-popup .mkh-popup-info {
    flex: 1;
    min-width: 0;
}

.mkh-store-popup .mkh-popup-name {
    font-size: 14px;
    font-weight: 700;
    color: #1f2937;
    margin: 0 0 2px 0;
    line-height: 1.2;
}

.mkh-store-popup .mkh-popup-distance {
    font-size: 11px;
    color: var(--accent-orange);
    font-weight: 600;
    margin: 0;
}

.mkh-store-popup .mkh-popup-address {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 0 0 8px 0;
    line-height: 1.4;
    display: flex;
    align-items: flex-start;
    gap: 6px;
}

.mkh-store-popup .mkh-popup-address i {
    color: var(--brand-primary);
    margin-top: 2px;
    font-size: 11px;
}

.mkh-store-popup .mkh-popup-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
    font-size: 12px;
}

.mkh-store-popup .mkh-popup-rating {
    color: #eab308;
    font-weight: 600;
}

.mkh-store-popup .mkh-popup-rating small {
    color: var(--text-muted);
    font-weight: 400;
}

.mkh-store-popup .mkh-popup-products {
    color: var(--text-secondary);
}

.mkh-store-popup .mkh-popup-products i {
    color: var(--brand-primary);
    margin-right: 3px;
}

.mkh-store-popup .mkh-popup-open {
    color: var(--success);
    font-weight: 600;
}

.mkh-store-popup .mkh-popup-open i {
    font-size: 6px;
    margin-right: 3px;
    animation: mkhPulse 1.5s ease-in-out infinite;
}

.mkh-store-popup .mkh-popup-link {
    display: block;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: #ffffff;
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-dark));
    padding: 8px 16px;
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.2s ease;
}

.mkh-store-popup .mkh-popup-link:hover {
    background: linear-gradient(135deg, var(--brand-primary-dark), var(--brand-primary-darker));
    box-shadow: 0 4px 12px rgba(0, 102, 204, 0.3);
    color: #ffffff;
    text-decoration: none;
}

/* -- User location marker (orange pulse) --------------------------------- */
.mkh-user-marker {
    background: transparent !important;
    border: none !important;
}

.mkh-user-dot {
    width: 16px;
    height: 16px;
    background: var(--accent-orange);
    border-radius: 50%;
    border: 3px solid #ffffff;
    box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.3);
    position: relative;
}

.mkh-user-dot::after {
    content: '';
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    border: 2px solid rgba(245, 158, 11, 0.4);
    animation: mkhUserPulse 2s ease-out infinite;
}

@keyframes mkhUserPulse {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }
    100% {
        transform: scale(2.5);
        opacity: 0;
    }
}

/* -- Map loading overlay ------------------------------------------------- */
.mkh-map-loader {
    position: absolute;
    inset: 0;
    background: rgba(13, 27, 42, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    transition: opacity 0.4s ease;
}

.mkh-map-loader.hidden {
    opacity: 0;
    pointer-events: none;
}

.mkh-map-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--brand-secondary);
    border-radius: 50%;
    animation: mkhSpin 0.8s linear infinite;
}

@keyframes mkhSpin {
    to { transform: rotate(360deg); }
}

/* -- Leaflet control overrides (z-index for stacking) -------------------- */
.mkh-map-banner .leaflet-top,
.mkh-map-banner .leaflet-bottom {
    z-index: 2 !important;
}

.mkh-map-banner .leaflet-control-zoom {
    border: none !important;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3) !important;
    border-radius: 8px !important;
    overflow: hidden;
}

.mkh-map-banner .leaflet-control-zoom a {
    background: rgba(13, 27, 42, 0.8) !important;
    color: #ffffff !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
    width: 34px !important;
    height: 34px !important;
    line-height: 34px !important;
    font-size: 16px !important;
    transition: background 0.2s;
}

.mkh-map-banner .leaflet-control-zoom a:hover {
    background: var(--brand-primary) !important;
}

/* -- Delivery tracking map style (dark themed) --------------------------- */
.mkh-tracker-map {
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid var(--border-secondary);
    box-shadow: 0 2px 16px rgba(0, 102, 204, 0.1);
}

/* -- Address picker map style -------------------------------------------- */
.mkh-picker-map {
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid var(--border-secondary);
    box-shadow: 0 2px 12px rgba(0, 102, 204, 0.07);
}

/* -- Leaflet global z-index reset (prevent maps from overlaying header) - */
.leaflet-top,
.leaflet-bottom,
.leaflet-pane {
    z-index: 1 !important;
}

.leaflet-control {
    z-index: 2 !important;
}

/* -- Map attribution restyle --------------------------------------------- */
.leaflet-control-attribution {
    background: rgba(13, 27, 42, 0.6) !important;
    color: rgba(255, 255, 255, 0.5) !important;
    font-size: 10px !important;
    padding: 2px 8px !important;
    border-radius: 4px 0 0 0 !important;
}

.leaflet-control-attribution a {
    color: rgba(255, 255, 255, 0.7) !important;
}
