/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Colors */
    --primary-blue: #1e3a5f;
    --dark-blue: #0f1f36;
    --light-blue: #e8f4fc;
    --accent-blue: #3b82f6;
    --text-primary: #1a1a1a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --background: #ffffff;
    --background-alt: #f8fafc;

    /* Status Colors */
    --status-normal: #10b981;
    --status-normal-bg: #ecfdf5;
    --status-elevated: #f59e0b;
    --status-elevated-bg: #fffbeb;
    --status-high: #f97316;
    --status-high-bg: #fff7ed;
    --status-flooding: #dc2626;
    --status-flooding-bg: #fef2f2;
    --status-severe: #991b1b;

    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', 'Courier New', monospace;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    --space-3xl: 4rem;

    /* Border radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

body {
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--background-alt);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 var(--space-md);
}

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

/* Header */
.site-header {
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--dark-blue) 100%);
    color: white;
    padding: var(--space-lg) 0;
    box-shadow: var(--shadow-lg);
}

.site-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: var(--space-xs);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.site-header h1::before {
    content: '🌊';
    font-size: 1.5rem;
}

.site-header .subtitle {
    font-size: 0.95rem;
    opacity: 0.85;
    font-weight: 400;
}

/* Hero Section */
.hero {
    background-color: var(--background);
    padding: var(--space-2xl) 0;
    border-bottom: 1px solid var(--border-color);
}

.status-display {
    text-align: center;
    margin-bottom: var(--space-xl);
    padding: var(--space-xl);
    background: var(--background);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}

.status-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.status-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: var(--status-normal);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2);
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

.status-text {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--status-normal);
}

/* Status color variants */
.status-display.normal .status-dot {
    background-color: var(--status-normal);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2);
}

.status-display.normal .status-text {
    color: var(--status-normal);
}

.status-display.normal {
    border-color: var(--status-normal);
    background: linear-gradient(to bottom, var(--status-normal-bg), var(--background));
}

.status-display.elevated .status-dot {
    background-color: var(--status-elevated);
    box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.2);
}

.status-display.elevated .status-text {
    color: var(--status-elevated);
}

.status-display.elevated {
    border-color: var(--status-elevated);
    background: linear-gradient(to bottom, var(--status-elevated-bg), var(--background));
}

.status-display.high .status-dot {
    background-color: var(--status-high);
    box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.2);
}

.status-display.high .status-text {
    color: var(--status-high);
}

.status-display.high {
    border-color: var(--status-high);
    background: linear-gradient(to bottom, var(--status-high-bg), var(--background));
}

.status-display.flooding .status-dot {
    background-color: var(--status-flooding);
    box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.2);
    animation: pulse-urgent 1s ease-in-out infinite;
}

@keyframes pulse-urgent {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.2);
    }
    50% {
        transform: scale(1.2);
        box-shadow: 0 0 0 8px rgba(220, 38, 38, 0.3);
    }
}

.status-display.flooding .status-text {
    color: var(--status-flooding);
}

.status-display.flooding {
    border-color: var(--status-flooding);
    background: linear-gradient(to bottom, var(--status-flooding-bg), var(--background));
}

.level-display {
    margin-bottom: var(--space-lg);
}

.level-value {
    font-size: 4.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    font-family: var(--font-mono);
    color: var(--primary-blue);
    line-height: 1;
    margin-bottom: var(--space-sm);
    letter-spacing: -0.02em;
}

.level-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
}

.trend-info {
    font-size: 0.95rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    flex-wrap: wrap;
}

.trend {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    font-weight: 600;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-md);
    background: var(--background-alt);
}

.trend-symbol {
    font-size: 1.25rem;
}

.trend.rising {
    color: var(--status-flooding);
    background: var(--status-flooding-bg);
}

.trend.falling {
    color: var(--status-normal);
    background: var(--status-normal-bg);
}

.trend.stable {
    color: var(--text-secondary);
}

.separator {
    color: var(--border-color);
}

.status-message {
    margin-top: var(--space-lg);
    padding: var(--space-md) var(--space-lg);
    background-color: var(--background-alt);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    color: var(--text-primary);
}

