:root {
  --bg: #0b1220;
  --panel: #121a2b;
  --panel-2: #162033;
  --border: #22304a;
  --text: #e7eefc;
  --muted: #8fa3c4;
  --green: #25d366;
  --green-d: #128c7e;
  --amber: #f5a524;
  --red: #ef4444;
  --blue: #3b82f6;
  --radius: 14px;
}

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

[hidden] { display: none !important; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: radial-gradient(1200px 600px at 20% -10%, #14304a 0%, transparent 60%), var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; gap: 16px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 18, 32, 0.8); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-icon {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--green), var(--green-d));
  font-weight: 800; color: #04120a; letter-spacing: -1px;
}
.brand h1 { font-size: 1.15rem; }
.sub { color: var(--muted); font-size: 0.8rem; }
.top-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.clock { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }

.btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 9px 16px; border-radius: 10px; font-size: 0.9rem; cursor: pointer;
  transition: 0.15s; font-weight: 600;
}
.btn:hover { filter: brightness(1.15); transform: translateY(-1px); }
.btn.primary { background: linear-gradient(135deg, var(--green), var(--green-d)); border: none; color: #04120a; }
.btn.ghost { background: transparent; }
.btn.danger { background: rgba(239, 68, 68, 0.15); border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }
.btn.sm { padding: 6px 10px; font-size: 0.8rem; border-radius: 8px; }

.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px; padding: 20px 28px 6px;
}
.stat {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 4px;
}
.stat-num { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; }
.stat.ok .stat-num { color: var(--green); }
.stat.warn .stat-num { color: var(--amber); }
.stat.off .stat-num { color: var(--red); }

.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 16px; padding: 20px 28px 40px;
}

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; gap: 14px;
  transition: 0.15s;
}
.card:hover { border-color: #2d4266; transform: translateY(-2px); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  background: var(--panel-2); border: 1px solid var(--border); font-weight: 700; color: var(--green);
  font-size: 1rem; flex-shrink: 0;
}
.card-id { display: flex; gap: 12px; align-items: center; min-width: 0; }
.card-id h3 { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.card-id p { color: var(--muted); font-size: 0.82rem; font-variant-numeric: tabular-nums; }

.badge {
  font-size: 0.72rem; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap;
}
.badge.online { background: rgba(37, 211, 102, 0.15); color: var(--green); border: 1px solid rgba(37, 211, 102, 0.4); }
.badge.qr, .badge.connecting { background: rgba(245, 165, 36, 0.15); color: var(--amber); border: 1px solid rgba(245, 165, 36, 0.4); }
.badge.offline { background: rgba(239, 68, 68, 0.12); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.35); }

.meta { display: flex; gap: 16px; font-size: 0.82rem; color: var(--muted); flex-wrap: wrap; }
.meta b { color: var(--text); font-weight: 600; }
.err {
  font-size: 0.78rem; color: #fca5a5; background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3); padding: 6px 10px; border-radius: 8px;
}
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

.modal-mask {
  position: fixed; inset: 0; background: rgba(4, 8, 16, 0.75); backdrop-filter: blur(4px);
  display: grid; place-items: center; z-index: 100; padding: 20px;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 24px; width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.modal h2 { font-size: 1.1rem; }
.hint { color: var(--muted); font-size: 0.84rem; }
.modal label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.modal input, .modal textarea {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 13px; border-radius: 10px; font-size: 0.95rem; font-family: inherit; resize: vertical;
}
.modal input:focus, .modal textarea:focus { outline: none; border-color: var(--green); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.qr-box {
  background: #fff; padding: 16px; border-radius: 12px; display: grid; place-items: center;
  width: fit-content; margin: 0 auto;
}
.qr-box img { width: 280px; height: 280px; display: block; }
.qr-status { text-align: center; color: var(--muted); font-size: 0.85rem; }
.qr-status.ok { color: var(--green); }

.pair-box {
  border-top: 1px dashed var(--border); padding-top: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.pair-code {
  background: var(--panel-2); border: 1px dashed var(--green); border-radius: 12px;
  padding: 14px; text-align: center; display: flex; flex-direction: column; gap: 8px;
}
.pair-code span {
  font-size: 1.7rem; font-weight: 800; letter-spacing: 0.2em; color: var(--green);
  font-family: ui-monospace, 'Courier New', monospace;
}

.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 22px; border-radius: 12px; z-index: 200; font-size: 0.9rem;
  box-shadow: 0 12px 32px rgba(0,0,0,0.4); max-width: 90vw;
}
.toast.error { border-color: rgba(239,68,68,0.5); color: #fca5a5; }
.toast.success { border-color: rgba(37,211,102,0.5); color: var(--green); }

@media (max-width: 640px) {
  .topbar, .stats, .grid { padding-left: 16px; padding-right: 16px; }
  .grid { grid-template-columns: 1fr; }
  .qr-box img { width: 240px; height: 240px; }
}
