* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    color: #333;
    overflow: hidden;
}

.app-container {
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
}

.app-header {
    background: linear-gradient(white 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#header {
    width: 100%;
    background-color: #FFFFFF;
    color: rgb(0, 0, 0);
    padding: 10px 20px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-title {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.5px;
}

#platformTitle {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#platformTitle span {
    display: inline-block;
    line-height: 1.2;
    font-weight: bold;
    font-size: 15px;
}

#logo {
    display: flex;
    align-items: center;
}

#logo img {
    height: 50px;
    vertical-align: middle;
    margin-right: 10px;
}

#logo div {
    display: flex;
    flex-direction: column;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#logo div span {
    display: inline-block;
    white-space: nowrap;
}

#logo div span:nth-of-type(1) {
    font-weight: bold;
    font-size: 15px;
}

#logo div span:nth-of-type(2) {
    font-weight: bold;
    font-size: 15px;
}

#right-header {
    background-color: #FFFFFF;
    color: rgb(0, 0, 0);
    padding: 10px 20px;
    box-sizing: border-box;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

#nav-menu a {
    color: rgb(73, 72, 75);
    text-decoration: none;
    margin: 0 7px;
    font-size: 12px;
}
#auth-buttons {
    display: flex;
    gap: 10px;
}
#auth-buttons a {
    color: rgb(73, 72, 75);
    text-decoration: none;
    padding: 5px 10px;
    font-size: 12px;
    border-radius: 5px;
    border: 2px solid rgb(73, 72, 75);
}
#auth-buttons a:hover {
    background-color: rgb(44, 125, 192);
    color: white;
}
#auth-buttons #signup-btn {
    background: #007bff;
    color: white;
}

.error-banner {
    background-color: #fee;
    border: 1px solid #fcc;
    color: #c33;
    padding: 12px 16px;
    text-align: center;
    font-size: 14px;
}

.main-content {
    display: flex;
    flex-direction: row;
    box-sizing: border-box;
    border-top: 3px solid #ddd;
    height: 100vh;
    transition: all 0.3s ease;
    position: relative;
}

.map-container {
    flex: 1;
    position: relative;
}

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

.filter-panel {
    position: absolute;
    top: 16px;
    left: 16px;
    background: white;
    padding: 0;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    min-width: 280px;
    max-width: 320px;
    max-height: calc(100vh - 140px);
    overflow: hidden;
    margin-top: 100px;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

.filter-panel::-webkit-scrollbar {
    width: 8px;
}

.filter-panel::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.filter-panel::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.filter-panel::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.filter-panel.collapsed {
    min-width: 60px;
    max-width: 60px;
    min-height: auto;
    max-height: none;
    padding: 8px;
    overflow: visible !important;
}

.filter-panel-header {
    display: flex;
    gap: 0;
    padding: 12px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
    border-radius: 8px 8px 0 0;
}

.filter-tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 16px;
    color: #6b7280;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}

.filter-tab-btn.active {
    color: #3b82f6;
    border-bottom-color: #3b82f6;
}

.filter-tab-btn:hover {
    color: #374151;
}

.filter-panel-toggle-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    transition: all 0.2s;
}

.filter-panel-toggle-btn:hover {
    color: #374151;
}

.filter-content,
.legend-content {
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
}

.filter-content::-webkit-scrollbar,
.legend-content::-webkit-scrollbar {
    width: 8px;
}

.filter-content::-webkit-scrollbar-track,
.legend-content::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.filter-content::-webkit-scrollbar-thumb,
.legend-content::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.filter-content::-webkit-scrollbar-thumb:hover,
.legend-content::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.filter-panel.collapsed .filter-panel-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0;
    border: none;
    background: transparent;
    width: 100%;
    height: auto;
}

.filter-panel.collapsed .filter-tab-btn {
    padding: 6px;
    font-size: 16px;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 4px;
    background: transparent;
    color: #6b7280;
    flex: none;
}

.filter-panel.collapsed .filter-tab-btn:hover,
.filter-panel.collapsed .filter-panel-toggle-btn:hover {
    background: #f3f4f6;
}

