/**
 * Frontend styles for Moth Heatmap Plugin
 * Responsive design for the heatmap display and controls
 * Enhanced with CSS variables for styling-api.js compatibility
 */

/* ===================================================================
   CSS CUSTOM PROPERTIES (CSS Variables)
   Used by styling-api.js for dynamic theming
   =================================================================== */
:root {
    /* Heatmap Colors - Used by styling-api.js */
    --moth-heatmap-low-color: #4ecdc4;
    --moth-heatmap-medium-color: #ffd93d;
    --moth-heatmap-high-color: #ff6b6b;

    /* Map Boundaries - Used by styling-api.js */
    --moth-heatmap-boundary-stroke-color: #668839;
    --moth-heatmap-boundary-fill-color: #f0f8e8;
    --moth-heatmap-boundary-hover-color: #8fbc47;

    /* Interface Theme - Used by styling-api.js */
    --moth-heatmap-primary-color: #668839;
    --moth-heatmap-secondary-color: #8fbc47;
    --moth-heatmap-accent-color: #a8d060;

    /* Map Markers - Used by styling-api.js */
    --moth-heatmap-marker-color: #668839;
    --moth-heatmap-marker-color-opacity: 1;
    --moth-heatmap-marker-border-color: #333333;
    --moth-heatmap-marker-border-opacity: 1;
    --moth-heatmap-marker-size: 20px;

    /* Heatmap Appearance - Used by styling-api.js */
    --moth-heatmap-opacity: 0.8;
    --moth-heatmap-radius: 20px;
    --moth-heatmap-blur: 15px;

    /* Map Styling - Used by styling-api.js */
    --moth-heatmap-boundary-width: 2px;
    --moth-heatmap-corner-radius: 8px;

    /* Animation & Effects - Used by styling-api.js */
    --moth-heatmap-enable-animations: 1;
    --moth-heatmap-enable-hover-effects: 1;
    --moth-heatmap-enable-transitions: 1;
}

/* Main container */
.moth-heatmap-container {
    width: 100%;
    max-width: 100%; /* Prevent horizontal overflow */
    margin: 20px 0;
    font-family:
        "IBM Plex Sans",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
    position: relative;
    overflow-x: hidden; /* Prevent horizontal scroll */
    box-sizing: border-box;
}

/* Overlay legend for heatmap - bottom left, compact */
.moth-heatmap-legend-overlay {
    position: absolute;
    left: 16px;
    bottom: 16px;
    z-index: 20;
    pointer-events: none;
}

/* Desktop legend - show on larger screens */
.moth-heatmap-legend-desktop {
    display: block;
}

/* Mobile legend - hide on larger screens */
.moth-heatmap-legend-mobile {
    display: none;
}
.moth-heatmap-legend-small .moth-heatmap-legend {
    background: rgba(255, 255, 255, 0.92);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    padding: 10px 16px;
    min-width: 180px;
    max-width: 220px;
    font-size: 13px;
    pointer-events: auto;
}
.moth-heatmap-legend-small .legend-label {
    font-size: 12px;
    font-weight: 600;
    color: #668839;
    margin-bottom: 4px;
    display: block;
}
.moth-heatmap-legend-small .legend-gradient-container {
    margin: 6px 0 0 0;
    width: 100%;
}
.moth-heatmap-legend-small .legend-gradient {
    height: 10px;
    border-radius: 5px;
    width: 100%;
}
.moth-heatmap-legend-small .legend-range {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    margin-top: 2px;
}
@media (max-width: 600px) {
    /* Hide desktop legend on mobile */
    .moth-heatmap-legend-desktop {
        display: none;
    }

    /* Show mobile legend on mobile */
    .moth-heatmap-legend-mobile {
        display: block;
        position: static;
        left: auto;
        bottom: auto;
        width: 100%;
        margin-top: 12px;
    }

    .moth-heatmap-legend-small .moth-heatmap-legend {
        width: 100%;
        min-width: auto;
        max-width: none;
        padding: 12px 16px;
        font-size: 12px;
        margin: 0;
    }
    .moth-heatmap-legend-small .legend-gradient-container {
        width: 100%;
    }
    .moth-heatmap-legend-small .legend-gradient {
        width: 100%;
        height: 12px;
    }
}