/* Rainfall Display */
.rainfall-display {
    margin: var(--space-xl) 0;
    padding: var(--space-lg);
    background: linear-gradient(135deg, #e0f2fe, #f0f9ff);
    border-radius: var(--radius-lg);
    border: 1px solid #bae6fd;
}

.rainfall-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.rainfall-icon {
    font-size: 1.25rem;
}

.rainfall-title {
    font-weight: 600;
    color: var(--primary-blue);
}

.rainfall-data {
    display: flex;
    justify-content: center;
    gap: var(--space-2xl);
    margin-bottom: var(--space-sm);
}

.rainfall-item {
    text-align: center;
}

.rainfall-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-blue);
    font-family: var(--font-mono);
}

.rainfall-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.rainfall-note {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
    font-style: italic;
}

/* Road Status Grid */
.road-status-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-md);
    margin: var(--space-xl) 0;
}

.road-status-item {
    background: var(--background);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    text-align: center;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.road-name {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: var(--space-xs);
}

.road-indicator {
    display: inline-block;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.road-indicator.clear {
    background: var(--status-normal-bg);
    color: var(--status-normal);
}

.road-indicator.risk {
    background: var(--status-elevated-bg);
    color: var(--status-elevated);
}

.road-indicator.flooded {
    background: var(--status-flooding-bg);
    color: var(--status-flooding);
}

.context-info {
    margin-top: var(--space-xl);
    padding: var(--space-lg);
    background-color: var(--background);
    border-radius: var(--radius-lg);
    display: flex;
    justify-content: center;
    gap: var(--space-2xl);
    flex-wrap: wrap;
    border: 1px solid var(--border-color);
}

.context-info p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.context-info strong {
    color: var(--primary-blue);
    font-weight: 600;
}

/* Error Display */
.error-message {
    background-color: var(--status-flooding-bg);
    border: 1px solid #fecaca;
    border-left: 4px solid var(--status-flooding);
    color: #991b1b;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    margin-top: var(--space-md);
    font-size: 0.95rem;
}

.error-message a {
    color: #991b1b;
    text-decoration: underline;
}

.hidden {
    display: none !important;
}

/* ============================================
   PREDICTIVE TIMELINE SECTION
   ============================================ */

.prediction-section {
    background-color: var(--background);
    padding: var(--space-2xl) 0;
    border-bottom: 1px solid var(--border-color);
}

.prediction-section h2 {
    font-size: 1.25rem;
    color: var(--primary-blue);
    margin-bottom: var(--space-lg);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.prediction-section h2::before {
    content: '⏱️';
}

#prediction-display {
    background: var(--background-alt);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    border: 1px solid var(--border-color);
}

.prediction-status {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    border-radius: var(--radius-md);
}

.prediction-status.stable {
    background: var(--status-normal-bg);
    color: #166534;
}

.prediction-status.rising {
    background: var(--status-elevated-bg);
    color: #92400e;
}

.prediction-icon {
    font-size: 1.5rem;
}

.prediction-text {
    font-weight: 500;
}

.prediction-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.prediction-rate {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    font-weight: 700;
    font-size: 1.1rem;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
}

.prediction-rate.rising {
    background: var(--status-flooding-bg);
    color: var(--status-flooding);
}

.rate-icon {
    font-size: 1.25rem;
}

.prediction-disclaimer {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-style: italic;
}

.prediction-timeline {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.prediction-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md) var(--space-lg);
    background: var(--background);
    border-radius: var(--radius-md);
    border-left: 4px solid var(--border-color);
    transition: all 0.2s ease;
}

.prediction-item.urgent {
    border-left-color: var(--status-flooding);
    background: var(--status-flooding-bg);
}

.prediction-item.soon {
    border-left-color: var(--status-high);
    background: var(--status-high-bg);
}

.prediction-item.later {
    border-left-color: var(--status-elevated);
    background: var(--status-elevated-bg);
}

.prediction-threshold {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.prediction-threshold .threshold-level {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary-blue);
}

.prediction-threshold .threshold-name {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.prediction-time {
    text-align: right;
}

.time-estimate {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.prediction-caveat {
    margin-top: var(--space-lg);
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
    font-style: italic;
}

/* ============================================
   UPSTREAM MONITORING SECTION
   ============================================ */

.upstream-section {
    background-color: var(--background-alt);
    padding: var(--space-2xl) 0;
    border-bottom: 1px solid var(--border-color);
}

.upstream-section h2 {
    font-size: 1.25rem;
    color: var(--primary-blue);
    margin-bottom: var(--space-sm);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.upstream-section h2::before {
    content: '📍';
}

.upstream-hint {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-lg);
}

/* NEW: Explanation box about datum differences */
.upstream-explanation {
    background: var(--light-blue);
    border: 1px solid #bae6fd;
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-lg);
    font-size: 0.85rem;
    color: var(--text-primary);
}

.upstream-explanation strong {
    color: var(--primary-blue);
}

.upstream-explanation p {
    margin: 0;
    line-height: 1.6;
}

.upstream-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-lg);
    margin-bottom: var(--space-lg);
}

