/* ============================================================
   BloodBridge — Map Styles (Leaflet Live Map Integration)
   ============================================================ */

/* ── Map Container ── */
.map-container {
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--grey-100);
    margin-bottom: var(--space-4);
    position: relative;
}

.map-container #leaflet-map {
    height: 380px;
    width: 100%;
    z-index: 1;
}

/* ── Loading Overlay ── */
.map-loading {
    position: absolute;
    inset: 0;
    z-index: 10;
    background: rgba(255,255,255,0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--grey-600);
    transition: opacity 300ms;
    border-radius: var(--radius-xl);
}

.map-loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--grey-200);
    border-top-color: var(--teal-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ── Donor Marker — Pulsing Green Circle ── */
.custom-marker {
    background: none !important;
    border: none !important;
}

.donor-marker {
    position: relative;
    width: 24px;
    height: 24px;
}

.donor-marker-dot {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 14px;
    background: var(--green);
    border: 3px solid white;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 2px 6px rgba(39,174,96,0.4);
    z-index: 3;
}

.donor-marker-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(39,174,96,0.3);
    transform: translate(-50%, -50%) scale(1);
    animation: donorPulse 1.5s ease-out infinite;
}

.donor-marker-ring.ring-2 {
    animation-delay: 0.75s;
}

@keyframes donorPulse {
    0% { transform: translate(-50%, -50%) scale(1); opacity: 0.8; }
    100% { transform: translate(-50%, -50%) scale(1.6); opacity: 0; }
}

/* ── Pin Markers (Blood Bank & Hospital) ── */
.marker-pin {
    width: 28px;
    height: 28px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    animation: pinDrop 600ms cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}

.marker-pin.hospital { background: var(--teal-primary); }
.marker-pin.bloodbank { background: var(--red-primary); }

.marker-pin-inner {
    transform: rotate(45deg);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Destination Pin — Large with drop animation ── */
.destination-pin {
    width: 40px;
    height: 40px;
    animation: destPinDrop 800ms cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}

@keyframes pinDrop {
    0% { transform: rotate(-45deg) translateY(-20px) scale(0.5); opacity: 0; }
    60% { transform: rotate(-45deg) translateY(3px) scale(1.05); opacity: 1; }
    100% { transform: rotate(-45deg) translateY(0) scale(1); }
}

@keyframes destPinDrop {
    0% { transform: rotate(-45deg) translateY(-40px) scale(0.5); opacity: 0; }
    50% { transform: rotate(-45deg) translateY(4px) scale(1.1); opacity: 1; }
    100% { transform: rotate(-45deg) translateY(0) scale(1); }
}

/* ── Recenter Button ── */
.map-recenter-btn {
    width: 36px;
    height: 36px;
    background: var(--white);
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--teal-primary);
    transition: background 150ms;
}

.map-recenter-btn:hover {
    background: var(--grey-50);
}

/* ── Leaflet Popup Overrides ── */
.leaflet-popup-content-wrapper {
    border-radius: 10px !important;
    border: none !important;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12) !important;
    font-family: var(--font-body) !important;
    padding: 0 !important;
}

.leaflet-popup-content {
    margin: 0 !important;
    font-size: var(--text-sm) !important;
    line-height: 1.5 !important;
}

.leaflet-popup-tip {
    box-shadow: none !important;
}

.leaflet-popup-close-button {
    color: var(--grey-400) !important;
    font-size: 16px !important;
    padding: 6px 8px !important;
}

.map-popup {
    padding: var(--space-4);
    min-width: 180px;
}

.map-popup-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: var(--text-md);
    color: var(--navy);
    margin-bottom: var(--space-2);
}

.map-popup-row {
    font-size: var(--text-xs);
    color: var(--grey-600);
    margin-bottom: var(--space-1);
}

.map-popup-link {
    display: inline-block;
    margin-top: var(--space-2);
    color: var(--teal-primary);
    font-weight: 600;
    font-size: var(--text-xs);
    text-decoration: none;
}

.map-popup-phone {
    font-size: var(--text-md);
    color: var(--red-primary);
}

/* ── Navigation Info Bar ── */
.nav-info-bar {
    display: flex;
    align-items: center;
    background: var(--teal-primary);
    color: var(--white);
    border-radius: var(--radius-xl);
    padding: var(--space-4) var(--space-6);
    margin-bottom: var(--space-4);
    gap: var(--space-6);
    box-shadow: var(--shadow-md);
}

.nav-info-dest {
    flex: 1;
    min-width: 0;
}

.nav-info-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: var(--text-md);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-info-addr {
    font-size: var(--text-xs);
    opacity: 0.85;
    margin-top: 2px;
}

.nav-info-stat {
    text-align: center;
    padding: 0 var(--space-4);
    border-left: 1px solid rgba(255,255,255,0.2);
}

