/* Loading overlay flex and text styles */
.loading-flex {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
}
.small-spinner {
    width: 20px;
    height: 20px;
    margin-right: 10px;
    margin-bottom: 0;
}
.loading-text {
    font-weight: bold;
    color: #007bff;
}

/* Panel fetch button full width and margin */
.panel-fetch-btn {
    margin-top: 8px;
    width: 100%;
}

/* Panel close button margin */
.panel-close-btn {
    margin: 10px;
}
/* Custom styles for the map and controls */
body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding: 0;
    position: relative;
}

#map {
    height: 100vh;
    width: 100%;
}

/* Fullscreen styles */
body.fullscreen {
    overflow: hidden;
}

body.fullscreen #map {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 999;
}

body.fullscreen .control-panel {
    z-index: 1001;
}

#fullscreen-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
}

#fullscreen-btn:hover {
    background-color: #007bff;
    color: white;
}

#fullscreen-icon {
    font-size: 16px;
    line-height: 1;
}

/* Desktop zoom control positioning - bottom left to avoid info overlay */
.leaflet-control-container .leaflet-bottom.leaflet-left {
    bottom: 20px;
    left: 20px;
}

.leaflet-control-zoom {
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    border: 1px solid #ccc;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    /* Show minimize button on mobile */
    .control-panel-header {
        display: flex !important;
    }

    .control-panel {
        top: 5px;
        right: 5px;
        left: 5px;
        max-width: none;
        padding: 0;
        font-size: 14px;
    }

    .control-panel.minimized {
        left: auto;
        right: 5px;
        width: auto;
        min-width: auto;
    }

    #controls {
        gap: 6px;
        padding: 12px;
    }

    .toggle-label {
        padding: 10px 8px;
        font-size: 16px;
        min-height: 44px; /* Touch-friendly */
        border: 2px solid #dee2e6; /* Thicker border for easier targeting */
    }

    .toggle-label:active {
        background-color: #f8f9fa;
        transform: scale(0.98);
    }

    .custom-control {
        padding: 12px 16px;
        font-size: 16px;
        min-height: 44px; /* Touch-friendly */
        width: 100%;
        border: 2px solid #ccc; /* Thicker border for easier targeting */
    }

    .custom-control:active {
        background-color: #e9ecef;
        transform: scale(0.98);
    }

    #data-selector {
        font-size: 16px;
        padding: 12px 10px;
        min-height: 44px; /* Touch-friendly */
        border: 2px solid #dee2e6;
    }

    /* Enhanced map interactions for mobile */
    .leaflet-container {
        -webkit-tap-highlight-color: transparent;
    }

    /* Hide zoom controls on mobile */
    .leaflet-control-zoom {
        display: none !important;
    }

    /* Better popup styling on mobile */
    .leaflet-popup-content {
        font-size: 16px !important;
        line-height: 1.4 !important;
        margin: 10px 12px !important;
    }

    .leaflet-popup-content h4 {
        font-size: 18px !important;
        margin-bottom: 8px !important;
    }

    /* Hide fullscreen text on very small screens */
    @media (max-width: 480px) {
        #fullscreen-text {
            display: none;
        }

        .control-panel {
            top: 2px;
            right: 2px;
            left: 2px;
            padding: 0;
        }

        .control-panel.minimized {
            left: auto;
            right: 2px;
            top: 2px;
        }

        #controls {
            gap: 4px;
            padding: 10px;
        }

        .minimize-btn {
            width: 36px;
            height: 36px;
            font-size: 20px;
        }
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .control-panel {
        top: 2px;
        right: 2px;
        max-height: calc(100vh - 4px);
        overflow-y: auto;
    }
}

/* High DPI screens */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .custom-control, .toggle-label {
        border-width: 1px; /* Thinner borders on high DPI to compensate */
    }
}

/* Control Panel Styles - Enhanced visibility */
.control-panel {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1000;
    background: white;
    padding: 0;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    border: 2px solid #007bff; /* Debug border */
    min-width: 200px;
    max-width: 300px;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    transition: all 0.3s ease;
}

.control-panel.minimized {
    min-width: auto;
    max-width: none;
    width: auto;
}

.control-panel-header {
    display: flex;
    justify-content: flex-end;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 6px 6px 0 0;
    border-bottom: 1px solid #dee2e6;
    display: none; /* Hidden by default on desktop */
}

.minimize-btn {
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 18px;
    font-weight: bold;
    line-height: 1;
}