.upstream-station {
    background: var(--background);
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
}

.upstream-station-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--space-sm);
}

.upstream-station-name {
    font-weight: 700;
    color: var(--primary-blue);
    font-size: 1rem;
}

.upstream-travel-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--background-alt);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
}

.upstream-data {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-sm);
}

.upstream-level {
    font-family: var(--font-mono);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-blue);
}

.upstream-meta {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.upstream-status-badge {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
}

.upstream-status-badge.normal {
    background: var(--status-normal-bg);
    color: var(--status-normal);
}

.upstream-status-badge.elevated {
    background: var(--status-elevated-bg);
    color: var(--status-elevated);
}

.upstream-status-badge.high {
    background: var(--status-flooding-bg);
    color: var(--status-flooding);
}

/* NEW: Unavailable status */
.upstream-status-badge.unavailable {
    background: var(--background-alt);
    color: var(--text-secondary);
}

.upstream-trend {
    font-size: 1.25rem;
}

.upstream-trend.rising {
    color: var(--status-flooding);
}

.upstream-trend.falling {
    color: var(--status-normal);
}

.upstream-trend.stable {
    color: var(--text-secondary);
}

/* NEW: Context line showing typical range */
.upstream-context {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: var(--space-xs);
    padding-top: var(--space-xs);
    border-top: 1px solid var(--border-color);
}

#upstream-warning {
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    background: var(--status-normal-bg);
    color: #166534;
}

#upstream-warning.active {
    background: var(--status-elevated-bg);
    color: #92400e;
    border: 1px solid var(--status-elevated);
}

.warning-icon,
.ok-icon {
    font-size: 1.1rem;
}

/* NEW: Info icon for unavailable data */
.info-icon {
    font-size: 1.1rem;
}

/* ============================================
   HISTORICAL COMPARISON SELECTOR
   ============================================ */

.historical-selector {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    flex-wrap: wrap;
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-color);
}

.historical-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.historical-buttons {
    display: flex;
    gap: var(--space-xs);
    flex-wrap: wrap;
}

.historical-btn {
    padding: var(--space-sm) var(--space-md);
    border: 2px solid var(--border-color);
    background: var(--background);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-sans);
}

.historical-btn:hover {
    border-color: var(--primary-blue);
    color: var(--primary-blue);
}

.historical-btn:focus {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

.historical-btn.active {
    border-color: var(--accent-blue);
    background: var(--accent-blue);
    color: white;
}

/* Color-coded historical buttons */
.historical-btn[data-event="jan2024"].active {
    background: #8b5cf6;
    border-color: #8b5cf6;
}

.historical-btn[data-event="feb2014"].active {
    background: #f59e0b;
    border-color: #f59e0b;
}

.historical-btn[data-event="jan2003"].active {
    background: #ef4444;
    border-color: #ef4444;
}

/* ============================================
   GAUGE SECTION
   ============================================ */

.gauge-section {
    background-color: var(--background);
    padding: var(--space-2xl) 0;
    border-bottom: 1px solid var(--border-color);
}

.gauge-section h2 {
    font-size: 1.25rem;
    color: var(--primary-blue);
    margin-bottom: var(--space-sm);
    font-weight: 700;
}

.gauge-hint {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-xl);
}

