/* ADB-FDC Dashboard - styles */
:root {
    --bg: #f4f6fa;
    --card-bg: #ffffff;
    --border: #e2e6ee;
    --text: #1f2937;
    --muted: #6b7280;
    --accent: #1f5b8a;
    --accent-dark: #134168;

    /* QCVN08:2023 water-quality classes */
    --class-a: #2196f3;   /* A - Good */
    --class-b: #4caf50;   /* B - Moderate */
    --class-c: #ff9800;   /* C - Poor */
    --class-d: #e53935;   /* D - Very poor */

    /* Degradation */
    --de:      #d32f2f;
    --no-de:   #2e7d32;
    --no-de-w: #f9a825;   /* "no degradation, water-quality basis only" (N*) */

    --shadow: 0 1px 3px rgba(18, 38, 63, 0.08);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 Helvetica, Arial, sans-serif, "Apple Color Emoji",
                 "Segoe UI Emoji";
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
}

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 12px 22px;
    background: linear-gradient(180deg, var(--accent-dark), var(--accent));
    color: #fff;
    gap: 16px;
    box-shadow: var(--shadow);
}

.topbar .title strong {
    color: #ffd54f;
    margin-right: 4px;
}

.topbar .subtitle {
    margin-left: 12px;
    font-size: 13px;
    opacity: 0.85;
    font-weight: 400;
}

.controls {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.controls label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.92);
}

.controls select {
    padding: 6px 10px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    background: #ffffff;
    color: var(--text);
    font-size: 14px;
    min-width: 200px;
}

.view-toggle {
    display: inline-flex;
    background: rgba(255, 255, 255, 0.12);
    padding: 3px;
    border-radius: 6px;
}

.toggle-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    padding: 7px 14px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.toggle-btn:hover { background: rgba(255, 255, 255, 0.1); }
.toggle-btn.active {
    background: #fff;
    color: var(--accent-dark);
    font-weight: 600;
}

/* Layout */
.grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
    padding: 16px;
}

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

.card-header {
    padding: 12px 16px 0;
}
.card-header h2 {
    margin: 0;
    font-size: 16px;
    color: var(--accent-dark);
}
.card-header p {
    margin: 4px 0 0;
}
.card-body { padding: 12px 16px 16px; }
.muted { color: var(--muted); font-size: 12.5px; }

/* Map */
.map-card { position: relative; padding: 0; }
#map {
    width: 100%;
    height: min(62vh, 640px);
    min-height: 400px;
    border-bottom: 1px solid var(--border);
}

/* Playable time slider (water-quality time series) */
.time-control {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, #f4f6fb 0%, #fafbfd 100%);
}
.tc-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
}
.tc-btn {
    background: #ffffff;
    border: 1px solid var(--border);
    color: var(--accent-dark);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tc-btn:hover { background: #eef2f7; }
.tc-btn.tc-play {
    background: var(--accent-dark);
    color: #fff;
    border-color: var(--accent-dark);
    width: 34px;
    height: 34px;
    font-size: 14px;
}
.tc-btn.tc-play:hover { background: var(--accent); }
.tc-btn.tc-play.playing { background: #c62828; border-color: #c62828; }
.tc-btn.tc-play.playing:hover { background: #b71c1c; }
.tc-speed {
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #ffffff;
    color: var(--text);
    font-size: 12.5px;
    cursor: pointer;
}
.tc-slider {
    flex: 1;
    min-width: 100px;
    accent-color: var(--accent-dark);
    cursor: pointer;
}
.tc-date {
    min-width: 86px;
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-dark);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: #fafbfd;
    font-size: 12.5px;
}
.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.legend-swatch {
    width: 16px; height: 16px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.hint {
    margin: 8px 16px 12px;
    color: var(--muted);
    font-size: 12.5px;
}

/* Detail panel */
.detail-card {
    display: flex;
    flex-direction: column;
    max-height: calc(min(62vh, 640px) + 102px);
}
.detail-card .card-body {
    overflow-y: auto;
}
.empty-state {
    color: var(--muted);
    font-style: italic;
    padding-top: 6px;
}

.detail-meta {
    display: grid;
    grid-template-columns: max-content 1fr;
    column-gap: 12px;
    row-gap: 4px;
    margin-bottom: 14px;
    font-size: 13px;
}
.detail-meta dt {
    font-weight: 600;
    color: var(--muted);
}
.detail-meta dd { margin: 0; word-break: break-word; }

/* "Back to overview" button shown above station details */
.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #eef4fb;
    border: 1px solid #c8d6e8;
    color: var(--accent-dark);
    border-radius: 4px;
    padding: 5px 10px;
    font-size: 12.5px;
    cursor: pointer;
    margin-bottom: 12px;
    transition: background 0.15s, border-color 0.15s;
}
.back-btn:hover {
    background: #dde8f6;
    border-color: #9eb6d4;
}

/* Basin overview card content */
.overview-card .overview-vn-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent-dark);
    margin-bottom: 6px;
}
.overview-summary {
    margin: 0 0 12px;
    text-align: justify;
    line-height: 1.55;
    color: var(--text);
}
.overview-heading {
    margin: 12px 0 4px;
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
}
.overview-highlights {
    margin: 0 0 10px;
    padding-left: 18px;
    font-size: 13px;
}
.overview-highlights li { margin: 2px 0; }
.overview-bar {
    height: 18px;
    border-radius: 4px;
    margin-top: 4px;
}
.overview-bar-legend {
    margin-top: 4px;
    font-size: 12px;
}

.status-pill {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 12px;
    color: #fff;
    letter-spacing: 0.3px;
}
.status-pill.DE { background: var(--de); }
.status-pill.N-star, .status-pill.N { background: var(--no-de); }
.status-pill.unknown { background: var(--muted); }

.class-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 12px;
    color: #fff;
}
.class-pill.A { background: var(--class-a); }
.class-pill.B { background: var(--class-b); }
.class-pill.C { background: var(--class-c); }
.class-pill.D { background: var(--class-d); }

