:root {
  --bg: #070b16;
  --bg-2: #0b1122;
  --card: rgba(18, 26, 48, 0.72);
  --card-solid: #121a30;
  --line: rgba(148, 163, 214, 0.14);
  --line-2: rgba(148, 163, 214, 0.24);
  --text: #e6eaf5;
  --muted: #8d97b5;
  --teal: #5eead4;
  --indigo: #818cf8;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 16px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font: 15px/1.5 var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(94, 234, 212, 0.10), transparent 60%),
    radial-gradient(1000px 600px at 100% 0%, rgba(129, 140, 248, 0.14), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
code, .mono { font-family: var(--mono); font-size: 0.86em; }
code { background: rgba(148, 163, 214, 0.12); padding: 0.1em 0.4em; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
[hidden] { display: none !important; }

.i { width: 18px; height: 18px; flex: none; vertical-align: -3px; }
.i-xl { width: 40px; height: 40px; opacity: 0.5; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid transparent; font: inherit; font-weight: 600; font-size: 0.92rem;
  color: var(--text); background: transparent; cursor: pointer;
  transition: background-color .15s, border-color .15s, transform .1s, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn:focus-visible, .icon-btn:focus-visible, .seg button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--teal); outline-offset: 2px;
}
.btn-primary { background: linear-gradient(135deg, var(--teal), var(--indigo)); color: #06101f; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { border-color: var(--line-2); background: rgba(148, 163, 214, 0.06); }
.btn-ghost:hover { background: rgba(148, 163, 214, 0.14); }
.btn-danger { background: rgba(248, 113, 113, 0.16); color: #fecaca; border-color: rgba(248, 113, 113, 0.4); }
.btn-danger:hover { background: rgba(248, 113, 113, 0.28); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 0.84rem; border-radius: 8px; }
.btn-block { width: 100%; }
.icon-btn {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: rgba(148, 163, 214, 0.12); color: var(--text); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 14px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: rgba(7, 11, 22, 0.72);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; }
.brand-mark { width: 28px; height: 28px; }
.brand-lg { font-size: 1.3rem; justify-content: center; margin-bottom: 18px; }
.brand-lg .brand-mark { width: 40px; height: 40px; }
.host-chip {
  font-family: var(--mono); font-size: 0.8rem; color: var(--muted);
  padding: 3px 10px; border: 1px solid var(--line-2); border-radius: 99px;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.topbar form { margin: 0; }
.live { display: inline-flex; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.ok .dot { background: var(--ok); box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6); animation: ping 2s infinite; }
.live.bad .dot { background: var(--bad); }
@keyframes ping { 0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, .55); } 70% { box-shadow: 0 0 0 7px rgba(52, 211, 153, 0); } 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); } }

/* ---------- layout ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 24px clamp(16px, 4vw, 40px) 48px; display: grid; gap: 18px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(10px);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2, summary h2 { font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.cols > .card { min-width: 0; }

.banner {
  border-radius: 12px; padding: 12px 16px; font-size: 0.9rem;
  background: rgba(248, 113, 113, 0.12); border: 1px solid rgba(248, 113, 113, 0.35); color: #fecaca;
}

/* ---------- hero ---------- */
.hero {
  display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap;
  padding: 26px 28px;
  background:
    linear-gradient(120deg, rgba(94, 234, 212, 0.10), rgba(129, 140, 248, 0.10)),
    var(--card);
}
.eyebrow { margin: 0 0 6px; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--teal); font-weight: 700; }
.hero h1 { font-size: clamp(1.4rem, 2.6vw, 1.9rem); }
.hero p.muted { margin: 6px 0 0; max-width: 60ch; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.hero.state-bad .eyebrow { color: var(--bad); }
.hero.state-warn .eyebrow { color: var(--warn); }
.hero.state-live .eyebrow { color: var(--ok); }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px;
  display: flex; flex-direction: column; gap: 6px; min-width: 0;
  border-top: 2px solid var(--line-2);
}
.tile.ok { border-top-color: var(--ok); }
.tile.warn { border-top-color: var(--warn); }
.tile.bad { border-top-color: var(--bad); }
.tile.live { border-top-color: var(--teal); }
.tile-head { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.tile-value { font-size: 1.25rem; font-weight: 700; }
.tile-sub { font-size: 0.82rem; color: var(--muted); overflow-wrap: anywhere; }

.seg { display: inline-flex; padding: 3px; gap: 3px; border-radius: 9px; background: rgba(148, 163, 214, 0.08); border: 1px solid var(--line); align-self: flex-start; }
.seg button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 0.8rem; font-weight: 600;
  padding: 4px 12px; border-radius: 7px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--card-solid); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.06) inset, 0 2px 8px rgba(0,0,0,.3); }
