:root {
  --bg: #0f172a; --card: #1e293b; --line: #334155;
  --text: #e2e8f0; --muted: #94a3b8;
  --accent: #38bdf8; --ok: #22c55e; --bad: #ef4444; --warn: #f59e0b;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }
header { display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line); }
header h1 { font-size: 20px; margin: 0; }
#user { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 14px; }
main { max-width: 900px; margin: 0 auto; padding: 18px; }
.hidden { display: none !important; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h2 { margin: 0 0 12px; font-size: 18px; }
.hint { color: var(--muted); font-size: 14px; }
label { display: block; margin: 12px 0; font-size: 14px; color: var(--muted); }
input { display: block; width: 100%; margin-top: 6px; padding: 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 16px; }
button { cursor: pointer; border: 0; border-radius: 10px; padding: 12px 16px; font-size: 15px;
  font-weight: 600; background: var(--accent); color: #082f49; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button:disabled { opacity: .5; cursor: default; }
.tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tabs button { flex: 1; background: transparent; color: var(--muted); border: 1px solid var(--line); }
.tabs button.active { background: var(--accent); color: #082f49; border-color: var(--accent); }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.device { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.device .name { font-weight: 700; word-break: break-all; }
.device .status { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin: 6px 0 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); }
.dot.on { background: var(--ok); }
.relays { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.relay { display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.relay .label { font-size: 13px; color: var(--muted); }
.switch { position: relative; width: 58px; height: 32px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: var(--line); border-radius: 32px; transition: .2s; }
.switch .slider::before { content: ""; position: absolute; width: 26px; height: 26px; left: 3px; top: 3px;
  background: white; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::before { transform: translateX(26px); }
.switch input:disabled + .slider { opacity: .5; }
.inputs { display: flex; gap: 8px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.inputs span { padding: 3px 8px; border-radius: 8px; border: 1px solid var(--line); }
.inputs span.on { border-color: var(--warn); color: var(--warn); }
.meta { font-size: 12px; color: var(--muted); margin-top: 10px; }

#scanner video { width: 100%; border-radius: 12px; background: #000; margin-bottom: 8px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #0b1220; border: 1px solid var(--line); color: var(--text);
  padding: 12px 16px; border-radius: 12px; max-width: 90vw; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
#toast.err { border-color: var(--bad); }
