* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    min-height: 100vh;
    background: #eef1f5;
    color: #1f2937;
    font-family: Arial, Helvetica, sans-serif;
}


/* =====================================================
   HEADER
===================================================== */

.top-header {
    min-height: 88px;
    padding: 16px 24px;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;

    background: #ffffff;
    border-bottom: 1px solid #d9dee7;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.header-title h1 {
    margin-bottom: 5px;
    font-size: 24px;
    color: #172033;
}

.header-title p {
    font-size: 14px;
    color: #6b7280;
}

.header-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 18px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-button {
    padding: 9px 13px;

    border: 1px solid #cbd2dc;
    border-radius: 6px;

    background: #ffffff;
    color: #243047;

    font-size: 13px;
    font-weight: 600;
    text-decoration: none;

    transition: 0.2s ease;
}

.nav-button:hover {
    background: #f1f4f8;
    border-color: #9da8b7;
}

.logout-button {
    background: #dc3545;
    border-color: #dc3545;
    color: #ffffff;
}

.logout-button:hover {
    background: #bd2130;
    border-color: #bd2130;
}


/* =====================================================
   MQTT STATUS
===================================================== */

.connection-badge {
    min-width: 165px;
    padding: 9px 14px;

    border-radius: 20px;

    font-size: 13px;
    font-weight: 700;
    text-align: center;
}

.connection-badge.connected {
    background: #d9f5e3;
    border: 1px solid #75ce94;
    color: #146c36;
}

.connection-badge.disconnected {
    background: #fde2e5;
    border: 1px solid #ef9aa4;
    color: #a61b29;
}


/* =====================================================
   MAIN DASHBOARD
===================================================== */

.dashboard-container {
    width: 100%;
    max-width: 1920px;
    margin: 0 auto;
    padding: 18px 22px 24px;
}

.dashboard-summary {
    margin-bottom: 15px;
    padding: 12px 16px;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;

    background: #ffffff;
    border: 1px solid #dfe4ea;
    border-radius: 9px;
}

.dashboard-summary h2 {
    margin-bottom: 4px;
    font-size: 19px;
    color: #1b2638;
}

.dashboard-summary p {
    font-size: 13px;
    color: #697386;
}


/* =====================================================
   LEGEND
===================================================== */

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

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;

    color: #4b5563;
    font-size: 12px;
    font-weight: 600;
}

.legend-dot {
    width: 11px;
    height: 11px;
    display: inline-block;
    border-radius: 50%;
}

.legend-on {
    background: #19a95b;
}

.legend-off {
    background: #dc3545;
}

.legend-unknown {
    background: #9aa3af;
}


/* =====================================================
   SIX-COLUMN GRID
===================================================== */

.station-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 13px;
}


/* =====================================================
   STATION CARD
===================================================== */

.station-card {
    min-width: 0;
    min-height: 240px;
    padding: 15px;

    display: flex;
    flex-direction: column;

    border: 1px solid #d5dbe4;
    border-radius: 11px;

    box-shadow: 0 3px 9px rgba(30, 41, 59, 0.08);

    transition:
        background-color 0.3s ease,
        border-color 0.3s ease,
        transform 0.15s ease;
}

.station-card:hover {
    transform: translateY(-2px);
}

.station-card.station-on {
    background: #e9f8ee;
    border-color: #85d5a2;
}

.station-card.station-off {
    background: #fff0f1;
    border-color: #efabb2;
}

.station-card.station-unknown {
    background: #ffffff;
    border-color: #d5dbe4;
}


/* =====================================================
   CARD HEADER
===================================================== */

.station-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;

    padding-bottom: 11px;
    border-bottom: 1px solid rgba(80, 90, 105, 0.15);
}

.station-card-header h3 {
    font-size: 17px;
    color: #1f2937;
}

