:root {
    --bg: #eef7fb;
    --card: rgba(255, 255, 255, 0.9);
    --card-solid: #ffffff;
    --text: #102033;
    --muted: #64748b;
    --muted-light: #94a3b8;
    --line: rgba(148, 163, 184, 0.35);
    --line-strong: rgba(14, 165, 233, 0.35);
    --blue: #0ea5e9;
    --blue-dark: #0369a1;
    --green: #10b981;
    --green-dark: #047857;
    --red: #ef4444;
    --red-dark: #991b1b;
    --yellow: #f59e0b;
    --yellow-dark: #92400e;
    --gray: #64748b;
    --shadow: 0 24px 80px rgba(15, 23, 42, 0.12);
    --shadow-soft: 0 14px 40px rgba(15, 23, 42, 0.08);
    --radius: 24px;
    --radius-sm: 16px;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    font-family:
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    background:
        radial-gradient(circle at top left, rgba(14, 165, 233, 0.25), transparent 34%),
        linear-gradient(135deg, #e0f2fe 0%, #f8fafc 45%, #ecfeff 100%);
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

[hidden] {
    display: none !important;
}

.page-bg {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(120deg, rgba(14, 165, 233, 0.14), transparent 40%),
        radial-gradient(circle at 80% 20%, rgba(16, 185, 129, 0.17), transparent 34%);
}

.dam-page {
    position: relative;
    width: min(1640px, calc(100% - 32px));
    margin: 0 auto;
    padding: 42px 0;
}

/* =========================================================
   Header
========================================================= */

.dam-header {
    display: grid;
    grid-template-columns: 1fr 240px;
    gap: 24px;
    align-items: end;
    margin-bottom: 24px;
}

.dam-kicker {
    margin: 0 0 10px;
    color: var(--blue-dark);
    font-size: 13px;
    font-weight: 900;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.dam-header h1 {
    margin: 0;
    font-size: clamp(32px, 5vw, 56px);
    line-height: 1.08;
    letter-spacing: -0.04em;
}

.dam-lead {
    max-width: 760px;
    margin: 16px 0 0;
    color: var(--muted);
    font-size: 16px;
    line-height: 1.8;
}

.dam-header-mini {
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.76);
    backdrop-filter: blur(16px);
    box-shadow: var(--shadow-soft);
}

.dam-header-mini p {
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.dam-header-mini strong {
    display: block;
    font-size: 40px;
    line-height: 1;
    letter-spacing: -0.05em;
}

.dam-header-mini span {
    display: block;
    margin-top: 8px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

/* =========================================================
   Notice
========================================================= */

.notice-card {
    margin-bottom: 22px;
    padding: 18px 20px;
    border: 1px solid rgba(245, 158, 11, 0.35);
    border-radius: 20px;
    background: rgba(255, 251, 235, 0.86);
    color: #92400e;
    box-shadow: var(--shadow-soft);
}

.notice-card.error {
    border-color: rgba(239, 68, 68, 0.35);
    background: rgba(254, 226, 226, 0.86);
    color: #991b1b;
}

.notice-card strong {
    display: block;
    margin-bottom: 6px;
    font-size: 15px;
}

.notice-card p {
    margin: 0 0 10px;
    line-height: 1.7;
}

.notice-card code,
.empty-card code {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.08);
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 13px;
}

/* =========================================================
   Three Column Layout
========================================================= */

.monitor-layout {
    display: grid;
    grid-template-columns:
        minmax(330px, 0.95fr)
        minmax(390px, 1.05fr)
        minmax(360px, 0.95fr);
    gap: 22px;
    align-items: start;
}

.list-column,
.detail-column,
.chart-column {
    min-width: 0;
}

.detail-column,
.chart-column {
    position: sticky;
    top: 18px;
    align-self: start;
}

/* =========================================================
   Shared Cards
========================================================= */

.status-card,
.note-card,
.dam-list-section,
.chart-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    backdrop-filter: blur(18px);
    box-shadow: var(--shadow);
}

.status-card {
    position: relative;
    overflow: hidden;
    padding: clamp(22px, 3vw, 32px);
}

.status-card::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 12% 0%, rgba(14, 165, 233, 0.16), transparent 28%),
        radial-gradient(circle at 100% 20%, rgba(16, 185, 129, 0.12), transparent 26%);
}

.status-card > * {
    position: relative;
}

/* =========================================================
   Detail Panel
========================================================= */

.status-top {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 24px;
}

.status-label,
.metric-label {
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
}

