/* ===========================================
   MedOrbit v2 - Map & Custom Markers
   =========================================== */

.map-panel {
    position: relative;
    height: 100%;
    overflow: hidden;
    background: var(--bg-soft);
}

.map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* === Custom Markers === */
.custom-marker {
    background: transparent !important;
    border: none !important;
}

.marker-pin {
    width: 38px;
    height: 38px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    display: flex !important;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border: 3px solid white;
    position: relative;
    transition: all 0.2s var(--ease);
}

[dir="rtl"] .marker-pin {
    transform: rotate(45deg);
}

.marker-pin i {
    transform: rotate(45deg);
    color: white;
    font-size: 14px;
}

[dir="rtl"] .marker-pin i {
    transform: rotate(-45deg);
}

.marker-pin:hover {
    transform: rotate(-45deg) scale(1.15);
    z-index: 1000;
}

[dir="rtl"] .marker-pin:hover {
    transform: rotate(45deg) scale(1.15);
}

/* User location (blue/green) */
.marker-pin.user {
    background: var(--secondary);
    z-index: 999;
}

.marker-pin.user::after {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid var(--secondary);
    animation: userPulse 2s ease-out infinite;
}

@keyframes userPulse {
    0% { transform: scale(0.9); opacity: 1; }
    100% { transform: scale(2.2); opacity: 0; }
}

/* Categories */
.marker-pin.clinic {
    background: var(--cat-clinic);
}

.marker-pin.pharmacy {
    background: var(--cat-pharmacy);
}

.marker-pin.hospital {
    background: var(--cat-hospital);
}

.marker-pin.doctor {
    background: var(--cat-doctor);
}

.marker-pin.hidden {
    display: none;
}

/* === Map Controls (Floating) === */
.map-controls {
    position: absolute;
    bottom: 24px;
    right: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

[dir="rtl"] .map-controls {
    right: auto;
    left: 16px;
}

.map-control-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-elevated);
    color: var(--text);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-md);
    transition: all var(--t-fast);
    font-size: 15px;
    border: 1px solid var(--border);
}

.map-control-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.map-control-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* === Location Picker (shared: index.html + find-clinics.html) ===
   Centers the pill without a `transform` on this container — a transform
   here would make it a containing block for the mobile bottom-sheet's
   position:fixed below, anchoring the sheet to this small box instead of
   the viewport. */
.location-picker {
    position: absolute;
    top: 16px;
    left: 16px;
    right: 16px;
    z-index: 1001;
    display: flex;
    justify-content: center;
    pointer-events: none;
}

.location-picker > * {
    pointer-events: auto;
}

.location-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-full);
    box-shadow: var(--shadow-md);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-soft);
    white-space: nowrap;
    transition: all var(--t-fast);
}

.location-pill:hover {
    border-color: var(--primary-200, var(--primary));
}

.location-pill.locating {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.location-pill.resolved {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}

.location-pill.manual {
    background: var(--info, var(--primary));
    color: #fff;
    border-color: var(--info, var(--primary));
}

.location-pill.error {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.location-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    min-width: 260px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-lg);
    padding: 8px;
}
 

.location-menu.open {
    display: block;
}

.location-error-note {
    padding: 8px 10px;
    margin-bottom: 6px;
    background: rgba(239, 68, 68, 0.08);
    color: var(--danger);
    border-radius: var(--r-sm);
    font-size: 12px;
    line-height: 1.5;
}

.location-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    border-radius: var(--r-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    text-align: start;
    transition: background var(--t-fast);
}

.location-menu-item:hover {
    background: var(--bg-soft);
}

.location-menu-item i {
    width: 16px;
    color: var(--primary);
    text-align: center;
}

.location-menu-label {
    margin: 10px 6px 4px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-faint);
    text-transform: uppercase;
}

.location-district-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 2px 6px 4px;
}

.location-district-btn {
    padding: 6px 10px;
    border-radius: var(--r-full);
    border: 1px solid var(--border);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-soft);
    transition: all var(--t-fast);
}

.location-district-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-50);
}

/* === Mobile: the location menu becomes a bottom sheet instead of a small
   anchored dropdown (which would clip against a narrow map panel) === */
@media (max-width: 768px) {
    .location-menu-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: var(--bg-overlay);
        z-index: var(--z-drawer);
    }

    .location-menu-backdrop.open {
        display: block;
    }

    .location-menu {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        transform: none;
        min-width: 0;
        width: 100%;
        max-height: 70vh;
        overflow-y: auto;
        border-radius: var(--r-xl) var(--r-xl) 0 0;
        border-bottom: none;
        padding: 10px 12px calc(16px + env(safe-area-inset-bottom));
        z-index: calc(var(--z-drawer) + 1);
    }

    .location-menu-item,
    .location-district-btn {
        min-height: 44px;
        font-size: 14px;
    }

    .location-district-btn {
        padding: 10px 14px;
    }
}