/* Controls section - Apple-style modern design */
.moth-heatmap-controls {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(102, 136, 57, 0.1);
    border-radius: 4px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow:
        0 8px 32px rgba(102, 136, 57, 0.1),
        0 1px 2px rgba(0, 0, 0, 0.05);
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.moth-heatmap-controls:hover {
    box-shadow:
        0 12px 40px rgba(102, 136, 57, 0.15),
        0 2px 8px rgba(0, 0, 0, 0.08);
}

.moth-heatmap-filters {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
    align-items: stretch;
}

/* Date range container wrapper */
.date-range-wrapper {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 12px;
    background: rgba(102, 136, 57, 0.03);
    backdrop-filter: blur(5px);
    border-radius: 4px;
    border: 1px solid rgba(102, 136, 57, 0.1);
    position: relative;
    flex: 1;
    min-height: 120px;
}

.date-range-wrapper::before {
    content: "Date Range";
    position: absolute;
    top: -8px;
    left: 12px;
    background: #fff;
    color: #668839;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 6px;
}

/* Button group wrapper */
.button-group-wrapper {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: rgba(102, 136, 57, 0.03);
    backdrop-filter: blur(5px);
    border-radius: 4px;
    border: 1px solid rgba(102, 136, 57, 0.1);
    position: relative;
    flex: 1;
    min-height: 120px;
    justify-content: center;
}

.button-group-wrapper::before {
    content: "Actions";
    position: absolute;
    top: -8px;
    left: 12px;
    background: #fff;
    color: #668839;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 6px;
}

/* Reset nested filter groups inside wrappers */
.date-range-wrapper .filter-group,
.button-group-wrapper .filter-group {
    flex: unset;
    min-height: unset;
    padding: 0;
    background: none;
    backdrop-filter: none;
    border-radius: 0;
    border: none;
    position: static;
    margin: 0;
}

.date-range-wrapper .filter-group::before,
.button-group-wrapper .filter-group::before {
    display: none;
}

.date-range-wrapper .filter-group label,
.button-group-wrapper .filter-group label {
    margin-bottom: 4px;
}

/* Remove margin-top from buttons in wrapper */
.button-group-wrapper .moth-heatmap-update-btn,
.button-group-wrapper .moth-heatmap-reset-btn {
    margin-top: 0;
    margin-left: 0;
}

@media (max-width: 768px) {
    .moth-heatmap-filters {
        flex-wrap: wrap;
        gap: 14px;
    }

    .date-range-wrapper,
    .button-group-wrapper,
    .filter-group {
        flex: 1 1 calc(50% - 7px);
        min-height: 100px;
        padding: 10px;
    }

    .button-group-wrapper .filter-group button {
        padding: 12px 16px;
        font-size: 14px;
    }

    /* Info sections responsive for tablets */
    .moth-heatmap-info-sections {
        flex-direction: column;
        gap: 16px;
        align-items: stretch;
    }

    .moth-heatmap-legend,
    .moth-heatmap-charts {
        padding: 16px;
        max-width: none;
        min-width: auto;
        flex: none;
    }

    .legend-gradient {
        width: 250px;
    }

    .legend-range {
        width: 250px;
    }

    .charts-county-list {
        max-height: 200px;
    }

    .county-chart-btn {
        padding: 8px 12px;
    }

    .county-name {
        font-size: 12px;
    }

    .county-stats {
        font-size: 10px;
    }
}

@media (max-width: 480px) {
    .moth-heatmap-filters {
        flex-direction: column;
        gap: 14px;
        margin-top: 10px;
    }

    .date-range-wrapper,
    .button-group-wrapper,
    .filter-group {
        flex: 1 1 auto;
        min-height: 80px;
        padding: 16px;
        gap: 6px;
    }

    .date-range-wrapper::before,
    .button-group-wrapper::before,
    .filter-group::before {
        font-size: 10px;
    }

    .button-group-wrapper .filter-group button {
        padding: 10px 14px;
        font-size: 13px;
    }

    .filter-group label {
        font-size: 12px;
        margin-bottom: 4px;
    }

    .filter-group input,
    .filter-group select {
        font-size: 14px;
        padding: 8px 10px;
    }

    /* Info sections responsive for mobile */
    .moth-heatmap-info-sections {
        flex-direction: column;
        gap: 12px;
        margin-top: 16px;
        align-items: stretch;
    }

    .moth-heatmap-legend,
    .moth-heatmap-charts {
        padding: 12px;
        max-width: none;
        min-width: auto;
        flex: none;
    }

    .moth-heatmap-legend h4,
    .moth-heatmap-charts h4 {
        font-size: 14px;
        margin-bottom: 10px;
    }

    .legend-gradient {
        width: 200px;
        height: 18px;
    }

    .legend-range {
        width: 200px;
        font-size: 11px;
    }

    .legend-label {
        font-size: 13px;
        margin-bottom: 6px;
    }

    .charts-subtitle {
        font-size: 11px;
    }

    .charts-county-list {
        max-height: 160px;
        gap: 6px;
    }

    .county-chart-btn {
        padding: 8px 10px;
    }

    .county-name {
        font-size: 11px;
    }

    .county-stats {
        font-size: 9px;
    }
}

.filter-group {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 120px;
    padding: 16px;
    background: rgba(102, 136, 57, 0.03);
    backdrop-filter: blur(5px);
    border-radius: 4px;
    border: 1px solid rgba(102, 136, 57, 0.1);
    position: relative;
    justify-content: center;
}

/* Add labels for standalone filter groups */
.filter-group:has(select.moth-heatmap-species)::before {
    content: "Species Filter";
    position: absolute;
    top: -8px;
    left: 12px;
    background: #fff;
    color: #668839;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 6px;
}

.filter-group:has(select.moth-heatmap-counties)::before {
    content: "County Filter";
    position: absolute;
    top: -8px;
    left: 12px;
    background: #fff;
    color: #668839;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 6px;
}

/* Fallback for browsers without :has() support */
@supports not (selector(:has(a))) {
    .filter-group {
        position: relative;
    }

    .filter-group select + label::before,
    .filter-group label:first-child::after {
        content: attr(data-filter-name, "Filter");
        position: absolute;
        top: -8px;
        left: 12px;
        background: #fff;
        color: #668839;
        font-size: 11px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        padding: 0 6px;
    }
}

/* Additional styling for wrapped groups */
.date-range-wrapper .filter-group input {
    transition: all 0.2s ease;
}

.date-range-wrapper .filter-group input:focus {
    transform: translateY(-1px);
    box-shadow:
        0 0 0 3px rgba(102, 136, 57, 0.15),
        0 4px 12px rgba(102, 136, 57, 0.1);
}

.button-group-wrapper .filter-group button {
    width: 100%;
    justify-content: center;
    transition: all 0.2s ease;
}

.button-group-wrapper .filter-group button:hover {
    transform: translateY(-1px);
}

.filter-group label {
    font-weight: 500;
    margin-bottom: 6px;
    color: #668839;
    font-size: 13px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    font-feature-settings: "tnum";
    flex-shrink: 0;
}

/* Ensure proper spacing within filter groups */
.filter-group > * {
    flex-shrink: 0;
}

.filter-group > select,
.filter-group > input {
    flex-grow: 1;
}

.filter-group input,
.filter-group select {
    padding: 8px 12px;
    border: 1.5px solid rgba(102, 136, 57, 0.2);
    border-radius: 6px;
    font-size: 13px;
    background-color: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    font-family:
        "IBM Plex Sans",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
    box-shadow: 0 1px 3px rgba(102, 136, 57, 0.08);
    box-sizing: border-box;
}

.filter-group select {
    min-height: 40px;
}

.filter-group select[multiple] {
    max-height: 140px;
    overflow-y: auto;
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: #668839;
    background-color: #fff;
    box-shadow:
        0 0 0 3px rgba(102, 136, 57, 0.15),
        0 2px 8px rgba(102, 136, 57, 0.1);
    transform: translateY(-1px);
}

.filter-group input:hover,
.filter-group select:hover {
    border-color: rgba(102, 136, 57, 0.4);
    background-color: #fff;
    box-shadow: 0 2px 6px rgba(102, 136, 57, 0.1);
}

.moth-heatmap-species,
.moth-heatmap-counties {
    width: 200px;
    max-height: 120px;
    overflow-y: auto;
}

.moth-heatmap-counties {
    font-size: 13px;
}

.moth-heatmap-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin: 15px 0;
    padding: 15px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(102, 136, 57, 0.2);
}

/* Hide toggles container when empty (all toggles disabled) */
.moth-heatmap-toggles:empty {
    display: none;
}

.moth-heatmap-toggles label {
    display: flex;
    align-items: center;
    font-weight: 400;
    color: #668839;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    padding: 6px 12px;
    border-radius: 4px;
    background: rgba(102, 136, 57, 0.06);
    border: 1px solid rgba(102, 136, 57, 0.1);
    font-size: 13px;
    backdrop-filter: blur(5px);
}

.moth-heatmap-toggles label:hover {
    color: #668839;
    background: rgba(102, 136, 57, 0.12);
    border-color: rgba(102, 136, 57, 0.25);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(102, 136, 57, 0.15);
}

.moth-heatmap-toggles input[type="checkbox"] {
    margin-right: 8px;
    width: 16px;
    height: 16px;
    accent-color: #668839;
}

