/* Reset dan Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        sans-serif;
    background: linear-gradient(135deg, #203484 0%, #1a2a6b 50%, #152153 100%);
    overflow: hidden;
    height: 100vh;
}

/* Sidebar Styles */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 360px;
    height: 100vh;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-right: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    transform: translateX(0);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
}

#sidebar.hide {
    transform: translateX(-100%);
}

#sidebar::-webkit-scrollbar {
    width: 4px;
}

#sidebar::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

#sidebar::-webkit-scrollbar-thumb {
    background: rgba(103, 126, 234, 0.5);
    border-radius: 4px;
}

.sidebar-header {
    background: linear-gradient(135deg, #203484 0%, #1a2a6b 50%, #152153 100%);
    padding: 24px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
}

.sidebar-header::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="2" fill="rgba(255,255,255,0.1)"/></svg>');
    background-size: 20px 20px;
    opacity: 0.3;
}

.sidebar-logo {
    max-width: 120px;
    height: auto;
    margin-bottom: 12px;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
    position: relative;
    z-index: 1;
}

.sidebar-title {
    color: white;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: 1;
}

/* Form Styles */
#sidebar .p-3 {
    padding: 32px 24px !important;
}

.form-label {
    color: #2d3748 !important;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 8px;
    letter-spacing: 0.02em;
}

.form-select {
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid rgba(103, 126, 234, 0.2);
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    color: #2d3748;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    margin-bottom: 20px;
}

.form-select:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(103, 126, 234, 0.1);
    background: white;
    outline: none;
}

.form-select:hover {
    border-color: rgba(103, 126, 234, 0.4);
}

.btn {
    font-weight: 600;
    padding: 12px 24px;
    border-radius: 12px;
    border: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 14px;
    letter-spacing: 0.02em;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.2),
        transparent
    );
    transition: left 0.5s;
}

.btn:hover::before {
    left: 100%;
}

.btn-success {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(72, 187, 120, 0.3);
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(72, 187, 120, 0.4);
}

/* Toggle Buttons */
.toggle-btn {
    position: fixed;
    z-index: 1001;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    padding: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

.toggle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.btn-show {
    top: 24px;
    left: 24px;
}

.btn-hide {
    top: 24px;
    left: 24px;
}

.toggle-hide {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toggle-hide .sidebar-logo {
    max-width: 24px;
    margin-bottom: 0;
}

.toggle-btn i {
    font-size: 20px;
    color: #667eea;
}

.hide {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-10px);
}

/* Map Styles */
#map {
    position: fixed;
    top: 0;
    left: 360px;
    width: calc(100% - 360px);
    height: 100vh;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
}

#map.fullscreen {
    left: 0;
    width: 100%;
}

/* Legend Toggle Buttons - Positioned di kiri bawah, diatas map */
#legend-toggle-buttons {
    position: fixed;
    bottom: 24px;
    left: 384px; /* 360px (sidebar width) + 24px margin */
    z-index: 1002; /* Higher than map, lower than sidebar */
    display: flex;
    flex-direction: column; /* Vertikal per baris */
    gap: 8px;
    pointer-events: auto;
    transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Adjust position when sidebar is hidden */
#map.fullscreen ~ #legend-toggle-buttons {
    left: 24px;
}

.legend-btn {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    color: #2d3748;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 180px;
    text-align: center;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.legend-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.legend-btn.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.legend-btn.btn-danger {
    background: linear-gradient(135deg, #f56565 0%, #e53e3e 100%);
    color: white;
}

.legend-btn.btn-success {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
}

.legend-btn.btn-warning {
    background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%);
    color: white;
}

/* Legend Styles */
#legend {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    max-width: 320px;
    max-height: 400px;
    overflow-y: auto;
}

#legend::-webkit-scrollbar {
    width: 4px;
}

#legend::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

#legend::-webkit-scrollbar-thumb {
    background: rgba(103, 126, 234, 0.5);
    border-radius: 4px;
}

.legend-background {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    visibility: hidden;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.legend-background.show {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
}

#kecamatan-legend-item-wrapper {
    max-height: 250px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 8px;
}

#kecamatan-legend-item-wrapper::-webkit-scrollbar {
    width: 4px;
}

#kecamatan-legend-item-wrapper::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

