/* =======================
   GLOBAL STYLES & RESET
   ======================= */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    overflow: hidden;
    position: relative;
}


/* Animated Background Pattern */

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 20% 50%, rgba(255, 255, 255, 0.1) 2px, transparent 2px), radial-gradient(circle at 80% 50%, rgba(255, 255, 255, 0.1) 1px, transparent 1px);
    background-size: 100px 100px;
    pointer-events: none;
    z-index: 1;
    opacity: 0.5;
}


/* =======================
   MAIN LAYOUT
   ======================= */

.container {
    display: flex;
    height: 100vh;
    position: relative;
    z-index: 2;
}


/* =======================
   SIDEBAR STYLES
   ======================= */

.sidebar {
    width: 350px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-right: 1px solid rgba(255, 255, 255, 0.2);
    padding: 20px;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.sidebar.collapsed {
    transform: translateX(-100%);
}


/* Sidebar Header */

.header {
    color: white;
    margin-bottom: 30px;
}

.header h1 {
    font-size: 24px;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.header p {
    font-size: 14px;
    opacity: 0.8;
}


/* =======================
   STATISTICS GRID
   ======================= */

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 30px;
}

.stat-card {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 15px;
    text-align: center;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    background: rgba(255, 255, 255, 0.25);
}

.stat-card .number {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 5px;
}

.stat-card .label {
    font-size: 12px;
    opacity: 0.8;
}


/* =======================
   SECTION COMPONENTS
   ======================= */

.section {
    margin-bottom: 25px;
}

.section-title {
    color: white;
    font-size: 16px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}


/* =======================
   LAYER CONTROLS
   ======================= */

.layer-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.layer-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 12px;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
}

.layer-item:hover {
    background: rgba(255, 255, 255, 0.2);
}

.layer-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.layer-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}


/* Toggle Switch */

.toggle-switch {
    position: relative;
    width: 40px;
    height: 20px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.3s;
}

.toggle-switch.active {
    background: #4CAF50;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.toggle-switch.active::after {
    transform: translateX(20px);
}


/* =======================
   FILTER CONTROLS
   ======================= */

.filter-group {
    margin-bottom: 20px;
}

.filter-label {
    color: white;
    font-size: 14px;
    margin-bottom: 8px;
    display: block;
    font-weight: 500;
}

.filter-input {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.15);
    color: #222;
    font-size: 14px;
    transition: all 0.3s ease;
    border: 1px solid transparent;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

select.filter-input option {
    color: #222;
    background: #fff;
}

select.filter-input option:hover,
select.filter-input option:checked,
select.filter-input option[selected] {
    background: #e0f7fa;
    color: #00796b;
}

.filter-input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.filter-input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.2);
    border-color: #4CAF50;
}

.range-input {
    width: 100%;
    margin: 10px 0;
    -webkit-appearance: none;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.3);
    outline: none;
}

.range-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #4CAF50;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.range-input::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #4CAF50;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}


/* =======================
   CALCULATOR COMPONENT
   ======================= */

.calculator {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 15px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.calc-result {
    background: rgba(76, 175, 80, 0.2);
    border-radius: 8px;
    padding: 12px;
    margin-top: 10px;
    color: white;
    text-align: center;
    border: 1px solid rgba(76, 175, 80, 0.3);
    font-weight: 500;
}


/* =======================
   BUTTON STYLES
   ======================= */

.btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(45deg, #4CAF50, #45a049);
    color: white;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 10px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.4);
}