.status-top h2 {
    margin: 0;
    font-size: clamp(24px, 3vw, 36px);
    line-height: 1.25;
    letter-spacing: -0.03em;
}

.dam-sub-info {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.6;
}

.dam-location {
    margin: 6px 0 0;
    color: var(--muted-light);
    font-size: 13px;
    line-height: 1.6;
}

.detail-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-shrink: 0;
}

.refresh-btn {
    appearance: none;
    border: 0;
    border-radius: 999px;
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--blue), var(--blue-dark));
    color: #fff;
    font-size: 14px;
    font-weight: 900;
    box-shadow: 0 12px 30px rgba(14, 165, 233, 0.28);
    transition:
        transform 0.18s ease,
        box-shadow 0.18s ease,
        opacity 0.18s ease;
}

.refresh-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 36px rgba(14, 165, 233, 0.34);
}

.refresh-btn:disabled {
    opacity: 0.55;
    cursor: wait;
    transform: none;
}

.loading {
    padding: 18px;
    border-radius: 16px;
    background: rgba(14, 165, 233, 0.08);
    color: var(--blue-dark);
    font-weight: 800;
}

.error-box {
    padding: 18px;
    border: 1px solid rgba(239, 68, 68, 0.28);
    border-radius: 16px;
    background: rgba(254, 226, 226, 0.72);
    color: #991b1b;
    font-weight: 800;
    line-height: 1.7;
}

.storage-main {
    display: grid;
    grid-template-columns: 170px 1fr;
    gap: 22px;
    align-items: center;
    padding: 24px;
    border-radius: 22px;
    background:
        linear-gradient(135deg, rgba(14, 165, 233, 0.12), rgba(16, 185, 129, 0.12)),
        rgba(255, 255, 255, 0.72);
}

.storage-rate {
    display: flex;
    align-items: baseline;
    gap: 5px;
}

.storage-rate span {
    font-size: clamp(46px, 5vw, 72px);
    line-height: 1;
    font-weight: 950;
    letter-spacing: -0.07em;
}

.storage-rate small {
    font-size: 24px;
    font-weight: 950;
    color: var(--blue-dark);
}

.water-gauge-wrap {
    min-width: 0;
}

.water-gauge {
    position: relative;
    height: 34px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.22);
    box-shadow: inset 0 2px 10px rgba(15, 23, 42, 0.08);
}

.water-gauge-fill {
    position: absolute;
    inset: 0 auto 0 0;
    min-width: 0;
    border-radius: inherit;
    background:
        linear-gradient(90deg, rgba(14, 165, 233, 0.9), rgba(16, 185, 129, 0.95));
    transition: width 0.45s ease;
}

.gauge-caption {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 14px;
    text-align: right;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    margin-top: 18px;
}

.metric-card {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.78);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
}

.metric-card p {
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
}

.metric-card strong {
    display: block;
    font-size: clamp(22px, 2.4vw, 30px);
    line-height: 1.1;
    letter-spacing: -0.04em;
    word-break: break-word;
}

.metric-card span {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 13px;
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    margin-top: 16px;
}

.meta-grid > div {
    padding: 16px 18px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.58);
}

.meta-grid p {
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.meta-grid strong {
    display: block;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-all;
}

/* =========================================================
   List Area
========================================================= */

.dam-list-section {
    padding: clamp(20px, 3vw, 28px);
}

.section-head {
    display: grid;
    grid-template-columns: 1fr minmax(280px, 420px);
    gap: 22px;
    align-items: end;
    margin-bottom: 20px;
}

.section-head.compact {
    display: block;
    margin-bottom: 16px;
}

.section-head h2 {
    margin: 0;
    font-size: clamp(24px, 3vw, 34px);
    letter-spacing: -0.04em;
}

.section-head p {
    margin: 10px 0 0;
    color: var(--muted);
    line-height: 1.7;
}

.list-tools {
    display: grid;
    grid-template-columns: 1fr 150px;
    gap: 10px;
    margin-bottom: 12px;
}

.list-tools input,
.list-tools select {
    width: 100%;
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--text);
    outline: none;
    font-size: 14px;
}

.list-tools input {
    padding: 0 15px;
}

.list-tools select {
    padding: 0 12px;
    font-weight: 700;
}

.list-tools input:focus,
.list-tools select:focus {
    border-color: var(--line-strong);
    box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.1);
}

.list-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    align-items: center;
    margin: 0 0 14px;
    color: var(--muted);
    font-size: 13px;
}