.nav-info-value {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: var(--text-xl);
    letter-spacing: -0.5px;
}

.nav-info-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.7;
    margin-top: 2px;
}

/* ── Mark as Arrived Button ── */
.btn-arrived {
    display: none;
    width: 100%;
    padding: var(--space-4);
    background: var(--green);
    color: var(--white);
    border: none;
    border-radius: var(--radius-lg);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: var(--text-md);
    cursor: pointer;
    margin-top: var(--space-3);
    transition: background var(--duration-fast);
    box-shadow: var(--shadow-md);
}

.btn-arrived.visible { display: block; }
.btn-arrived:hover { background: #219a52; }

/* ── Map Legend ── */
.map-legend {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4);
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    font-size: var(--text-xs);
    color: var(--grey-600);
    margin-top: var(--space-3);
}

.map-legend-item {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.map-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.map-legend-dot.hospital { background: var(--teal-primary); }
.map-legend-dot.bloodbank { background: var(--red-primary); }
.map-legend-dot.donor { background: var(--green); }

/* ── Hide default LRM instructions panel ── */
.leaflet-routing-container { display: none !important; }

/* ── Permission Denied Fallback ── */
.map-denied {
    height: 380px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: var(--space-4);
    color: var(--grey-600);
    border-radius: var(--radius-xl);
    background: var(--grey-50);
    border: 1px solid var(--grey-200);
}

.map-denied svg { width: 48px; height: 48px; color: var(--grey-400); }
.map-denied p { font-size: var(--text-sm); max-width: 300px; }
.map-denied button {
    padding: 8px 24px;
    background: var(--teal-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
}

/* ── Dark Mode ── */
body.dark-mode .map-container { border-color: #30363d; }
body.dark-mode .map-loading { background: rgba(13,17,23,0.92); color: #c9d1d9; }
body.dark-mode .map-loading-spinner { border-color: #30363d; border-top-color: var(--teal-primary); }
body.dark-mode .map-recenter-btn { background: #161b22; color: var(--teal-primary); box-shadow: 0 2px 8px rgba(0,0,0,0.4); }
body.dark-mode .map-recenter-btn:hover { background: #21262d; }
body.dark-mode .leaflet-popup-content-wrapper { background: #161b22 !important; }
body.dark-mode .map-popup-title { color: #f1f3f5; }
body.dark-mode .map-popup-row { color: #9ca3af; }
body.dark-mode .map-legend { background: #161b22; color: #9ca3af; border: 1px solid #30363d; }
body.dark-mode .nav-info-bar { background: linear-gradient(135deg, var(--teal-primary), #117a65); }
body.dark-mode .map-denied { background: #161b22; border-color: #30363d; color: #9ca3af; }
body.dark-mode .btn-arrived { box-shadow: 0 4px 12px rgba(0,0,0,0.4); }

/* ── Map Fallback (preserved for non-Leaflet contexts) ── */
.map-fallback {
    height: 280px;
    background: linear-gradient(135deg, #e8f4f8 0%, #d1ecf1 100%);
    border-radius: var(--radius-xl);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--grey-600);
    gap: var(--space-3);
    position: relative;
    overflow: hidden;
}

.map-fallback::before {
    content: '';
    position: absolute;
    inset: 0;
    background: 
        radial-gradient(circle at 20% 30%, rgba(26,122,138,0.08) 0%, transparent 50%),
        radial-gradient(circle at 70% 60%, rgba(192,57,43,0.06) 0%, transparent 50%),
        radial-gradient(circle at 50% 80%, rgba(39,174,96,0.06) 0%, transparent 50%);
}

.map-fallback-icon {
    width: 48px; height: 48px; border-radius: var(--radius-full);
    background: rgba(26,122,138,0.1); display: flex; align-items: center; justify-content: center; z-index: 1;
}
.map-fallback-icon svg { width: 24px; height: 24px; color: var(--teal-primary); }
.map-fallback-text { font-size: var(--text-sm); font-weight: var(--font-semibold); z-index: 1; }
.map-fallback-sub { font-size: var(--text-xs); color: var(--grey-status); z-index: 1; }

/* ── Simulated dots (kept for non-leaflet fallback) ── */
.map-dot {
    position: absolute; width: 10px; height: 10px; border-radius: 50%; z-index: 1;
}
.map-dot::after {
    content: ''; position: absolute; inset: -4px; border-radius: 50%;
    animation: locationPulse 2.5s ease-out infinite;
}
.map-dot.bb { background: var(--red-primary); }
.map-dot.bb::after { background: rgba(192,57,43,0.3); }
.map-dot.hosp { background: var(--teal-primary); }
.map-dot.hosp::after { background: rgba(26,122,138,0.3); }
.map-dot.donor-dot { background: var(--green); }
.map-dot.donor-dot::after { background: rgba(39,174,96,0.3); }