.filter-panel.collapsed .filter-panel-toggle-btn {
    display: flex;
    width: 44px;
    height: 44px;
    padding: 6px;
    margin-top: 8px;
    background: transparent;
    border-radius: 4px;
}

.filter-panel.collapsed .filter-content,
.filter-panel.collapsed .legend-content {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
}

.filter-content h3,
.legend-content h3 {
    margin-bottom: 16px;
    font-size: 18px;
    font-weight: 600;
}

/* Filter Summary Box */
.filter-summary-box {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: #fef3c7;
    border: 2px solid #fbbf24;
    border-radius: 6px;
    padding: 12px 16px;
    z-index: 999;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    max-width: 600px;
    width: auto;
}

#filterSummaryContent {
    font-size: 14px;
    font-weight: 600;
    color: #000;
    line-height: 1.5;
}

/* Legends Container */
#legendsContainer {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.legend-section {
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 16px;
}

.legend-section:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.legend-section-title {
    font-size: 15px;
    font-weight: 700;
    color: #1f2937;
    margin-bottom: 12px;
}

.legend-section-subtitle {
    font-size: 13px;
    font-weight: 400;
    color: #4b5563;
    margin-bottom: 8px;
}

.legend-item-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 13px;
}

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

.legend-color-box {
    width: 20px;
    height: 20px;
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.legend-color-circle {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.legend-item-label {
    color: #374151;
}

.legend-panel {
    display: none;
}

.filter-group {
    margin-bottom: 16px;
}

.filter-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: #555;
}

.filter-group select,
.filter-group input[type="range"] {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background: white;
}

.filter-group select:focus {
    outline: none;
    border-color: #3b82f6;
}

.filter-group input[type="range"] {
    padding: 0;
}

.btn-primary {
    width: 100%;
    padding: 10px 16px;
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-primary:active {
    background: #1d4ed8;
}

.legend-panel {
    position: absolute;
    bottom: 32px;
    right: 10px;
    background: white;
    padding: 16px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    max-width: 200px;transition: all 0.3s ease;
}

.legend-panel.collapsed {
    padding: 8px;
    max-width: 40px;
}

.legend-toggle-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
    z-index: 10;
}

.filter-panel.collapsed .legend-toggle-btn {
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -50%);
}

.legend-toggle-btn:hover {
    background: #f3f4f6;
}

.legend-content {
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.legend-content.hidden {
    opacity: 0;
    visibility: hidden;
    height: 0;
    overflow: hidden;
}

.legend-panel h4 {
    margin-bottom: 12px;
    font-size: 14px;
    font-weight: 600;
}

.legend-panel p {
    margin: 4px 0 12px 0;
    font-size: 11px;
    color: #666;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
    font-size: 13px;
}

.legend-color {
    width: 22px;
    height: 18px;
    margin-right: 8px;
    border: 1px solid #ccc;
    flex-shrink: 0;
    border-radius: 2px;
}

.control-btn {
    background: white;
    border: none;
    padding: 12px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-btn:hover {
    background: #f9fafb;
}

.basemap-selector {
    position: absolute;
    top: 80px;
    right: 16px;
    z-index: 1000;
}

.basemap-menu,
.layer-menu {
    position: absolute;
    top: 56px;
    right: 50px;
    background: white;
    padding: 16px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    min-width: 180px;
}

.basemap-menu h4,
.layer-menu h4 {
    margin-bottom: 12px;
    font-size: 14px;
    font-weight: 600;
}

.basemap-menu label,
.layer-menu label {
    display: flex;
    align-items: center;
    padding: 8px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 14px;
    transition: background 0.2s;
}

.basemap-menu label:hover,
.layer-menu label:hover {
    background: #f3f4f6;
}

.basemap-menu input,
.layer-menu input {
    margin-right: 8px;
    cursor: pointer;
}

.layer-toggle {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 1000;
}

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f4f6;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay p,
.loading-state p {
    margin-top: 12px;
    font-size: 16px;
    color: #666;
}

.chart-toggle {
    position: absolute;
    top: 144px;
    right: 16px;
    z-index: 1000;
}

.chart-overlay {
    position: absolute;
    top: 120px;
    right: 60px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    width: 500px;
    max-width: calc(100vw - 32px);
    transition: all 0.3s ease;
}

.chart-overlay.expanded {
    top: 16px;
    right: 16px;
    bottom: 16px;
    left: 16px;
    width: auto;
    max-width: none;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
    border-radius: 8px 8px 0 0;
}

.chart-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chart-controls {
    display: flex;
    gap: 8px;
}

.chart-control-btn {
    background: white;
    border: 1px solid #d1d5db;
    padding: 6px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-control-btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.chart-body {
    padding: 20px;
    max-height: 450px;
    overflow-y: auto;
}

.chart-overlay.expanded .chart-body {
    max-height: calc(100vh - 120px);
}

#epicurveChart {
    width: 100%;
    height: 350px;
}

.chart-overlay.expanded #epicurveChart {
    height: calc(100vh - 180px);
}

.download-menu {
    position: absolute;
    top: 120px;
    right: 80px;
    background: white;
    padding: 12px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    min-width: 150px;
    z-index: 1001;
}

.download-menu h4 {
    margin: 0 0 8px 0;
    font-size: 13px;
    font-weight: 600;
    color: #666;
}

.download-option {
    display: block;
    width: 100%;
    padding: 8px 12px;
    background: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
    border-radius: 4px;
    font-size: 14px;
    transition: background 0.2s;
}

.download-option:hover {
    background: #f3f4f6;
}

.leaflet-popup-content-wrapper {
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.leaflet-popup-content {
    margin: 16px;
    font-size: 14px;
    line-height: 1.6;
}

.leaflet-touch .leaflet-control-layers, .leaflet-touch .leaflet-bar {
    border: 0px solid rgba(0, 0, 0, 0.2);
    background-clip: padding-box;
    padding-top: 35px;
}

.leaflet-popup-content h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.leaflet-popup-content h4 {
    margin-bottom: 10px;
    color: #1a4789;
    border-bottom: 2px solid #1a4789;
    padding-bottom: 5px;
}

.leaflet-popup-content strong {
    color: #374151;
}

.leaflet-popup-content hr {
    margin: 8px 0;
    border: none;
    border-top: 1px solid #e5e7eb;
}

/* Popup styling */
.leaflet-popup-content table {
    width: 100%;
    margin-top: 10px;
    border-collapse: collapse;
}
.leaflet-popup-content th, .leaflet-popup-content td {
    padding: 4px 2px;
    border: 1px solid #ddd;
}
.leaflet-popup-content th {
    background-color: #f5f5f5;
    font-weight: 600;
    text-align: left;
}
.leaflet-popup-content tr:nth-child(even) {
    background-color: #f9f9f9;
}

@media (max-width: 1024px) {
    .filter-panel {
        min-width: 240px;
    }

    .chart-overlay {
        width: 400px;
    }
}

@media (max-width: 768px) {
    .filter-panel {
        min-width: auto;
        max-width: calc(100vw - 32px);
        max-height: calc(100vh - 120px);
        overflow-y: auto;
    }

    .chart-overlay {
        width: calc(100vw - 32px);
    }
}

/* Event Donut Chart Icons */
.event-donut-icon,
.event-circle-icon {
    background: transparent !important;
    border: none !important;
}

.event-donut-icon svg,
.event-circle-icon svg {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
    transition: transform 0.2s ease;
}

.event-donut-icon:hover svg,
.event-circle-icon:hover svg {
    transform: scale(1.1);
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

.leaflet-popup-content {
    margin: 0 !important;
}

.leaflet-popup-content-wrapper {
    padding: 0 !important;
    border-radius: 8px !important;
}

/* Marketplace Icons */
.marketplace-icon {
    background: transparent !important;
    border: none !important;
}

.marketplace-icon svg {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
    transition: transform 0.2s ease;
}

.marketplace-icon:hover svg {
    transform: scale(1.15);
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

/* Temperature Legend */
.temperature-legend {
    position: absolute;
    bottom: 260px;
    right: 10px;
    background: white;
    padding: 15px;
    padding-top: 35px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    min-width: 180px;
    max-width: 200px;
    cursor: move;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.temperature-legend.dragging {
    opacity: 0.8;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    cursor: grabbing;
}

.legend-drag-handle {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 28px;
    background: linear-gradient(to bottom, #f3f4f6, #e5e7eb);
    border-radius: 8px 8px 0 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    border-bottom: 1px solid #d1d5db;
}

.legend-drag-handle:active {
    cursor: grabbing;
}

.legend-drag-handle svg {
    color: #6b7280;
    opacity: 0.7;
}

.temperature-legend h4 {
    margin: 0 0 6px 0;
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
    border-bottom: 2px solid #e5e7eb;
    padding-bottom: 8px;
}

.temp-period {
    margin: 0 0 12px 0;
    font-size: 11px;
    color: #6b7280;
    font-weight: 500;
    text-align: center;
}

.temp-legend-scale {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.temp-legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.temp-color {
    width: 30px;
    height: 20px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.temp-label {
    font-size: 12px;
    color: #4b5563;
    font-weight: 500;
}

/* Responsive adjustments for temperature legend */
@media (max-width: 768px) {
    .temperature-legend {
        bottom: 240px;
        right: 10px;
        padding: 30px;
        min-width: 160px;
    }
    
    .temperature-legend h4 {
        font-size: 13px;
        margin-bottom: 10px;
    }
    
    .temp-label {
        font-size: 11px;
    }
    
    .temp-color {
        width: 25px;
        height: 18px;
    }
}

/* Reset button styling - matches control-btn */
.leaflet-control-reset {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: white;
    border: none;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: background 0.2s;
    text-decoration: none;
    color: #333;
}

.leaflet-control-reset:hover {
    background: #f9fafb;
}

.leaflet-control-reset svg {
    display: block;
    margin: auto;
}

/* Position reset button to the right of zoom controls */
.leaflet-control-custom {
    position: absolute !important;
    top: 10px !important;
    left: 50px !important;
    margin: 0 !important;
    border: none !important;
    box-shadow: none !important;
}

/* ========================================
   RESPONSIVE DESIGN - MOBILE & TABLET
   ======================================== */

/* Tablet (Portrait) - 768px and below */
@media (max-width: 768px) {
    /* Header adjustments */
    #header {
        flex-direction: column;
        padding: 10px;
        gap: 10px;
    }
    
    #logo {
        justify-content: center;
        width: 100%;
    }
    
    #logo img {
        height: 40px;
    }
    
    #logo div span {
        font-size: 12px !important;
    }
    
    #right-header {
        width: 100%;
        padding: 5px 0;
        flex-direction: column;
        gap: 10px;
    }
    
    #nav-menu {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px;
    }
    
    #nav-menu a {
        font-size: 11px;
        margin: 0 3px;
    }
    
    #auth-buttons {
        justify-content: center;
    }
    
    #auth-buttons a {
        font-size: 11px;
        padding: 4px 8px;
    }
    
    /* Filter panel - make collapsible and smaller */
    .filter-panel {
        top: 10px;
        left: 10px;
        right: auto;
        max-width: calc(100vw - 20px);
        width: auto;
        min-width: 200px;
        padding: 12px;
    }
    
    .filter-panel h3 {
        font-size: 14px;
    }
    
    .filter-group label {
        font-size: 12px;
    }
    
    .filter-group select {
        font-size: 12px;
        padding: 6px;
    }
    
    .btn-primary {
        font-size: 12px;
        padding: 8px 12px;
    }
    
    /* Legend panel - adjust position */
    .legend-panel {
        bottom: 10px;
        left: 10px;
        right: auto;
        padding: 10px;
        max-width: 180px;
    }
    
    .legend-panel h4 {
        font-size: 12px;
        margin-bottom: 8px;
    }
    
    .legend-item {
        font-size: 11px;
        margin-bottom: 4px;
    }
    
    .legend-color {
        width: 16px;
        height: 16px;
    }
    
    /* Control buttons - adjust positions */
    .basemap-selector {
        top: 10px;
        right: 10px;
    }
    
    .layer-toggle {
        top: 60px;
        right: 10px;
    }
    
    .chart-toggle {
        top: 110px;
        right: 10px;
    }
    
    .control-btn {
        width: 36px;
        height: 36px;
        padding: 8px;
    }
    
    .control-btn svg {
        width: 18px;
        height: 18px;
    }
    
    /* Menus - adjust for mobile */
    .basemap-menu,
    .layer-menu {
        right: 0;
        top: 46px;
        max-width: calc(100vw - 20px);
        padding: 12px;
    }
    
    .basemap-menu h4,
    .layer-menu h4 {
        font-size: 13px;
    }
    
    .basemap-menu label,
    .layer-menu label {
        font-size: 12px;
        padding: 6px 0;
    }
    
    /* Chart overlay - full width on mobile */
    .chart-overlay {
        top: 60px;
        right: 10px;
        left: 10px;
        width: auto;
    }
    
    .chart-overlay.minimized {
        width: auto;
        right: 10px;
    }
    
    /* Reset button - adjust size */
    .leaflet-control-reset {
        width: 36px;
        height: 36px;
    }
    
    .leaflet-control-reset svg {
        width: 18px;
        height: 18px;
    }
    
    .leaflet-control-custom {
        left: 46px !important;
    }
}