.list-meta strong {
    color: var(--text);
}

.dam-card-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.dam-card-grid.compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

/* =========================================================
   Dam Card
========================================================= */

.dam-list-card {
    appearance: none;
    display: flex;
    min-height: 156px;
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 18px;
    color: var(--text);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(248, 250, 252, 0.86));
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.055);
    transition:
        transform 0.18s ease,
        box-shadow 0.18s ease,
        border-color 0.18s ease,
        background 0.18s ease;
}

.dam-list-card.compact {
    min-height: 168px;
    padding: 15px;
    border-radius: 18px;
}

.dam-list-card:hover {
    transform: translateY(-2px);
    border-color: rgba(14, 165, 233, 0.45);
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.11);
}

.dam-list-card.is-active {
    border-color: rgba(14, 165, 233, 0.75);
    background:
        linear-gradient(135deg, rgba(14, 165, 233, 0.14), rgba(16, 185, 129, 0.10)),
        rgba(255, 255, 255, 0.96);
    box-shadow:
        0 18px 44px rgba(14, 165, 233, 0.16),
        inset 0 0 0 1px rgba(14, 165, 233, 0.18);
}

.dam-card-top {
    display: flex;
    width: 100%;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
    margin-bottom: 10px;
}

.dam-card-area {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 25px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(14, 165, 233, 0.11);
    color: var(--blue-dark);
    font-size: 12px;
    font-weight: 900;
}

.dam-card-ok {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 24px;
    padding: 4px 9px;
    border-radius: 999px;
    background: rgba(16, 185, 129, 0.13);
    color: var(--green-dark);
    font-size: 11px;
    font-weight: 900;
    white-space: nowrap;
}

.dam-list-card strong {
    display: block;
    margin-bottom: 8px;
    font-size: 18px;
    line-height: 1.35;
    letter-spacing: -0.03em;
}

.dam-list-card.compact strong {
    font-size: 17px;
}

.dam-card-river {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.55;
}

.dam-card-rate-row {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 6px 0 10px;
}

.dam-card-rate {
    display: inline-flex;
    align-items: baseline;
    gap: 3px;
    padding: 8px 10px;
    border-radius: 14px;
    border: 1px solid transparent;
    font-weight: 900;
}

.dam-card-rate-label {
    margin-right: 4px;
    font-size: 11px;
    font-weight: 900;
    opacity: 0.82;
}

.dam-card-rate strong {
    margin: 0;
    font-size: 22px;
    line-height: 1;
    letter-spacing: -0.04em;
}

.dam-card-rate small {
    font-size: 12px;
    font-weight: 900;
}

.dam-card-rate.rate-red {
    border-color: rgba(239, 68, 68, 0.28);
    background: rgba(254, 226, 226, 0.9);
    color: var(--red-dark);
}

.dam-card-rate.rate-yellow {
    border-color: rgba(245, 158, 11, 0.32);
    background: rgba(254, 243, 199, 0.95);
    color: var(--yellow-dark);
}

.dam-card-rate.rate-green {
    border-color: rgba(16, 185, 129, 0.28);
    background: rgba(220, 252, 231, 0.92);
    color: #166534;
}

.dam-card-rate.rate-unknown {
    border-color: rgba(148, 163, 184, 0.32);
    background: rgba(241, 245, 249, 0.95);
    color: var(--gray);
}

.dam-card-observed {
    color: var(--muted-light);
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.dam-card-observed.muted {
    color: var(--muted-light);
}

.dam-card-id {
    display: block;
    margin-top: auto;
    color: var(--muted-light);
    font-size: 12px;
    line-height: 1.4;
    word-break: break-all;
}

.empty-card {
    padding: 22px;
    border: 1px dashed var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.55);
    color: var(--muted);
    line-height: 1.7;
}

/* =========================================================
   History Chart
========================================================= */

.chart-card {
    padding: 22px;
}

.chart-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.chart-head h2 {
    margin: 0;
    font-size: 20px;
    color: var(--text);
    letter-spacing: -0.03em;
}

.chart-head p {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.7;
}

.chart-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
    flex-shrink: 0;
}

.chart-controls select {
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--text);
    font-size: 13px;
    font-weight: 800;
    outline: none;
}

.chart-controls select:focus {
    border-color: var(--line-strong);
    box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.1);
}

.chart-status {
    margin: 8px 0 12px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    line-height: 1.6;
}

.chart-status.error {
    color: var(--red-dark);
}

