/* Donau Hochwasser Monitor - Dashboard Styles */

:root {
    --bg-body: #0d1b2a;
    --bg-card: #1b2838;
    --bg-card-hover: #213243;
    --bg-table-alt: #162231;
    --border: #2a3f55;
    --text: #e0e8f0;
    --text-secondary: #7a8ea0;
    --text-muted: #4a6070;
    --accent: #29b6f6;
    --accent-dim: #0288d1;
    --success: #4caf50;
    --success-bg: rgba(76, 175, 80, 0.1);
    --warning: #ff9800;
    --warning-bg: rgba(255, 152, 0, 0.1);
    --danger: #f44336;
    --danger-bg: rgba(244, 67, 54, 0.12);
    --info: #78909c;
    --radius: 10px;
    --shadow: 0 2px 12px rgba(0,0,0,0.3);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background: var(--bg-body);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ---- Header ---- */
.header {
    background: linear-gradient(135deg, #0d2137 0%, #1a3a5c 100%);
    border-bottom: 1px solid var(--border);
    padding: 1.2rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

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

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: -0.02em;
}

.header h1 span {
    color: var(--text);
    font-weight: 400;
}

.header-subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.status-badge::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.status-normal { background: var(--success-bg); color: var(--success); }
.status-erhoeht { background: rgba(255, 235, 59, 0.12); color: #ffee58; }
.status-warnung { background: var(--warning-bg); color: var(--warning); }
.status-alarm { background: var(--danger-bg); color: var(--danger); }

.status-alarm::before {
    animation: pulse 1.2s ease-in-out infinite;
}

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

/* ---- Main layout ---- */
.main {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* ---- Section ---- */
.section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.section-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.section-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.section-body {
    padding: 1.5rem;
}

/* ---- Station overview cards ---- */
.stations-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
}

.station-card {
    background: var(--bg-body);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
    transition: border-color 0.2s, transform 0.2s;
    cursor: default;
    position: relative;
}

.station-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.station-card.highlight {
    border-color: var(--accent);
    border-width: 2px;
}

.station-card .name {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

.station-card .value {
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1.1;
}

.station-card .unit {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.station-card .timestamp {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
}

.station-card .class-label {
    display: inline-block;
    margin-top: 0.4rem;
    font-size: 0.65rem;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

/* Water level color coding */
.level-niedrig { color: var(--info); }
.level-niedrig .class-label { background: rgba(120, 144, 156, 0.15); color: var(--info); }

.level-normal { color: var(--success); }
.level-normal .class-label { background: var(--success-bg); color: var(--success); }

.level-erhoeht { color: #ffee58; }
.level-erhoeht .class-label { background: rgba(255, 235, 59, 0.12); color: #ffee58; }

.level-warnung { color: var(--warning); }
.level-warnung .class-label { background: var(--warning-bg); color: var(--warning); }

.level-alarm { color: var(--danger); }
.level-alarm .class-label { background: var(--danger-bg); color: var(--danger); }

/* ---- River schematic ---- */
.river-schematic {
    padding: 1.5rem;
    overflow-x: auto;
}

.river-line {
    display: flex;
    align-items: center;
    min-width: 700px;
    position: relative;
    padding: 2rem 0;
}

.river-segment {
    flex: 1;
    display: flex;
    align-items: center;
    position: relative;
}

.river-flow {
    flex: 1;
    height: 4px;
    background: linear-gradient(90deg, var(--accent-dim), var(--accent));
    position: relative;
}

.river-flow::after {
    content: '';
    position: absolute;
    right: -6px;
    top: -4px;
    border: 6px solid transparent;
    border-left-color: var(--accent);
}

.travel-time {
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.river-station {
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 1;
    padding: 0 0.3rem;
    flex-shrink: 0;
}

.river-station .dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 3px solid var(--bg-card);
    box-shadow: 0 0 0 2px var(--accent);
    margin-bottom: 0.4rem;
}

.river-station.active .dot {
    width: 18px;
    height: 18px;
    background: var(--success);
    box-shadow: 0 0 0 2px var(--success), 0 0 8px var(--success);
}

.river-station .label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

.river-station .sublabel {
    font-size: 0.65rem;
    color: var(--text-secondary);
}

/* ---- Forecast iframes ---- */
.forecast-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
    gap: 1.5rem;
}

.forecast-card {
    background: var(--bg-body);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.forecast-card h3 {
    padding: 0.8rem 1rem;
    font-size: 0.9rem;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.forecast-card h3 .provider {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 400;
}

.forecast-card iframe {
    width: 100%;
    height: 500px;
    border: none;
    background: #fff;
}

/* ---- Forecast table ---- */
.table-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.table-controls label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.table-controls select {
    background: var(--bg-body);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
}

.table-controls select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ---- Forecast content: chart + table side by side ---- */
.forecast-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
}

.forecast-chart-wrap {
    position: relative;
    padding: 1rem 1.5rem;
    border-right: 1px solid var(--border);
    min-height: 350px;
}

.forecast-chart-wrap canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.chart-tooltip {
    display: none;
    position: absolute;
    background: var(--bg-card);
    border: 1px solid var(--accent);
    border-radius: 6px;
    padding: 0.5rem 0.7rem;
    font-size: 0.78rem;
    color: var(--text);
    pointer-events: none;
    z-index: 10;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.chart-tooltip .tt-time {
    color: var(--text-secondary);
    font-size: 0.7rem;
}

.chart-tooltip .tt-value {
    font-weight: 700;
    font-size: 1rem;
}

.chart-tooltip .tt-range {
    color: var(--text-muted);
    font-size: 0.7rem;
}

.forecast-table-wrap {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 500px;
}

@media (max-width: 1000px) {
    .forecast-content {
        grid-template-columns: 1fr;
    }
    .forecast-chart-wrap {
        border-right: none;
        border-bottom: 1px solid var(--border);
        min-height: 280px;
    }
}

.forecast-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.forecast-table thead th {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-weight: 600;
    text-align: left;
    padding: 0.7rem 1rem;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

.forecast-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.forecast-table tbody tr:hover {
    background: var(--bg-card-hover);
}

.forecast-table td {
    padding: 0.6rem 1rem;
    white-space: nowrap;
}

.forecast-table .td-time {
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.forecast-table .td-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    font-size: 0.95rem;
}

.forecast-table .td-range {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.forecast-table .row-alarm {
    background: var(--danger-bg);
}

.forecast-table .row-alarm .td-value {
    color: var(--danger);
}

.forecast-table .row-strasse {
    background: rgba(255, 87, 34, 0.12);
}

.forecast-table .row-strasse .td-value {
    color: #ff7043;
}

.forecast-table .row-warnung {
    background: var(--warning-bg);
}

.forecast-table .row-warnung .td-value {
    color: var(--warning);
}

.forecast-table .row-erhoeht {
    background: rgba(255, 235, 59, 0.06);
}

.forecast-table .row-erhoeht .td-value {
    color: #ffee58;
}

.forecast-table .row-peak {
    position: relative;
}

.forecast-table .row-peak::after {
    content: 'PEAK';
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--danger);
    background: var(--danger-bg);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    letter-spacing: 0.05em;
}

/* ---- Confidence bar ---- */
.confidence-bar {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    height: 6px;
    width: 60px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    vertical-align: middle;
}

.confidence-bar .fill {
    height: 100%;
    border-radius: 3px;
    background: var(--accent);
}

/* ---- Info section ---- */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.info-card {
    background: var(--bg-body);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.2rem;
}

.info-card h3 {
    font-size: 0.9rem;
    color: var(--accent);
    margin-bottom: 0.8rem;
}

.info-card p, .info-card li {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.7;
}

.info-card ul {
    list-style: none;
    padding: 0;
}

.info-card ul li::before {
    content: '~';
    color: var(--accent);
    font-weight: bold;
    margin-right: 0.5rem;
}

.level-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.level-legend .item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
}

.level-legend .swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

/* ---- Footer ---- */
.footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    border-top: 1px solid var(--border);
}

.footer a {
    color: var(--accent);
    text-decoration: none;
}

/* ---- Loading / Error states ---- */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    padding: 2rem;
    color: var(--text-secondary);
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.error-msg {
    color: var(--danger);
    padding: 1rem;
    text-align: center;
    font-size: 0.85rem;
}

/* ---- Auto-refresh indicator ---- */
.refresh-indicator {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.refresh-indicator .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    animation: blink 3s ease-in-out infinite;
}

@keyframes blink {
    0%, 80%, 100% { opacity: 1; }
    40% { opacity: 0.2; }
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
    .header {
        padding: 1rem;
    }

    .header h1 {
        font-size: 1.2rem;
    }

    .main {
        padding: 1rem;
    }

    .forecast-grid {
        grid-template-columns: 1fr;
    }

    .forecast-card iframe {
        height: 400px;
    }

    .stations-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    .station-card .value {
        font-size: 1.4rem;
    }

    .river-schematic {
        padding: 1rem;
    }
}

@media (max-width: 500px) {
    .header {
        flex-direction: column;
        align-items: flex-start;
    }

    .forecast-card iframe {
        height: 350px;
    }

    .stations-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .info-grid {
        grid-template-columns: 1fr;
    }
}
