/* --- RESET & VARIABLES --- */
:root {
    --bg-gradient: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: 1px solid rgba(255, 255, 255, 0.5);
    --text-main: #1d1d1f;
    --text-sub: #86868b;
    --accent-blue: #0071e3;
    --accent-green: #34c759; /* Green for ON */
    --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-gradient);
    min-height: 100vh;
    color: var(--text-main);
    display: flex; justify-content: center; padding: 20px;
}

.main-wrapper { width: 100%; max-width: 600px; display: flex; flex-direction: column; gap: 20px; }

/* --- HEADER --- */
.glass-header {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 24px;
    padding: 15px 20px;
    display: flex; justify-content: space-between; align-items: center;
    border: var(--glass-border);
    box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 15px; }
.brand-logo { height: 45px; width: auto; border-radius: 6px; }
.brand-text h1 { font-size: 18px; font-weight: 700; text-transform: lowercase; margin-bottom: 2px; }
.brand-text p { font-size: 12px; color: var(--text-sub); }
.settings-btn { background: rgba(0,0,0,0.05); border: none; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; transition: 0.2s; color: var(--text-main); }
.settings-btn:hover { background: rgba(0,0,0,0.1); }

/* --- STATUS BAR --- */
.status-bar { text-align: center; font-size: 13px; color: var(--text-sub); font-weight: 500; }
.dot { height: 8px; width: 8px; background-color: var(--accent-green); border-radius: 50%; display: inline-block; margin-right: 6px; }

/* --- CONTROL GRID (Dynamic) --- */
.control-grid { display: grid; grid-template-columns: 1fr; gap: 15px; }
/* Use 2 columns if screen is wide enough */
@media (min-width: 450px) { .control-grid { grid-template-columns: 1fr 1fr; } }

/* --- RELAY CARDS --- */
.device-card {
    background: rgba(255,255,255,0.8);
    border-radius: 20px; padding: 20px;
    display: flex; justify-content: space-between; align-items: center;
    border: var(--glass-border);
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    transition: 0.3s;
}
.device-card.active { background: white; border-color: var(--accent-green); }

.device-info { display: flex; flex-direction: column; gap: 5px; }
.device-name { font-weight: 600; font-size: 16px; }
.device-status { font-size: 12px; color: var(--text-sub); }

.icon-box {
    width: 32px; height: 32px; background: #f2f2f7;
    border-radius: 8px; display: flex; align-items: center; justify-content: center;
    color: var(--text-sub); margin-bottom: 5px; transition: 0.3s;
}
.device-card.active .icon-box { background: var(--accent-green); color: white; }
.device-card.active .device-status { color: var(--accent-green); }

/* --- SWITCH UI --- */
.switch { position: relative; display: inline-block; width: 50px; height: 30px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #e9e9ea; transition: .4s; border-radius: 34px;
}
.slider:before {
    position: absolute; content: ""; height: 26px; width: 26px;
    left: 2px; bottom: 2px; background-color: white; transition: .4s;
    border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
input:checked + .slider { background-color: var(--accent-green); }
input:checked + .slider:before { transform: translateX(20px); }

/* --- FORMS & MODALS --- */
.config-card, .modal-card { background: white; padding: 25px; border-radius: 20px; text-align: center; }
input { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid #ddd; background: #f9f9f9; margin-bottom: 15px; }
.cta-button { width: 100%; padding: 12px; border-radius: 10px; border: none; background: var(--accent-blue); color: white; font-weight: 600; cursor: pointer; }

.glass-footer { text-align: center; padding: 15px; color: var(--text-sub); font-size: 12px; background: rgba(255,255,255,0.4); border-radius: 15px; }
.modal-backdrop { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); z-index: 100; justify-content: center; align-items: center; }
.modal-card { width: 90%; max-width: 350px; }
.modal-header { display: flex; justify-content: space-between; margin-bottom: 15px; }
.close-btn { background: none; border: none; font-size: 24px; cursor: pointer; }
.loading-overlay { position: fixed; top:0; left:0; width:100%; height:100%; background: white; z-index: 200; display: flex; justify-content: center; align-items: center; }
.spinner { width: 40px; height: 40px; border: 3px solid #f2f2f7; border-top-color: var(--accent-blue); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }