/* CSS FIXES - Add these styles to your existing CSS */

/* FIXED: Map container overflow and sizing issues */
.map-section {
    grid-column: 1 / -1;
    height: 550px;
    min-height: 450px;
    max-height: 600px;
    overflow: hidden; /* Prevent overflow */
    position: relative;
}

#map {
    height: 500px !important;
    width: 100% !important;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    position: relative;
    z-index: 1;
}

/* Ensure leaflet map respects container boundaries */
.leaflet-container {
    height: 100% !important;
    width: 100% !important;
    max-height: 500px;
    overflow: hidden;
}

/* Fix leaflet control positioning */
.leaflet-top, .leaflet-bottom {
    z-index: 1000;
}

.leaflet-control-container {
    position: relative;
}

/* FIXED: Container grid layout improvements */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    gap: 2rem;
    min-height: calc(100vh - 120px); /* Account for header */
}

/* Ensure map takes full width */
.full-width {
    grid-column: 1 / -1;
}

/* FIXED: Section improvements */
.section {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    border: 1px solid #e9ecef;
    overflow: hidden; /* Prevent content overflow */
    position: relative;
}

/* FIXED: Statistics and Fauna sections layout */
.statistics-content,
.fauna-content {
    max-height: 600px;
    overflow-y: auto;
}

.fauna-emoji-marker {
    background: transparent !important;
    border: none !important;
}

.fauna-emoji-marker div {
    transition: transform 0.2s ease;
}

.fauna-emoji-marker:hover div {
    transform: scale(1.2);
}

/* FIXED: Chart container sizing */
.chart-container {
    margin-top: 2rem;
    height: 300px;
    position: relative;
    overflow: hidden;
}

#statisticsChart {
    max-height: 400px !important;
    max-width: 100% !important;
}

/* FIXED: Weather grid responsive layout */
.weather-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

/* FIXED: Fauna grid layout */
.fauna-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
    max-height: 500px;
    overflow-y: auto;
}

/* FIXED: Modal improvements */
.modal {
    display: none;
    position: fixed;
    z-index: 2000; /* Higher than map controls */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    overflow-y: auto;
}

.modal-content {
    background-color: white;
    margin: 2% auto;
    padding: 2rem;
    border-radius: 8px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

/* FIXED: Fullscreen enhancements */
.section:fullscreen {
    background: white;
    padding: 2rem;
    overflow: auto;
}

.section:fullscreen #map {
    height: calc(100vh - 150px) !important;
}

/* FIXED: Header layout improvements */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: relative;
    z-index: 100;
}

.header-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

/* FIXED: Loading and error states */
.loading-spinner {
    text-align: center;
    padding: 2rem;
    color: #6c757d;
    position: relative;
}

.loading-spinner::after {
    content: "";
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 0.5rem;
}

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

/* FIXED: Notification positioning */
.notification {
    position: fixed;
    top: 80px; /* Below header */
    right: 20px;
    padding: 1rem 1.5rem;
    border-radius: 4px;
    color: white;
    font-weight: bold;
    z-index: 2001; /* Above modals */
    animation: slideIn 0.3s ease;
    max-width: 300px;
    word-wrap: break-word;
}

.notification.success { background: #28a745; }
.notification.error { background: #dc3545; }
.notification.warning { background: #ffc107; color: #212529; }
.notification.info { background: #17a2b8; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* FIXED: Responsive design improvements */
@media (max-width: 768px) {
    .container {
        grid-template-columns: 1fr;
        padding: 1rem;
        gap: 1rem;
    }
    
    .map-section {
        height: 400px;
    }
    
    #map {
        height: 350px !important;
    }
    
    .header {
        padding: 1rem;
    }
    
    .header h1 {
        font-size: 1.5rem;
    }
    
    .header-controls {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .status-info {
        gap: 1rem;
        flex-wrap: wrap;
    }
    
    .weather-grid {
        grid-template-columns: 1fr;
    }
    
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }
    
    .fauna-grid {
        grid-template-columns: 1fr;
    }
    
    .modal-content {
        width: 95%;
        margin: 5% auto;
        padding: 1rem;
        max-height: 85vh;
    }
    
    .notification {
        right: 10px;
        left: 10px;
        max-width: none;
    }
    .chart-container {
        margin-top: 2rem;
        height: 450px; /* Increased from 300px */
        min-height: 400px;
    }

    #statisticsChart {
        max-height: 450px !important;
        min-height: 400px !important;
    }

    /* Also make the overall statistics section taller on mobile */
    .statistics-content {
        max-height: 800px; /* Increased from 600px */
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0.5rem;
    }
    
    .section {
        padding: 1rem;
    }
    
    .map-section {
        height: 300px;
    }
    
    #map {
        height: 250px !important;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .chart-container {
        height: 400px; /* Still good height for very small screens */
        min-height: 350px;
    }

    #statisticsChart {
        max-height: 400px !important;
        min-height: 350px !important;
    }
}

/* FIXED: Table responsive design */
.comparison-table {
    overflow-x: auto;
    margin: 1rem 0;
}

.comparison-table table {
    width: 100%;
    min-width: 600px;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.comparison-table th,
.comparison-table td {
    padding: 0.75rem;
    border: 1px solid #e9ecef;
    text-align: left;
    white-space: nowrap;
}

.comparison-table th {
    background: #f8f9fa;
    font-weight: bold;
    color: #495057;
    position: sticky;
    top: 0;
    z-index: 10;
}

.comparison-table tr:hover {
    background: #f8f9fa;
}

/* FIXED: Button improvements */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-block;
    white-space: nowrap;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.btn:active {
    transform: translateY(0);
}

/* FIXED: Species and fauna card improvements */
.fauna-card,
.weather-card {
    transition: all 0.2s ease;
    cursor: pointer;
    overflow: hidden;
}

.fauna-card:hover,
.weather-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.weather-card.selected {
    background: #e3f2fd !important;
    border: 2px solid #2196f3 !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3) !important;
}

.selected-station-header {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    border-left: 4px solid #007bff;
}

.selected-station-header h4 {
    margin: 0;
    color: #495057;
    font-size: 1.1rem;
}

/* FIXED: Scrollbar styling */
.statistics-content::-webkit-scrollbar,
.fauna-content::-webkit-scrollbar,
.fauna-grid::-webkit-scrollbar,
.weather-grid::-webkit-scrollbar,
.comparison-table::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.statistics-content::-webkit-scrollbar-track,
.fauna-content::-webkit-scrollbar-track,
.fauna-grid::-webkit-scrollbar-track,
.weather-grid::-webkit-scrollbar-track,
.comparison-table::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.statistics-content::-webkit-scrollbar-thumb,
.fauna-content::-webkit-scrollbar-thumb,
.fauna-grid::-webkit-scrollbar-thumb,
.weather-grid::-webkit-scrollbar-thumb,
.comparison-table::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.statistics-content::-webkit-scrollbar-thumb:hover,
.fauna-content::-webkit-scrollbar-thumb:hover,
.fauna-grid::-webkit-scrollbar-thumb:hover,
.weather-grid::-webkit-scrollbar-thumb:hover,
.comparison-table::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}
