:root {

    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #10b981;
    --secondary-dark: #059669;
    --accent: #f43f5e;
    --accent-light: #fb7185;


    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --bg-elevated: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --gradient-primary: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
    --gradient-secondary: linear-gradient(135deg, #10b981 0%, #14b8a6 100%);
    --gradient-danger: linear-gradient(135deg, #f43f5e 0%, #fb7185 100%);
    --gradient-bg: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);


    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.3);

    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;


    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-2xl: 1.5rem;
    --radius-full: 9999px;


    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;


    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}


*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    font-family: var(--font-family);
    background: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100%;
    display: flex;
    flex-direction: column;
}


body:has(.permission-screen:not(.hidden)) footer,
body:has(.loading-screen:not(.hidden)) footer,
body:has(.error-screen:not(.hidden)) footer {
    display: none;
}


body:has(.map-container:not(.hidden)) footer {
    display: none;
}

body:has(.map-container:not(.hidden)) {
    overflow: hidden;
}


.hidden {
    display: none !important;
}

.permission-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-bg);
    z-index: 1000;
    overflow: hidden;
}

.permission-card {
    background: var(--bg-card);
    border-radius: var(--radius-2xl);
    padding: var(--spacing-2xl);
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: var(--shadow-xl), var(--shadow-glow);
    border: 1px solid rgba(99, 102, 241, 0.2);
    position: relative;
    z-index: 10;
    animation: slideUp 0.6s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.permission-icon {
    width: 80px;
    height: 80px;
    background: var(--gradient-primary);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto var(--spacing-lg);
    animation: pulse 2s infinite;
}

.permission-icon svg {
    width: 40px;
    height: 40px;
    color: white;
}

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4);
    }

    50% {
        box-shadow: 0 0 0 20px rgba(99, 102, 241, 0);
    }
}

.permission-title {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: var(--spacing-sm);
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.permission-description {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-bottom: var(--spacing-xl);
    line-height: 1.7;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    border: none;
    padding: var(--spacing-md) var(--spacing-xl);
    border-radius: var(--radius-full);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-md);
    width: 100%;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg), 0 0 30px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon svg {
    width: 20px;
    height: 20px;
}

.permission-note {
    margin-top: var(--spacing-lg);
    font-size: 0.75rem;
    color: var(--text-muted);
}


.floating-elements {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.float-element {
    position: absolute;
    font-size: 2rem;
    opacity: 0.15;
    animation: float 6s ease-in-out infinite;
}

.float-1 {
    top: 10%;
    left: 10%;
    animation-delay: 0s;
}

.float-2 {
    top: 20%;
    right: 15%;
    animation-delay: 1s;
}

.float-3 {
    bottom: 30%;
    left: 20%;
    animation-delay: 2s;
}

.float-4 {
    bottom: 15%;
    right: 10%;
    animation-delay: 3s;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0) rotate(0deg);
    }

    50% {
        transform: translateY(-20px) rotate(10deg);
    }
}


.loading-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-bg);
    z-index: 1000;
}

.loader-container {
    text-align: center;
}

.pulse-loader {
    position: relative;
    width: 100px;
    height: 100px;
    margin: 0 auto var(--spacing-xl);
}

.pulse-ring {
    position: absolute;
    inset: 0;
    border: 3px solid var(--primary);
    border-radius: var(--radius-full);
    animation: pulseRing 1.5s ease-out infinite;
}

@keyframes pulseRing {
    0% {
        transform: scale(0.8);
        opacity: 1;
    }

    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

.pulse-core {
    position: absolute;
    inset: 20px;
    background: var(--gradient-primary);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulseCore 1.5s ease-in-out infinite;
}

.pulse-core svg {
    width: 30px;
    height: 30px;
    color: white;
}

@keyframes pulseCore {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

.loading-text {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
}

.loading-subtext {
    color: var(--text-secondary);
    font-size: 0.9rem;
}


.error-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-bg);
    z-index: 1000;
}

