/* =========================================================
   Raspberry Pi Monitor Dashboard
   Full replacement stylesheet
   ========================================================= */

.monitor-page {
    width: min(1180px, calc(100% - 32px));
    margin: 28px auto 42px;
    color: #162033;
}

.monitor-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
}

.monitor-heading h1 {
    margin: 0;
    color: #102447;
    font-size: 28px;
    line-height: 1.25;
}

.monitor-heading p {
    margin: 6px 0 0;
    color: #667085;
    font-size: 14px;
}

.monitor-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 17px;
    border: 1px solid transparent;
    border-radius: 9px;
    text-decoration: none;
    font-weight: 800;
    font-size: 14px;
    transition: transform .15s ease, filter .15s ease;
}

.action-btn:hover {
    transform: translateY(-1px);
    filter: brightness(.97);
}

.action-btn.primary {
    background: #145c96;
    border-color: #145c96;
    color: #fff;
}

.action-btn.secondary {
    background: #fff;
    border-color: #c8d4e1;
    color: #243a58;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.summary-box {
    position: relative;
    overflow: hidden;
    min-height: 105px;
    padding: 18px 20px;
    border: 1px solid #d7e0ea;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 6px 18px rgba(15, 35, 67, .07);
}

.summary-box::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 6px;
}

.summary-box.total::before { background: #145c96; }
.summary-box.online::before { background: #07883f; }
.summary-box.offline::before { background: #d20a18; }
.summary-box.unknown::before { background: #687386; }

.summary-box span {
    display: block;
    color: #667085;
    font-size: 13px;
    margin-bottom: 10px;
}

.summary-box strong {
    color: #102447;
    font-size: 33px;
    line-height: 1;
}

.monitor-alert {
    margin-bottom: 16px;
    padding: 13px 15px;
    border: 1px solid #f2b8b5;
    border-radius: 9px;
    background: #fff0ef;
    color: #9f241b;
}

.monitor-alert a {
    margin-left: 8px;
    color: #9f241b;
    font-weight: 800;
}

.monitor-table-card {
    overflow: hidden;
    border: 1px solid #cad6e3;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 7px 22px rgba(15, 35, 67, .08);
}

.table-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 17px 19px;
    border-bottom: 1px solid #d8e2ec;
}

.table-title h2 {
    margin: 0;
    color: #102447;
    font-size: 18px;
}

.table-title span {
    display: block;
    margin-top: 4px;
    color: #667085;
    font-size: 12px;
}

.monitor-table-scroll {
    overflow-x: auto;
}

.monitor-table {
    width: 100%;
    min-width: 920px;
    border-collapse: collapse;
}

.monitor-table thead th {
    padding: 13px 15px;
    background: #102447;
    color: #fff;
    text-align: left;
    font-size: 13px;
    white-space: nowrap;
}

.monitor-table tbody td {
    padding: 13px 15px;
    border-bottom: 1px solid #dce5ef;
    vertical-align: middle;
    font-size: 14px;
}

.monitor-table tbody tr:last-child td {
    border-bottom: 0;
}

.factory-column { width: 170px; }
.status-column { width: 145px; }
.time-column { width: 170px; }
.action-column { width: 145px; }

.factory-cell {
    min-width: 150px;
    border-right: 1px solid #efc4a7;
    background: #fff1e7;
    text-align: center;
}

.factory-cell strong {
    display: block;
    color: #7a3511;
    font-size: 16px;
}

.factory-cell span {
    display: block;
    margin-top: 5px;
    color: #9a5b39;
    font-size: 12px;
}

.device-cell {
    position: relative;
    min-width: 220px;
}

.device-cell > strong {
    color: #111827;
    font-size: 14px;
}

.cancelled-label {
    display: inline-flex;
    margin-left: 7px;
    padding: 3px 7px;
    border-radius: 999px;
    background: #fee2e2;
    color: #a10f18;
    font-size: 10px;
    font-weight: 900;
}

.ip-button {
    padding: 0;
    border: 0;
    background: transparent;
    color: #075ca8;
    font: inherit;
    font-weight: 900;
    cursor: pointer;
}

.ip-button:hover {
    text-decoration: underline;
}

.ip-button.copied {
    color: #07883f;
}

/* สถานะหลัก */

.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 122px;
    padding: 9px 13px;
    border: 2px solid transparent;
    border-radius: 999px;
    color: #fff;
    font-size: 12px;
    font-weight: 950;
    letter-spacing: .7px;
    box-shadow: 0 4px 11px rgba(16, 36, 71, .14);
}

.status-light {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: currentColor;
    box-shadow:
        0 0 0 3px rgba(255,255,255,.25),
        0 0 9px rgba(255,255,255,.85);
}

.status-badge.online {
    background: #07883f;
    border-color: #006d32;
    animation: onlinePulse 1.9s ease-in-out infinite;
}

.status-badge.offline {
    background: #d20a18;
    border-color: #97000a;
    animation: offlineBlink .85s steps(2, start) infinite;
}

.status-badge.unknown {
    background: #687386;
    border-color: #4d5768;
}

/* แถว Online / Offline */

.device-row.state-online td:not(.factory-cell) {
    background: #f5fff9;
}

.device-row.state-online .device-cell {
    box-shadow: inset 5px 0 0 #07883f;
}

.device-row.state-offline td:not(.factory-cell) {
    background: #fff0f1;
    border-bottom-color: #efa9ae;
}

.device-row.state-offline .device-cell {
    box-shadow: inset 5px 0 0 #d20a18;
}

.device-row.state-offline {
    animation: offlineRowFlash 1.15s ease-in-out infinite;
}

.device-row.state-unknown td:not(.factory-cell) {
    background: #f7f8fa;
}

.device-row.state-unknown .device-cell {
    box-shadow: inset 5px 0 0 #687386;
}

.last-seen {
    color: #475467;
    font-size: 12px !important;
    white-space: nowrap;
}

/* ปุ่ม Node-RED */

.node-red-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 118px;
    min-height: 37px;
    padding: 0 12px;
    border: 2px solid transparent;
    border-radius: 9px;
    text-decoration: none;
    font-size: 12px;
    font-weight: 900;
    transition: transform .15s ease, filter .15s ease;
}

.node-red-button:hover {
    transform: translateY(-1px);
    filter: brightness(.96);
}

.node-red-button.online {
    background: #145c96;
    border-color: #145c96;
    color: #fff;
}

.node-red-button.offline {
    background: #fff;
    border-color: #d20a18;
    color: #b00010;
    animation: offlineButtonBlink 1.05s ease-in-out infinite;
}

.node-red-button.unknown {
    background: #f2f4f7;
    border-color: #aeb7c4;
    color: #475467;
}

.monitor-footnote {
    margin: 12px 2px 0;
    color: #667085;
    font-size: 12px;
}

.monitor-footnote code {
    color: #102447;
    font-weight: 800;
}

.empty-state {
    padding: 36px !important;
    text-align: center;
    color: #667085;
}

/* Animation */

@keyframes onlinePulse {
    0%, 100% {
        transform: scale(1);
        filter: brightness(1);
        box-shadow:
            0 0 0 3px rgba(7,136,63,.12),
            0 4px 11px rgba(7,136,63,.25);
    }

    50% {
        transform: scale(1.045);
        filter: brightness(1.18);
        box-shadow:
            0 0 0 7px rgba(7,136,63,.15),
            0 5px 15px rgba(7,136,63,.38);
    }
}

@keyframes offlineBlink {
    0%, 42% {
        opacity: 1;
        transform: scale(1);
        filter: brightness(1);
    }

    43%, 100% {
        opacity: .48;
        transform: scale(1.07);
        filter: brightness(1.42);
    }
}

@keyframes offlineRowFlash {
    0%, 100% {
        filter: none;
    }

    50% {
        filter: saturate(1.25) brightness(1.02);
    }
}

@keyframes offlineButtonBlink {
    0%, 100% {
        background: #fff;
        color: #b00010;
    }

    50% {
        background: #d20a18;
        color: #fff;
    }
}

/* Responsive */

@media (max-width: 900px) {
    .summary-grid {
        grid-template-columns: repeat(2, minmax(150px, 1fr));
    }

    .monitor-heading {
        align-items: flex-start;
        flex-direction: column;
    }
}

@media (max-width: 520px) {
    .monitor-page {
        width: min(100% - 20px, 1180px);
        margin-top: 18px;
    }

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

    .monitor-heading h1 {
        font-size: 23px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .status-badge.online,
    .status-badge.offline,
    .device-row.state-offline,
    .node-red-button.offline {
        animation: none !important;
    }
}


/* Compact mobile + remove descriptive spacing */
.monitor-heading p,
.table-title span,
.monitor-footnote {
    display: none !important;
}

@media (max-width: 600px) {
    .monitor-page {
        width: calc(100% - 16px) !important;
        margin: 10px auto 20px !important;
    }

    .monitor-heading {
        margin-bottom: 10px !important;
    }

    .monitor-heading h1 {
        font-size: 20px !important;
        line-height: 1.2 !important;
    }

    .monitor-actions {
        gap: 6px !important;
    }

    .action-btn {
        min-height: 36px !important;
        padding: 0 11px !important;
        font-size: 12px !important;
        border-radius: 8px !important;
    }

    .summary-grid {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 8px !important;
        margin-bottom: 10px !important;
    }

    .summary-box {
        min-height: 74px !important;
        padding: 11px 12px !important;
        border-radius: 10px !important;
    }

    .summary-box span {
        margin-bottom: 5px !important;
        font-size: 11px !important;
    }

    .summary-box strong {
        font-size: 25px !important;
    }

    .table-title {
        padding: 10px 12px !important;
    }

    .table-title h2 {
        font-size: 15px !important;
    }

    .monitor-table-card {
        border-radius: 10px !important;
    }

    .monitor-table {
        min-width: 660px !important;
    }

    .monitor-table thead th {
        padding: 9px 10px !important;
        font-size: 11px !important;
    }

    .monitor-table tbody td {
        padding: 9px 10px !important;
        font-size: 12px !important;
    }

    .factory-cell strong {
        font-size: 13px !important;
    }

    .factory-cell span {
        font-size: 10px !important;
    }

    .status-badge {
        min-width: 88px !important;
        padding: 6px 8px !important;
        font-size: 10px !important;
    }

    .node-red-button {
        min-width: 92px !important;
        min-height: 32px !important;
        font-size: 10px !important;
    }

    .last-seen {
        font-size: 10px !important;
    }
}