.gauge-container {
    display: flex;
    justify-content: center;
    padding: 0 var(--space-md);
}

.gauge {
    display: flex;
    gap: var(--space-md);
    width: 100%;
    max-width: 600px;
    align-items: stretch;
}

/* Gauge track wrapper for tooltip positioning */
.gauge-track-wrapper {
    position: relative;
    flex: 1;
    max-width: 400px;
    height: 320px;
}

.gauge-track {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to top, 
        rgba(16, 185, 129, 0.1) 0%, 
        rgba(16, 185, 129, 0.05) 40%, 
        rgba(245, 158, 11, 0.05) 65%, 
        rgba(220, 38, 38, 0.05) 100%
    );
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    z-index: 1;
}

.gauge-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 0%;
    background: linear-gradient(to top, #0284c7, #0ea5e9, #38bdf8);
    transition: height 1s ease-out;
    opacity: 0.85;
    z-index: 2;
}

/* Water ripple effect */
.gauge-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 8px;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.4), transparent);
    animation: ripple 2s ease-in-out infinite;
}

@keyframes ripple {
    0%, 100% {
        opacity: 0.4;
        transform: translateY(0);
    }
    50% {
        opacity: 0.7;
        transform: translateY(-2px);
    }
}

/* Threshold markers */
.threshold {
    position: absolute;
    left: 0;
    right: 0;
    height: 20px;
    margin-top: -10px;
    display: flex;
    align-items: center;
    z-index: 10;
    cursor: pointer;
}

/* FIXED: Bring hovered threshold above others but below tooltip */
.threshold:hover,
.threshold:focus {
    z-index: 50;
}

.threshold-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background-color: rgba(100, 116, 139, 0.4);
    transition: all 0.2s ease;
}

.threshold-line::before,
.threshold-line::after {
    content: '';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    transition: all 0.2s ease;
}

.threshold-line::before {
    left: 0;
}

.threshold-line::after {
    right: 0;
}

/* Warning threshold styling */
.threshold.warning .threshold-line {
    background-color: var(--status-high);
    height: 3px;
}

.threshold.warning .threshold-line::before,
.threshold.warning .threshold-line::after {
    background-color: var(--status-high);
    width: 10px;
    height: 10px;
}

/* Severe threshold styling */
.threshold.severe .threshold-line {
    background-color: var(--status-flooding);
    height: 3px;
}

.threshold.severe .threshold-line::before,
.threshold.severe .threshold-line::after {
    background-color: var(--status-flooding);
    width: 10px;
    height: 10px;
}

/* Hover/focus states */
.threshold:hover .threshold-line,
.threshold:focus .threshold-line {
    height: 4px;
    background-color: var(--primary-blue);
}

.threshold:hover .threshold-line::before,
.threshold:hover .threshold-line::after,
.threshold:focus .threshold-line::before,
.threshold:focus .threshold-line::after {
    width: 12px;
    height: 12px;
    background-color: var(--primary-blue);
}

.threshold.warning:hover .threshold-line,
.threshold.warning:focus .threshold-line {
    background-color: var(--status-high);
}

.threshold.warning:hover .threshold-line::before,
.threshold.warning:hover .threshold-line::after,
.threshold.warning:focus .threshold-line::before,
.threshold.warning:focus .threshold-line::after {
    background-color: var(--status-high);
}

.threshold.severe:hover .threshold-line,
.threshold.severe:focus .threshold-line {
    background-color: var(--status-flooding);
}

.threshold.severe:hover .threshold-line::before,
.threshold.severe:hover .threshold-line::after,
.threshold.severe:focus .threshold-line::before,
.threshold.severe:focus .threshold-line::after {
    background-color: var(--status-flooding);
}

.threshold:focus {
    outline: none;
}

/* FIXED: Threshold tooltips - z-index increased to appear above threshold lines */
.threshold-tooltip {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 12px);
    transform: translateX(-50%) translateY(10px);
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    min-width: 220px;
    max-width: 280px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
    z-index: 1000; /* FIXED: Was 100, increased to appear above everything */
    pointer-events: none;
    text-align: left;
}

/* Tooltip arrow pointing down */
.threshold-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 8px solid transparent;
    border-top-color: var(--background);
}