.error-card {
    background: var(--bg-card);
    border-radius: var(--radius-2xl);
    padding: var(--spacing-2xl);
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: var(--shadow-xl);
    border: 1px solid rgba(244, 63, 94, 0.2);
}

.error-icon {
    width: 80px;
    height: 80px;
    background: var(--gradient-danger);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto var(--spacing-lg);
}

.error-icon svg {
    width: 40px;
    height: 40px;
    color: white;
}

.error-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: var(--spacing-sm);
}

.error-description {
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xl);
}


/* ===== Map Container ===== */
.map-container {
    position: fixed;
    top: 73px;
    /* Below navbar */
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
}

.floating-stats {
    position: absolute;
    top: var(--spacing-md);
    right: var(--spacing-md);
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-xl);
    padding: var(--spacing-sm) var(--spacing-lg);
    z-index: 400;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(99, 102, 241, 0.2);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-number {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-light);
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-divider {
    width: 1px;
    height: 30px;
    background: var(--bg-elevated);
}


#map {
    flex: 1;
    z-index: 1;
}


.custom-marker {
    display: flex;
    align-items: center;
    justify-content: center;
}

.marker-hospital {
    width: 45px;
    height: 45px;
    background: var(--gradient-primary);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: var(--shadow-lg);
    border: 3px solid white;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.marker-hospital:hover {
    transform: scale(1.1);
}

.marker-with-ambulance {
    position: relative;
}

.ambulance-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 28px;
    height: 28px;
    background: var(--gradient-danger);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    box-shadow: var(--shadow-md);
    border: 2px solid white;
    cursor: pointer;
    transition: transform var(--transition-fast);
    z-index: 10;
}

.ambulance-badge:hover {
    transform: scale(1.2);
}

.marker-user {
    width: 24px;
    height: 24px;
    background: var(--secondary);
    border-radius: var(--radius-full);
    border: 4px solid white;
    box-shadow: var(--shadow-lg), 0 0 20px rgba(16, 185, 129, 0.5);
    animation: userPulse 2s infinite;
}

@keyframes userPulse {

    0%,
    100% {
        box-shadow: var(--shadow-lg), 0 0 0 0 rgba(16, 185, 129, 0.5);
    }

    50% {
        box-shadow: var(--shadow-lg), 0 0 0 15px rgba(16, 185, 129, 0);
    }
}

.map-legend {
    position: absolute;
    top: var(--spacing-md);
    left: var(--spacing-md);
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    z-index: 400;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.legend-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--spacing-sm);
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.legend-icon {
    font-size: 1rem;
}


.direction-btn {
    position: absolute;
    bottom: var(--spacing-xl);
    left: 50%;
    transform: translateX(-50%);
    background: var(--gradient-secondary);
    border: none;
    border-radius: var(--radius-2xl);
    padding: var(--spacing-md) var(--spacing-xl);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    cursor: pointer;
    box-shadow: var(--shadow-xl), 0 0 30px rgba(16, 185, 129, 0.3);
    z-index: 400;
    transition: all var(--transition-normal);
    min-width: 280px;
}

.direction-btn:hover {
    transform: translateX(-50%) translateY(-3px);
    box-shadow: var(--shadow-xl), 0 0 40px rgba(16, 185, 129, 0.5);
}

.direction-btn-content {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.direction-icon {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
}

.direction-icon svg {
    width: 20px;
    height: 20px;
    color: white;
}

.direction-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    color: white;
}

.direction-title {
    font-size: 1rem;
    font-weight: 600;
}

.direction-subtitle {
    font-size: 0.75rem;
    opacity: 0.8;
}

.direction-arrow {
    font-size: 1.25rem;
    color: white;
    margin-left: auto;
}


.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius-2xl);
    padding: var(--spacing-xl);
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-xl);
    border: 1px solid rgba(244, 63, 94, 0.3);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-close {
    position: absolute;
    top: var(--spacing-md);
    right: var(--spacing-md);
    width: 32px;
    height: 32px;
    background: var(--bg-elevated);
    border: none;
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--accent);
    color: white;
}