.chart-canvas-wrap {
    position: relative;
    min-height: 300px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.72);
}

.chart-canvas-wrap canvas {
    width: 100% !important;
    height: 300px !important;
}

.chart-empty {
    display: none;
    margin-bottom: 12px;
    padding: 24px 18px;
    border: 1px dashed var(--line);
    border-radius: 18px;
    background: rgba(248, 250, 252, 0.78);
    color: var(--muted);
    text-align: center;
    font-size: 14px;
    line-height: 1.7;
}

.chart-empty.is-visible {
    display: block;
}

.chart-summary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 16px;
}

.chart-summary-item {
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.62);
}

.chart-summary-item p {
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.chart-summary-item strong {
    display: block;
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

/* =========================================================
   Note
========================================================= */

.note-card {
    margin-top: 18px;
    padding: 22px;
}

.note-card h2 {
    margin: 0 0 10px;
    font-size: 20px;
}

.note-card p {
    margin: 0;
    color: var(--muted);
    line-height: 1.8;
}

/* =========================================================
   Responsive
========================================================= */

@media (max-width: 1500px) {
    .dam-page {
        width: min(1460px, calc(100% - 28px));
    }

    .monitor-layout {
        grid-template-columns:
            minmax(300px, 0.9fr)
            minmax(360px, 1fr)
            minmax(340px, 0.95fr);
        gap: 18px;
    }

    .dam-card-grid.compact {
        grid-template-columns: 1fr;
    }

    .storage-main {
        grid-template-columns: 1fr;
        gap: 18px;
    }

    .gauge-caption {
        text-align: left;
    }
}

@media (max-width: 1180px) {
    .dam-page {
        width: min(100% - 26px, 1360px);
    }

    .monitor-layout {
        grid-template-columns: minmax(340px, 0.9fr) minmax(460px, 1.1fr);
        gap: 18px;
    }

    .chart-column {
        grid-column: 1 / -1;
        position: static;
    }

    .detail-column {
        position: sticky;
        top: 18px;
    }

    .chart-card {
        margin-top: 0;
    }

    .chart-head {
        align-items: center;
    }

    .chart-canvas-wrap {
        min-height: 320px;
    }

    .chart-canvas-wrap canvas {
        height: 320px !important;
    }
}

@media (max-width: 920px) {
    .dam-page {
        width: min(100% - 22px, 1360px);
        padding: 28px 0;
    }

    .dam-header {
        grid-template-columns: 1fr;
    }

    .dam-header-mini {
        width: 100%;
    }

    .monitor-layout {
        display: flex;
        flex-direction: column;
        gap: 18px;
    }

    .list-column,
    .detail-column,
    .chart-column {
        position: static;
        width: 100%;
    }

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

    .status-top {
        flex-direction: column;
    }

    .detail-actions,
    .refresh-btn {
        width: 100%;
    }

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

    .chart-head {
        display: block;
    }

    .chart-controls {
        justify-content: flex-start;
        margin-top: 14px;
    }

    .chart-summary-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 680px) {
    .list-tools {
        grid-template-columns: 1fr;
    }

    .dam-card-grid,
    .dam-card-grid.compact {
        grid-template-columns: 1fr;
    }

    .metric-grid,
    .meta-grid {
        grid-template-columns: 1fr;
    }

    .status-card,
    .note-card,
    .dam-list-section,
    .chart-card {
        border-radius: 20px;
    }

    .status-card,
    .dam-list-section,
    .chart-card {
        padding: 18px;
    }

    .dam-header h1 {
        font-size: 34px;
    }

    .dam-lead {
        font-size: 14px;
    }

    .storage-main {
        padding: 22px;
    }

    .storage-rate span {
        font-size: 58px;
    }

    .dam-list-card.compact {
        min-height: 154px;
    }

    .chart-controls {
        display: grid;
        grid-template-columns: 1fr;
    }

    .chart-controls select {
        width: 100%;
    }

    .chart-canvas-wrap {
        min-height: 250px;
        padding: 10px;
    }

    .chart-canvas-wrap canvas {
        height: 250px !important;
    }
}

@media (max-width: 420px) {
    .dam-page {
        width: min(100% - 16px, 1360px);
        padding: 20px 0;
    }

    .dam-card-top {
        align-items: flex-start;
        flex-direction: column;
    }

    .dam-card-rate-row {
        align-items: flex-start;
        flex-direction: column;
    }

    .status-top h2 {
        font-size: 25px;
    }

    .storage-rate span {
        font-size: 52px;
    }
}