/**
 * SVG Map Plugin - Frontend Styles
 */

/* Wrapper with Filters */
.smp-map-wrapper-outer {
    display: block;
}

.smp-map-wrapper-outer.smp-has-filters {
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

/* Filters Sidebar */
.smp-filters-sidebar {
    flex: 0 0 240px;
    padding: 0 15px 0 0;
}

.smp-filters-title {
    font-size: 20px;
    font-weight: 700;
    margin: 0 0 20px 0;
    color: #1a1a1a;
    line-height: 1.3;
}

.smp-filter-group {
    margin-bottom: 15px;
}

.smp-filter-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 13px;
    color: #333;
}

.smp-filter-select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    background: #fff;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

.smp-filter-select:focus {
    outline: none;
    border-color: #1e3a5f;
}

.smp-reset-filters {
    display: inline-block;
    width: auto;
    padding: 10px 30px;
    background: #e85a2a;
    color: #fff;
    border: none;
    border-radius: 25px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 5px;
}

.smp-reset-filters:hover {
    background: #d14a1a;
}

/* Map Container */
.smp-map-container {
    position: relative;
    flex: 1;
    overflow: hidden;
    border-radius: 8px !important;
    background: #f5f5f5;
    border: 1px solid #e0e0e0 !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);

    /* Responsive height so the full US map can be visible on first load */
    height: clamp(360px, 70vh, 620px);
    min-height: 360px;
}

.smp-map-inner {
    position: relative;
    width: 100%;
    height: 100%;
}

.smp-map-container svg.smp-svg {
    display: block;
    width: 100%;
    height: auto;
}

/* When panzoom is enabled we let panzoom own scaling. */
.smp-map-container.smp-panzoom-enabled .smp-map-inner {
    width: auto;
}

.smp-map-container.smp-panzoom-enabled svg.smp-svg {
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
}

/* Pins Overlay - positioned relative to container, not map-inner (avoids zoom blur) */
.smp-pins-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 20;
}

/* Pin Styles - now using pixel positioning from JS */
.smp-pin {
    position: absolute;
    transform: translate(-50%, -100%);
    cursor: pointer;
    pointer-events: auto;
    transition: transform 0.15s ease, filter 0.15s ease;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
    z-index: 10;
}

.smp-pin:hover,
.smp-pin:focus,
.smp-pin.smp-pin-active {
    transform: translate(-50%, -100%) scale(1.25);
    z-index: 100;
    outline: none;
    filter: drop-shadow(0 3px 6px rgba(0,0,0,0.4));
}

/* Stacked pin with count badge */
.smp-pin-stacked {
    z-index: 15;
}

.smp-pin-count {
    position: absolute;
    top: -5px;
    right: -8px;
    background: #333;
    color: #fff;
    font-size: 10px;
    font-weight: bold;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.smp-pin-icon {
    display: block;
    width: var(--smp-pin-size, 20px);
    height: auto;
}

/* Responsive pin sizing
   - Desktop size can be set per-map via settings (data-pin-size)
   - Mobile size is derived (or can be provided) so pins never look huge on phones
*/
.smp-map-container {
    --smp-pin-size-desktop: 20px;
    --smp-pin-size-mobile: 16px;
    --smp-pin-size: var(--smp-pin-size-desktop);
}

@media (max-width: 768px) {
    .smp-map-wrapper-outer.smp-has-filters {
        display: block;
    }

    .smp-filters-sidebar {
        flex: none;
        width: 100%;
        padding: 0;
        margin-bottom: 14px;
    }

    .smp-map-container {
        height: clamp(320px, 55vh, 520px);
        --smp-pin-size: var(--smp-pin-size-mobile);
    }

    .smp-pin-count {
        min-width: 14px;
        height: 14px;
        font-size: 9px;
    }
}

/* Stacked pins list popup */
.smp-stack-list {
    text-align: left;
}

.smp-stack-header {
    font-weight: 600;
    font-size: 14px;
    color: #333;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #eee;
}

.smp-stack-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    margin: 4px 0;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.smp-stack-item:hover {
    background: #f5f5f5;
}

.smp-stack-item-img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.smp-stack-item-icon {
    font-size: 20px;
    width: 36px;
    text-align: center;
    flex-shrink: 0;
}

.smp-stack-item-title {
    font-size: 13px;
    color: #e85a2a;
    font-weight: 500;
    text-decoration: underline;
}

/* Pin Popup */
.smp-pin-popup {
    position: absolute;
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    min-width: 180px;
    max-width: 240px;
    box-shadow: 0 4px 25px rgba(0,0,0,0.15);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 1000;
    pointer-events: none;
    overflow: visible;
}

/* Pointy arrow for popup */
.smp-pin-popup::after {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
}

/* Arrow pointing down (popup above pin) */
.smp-pin-popup.smp-popup-above::after {
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    border-top: 12px solid #fff;
}

/* Arrow pointing up (popup below pin) */
.smp-pin-popup.smp-popup-below::after {
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    border-bottom: 12px solid #fff;
}

.smp-pin-popup.smp-popup-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Close button - hidden on desktop, visible on mobile/touch */
.smp-popup-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border: none;
    background: #f0f0f0;
    border-radius: 50%;
    font-size: 18px;
    line-height: 1;
    color: #666;
    cursor: pointer;
    display: none; /* Hidden on desktop */
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
    padding: 0;
}

.smp-popup-close:hover {
    background: #e0e0e0;
    color: #333;
}

/* Show close button on mobile/touch devices */
@media (max-width: 768px), (hover: none) {
    .smp-popup-close {
        display: flex;
    }
}

.smp-pin-popup-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.smp-pin-popup-content {
    width: 100%;
    margin-bottom: 10px;
    text-align: center;
}

.smp-pin-popup-title {
    font-weight: 600;
    font-size: 18px;
    color: #180e7c;
    margin-bottom: 5px;
    line-height: 1.3;
}

.smp-pin-popup-title a {
    color: #180e7c !important;
    text-decoration: underline !important;
}

.smp-pin-popup-title a:hover {
    text-decoration: none !important;
}

.smp-pin-popup-description {
    font-size: 13px;
    color: #555;
    line-height: 1.5;
}

.smp-pin-popup-image {
    width: 130px !important;
    height: 130px !important;
    min-width: 130px !important;
    min-height: 130px !important;
    max-width: 130px !important;
    max-height: 130px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    display: none;
    border: 3px solid #e0e0e0 !important;
    margin: 0 auto;
}

.smp-pin-popup-image.smp-has-image {
    display: block !important;
}

/* Force image size even without class */
.smp-pin-popup .smp-pin-popup-image[src]:not([src=""]) {
    display: block !important;
    width: 130px !important;
    height: 130px !important;
    min-width: 130px !important;
    min-height: 130px !important;
    max-width: 130px !important;
    max-height: 130px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
}

@media (max-width: 768px) {
    .smp-pin-popup-image,
    .smp-pin-popup .smp-pin-popup-image[src]:not([src=""]) {
        width: 100px !important;
        height: 100px !important;
        min-width: 100px !important;
        min-height: 100px !important;
        max-width: 100px !important;
        max-height: 100px !important;
    }
}

/* Zoom Controls */
.smp-zoom-controls {
    position: absolute;
    top: 15px;
    right: 15px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    z-index: 100;
}

.smp-zoom-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 4px;
    font-size: 20px;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    color: #333;
}

.smp-zoom-btn:hover {
    background: #fff;
    transform: scale(1.05);
}

.smp-zoom-btn:active {
    transform: scale(0.95);
}

/* Error Message */
.smp-error {
    background: #fff3cd;
    border: 1px solid #ffc107;
    color: #856404;
    padding: 15px 20px;
    border-radius: 4px;
    text-align: center;
}

