:root {
  --bg: #0b0f14;
  --surface: #121820;
  --surface2: #1a2230;
  --border: #243044;
  --text: #e8eef7;
  --muted: #8fa0b8;
  --accent: #25d366;
  --accent2: #128c7e;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: Inter, Segoe UI, system-ui, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }

.hidden { display: none !important; }

#login-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(circle at top, #123 0%, var(--bg) 55%);
}
.login-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 8px; font-size: 1.5rem; }
.login-card p { margin: 0 0 20px; color: var(--muted); }

#app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border); padding: 20px 16px;
  position: sticky; top: 0; height: 100vh; overflow: auto;
}
.brand { font-weight: 700; font-size: 1.1rem; margin-bottom: 6px; }
.brand small { display: block; color: var(--muted); font-weight: 500; }
.nav { margin-top: 24px; display: grid; gap: 6px; }
.nav button {
  background: transparent; border: 0; color: var(--text); text-align: left;
  padding: 10px 12px; border-radius: 10px; cursor: pointer; font-size: 0.95rem;
}
.nav button:hover, .nav button.active { background: var(--surface2); color: #fff; }
.sidebar-footer { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.85rem; }

.main { padding: 24px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.topbar h2 { margin: 0; font-size: 1.35rem; }
.chip { background: var(--surface2); border: 1px solid var(--border); padding: 6px 10px; border-radius: 999px; font-size: 0.85rem; color: var(--muted); }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 12px; font-size: 1rem; }
.stat-value { font-size: 1.8rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.85rem; }

label { display: block; margin: 10px 0 6px; color: var(--muted); font-size: 0.85rem; }
input, select, textarea {
  width: 100%; background: var(--surface2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; font: inherit;
}
textarea { min-height: 90px; resize: vertical; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1; min-width: 160px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 10px; padding: 10px 14px; font: inherit; cursor: pointer;
  background: var(--accent); color: #052e16; font-weight: 600;
}
.btn:hover { filter: brightness(1.05); }
.btn.secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.alert {
  padding: 12px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 0.92rem;
  border: 1px solid var(--border); background: var(--surface2);
}
.alert.ok { border-color: #166534; background: #052e16; color: #bbf7d0; }
.alert.err { border-color: #991b1b; background: #450a0a; color: #fecaca; }

.qr-box { text-align: center; }
.qr-box img { max-width: 280px; width: 100%; border-radius: 12px; background: #fff; padding: 12px; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.on { background: var(--accent); }
.status-dot.off { background: var(--danger); }
.status-dot.pending { background: var(--warn); }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }

.section { display: none; }
.section.active { display: block; }

@media (max-width: 900px) {
  #app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
}

.rule-list { display: grid; gap: 10px; margin-top: 8px; }
.rule-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  margin-left: 6px;
  vertical-align: middle;
}
.rule-item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface2);
}
.rule-toggle {
  width: 32px; height: 32px; min-width: 32px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25); cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
}
.rule-toggle.on { background: var(--accent); box-shadow: 0 0 0 3px rgba(37,211,102,0.25); }
.rule-toggle.off { background: var(--danger); box-shadow: 0 0 0 3px rgba(239,68,68,0.2); }
.rule-body { flex: 1; min-width: 0; }
.rule-title { font-weight: 600; margin-bottom: 4px; }
.rule-meta { color: var(--muted); font-size: 0.82rem; line-height: 1.4; }
.rule-preview { margin-top: 6px; font-size: 0.88rem; color: var(--text); opacity: 0.9; white-space: pre-wrap; }
.rule-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.rule-actions button { padding: 6px 10px; font-size: 0.82rem; }