.yearly-mini {
    margin-top: 4px;
    font-size: 12px;
}
.yearly-mini table {
    width: 100%;
    border-collapse: collapse;
}
.yearly-mini th, .yearly-mini td {
    padding: 4px 6px;
    border-bottom: 1px solid var(--border);
    text-align: right;
}
.yearly-mini th { text-align: center; }
.yearly-mini td:first-child { text-align: left; font-weight: 600; }
.bar {
    display: flex;
    height: 14px;
    border-radius: 3px;
    overflow: hidden;
    margin-top: 2px;
}
.bar > span { display: inline-block; }
.bar > span.A { background: var(--class-a); }
.bar > span.B { background: var(--class-b); }
.bar > span.C { background: var(--class-c); }
.bar > span.D { background: var(--class-d); }

/* River summary chart */
.river-summary, .stations-table, .fdc-card, .upstream-card {
    margin: 0 16px 16px;
}
.chart-wrap {
    position: relative;
    width: 100%;
    height: 380px;
    overflow: hidden;
}

.fdc-yearly-wrap {
    height: auto;
    min-height: 380px;
    overflow: visible;
    display: flex;
    flex-direction: column;
    padding-bottom: 4px;
}

.fdc-yearly-canvas-wrap {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    height: 320px;
    min-height: 280px;
}

.fdc-yearly-legend {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px 18px;
    padding: 10px 8px 18px;
    font-size: 12px;
    line-height: 1.4;
    color: var(--text);
}

.fdc-yearly-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.fdc-yearly-legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* Upstream -> downstream profile */
.upstream-axis-labels {
    font-size: 12px;
    color: var(--accent-dark);
    font-weight: 600;
    padding: 0 2px;
}
.upstream-axis-labels.up-top    { margin: 0 0 4px 0; }
.upstream-axis-labels.down-bottom { margin: 6px 0 0 0; }

.upstream-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    margin-top: 8px;
    font-size: 12px;
    color: var(--text);
}
.upstream-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.upstream-legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    display: inline-block;
}
.upstream-chart-wrap {
    position: relative;
    width: 100%;
    min-height: 220px;
}
.chart-wrap h3 {
    margin: 0 0 6px;
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
}

.chart-wrap .chart-note {
    margin: 0 0 8px;
    font-size: 12px;
    line-height: 1.45;
}

/* Tables */
.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
th, td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    text-align: right;
    white-space: nowrap;
}
th { background: #f8fafc; text-align: center; font-weight: 600; color: var(--muted); }
td:nth-child(1), td:nth-child(2) { text-align: left; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f0f6ff; }
tbody tr.selected { background: #dbeafe; }

/* FDC card */
.fdc-controls {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.fdc-controls select { min-width: 240px; }
.fdc-thresholds {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    font-size: 13px;
}
.fdc-thresholds .tag {
    background: #eef2f7;
    padding: 4px 10px;
    border-radius: 4px;
}
.fdc-thresholds .tag strong { color: var(--accent-dark); }

.fdc-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.fdc-card .table-wrap {
    margin-top: 4px;
}

@media (max-width: 1100px) {
    .grid { grid-template-columns: 1fr; }
    .fdc-grid { grid-template-columns: 1fr; }
    .detail-card { max-height: none; }
}

.footer {
    text-align: center;
    padding: 16px;
    font-size: 12px;
    color: var(--muted);
}