/* Mobile (Portrait) - 480px and below */
@media (max-width: 480px) {
    /* Header - more compact */
    #logo img {
        height: 35px;
    }
    
    #logo div span {
        font-size: 11px !important;
    }
    
    #nav-menu a {
        font-size: 10px;
        margin: 0 2px;
    }
    
    #auth-buttons a {
        font-size: 10px;
        padding: 3px 6px;
    }
    
    /* Filter panel - even more compact */
    .filter-panel {
        min-width: 180px;
        max-width: calc(100vw - 20px);
        padding: 10px;
        max-height: calc(100vh - 100px);
        overflow-y: auto;
    }
    
    .filter-panel h3 {
        font-size: 13px;
    }
    
    .filter-group label {
        font-size: 11px;
    }
    
    .filter-group select {
        font-size: 11px;
        padding: 5px;
    }
    
    .btn-primary {
        font-size: 11px;
        padding: 6px 10px;
    }
    
    /* Legend panel - smaller */
    .legend-panel {
        padding: 8px;
        max-width: 150px;
    }
    
    .legend-panel h4 {
        font-size: 11px;
        margin-bottom: 6px;
    }
    
    .legend-item {
        font-size: 10px;
        margin-bottom: 3px;
    }
    
    .legend-color {
        width: 14px;
        height: 14px;
    }
    
    /* Control buttons - smaller */
    .control-btn {
        width: 32px;
        height: 32px;
        padding: 6px;
    }
    
    .control-btn svg {
        width: 16px;
        height: 16px;
    }
    
    /* Reset button - smaller */
    .leaflet-control-reset {
        width: 32px;
        height: 32px;
    }
    
    .leaflet-control-reset svg {
        width: 16px;
        height: 16px;
    }
    
    .leaflet-control-custom {
        left: 42px !important;
    }
    
    /* Temperature legend - more compact */
    .temperature-legend {
        bottom: 220px;
        right: 8px;
        padding: 30px;
        min-width: 140px;
    }
    
    .temperature-legend h4 {
        font-size: 12px;
    }
    
    .temp-period {
        font-size: 10px;
    }
    
    .temp-label {
        font-size: 10px;
    }
    
    .temp-color {
        width: 20px;
        height: 15px;
    }
    
    /* Chart overlay - full screen on small mobile */
    .chart-overlay {
        top: 50px;
        right: 5px;
        left: 5px;
    }
    
    .chart-header {
        padding: 8px;
    }
    
    .chart-title {
        font-size: 13px;
    }
    
    .chart-control-btn {
        width: 28px;
        height: 28px;
        padding: 4px;
    }
    
    .chart-control-btn svg {
        width: 14px;
        height: 14px;
    }
}

