:root {
  --bg: #0f172a; --card: #1e293b; --line: #334155; --text: #e2e8f0; --muted: #94a3b8;
  --ok: #22c55e; --bad: #ef4444; --warn: #f59e0b; --accent: #818cf8;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: #a5b4fc; text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 0 0 10px; }
.sub { color: var(--muted); font-size: 12px; }

.top { display: flex; align-items: center; gap: 16px; padding: 12px 24px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; color: var(--text); }
.mqtt { margin-left: auto; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.mqtt.ok .dot { background: var(--ok); } .mqtt.bad .dot { background: var(--bad); }
.logout { display: flex; align-items: center; gap: 10px; margin: 0; }
.user { color: var(--muted); font-size: 12px; }
main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px; }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: 0 0 auto; }
.dot.online { background: var(--ok); box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.dot.stale { background: var(--warn); }
.dot.offline { background: var(--bad); }
.dot.big { width: 14px; height: 14px; }

.btn { background: var(--accent); color: #0f172a; border: 0; border-radius: 8px; padding: 7px 14px; font: inherit; font-weight: 600; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn.ghost:hover { color: var(--text); border-color: var(--muted); }
input, textarea { width: 100%; padding: 7px 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; }
.login { max-width: 340px; margin: 60px auto; display: flex; flex-direction: column; gap: 12px; }
.alert { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.4); color: #fca5a5; padding: 8px 10px; border-radius: 8px; }
.empty { color: var(--muted); text-align: center; padding: 48px 0; }

.summary { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; color: var(--muted); font-size: 13px; }
.chip.active { border-color: var(--accent); color: var(--text); }
.chip b { color: var(--text); }
.search { margin-left: auto; min-width: 220px; }

table { width: 100%; border-collapse: collapse; }
table.devices th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.devices td { padding: 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.devices tbody tr { cursor: pointer; }
table.devices tbody tr:hover { background: rgba(129,140,248,.06); }
table.devices tr.st-offline td { color: var(--muted); }

.crumbs { margin: 0 0 12px; color: var(--muted); }
.dev-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.grid .card { margin-bottom: 0; }
.grid + .card { margin-top: 16px; }
table.kv th { text-align: left; color: var(--muted); font-weight: 400; padding: 4px 12px 4px 0; width: 40%; vertical-align: top; }
table.kv td { padding: 4px 0; }
table.list td { padding: 5px 10px 5px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list td.when { white-space: nowrap; color: var(--muted); width: 1%; }
table.list td.payload { word-break: break-all; }
.meta { display: flex; flex-direction: column; gap: 10px; }
.meta .btn { align-self: flex-start; }
.ev { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); }
.ev-online { color: #86efac; border-color: rgba(34,197,94,.4); }
.ev-offline { color: #fca5a5; border-color: rgba(239,68,68,.4); }
.ev-restart { color: #fcd34d; border-color: rgba(245,158,11,.4); }
.ev-fw_changed { color: #a5b4fc; border-color: rgba(129,140,248,.4); }

@media (max-width: 720px) {
  table.devices th:nth-child(5), table.devices td:nth-child(5),
  table.devices th:nth-child(7), table.devices td:nth-child(7) { display: none; }
  .search { margin-left: 0; width: 100%; }
}
