/**
 * Peta Desa Styles
 * Responsive design with collapsible layer controls
 */

/* Container */
.statistik-desa-peta-container {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    border-radius: 16px;
    padding: 24px;
    margin: 20px 0;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

/* Header */
.peta-header {
    margin-bottom: 20px;
}

.peta-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.5rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0;
}

.peta-icon {
    width: 28px;
    height: 28px;
    color: #3b82f6;
}

/* Map Wrapper */
.peta-wrapper {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
    position: relative;
}

/* Layer Panel */
.peta-layer-panel {
    flex: 0 0 220px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    transition: all 0.3s ease;
}

/* Panel Toggle Button */
.layer-panel-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border: none;
    color: white;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.layer-panel-toggle:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
}

.toggle-icon svg {
    width: 18px;
    height: 18px;
}

.toggle-text {
    flex: 1;
    text-align: left;
}

.toggle-arrow {
    transition: transform 0.3s ease;
}

.toggle-arrow svg {
    width: 18px;
    height: 18px;
}

.layer-panel-toggle[aria-expanded="false"] .toggle-arrow {
    transform: rotate(-90deg);
}

/* Layer Controls */
.layer-controls {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: all 0.3s ease;
}

/* When panel is collapsed in desktop */
.peta-layer-panel.collapsed .layer-controls {
    display: none;
}

.layer-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    padding: 8px 10px;
    border-radius: 8px;
    transition: background 0.2s ease;
}

.layer-toggle:hover {
    background: #f1f5f9;
}

.layer-toggle input[type="checkbox"] {
    display: none;
}

.toggle-slider {
    position: relative;
    flex-shrink: 0;
    width: 36px;
    height: 20px;
    background: #cbd5e1;
    border-radius: 10px;
    transition: background 0.3s ease;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.layer-toggle input:checked+.toggle-slider {
    background: #3b82f6;
}

.layer-toggle input:checked+.toggle-slider::after {
    transform: translateX(16px);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: #475569;
    font-weight: 500;
}

/* Layer Icons */
.layer-icon {
    display: inline-block;
    flex-shrink: 0;
}

.layer-icon-line {
    width: 18px;
    height: 3px;
    background: #2563eb;
    border-radius: 2px;
}

.layer-icon-area {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    opacity: 0.7;
}

.layer-icon-marker {
    width: 10px;
    height: 10px;
    background: #3b82f6;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Map Container */
.peta-map-container {
    flex: 1;
    height: 500px;
    min-height: 400px;
    background: #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 1;
}

/* Mobile Layer Toggle - Removed, use dropdown layer peta instead */
.mobile-layer-toggle {
    display: none !important;
}

/* Loading State */
.peta-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.9);
    z-index: 10;
    /* Lower z-index to not block navbar */
    gap: 16px;
}

.peta-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.peta-loading span {
    font-size: 0.9rem;
    color: #64748b;
}

/* Error State */
.peta-error {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #ef4444;
    font-size: 1rem;
}

/* Legend */
.peta-legend {
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.peta-legend h4 {
    font-size: 0.9rem;
    font-weight: 600;
    color: #475569;
    margin: 0 0 12px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.legend-content {
    display: flex;
    flex-wrap: wrap;
    gap: 16px 24px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: #475569;
}

.legend-marker {
    width: 12px;
    height: 12px;
    background: #3b82f6;
    border-radius: 50%;
}

.legend-polygon {
    width: 16px;
    height: 12px;
    border-radius: 2px;
    opacity: 0.7;
}

.legend-line {
    width: 20px;
    height: 3px;
    border-radius: 2px;
}

/* Info Panel */
.peta-info-panel {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    margin-top: 16px;
    overflow: hidden;
}

.info-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
}

.info-header h4 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.info-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease;
}

.info-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.info-content {
    padding: 20px;
    color: #475569;
    line-height: 1.6;
}

.info-content p {
    margin: 0 0 12px 0;
}

.info-content p:last-child {
    margin-bottom: 0;
}

.info-foto {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin-top: 8px;
}

/* Custom Marker Icon */
.custom-marker-icon {
    background: transparent;
    border: none;
}