/* Landscape mobile - 640px and below */
@media (max-width: 640px) and (orientation: landscape) {
    /* Header - single line in landscape */
    #header {
        flex-direction: row;
        padding: 5px 10px;
    }
    
    #logo {
        width: auto;
    }
    
    #logo img {
        height: 30px;
    }
    
    #logo div span {
        font-size: 10px !important;
    }
    
    #right-header {
        flex-direction: row;
        width: auto;
        padding: 0;
        gap: 10px;
    }
    
    #nav-menu {
        gap: 3px;
    }
    
    #nav-menu a {
        font-size: 9px;
        margin: 0 2px;
    }
    
    #auth-buttons a {
        font-size: 9px;
        padding: 3px 5px;
    }
    
    /* Filter panel - smaller in landscape */
    .filter-panel {
        top: 5px;
        left: 5px;
        padding: 8px;
        max-height: calc(100vh - 100px);
        overflow-y: auto;
    }
    
    /* Legend panel - bottom left corner */
    .legend-panel {
        bottom: 5px;
        left: 5px;
        padding: 6px;
    }
    
    /* Temperature legend - adjust position */
    .temperature-legend {
        bottom: 180px;
        right: 5px;
    }
}

/* Large tablets - 1024px and below */
@media (max-width: 1024px) and (min-width: 769px) {
    /* Slightly adjust control positions */
    .filter-panel {
        max-width: 280px;
    }
    
    .basemap-selector {
        top: 12px;
        right: 12px;
    }
    
    .layer-toggle {
        top: 70px;
        right: 12px;
    }
    
    .chart-toggle {
        top: 128px;
        right: 12px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Increase touch targets */
    .control-btn {
        min-width: 44px;
        min-height: 44px;
    }
    
    .leaflet-control-reset {
        min-width: 44px;
        min-height: 44px;
    }
    
    .filter-group select,
    .btn-primary {
        min-height: 44px;
    }
    
    /* Larger checkboxes and radio buttons */
    input[type="checkbox"],
    input[type="radio"] {
        width: 18px;
        height: 18px;
    }
    
    /* Prevent text selection on touch */
    .control-btn,
    .leaflet-control-reset,
    .legend-toggle-btn {
        -webkit-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
}

/* Print styles */
@media print {
    .filter-panel,
    .basemap-selector,
    .layer-toggle,
    .chart-toggle,
    .leaflet-control-zoom,
    .leaflet-control-custom {
        display: none !important;
    }
    
    #header {
        padding: 10px;
    }
    
    .main-content {
        height: auto;
    }
}

/* ===== SIDEBAR STYLES ===== */
.sidebar {
    width: 350px;
    background-color: white;
    color: rgb(44, 125, 192);
    height: 100%;
    padding: 0 4px 10px 10px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    border-right: 2px solid #ddd;
    transition: width 0.3s ease, padding 0.3s ease;
    position: relative;
    z-index: 900;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar.collapsed {
    width: 0;
    padding: 0;
    overflow: hidden;
}

.sidebar-toggle {
    position: fixed;
    left: 349px;
    top: 70px;
    width: 40px;
    height: 40px;
    background: white;
    border: 1px solid #ddd;
    border-left: none;
    border-radius: 0 4px 4px 0;
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: left 0.3s ease;
}

.sidebar.collapsed .sidebar-toggle {
    left: 0;
}

.sidebar-toggle:hover {
    background: #f8f9fa;
}

.sidebar-toggle i {
    transition: transform 0.3s ease;
}

.sidebar-menu {
    list-style-type: none;
    padding: 0;
    margin: 0;
    flex-grow: 1;
}

.sidebar-menu li {
    list-style: none;
    margin: 8px 0;
}

.bottom-line {
    border-bottom: 1px solid #ddd;
    padding-bottom: 10px;
    margin-bottom: 10px;
    max-height: 1000px;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.bottom-line.collapsed {
    max-height: 0;
    padding: 0;
    margin: 0;
    border-bottom: none;
}

.sidebar a {
    text-decoration: none;
}

.sidebar-menu > .bottom-line > li > a {
    color: #333;
    text-decoration: none;
    font-size: 18px;
    display: flex;
    width: 100%;
    align-items: center;
    padding: 6px 6px 6px 9px;
    border-radius: 5px;
}

.sidebar-menu > .bottom-line > li > a:hover,
.sidebar-menu > .bottom-line > li > a:focus,
.sidebar-menu > .bottom-line > li > a:active {
    background-color: rgb(44, 125, 192);
    color: white;
    margin-right: 20px;
}

.far-end {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 10px;
    border-radius: 5px;
}

.far-end:hover {
    background: #f8f9fa;
}

.far-end i {
    transition: transform 0.3s ease;
    color: rgb(44, 125, 192);
}

.sidebar-group.expanded .far-end i {
    transform: rotate(180deg);
}

.far-end a {
    color: rgb(54, 69, 79);
    font-size: 18px;
    display: flex;
    width: 100%;
    align-items: center;
}

.submenu {
    display: flex;
    align-items: center;
    border-radius: 1px;
    padding: 0 4px 0 4px;
    width: 100%;
}

.submenu i {
    margin-right: 10px;
    color: rgb(44, 125, 192);
    font-size: 12px;
}

.submenu a {
    color: rgb(54, 69, 79);
    text-decoration: none;
    font-size: 15px;
    display: flex;
    width: 100%;
    align-items: center;
    padding: 6px 6px 6px 0;
    border-radius: 5px;
}

.submenu a:hover,
.submenu a:focus,
.submenu a:active {
    background-color: rgb(44, 125, 192);
    color: white;
    margin-right: 20px;
}

.sidebar-group .bottom-line {
    display: block;
}

.download-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 10px 0 10px;
}

.download-buttons .btn {
    padding: 8px 12px;
    font-size: 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.download-buttons .btn-primary {
    background: #3b82f6;
    color: white;
}

.download-buttons .btn-primary:hover:not(:disabled) {
    background: #2563eb;
}

.download-buttons .btn:disabled {
    background: #d1d5db;
    color: #8b949e;
    cursor: not-allowed;
}

/* disabled / unfinished sections */
.disabled-group .far-end a,
.disabled-group .submenu a,
.disabled-group .submenu i,
.disabled-group .far-end i {
    color: #afb7bd !important;
}

.disabled-group .far-end {
    cursor: pointer;
}

.disabled-group .submenu a {
    cursor: default;
    pointer-events: none;
}

.disabled-group .far-end:hover,
.disabled-group .submenu a:hover {
    background: transparent !important;
    color: #afb7bd !important;
    margin-right: 0 !important;
}

/* collapsed sidebar text hiding */
.sidebar.collapsed .far-end a,
.sidebar.collapsed .bottom-line,
.sidebar.collapsed .submenu,
.sidebar.collapsed .download-buttons {
    display: none;
}

.sidebar.collapsed .far-end {
    justify-content: center;
    padding: 12px 10px;
}

/* responsive */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        height: calc(100vh - 80px);
        z-index: 1001;
        transform: translateX(0);
        transition: transform 0.3s ease;
    }

    .sidebar.collapsed {
        transform: translateX(-250px);
        width: 250px;
        padding: 0 4px 10px 10px;
    }

    .sidebar-toggle {
        position: fixed;
        left: 250px;
        transition: left 0.3s ease;
    }

    .sidebar.collapsed .sidebar-toggle {
        left: 0;
    }
}


/* ===== DATASET DROPDOWN STYLES ===== */
.nav-dropdown {
    position: relative;
    display: inline-block;
}

.nav-dropdown-btn {
    background: transparent;
    border: none;
    color: rgb(73, 72, 75);
    text-decoration: none;
    margin: 0 7px;
    font-size: 12px;
    cursor: pointer;
    padding: 5px 8px;
    border-radius: 4px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.nav-dropdown-btn:hover {
    background: #f0f0f0;
}

.nav-dropdown-btn i {
    font-size: 10px;
    transition: transform 0.3s ease;
}

.nav-dropdown-btn.active i {
    transform: rotate(180deg);
}

.nav-dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    min-width: 150px;
    z-index: 1001;
    margin-top: 4px;
}

.nav-dropdown-menu a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    color: rgb(73, 72, 75);
    text-decoration: none;
    font-size: 13px;
    transition: background 0.2s;
    border: none;
}

.nav-dropdown-menu a:hover {
    background: #f0f0f0;
}

.nav-dropdown-menu a:first-child {
    border-radius: 4px 4px 0 0;
}

.nav-dropdown-menu a:last-child {
    border-radius: 0 0 4px 4px;
}

.badge-progress {
    display: inline-block;
    background: #ffc107;
    color: #333;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 8px;
    font-weight: 600;
}

/* ===== RESPONSIVE ADJUSTMENTS ===== */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: 0;
        top: 80px;
        height: calc(100vh - 80px);
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
        z-index: 950;
    }

    .sidebar.collapsed {
        width: 0;
        overflow: hidden;
    }

    .map-container {
        flex: 1;
    }
}


/* ===== CHART OVERLAY STYLES ===== */
.chart-overlay {
    position: fixed;
    bottom: 20px;
    right: 60px;
    width: 500px;
    height: 300px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    z-index: 800;
    transition: all 0.3s ease;
}

.chart-overlay.expanded {
    width: 90vw;
    height: 80vh;
    bottom: 50%;
    right: 50%;
    transform: translate(50%, 50%);
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
    background: #f8f9fa;
    border-radius: 8px 8px 0 0;
}

.chart-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #333;
}

.chart-controls {
    display: flex;
    gap: 8px;
    position: relative;
}