.seg button:disabled { cursor: progress; }

/* ---------- metrics ---------- */
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.metric { padding: 14px; border-radius: 12px; background: rgba(7, 11, 22, 0.45); border: 1px solid var(--line); min-width: 0; }
.metric-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.metric-label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.metric-value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric-value small { font-size: 0.75rem; color: var(--muted); font-weight: 500; margin-left: 2px; }
.bar { height: 6px; border-radius: 99px; background: rgba(148, 163, 214, 0.12); overflow: hidden; margin: 10px 0 8px; }
.bar span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--teal), var(--indigo)); transition: width .6s ease; }
.metric.hot .bar span { background: linear-gradient(90deg, var(--warn), var(--bad)); }
.spark { width: 100%; height: 34px; display: block; }
.spark.empty { visibility: hidden; }
.spark path.line { fill: none; stroke: var(--indigo); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.spark path.area { fill: rgba(129, 140, 248, 0.14); stroke: none; }
.metric-foot { font-size: 0.75rem; color: var(--muted); }

/* ---------- devices ---------- */
.count { font-size: 0.78rem; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: rgba(129, 140, 248, 0.18); color: #c7d2fe; }
.devices, .checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.device { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; background: rgba(7, 11, 22, 0.45); border: 1px solid var(--line); }
.device-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: rgba(94, 234, 212, 0.12); color: var(--teal); flex: none; }
.device-main { flex: 1; min-width: 0; }
.device-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-meta { font-size: 0.78rem; color: var(--muted); }
.pill { font-size: 0.7rem; font-weight: 700; padding: 1px 7px; border-radius: 99px; margin-left: 6px; vertical-align: 1px; }
.pill-warn { background: rgba(251, 191, 36, 0.16); color: var(--warn); }
.empty { text-align: center; padding: 22px 10px; color: var(--muted); display: grid; justify-items: center; gap: 6px; }
.empty p { margin: 0 0 6px; }

/* ---------- checks ---------- */
.check-row { display: grid; grid-template-columns: 22px 1fr; gap: 10px; padding: 9px 10px; border-radius: 10px; }
.check-row:nth-child(odd) { background: rgba(7, 11, 22, 0.35); }
.check-row .i { margin-top: 2px; }
.check-row.ok .i { color: var(--ok); }
.check-row.warn .i { color: var(--warn); }
.check-row.fail .i { color: var(--bad); }
.check-name { font-weight: 600; font-size: 0.88rem; }
.check-detail { font-size: 0.8rem; color: var(--muted); overflow-wrap: anywhere; }
.check-fix { font-size: 0.78rem; margin-top: 4px; }
.check-fix code { overflow-wrap: anywhere; }

/* ---------- log ---------- */
details summary { list-style: none; display: flex; align-items: center; gap: 12px; cursor: pointer; }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: "›"; font-size: 1.2rem; color: var(--muted); transition: transform .2s; }
details[open] summary::before { transform: rotate(90deg); }
.log {
  margin: 14px 0 0; padding: 14px; max-height: 360px; overflow: auto; border-radius: 10px;
  background: #050811; border: 1px solid var(--line); font: 12px/1.55 var(--mono); color: #b7c0dc; white-space: pre-wrap; overflow-wrap: anywhere;
}

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--line-2); border-radius: 20px; padding: 0; color: var(--text);
  background: var(--card-solid); width: min(760px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
}
dialog::backdrop { background: rgba(3, 6, 14, 0.66); backdrop-filter: blur(4px); }
dialog[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
#confirm-dialog { width: min(420px, calc(100vw - 24px)); }
.dlg { padding: 22px 24px 24px; }
.dlg-sm p { margin: 10px 0 20px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; }

.pair-grid { display: grid; grid-template-columns: auto 1fr; gap: 26px; align-items: center; }
.qr-wrap { display: grid; gap: 10px; justify-items: center; }
.qr { width: 260px; height: 260px; border-radius: 16px; background: #fff; padding: 8px; display: grid; place-items: center; }
.qr svg { width: 100%; height: 100%; display: block; }
.ttl { width: 260px; display: grid; gap: 6px; justify-items: center; }
.ttl-bar { width: 100%; height: 4px; border-radius: 99px; background: rgba(148, 163, 214, 0.15); overflow: hidden; }
.ttl-bar span { display: block; height: 100%; width: 100%; background: var(--teal); transition: width 1s linear; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 14px; color: var(--muted); }
.steps b { color: var(--text); }
.steps li::marker { color: var(--teal); font-weight: 700; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 20px 0 0; padding: 14px 16px; border-radius: 12px; background: rgba(7, 11, 22, 0.5); border: 1px solid var(--line); font-size: 0.85rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 0.82rem; overflow-wrap: anywhere; }
.waiting { display: flex; align-items: center; gap: 10px; margin: 16px 0 0; color: var(--muted); font-size: 0.9rem; }
.done { text-align: center; padding: 18px 0 6px; display: grid; justify-items: center; gap: 8px; }
.done p { margin: 0 0 12px; }
.done-badge { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: rgba(52, 211, 153, 0.16); color: var(--ok); margin-bottom: 6px; }
.done-badge .i { width: 32px; height: 32px; }

.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(129, 140, 248, 0.25); border-top-color: var(--indigo); animation: spin .8s linear infinite; }
.spinner-sm { width: 16px; height: 16px; border-width: 2px; flex: none; }
.qr .spinner { border-color: rgba(0,0,0,.12); border-top-color: #4f46e5; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  padding: 12px 16px; border-radius: 12px; background: var(--card-solid); border: 1px solid var(--line-2);
  box-shadow: 0 12px 40px rgba(0,0,0,.45); font-size: 0.9rem; animation: pop .2s ease-out;
}
.toast.ok { border-left: 3px solid var(--ok); }
.toast.err { border-left: 3px solid var(--bad); }
.toast.warn { border-left: 3px solid var(--warn); }

.foot { text-align: center; color: var(--muted); font-size: 0.78rem; }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; padding: 24px; }
.login { width: min(420px, 100%); display: grid; gap: 16px; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 32px 28px; backdrop-filter: blur(12px); }
.login-card h1 { font-size: 1.35rem; text-align: center; }
.login-card > .muted { text-align: center; margin: 6px 0 22px; font-size: 0.92rem; }
.stack { display: grid; gap: 10px; }
.stack label { font-size: 0.85rem; font-weight: 600; }
.stack input[type="password"], .stack input[type="text"] {
  height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line-2);
  background: rgba(7, 11, 22, 0.6); color: var(--text); font: 15px var(--mono);
}
.stack input:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; border-color: transparent; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500 !important; color: var(--muted); }
.check input { accent-color: var(--teal); }
.form-error { margin: 0; padding: 10px 12px; border-radius: 10px; background: rgba(248, 113, 113, 0.12); color: #fecaca; font-size: 0.86rem; }
.stack .btn { margin-top: 6px; height: 44px; }
.hint { margin: 20px 0 0; font-size: 0.8rem; color: var(--muted); text-align: center; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .hide-sm { display: none; }
  .host-chip { display: none; }
  .hero { padding: 20px; }
  .hero-actions, .hero-actions .btn { width: 100%; }
  .pair-grid { grid-template-columns: 1fr; justify-items: center; }
  .qr { width: min(260px, 70vw); height: min(260px, 70vw); }
}
@media (max-width: 420px) {
  .tiles { grid-template-columns: 1fr; }
  .metric { padding: 12px; }
  .metric-value { font-size: 1.1rem; }
  .metric-top { flex-direction: column; align-items: flex-start; gap: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
