/* Base Variables & Reset */
:root {
    --bg-color: #f4f7f6;
    --text-main: #333;
    --text-muted: #666;
    --primary-color: #2c3e50;
    --accent-color: #3498db;
    --border-color: #ddd;
    --highlight-bg: #e8f4fd;
    --card-bg: #fff;
    --error-color: #e74c3c;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    /* Prevent body from scrolling horizontally */
    overflow-x: hidden; 
}

/* Header */
.app-header {
    background-color: var(--primary-color);
    color: white;
    padding: 1.5rem 1rem;
    text-align: center;
}

.app-header p {
    color: #bdc3c7;
    font-size: 0.9rem;
}

/* Layout Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    /* Ensure flex children can shrink properly */
    min-width: 0; 
}

/* Filters */
.controls-section {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: center;
    background: var(--card-bg);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    width: 100%;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    /* Allow the group to shrink on small screens */
    min-width: 0;
    flex: 1;
}

select {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    background-color: white;
    cursor: pointer;
    /* Prevent long indicator names from breaking the layout */
    max-width: 100%;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

/* Loading & Errors */
.hidden {
    display: none !important;
}

#loading-indicator {
    color: var(--accent-color);
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--accent-color);
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin { 100% { transform: rotate(360deg); } }

.error-text {
    color: var(--error-color);
    font-weight: bold;
}

/* Map */
.map-section {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 0.5rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    width: 100%;
}

#map {
    width: 100%;
    height: 50vh;
    min-height: 400px;
    border-radius: 6px;
    background: #e0e6ed;
    z-index: 1; /* Keep leaflet controls below dropdowns if they overlap */
}

/* Tooltip standard customization */
.leaflet-tooltip {
    font-family: var(--font-family);
    font-weight: bold;
    color: var(--text-main);
}

/* Summary Grid */
.summary-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

.summary-card {
    background: var(--card-bg);
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    text-align: center;
}

.summary-card h3 {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.summary-card p {
    font-size: 1.1rem;
    font-weight: bold;
    margin-top: 0.5rem;
}

.selected-card {
    background: var(--highlight-bg);
    border-left: 5px solid var(--accent-color);
    padding: 1rem 1.5rem;
    border-radius: 4px;
}

/* Table */
.table-section {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    /* Strict boundaries to prevent horizontal overflow */
    overflow: hidden;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.table-container {
    /* Enforce scrolling inside the container */
    overflow-x: auto;
    max-height: 500px;
    width: 100%;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    /* Ensure table content dictates width, but container scrolls */
    min-width: 400px; 
}

th, td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap; /* Keep table rows organized */
}

th {
    background-color: #fafafa;
    position: sticky;
    top: 0;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
    z-index: 2; /* Ensure sticky header stays above rows */
}

th:hover {
    background-color: #f0f0f0;
}

tr:hover {
    background-color: #f9f9f9;
}

tr.selected-row {
    background-color: var(--highlight-bg);
    font-weight: bold;
}

/* Responsive Adjustments for Mobile */
@media (max-width: 768px) {
    .container {
        padding: 1rem; /* Less padding on small screens to maximize space */
        gap: 1rem;
    }
    
    .controls-section {
        flex-direction: column;
        align-items: stretch;
        padding: 1rem;
    }
    
    .filter-group {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }
    
    .filter-group label {
        font-weight: 600;
        font-size: 0.9rem;
    }

    #map {
        height: 40vh;
        min-height: 300px;
    }

    th, td {
        padding: 0.5rem;
        font-size: 0.9rem;
    }
}