.modal-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.modal-icon {
    width: 50px;
    height: 50px;
    background: var(--gradient-danger);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.hospital-name {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--bg-elevated);
}

.contact-section {
    margin-bottom: var(--spacing-lg);
}

.contact-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--spacing-sm);
}

.contact-number {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--secondary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.contact-number svg {
    width: 24px;
    height: 24px;
}

.contact-number:hover {
    color: var(--secondary-dark);
}

.modal-actions {
    display: flex;
    gap: var(--spacing-md);
}

.btn-call,
.btn-directions {
    flex: 1;
    padding: var(--spacing-md);
    border: none;
    border-radius: var(--radius-lg);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    transition: all var(--transition-normal);
}

.btn-call {
    background: var(--gradient-danger);
    color: white;
}

.btn-call:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(244, 63, 94, 0.4);
}

.btn-directions {
    background: var(--gradient-primary);
    color: white;
}

.btn-directions:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.4);
}

.btn-call svg,
.btn-directions svg {
    width: 18px;
    height: 18px;
}

/* ===== Routing Panel ===== */
.routing-panel {
    position: absolute;
    top: 70px;
    right: var(--spacing-md);
    width: 320px;
    max-height: calc(100vh - 200px);
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    border: 1px solid rgba(99, 102, 241, 0.2);
    z-index: 400;
    overflow: hidden;
}

.routing-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--gradient-primary);
}

.routing-header h3 {
    color: white;
    font-size: 1rem;
    font-weight: 600;
}

.close-routing {
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: var(--radius-full);
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
}

.close-routing:hover {
    background: rgba(255, 255, 255, 0.3);
}

.routing-instructions {
    padding: var(--spacing-md);
    max-height: 400px;
    overflow-y: auto;
}

.routing-instructions::-webkit-scrollbar {
    width: 6px;
}

.routing-instructions::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

.routing-instructions::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: var(--radius-full);
}

/* Leaflet Routing Machine Override */
.leaflet-routing-container {
    display: none;
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
    .permission-card {
        padding: var(--spacing-xl);
    }

    .map-legend {
        top: auto;
        bottom: 120px;
        left: var(--spacing-sm);
        right: auto;
    }

    .direction-btn {
        left: var(--spacing-md);
        right: var(--spacing-md);
        transform: none;
        min-width: auto;
    }

    .direction-btn:hover {
        transform: translateY(-3px);
    }

    .routing-panel {
        left: var(--spacing-md);
        right: var(--spacing-md);
        width: auto;
    }

    .header-stats {
        display: none;
    }
}

/* ===== Leaflet Popup Override ===== */
.leaflet-popup-content-wrapper {
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
}

.leaflet-popup-content {
    margin: var(--spacing-md);
}

.leaflet-popup-tip {
    background: var(--bg-card);
}

.popup-content {
    min-width: 200px;
}

.popup-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: var(--spacing-xs);
    color: var(--primary-light);
}

.popup-type {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-sm);
}

.popup-distance {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-size: 0.8rem;
    color: var(--secondary);
    font-weight: 500;
}

.popup-ambulance {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-size: 0.8rem;
    color: var(--accent);
    font-weight: 500;
    margin-top: var(--spacing-xs);
}

.popup-actions {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--bg-elevated);
}

.popup-btn {
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: center;
}

.popup-btn-directions {
    background: var(--gradient-primary);
    color: white;
}

.popup-btn-directions:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.popup-btn-ambulance {
    background: var(--gradient-danger);
    color: white;
}

.popup-btn-ambulance:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(244, 63, 94, 0.4);
}

/* Ensure map has minimum height */
#map {
    flex: 1;
    z-index: 1;
    min-height: 400px;
    height: 100%;
}

/* Fix for Leaflet marker pane z-index */
.leaflet-marker-pane {
    z-index: 600;
}

.leaflet-popup-pane {
    z-index: 700;
}

/* Make sure marker elements are clickable */
.hospital-marker {
    pointer-events: auto !important;
}

.marker-hospital,
.ambulance-badge {
    pointer-events: auto !important;
    cursor: pointer !important;
}