.minimize-btn:hover {
    background: #e9ecef;
    border-color: #007bff;
}

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

#controls {
    display: flex !important;
    flex-direction: column;
    gap: 8px;
    visibility: visible !important;
    opacity: 1 !important;
    background: #f8f9fa; /* Debug background */
    padding: 15px;
    border-radius: 0 0 6px 6px;
    transition: all 0.3s ease;
}

.control-panel.minimized #controls {
    display: none !important;
}

.leaflet-control {
    display: flex;
    align-items: center;
    width: 100%;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    cursor: pointer;
    padding: 8px;
    width: 100%;
    background: white;
    border-radius: 4px;
    border: 1px solid #dee2e6;
    margin: 2px 0;
}

.toggle-label input[type="checkbox"] {
    margin: 0;
}

/* Make sure the data selector is visible */
#data-selector {
    width: 100%;
    margin-bottom: 8px;
    border: 2px solid #28a745; /* Debug border */
}

.info {
    padding: 6px 8px;
    font: 14px/16px Arial, Helvetica, sans-serif;
    background: white;
    background: rgba(255,255,255,0.8);
    box-shadow: 0 0 15px rgba(0,0,0,0.2);
    border-radius: 5px;
}

.info h4 {
    margin: 0 0 5px;
    color: #777;
}

.legend {
    line-height: 18px;
    color: #555;
}

.legend i {
    width: 18px;
    height: 18px;
    float: left;
    margin-right: 8px;
    opacity: 0.7;
}

.leaflet-control-container .leaflet-top.leaflet-right {
    display: flex;
    flex-direction: column;
    padding-top: 10px;
    padding-right: 10px;
    gap: 10px;
}

.leaflet-control-container .leaflet-top.leaflet-center {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    pointer-events: none;
}

.leaflet-control-container .leaflet-top.leaflet-center .leaflet-control {
    pointer-events: auto;
}

.custom-control {
    padding: 8px 12px;
    border-radius: 5px;
    border: 1px solid #ccc;
    background-color: white;
    font-family: 'Inter', sans-serif;
    box-shadow: 0 1px 5px rgba(0,0,0,0.65);
    cursor: pointer;
    width: 100%;
    text-align: center;
    font-size: 14px;
    margin: 2px 0;
}

.custom-control:hover {
    background-color: #f8f9fa;
    border-color: #007bff;
}

/* Optgroup styling for categorized dropdown */
#data-selector optgroup {
    font-weight: bold;
    font-size: 13px;
    color: #495057;
    background-color: #f8f9fa;
    padding: 4px 8px;
    margin-top: 2px;
}

#data-selector optgroup:first-of-type {
    margin-top: 0;
}

#data-selector option {
    font-weight: normal;
    font-size: 14px;
    color: #212529;
    padding: 6px 12px;
    background-color: white;
}

#data-selector option:hover {
    background-color: #e3f2fd;
}

/* Add some spacing between optgroups */
#data-selector {
    line-height: 1.4;
}

#manage-data-btn {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}

#fetch-all-btn {
    background-color: #17a2b8;
    color: white;
    border-color: #17a2b8;
}

#save-data-btn {
    background-color: #28a745;
    color: white;
    border-color: #28a745;
    font-weight: bold;
}

#data-manager-panel {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 320px;
    max-height: 80vh;
    overflow-y: auto;
    background: white;
    z-index: 1000;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    display: none; /* Hidden by default */
}

#data-manager-panel h3 {
    font-size: 1.2em;
    margin-top: 0;
}

.data-chunk {
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.data-chunk button {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
}

.data-chunk button:disabled {
    background-color: #ccc;
}

.status-loaded {
    color: green;
    font-weight: bold;
}

.status-not-loaded {
    color: #aaa;
}

.progress-container {
    width: 100%;
    background-color: #e0e0e0;
    border-radius: 4px;
    margin: 5px 0;
    height: 20px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background-color: #007bff;
    border-radius: 4px;
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 12px;
    font-weight: bold;
}

.loading-overlay {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 280px;
    background-color: rgba(255, 255, 255, 0.95);
    border: 2px solid #007bff;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 2000;
    display: none;
}

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

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

/* Emoji icon styles */
.emoji-icon {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
}

.emoji-icon div {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', sans-serif;
    text-shadow: 0 0 3px rgba(0,0,0,0.3);
    filter: drop-shadow(0 0 2px rgba(255,255,255,0.8));
}