/* Loading State */
.smp-map-container.smp-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #1e3a5f;
    border-radius: 50%;
    animation: smp-spin 1s linear infinite;
}

@keyframes smp-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Animation for pins on load */
@keyframes smp-pin-drop {
    0% {
        transform: translate(-50%, -200%);
        opacity: 0;
    }
    60% {
        transform: translate(-50%, -90%);
    }
    80% {
        transform: translate(-50%, -105%);
    }
    100% {
        transform: translate(-50%, -100%);
        opacity: 1;
    }
}

.smp-pin.smp-animate {
    animation: smp-pin-drop 0.5s ease-out forwards;
}

/* Smooth panning */
.smp-map-container.smp-panning {
    cursor: grabbing;
}

.smp-map-container.smp-panning .smp-pin {
    pointer-events: none;
}

/* Responsive */
@media (max-width: 900px) {
    .smp-map-wrapper-outer.smp-has-filters {
        flex-direction: column;
    }
    
    .smp-filters-sidebar {
        flex: none;
        width: 100%;
    }
    
    .smp-filters-form {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    .smp-filter-group {
        margin-bottom: 0;
    }
    
    .smp-reset-filters {
        grid-column: 1 / -1;
    }
}

@media (max-width: 600px) {
    .smp-filters-form {
        grid-template-columns: 1fr;
    }
    
    .smp-pin-popup {
        min-width: 160px;
        max-width: 200px;
        padding: 15px;
        border-radius: 10px;
    }
    
    .smp-pin-popup-title {
        font-size: 16px !important;
    }
    
    .smp-pin-popup-description {
        font-size: 12px !important;
    }
    
    .smp-popup-close {
        width: 32px;
        height: 32px;
        font-size: 20px;
        top: -10px;
        right: -10px;
    }
    
    .smp-zoom-controls {
        top: 10px;
        right: 10px;
    }
    
    .smp-zoom-btn {
        width: 32px;
        height: 32px;
        font-size: 18px;
    }
}

/* Spider lines for expanded pins */
.smp-spider-lines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 40;
}

