* {
    box-sizing: border-box;
    font-weight: 700;
}

html,
body {
    min-height: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

body {
    margin: 0;
    color: #17202a;
    background: #f5f7f9;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans TC", sans-serif;
    font-weight: 700;
}

input,
button,
select,
textarea {
    font: inherit;
    font-weight: 700;
}

.receive-time--green {
    color: #138a36;
}

.receive-time--red {
    color: #d00000;
}

.receive-time--black {
    color: #000;
}

.receive-time .meta-label {
    color: inherit;
}

body > form {
    width: min(1180px, calc(100% - 32px));
    margin: 24px auto;
}

.page-shell {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    min-width: 0;
}

.device-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    width: 100%;
    min-width: 0;
    margin-bottom: 14px;
}

.device-page-header h1 {
    margin: 0;
    font-size: clamp(22px, 4vw, 30px);
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.device-page-subtitle,
.device-id {
    color: #667788;
    font-size: 13px;
    margin-top: 4px;
}

.device-card-list,
.device-card {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.device-card {
    position: relative;
    padding: 14px 14px 18px 20px;
    margin-bottom: 22px;
    border: 1px solid transparent;
    border-radius: 12px;
    box-shadow: 0 5px 18px rgba(22, 34, 51, 0.08);
}

.device-card::before {
    content: "";
    position: absolute;
    top: 14px;
    bottom: 18px;
    left: 7px;
    width: 6px;
    border-radius: 6px;
}

.device-card--yellow {
    background: #fff9dc;
    border-color: #f1df8e;
}

.device-card--yellow::before {
    background: #e0a800;
}

.device-card--yellow .monitor-panel {
    border-color: #ead782;
}

.device-card--yellow .monitor-header {
    background: #fff7cf;
    border-bottom-color: #efe0a3;
}

.device-card--yellow .monitor-title {
    color: #805d00;
}

.device-card--green {
    background: #eaf8ec;
    border-color: #a8d9ae;
}

.device-card--green::before {
    background: #2e9b4b;
}

.device-card--green .monitor-panel {
    border-color: #9fd3a7;
}

.device-card--green .monitor-header {
    background: #e2f5e5;
    border-bottom-color: #b9dfbf;
}

.device-card--green .monitor-title {
    color: #1f6d35;
}

.device-card .device-chart-panel,
.device-card .device-map-panel {
    background: rgba(255, 255, 255, 0.96);
}

.device-card:last-child {
    margin-bottom: 0;
}

.device-chart-panel,
.device-map-panel,
.device-chart,
.device-map {
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.device-map {
    height: clamp(300px, 44vw, 420px);
    border: 1px solid #e6edf3;
    border-radius: 8px;
    overflow: hidden;
}

.monitor-panel,
.panel {
    width: 100%;
    min-width: 0;
    background: #fff;
    border: 1px solid #dfe5eb;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(22, 34, 51, 0.08);
    overflow: hidden;
    margin-bottom: 14px;
}

.panel {
    padding: 14px;
}

.monitor-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 16px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid #e7edf2;
    background: #fbfcfd;
}

.monitor-main {
    flex: 1 1 520px;
    min-width: 0;
}

.monitor-title {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 0;
    margin-bottom: 8px;
}

.monitor-actions,
.topbar,
.left,
.right {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
}

.monitor-actions {
    justify-content: flex-end;
    flex: 0 1 auto;
}

.point-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.topbar {
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 14px;
    gap: 12px;
}

.monitor-action,
.right a,
.left input[type=submit] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 6px 12px;
    border-radius: 6px;
    background: #1976d2;
    color: #fff;
    border: 0;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.25;
    white-space: nowrap;
}

.monitor-action:hover,
.right a:hover,
.left input[type=submit]:hover {
    background: #145da3;
}

.monitor-action:disabled,
.left input[type=submit]:disabled {
    background: #8a97a3;
    cursor: default;
}

.monitor-action--secondary {
    background: #546e7a;
}

.monitor-action--secondary:hover {
    background: #40545d;
}

.device-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(180px, 1fr));
    gap: 8px 18px;
    color: #465564;
    font-size: 14px;
}

.device-meta > div {
    min-width: 0;
    overflow-wrap: anywhere;
}

.meta-label,
.metric-label,
.field-label {
    color: #667788;
    font-weight: 700;
    margin-right: 6px;
}

.status-text {
    display: block;
    color: #b00020;
    font-size: 13px;
    margin-top: 8px;
}

.metrics-grid,
.field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1px;
    background: #e8eef3;
}

.metric-card,
.field-card {
    min-width: 0;
    min-height: 84px;
    padding: 14px 16px;
    background: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.metric-value,
.field-value {
    display: block;
    margin-top: 6px;
    color: #17202a;
    font-weight: 800;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.metric-value {
    font-size: 24px;
}

.field-value {
    font-size: 20px;
}

.metric-card--primary .metric-value {
    color: #1565c0;
}

.metric-card--ok .metric-value {
    color: #2e7d32;
}

.metric-card--warm .metric-value {
    color: #c45100;
}

.metric-card--aqua .metric-value {
    color: #00838f;
}

.metric-value.metric-value--green {
    color: #138a36;
}

.metric-value.metric-value--yellow {
    color: #d39b00;
}

.metric-value.metric-value--red {
    color: #d00000;
}

.coord-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 12px 20px 16px;
    color: #465564;
    background: #fff;
    overflow-wrap: anywhere;
}

.panel .title,
.panel-title {
    font-weight: 800;
    margin: 4px 0 10px;
}

.panel-chart {
    position: relative;
    height: clamp(320px, 42vw, 420px);
    overflow: hidden;
}

.panel-chart canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

.chart-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: nowrap;
    gap: 24px;
    min-width: 0;
    margin: 2px 0 8px;
    font-size: 22px;
    line-height: 1;
    white-space: nowrap;
}

.chart-legend > button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    line-height: 1;
    white-space: nowrap;
}

.chart-legend > button:hover {
    color: #1976d2;
}

.chart-legend > button.is-hidden {
    opacity: 0.35;
    text-decoration: line-through;
}

.chart-legend__swatch {
    display: inline-block;
    width: 48px;
    height: 20px;
}

.chart-legend__swatch--water {
    background: #00838f;
}

.chart-legend__swatch--signal {
    background: #1565c0;
}

.chart-legend__swatch--voltage {
    background: #546e7a;
}

#map {
    width: 100%;
    height: clamp(340px, 46vw, 430px);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #e6edf3;
}

.map-status {
    color: #465564;
    font-size: 13px;
    margin-bottom: 8px;
}

.map-popup {
    min-width: 190px;
    line-height: 1.7;
    color: #17202a;
}

.map-popup strong {
    display: block;
    margin-bottom: 4px;
}

.table-wrap {
    overflow: auto;
    border: 1px solid #e6edf3;
    border-radius: 8px;
}

table {
    width: 100%;
    min-width: 980px;
    border-collapse: collapse;
    background: #fff;
    font-size: 13px;
}

th,
td {
    border-bottom: 1px solid #e8eef3;
    padding: 8px 10px;
    text-align: left;
    white-space: nowrap;
}

th {
    color: #52616f;
    background: #f7f9fb;
    font-weight: 800;
}

.filter-item {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #465564;
    font-size: 14px;
    font-weight: 700;
    min-width: 0;
}

.filter-item input {
    min-height: 34px;
    padding: 5px 8px;
    border: 1px solid #cbd6df;
    border-radius: 6px;
    color: #17202a;
    background: #fff;
    max-width: 100%;
}

.point-mode {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    color: #465564;
    font-size: 14px;
    font-weight: 700;
    min-height: 34px;
}

.point-mode label {
    margin-left: 4px;
}

.point-label-icon {
    pointer-events: none;
    text-align: center;
}

.point-label-icon span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    min-height: 20px;
    padding: 2px 5px;
    border-radius: 4px;
    background: #17202a;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.24);
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
}

.hint {
    color: #666;
    font-size: 12px;
    margin-top: 6px;
}

#countdownBox {
    position: fixed;
    top: 10px;
    right: 20px;
    z-index: 1000;
    min-height: 34px;
    padding: 6px 10px;
    border: 0;
    border-radius: 6px;
    background: #333;
    color: #fff;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

#countdownBox:hover {
    background: #222;
}

#countdownBox.is-paused {
    background: #7a4f00;
}

@media (max-width: 900px) {
    .monitor-header {
        gap: 12px;
    }

    .monitor-actions {
        width: 100%;
        justify-content: flex-start;
    }
}

@media (max-width: 760px) {
    body > form {
        width: min(100% - 24px, 1180px);
        margin: 14px auto;
    }

    #countdownBox {
        position: static;
        width: 100%;
        margin: 0 0 12px;
    }

    .monitor-header {
        padding: 16px;
    }

    .device-page-header {
        align-items: stretch;
    }

    .device-page-header .monitor-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

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

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

    .metric-card,
    .field-card {
        padding: 12px;
        min-height: 78px;
    }

    .metric-value {
        font-size: 21px;
    }

    .field-value {
        font-size: 18px;
    }

    .topbar,
    .left,
    .right {
        width: 100%;
    }

    .filter-item {
        width: 100%;
        justify-content: space-between;
    }

    .filter-item input {
        flex: 1;
        min-width: 0;
    }

    .left input[type=submit],
    .right a,
    .monitor-action {
        flex: 1 1 auto;
        min-width: min(140px, 100%);
        text-align: center;
    }

    .panel {
        padding: 12px;
    }

    .panel-chart {
        height: 320px;
    }

    .device-chart {
        height: 300px;
    }

    .device-map {
        height: 320px;
    }

    #map {
        height: 360px;
    }
}

@media (max-width: 460px) {
    body > form {
        width: calc(100% - 8px);
        margin: 4px auto;
    }

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

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

    .device-page-header .monitor-actions {
        grid-template-columns: 1fr;
    }

    .device-card {
        padding: 7px 5px 8px 11px;
        margin-bottom: 12px;
        border-radius: 10px;
    }

    .device-card::before {
        top: 7px;
        bottom: 8px;
        left: 3px;
        width: 3px;
    }

    .monitor-panel,
    .panel {
        margin-bottom: 8px;
    }

    .monitor-header {
        gap: 8px;
        padding: 11px 10px 9px;
    }

    .monitor-title {
        margin-bottom: 5px;
        font-size: 19px;
    }

    .device-id,
    .device-meta {
        font-size: 12px;
    }

    .device-meta {
        gap: 5px;
    }

    .monitor-actions {
        gap: 5px;
    }

    .metric-card {
        min-height: 66px;
        padding: 8px 6px;
    }

    .metric-label {
        margin-right: 0;
        font-size: 12px;
        white-space: nowrap;
    }

    .metric-value {
        margin-top: 4px;
        font-size: 16px;
        white-space: nowrap;
    }

    .monitor-action,
    .right a,
    .left input[type=submit] {
        width: 100%;
        min-height: 32px;
        padding: 5px 8px;
    }

    .filter-item {
        align-items: stretch;
        flex-direction: column;
        gap: 5px;
    }

    .panel-chart {
        height: 280px;
    }

    .chart-legend {
        justify-content: flex-start;
        gap: 8px;
        margin: 1px 4px 5px;
        padding-left: 58px;
        font-size: 11px;
    }

    .chart-legend > button {
        gap: 3px;
    }

    .chart-legend__swatch {
        width: 24px;
        height: 10px;
    }

    .device-chart {
        height: 270px;
    }

    .device-map {
        height: 300px;
    }

    #map {
        height: 330px;
    }
}

/* Login page */
.login-page {
    --login-bg: #eef3f6;
    --login-card: #fff;
    --login-line: #d9e2e8;
    --login-text: #17202a;
    --login-muted: #627384;
    --login-accent: #1976d2;
    --login-accent-dark: #145da3;
    --login-danger: #b00020;
    margin: 0;
    color: var(--login-text);
    background:
        linear-gradient(135deg, rgba(25, 118, 210, 0.14), transparent 36%),
        linear-gradient(315deg, rgba(0, 131, 143, 0.12), transparent 38%),
        var(--login-bg);
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px 16px;
}

.login-card {
    width: min(420px, 100%);
    padding: 28px;
    background: var(--login-card);
    border: 1px solid var(--login-line);
    border-radius: 8px;
    box-shadow: 0 18px 45px rgba(22, 34, 51, 0.14);
}

.brand-title {
    margin: 0 0 6px;
    font-size: 28px;
    line-height: 1.2;
    font-weight: 800;
}

.brand-subtitle {
    margin: 0 0 22px;
    color: var(--login-muted);
    font-size: 14px;
}

.field {
    margin-bottom: 14px;
}

.field label {
    display: block;
    margin-bottom: 6px;
    color: #3d4d5c;
    font-size: 14px;
}

.field input[type=text],
.field input[type=password] {
    width: 100%;
    min-height: 42px;
    padding: 9px 11px;
    border: 1px solid #cbd6df;
    border-radius: 6px;
    color: var(--login-text);
    background: #fff;
    font-size: 15px;
}

.field input[type=text]:focus,
.field input[type=password]:focus {
    outline: 2px solid rgba(25, 118, 210, 0.18);
    border-color: var(--login-accent);
}

.login-options {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 6px 0 18px;
    color: #465564;
    font-size: 14px;
}

.login-button {
    width: 100%;
    min-height: 42px;
    border: 0;
    border-radius: 6px;
    background: var(--login-accent);
    color: #fff;
    cursor: pointer;
    font-size: 16px;
    font-weight: 800;
}

.login-button:hover {
    background: var(--login-accent-dark);
}

.error-msg {
    display: block;
    min-height: 20px;
    margin-top: 12px;
    color: var(--login-danger);
    font-size: 14px;
}

/* Change-password page */
.password-page {
    margin: 24px;
}

.password-page h1 {
    margin: 0 0 16px;
    font-size: 20px;
}

.password-page .form {
    max-width: 480px;
}

.password-page .row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.password-page .row label {
    width: 110px;
}

.password-page .row input[type=text],
.password-page .row input[type=password] {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
}

.password-page .actions {
    margin-top: 14px;
}

.password-page .btn {
    padding: 8px 14px;
    border: 0;
    border-radius: 8px;
    background: #1976d2;
    color: #fff;
    cursor: pointer;
}

.password-page .btn:hover {
    background: #145da3;
}

.password-page .msg {
    display: block;
    margin-top: 12px;
    font-size: 14px;
}

.password-page .ok {
    color: #1b5e20;
}

.password-page .err {
    color: #b00020;
}

@media (max-width: 480px) {
    .login-card {
        padding: 22px;
    }

    .brand-title {
        font-size: 24px;
    }

    .password-page {
        margin: 16px;
    }

    .password-page .row {
        align-items: stretch;
        flex-direction: column;
        gap: 5px;
    }

    .password-page .row label {
        width: auto;
    }
}