.status-indicator {
    width: 22px;
    height: 22px;

    flex-shrink: 0;
    display: inline-block;

    border: 3px solid rgba(255, 255, 255, 0.9);
    border-radius: 50%;

    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.status-on {
    background: #15a957;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.15),
        0 0 10px rgba(21, 169, 87, 0.4);
}

.status-off {
    background: #dc3545;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.15),
        0 0 10px rgba(220, 53, 69, 0.35);
}

.status-unknown {
    background: #9ca3af;
}


/* =====================================================
   RELAY DISPLAY
===================================================== */

.relay-display {
    flex: 1;

    padding: 18px 5px 15px;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.relay-label {
    margin-bottom: 5px;

    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: #788294;
}

.relay-text {
    font-size: 27px;
    font-weight: 800;
    letter-spacing: 1px;
}

.text-on {
    color: #168743;
}

.text-off {
    color: #c62d3c;
}

.text-unknown {
    color: #747d89;
}


/* =====================================================
   RELAY BUTTONS
===================================================== */

.relay-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
}

.relay-button {
    min-height: 42px;

    border: none;
    border-radius: 7px;

    color: #ffffff;

    font-size: 15px;
    font-weight: 800;

    cursor: pointer;
    transition:
        transform 0.1s ease,
        opacity 0.2s ease,
        box-shadow 0.2s ease;
}

.relay-button:hover:not(:disabled) {
    transform: translateY(-1px);
}

.relay-button:active:not(:disabled) {
    transform: translateY(1px);
}

.relay-button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.on-button {
    background: #169c50;
    box-shadow: 0 3px 7px rgba(22, 156, 80, 0.22);
}

.on-button:hover:not(:disabled) {
    background: #118141;
}

.off-button {
    background: #dc3545;
    box-shadow: 0 3px 7px rgba(220, 53, 69, 0.22);
}

.off-button:hover:not(:disabled) {
    background: #bd2837;
}


/* =====================================================
   LAST UPDATE
===================================================== */

.last-update-section {
    margin-top: 13px;
    padding-top: 10px;

    display: flex;
    flex-direction: column;
    gap: 4px;

    border-top: 1px solid rgba(80, 90, 105, 0.15);
}

.last-update-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: #808999;
}

.last-update-time {
    min-height: 16px;

    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;

    font-size: 11px;
    font-weight: 600;
    color: #4f5968;
}


/* =====================================================
   NOTIFICATION
===================================================== */

.notification {
    position: fixed;
    top: 100px;
    right: 22px;
    z-index: 1000;

    max-width: 350px;
    padding: 13px 17px;

    border-radius: 8px;

    color: #ffffff;
    font-size: 14px;
    font-weight: 600;

    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);

    transition: 0.25s ease;
}

.notification.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.success-message {
    background: #198754;
    box-shadow: 0 5px 15px rgba(25, 135, 84, 0.3);
}

.error-message {
    background: #dc3545;
    box-shadow: 0 5px 15px rgba(220, 53, 69, 0.3);
}


/* =====================================================
   RESPONSIVE
===================================================== */

/* Smaller desktop and laptop */
@media (max-width: 1500px) {

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

}


/* Tablet */
@media (max-width: 1050px) {

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

    .header-right {
        width: 100%;
        justify-content: space-between;
    }

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

}


/* Small tablet */
@media (max-width: 760px) {

    .dashboard-container {
        padding: 14px;
    }

    .dashboard-summary {
        align-items: flex-start;
        flex-direction: column;
    }

    .header-right {
        align-items: flex-start;
        flex-direction: column;
    }

    .header-actions {
        flex-wrap: wrap;
    }

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

}


/* Mobile */
@media (max-width: 500px) {

    .top-header {
        padding: 14px;
    }

    .header-title h1 {
        font-size: 20px;
    }

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

    .station-card {
        min-height: 225px;
    }

    .connection-badge {
        min-width: 0;
        width: 100%;
    }

    .header-actions {
        width: 100%;
    }

    .nav-button {
        flex: 1;
        text-align: center;
    }

    .legend {
        flex-wrap: wrap;
    }

}
.dashboard-content{
    display:flex;
    align-items:flex-start;
    gap:20px;
}

