:root {
    --bg-grad-1: #0f172a;
    --bg-grad-2: #1e293b;
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --accent: #06b6d4;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body.app-body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, #eef2ff 0%, #f0fdfa 100%);
    color: var(--text);
    min-height: 100vh;
    margin: 0;
}

/* ============ LOGIN ============ */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background:
        radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.25), transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(6, 182, 212, 0.25), transparent 50%),
        linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

.login-card {
    background: var(--surface);
    width: 100%;
    max-width: 420px;
    padding: 40px 36px;
}

.login-header { text-align: center; margin-bottom: 28px; }
.login-header h2 { margin: 12px 0 4px; font-weight: 700; }

.login-logo {
    width: 64px; height: 64px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 26px;
    margin-bottom: 8px;
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

.login-form .form-group { margin-bottom: 18px; }
.login-form label {
    display: block; font-weight: 500; margin-bottom: 6px; font-size: 14px;
}
.login-form label i { color: var(--primary); margin-right: 6px; }

.login-footer { text-align: center; margin-top: 24px; }

/* ============ HEADER ============ */
.app-header {
    background: var(--surface);
    padding: 16px 0;
    position: sticky; top: 0; z-index: 10;
}
.header-inner {
    max-width: 1280px; margin: 0 auto;
    padding: 0 24px;
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-icon {
    width: 44px; height: 44px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 18px;
}
.brand-title { margin: 0; font-weight: 700; font-size: 18px; }

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

.status-chip {
    padding: 6px 12px; border-radius: 999px;
    font-size: 13px; font-weight: 500;
    display: inline-flex; align-items: center; gap: 6px;
}
.status-chip--ok { background: #d1fae5; color: #065f46; }
.status-chip--off { background: #fee2e2; color: #991b1b; }

.user-chip {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 6px 12px; background: var(--surface-soft);
    border-radius: 999px; font-size: 14px;
}
.role-tag {
    font-size: 11px; text-transform: uppercase; font-weight: 700;
    padding: 2px 8px; border-radius: 999px; letter-spacing: 0.4px;
}
.role-tag--admin { background: var(--primary); color: #fff; }
.role-tag--viewer { background: var(--accent); color: #fff; }

/* ============ MAIN ============ */
.app-main {
    max-width: 1280px; margin: 0 auto;
    padding: 28px 24px;
    display: flex; flex-direction: column; gap: 24px;
}

.cards-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.card { background: var(--surface); overflow: hidden; }
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px;
}
.card-header h4 { margin: 0; font-size: 15px; font-weight: 600; }
.card-header h4 i { color: var(--primary); margin-right: 6px; }
.card-body { padding: 22px; }
.card-body .form-group { margin-bottom: 14px; }
.card-body .form-group label {
    display: block; font-weight: 500; margin-bottom: 6px; font-size: 14px;
}
.card-body .form-group label i { color: var(--primary); margin-right: 6px; }
.role-select { min-width: 110px; }

/* Sensor */
.big-number {
    font-size: 56px; font-weight: 700; line-height: 1;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.big-number-sub {
    color: var(--text-muted); font-size: 13px; margin-top: 4px;
}
.gauge-wrap { margin: 18px 0 14px; }
.gauge-bar {
    width: 100%; height: 12px; background: var(--surface-soft);
    border-radius: 999px; overflow: hidden;
}
.gauge-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--primary));
    border-radius: 999px;
    transition: width 0.6s ease;
}
.gauge-labels {
    display: flex; justify-content: space-between;
    margin-top: 6px; font-size: 11px; color: var(--text-muted);
}
.card-meta { color: var(--text-muted); font-size: 12px; margin-top: 8px; }

/* LED */
.led-visual {
    display: flex; justify-content: center; padding: 12px 0 20px;
}
.led-bulb {
    width: 90px; height: 90px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #4b5563, #1f2937);
    box-shadow: inset 0 -4px 8px rgba(0, 0, 0, 0.4);
    transition: all 0.4s ease;
}
.led-bulb.on {
    background: radial-gradient(circle at 30% 30%, #fde68a, #f59e0b);
    box-shadow:
        0 0 30px rgba(245, 158, 11, 0.7),
        0 0 60px rgba(245, 158, 11, 0.4),
        inset 0 -4px 8px rgba(0, 0, 0, 0.1);
}
.actuator-info {
    display: flex; justify-content: space-around;
    padding: 10px 0; border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px; font-size: 14px;
}

.admin-controls { display: flex; flex-direction: column; gap: 14px; }
.toggle-wrap { display: flex; align-items: center; gap: 12px; }
.slider-wrap label { font-size: 13px; color: var(--text-muted); }
.slider-wrap input[type="range"] {
    width: 100%; margin-top: 6px;
    accent-color: var(--primary);
}

/* Switch */
.switch {
    position: relative; display: inline-block;
    width: 48px; height: 26px; flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
    position: absolute; cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #cbd5e1; transition: 0.3s;
    border-radius: 999px;
}
.switch .slider:before {
    position: absolute; content: "";
    height: 20px; width: 20px;
    left: 3px; top: 3px;
    background: #fff; transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider:before { transform: translateX(22px); }

/* Dot state */
.dot-state {
    width: 12px; height: 12px; border-radius: 50%;
    display: inline-block;
}
.dot-on { background: var(--success); box-shadow: 0 0 8px var(--success); }
.dot-off { background: #cbd5e1; }

/* Config */
.config-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 0; border-bottom: 1px solid var(--border);
    gap: 12px;
}
.config-row:last-child { border-bottom: none; }
.config-row small { display: block; font-size: 12px; }

/* Historic */
.history-card .card-header > div { display: flex; gap: 8px; align-items: center; }
.table-wrap {
    max-height: 320px; overflow-y: auto;
    margin-top: 18px; border: 1px solid var(--border);
    border-radius: 8px;
}
.table-wrap table { margin: 0; }
.table-wrap thead th { position: sticky; top: 0; }

/* Buttons */
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff !important;
    border: none;
    font-weight: 500;
    transition: transform 0.15s, box-shadow 0.15s;
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 16px rgba(99, 102, 241, 0.3);
}
.btn-ghost {
    background: transparent;
    border: 1px solid var(--border) !important;
}
.btn-ghost:hover { background: var(--surface-soft); }

/* Toast */
.toast-container {
    position: fixed; bottom: 24px; right: 24px;
    display: flex; flex-direction: column; gap: 10px;
    z-index: 1000;
}
.toast {
    background: var(--surface);
    border-left: 4px solid var(--primary);
    padding: 12px 16px; border-radius: 8px;
    box-shadow: var(--shadow);
    min-width: 240px;
    animation: slideIn 0.3s ease;
    font-size: 14px;
}
.toast.toast--ok { border-left-color: var(--success); }
.toast.toast--err { border-left-color: var(--danger); }
.toast.toast--warn { border-left-color: var(--warning); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 600px) {
    .big-number { font-size: 42px; }
    .header-actions { width: 100%; justify-content: flex-end; }
    .brand-title { font-size: 16px; }
}
