:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --fg: #1b1f24;
  --muted: #5f6b77;
  --line: #dde2e8;
  --accent: #2457d6;
  --accent-fg: #ffffff;
  --accent-soft: #e8eefc;
  --ok: #1a7f37;
  --warn: #9a6700;
  --bad: #c62828;
  --row-hover: #f0f3f7;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --panel: #191d23;
    --fg: #e6e9ee;
    --muted: #9aa5b1;
    --line: #2b313a;
    --accent: #5b8cff;
    --accent-fg: #0c1220;
    --accent-soft: #1d2a47;
    --ok: #4ac26b;
    --warn: #d4a72c;
    --bad: #f47067;
    --row-hover: #1f242b;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input { font: inherit; color: inherit; }
a { color: var(--accent); }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.boot { padding: 40px; color: var(--muted); text-align: center; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel);
  cursor: pointer; text-decoration: none; color: var(--fg); white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--row-hover); border-color: transparent; }
.btn-ghost.danger { color: var(--bad); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn { background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--muted); padding: 4px 8px; }
input:not([type=radio]):not([type=checkbox]) {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); min-width: 0;
}
input:focus-visible, .btn:focus-visible, canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.form-error { color: var(--bad); min-height: 1.4em; margin: 4px 0; }

/* ---------- login ---------- */
.login-page { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px 26px; display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow);
}
.login-card .brand { margin-bottom: 14px; font-size: 18px; }
.login-card label { margin-top: 8px; color: var(--muted); font-size: 13px; }
.login-card #totp { font-family: ui-monospace, Consolas, monospace; letter-spacing: .35em; font-size: 18px; }
.login-card .btn { margin-top: 6px; padding: 10px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.brand-mark {
  width: 22px; height: 16px; border-radius: 4px; background: var(--accent); position: relative; flex: none;
}
.brand-mark::after { content: ""; position: absolute; left: 6px; right: 6px; bottom: -5px; height: 3px; border-radius: 2px; background: var(--accent); }

/* ---------- shell ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px; padding: 10px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap;
}
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { padding: 6px 12px; border-radius: 7px; text-decoration: none; color: var(--muted); }
.tab:hover { background: var(--row-hover); }
.tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.user { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.conn { font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.conn-ok { color: var(--ok); } .conn-warn { color: var(--warn); } .conn-bad { color: var(--bad); }
.content { padding: 20px; max-width: 1280px; margin: 0 auto; }
.content h1 { font-size: 18px; margin: 0; }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.spacer { flex: 1; }
.connect-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.id-input { width: 140px; letter-spacing: .06em; }
.toolbar input[type=search] { width: 240px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 12px; }
.stack { display: flex; flex-direction: column; gap: 8px; }

/* ---------- tables ---------- */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--row-hover); }
.table tr.offline .dev-name { color: var(--muted); }
.table td .btn + .btn { margin-left: 2px; }
.details { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 9px; vertical-align: 1px; }
.dot-on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.dot-off { background: var(--line); }
.dev-name { font-weight: 550; }
.empty { padding: 28px; text-align: center; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--row-hover); }
.badge-active { color: var(--ok); }
.badge-rejected, .badge-timeout { color: var(--warn); }

/* ---------- modal & toasts ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 12px; width: min(520px, 100%); box-shadow: var(--shadow); border: 1px solid var(--line); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 0; }
.modal-head h2 { font-size: 16px; margin: 0; }
.modal-body { padding: 8px 18px 18px; }
.token { flex: 1; font-size: 13px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: 10px 14px; box-shadow: var(--shadow); }
.toast-ok { border-left-color: var(--ok); } .toast-warn { border-left-color: var(--warn); } .toast-bad { border-left-color: var(--bad); }

/* ---------- viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 40; background: #0b0d10; color: #e6e9ee; display: flex; flex-direction: column; }
.v-bar { display: flex; align-items: center; gap: 16px; padding: 6px 12px; background: #15191f; border-bottom: 1px solid #262c35; flex-wrap: wrap; }
.v-bar .btn { color: #e6e9ee; }
.v-bar .btn-ghost:hover { background: #222831; }
.v-title { display: flex; gap: 10px; align-items: baseline; }
.v-title .muted { color: #9aa5b1; }
.v-info { display: flex; gap: 14px; font-size: 13px; color: #9aa5b1; flex-wrap: wrap; }
.v-status.ok { color: #4ac26b; } .v-status.warn { color: #d4a72c; }
.v-route.p2p { color: #4ac26b; } .v-route.relay { color: #d4a72c; }
.v-actions { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.v-stage { flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden; position: relative; }
.v-stage.scroll { place-items: start; overflow: auto; }
.v-canvas { display: none; background: #000; cursor: default; image-rendering: auto; }
.v-canvas.live { display: block; }
.v-placeholder { display: flex; flex-direction: column; align-items: center; gap: 14px; color: #9aa5b1; padding: 16px; text-align: center; }
.spinner { width: 34px; height: 34px; border: 3px solid #2b313a; border-top-color: #5b8cff; border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

@media (max-width: 720px) {
  .content { padding: 14px 16px; }
  .topbar { padding: 10px 16px; gap: 10px; }
  .user { margin-left: 0; width: 100%; justify-content: space-between; }
  .toolbar input[type=search] { flex: 1; }
}