.threshold-tooltip::before {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 9px solid transparent;
    border-top-color: var(--border-color);
}

.threshold:hover .threshold-tooltip,
.threshold:focus .threshold-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.threshold-tooltip strong {
    display: block;
    color: var(--primary-blue);
    font-size: 0.9rem;
    margin-bottom: var(--space-xs);
}

.threshold-tooltip p {
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.5;
    margin: 0;
}

/* Warning tooltip styling */
.threshold.warning .threshold-tooltip {
    border-color: var(--status-high);
    border-left: 4px solid var(--status-high);
}

.threshold.warning .threshold-tooltip strong {
    color: var(--status-high);
}

/* Severe tooltip styling */
.threshold.severe .threshold-tooltip {
    border-color: var(--status-flooding);
    border-left: 4px solid var(--status-flooding);
}

.threshold.severe .threshold-tooltip strong {
    color: var(--status-flooding);
}

.gauge-scale {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
    font-family: var(--font-mono);
    padding: var(--space-xs) 0;
    min-width: 45px;
}

.gauge-scale-left {
    text-align: right;
    padding-right: var(--space-sm);
}

.gauge-scale-right {
    text-align: left;
    padding-left: var(--space-sm);
}

/* ============================================
   CHART SECTION
   ============================================ */

.chart-section {
    background-color: var(--background-alt);
    padding: var(--space-2xl) 0;
    border-bottom: 1px solid var(--border-color);
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

.chart-section h2 {
    font-size: 1.25rem;
    color: var(--primary-blue);
    font-weight: 700;
    margin: 0;
}

/* Time Range Selector */
.time-range-selector {
    display: flex;
    gap: var(--space-xs);
    background: var(--background);
    padding: var(--space-xs);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.time-range-btn {
    padding: var(--space-sm) var(--space-md);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-sans);
}

.time-range-btn:hover {
    background: var(--background-alt);
    color: var(--primary-blue);
}

.time-range-btn:focus {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

.time-range-btn.active {
    background: var(--primary-blue);
    color: white;
    box-shadow: var(--shadow-sm);
}

.time-range-btn.active:hover {
    background: var(--dark-blue);
}

.chart-container {
    background-color: var(--background);
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    position: relative;
    height: 320px;
}

.chart-note {
    margin-top: var(--space-md);
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: center;
    min-height: 1.5em;
}

/* ============================================
   WARNINGS SECTION
   ============================================ */

.warnings-section {
    background-color: var(--background);
    padding: var(--space-2xl) 0;
    border-bottom: 1px solid var(--border-color);
}

.warnings-section h2 {
    font-size: 1.25rem;
    color: var(--primary-blue);
    margin-bottom: var(--space-lg);
    font-weight: 700;
}

.warning-item {
    background-color: var(--light-blue);
    border-left: 4px solid var(--primary-blue);
    padding: var(--space-lg);
    margin-bottom: var(--space-md);
    border-radius: var(--radius-md);
}

.warning-item.severe {
    background-color: var(--status-flooding-bg);
    border-left-color: var(--status-flooding);
}

.warning-item.warning {
    background-color: var(--status-high-bg);
    border-left-color: var(--status-high);
}

.warning-item.alert {
    background-color: var(--status-elevated-bg);
    border-left-color: var(--status-elevated);
}

.warning-item h3 {
    font-size: 1rem;
    color: var(--primary-blue);
    margin-bottom: var(--space-sm);
    font-weight: 600;
}

.warning-item.severe h3 {
    color: var(--status-flooding);
}

.warning-item.warning h3 {
    color: var(--status-high);
}

.warning-item.alert h3 {
    color: var(--status-elevated);
}

.warning-item p {
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
    font-size: 0.95rem;
}

.warning-item a {
    color: var(--accent-blue);
    text-decoration: none;
    font-weight: 500;
}

.warning-item a:hover {
    text-decoration: underline;
}

.no-warnings {
    padding: var(--space-lg);
    background-color: var(--status-normal-bg);
    border-left: 4px solid var(--status-normal);
    border-radius: var(--radius-md);
    color: #166534;
    font-weight: 500;
}

/* ============================================
   THRESHOLDS SECTION
   ============================================ */

.thresholds-section {
    background-color: var(--background-alt);
    padding: var(--space-2xl) 0;
    border-bottom: 1px solid var(--border-color);
}

.thresholds-section h2 {
    font-size: 1.25rem;
    color: var(--primary-blue);
    margin-bottom: var(--space-xl);
    font-weight: 700;
}

.thresholds-table {
    width: 100%;
    border-collapse: collapse;
    background-color: var(--background);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    margin-bottom: var(--space-lg);
}

.thresholds-table thead {
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--dark-blue) 100%);
    color: white;
}

