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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f5f7fa;
    color: #2c3e50;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 2rem 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

header .container { display: flex; align-items: center; gap: 1rem; }

header .logo { height: 120px; width: 120px; max-width: 120px; max-height: 120px; flex-shrink: 0; border-radius: 50%; object-fit: cover; }

header h1,
header .site-name {
    font-size: 2.5rem;
    font-weight: bold;
    margin-bottom: 0;
    display: block;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.subtitle {
    opacity: 0.9;
    font-size: 1.1rem;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
}

.nav-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin: 1.5rem 0 0;
}

.nav-buttons button {
    padding: 0.55rem 1rem;
    font-size: 0.88rem;
}

.controls {
    background: white;
    padding: 1rem 1.5rem;
    margin: 0.75rem 0 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

#riverSelect {
    flex: 1;
    min-width: 200px;
    padding: 0.75rem 1rem;
    border: 2px solid #e1e8ed;
    border-radius: 6px;
    font-size: 1rem;
    background: white;
}

#riverSelect:focus {
    outline: none;
    border-color: #667eea;
}

button {
    padding: 0.75rem 1.5rem;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.3s;
}

button:hover {
    background: #5568d3;
}

#showWarningsBtn {
    background: #e74c3c;
}

#showWarningsBtn:hover {
    background: #c0392b;
}

#showFavoritesBtn {
    background: #f39c12;
}

#showFavoritesBtn:hover {
    background: #e67e22;
}

.favorite-btn {
    background: transparent;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0.2rem;
    transition: transform 0.2s, color 0.2s;
    color: #999;
    line-height: 1;
}

.favorite-btn:hover {
    transform: scale(1.2);
    color: #f39c12;
}

.favorite-btn.active {
    color: #f39c12;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 2rem;
    margin-bottom: 2rem;
    position: relative;
}

#map {
    height: 600px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

#sidebar {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    padding: 1.5rem;
    height: 600px;
    overflow-y: auto;
}

#sidebar h2 {
    margin-bottom: 1rem;
    color: #667eea;
}

.station-card {
    background: #f8f9fa;
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border-left: 4px solid #667eea;
}

.station-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.station-name {
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 0.5rem;
}

.station-river {
    color: #7f8c8d;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.station-level {
    font-size: 1.2rem;
    color: #27ae60;
    font-weight: 600;
}

.station-level.warning {
    color: #f39c12;
}

.station-level.danger {
    color: #e74c3c;
}

.warnings {
    background: #fff3cd;
    border: 2px solid #f39c12;
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.warnings h3 {
    color: #e67e22;
    margin-bottom: 0.5rem;
}

.warning-item {
    background: white;
    padding: 0.75rem;
    margin: 0.5rem 0;
    border-radius: 4px;
    font-size: 0.9rem;
}

.hidden {
    display: none !important;
}

.loading {
    text-align: center;
    color: #7f8c8d;
    padding: 2rem;
}

/* Modal */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.close {
    position: absolute;
    right: 1rem;
    top: 1rem;
    font-size: 2rem;
    cursor: pointer;
    color: #7f8c8d;
}

.close:hover {
    color: #2c3e50;
}

footer {
    background: #2c3e50;
    color: white;
    text-align: center;
    padding: 1.5rem;
    margin-top: 2rem;
}

/* SEO Footer */
.site-footer {
    background: #1a252f;
    color: #ccc;
    padding: 2.5rem 1.5rem 1.5rem;
    margin-top: 2rem;
    text-align: left;
}
.site-footer .footer-content {
    max-width: 1200px;
    margin: 0 auto;
}
.site-footer .footer-columns {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
    margin-bottom: 2rem;
}
.site-footer .footer-col h3 {
    color: #e67e22;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 0.75rem;
    font-weight: 600;
}
.site-footer .footer-col ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
.site-footer .footer-col li {
    margin-bottom: 0.35rem;
}
.site-footer .footer-col a {
    color: #aab;
    text-decoration: none;
    font-size: 0.85rem;
    transition: color 0.15s;
}
.site-footer .footer-col a:hover {
    color: #e67e22;
}
.site-footer .footer-bottom {
    border-top: 1px solid #2c3e50;
    padding-top: 1.25rem;
    text-align: center;
    font-size: 0.8rem;
    color: #889;
}
.site-footer .footer-bottom a {
    color: #aab;
    text-decoration: none;
}
.site-footer .footer-bottom a:hover {
    color: #e67e22;
}
@media (max-width: 768px) {
    .site-footer .footer-columns {
        grid-template-columns: 1fr 1fr;
        gap: 1.5rem;
    }
}
@media (max-width: 480px) {
    .site-footer .footer-columns {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}

/* Custom marker styles */
.custom-marker,
.station-marker {
    background: transparent !important;
    border: none !important;
}

.leaflet-popup-content {
    margin: 12px;
}

@media (max-width: 968px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    #sidebar {
        height: auto;
    }

    #locateMeBtn {
        right: 10px;
    }
    #zoomLevel {
        right: 10px;
    }
}

