/* --- 1. Global Layout & Fonts --- */
body {
    margin: 0;
    padding: 0;
    font-family: 'Nunito', sans-serif;
}

#map {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
}

/* --- 2. Playful Popup Styling --- */

/* Force the popup to be wider than the default */
.mapboxgl-popup {
    max-width: 340px !important;
}

/* The actual box container */
.mapboxgl-popup-content {
    padding: 0;
    border-radius: 20px; /* Very rounded corners */
    overflow: hidden;
    border: 3px solid white;
    box-shadow: 0 8px 20px rgba(0,0,0,0.15), 0 0 0 1px rgba(0,0,0,0.05);
    background: #fffaf0; /* Off-white warmer background */
}

/* Hide the default sharp close button */
.mapboxgl-popup-close-button {
    display: none;
}

/* The Cover Image */
.popup-header-image {
    width: 100%;
    height: 160px;
    object-fit: cover;
    display: block;
    border-bottom: 4px solid #FFD700; /* Gold border */
}

.popup-body {
    padding: 18px;
}

.popup-body h3 {
    margin: 0 0 10px;
    font-size: 20px;
    color: #2c3e50;
    font-weight: 700;
    line-height: 1.2;
}

/* A colourful bubble for the date */
.date-bubble {
    display: inline-block;
    background-color: #7c4dff; /* Deep purple */
    color: white;
    padding: 5px 12px;
    border-radius: 15px;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 10px;
    box-shadow: 2px 2px 0px #512da8; /* Hard shadow for pop */
}

/* Location Icon & Text */
.location-row {
    font-size: 13px;
    color: #666;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Event Description */
.event-desc {
    font-size: 14px;
    color: #555;
    line-height: 1.5;
    margin-bottom: 18px;
    /* Truncate text after 3 lines */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Playful Gradient Button */
.btn-link {
    display: block;
    text-align: center;
    /* A fun gradient from pink to orange */
    background: linear-gradient(45deg, #ff4081, #ff6e40);
    color: white;
    text-decoration: none;
    padding: 12px;
    border-radius: 30px;
    font-size: 15px;
    font-weight: 700;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 10px rgba(255, 64, 129, 0.3);
}

.btn-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(255, 64, 129, 0.4);
}

/* --- 3. Custom Marker Styling --- */

/* The container holding the custom marker elements */
.custom-marker-container {
    cursor: pointer;
    /* Ensure the bottom tip of the pin is exactly on the coordinate */
    transform: translate(-50%, -100%);
}

/* The colorful round top part */
.marker-head {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    /* Variable handled by JS, default fallback provided */
    background-color: var(--bgColor, #FF5722);
    border: 3px solid white;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    position: relative;
    z-index: 2;
    transition: transform 0.2s;
}

/* The pointy bit at the bottom */
.marker-tail {
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    /* The top border color must match the head's BG color */
    border-top: 14px solid var(--bgColor, #FF5722);
    position: absolute;
    bottom: -11px; /* Adjust to sit just under the head */
    left: 50%;
    transform: translateX(-50%);
    z-index: 1;
}

/* Hover effect for markers */
.custom-marker-container:hover .marker-head {
    transform: scale(1.15);
    box-shadow: 0 8px 16px rgba(0,0,0,0.3);
}

.btn-sent {
    background: #4CAF50 !important; /* Green */
    cursor: default;
    box-shadow: none;
    pointer-events: none; /* Make it unclickable */
}


#loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fff; /* White background to hide the map initially */
    z-index: 9999; /* Sit on top of everything */
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease-out; /* Smooth fade out */
}

/* The Spinner Animation */
.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3; /* Light grey base */
    border-top: 5px solid #FF5722; /* Orange spinner color */
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Keyframes for rotation */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Class to hide the loader */
.loader-hidden {
    opacity: 0;
    pointer-events: none; /* Let clicks pass through to the map */
}

/* --- BUTTON LOADING ANIMATION --- */

/* Keyframe for the small button spinner */
@keyframes button-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* The spinner circle itself */
.btn-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 3px solid rgba(255,255,255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: button-spin 1s ease-in-out infinite;
    vertical-align: middle;
}


/* --- MOBILE RESPONSIVENESS --- */

/* Only apply these rules on screens smaller than 600px */
@media (max-width: 600px) {

    /* 1. Make the popup width responsive */
    .mapboxgl-popup {
        max-width: 280px !important; /* Fixed smaller width for better fit */
    }

    /* 2. Shrink the cover image significantly */
    .popup-header-image {
        height: 100px; /* Reduced from 160px */
    }

    /* 3. Tighten the body padding */
    .popup-body {
        padding: 12px; /* Reduced from 18px */
    }

    /* 4. Smaller Text Elements */
    .popup-body h3 {
        font-size: 16px;
        margin-bottom: 4px;
        line-height: 1.2;
    }

    .date-bubble {
        font-size: 11px;
        padding: 3px 8px;
        margin-bottom: 6px;
    }

    .location-row {
        font-size: 11px;
        margin-bottom: 8px;
    }

    .event-desc {
        font-size: 12px;
        line-height: 1.3;
        margin-bottom: 12px;
        -webkit-line-clamp: 2; /* Limit to 2 lines of text */
    }

    /* 5. Compact Button */
    .btn-link {
        padding: 8px;
        font-size: 13px;
        margin-top: 0;
    }
}

#loader-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: white; /* or your theme color */
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loader-hidden {
    opacity: 0;
    visibility: hidden;
}

.loader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px; /* Space between text and spinner */
}

#loader-status {
    font-family: 'Nunito', sans-serif;
    color: #333;
    font-size: 18px;
    font-weight: 700;
    text-align: center;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}