:root {
    color-scheme: light;
    --bg: #f3f6f8;
    --card: #ffffff;
    --text: #17202a;
    --muted: #64748b;
    --border: #dfe7ec;
    --normal: #16855b;
    --warning: #c77c00;
    --critical: #c0392b;
    --accent: #1769aa;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}

.page {
    max-width: 1120px;
    margin: 0 auto;
    padding: 20px 14px 40px;
}

.header {
    margin-bottom: 18px;
}

.header h1 {
    margin: 0 0 5px;
    font-size: 1.8rem;
}

.header p {
    margin: 0;
    color: var(--muted);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.header-links {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.project-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    padding: 9px 14px;
    border-radius: 999px;
    background: #ffffff;
    border: 1px solid var(--accent);
    color: var(--accent);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 700;
}

.project-link:hover {
    background: #eaf4fb;
}

.station-card,
.chart-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
}

.station-card {
    padding: 18px;
    margin-bottom: 18px;
}

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

.station-name {
    font-size: 1.18rem;
    font-weight: 700;
}

.station-code {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.92rem;
}

.status {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 7px 12px;
    font-weight: 700;
    white-space: nowrap;
}

.status-normal {
    background: #e7f7ef;
    color: var(--normal);
}

.status-warning {
    background: #fff4d7;
    color: var(--warning);
}

.status-critical {
    background: #fde9e7;
    color: var(--critical);
}

.status-unknown {
    background: #eef2f6;
    color: var(--muted);
}

.metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.metric {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 13px;
    min-height: 96px;
}

.metric-label {
    color: var(--muted);
    font-size: 0.88rem;
    margin-bottom: 6px;
}

.metric-value {
    font-size: 1.45rem;
    font-weight: 750;
    line-height: 1.2;
}

.metric-unit {
    font-size: 0.85rem;
    color: var(--muted);
    margin-top: 4px;
}

.secondary {
    margin-top: 13px;
    display: flex;
    flex-wrap: wrap;
    gap: 14px 24px;
    color: var(--muted);
    font-size: 0.93rem;
}

.controls {
    display: flex;
    gap: 8px;
    margin: 0 0 14px;
    flex-wrap: wrap;
}

.range-button {
    appearance: none;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    padding: 9px 13px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 650;
}

.range-button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.chart-card {
    padding: 16px;
    margin-bottom: 18px;
}

.chart-card h2 {
    font-size: 1.05rem;
    margin: 0 0 4px;
}

.chart-note {
    color: var(--muted);
    font-size: 0.86rem;
    margin-bottom: 12px;
}

.current-note {
    margin-top: 8px;
    color: var(--muted);
    font-size: 0.82rem;
}

.chart-wrap {
    position: relative;
    height: 380px;
}

.station-thresholds {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.threshold-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
}

.threshold-card.station-a {
    border-top: 4px solid #1e88e5;
}

.threshold-card.station-b {
    border-top: 4px solid #e91e63;
}

.threshold-title {
    font-size: 1rem;
    font-weight: 750;
    margin-bottom: 4px;
}

.threshold-code {
    color: var(--muted);
    font-size: 0.86rem;
    margin-bottom: 12px;
}

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

.threshold-group {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
}

.threshold-group-title {
    font-weight: 700;
    margin-bottom: 8px;
}

.threshold-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 5px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.threshold-row:last-child {
    border-bottom: 0;
}

.threshold-value {
    font-weight: 700;
    white-space: nowrap;
}

.footer {
    color: var(--muted);
    font-size: 0.84rem;
    line-height: 1.6;
    margin-top: 12px;
}

.error {
    background: #fde9e7;
    border: 1px solid #f1b5af;
    color: #8f241b;
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 12px;
    display: none;
}

@media (max-width: 760px) {
    .page {
        padding-top: 14px;
    }

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

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

    .header-links {
        width: 100%;
        justify-content: flex-start;
    }

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

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

    .chart-wrap {
        height: 320px;
    }

    .station-thresholds {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 420px) {
    .metrics {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .metric {
        padding: 11px;
        min-height: 90px;
    }

    .metric-value {
        font-size: 1.25rem;
    }

    .chart-wrap {
        height: 285px;
    }

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

.refresh-button {
    margin-left: auto;
}

.auto-refresh-note {
    font-size: 0.86rem;
}

@media (max-width: 760px) {
    .refresh-button {
        margin-left: 0;
    }
}


.preset-controls {
    display: flex;
    gap: 8px;
}

.date-range-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 150px;
}

.selected-range-label {
    min-height: 0;
    margin: -5px 0 12px;
    color: var(--accent);
    font-size: 0.88rem;
    font-weight: 650;
}

.selected-range-label:empty {
    display: none;
}

.date-range-dialog {
    width: min(92vw, 410px);
    border: 0;
    border-radius: 16px;
    padding: 0;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
}

.date-range-dialog::backdrop {
    background: rgba(15, 23, 42, 0.48);
}

.date-dialog-form {
    display: grid;
    gap: 12px;
    padding: 18px;
}

.date-dialog-head,
.calendar-nav,
.calendar-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.date-dialog-head {
    font-size: 1.05rem;
}

.dialog-close,
.calendar-nav-button {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.dialog-close {
    font-size: 1.7rem;
    line-height: 1;
}

.calendar-nav-button {
    width: 42px;
    height: 42px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    font-size: 1.55rem;
    line-height: 1;
}

.calendar-nav-button:disabled {
    opacity: 0.3;
    cursor: default;
}

.date-dialog-note {
    margin: 0;
    color: var(--muted);
    font-size: 0.84rem;
    line-height: 1.5;
}

.calendar-weekdays,
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 3px;
}

.calendar-weekdays span {
    padding: 5px 0;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 700;
    text-align: center;
}

.calendar-day,
.calendar-blank {
    aspect-ratio: 1;
    min-width: 0;
}

.calendar-day {
    appearance: none;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-weight: 650;
    cursor: pointer;
}

.calendar-day:hover:not(:disabled) {
    background: #eef4f8;
}

.calendar-day.today {
    outline: 1px solid var(--accent);
    outline-offset: -2px;
}

.calendar-day.in-range {
    border-radius: 4px;
    background: #dbeafe;
}

.calendar-day.range-start,
.calendar-day.range-end {
    background: var(--accent);
    color: #fff;
}

.calendar-day:disabled {
    color: #c4ccd4;
    cursor: default;
}

.calendar-selection {
    min-height: 42px;
    display: flex;
    align-items: center;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f8fafc;
    color: var(--muted);
    font-size: 0.84rem;
    line-height: 1.4;
}

.calendar-actions {
    margin-top: 2px;
}

.calendar-actions .range-button {
    min-width: 110px;
}

.calendar-apply:disabled,
.date-apply-button:disabled {
    opacity: 0.45;
    cursor: default;
}

@media (max-width: 760px) {
    .controls {
        align-items: center;
    }

    .preset-controls {
        width: 100%;
    }

    .preset-controls .range-button {
        flex: 1 1 0;
    }

    .date-range-button,
    .refresh-button {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
        justify-content: center;
    }

    .date-range-dialog {
        width: min(96vw, 410px);
    }

    .date-dialog-form {
        padding: 14px;
    }
}



/* Compact date-range calendar: keep the full picker visible without internal scrolling. */
.date-range-dialog {
    max-height: calc(100dvh - 20px);
    overflow: hidden;
}

.date-dialog-form {
    gap: 8px;
    padding: 14px 16px;
}

.date-dialog-head {
    font-size: 1rem;
}

.date-dialog-note {
    line-height: 1.35;
}

.calendar-nav-button {
    width: 36px;
    height: 36px;
    font-size: 1.35rem;
}

.calendar-weekdays span {
    padding: 2px 0;
}

.calendar-grid {
    gap: 2px;
}

.calendar-day,
.calendar-blank {
    aspect-ratio: auto;
    height: 38px;
}

.calendar-selection {
    min-height: 36px;
    padding: 7px 10px;
}

.calendar-actions .range-button {
    padding-top: 8px;
    padding-bottom: 8px;
}

@media (max-width: 760px) {
    .date-range-dialog {
        width: min(94vw, 390px);
        max-height: calc(100dvh - 12px);
    }

    .date-dialog-form {
        gap: 6px;
        padding: 12px;
    }

    .date-dialog-note {
        font-size: 0.78rem;
    }

    .calendar-day,
    .calendar-blank {
        height: 36px;
    }

    .calendar-selection {
        min-height: 34px;
        padding: 6px 9px;
        font-size: 0.8rem;
    }
}

@media (max-width: 420px) {
    .date-range-dialog {
        width: min(96vw, 370px);
    }

    .date-dialog-form {
        padding: 10px;
    }

    .calendar-day,
    .calendar-blank {
        height: 34px;
    }
}

/* Compact date-range calendar override */
.date-range-dialog {
    width: min(94vw, 380px);
    max-height: calc(100vh - 12px);
    overflow: hidden;
}

.date-dialog-form {
    gap: 7px;
    padding: 12px;
}

.date-dialog-head {
    font-size: 1rem;
}

.date-dialog-note {
    font-size: 0.78rem;
    line-height: 1.35;
}

.calendar-nav {
    gap: 8px;
}

.calendar-nav-button {
    width: 34px;
    height: 34px;
    font-size: 1.25rem;
    border-radius: 9px;
}

.calendar-weekdays,
.calendar-grid {
    gap: 2px;
}

.calendar-weekdays span {
    padding: 2px 0;
    font-size: 0.7rem;
}

.calendar-day,
.calendar-blank {
    aspect-ratio: auto;
    height: 32px;
}

.calendar-day {
    border-radius: 7px;
    font-size: 0.92rem;
}

.calendar-selection {
    min-height: 34px;
    padding: 7px 9px;
    font-size: 0.78rem;
}

.calendar-actions {
    margin-top: 0;
}

.calendar-actions .range-button {
    min-width: 96px;
    padding: 8px 10px;
}

@media (max-width: 760px) {
    .date-range-dialog {
        width: min(96vw, 380px);
        max-height: calc(100vh - 8px);
    }

    .date-dialog-form {
        gap: 6px;
        padding: 10px;
    }

    .date-dialog-head {
        font-size: 0.98rem;
    }

    .dialog-close {
        font-size: 1.45rem;
    }

    .date-dialog-note {
        font-size: 0.75rem;
        line-height: 1.3;
    }

    .calendar-day,
    .calendar-blank {
        height: 30px;
    }

    .calendar-day {
        font-size: 0.9rem;
    }

    .calendar-selection {
        min-height: 32px;
        padding: 6px 8px;
    }

    .calendar-actions .range-button {
        padding: 7px 9px;
    }
}

/* Responsive dashboard navigation */
.dashboard-menu-button{display:none;appearance:none;border:1px solid var(--border);background:#fff;color:var(--accent);border-radius:10px;width:44px;height:44px;font-size:1.45rem;cursor:pointer}
@media(max-width:760px){.header-top{position:relative;flex-direction:row;align-items:flex-start}.dashboard-menu-button{display:block;margin-left:auto;flex:0 0 44px}.header-links{display:none;position:absolute;z-index:1000;right:0;top:52px;width:min(300px,calc(100vw - 28px));padding:9px;background:#fff;border:1px solid var(--border);border-radius:13px;box-shadow:0 10px 28px rgba(15,23,42,.18)}.header-links.is-open{display:grid;gap:7px}.header-links .project-link{width:100%;border-radius:9px;padding:11px 12px}}
