/* MapLibre GIS Module CSS - Modern vector mapping styles */

/* Map Container */
#map {
    width: 100%;
    min-height: 400px !important;
    height: 400px !important;
    position: relative;
    background-color: var(--background-color);
    min-height: 400px; /* Ensure minimum height */
}

/* GIS Workspace */
#gis-workspace {
    position: relative;
    width: 100%;
    height: 100%;
    display: block; /* Changed from flex to block for proper map rendering */
}

/* Layer Panel */
#layer-panel {
    position: absolute;
    top: 80px;
    left: 16px;
    width: 280px;
    max-height: calc(100vh - 200px);
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-medium);
    z-index: 1000;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#layer-panel h3 {
    margin: 0;
    padding: 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    background-color: var(--hover-color);
    border-bottom: 1px solid var(--border-color);
}

#layer-controls {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    max-height: 400px;
}

/* Layer Category */
.layer-category {
    margin-bottom: 8px;
}

.layer-category h4 {
    margin: 16px 0 8px 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.layer-category:first-child h4 {
    margin-top: 0;
}

/* Layer Controls */
.layer-control {
    display: flex;
    align-items: center;
    padding: 6px 0;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-primary);
    transition: var(--transition);
    gap: 8px;
}

.layer-control:hover {
    background-color: var(--hover-color);
    border-radius: var(--radius-sm);
    padding-left: 4px;
    padding-right: 4px;
}

.layer-control input[type="checkbox"] {
    margin: 0;
    width: 14px;
    height: 14px;
    accent-color: var(--primary-color);
    cursor: pointer;
}

.layer-control span {
    flex: 1;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Layer Color Indicator */
.layer-color-indicator {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
    display: inline-block;
}

/* Legend Panel */
#legend-panel {
    position: absolute;
    bottom: 100px;
    left: 16px;
    width: 280px;
    max-height: 300px;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-medium);
    z-index: 1000;
    overflow: hidden;
}

#legend-panel h3 {
    margin: 0;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    background-color: var(--hover-color);
    border-bottom: 1px solid var(--border-color);
}

#legend-content {
    padding: 12px 16px;
    max-height: 200px;
    overflow-y: auto;
}

/* Legend Items */
.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    gap: 8px;
}

.legend-item:last-child {
    margin-bottom: 0;
}

.legend-symbol {
    flex-shrink: 0;
    display: block;
}

.legend-item span {
    font-size: 11px;
    color: var(--text-primary);
    line-height: 1.2;
}

/* MapLibre Controls Styling */
.maplibregl-ctrl-group {
    background-color: var(--surface-color) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-medium) !important;
}

.maplibregl-ctrl-group button {
    background-color: var(--surface-color) !important;
    color: var(--text-primary) !important;
    border: none !important;
    width: 32px !important;
    height: 32px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: var(--transition) !important;
}

.maplibregl-ctrl-group button:hover {
    background-color: var(--hover-color) !important;
}

.maplibregl-ctrl-group button:not(:last-child) {
    border-bottom: 1px solid var(--border-color) !important;
}

/* Attribution */
.maplibregl-ctrl-attrib {
    background-color: var(--surface-color) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-sm) !important;
    font-size: 10px !important;
    color: var(--text-secondary) !important;
}

.maplibregl-ctrl-attrib a {
    color: var(--primary-color) !important;
}

/* Scale Control */
.maplibregl-ctrl-scale {
    background-color: var(--surface-color) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-sm) !important;
    color: var(--text-primary) !important;
    font-size: 10px !important;
    padding: 2px 6px !important;
}

/* Popup Styling */
.maplibregl-popup {
    z-index: 2000;
}

.maplibregl-popup-content {
    background-color: var(--surface-color) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-heavy) !important;
    padding: 0 !important;
    max-width: 300px !important;
}

.popup-content {
    padding: 16px;
}

.popup-content h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: capitalize;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.popup-content p {
    margin: 0 0 6px 0;
    font-size: 12px;
    color: var(--text-primary);
    line-height: 1.4;
}

.popup-content p:last-child {
    margin-bottom: 0;
}

.popup-content strong {
    color: var(--text-primary);
    font-weight: 500;
}

.maplibregl-popup-close-button {
    background-color: transparent !important;
    border: none !important;
    color: var(--text-secondary) !important;
    font-size: 16px !important;
    padding: 4px 8px !important;
    cursor: pointer !important;
    transition: var(--transition) !important;
}

.maplibregl-popup-close-button:hover {
    color: var(--text-primary) !important;
    background-color: var(--hover-color) !important;
    border-radius: var(--radius-sm) !important;
}

.maplibregl-popup-tip {
    border-top-color: var(--surface-color) !important;
    border-bottom-color: var(--surface-color) !important;
}

/* Loading State */
.gis-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--surface-color);
    padding: 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-medium);
    border: 1px solid var(--border-color);
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-primary);
    font-size: 14px;
}

.gis-loading .spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Error State */
.gis-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--surface-color);
    padding: 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-medium);
    border: 1px solid #dc2626;
    z-index: 2000;
    max-width: 400px;
    text-align: center;
}

.gis-error h4 {
    color: #dc2626;
    margin: 0 0 8px 0;
    font-size: 14px;
}

.gis-error p {
    color: var(--text-secondary);
    margin: 0;
    font-size: 12px;
    line-height: 1.4;
}

/* Responsive Design */
@media (max-width: 768px) {
    #layer-panel,
    #legend-panel {
        width: calc(100vw - 32px);
        max-width: 320px;
    }
    
    #layer-panel {
        top: 60px;
        left: 16px;
        right: 16px;
        width: auto;
        max-height: 250px;
    }
    
    #legend-panel {
        bottom: 60px; /* Changed from 16px to 60px for better visibility */
        left: 16px;
        right: 16px;
        width: auto;
        max-height: 200px;
    }
    
    .layer-control {
        padding: 8px 0;
        font-size: 13px;
    }
    
    .maplibregl-popup-content {
        max-width: calc(100vw - 40px) !important;
    }
}

/* Dark Mode Adjustments */
[data-theme="dark"] .maplibregl-popup-content {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .maplibregl-ctrl-group button {
    filter: brightness(0.9);
}

/* Scrollbar Styling for Panels */
#layer-controls::-webkit-scrollbar,
#legend-content::-webkit-scrollbar {
    width: 4px;
}

#layer-controls::-webkit-scrollbar-track,
#legend-content::-webkit-scrollbar-track {
    background: var(--background-color);
}

#layer-controls::-webkit-scrollbar-thumb,
#legend-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

#layer-controls::-webkit-scrollbar-thumb:hover,
#legend-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Firefox scrollbar */
#layer-controls,
#legend-content {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--background-color);
}

/* Focus States */
.layer-control:focus-within {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Animation for panel show/hide */
.panel-slide-in {
    animation: slideIn 0.3s ease;
}

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

/* High contrast mode support */
@media (prefers-contrast: high) {
    #layer-panel,
    #legend-panel {
        border-width: 2px;
    }
    
    .layer-control {
        border: 1px solid transparent;
    }
    
    .layer-control:hover {
        border-color: var(--primary-color);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .layer-control,
    .maplibregl-ctrl-group button {
        transition: none;
    }
    
    .panel-slide-in {
        animation: none;
    }
}

/* Module Transition Support for MapLibre */
.module {
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

/* Ensure map renders correctly during transitions */
#gis-module.active #map {
    height: 100vh !important;
    min-height: 400px !important;
}