.btn-secondary {
    background: linear-gradient(45deg, #2196F3, #1976D2);
}

.btn-secondary:hover {
    box-shadow: 0 4px 15px rgba(33, 150, 243, 0.4);
}

.btn-tertiary {
    background: linear-gradient(45deg, #FF9800, #F57C00);
}

.btn-tertiary:hover {
    box-shadow: 0 4px 15px rgba(255, 152, 0, 0.4);
}

.btn-advanced {
    background: linear-gradient(45deg, #9C27B0, #7B1FA2);
    font-size: 12px;
    padding: 10px;
}

.btn-advanced:hover {
    box-shadow: 0 4px 15px rgba(156, 39, 176, 0.4);
}


/* =======================
   MAP CONTAINER
   ======================= */

.map-container {
    flex: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
}


/* =======================
   SIDEBAR TOGGLE
   ======================= */

.toggle-sidebar {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.3s;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.toggle-sidebar:hover {
    background: white;
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}


/* =======================
   SEARCH COMPONENT
   ======================= */

.search-container {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 1000;
    width: 350px;
}

.search-box {
    position: relative;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 25px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
}

.search-box:focus-within {
    box-shadow: 0 6px 30px rgba(0, 0, 0, 0.2);
    border-color: #4CAF50;
    transform: translateY(-2px);
}

.search-input {
    width: 100%;
    padding: 15px 50px 15px 50px;
    border: none;
    border-radius: 25px;
    font-size: 16px;
    background: transparent;
    color: #333;
    outline: none;
}

.search-input::placeholder {
    color: #666;
}

.search-icon {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    color: #666;
    font-size: 16px;
    transition: color 0.3s;
}

.search-box:focus-within .search-icon {
    color: #4CAF50;
}

.clear-search {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 16px;
    padding: 5px;
    border-radius: 50%;
    transition: all 0.2s;
}

.clear-search:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}


/* =======================
   SEARCH SUGGESTIONS
   ======================= */

.search-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    margin-top: 5px;
    max-height: 300px;
    overflow-y: auto;
    display: none;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.suggestion-item {
    padding: 12px 20px;
    cursor: pointer;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.suggestion-item:hover {
    background: rgba(76, 175, 80, 0.1);
    transform: translateX(5px);
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-icon {
    color: #4CAF50;
    font-size: 14px;
    width: 20px;
    text-align: center;
}

.suggestion-text {
    flex: 1;
}

.suggestion-type {
    font-size: 11px;
    color: #666;
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    font-weight: 500;
}


/* =======================
   ANALYSIS PANEL
   ======================= */

.analysis-panel {
    position: absolute;
    top: 80px;
    right: 20px;
    width: 300px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: none;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.analysis-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.analysis-title {
    font-weight: bold;
    color: #333;
    flex: 1;
    font-size: 16px;
}

.close-panel {
    background: none;
    border: none;
    font-size: 16px;
    color: #666;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: all 0.2s;
}

.close-panel:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}


/* Environmental Data Display */

.environmental-data {
    display: grid;
    gap: 10px;
    margin-bottom: 15px;
}

.env-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: rgba(76, 175, 80, 0.1);
    border-radius: 8px;
    font-size: 14px;
    border: 1px solid rgba(76, 175, 80, 0.2);
    transition: all 0.2s ease;
}

.env-item:hover {
    background: rgba(76, 175, 80, 0.15);
}

.env-label {
    color: #333;
    font-weight: 500;
}

.env-value {
    color: #4CAF50;
    font-weight: bold;
}


/* =======================
   LOADING INDICATORS
   ======================= */

.loading-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: #666;
    font-size: 14px;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-top: 2px solid #4CAF50;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 10px;
}


/* =======================
   STATUS BADGES
   ======================= */

.status-badge {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
}

.status-operational {
    background: #4CAF50;
    color: white;
}

.status-construction {
    background: #FF9800;
    color: white;
}

.status-planned {
    background: #2196F3;
    color: white;
}


/* =======================
   LEGEND COMPONENT
   ======================= */

.legend {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 15px;
    min-width: 200px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    z-index: 2000;
}

.legend-title {
    font-weight: bold;
    margin-bottom: 10px;
    color: #333;
    font-size: 14px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 12px;
    color: #555;
    transition: all 0.2s ease;
}

.legend-item:hover {
    color: #333;
    transform: translateX(3px);
}

.legend-marker {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}


/* =======================
   DATA SOURCE INDICATOR
   ======================= */

.data-source-indicator {
    position: absolute;
    bottom: 80px;
    left: 20px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    min-width: 200px;
    z-index: 1000;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.data-source-title {
    font-weight: bold;
    margin-bottom: 10px;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.data-source-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 5px;
    font-size: 12px;
    color: #555;
    padding: 3px 0;
}

.data-status {
    display: flex;
    align-items: center;
    gap: 5px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-online {
    background: #4CAF50;
    animation: pulse 2s infinite;
}

.status-offline {
    background: #F44336;
}

.status-loading {
    background: #FF9800;
    animation: blink 1s infinite;
}


/* =======================
   ANIMATIONS
   ======================= */

@keyframes pulse {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
    100% {
        opacity: 1;
    }
}

@keyframes blink {
    0%,
    50% {
        opacity: 1;
    }
    51%,
    100% {
        opacity: 0.3;
    }
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
}

@keyframes bounce {
    0%,
    20%,
    50%,
    80%,
    100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
}


/* =======================
   CUSTOM MAP MARKERS
   ======================= */

.custom-marker {
    transition: all 0.3s ease;
}

.custom-marker:hover {
    transform: scale(1.2);
}

.analysis-marker {
    animation: pulse 2s infinite;
}

.cluster-marker {
    animation: bounce 2s infinite;
}

.optimization-result-marker {
    transition: all 0.3s ease;
}

.optimization-result-marker:hover {
    transform: scale(1.1);
}


/* =======================
   LEAFLET MAP CUSTOMIZATIONS
   ======================= */

.leaflet-popup-content-wrapper {
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.leaflet-popup-content {
    margin: 0;
    line-height: 1.4;
}

.leaflet-popup-close-button {
    color: #666 !important;
    font-size: 18px !important;
    padding: 2px 6px !important;
}

.leaflet-control-zoom {
    border: none !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2) !important;
}

.leaflet-control-zoom a {
    background: rgba(255, 255, 255, 0.9) !important;
    border: none !important;
    color: #333 !important;
    transition: all 0.2s ease !important;
}

.leaflet-control-zoom a:hover {
    background: white !important;
    transform: scale(1.1) !important;
}


/* =======================
   RESPONSIVE DESIGN
   ======================= */

@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        z-index: 1001;
        height: 100%;
        width: 300px;
        box-shadow: 2px 0 15px rgba(0, 0, 0, 0.3);
    }
    .search-container {
        width: calc(100% - 100px);
        right: 20px;
    }
    .analysis-panel {
        width: calc(100% - 40px);
        right: 20px;
        top: 90px;
    }
    .legend {
        bottom: 10px;
        right: 10px;
        min-width: auto;
        font-size: 11px;
    }
    .data-source-indicator {
        bottom: 60px;
        left: 10px;
        min-width: 150px;
        font-size: 11px;
    }
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .header h1 {
        font-size: 20px;
    }
    .btn {
        padding: 10px;
        font-size: 12px;
    }
    .btn-advanced {
        font-size: 11px;
        padding: 8px;
    }
}

@media (max-width: 480px) {
    .sidebar {
        width: 280px;
        padding: 15px;
    }
    .search-container {
        width: calc(100% - 80px);
    }
    .toggle-sidebar {
        width: 45px;
        height: 45px;
        font-size: 16px;
    }
    .stats-grid {
        margin-bottom: 20px;
    }
    .stat-card {
        padding: 12px;
    }
    .stat-card .number {
        font-size: 20px;
    }
    .legend {
        display: none;
        /* Hide legend on very small screens */
    }
}


/* =======================
   ACCESSIBILITY FEATURES
   ======================= */

.btn:focus,
.filter-input:focus,
.search-input:focus,
.toggle-switch:focus {
    outline: 2px solid #4CAF50;
    outline-offset: 2px;
}

.toggle-switch:focus::after {
    box-shadow: 0 0 0 2px #4CAF50;
}


/* High contrast mode support */

@media (prefers-contrast: high) {
    .sidebar {
        background: rgba(0, 0, 0, 0.8);
        border-right: 2px solid white;
    }
    .stat-card,
    .layer-item,
    .calculator {
        background: rgba(255, 255, 255, 0.9);
        color: #000;
        border: 2px solid #333;
    }
    .btn {
        border: 2px solid white;
    }
}


/* Reduced motion support */

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .status-online,
    .status-loading,
    .analysis-marker,
    .cluster-marker {
        animation: none !important;
    }
}


/* =======================
   PRINT STYLES
   ======================= */

@media print {
    body {
        background: white;
    }
    .sidebar {
        position: static;
        width: 100%;
        background: white;
        color: black;
        padding: 20px;
    }
    .map-container {
        display: none;
    }
    .toggle-sidebar,
    .search-container,
    .analysis-panel,
    .data-source-indicator {
        display: none;
    }
    .btn {
        display: none;
    }
    .header h1 {
        color: black;
    }
    .stat-card {
        background: #f5f5f5;
        color: black;
        border: 1px solid #ddd;
    }
}