.thresholds-table th {
    padding: var(--space-md) var(--space-lg);
    text-align: left;
    font-weight: 600;
    font-size: 0.875rem;
    letter-spacing: 0.025em;
}

.thresholds-table td {
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-color);
}

.thresholds-table tbody tr:hover {
    background-color: var(--light-blue);
}

.thresholds-table td:first-child {
    font-weight: 600;
    font-family: var(--font-mono);
    color: var(--primary-blue);
    font-size: 0.95rem;
}

.note {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.7;
}

.note a {
    color: var(--accent-blue);
    text-decoration: none;
    font-weight: 500;
}

.note a:hover {
    text-decoration: underline;
}

/* ============================================
   FAQ SECTION
   ============================================ */

.faq-section {
    background-color: var(--background);
    padding: var(--space-2xl) 0;
    border-bottom: 1px solid var(--border-color);
}

.faq-section h2 {
    font-size: 1.25rem;
    color: var(--primary-blue);
    margin-bottom: var(--space-xl);
    font-weight: 700;
}

.faq-item {
    margin-bottom: var(--space-xl);
    padding-bottom: var(--space-lg);
    border-bottom: 1px solid var(--border-color);
}

.faq-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.faq-item h3 {
    font-size: 1.1rem;
    color: var(--primary-blue);
    margin-bottom: var(--space-sm);
    font-weight: 600;
}

.faq-item p {
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.7;
}

.faq-item a {
    color: var(--accent-blue);
    text-decoration: none;
}

.faq-item a:hover {
    text-decoration: underline;
}

/* ============================================
   HISTORY SECTION
   ============================================ */

.history-section {
    background-color: var(--background-alt);
    padding: var(--space-2xl) 0;
}

.history-section h2 {
    font-size: 1.25rem;
    color: var(--primary-blue);
    margin-bottom: var(--space-lg);
    font-weight: 700;
}

.history-list {
    list-style: none;
    margin-bottom: var(--space-lg);
}

.history-list li {
    padding: var(--space-md) 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.95rem;
    display: flex;
    gap: var(--space-sm);
}

.history-list li:last-child {
    border-bottom: none;
}

.history-list strong {
    color: var(--primary-blue);
    font-weight: 600;
    white-space: nowrap;
}

.history-context {
    color: var(--text-secondary);
    line-height: 1.7;
    font-size: 0.9rem;
}

/* ============================================
   FOOTER
   ============================================ */

