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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f2f4f7;
    color: #1d1d1f;
    min-height: 100vh;
}

.container {
    max-width: 480px;
    margin: 0 auto;
    padding: 24px 16px;
}

h1 {
    text-align: center;
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 0;
    color: #1d1d1f;
}

/* Top bar */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.top-bar h1 {
    flex: 1;
}

.top-link {
    color: #007aff;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
}

/* Cards grid */
.cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.card {
    background: #fff;
    border-radius: 16px;
    padding: 18px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.card .label {
    display: block;
    font-size: 0.75rem;
    color: #8e8e93;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.card .value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: #1d1d1f;
}

.card .value.on {
    color: #34c759;
}

.card .value.off {
    color: #ff3b30;
}

/* Setpoint section */
.setpoint-section {
    background: #fff;
    border-radius: 16px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.setpoint-section h2 {
    font-size: 1rem;
    font-weight: 600;
    color: #8e8e93;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 14px;
}

.sp-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-bottom: 14px;
}

.sp-controls button {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: #007aff;
    color: #fff;
    font-size: 1.3rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.sp-controls button:active {
    background: #005ecb;
}

.sp-controls input {
    width: 80px;
    text-align: center;
    font-size: 1.4rem;
    font-weight: 700;
    padding: 8px;
    border: 2px solid #e5e5ea;
    border-radius: 12px;
    background: #f9f9fb;
    color: #1d1d1f;
    outline: none;
}

.sp-controls input:focus {
    border-color: #007aff;
}

/* Hysteresis row */
.hyst-row {
    margin-top: 10px;
    padding-top: 14px;
    border-top: 1px solid #f0f0f2;
}

.hyst-label {
    display: block;
    font-size: 0.75rem;
    color: #8e8e93;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.hyst-row .sp-controls {
    margin-bottom: 0;
}

.hyst-row .sp-controls button {
    width: 36px;
    height: 36px;
    font-size: 1rem;
}

.hyst-row .sp-controls input {
    width: 68px;
    font-size: 1.2rem;
}

/* Power ON/OFF toggle */
.power-section {
    background: #fff;
    border-radius: 16px;
    padding: 16px 20px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.power-label {
    font-size: 1rem;
    font-weight: 600;
    color: #1d1d1f;
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.toggle {
    width: 52px;
    height: 30px;
    border-radius: 15px;
    position: relative;
    transition: background 0.3s;
}

.toggle-on {
    background: #34c759;
}

.toggle-off {
    background: #c7c7cc;
}

.toggle-knob {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #fff;
    position: absolute;
    top: 2px;
    transition: left 0.3s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.toggle-on .toggle-knob {
    left: 24px;
}

.toggle-off .toggle-knob {
    left: 2px;
}

.toggle-text {
    font-size: 0.9rem;
    font-weight: 700;
    min-width: 30px;
    color: #1d1d1f;
}

/* No data state */
.no-data {
    text-align: center;
    padding: 40px 20px;
    color: #8e8e93;
}

.no-data strong {
    color: #007aff;
}

/* Login page */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    background: #fff;
    border-radius: 20px;
    padding: 40px 32px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    text-align: center;
}

.login-card h1 {
    margin-bottom: 4px;
}

.login-subtitle {
    color: #8e8e93;
    font-size: 0.95rem;
    margin-bottom: 28px;
}

.login-card input[type="text"],
.login-card input[type="password"] {
    display: block;
    width: 100%;
    padding: 14px 16px;
    margin-bottom: 12px;
    border: 2px solid #e5e5ea;
    border-radius: 12px;
    font-size: 1rem;
    background: #f9f9fb;
    color: #1d1d1f;
    outline: none;
    transition: border-color 0.2s;
}

.login-card input:focus {
    border-color: #007aff;
}

.login-card button {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    background: #007aff;
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 6px;
    transition: background 0.2s;
}

.login-card button:active {
    background: #005ecb;
}

.login-error {
    color: #ff3b30;
    font-size: 0.9rem;
    margin-bottom: 16px;
    font-weight: 500;
}

.login-success {
    color: #34c759;
    font-size: 0.9rem;
    margin-bottom: 16px;
    font-weight: 500;
}

.settings-back {
    display: inline-block;
    margin-top: 16px;
    color: #007aff;
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
}

/* ===== Device Tabs ===== */
.tabs {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 18px;
    background: #fff;
    border-radius: 14px;
    text-decoration: none;
    color: #8e8e93;
    font-size: 0.95rem;
    font-weight: 700;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    transition: all 0.2s;
    white-space: nowrap;
    border: 2px solid transparent;
}

.tab:active {
    transform: scale(0.97);
}

.tab-active {
    background: #007aff;
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.35);
    border-color: #007aff;
}

.tab-status {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}

.tab-online {
    background: #34c759;
}

.tab-offline {
    background: #ff3b30;
}

.tab-active .tab-online {
    background: #a8f0ba;
}

.tab-active .tab-offline {
    background: #ffb3ae;
}

/* ===== Energy Meter Layout ===== */
.card-wide {
    grid-column: 1 / -1;
}

.value-lg {
    font-size: 2rem !important;
}

.channel-section {
    background: #fff;
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    margin-bottom: 10px;
}

.channel-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: #007aff;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    text-align: center;
}

.channel-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.channel-item {
    text-align: center;
    padding: 8px 4px;
    background: #f9f9fb;
    border-radius: 10px;
}

.channel-item .label {
    display: block;
    font-size: 0.7rem;
    color: #8e8e93;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-weight: 600;
    margin-bottom: 4px;
}

.channel-item .value {
    display: block;
    font-size: 1.2rem;
    font-weight: 700;
    color: #1d1d1f;
}

.channel-item-wide {
    grid-column: 1 / -1;
}

.channel-item-wide .value {
    font-size: 1.6rem;
}

/* ===== Status Bar (Energy Meter) ===== */
.status-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: #fff;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #8e8e93;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.status-dot.on {
    background: #34c759;
}

.status-dot.off {
    background: #ff3b30;
}