.station-grid{
    flex:1;
}

.right-panel{
    width:220px;
    background:#fff;
    border-radius:10px;
    padding:15px;
    box-shadow:0 2px 8px rgba(0,0,0,.15);
    position:sticky;
    top:20px;
}

.right-panel h3{
    margin-top:0;
    margin-bottom:15px;
}

#onStationCount{
    font-weight:bold;
    margin-bottom:10px;
}

#onStationList{
    list-style:none;
    padding:0;
    margin:0;
}

#onStationList li{
    background:#dff7df;
    padding:8px;
    margin-bottom:6px;
    border-radius:5px;
    font-weight:bold;
}
/* =====================================================
   HISTORY PAGE
===================================================== */

.history-container {
    width: min(1600px, calc(100% - 32px));
    margin: 24px auto;
}

.history-filter-card,
.history-table-card {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.history-filter-card {
    padding: 20px;
    margin-bottom: 20px;
}

.history-filter-form {
    display: grid;
    grid-template-columns: repeat(6, minmax(130px, 1fr));
    gap: 14px;
    align-items: end;
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.filter-field label {
    font-size: 13px;
    font-weight: 700;
    color: #344054;
}

.filter-field input,
.filter-field select {
    width: 100%;
    min-height: 42px;
    padding: 9px 10px;
    border: 1px solid #d0d5dd;
    border-radius: 7px;
    background: #ffffff;
    font-size: 14px;
}

.filter-field input:focus,
.filter-field select:focus {
    outline: 2px solid rgba(31, 111, 235, 0.2);
    border-color: #1f6feb;
}

.history-filter-actions {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 5px;
}

.history-button {
    min-height: 40px;
    padding: 10px 18px;
    border: none;
    border-radius: 7px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.primary-history-button {
    background: #1f6feb;
    color: #ffffff;
}

.secondary-history-button {
    background: #e9ecef;
    color: #343a40;
}

.export-history-button {
    background: #198754;
    color: #ffffff;
}

.history-table-card {
    overflow: hidden;
}

.history-table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid #e4e7ec;
}

.history-table-header h2 {
    margin: 0;
    font-size: 20px;
}

.history-table-header span {
    color: #667085;
    font-size: 14px;
}

.history-table-wrapper {
    width: 100%;
    overflow-x: auto;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1100px;
}

.history-table th,
.history-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid #eaecf0;
    vertical-align: middle;
    font-size: 14px;
}

.history-table th {
    background: #f8f9fa;
    color: #344054;
    font-weight: 700;
    white-space: nowrap;
}

.history-table tbody tr:hover {
    background: #f9fafb;
}

.command-badge,
.publish-badge {
    display: inline-block;
    min-width: 66px;
    padding: 5px 9px;
    border-radius: 999px;
    text-align: center;
    font-weight: 700;
    font-size: 12px;
}

.command-on {
    background: #d1e7dd;
    color: #0f5132;
}

.command-off {
    background: #f8d7da;
    color: #842029;
}

.publish-success {
    background: #d1e7dd;
    color: #0f5132;
}

.publish-failed {
    background: #f8d7da;
    color: #842029;
}

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

@media (max-width: 1200px) {
    .history-filter-form {
        grid-template-columns: repeat(3, minmax(150px, 1fr));
    }
}

@media (max-width: 700px) {
    .history-container {
        width: calc(100% - 20px);
        margin: 12px auto;
    }

    .history-filter-form {
        grid-template-columns: 1fr;
    }

    .history-filter-actions {
        flex-direction: column;
    }

    .history-button {
        width: 100%;
    }

    .history-table-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 5px;
    }
}
/* =====================================================
   LOGIN PAGE
===================================================== */

.login-page {
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(
            circle at top left,
            rgba(37, 99, 235, 0.16),
            transparent 38%
        ),
        radial-gradient(
            circle at bottom right,
            rgba(14, 165, 233, 0.12),
            transparent 36%
        ),
        linear-gradient(
            135deg,
            #eef4ff 0%,
            #f8fafc 50%,
            #edf7f5 100%
        );
    color: #172033;
    font-family:
        Inter,
        "Segoe UI",
        Arial,
        sans-serif;
}

.login-wrapper {
    min-height: 100vh;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 430px;
    box-sizing: border-box;
    padding: 38px;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 20px;
    box-shadow:
        0 24px 70px rgba(15, 23, 42, 0.14),
        0 6px 20px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(12px);
}

.login-brand {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo {
    width: 270px;
    height: 60px;
    margin: 0 auto 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 18px;
    background: linear-gradient(
        135deg,
        #1d4ed8,
        #0284c7
    );
    color: #ffffff;
    font-size: 21px;
    font-weight: 800;
    letter-spacing: 1px;
    box-shadow: 0 12px 26px rgba(29, 78, 216, 0.28);
}

.login-brand h1 {
    margin: 0 0 8px;
    color: #111827;
    font-size: 29px;
    line-height: 1.2;
}

.login-brand p {
    max-width: 330px;
    margin: 0 auto;
    color: #667085;
    font-size: 14px;
    line-height: 1.55;
}

.login-messages {
    margin-bottom: 20px;
}

.login-alert {
    padding: 11px 13px;
    border-radius: 9px;
    font-size: 14px;
    line-height: 1.45;
}

.login-alert-error {
    color: #9f1239;
    background: #fff1f2;
    border: 1px solid #fecdd3;
}

.login-alert-success {
    color: #166534;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.login-field label {
    color: #344054;
    font-size: 14px;
    font-weight: 700;
}

.login-input-wrapper {
    position: relative;
}

.login-input-wrapper input {
    width: 100%;
    height: 50px;
    box-sizing: border-box;
    padding: 0 70px 0 44px;
    border: 1px solid #d0d5dd;
    border-radius: 11px;
    background: #ffffff;
    color: #101828;
    font-size: 15px;
    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        background 0.2s ease;
}

.login-input-wrapper input::placeholder {
    color: #98a2b3;
}

.login-input-wrapper input:hover {
    border-color: #98a2b3;
}

.login-input-wrapper input:focus {
    outline: none;
    border-color: #2563eb;
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.13);
}

.login-input-icon {
    position: absolute;
    top: 50%;
    left: 14px;
    transform: translateY(-50%);
    font-size: 16px;
    pointer-events: none;
}

.password-toggle {
    position: absolute;
    top: 50%;
    right: 13px;
    transform: translateY(-50%);
    padding: 5px 7px;
    border: none;
    background: transparent;
    color: #2563eb;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.password-toggle:hover {
    color: #1d4ed8;
}

.password-toggle:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
    border-radius: 4px;
}

.login-submit-button {
    width: 100%;
    min-height: 51px;
    margin-top: 3px;
    border: none;
    border-radius: 11px;
    background: linear-gradient(
        135deg,
        #1d4ed8,
        #0284c7
    );
    color: #ffffff;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0.2px;
    cursor: pointer;
    box-shadow: 0 11px 24px rgba(29, 78, 216, 0.25);
    transition:
        transform 0.18s ease,
        box-shadow 0.18s ease,
        opacity 0.18s ease;
}

.login-submit-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 30px rgba(29, 78, 216, 0.31);
}

.login-submit-button:active {
    transform: translateY(0);
}

.login-submit-button:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.35);
    outline-offset: 3px;
}

.login-security-note {
    margin: 24px 0 0;
    color: #98a2b3;
    text-align: center;
    font-size: 12px;
}

@media (max-width: 520px) {
    .login-wrapper {
        padding: 16px;
    }

    .login-card {
        padding: 30px 22px;
        border-radius: 16px;
    }

    .login-brand h1 {
        font-size: 25px;
    }

    .login-logo {
        width: 62px;
        height: 62px;
        border-radius: 16px;
    }
}