.site-footer {
    background: linear-gradient(135deg, var(--dark-blue) 0%, #0a1628 100%);
    color: rgba(255, 255, 255, 0.9);
    padding: var(--space-2xl) 0 var(--space-xl);
}

.site-footer h3 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: var(--space-md);
    color: white;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.attribution {
    margin-bottom: var(--space-xl);
    padding-bottom: var(--space-xl);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.attribution p {
    margin-bottom: var(--space-sm);
    font-size: 0.875rem;
}

.disclaimer {
    font-size: 0.8rem;
    opacity: 0.7;
}

.meta-info {
    margin-bottom: var(--space-xl);
    font-size: 0.875rem;
    opacity: 0.8;
}

.useful-links ul {
    list-style: none;
    display: grid;
    gap: var(--space-sm);
}

.useful-links a {
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    transition: color 0.2s ease;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
}

.useful-links a::before {
    content: '→';
    opacity: 0.5;
}

.useful-links a:hover {
    color: white;
}

.footer-bottom {
    margin-top: var(--space-xl);
    padding-top: var(--space-lg);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.8rem;
    opacity: 0.7;
}

.footer-bottom a {
    color: rgba(255, 255, 255, 0.8);
}

/* Loading state */
.loading {
    color: var(--text-secondary);
    font-style: italic;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 768px) {
    .site-header h1 {
        font-size: 1.35rem;
    }

    .status-text {
        font-size: 1rem;
    }

    .level-value {
        font-size: 3.5rem;
    }

    .road-status-grid {
        grid-template-columns: 1fr;
    }

    .upstream-grid {
        grid-template-columns: 1fr;
    }
    
    .upstream-level {
        font-size: 1.5rem;
    }

    .rainfall-data {
        gap: var(--space-xl);
    }

    .gauge {
        flex-direction: column;
        align-items: center;
    }

    .gauge-track-wrapper {
        height: 280px;
        width: 100%;
        max-width: 100%;
    }

    .gauge-scale {
        flex-direction: row;
        justify-content: space-between;
        width: 100%;
        max-width: 400px;
        padding: var(--space-sm) 0 0;
    }

    .gauge-scale-left {
        display: none;
    }

    .gauge-scale-right {
        display: flex;
        text-align: center;
        padding: var(--space-sm) 0 0;
    }

    /* Mobile tooltips - position to the right to avoid cutoff */
    .threshold-tooltip {
        left: calc(100% + 10px);
        bottom: auto;
        top: 50%;
        transform: translateY(-50%) translateX(10px);
        min-width: 180px;
        max-width: 200px;
    }

    .threshold-tooltip::after {
        top: 50%;
        left: -8px;
        transform: translateY(-50%);
        border: 8px solid transparent;
        border-right-color: var(--background);
        border-top-color: transparent;
    }

    .threshold-tooltip::before {
        top: 50%;
        left: -9px;
        transform: translateY(-50%);
        border: 9px solid transparent;
        border-right-color: var(--border-color);
        border-top-color: transparent;
    }

    .threshold:hover .threshold-tooltip,
    .threshold:focus .threshold-tooltip {
        transform: translateY(-50%) translateX(0);
    }

    .chart-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .time-range-selector {
        width: 100%;
        justify-content: space-between;
    }

    .time-range-btn {
        flex: 1;
        padding: var(--space-sm) var(--space-xs);
        font-size: 0.75rem;
    }

    .chart-container {
        height: 260px;
        padding: var(--space-md);
    }

    .context-info {
        flex-direction: column;
        gap: var(--space-sm);
        text-align: center;
    }

    .thresholds-table {
        font-size: 0.875rem;
    }

    .thresholds-table th,
    .thresholds-table td {
        padding: var(--space-sm) var(--space-md);
    }

    .history-list li {
        flex-direction: column;
        gap: var(--space-xs);
    }

    .prediction-item {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-sm);
    }

    .prediction-time {
        text-align: left;
    }

    .historical-selector {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (min-width: 769px) {
    .container {
        padding: 0 var(--space-xl);
    }

    .hero {
        padding: var(--space-3xl) 0;
    }

    .level-value {
        font-size: 5rem;
    }

    .status-text {
        font-size: 1.5rem;
    }

    .chart-container {
        height: 350px;
    }

    .useful-links ul {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-md);
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .chart-section,
    .site-footer {
        page-break-inside: avoid;
    }

    .site-footer {
        background-color: transparent;
        color: black;
    }

    a {
        text-decoration: none;
    }

    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
    }

    .time-range-selector,
    .historical-selector {
        display: none;
    }
}

/* ============================================
   HIGH CONTRAST MODE SUPPORT
   ============================================ */

@media (prefers-contrast: high) {
    :root {
        --border-color: #000;
    }

    .status-dot {
        border: 2px solid currentColor;
    }

    .gauge-track {
        border-width: 3px;
    }
}

/* ============================================
   DARK MODE SUPPORT (optional)
   ============================================ */

@media (prefers-color-scheme: dark) {
    /* Uncomment below for dark mode support */
    /*
    :root {
        --background: #1a1a2e;
        --background-alt: #16213e;
        --text-primary: #eee;
        --text-secondary: #aaa;
        --border-color: #333;
        --light-blue: #1e3a5f;
    }
    */
}