/* Stats Widget */
.stats-widget {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1.5rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.stats-widget h3 {
    margin: 0 0 1rem 0;
    font-size: 1.3rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
}

.stat-item {
    background: rgba(255, 255, 255, 0.15);
    padding: 0.75rem;
    border-radius: 8px;
    backdrop-filter: blur(10px);
}

.stat-item .number {
    font-size: 1.5rem;
    font-weight: bold;
    margin-bottom: 0.25rem;
}

.stat-item .label {
    font-size: 0.85rem;
    opacity: 0.9;
}

.stat-item.above {
    background: rgba(231, 76, 60, 0.2);
}

.stat-item.normal {
    background: rgba(39, 174, 96, 0.2);
}

.stat-item.below {
    background: rgba(52, 152, 219, 0.2);
}

/* User location marker */
.user-location-marker {
    background: transparent !important;
    border: none !important;
}

.user-location-dot {
    width: 12px;
    height: 12px;
    background: #4285F4;
    border: 2px solid white;
    border-radius: 50%;
    position: absolute;
    top: 4px;
    left: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    z-index: 2;
}

.user-location-pulse {
    width: 20px;
    height: 20px;
    background: rgba(66, 133, 244, 0.3);
    border-radius: 50%;
    position: absolute;
    top: 0;
    left: 0;
    animation: pulse 2s ease-out infinite;
    z-index: 1;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.6; }
    100% { transform: scale(3); opacity: 0; }
}

#locateMeBtn {
    position: absolute;
    top: 10px;
    right: 420px;
    z-index: 1000;
    background: white;
    color: #2c3e50;
    border: 1px solid #ccc;
    border-radius: 5px;
    padding: 4px 8px;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 0.2rem;
}

#locateMeBtn:hover {
    background: #f8f9fa;
    border-color: #aaa;
}

#zoomLevel {
    position: absolute;
    top: 44px;
    right: 420px;
    z-index: 1000;
    font-size: 0.7rem;
    color: #999;
    background: rgba(255,255,255,0.8);
    padding: 2px 6px;
    border-radius: 4px;
}

/* Sewage overlay markers */
.sewage-marker {
    background: transparent !important;
    border: none !important;
}

.sewage-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.8);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    position: absolute;
    top: 2px;
    left: 2px;
}

/* Map Tabs */
.map-tabs {
    display: flex;
    gap: 0;
    margin: 0 0 -1px 0;
    padding: 0 2rem;
}

.map-tab {
    padding: 0.6rem 1.5rem;
    border: 1px solid #ddd;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    background: #e9ecef;
    color: #666;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.map-tab:hover {
    background: #f0f0f0;
    color: #333;
}

.map-tab.active {
    background: white;
    color: #2c3e50;
    border-color: #ddd;
    box-shadow: 0 -2px 4px rgba(0,0,0,0.05);
}

.tab-badge {
    background: #e74c3c;
    color: white;
    padding: 0.1rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: bold;
    margin-left: 0.25rem;
}