/* === Status Pill === */
.map-status {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-full);
    box-shadow: var(--shadow-md);
    font-size: 13px;
    color: var(--text-soft);
    max-width: calc(100% - 32px);
    transition: all var(--t-base);
    animation: slideDown 0.3s var(--ease-out);
}

@keyframes slideDown {
    from { transform: translate(-50%, -20px); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

.map-status i {
    color: var(--primary);
    font-size: 13px;
    flex-shrink: 0;
}

.map-status.locating {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.map-status.locating i {
    color: white;
    animation: spin 1s linear infinite;
}

.map-status.success {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.map-status.success i { color: white; }

.map-status.error {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.map-status.error i { color: white; }

.map-status.info {
    background: var(--info);
    color: white;
    border-color: var(--info);
}

.map-status.info i { color: white; }

/* === Empty State Overlay === */
.map-empty {
    position: absolute;
    inset: 0;
    z-index: 999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-soft);
    pointer-events: none;
}

.map-empty-icon {
    width: 100px;
    height: 100px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-elevated);
    color: var(--text-faint);
    border-radius: var(--r-full);
    font-size: 40px;
    box-shadow: var(--shadow-md);
}

.map-empty h3 {
    font-size: 18px;
    color: var(--text);
    margin-bottom: 8px;
    font-weight: 700;
}

.map-empty p {
    font-size: 14px;
    color: var(--text-mute);
    max-width: 300px;
    text-align: center;
    line-height: 1.6;
}

/* === Leaflet Popup Override === */
.leaflet-popup-content-wrapper {
    border-radius: var(--r-md) !important;
    box-shadow: var(--shadow-xl) !important;
    padding: 0 !important;
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
    overflow: hidden;
}

.leaflet-popup-content {
    margin: 0 !important;
    font-family: 'Cairo', 'Inter', sans-serif !important;
    font-size: 13px !important;
    line-height: 1.5 !important;
    min-width: 240px;
    max-width: 280px;
}

.leaflet-popup-tip {
    background: var(--bg-elevated) !important;
    border: 1px solid var(--border) !important;
}

.leaflet-popup-close-button {
    color: var(--text-mute) !important;
    font-size: 18px !important;
    padding: 6px 8px !important;
}

.popup-content {
    padding: 14px;
}

.popup-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.popup-title {
    font-weight: 700;
    color: var(--text);
    font-size: 14px;
    line-height: 1.3;
    flex: 1;
}

.popup-type {
    flex-shrink: 0;
    padding: 2px 7px;
    border-radius: var(--r-full);
    font-size: 9.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.popup-type.clinic { background: rgba(37, 99, 235, 0.1); color: var(--cat-clinic); }
.popup-type.pharmacy { background: rgba(245, 158, 11, 0.1); color: var(--cat-pharmacy); }
.popup-type.hospital { background: rgba(220, 38, 38, 0.1); color: var(--cat-hospital); }
.popup-type.doctor { background: rgba(124, 58, 237, 0.1); color: var(--cat-doctor); }

.popup-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
    color: var(--text-soft);
    font-size: 12px;
}

.popup-meta-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.popup-meta-row i {
    color: var(--primary);
    font-size: 11px;
    width: 14px;
    flex-shrink: 0;
}

.popup-meta-row a {
    color: var(--text-soft);
    text-decoration: none;
}

.popup-meta-row a:hover {
    color: var(--primary);
}

.popup-actions {
    display: flex;
    gap: 6px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.popup-actions .btn {
    flex: 1;
    font-size: 11.5px;
    padding: 7px 8px;
}

/* === Attribution override === */
.leaflet-control-attribution {
    background: var(--bg-elevated) !important;
    color: var(--text-mute) !important;
    font-size: 10px !important;
    padding: 2px 8px !important;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
}

.leaflet-control-attribution a {
    color: var(--primary) !important;
}

.leaflet-control-zoom a {
    background: var(--bg-elevated) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
    transition: all var(--t-fast);
}

.leaflet-control-zoom a:hover {
    background: var(--primary) !important;
    color: white !important;
    border-color: var(--primary) !important;
}

@media (max-width: 1024px) {
    .leaflet-control-zoom a {
        width: 44px !important;
        height: 44px !important;
        line-height: 44px !important;
    }
}