/* Buttons - Apple-style modern design */
.button,
.moth-heatmap-update-btn,
.moth-heatmap-reset-btn {
    background: linear-gradient(135deg, #668839 0%, #546a2f 100%);
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    margin-top: 16px;
    box-shadow:
        0 4px 12px rgba(102, 136, 57, 0.25),
        0 1px 3px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
    font-family:
        "IBM Plex Sans",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
}

.button:hover,
.moth-heatmap-update-btn:hover,
.moth-heatmap-reset-btn:hover {
    background: linear-gradient(135deg, #546a2f 0%, #3d4d23 100%);
    transform: translateY(-2px);
    box-shadow:
        0 8px 20px rgba(102, 136, 57, 0.3),
        0 2px 6px rgba(0, 0, 0, 0.15);
}

.button:active,
.moth-heatmap-update-btn:active,
.moth-heatmap-reset-btn:active {
    transform: translateY(0);
    box-shadow:
        0 4px 12px rgba(102, 136, 57, 0.25),
        0 1px 3px rgba(0, 0, 0, 0.1);
}

.moth-heatmap-reset-btn {
    background: linear-gradient(135deg, #8e8e93 0%, #6d6d70 100%);
    box-shadow:
        0 4px 12px rgba(142, 142, 147, 0.25),
        0 1px 3px rgba(0, 0, 0, 0.1);
}

.moth-heatmap-reset-btn:hover {
    background: linear-gradient(135deg, #6d6d70 0%, #48484a 100%);
    box-shadow:
        0 8px 20px rgba(142, 142, 147, 0.3),
        0 2px 6px rgba(0, 0, 0, 0.15);
}

/* Map wrapper */
.moth-heatmap-map-wrapper {
    position: relative;
    border-radius: 4px;
    overflow: hidden;
    box-shadow:
        0 8px 8px rgba(0, 0, 0, 0.15),
        0 3px 3px rgba(0, 0, 0, 0.1);
    transition: box-shadow 0.3s ease;
    background: #fff;

    /* Mobile performance optimizations */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Simplified cursor rules - only for UI elements that need them */
.moth-heatmap-container button,
.moth-heatmap-container .info-close,
.moth-heatmap-container .county-chart-btn,
.moth-heatmap-container a,
.moth-heatmap-container [role="button"],
.moth-heatmap-container input[type="button"],
.moth-heatmap-container input[type="submit"] {
    cursor: pointer;
    /* Improve touch target size on mobile */
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
}

/* Form elements get appropriate cursors */
.moth-heatmap-container input[type="text"],
.moth-heatmap-container input[type="date"],
.moth-heatmap-container select,
.moth-heatmap-container textarea {
    cursor: auto;
    /* Optimize for mobile input */
    -webkit-tap-highlight-color: transparent;
}

.moth-heatmap-container input[type="text"]:focus,
.moth-heatmap-container input[type="date"]:focus,
.moth-heatmap-container textarea:focus {
    cursor: text;
}

.moth-heatmap-map-wrapper:hover {
    box-shadow:
        0 12px 35px rgba(0, 0, 0, 0.2),
        0 4px 8px rgba(0, 0, 0, 0.12);
}

/* Map controls overlay */
.moth-heatmap-map-controls {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;

    /* Mobile touch optimization */
    touch-action: manipulation;
}

.moth-heatmap-zoom-control {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    color: #495057;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

    /* Mobile optimization */
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.moth-heatmap-map {
    width: 100%;
    height: 600px;
    border: none;

    /* Mobile performance and touch optimizations */
    touch-action: pan-x pan-y;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;

    /* Optimize for mobile scrolling and prevent zoom on double tap */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;

    /* Improve rendering performance */
    will-change: transform;
}

/* Mobile-specific gesture hint overlay */
.moth-heatmap-map-wrapper::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 1;
    opacity: 0;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 500;
    transition: opacity 0.3s ease;
}

/* Show gesture hint on touch devices when appropriate */
@media (pointer: coarse) {
    .moth-heatmap-map-wrapper.show-gesture-hint::after {
        content: "👆 Use two fingers to move the map";
        opacity: 1;
    }
}

/* Loading indicator */
.moth-heatmap-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007cba;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

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

.moth-heatmap-loading p {
    color: #666;
    font-size: 16px;
    margin: 0;
}

/* Data counter */
.moth-heatmap-data-counter {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 600;
    color: #495057;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    max-width: 280px;
    min-width: 200px;
}

.counter-summary {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.counter-main {
    font-size: 13px;
    font-weight: 600;
    color: #2c3e50;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    padding-bottom: 8px;
}

.counter-species {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.species-header {
    font-size: 12px;
    font-weight: 600;
    color: #34495e;
    margin-bottom: 4px;
}

.species-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.species-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 0;
    font-size: 11px;
    line-height: 1.3;
}

.species-name {
    color: #555;
    font-weight: 500;
    flex: 1;
    margin-right: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.species-count {
    color: #007cba;
    font-weight: 600;
    font-size: 11px;
    flex-shrink: 0;
}

.species-more {
    font-size: 10px;
    color: #777;
    font-style: italic;
    text-align: center;
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.moth-heatmap-legend h4 {
    margin: 0 0 12px 0;
    color: #668839;
    font-size: 15px;
    font-weight: 500;
    letter-spacing: 0.01em;
    font-family:
        "IBM Plex Sans",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
}

.legend-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Legend content container */
.legend-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.legend-item {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Legend title and description */
.legend-label {
    font-weight: 500;
    color: #668839;
    font-size: 14px;
    font-family:
        "IBM Plex Sans",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
    text-align: center;
    margin-bottom: 8px;
}

/* Gradient bar container */
.legend-gradient-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.legend-gradient {
    width: 300px;
    height: 20px;
    background: linear-gradient(
        to right,
        rgba(0, 255, 0, 0.7) 0%,
        /* Green (low) */ rgba(255, 255, 0, 0.8) 33%,
        /* Yellow (medium) */ rgba(255, 165, 0, 0.85) 66%,
        /* Orange (medium-high) */ rgba(255, 0, 0, 0.9) 100%
    ); /* Red (high) */
    border-radius: 10px;
    border: 1px solid rgba(102, 136, 57, 0.2);
    box-shadow:
        inset 0 1px 2px rgba(0, 0, 0, 0.1),
        0 2px 8px rgba(102, 136, 57, 0.15);
    position: relative;
    overflow: hidden;
}

.legend-gradient::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        to right,
        transparent 0%,
        rgba(255, 255, 255, 0.1) 50%,
        transparent 100%
    );
    pointer-events: none;
}

/* Range labels positioned relative to gradient */
.legend-range {
    display: flex;
    justify-content: space-between;
    width: 100px;
    font-size: 12px;
    color: rgba(102, 136, 57, 0.8);
    font-family:
        "IBM Plex Sans",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
    font-weight: 500;
    letter-spacing: 0.02em;
}

.legend-min {
    text-align: left;
}

.legend-max {
    text-align: right;
}

/* Info panel - unified modal design for desktop and mobile
   Fixed z-index layering: backdrop (9999) < modal content (10001) < interactive elements (10002) */
.moth-heatmap-info-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    min-width: 300px;
    max-height: 80vh;
    overflow-y: auto;
    z-index: 10001;
    animation: modalSlideIn 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    pointer-events: auto;
}

/* Modal backdrop overlay */
.moth-heatmap-info-panel::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 9999;
    pointer-events: all;
    animation: fadeInOverlay 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

@keyframes fadeInOverlay {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid #e0e0e0;
    background: #f8f9fa;
    border-radius: 4px 4px 0 0;
    position: relative;
    z-index: 10002;
    pointer-events: auto;
}

.info-title {
    margin: 0;
    font-size: 16px;
    color: #333;
}

.info-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer !important;
    color: #666;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
    z-index: 10002;
    position: relative;
}

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

.info-content {
    padding: 15px;
    background-color: #fff;
    position: relative;
    z-index: 10002;
    pointer-events: auto;
}

.county-stats {
    display: grid;
    gap: 8px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    border-bottom: 1px solid #f0f0f0;
}

.stat-item:last-child {
    border-bottom: none;
}

.stat-item label {
    font-weight: 500;
    color: #555;
}

.stat-item span {
    color: #333;
    font-weight: 600;
}

.top-species {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
}

.top-species h5 {
    margin: 0 0 10px 0;
    color: #333;
    font-size: 14px;
}

.top-species ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.top-species li {
    padding: 3px 0;
    font-size: 13px;
    color: #555;
    border-bottom: 1px solid #f5f5f5;
}

.top-species li:last-child {
    border-bottom: none;
}

/* Error states */
.moth-heatmap-error {
    background: #fff2f2;
    border: 1px solid #ffcccb;
    border-radius: 4px;
    padding: 20px;
    text-align: center;
    color: #d63638;
}

.moth-heatmap-error p {
    margin: 0 0 15px 0;
    font-size: 16px;
}

.moth-heatmap-error button {
    background: #d63638;
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.moth-heatmap-error button:hover {
    background: #b32d2e;
}

/* Responsive design */
@media (max-width: 768px) {
    .moth-heatmap-container {
        margin: 10px 0;
    }

    .moth-heatmap-controls {
        margin-top: 20px;
        margin-bottom: 15px;
        padding: 16px;
    }

    .moth-heatmap-filters {
        flex-direction: column;
        gap: 12px;
        margin-top: 24px;
    }

    .filter-group {
        min-width: 100%;
        margin-bottom: 8px;
    }

    .moth-heatmap-species,
    .moth-heatmap-counties {
        min-width: 100%;
        max-width: 100%;
        margin-bottom: 10px;
    }

    .moth-heatmap-toggles {
        flex-direction: column;
        gap: 10px;
    }

    .moth-heatmap-info-panel {
        max-width: 90vw;
        min-width: 280px;
    }

    .moth-heatmap-map {
        height: 400px;
        /* Mobile-specific optimizations */
        min-height: 300px;
        max-height: 50vh;
    }

    /* Optimize map controls for tablets */
    .moth-heatmap-map-controls {
        top: 12px;
        left: 12px;
        gap: 6px;
    }

    .moth-heatmap-zoom-control {
        padding: 6px 10px;
        font-size: 11px;
    }

    /* Adjust data counter for tablets */
    .moth-heatmap-data-counter {
        top: 12px;
        right: 12px;
        padding: 8px 12px;
        font-size: 11px;
    }

    .button,
    .moth-heatmap-update-btn,
    .moth-heatmap-reset-btn {
        width: 100%;
        margin: 5px 0;
        min-height: 44px; /* Improve touch targets */
    }
}

@media (max-width: 480px) {
    .moth-heatmap-container {
        margin: 5px; /* Reduced margin with side padding for viewport safety */
        max-width: calc(100vw - 10px); /* Ensure container fits in viewport */
        overflow-x: hidden; /* Prevent any horizontal scroll */
    }

    /* Ensure all child elements respect container bounds */
    .moth-heatmap-container * {
        max-width: 100%;
        box-sizing: border-box;
    }

    .moth-heatmap-controls {
        margin-top: 15px; /* Reduced top margin */
        margin-bottom: 10px;
        padding: 12px; /* Reduced padding */
        position: relative;
    }

    /* Default to collapsed state on mobile to prevent flash */
    .moth-heatmap-controls .moth-heatmap-filters,
    .moth-heatmap-controls .moth-heatmap-toggles {
        display: none;
    }

    .moth-heatmap-controls::after {
        content: "▶";
        position: absolute;
        top: 20px;
        right: 20px;
        font-size: 12px;
        color: #668839;
        transition: transform 0.3s ease;
        pointer-events: none;
        transform: rotate(-90deg);
    }

    /* Expanded state (when .expanded class is added by JavaScript) */
    .moth-heatmap-controls.expanded .moth-heatmap-filters,
    .moth-heatmap-controls.expanded .moth-heatmap-toggles {
        display: block;
    }

    .moth-heatmap-controls.expanded::after {
        content: "▼";
        transform: rotate(0deg);
    }

    /* Mobile collapsible filter header (responsive UX) */
    .moth-heatmap-controls::before {
        content: "🔍 Filters & Controls (tap to expand)";
        display: block;
        font-weight: 600;
        font-size: 14px;
        color: #668839;
        padding: 8px 12px;
        background: rgba(102, 136, 57, 0.1);
        border-radius: 4px;
        cursor: pointer;
        position: relative;
        touch-action: manipulation; /* Optimize for touch */
        user-select: none; /* Prevent text selection */
    }

    /* Add expandable hint text below the filter header */
    .moth-heatmap-controls.expanded::before {
        content: "🔍 Filters & Controls (tap to collapse)";
    }

    /* Make entire control header clickable on mobile */
    .moth-heatmap-controls {
        cursor: pointer;
    }

    /* Override cursor for child elements to prevent conflicts */
    .moth-heatmap-controls .moth-heatmap-filters,
    .moth-heatmap-controls .moth-heatmap-toggles {
        cursor: auto;
    }

    /* Mobile-optimized map height for better content visibility */
    .moth-heatmap-map {
        height: 350px; /* Increased from 300px for better map interaction */
        min-height: 300px;
        max-height: 45vh; /* Responsive height based on viewport */
        border-radius: 4px; /* Slightly smaller radius on mobile */
    }

    /* Optimize map controls for mobile phones */
    .moth-heatmap-map-controls {
        top: 8px;
        left: 8px;
        gap: 4px;
    }

    .moth-heatmap-zoom-control {
        padding: 6px 8px;
        font-size: 10px;
        min-height: 32px;
        min-width: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Adjust data counter for mobile phones */
    .moth-heatmap-data-counter {
        top: 8px;
        right: 8px;
        padding: 6px 8px;
        font-size: 10px;
        max-width: calc(100vw - 80px); /* Prevent overflow */
        word-wrap: break-word;
    }

    /* Enhanced touch targets for mobile */
    .moth-heatmap-container button,
    .moth-heatmap-container .county-chart-btn {
        min-height: 24px; /* Larger touch targets for phones */
        padding: 16px 16px;
        font-size: 14px;
        border-radius: 6px;
    }

    /* Improve mobile form elements */
    .moth-heatmap-container select,
    .moth-heatmap-container input[type="date"] {
        min-height: 48px;
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 12px;
    }

    /* Enhanced touch targets for mobile */
    .filter-group input,
    .filter-group select {
        font-size: 16px; /* Prevent zoom on iOS */
        min-height: 24px; /* Increased from 44px for better touch targets */
        padding: 14px 18px; /* Increased padding for easier tapping */
        border-radius: 4px; /* Smaller radius for mobile */
    }

    .filter-group label {
        font-size: 14px;
        margin-bottom: 8px; /* Increased spacing */
        display: block;
        font-weight: 600; /* Bolder for better readability */
    }

    /* Improved button touch targets */
    .button,
    .moth-heatmap-update-btn,
    .moth-heatmap-reset-btn {
        min-height: 48px; /* Consistent with iOS/Android guidelines */
        padding: 14px 20px; /* Increased padding */
        font-size: 15px; /* Slightly larger text */
        border-radius: 4px; /* Smaller radius for mobile */
        font-weight: 600; /* Bolder text */
    }

    /* Mobile-optimized data counter */
    .moth-heatmap-data-counter {
        position: relative;
        top: auto;
        right: auto;
        margin-top: 16px;
        max-width: none;
        min-width: auto;
        padding: 10px 12px; /* Reduced padding */
        font-size: 11px; /* Slightly smaller text */
    }

    /* Enhanced mobile modal for very small screens */
    .moth-heatmap-info-panel {
        max-width: 95vw;
        max-height: 90vh; /* Increased for better content viewing */
        min-width: 280px; /* Slightly wider minimum */
        border-radius: 4px 4px 0 0; /* Rounded top corners only */
        bottom: 10%; /* Anchor to bottom on mobile */
        top: auto;
        transform: translateX(-50%);
    }

    .moth-heatmap-info-panel .info-header {
        padding: 16px; /* Increased padding for touch targets */
        position: sticky;
        top: 0;
        background: #f8f9fa;
        border-bottom: 1px solid #e0e0e0;
        border-radius: 4px 4px 0 0;
    }

    .moth-heatmap-info-panel .info-close {
        width: 32px; /* Larger close button for touch */
        height: 32px;
        font-size: 24px;
    }

    .moth-heatmap-info-panel .info-content {
        padding: 16px; /* Increased padding */
        max-height: calc(90vh - 80px); /* Adjusted for larger header */
        overflow-y: auto;
    }

    .counter-summary {
        gap: 8px; /* Increased spacing */
    }

    /* Ensure filter dropdowns are accessible on very small screens */
    .moth-heatmap-species,
    .moth-heatmap-counties {
        margin-bottom: 12px;
        min-height: 48px; /* Consistent touch target */
    }

    .filter-group {
        margin-bottom: 12px; /* Increased spacing */
    }

    /* Toggle checkboxes - larger for mobile */
    .moth-heatmap-toggles input[type="checkbox"] {
        width: 20px; /* Larger checkbox */
        height: 20px;
        margin-right: 10px;
    }

    .moth-heatmap-toggles label {
        padding: 10px 16px; /* Increased padding for touch */
        min-height: 44px; /* Touch target compliance */
        display: flex;
        align-items: center;
    }

    .counter-main {
        font-size: 12px;
        padding-bottom: 6px;
    }

    .species-header {
        font-size: 11px;
        margin-bottom: 3px;
    }

    .species-item {
        font-size: 10px;
        padding: 1px 0;
    }

    .species-name {
        margin-right: 6px;
    }

    .species-count {
        font-size: 10px;
    }

    .species-more {
        font-size: 9px;
        margin-top: 3px;
        padding-top: 3px;
    }

    /* Improve gesture handling on mobile map */
    .moth-heatmap-map-wrapper {
        border-radius: 4px; /* Consistent with map */
        /* Prevent page scroll when interacting with map */
        touch-action: none;
    }

    /* Mobile loading optimization */
    .moth-heatmap-loading {
        background: rgba(255, 255, 255, 0.95); /* More opaque on mobile */
    }

    .loading-spinner {
        width: 32px; /* Smaller spinner on mobile */
        height: 32px;
    }

    /* Simplified mobile UI - hide non-essential elements */
    .moth-heatmap-legend h4 {
        font-size: 13px; /* Smaller legend title */
    }

    .legend-gradient {
        width: 250px; /* Smaller gradient on mobile */
        height: 16px; /* Thinner gradient */
    }

    .legend-range {
        width: 250px;
        font-size: 11px; /* Smaller range labels */
    }

    /* Simplify info sections layout */
    .moth-heatmap-info-sections {
        margin-top: 12px; /* Reduced margin */
    }

    .moth-heatmap-legend {
        padding: 10px; /* Reduced padding */
    }

    /* Hide scale control and zoom control text overlays on mobile */
    .moth-heatmap-map-controls {
        display: none; /* Hide custom map controls on mobile */
    }

    .moth-heatmap-data-counter .counter-main {
        text-align: center; /* Center the main counter text */
        font-size: 13px; /* Slightly larger for better readability */
        padding-bottom: 0; /* Remove bottom padding */
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .legend-gradient {
        background-size: 100% 100%;
    }
}

/* Print styles */
@media print {
    .moth-heatmap-controls,
    .moth-heatmap-info-panel {
        display: none;
    }

    .moth-heatmap-container {
        break-inside: avoid;
    }

    .moth-heatmap-map {
        height: 400px;
        border: 1px solid #000;
    }
}

/* Accessibility improvements */
.moth-heatmap-container *:focus {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

.moth-heatmap-container button:focus,
.moth-heatmap-container input:focus,
.moth-heatmap-container select:focus {
    box-shadow: 0 0 0 3px rgba(0, 124, 186, 0.3);
}

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Impact level badges and styling */
.impact-badge {
    display: inline-block;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    border-radius: 4px;
    margin-left: 8px;
    vertical-align: middle;
}

.impact-badge.impact-low {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.impact-badge.impact-medium {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

.impact-badge.impact-high {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.impact-badge.impact-very-high {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    animation: pulse-impact 2s infinite;
}

@keyframes pulse-impact {
    0% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(220, 53, 69, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
    }
}

/* Impact level text styling */
.impact-low,
.modal-stat-value.impact-low {
    color: #28a745;
    font-weight: 600;
}

.impact-medium,
.modal-stat-value.impact-medium {
    color: #fd7e14;
    font-weight: 600;
}

.impact-high,
.modal-stat-value.impact-high {
    color: #dc3545;
    font-weight: 600;
}

.impact-very_high,
.modal-stat-value.impact-very_high {
    color: #dc3545;
    font-weight: 700;
    text-shadow: 0 0 2px rgba(220, 53, 69, 0.3);
}

/* Enhanced info panel styling for impact data */
.stat-item .impact-low,
.stat-item .impact-medium,
.stat-item .impact-high,
.stat-item .impact-very_high,
.modal-stat-value.impact-low,
.modal-stat-value.impact-medium,
.modal-stat-value.impact-high,
.modal-stat-value.impact-very_high {
    text-transform: capitalize;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
    font-weight: 600;
}

/* Enhanced marker info window styling */
.marker-info {
    min-width: 200px;
    font-family:
        "IBM Plex Sans",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
}

.marker-info h4 {
    margin: 0 0 8px 0;
    color: #2c3e50;
    font-size: 14px;
    font-weight: 600;
}

.marker-info p {
    margin: 4px 0;
    font-size: 12px;
    line-height: 1.4;
}

.marker-info strong {
    color: #34495e;
    font-weight: 600;
}

/* Multi-select dropdown improvements */
.moth-heatmap-counties,
.moth-heatmap-species {
    min-height: 60px !important;
    max-height: 120px;
    overflow-y: auto;
}

.moth-heatmap-counties option,
.moth-heatmap-species option {
    padding: 4px 8px;
    cursor: pointer;
}

.moth-heatmap-counties option:hover,
.moth-heatmap-species option:hover {
    background-color: #f0f0f0;
}

.moth-heatmap-counties option:checked,
.moth-heatmap-species option:checked {
    background-color: #007cba;
    color: white;
}

/* Enhanced tooltips */
.moth-heatmap-hover-tooltip {
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    color: white;
    padding: 12px;
    border-radius: 4px;
    font-size: 12px;
    font-family:
        "IBM Plex Sans",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
    max-width: 200px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 1000;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.hover-tooltip-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.hover-site-info strong,
.hover-heatmap-info strong {
    color: #ffffff;
    font-weight: 600;
    font-size: 13px;
}

.hover-coords {
    color: #cccccc;
    font-size: 11px;
    font-family: monospace;
}

.hover-moth-count {
    color: #ffd700;
    font-size: 13px;
    font-weight: 600;
}

.hover-hint {
    color: #aaaaaa;
    font-size: 10px;
    font-style: italic;
    margin-top: 4px;
}

.hover-tooltip-content.heatmap {
    color: #ffffff;
}

.hover-tooltip-content.heatmap .hover-hint {
    color: #ffcc00;
}

/* Enhanced marker info windows */
.marker-info.enhanced {
    min-width: 280px;
    max-width: 350px;
    font-family:
        "IBM Plex Sans",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
    line-height: 1.4;
}

.marker-info.enhanced h4 {
    margin: 0 0 12px 0;
    color: #2c3e50;
    font-size: 16px;
    font-weight: 600;
    border-bottom: 2px solid #3498db;
    padding-bottom: 8px;
}

.marker-info.enhanced .site-location {
    margin-bottom: 12px;
    color: #555;
    font-size: 12px;
}

.marker-info.enhanced .site-location strong {
    color: #2c3e50;
}

.marker-info.enhanced .site-stats {
    margin-bottom: 12px;
    background: #f8f9fa;
    padding: 10px;
    border-radius: 6px;
}

.marker-info.enhanced .stat-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.marker-info.enhanced .stat-row:last-child {
    margin-bottom: 0;
}

.marker-info.enhanced .stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}

.marker-info.enhanced .stat-item label {
    font-size: 11px;
    color: #666;
    margin-bottom: 2px;
    font-weight: 500;
}

.marker-info.enhanced .stat-value {
    font-size: 14px;
    font-weight: 600;
    color: #2c3e50;
}

.marker-info.enhanced .date-range {
    margin-bottom: 12px;
    font-size: 12px;
    color: #555;
    background: #e8f4f8;
    padding: 8px;
    border-radius: 4px;
}

.marker-info.enhanced .date-range strong {
    color: #2c3e50;
}

.marker-info.enhanced .collectors-info {
    margin-bottom: 12px;
    font-size: 12px;
    color: #555;
}

.marker-info.enhanced .collectors-info strong {
    color: #2c3e50;
}

.marker-info.enhanced .top-species {
    background: #fff3cd;
    padding: 10px;
    border-radius: 6px;
    border-left: 4px solid #ffc107;
}

.marker-info.enhanced .top-species strong {
    color: #856404;
    font-size: 13px;
}

.marker-info.enhanced .top-species ul {
    margin: 8px 0 0 0;
    padding: 0;
    list-style: none;
}

.marker-info.enhanced .top-species li {
    padding: 4px 0;
    font-size: 12px;
    color: #856404;
    border-bottom: 1px solid rgba(255, 193, 7, 0.2);
}

.marker-info.enhanced .top-species li:last-child {
    border-bottom: none;
}

/* Loading state for enhanced tooltips */
.marker-info.loading {
    min-width: 200px;
    text-align: center;
    padding: 20px;
}

.marker-info.loading .loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 10px;
}

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

/* Basic fallback marker info */
.marker-info.basic {
    min-width: 200px;
    font-family:
        "IBM Plex Sans",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
}

.marker-info.basic h4 {
    margin: 0 0 8px 0;
    color: #2c3e50;
    font-size: 14px;
    font-weight: 600;
}

.marker-info.basic p {
    margin: 4px 0;
    font-size: 12px;
    line-height: 1.4;
}

.marker-info.basic strong {
    color: #34495e;
    font-weight: 600;
}

/* Modal styles for site details */
.moth-heatmap-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: var(--moth-modal-background-color, rgba(0, 0, 0, 0.5));
    backdrop-filter: blur(var(--moth-modal-backdrop-blur, 3px));
    animation: fadeIn 0.3s ease-in-out;
}

.moth-heatmap-modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

.moth-heatmap-modal-content {
    background: white;
    border-radius: var(--moth-modal-border-radius, 4px);
    box-shadow: var(--moth-modal-box-shadow, 0 10px 30px rgba(0, 0, 0, 0.3));
    max-width: var(--moth-modal-max-width, 600px);
    width: var(--moth-modal-width, 90%);
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    animation: slideIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.moth-heatmap-modal-header {
    padding: var(--moth-modal-header-padding, 20px 20px 15px);
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--moth-modal-header-background, linear-gradient(135deg, #668839, #86a482));
    color: var(--moth-modal-header-text-color, white);
    border-radius: var(--moth-modal-border-radius, 4px) var(--moth-modal-border-radius, 4px) 0 0;
}

.moth-heatmap-modal-header h2 {
    margin: 0;
    font-size: var(--moth-modal-header-title-font-size, 1.3em);
    font-weight: 600;
}

.moth-heatmap-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: white;
    padding: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.moth-heatmap-modal-close:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.moth-heatmap-modal-body {
    padding: var(--moth-modal-body-padding, 20px);
    background-color: var(--moth-modal-body-background-color, white);
}

.modal-site-location {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 4px;
    margin-bottom: 20px;
    font-size: 14px;
    line-height: 1.4;
}

.modal-site-location strong {
    color: #2c3e50;
    display: inline-block;
    min-width: 80px;
}

.modal-site-stats {
    margin-bottom: 20px;
}

.modal-stat-row {
    display: grid;
    grid-template-columns: repeat(var(--moth-modal-stats-grid-columns, 4), 1fr);
    gap: 12px;
    margin-bottom: 15px;
}

.modal-stat-item {
    background: var(--moth-modal-stats-item-background, rgba(255, 255, 255, 0.6));
    backdrop-filter: blur(10px);
    padding: 10px 8px;
    border-radius: 4px;
    text-align: center;
    border: var(--moth-modal-stats-item-border, 1px solid rgba(102, 136, 57, 0.2));
    min-width: 0;
}

.modal-stat-item label {
    display: block;
    font-size: 10px;
    color: var(--moth-modal-stats-label-color, #668839);
    margin-bottom: 4px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modal-stat-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--moth-modal-stats-value-color, #333);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Date and Collectors combined container */
.modal-date-collectors {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.modal-date-range {
    background: rgba(232, 245, 232, 0.8);
    backdrop-filter: blur(10px);
    padding: 12px;
    border-radius: 4px;
    border: 1px solid rgba(102, 136, 57, 0.3);
    font-size: 12px;
    line-height: 1.4;
}

.modal-date-range strong {
    color: #668839;
    display: inline;
    margin-right: 6px;
    font-size: 12px;
    font-weight: 600;
}

.modal-collectors-info {
    background: rgba(255, 243, 205, 0.8);
    backdrop-filter: blur(10px);
    padding: 12px;
    border-radius: 4px;
    border: 1px solid rgba(102, 136, 57, 0.3);
    font-size: 12px;
    line-height: 1.4;
}

.modal-collectors-info strong {
    color: #668839;
    display: inline;
    margin-right: 6px;
    font-size: 12px;
    font-weight: 600;
}

.modal-top-species {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 4px;
    border-left: 4px solid #6f42c1;
}

.modal-top-species strong {
    color: #6f42c1;
    display: block;
    margin-bottom: 10px;
}

.modal-top-species ul {
    margin: 0;
    padding-left: 0;
    list-style: none;
}

.modal-top-species li {
    padding: 8px 0;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-top-species li:last-child {
    border-bottom: none;
}

.modal-species-name {
    font-weight: 500;
    color: #2c3e50;
}

.modal-species-count {
    background: #668839;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}

.modal-loading {
    text-align: center;
    padding: 40px 20px;
}

.modal-loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

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

/* Responsive design for modal */
@media (max-width: 768px) {
    .moth-heatmap-modal-content {
        width: 95%;
        max-height: 82dvh;
    }

    .moth-heatmap-modal-header {
        padding: 15px;
    }

    .moth-heatmap-modal-header h2 {
        font-size: 1.1em;
    }

    .moth-heatmap-modal-body {
        padding: 15px;
    }

    .modal-stat-row {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .modal-stat-item {
        padding: 8px 6px;
    }

    .modal-stat-item label {
        font-size: 10px;
    }

    .modal-stat-value {
        font-size: 13px;
    }

    .modal-date-collectors {
        grid-template-columns: 2fr 2fr;
        gap: 8px;
    }

    .modal-date-range,
    .modal-collectors-info {
        font-size: 11px;
        padding: 10px;
    }

    .modal-date-range strong,
    .modal-collectors-info strong {
        font-size: 11px;
    }

    /* Chart responsive adjustments */
    .modal-chart-section {
        margin: 15px 0;
        padding: 12px;
    }

    .modal-chart-container {
        padding: 12px;
        min-height: 250px;
    }

    .modal-chart-header strong {
        font-size: 13px;
    }

    .modal-chart-loading {
        font-size: 11px;
        padding: 15px;
    }

    /* Info sections container - horizontal flex for desktop, vertical for mobile */
    .moth-heatmap-info-sections {
        display: flex;
        flex-direction: column-reverse;
        gap: 20px;
        margin-top: 20px;
        align-items: flex-start;
        flex-wrap: wrap;
    }
}

@media (max-width: 480px) {
    .modal-stat-row {
        grid-template-columns: 2fr 2fr;
        gap: 6px;
    }

    .modal-stat-item {
        padding: 8px;
    }

    .modal-stat-item label {
        font-size: 11px;
    }

    .modal-stat-value {
        font-size: 13px;
    }

    .modal-date-range,
    .modal-collectors-info {
        font-size: 10px;
        padding: 8px;
    }

    .modal-date-range strong,
    .modal-collectors-info strong {
        font-size: 10px;
    }

    /* Chart adjustments for very small screens */
    .modal-chart-section {
        margin: 10px 0;
        padding: 8px;
    }

    .modal-chart-container {
        padding: 8px;
        min-height: 200px;
    }

    .modal-chart-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .modal-chart-header strong {
        font-size: 12px;
    }

    .modal-chart-loading {
        font-size: 10px;
        padding: 10px;
    }
}

/* Modal chart section styles - Consolidated and improved */
.modal-chart-section {
    margin: 20px 0;
    padding: 16px;
    background: rgba(102, 136, 57, 0.03);
    border-radius: 8px;
    border: 1px solid rgba(102, 136, 57, 0.1);
    position: relative;
    z-index: 1;
}

.modal-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.modal-chart-header strong {
    font-size: 14px;
    color: #668839;
    font-weight: 500;
    font-family:
        "IBM Plex Sans",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
}

.modal-chart-loading {
    font-size: 12px;
    color: #888;
    font-style: italic;
    font-family:
        "IBM Plex Sans",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
    text-align: center;
    padding: 20px;
}

.modal-chart-container {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    padding: 16px;
    box-shadow: inset 0 1px 3px rgba(102, 136, 57, 0.1);
    position: relative;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-chart-container canvas {
    border-radius: 6px;
    max-width: 100%;
    height: auto !important;
    font-family:
        "IBM Plex Sans",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
}

.moth-heatmap-charts h4 {
    margin: 0 0 12px 0;
    color: #668839;
    font-size: 15px;
    font-weight: 500;
    letter-spacing: 0.01em;
    font-family:
        "IBM Plex Sans",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
}

.charts-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.charts-subtitle {
    font-size: 12px;
    color: rgba(102, 136, 57, 0.8);
    font-family:
        "IBM Plex Sans",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
    font-weight: 400;
    line-height: 1.4;
}

.charts-county-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 240px;
    overflow-y: auto;
    padding-right: 4px;
    cursor: auto;
}

/* Custom scrollbar for county list */
.charts-county-list::-webkit-scrollbar {
    width: 4px;
}

.charts-county-list::-webkit-scrollbar-track {
    background: rgba(102, 136, 57, 0.05);
    border-radius: 2px;
}

.charts-county-list::-webkit-scrollbar-thumb {
    background: rgba(102, 136, 57, 0.3);
    border-radius: 2px;
}

.charts-county-list::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 136, 57, 0.5);
}

.county-chart-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(102, 136, 57, 0.1);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    font-family:
        "IBM Plex Sans",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
    text-align: left;
    width: 100%;
    backdrop-filter: blur(10px);
}

.county-chart-btn:hover {
    background: rgba(102, 136, 57, 0.08);
    border-color: rgba(102, 136, 57, 0.2);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(102, 136, 57, 0.15);
}

.county-chart-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(102, 136, 57, 0.2);
}

.county-chart-btn:focus {
    outline: none;
    border-color: rgba(102, 136, 57, 0.4);
    box-shadow: 0 0 0 3px rgba(102, 136, 57, 0.15);
}

.county-name {
    font-weight: 500;
    color: #668839;
    font-size: 13px;
    letter-spacing: 0.1em;
}

.county-stats {
    font-size: 11px;
    color: rgba(102, 136, 57, 0.7);
    font-weight: 400;
    white-space: nowrap;
}

/* Modal content styling for county details */
.modal-trap-sites {
    margin-top: 12px;
    padding: 12px;
    background: rgba(102, 136, 57, 0.05);
    border-radius: 4px;
    border-left: 3px solid #668839;
}

.modal-trap-sites strong {
    color: #668839;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    display: block;
}

.modal-sites-list {
    font-size: 12px;
    color: #555;
    line-height: 1.4;
    font-weight: 400;
}

.modal-date-collectors {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 12px 0;
    padding: 10px;
    background: rgba(102, 136, 57, 0.03);
    border-radius: 6px;
    border: 1px solid rgba(102, 136, 57, 0.1);
}

.modal-date-range,
.modal-collectors-info {
    font-size: 12px;
    color: #555;
    line-height: 1.4;
}

.modal-date-range strong,
.modal-collectors-info strong {
    color: #668839;
    font-weight: 600;
}

/* Top species styling */
.modal-top-species {
    margin-top: 12px;
    padding: 12px;
    background: rgba(255, 193, 7, 0.1);
    border-radius: 4px;
    border-left: 3px solid #ffc107;
}

.modal-top-species strong {
    color: #856404;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
    display: block;
}

.modal-top-species ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.modal-top-species li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 12px;
    border-bottom: 1px solid rgba(255, 193, 7, 0.2);
}

.modal-top-species li:last-child {
    border-bottom: none;
}

.modal-species-name {
    color: #856404;
    font-weight: 500;
    flex: 1;
}

.modal-species-count {
    color: #856404;
    font-weight: 600;
    font-size: 11px;
    background: rgba(255, 193, 7, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
}

/* Site stats styling */
.modal-site-stats {
    margin: 12px 0;
    padding: 12px;
    background: rgba(102, 136, 57, 0.08);
    border-radius: 4px;
}

.modal-stat-row {
    justify-content: space-between;
    gap: 12px;
}

.modal-stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    text-align: center;
}

.modal-stat-item label {
    font-size: 11px;
    color: rgba(102, 136, 57, 0.8);
    margin-bottom: 4px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-stat-value {
    font-size: 13px;
    font-weight: 600;
    color: #668839;
    font-family:
        "IBM Plex Sans",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
}

/* Site location styling */
.modal-site-location {
    margin-bottom: 12px;
    padding: 10px;
    background: rgba(102, 136, 57, 0.05);
    border-radius: 6px;
    font-size: 12px;
    color: #555;
    line-height: 1.4;
}

.modal-site-location strong {
    color: #668839;
    font-weight: 600;
}

/* Info sections container - horizontal flex for desktop, vertical for mobile */
.moth-heatmap-info-sections {
    display: flex;
    flex-direction: row;
    gap: 20px;
    margin-top: 20px;
    align-items: flex-start;
    flex-wrap: wrap;
}

/* Legend - Apple-style modern design */
.moth-heatmap-legend {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(102, 136, 57, 0.08);
    border-radius: 4px;
    padding: 20px;
    box-shadow:
        0 8px 32px rgba(102, 136, 57, 0.08),
        0 1px 2px rgba(0, 0, 0, 0.04);
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    flex: 1;

    width: 100%;
    position: relative;
    overflow: hidden;
}

.moth-heatmap-legend:hover {
    transform: translateY(-2px);
    box-shadow:
        0 12px 40px rgba(102, 136, 57, 0.12),
        0 2px 6px rgba(0, 0, 0, 0.08);
}

/* Charts section - Apple-style modern design */
.moth-heatmap-charts {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(102, 136, 57, 0.08);
    border-radius: 4px;
    padding: 20px;
    box-shadow:
        0 8px 32px rgba(102, 136, 57, 0.08),
        0 1px 2px rgba(0, 0, 0, 0.04);
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    flex: 1;

    width: 100%;
    position: relative;
    overflow: hidden;
}

.moth-heatmap-charts:hover {
    transform: translateY(-2px);
    box-shadow:
        0 12px 40px rgba(102, 136, 57, 0.12),
        0 2px 6px rgba(0, 0, 0, 0.08);
}

/* Notification System */
.moth-heatmap-notifications {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    max-width: 90%;
    width: auto;
    min-width: 300px;
    pointer-events: none; /* Allow map interaction behind notifications */
}

.moth-heatmap-notification {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    margin-bottom: 8px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.3s ease;
    pointer-events: auto; /* Re-enable pointer events for notifications */
    max-width: 500px;
    word-wrap: break-word;
}

.moth-heatmap-notification.notification-visible {
    opacity: 1;
    transform: translateY(0);
}

/* Notification type styles */
.moth-heatmap-notification.notification-info {
    background-color: #d1ecf1;
    border: 1px solid #bee5eb;
    color: #0c5460;
}

.moth-heatmap-notification.notification-warning {
    background-color: #fff3cd;
    border: 1px solid #ffeaa7;
    color: #856404;
}

.moth-heatmap-notification.notification-error {
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

.moth-heatmap-notification.notification-critical {
    background-color: #f5c6cb;
    border: 2px solid #dc3545;
    color: #721c24;
    font-weight: 600;
}

/* Notification content */
.moth-heatmap-notification .notification-content {
    flex: 1;
    margin-right: 12px;
}

/* Close button */
.moth-heatmap-notification .notification-close {
    background: none;
    border: none;
    font-size: 18px;
    font-weight: bold;
    color: inherit;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
}

.moth-heatmap-notification .notification-close:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

.moth-heatmap-notification .notification-close:focus {
    outline: 2px solid rgba(0, 0, 0, 0.3);
    outline-offset: 2px;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .moth-heatmap-notifications {
        max-width: 95%;
        min-width: 280px;
        top: 5px;
    }

    .moth-heatmap-notification {
        padding: 10px 12px;
        font-size: 13px;
    }

    .moth-heatmap-notification .notification-content {
        margin-right: 8px;
    }
}

/* ===================================================================
   MULTI-MAP SUPPORT
   Styles to ensure multiple maps can coexist on the same page
   =================================================================== */

/* Namespace custom maps to prevent conflicts */
.moth-heatmap-container.custom-map {
    position: relative;
    isolation: isolate;
}

/* Ensure unique styling for each map instance */
.moth-heatmap-container.custom-map .moth-heatmap-canvas {
    position: relative;
    z-index: 1;
}

/* Prevent ID conflicts between multiple maps */
.moth-heatmap-container.custom-map [id] {
    /* IDs are already unique via uniqid() in PHP */
}

/* Ensure notifications don't overlap between maps */
.moth-heatmap-container.custom-map .moth-heatmap-notifications {
    position: absolute;
    z-index: 1000;
}

/* Custom map specific styles */
.moth-heatmap-container.custom-map .moth-heatmap-controls {
    /* Custom maps may have different control layouts */
    margin-bottom: 15px;
}

/* Legend positioning for multiple maps */
.moth-heatmap-container.custom-map .moth-heatmap-legend {
    position: relative;
    z-index: 10;
}

/* Loading spinner for custom maps */
.moth-heatmap-container.custom-map .loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
}

/* Ensure tooltips don't interfere between maps */
.moth-heatmap-container.custom-map .moth-heatmap-tooltip {
    position: absolute;
    z-index: 1001;
    pointer-events: none;
}

/* Custom map modals and overlays */
.moth-heatmap-container.custom-map .moth-heatmap-modal {
    position: fixed;
    z-index: 10000;
}

/* Charts and popups for custom maps */
.moth-heatmap-container.custom-map .moth-heatmap-chart-container {
    position: relative;
    z-index: 50;
}

/* Responsive adjustments for multiple maps */
@media (max-width: 768px) {
    .moth-heatmap-container.custom-map {
        margin-bottom: 20px;
    }
    
    .moth-heatmap-container.custom-map:last-child {
        margin-bottom: 0;
    }
}

/* Print styles for multiple maps */
@media print {
    .moth-heatmap-container.custom-map {
        page-break-inside: avoid;
        break-inside: avoid;
    }
    
    .moth-heatmap-container.custom-map + .moth-heatmap-container.custom-map {
        page-break-before: always;
        break-before: always;
    }
}