#kecamatan-legend-item-wrapper::-webkit-scrollbar-thumb {
    background: rgba(103, 126, 234, 0.5);
    border-radius: 2px;
}

.legend-background h4 {
    color: #2d3748;
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 16px;
    letter-spacing: -0.02em;
    border-bottom: 2px solid rgba(103, 126, 234, 0.2);
    padding-bottom: 8px;
}

/* Leaflet Control Layers Position Fix - Diatas kanan */
.leaflet-control-layers {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    z-index: 1001 !important;
}

.leaflet-top.leaflet-right {
    top: 24px !important;
    right: 24px !important;
}

/* Legend Background Show/Hide Fix */
.legend-background {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    display: none;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.legend-background.show {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.legend-item:last-child {
    border-bottom: none;
}

.legend-color-box {
    width: 20px;
    height: 20px;
    border-radius: 6px;
    border: 2px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.legend-label {
    font-size: 13px;
    font-weight: 500;
    color: #2d3748;
    line-height: 1.4;
    letter-spacing: 0.01em;
}

.marker-icon {
    width: 20px;
    height: 20px;
    object-fit: contain;
    flex-shrink: 0;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #667eea;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
}

/* Leaflet Customization */
.leaflet-popup-content-wrapper {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.leaflet-popup-tip {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
}

.leaflet-control-layers {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.leaflet-control-zoom {
    border: none;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.leaflet-control-zoom a {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #2d3748;
    font-weight: 600;
    transition: all 0.3s ease;
}

.leaflet-control-zoom a:hover {
    background: white;
    color: #667eea;
}

/* Responsive Design */
@media (max-width: 768px) {
    #sidebar {
        width: 100%;
        transform: translateX(-100%);
    }

    #sidebar.show-mobile {
        transform: translateX(0);
    }

    #map {
        left: 0;
        width: 100%;
    }

    #legend-toggle-buttons {
        bottom: 16px;
        left: 16px;
        gap: 6px;
    }

    .legend-btn {
        min-width: 140px;
        padding: 8px 12px;
        font-size: 12px;
    }

    #legend {
        bottom: 16px;
        right: 16px;
        max-width: 280px;
    }

    .sidebar-header {
        padding: 20px;
    }

    .sidebar-title {
        font-size: 20px;
    }

    .sidebar-logo {
        max-width: 70px;
    }

    #sidebar .p-3 {
        padding: 24px 20px !important;
    }

    .leaflet-top.leaflet-right {
        top: 16px !important;
        right: 16px !important;
    }
}

@media (max-width: 480px) {
    .toggle-btn {
        padding: 10px;
    }

    .btn-show,
    .btn-hide {
        top: 16px;
        left: 16px;
    }

    #legend-toggle-buttons {
        bottom: 12px;
        left: 12px;
        gap: 4px;
    }

    .legend-btn {
        min-width: 120px;
        padding: 6px 10px;
        font-size: 11px;
    }

    #legend {
        bottom: 12px;
        right: 12px;
        max-width: 240px;
    }

    .legend-background {
        padding: 16px;
    }

    .legend-background h4 {
        font-size: 14px;
    }

    .legend-label {
        font-size: 12px;
    }

    .sidebar-logo {
        max-width: 60px;
    }

    .leaflet-top.leaflet-right {
        top: 12px !important;
        right: 12px !important;
    }
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.legend-item {
    animation: fadeInUp 0.3s ease forwards;
}

.legend-item:nth-child(2) {
    animation-delay: 0.1s;
}
.legend-item:nth-child(3) {
    animation-delay: 0.2s;
}
.legend-item:nth-child(4) {
    animation-delay: 0.3s;
}
.legend-item:nth-child(5) {
    animation-delay: 0.4s;
}

/* Hover Effects */
.legend-item:hover {
    background: rgba(103, 126, 234, 0.05);
    border-radius: 8px;
    padding: 8px 12px;
    margin: 0 -12px;
    transition: all 0.3s ease;
}

/* Focus States */
.form-select:focus,
.btn:focus,
input[type="checkbox"]:focus {
    outline: 2px solid rgba(103, 126, 234, 0.5);
    outline-offset: 2px;
}

/* Loading State */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(103, 126, 234, 0.2);
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    transform: translate(-50%, -50%);
}

@keyframes spin {
    0% {
        transform: translate(-50%, -50%) rotate(0deg);
    }
    100% {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}