.tab-badge-clickable {
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.tab-badge-clickable:hover {
    transform: scale(1.08);
    box-shadow: 0 2px 6px rgba(231, 76, 60, 0.4);
}

.tab-badge-active {
    outline: 2px solid #fff;
    box-shadow: 0 0 0 3px #e74c3c;
}

.tab-badge-critical {
    animation: pulse-badge 2s ease-in-out infinite;
}

.tab-badge-critical.tab-badge-active {
    animation: none;
}

@keyframes pulse-badge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@media (max-width: 768px) {
    .map-tabs {
        padding: 0 0.5rem;
    }
    .map-tab {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
        flex: 1;
        text-align: center;
    }
    .tab-badge {
        display: block;
        margin: 0.2rem auto 0;
        font-size: 0.7rem;
    }
}

/* Sewage sidebar */
.sewage-stats-panel {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.sewage-stat {
    background: #f8f9fa;
    padding: 0.75rem;
    border-radius: 6px;
    text-align: center;
}

.sewage-stat .number {
    font-size: 1.3rem;
    font-weight: bold;
    color: #2c3e50;
}

.sewage-stat .label {
    font-size: 0.8rem;
    color: #666;
}

.sewage-stat.discharging .number { color: #8b0000; }
.sewage-stat.offline .number { color: #95a5a6; }

.sewage-card {
    background: #f8f9fa;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: 6px;
    border-left: 4px solid #27ae60;
    font-size: 0.9rem;
}

.sewage-card.discharging { border-left-color: #8b0000; background: #fff5f5; }
.sewage-card.offline { border-left-color: #95a5a6; }

.sewage-card .site-name { font-weight: 600; color: #2c3e50; margin-bottom: 0.25rem; }
.sewage-card .site-detail { color: #666; font-size: 0.85rem; }

/* Flood Zone Overlay Controls */
.map-overlay-panel {
    padding: 0.5rem 2rem;
    margin-bottom: 0.25rem;
    display: flex;
    gap: 1.25rem;
    flex-wrap: wrap;
    align-items: center;
}

.flood-overlay-option {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.88rem;
    color: #2c3e50;
    cursor: pointer;
    white-space: nowrap;
}

.flood-overlay-option input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.flood-overlay-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.15);
}

.flood-overlay-hint {
    font-size: 0.82rem;
    color: #f39c12;
    font-style: italic;
    width: 100%;
}

/* Flood zone badge */
.flood-zone-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.flood-zone-badge.zone-3 {
    background: rgba(231,76,60,0.15);
    color: #c0392b;
    border: 1px solid rgba(231,76,60,0.3);
}

.flood-zone-badge.zone-2 {
    background: rgba(243,156,18,0.15);
    color: #d68910;
    border: 1px solid rgba(243,156,18,0.3);
}

.flood-zone-badge.zone-2-3 {
    background: rgba(231,76,60,0.15);
    color: #c0392b;
    border: 1px solid rgba(231,76,60,0.3);
}

@media (max-width: 600px) {
    .map-overlay-panel { padding: 0.5rem 1rem; flex-direction: column; gap: 0.5rem; align-items: flex-start; }
}

/* Shared flood overlay Leaflet control (sub-pages) */
.flood-overlay-ctrl {
    background: white;
    border-radius: 8px !important;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 0.85rem;
}
.flood-overlay-ctrl-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    background: white;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: #2c3e50;
    white-space: nowrap;
    border-radius: 8px;
}
.flood-overlay-ctrl-toggle:hover { background: #f8f9fa; }
.flood-ctrl-arrow { font-size: 0.65rem; color: #999; }
.flood-overlay-ctrl-panel {
    padding: 0.5rem 0.75rem;
    border-top: 1px solid #eee;
}
.flood-overlay-ctrl-panel label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0;
    cursor: pointer;
    font-size: 0.82rem;
    color: #444;
    white-space: nowrap;
}
.flood-overlay-ctrl-panel input[type="checkbox"] {
    width: 14px;
    height: 14px;
    margin: 0;
}
.fo-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}
.flood-zoom-hint {
    font-size: 0.75rem;
    color: #e67e22;
    padding: 0.25rem 0 0.1rem;
}

/* Sewage discharge indicator on station page */
.sewage-indicator {
    background: white;
    padding: 1.25rem 1.5rem;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    margin-bottom: 1.5rem;
    display: none;
    border-left: 4px solid #e0e0e0;
}
.sewage-indicator.visible { display: block; }
.sewage-indicator.sewage-active { border-left-color: #8b4513; }
.sewage-indicator .si-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    color: #8b4513;
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
}
.sewage-indicator .si-header .si-icon { font-size: 1.2rem; }
.sewage-indicator .si-summary {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 0.75rem;
}
.sewage-indicator .si-site {
    padding: 0.5rem 0.75rem;
    background: #fdf6f0;
    border-radius: 6px;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
}
.sewage-indicator .si-site-name {
    font-weight: 600;
    color: #5d3a1a;
}
.sewage-indicator .si-site-meta {
    color: #888;
    font-size: 0.8rem;
    margin-top: 0.15rem;
}

/* Map Legend */
.map-legend {
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(4px);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    font-size: 0.78rem;
    line-height: 1.5;
    transition: all 0.2s ease;
    overflow: hidden;
}
.map-legend-toggle {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.85rem;
    color: #667eea;
    border-radius: 8px;
}
.map-legend-toggle:hover { background: rgba(102,126,234,0.1); }
.map-legend-body {
    display: none;
    padding: 6px 12px 10px;
}
.map-legend.expanded .map-legend-toggle { display: none; }
.map-legend.expanded .map-legend-body { display: block; }
.map-legend.expanded { padding: 0; }
.map-legend-title {
    font-weight: 700;
    font-size: 0.82rem;
    color: #2c3e50;
    margin-bottom: 4px;
    padding-bottom: 4px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
}
.legend-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 1px 0;
    color: #444;
}
.legend-divider {
    height: 1px;
    background: #eee;
    margin: 4px 0;
}

/* Trend arrows on sidebar cards */
.trend-arrow {
    font-size: 0.75rem;
    font-weight: 700;
    margin-left: 4px;
    vertical-align: middle;
}
.trend-rising { color: #e74c3c; }
.trend-falling { color: #3498db; }
.trend-steady { color: #95a5a6; font-size: 0.65rem; }

/* Card right column (star only) */
.card-right {
    flex-shrink: 0;
    padding-left: 8px;
}

/* Sparkline row below value */
.sparkline-row {
    margin-top: 4px;
}
.sidebar-sparkline {
    display: block;
    width: 100%;
    max-width: 120px;
    height: 22px;
}
.sparkline-placeholder {
    display: block;
    height: 22px;
    width: 80px;
    background: #e8e8e8;
    border-radius: 3px;
    animation: shimmer 1.2s ease-in-out infinite;
}
@keyframes shimmer {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* Enhanced station card (zoom > 8) */
.station-card.enhanced {
    border-left-width: 3px;
}
.card-view-hint {
    font-size: 0.7rem;
    color: #aaa;
    margin-top: 4px;
}
.station-card.enhanced:hover .card-view-hint {
    color: #667eea;
}

/* Popup favorite button */
.popup-fav-btn {
    background: none;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
    transition: transform 0.15s, border-color 0.15s;
    flex-shrink: 0;
    color: #999;
}
.popup-fav-btn:hover { transform: scale(1.1); border-color: #f39c12; color: #f39c12; }
.popup-fav-btn.active { color: #f39c12; border-color: #f39c12; }

/* Region cluster markers (low zoom) */
.region-cluster {
    background: transparent !important;
    border: none !important;
}
.region-cluster-circle {
    background: rgba(102, 126, 234, 0.85);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0,0,0,0.25);
    transition: transform 0.2s;
    border: 3px solid rgba(255,255,255,0.7);
}
.region-cluster-circle:hover {
    transform: scale(1.1);
}
.region-count {
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.1;
}
.region-name {
    font-size: 0.55rem;
    font-weight: 600;
    opacity: 0.9;
    text-align: center;
    line-height: 1.1;
}