.chart-control-btn {
    background: white;
    border: 1px solid #ddd;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    color: #666;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-control-btn:hover {
    background: #f0f0f0;
    border-color: #999;
    color: #333;
}

.chart-download-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    margin-top: 4px;
    min-width: 150px;
}

.download-option {
    display: block;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: white;
    text-align: left;
    cursor: pointer;
    font-size: 13px;
    color: #333;
    transition: background 0.2s;
}

.download-option:hover {
    background: #f0f0f0;
}

.download-option:first-child {
    border-radius: 4px 4px 0 0;
}

.download-option:last-child {
    border-radius: 0 0 4px 4px;
}

.chart-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: white;
    border-radius: 0 0 8px 8px;
}

.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 12px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f0f0f0;
    border-top: 4px solid #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-state p {
    color: #666;
    font-size: 14px;
    margin: 0;
}

/* ===== RESPONSIVE CHART OVERLAY ===== */
@media (max-width: 768px) {
    .chart-overlay {
        width: 95vw;
        height: 250px;
        bottom: 10px;
        right: 10px;
    }

    .chart-overlay.expanded {
        width: 95vw;
        height: 80vh;
        bottom: 50%;
        right: 50%;
        transform: translate(50%, 50%);
    }

    .chart-header h3 {
        font-size: 12px;
    }

    .chart-control-btn {
        padding: 4px 6px;
    }
}

