:root {
    --primary: #2a75d3;
    --primary-hover: #1e5bb3;
    --success: #10b981;
    --success-hover: #059669;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --bg-main: #f4f6f9;
    --card-shadow: 0 4px 20px rgba(160, 170, 190, 0.12);
    --text-dark: #1e293b;
    --text-muted: #64748b;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-dark);
    margin: 0;
    padding: 24px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #ffffff;
    padding: 16px 24px;
    border-radius: 16px;
    box-shadow: var(--card-shadow);
    margin-bottom: 24px;
}

.header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 12px;
}

.header h2 small {
    background: #f1f5f9;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

.btn-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn {
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    white-space: nowrap;
}

.btn-settings {
    background: #f1f5f9;
    color: #334155;
}

.btn-settings:hover {
    background: #e2e8f0;
}

.btn-logout {
    background: #fee2e2;
    color: #991b1b;
}

.btn-logout:hover {
    background: #fca5a5;
}

.btn-action-on {
    background: var(--success);
    color: white;
    width: 110px;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.15);
}

.btn-action-on:hover {
    background: var(--success-hover);
    transform: translateY(-1px);
}

.btn-action-off {
    background: var(--danger);
    color: white;
    width: 110px;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.15);
}

.btn-action-off:hover {
    background: var(--danger-hover);
    transform: translateY(-1px);
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
    margin-bottom: 24px;
}

.card {
    background: #ffffff;
    padding: 24px;
    border-radius: 16px;
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
}

.card-body-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
}

.card h3 {
    margin: 0;
    font-size: 15px;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.5px;
}

.status-val {
    font-size: 28px;
    font-weight: 800;
    margin: 0;
    transition: color 0.3s ease;
}

.chart-container {
    background: #ffffff;
    padding: 24px;
    border-radius: 16px;
    box-shadow: var(--card-shadow);
    margin-bottom: 24px;
    height: 340px;
}

.table-card h3 {
    padding: 24px 24px 0 24px;
    font-size: 16px;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    margin-top: 16px;
}

th {
    background: #f8fafc;
    padding: 14px 24px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid #e2e8f0;
}

td {
    padding: 16px 24px;
    font-size: 14px;
    color: #334155;
    border-bottom: 1px solid #f1f5f9;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: #f8fafc;
}

.badge {
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 6px;
    display: inline-block;
}

.bg-light {
    background: #fef3c7;
    color: #b45309;
}

.bg-wend {
    background: #dbeafe;
    color: #1d4ed8;
}

@media (max-width: 600px) {
    body {
        padding: 16px;
    }

    .header {
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
        padding: 20px;
    }

    .btn-group {
        width: 100%;
        justify-content: space-between;
    }
}

.global-loading-mask {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: white;
    transition: all 0.3s ease;
}

.mask-box {
    background: #ffffff;
    color: #1e293b;
    padding: 30px 40px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #2a75d3;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px auto;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.header {
    margin-bottom: 10px;
    padding: 15px 12px;
}

@media (min-width: 768px) {
    .header {
        padding: 16px 24px;
    }
}

.badge-elec {
    background: #e0f2fe;
    color: #0369a1;
}

.badge-temp {
    background: #fee2e2;
    color: #b91c1c;
}

.badge-env {
    background: #f0fdf4;
    color: #15803d;
}

.badge-alarm {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fca5a5;
    animation: blink 2s infinite;
}

@keyframes blink {
    50% {
        opacity: 0.6;
    }
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(48%, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.chart-card {
    background: #ffffff;
    border-radius: 16px;
    border: none;
    padding: 24px;
    box-shadow: var(--card-shadow);
}

.chart-wrapper {
    position: relative;
    height: 260px;
    width: 100%;
}

@media (max-width: 1024px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

.btn-refresh {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #ffffff;
    color: #475569;
    border: 1px solid #cbd5e1;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-refresh:hover {
    background: #f8fafc;
    color: #1e293b;
    border-color: #94a3b8;
}

.btn-refresh:active {
    transform: scale(0.97);
}

.spinning {
    animation: rotateSpin 0.8s linear infinite;
}

@keyframes rotateSpin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}