.marker-pin {
    width: 30px;
    height: 30px;
    border-radius: 50% 50% 50% 0;
    background: #3b82f6;
    position: absolute;
    transform: rotate(-45deg);
    left: 50%;
    top: 50%;
    margin: -15px 0 0 -15px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.marker-inner {
    width: 10px;
    height: 10px;
    background: white;
    border-radius: 50%;
    transform: rotate(45deg);
}

/* Popup Styles */
.peta-popup {
    min-width: 180px;
}

.popup-title {
    font-size: 1rem;
    font-weight: 600;
    color: #1e293b;
    margin: 0 0 8px 0;
}

.popup-category {
    font-size: 0.8rem;
    color: #64748b;
    margin: 0 0 6px 0;
}

.popup-desc {
    font-size: 0.8rem;
    color: #475569;
    margin: 0;
    line-height: 1.5;
}

/* ======================= */
/* RESPONSIVE STYLES       */
/* ======================= */

/* Tablet */
@media (max-width: 992px) {
    .statistik-desa-peta-container {
        padding: 20px;
    }

    .peta-layer-panel {
        flex: 0 0 200px;
    }

    .peta-map-container {
        height: 450px;
    }
}

/* Mobile */
@media (max-width: 768px) {
    .statistik-desa-peta-container {
        padding: 16px;
        border-radius: 12px;
    }

    .peta-header {
        margin-bottom: 16px;
    }

    .peta-title {
        font-size: 1.25rem;
    }

    .peta-wrapper {
        flex-direction: column;
    }

    /* Layer panel - start collapsed on mobile */
    .peta-layer-panel {
        position: relative;
        width: 100%;
        flex: none;
        max-height: 48px;
        overflow: hidden;
        margin-bottom: 10px;
        transition: max-height 0.3s ease, margin-bottom 0.3s ease;
        z-index: 1;
    }

    .peta-layer-panel .layer-controls {
        display: none;
    }

    /* When user clicks toggle header, expand it */
    .peta-layer-panel.mobile-visible {
        max-height: 400px;
        margin-bottom: 16px;
        z-index: 1;
    }

    .peta-layer-panel.mobile-visible .layer-controls {
        display: flex;
    }

    .peta-map-container {
        height: 400px;
        min-height: 350px;
    }

    .legend-content {
        flex-direction: column;
        gap: 8px;
    }

    .info-header {
        padding: 14px 16px;
    }

    .info-header h4 {
        font-size: 1rem;
    }

    .info-content {
        padding: 16px;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .statistik-desa-peta-container {
        padding: 12px;
        margin: 12px 0;
    }

    .peta-title {
        font-size: 1.1rem;
    }

    .peta-icon {
        width: 22px;
        height: 22px;
    }

    .peta-map-container {
        height: 350px;
        min-height: 300px;
    }

    .peta-layer-panel {
        width: 100%;
    }

    .layer-toggle {
        padding: 6px 8px;
    }

    .toggle-slider {
        width: 32px;
        height: 18px;
    }

    .toggle-slider::after {
        width: 14px;
        height: 14px;
    }

    .layer-toggle input:checked+.toggle-slider::after {
        transform: translateX(14px);
    }

    .toggle-label {
        font-size: 0.8rem;
    }

    .peta-legend {
        padding: 12px;
    }

    .peta-legend h4 {
        font-size: 0.8rem;
    }

    .legend-item {
        font-size: 0.75rem;
    }
}

/* Leaflet overrides */
.leaflet-container {
    font-family: inherit;
}

.leaflet-popup-content-wrapper {
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}

.leaflet-popup-content {
    margin: 12px 16px;
}

.leaflet-popup-tip {
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}

/* Improve touch targets on mobile */
@media (max-width: 768px) {
    .leaflet-control-zoom a {
        width: 36px !important;
        height: 36px !important;
        line-height: 36px !important;
        font-size: 18px !important;
    }
}

/* Layer control styling (map type selector) */
.leaflet-control-layers {
    border-radius: 8px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
    border: none !important;
}

.leaflet-control-layers-toggle {
    width: 44px !important;
    height: 44px !important;
    background-size: 26px 26px !important;
}

.leaflet-control-layers-expanded {
    padding: 10px 14px !important;
    background: white !important;
    min-width: 150px !important;
}

.leaflet-control-layers-base label {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    padding: 6px 4px !important;
    cursor: pointer !important;
    font-size: 0.9rem !important;
    font-weight: 500 !important;
    color: #475569 !important;
}

.leaflet-control-layers-base label:hover {
    background: #f1f5f9 !important;
    border-radius: 6px !important;
}

.leaflet-control-layers-selector {
    margin-right: 6px !important;
}

@media (max-width: 768px) {
    .leaflet-control-layers {
        margin-right: 10px !important;
        margin-top: 10px !important;
    }

    .leaflet-control-layers-toggle {
        width: 44px !important;
        height: 44px !important;
    }

    .leaflet-control-layers-expanded {
        max-width: 200px !important;
    }

    /* Disable layer control on mobile - not working properly */
    .leaflet-control-layers {
        display: none !important;
    }
}

/* Dusun Label Styles */
.dusun-label {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

.dusun-label-text {
    background: transparent;
    color: #1e293b;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    border: none;
    box-shadow: none;
    pointer-events: none;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.8);
}