/* Near-Neighbors Risk Styling */
.risk-marker {
    border-radius: 50%;
    transition: all 0.3s ease;
}

.risk-marker:hover {
    opacity: 1 !important;
    filter: drop-shadow(0 0 5px rgba(0, 0, 0, 0.5));
}

.risk-popup {
    padding: 8px;
    font-size: 12px;
    line-height: 1.5;
}

.risk-popup strong {
    display: inline-block;
    min-width: 120px;
}

.risk-badge {
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: bold;
    color: white;
    font-size: 11px;
}

.risk-badge.risk-high {
    background-color: #d73027;
}

.risk-badge.risk-medium {
    background-color: #fee090;
    color: #333;
}

.risk-badge.risk-low {
    background-color: #91bfdb;
    color: #fff;
}

/* Risk Legend */
.risk-legend {
    background: white;
    padding: 12px;
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-top: 10px;
}

.risk-legend h4 {
    margin: 0 0 8px 0;
    font-size: 13px;
    font-weight: bold;
}

.risk-legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
    font-size: 12px;
}

.risk-legend-color {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid #000;
    margin-right: 8px;
}

.risk-legend-color.high {
    background-color: #d73027;
}

.risk-legend-color.medium {
    background-color: #fee090;
}

.risk-legend-color.low {
    background-color: #91bfdb;
}