.smp-spider-leg {
    position: absolute;
    height: 1px;
    background: rgba(232, 90, 42, 0.3);
    transform-origin: 0 0;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.smp-spider-lines-visible .smp-spider-leg {
    opacity: 1;
}

/* Expanded pins (spread from cluster) */
.smp-pin-expanded {
    z-index: 50;
}

.smp-pin-clustered {
    cursor: pointer;
}

@media (max-width: 768px) {
    .smp-pin-expanded {
        z-index: 50;
    }
}

/* Leaflet GeoJSON Map Styling */
.smp-map-container[data-map-type="geojson"] .smp-map-inner {
    width: 100%;
    height: 100%;
}

.smp-map-container[data-map-type="geojson"] .leaflet-container {
    width: 100%;
    height: 100%;
    border-radius: 8px;
}

/* Hide Leaflet attribution for cleaner look */
.smp-map-container .leaflet-control-attribution {
    display: none !important;
}

/* Custom Leaflet pin marker */
.smp-leaflet-pin {
    background: transparent !important;
    border: none !important;
}

.smp-leaflet-pin svg {
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
    transition: transform 0.2s ease;
}

.smp-leaflet-pin:hover svg {
    transform: scale(1.2);
}

/* Leaflet popup overrides for kindness style */
.smp-map-container .leaflet-popup-content-wrapper {
    padding: 20px;
    border-radius: 6px;
}
.smp-map-container .leaflet-popup-content {
    margin: 0;
    width: 100% !important;
}
.smp-map-container .leaflet-container a.leaflet-popup-close-button {
    right: 10px;
    top: 10px;
    color: #999;
    font-size: 20px;
}

/* Act of Kindness Popup - matches Chase Foundation exactly */
.kindness-popup,
.kindness-popup .kindness-title,
.kindness-popup .kindness-label,
.kindness-popup .kindness-value,
.kindness-popup .ball-id,
.kindness-popup .current-post-indicator {
    font-family: 'Montserrat', Arial, sans-serif !important;
    font-size: 16px !important;
    color: #333 !important;
    font-weight: normal !important;
    line-height: 1.4 !important;
}
.kindness-popup { min-width: 100%; max-width: 100%; }
.kindness-title { margin-bottom: 15px !important; border-bottom: 1px solid #eee !important; padding-bottom: 10px !important; }
.kindness-section { margin-bottom: 12px !important; }
.kindness-label { margin-bottom: 3px !important; }
.kindness-popup .ball-id { color: #f47321 !important; margin-bottom: 8px !important; }
.kindness-popup .current-post-indicator { color: #2196F3 !important; font-weight: 600 !important; font-size: 12px !important; }

/* Cluster styling - matches Chase Foundation exactly */
.custom-cluster { background: transparent !important; border: none !important; }
.custom-cluster-icon {
    width: 55px;
    height: 35px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}
.leaflet-marker-icon.leaflet-marker-icon { cursor: pointer !important; }
.marker-cluster { cursor: pointer !important; }

/* Override default MarkerCluster.Default.css blue/green circles */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
    background: transparent !important;
    border: none !important;
}
.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
    background: transparent !important;
}

/* Country label tooltips */
.smp-map-container .leaflet-tooltip-pane {
    z-index: 650 !important;
}

.smp-country-label {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    font-weight: 600 !important;
    white-space: normal !important;
    pointer-events: none !important;
    padding: 0 !important;
    margin: 0 !important;
    text-align: center !important;
    line-height: 1.3 !important;
}

.smp-country-label::before {
    display: none !important;
}

.smp-continent-label {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    white-space: nowrap !important;
    pointer-events: none !important;
    text-align: center !important;
}

.smp-continent-label span {
    position: relative;
    left: -50%;
    white-space: normal !important;
    display: inline-block;
    text-align: center;
    line-height: 1.3;
}

/* Mobile popup styles - matches Chase Foundation */
@media screen and (max-width: 767px) {
    .leaflet-popup {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        z-index: 1000 !important;
    }
    .leaflet-popup-content-wrapper,
    .leaflet-popup-tip {
        opacity: 1 !important;
        visibility: visible !important;
    }
    .force-mobile-popup-visible,
    .kindness-popup-container,
    .mobile-popup-container {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    .mobile-popup .kindness-title,
    .mobile-popup .kindness-label,
    .mobile-popup .kindness-value {
        font-family: 'Montserrat', Arial, sans-serif !important;
        font-size: 16px !important;
        color: #333 !important;
        font-weight: normal !important;
        line-height: 1.4 !important;
    }
    .mobile-popup .ball-id {
        font-family: 'Montserrat', Arial, sans-serif !important;
        font-size: 16px !important;
        color: #f47321 !important;
        font-weight: normal !important;
        line-height: 1.4 !important;
        margin: 0 !important;
    }
    .mobile-popup { overflow: hidden !important; }
    .mobile-popup .kindness-section { margin-bottom: 3px !important; overflow: hidden !important; }
    .mobile-popup .kindness-value {
        max-height: 110px !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        padding-bottom: 2px !important;
        padding-right: 5px !important;
    }
    .leaflet-container a.leaflet-popup-close-button { right: 5px !important; top: 5px !important; }
    .leaflet-popup-content-wrapper { width: 240px !important; padding: 12px !important; overflow: hidden !important; }
    .leaflet-popup-content { width: 100% !important; margin: 0 !important; overflow: hidden !important; }
    .leaflet-control-zoom { margin-top: 60px !important; }
    .leaflet-control-attribution { display: none; }
}

.smp-country-tooltip {
    background: rgba(0,0,0,0.8) !important;
    color: #fff !important;
    border: none !important;
    border-radius: 4px !important;
    padding: 4px 8px !important;
    font-size: 12px !important;
}

.smp-country-tooltip::before {
    border-top-color: rgba(0,0,0,0.8) !important;
}
