:root {
  --bg: #0a0b10;
  --bg-2: #0e1018;
  --surface: #151823;
  --surface-2: #1b1f2c;
  --border: #262b3a;
  --border-soft: #1e2330;
  --text: #e7e9f0;
  --muted: #8b90a3;
  --muted-2: #676c7e;
  --accent: #22c55e;
  --accent-2: #4ade80;
  --accent-glow: rgba(34, 197, 94, 0.33);
  --danger: #ff5c72;
  --danger-bg: rgba(255, 92, 114, 0.12);
  --ok: #37d399;
  --warn: #ffb454;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.75);
  --font: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background:
    radial-gradient(1100px 600px at 78% -8%, rgba(34, 197, 94, 0.13), transparent 60%),
    radial-gradient(900px 500px at 5% 108%, rgba(74, 222, 128, 0.07), transparent 55%),
    var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent-2); }

.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 13px; margin: 4px 0 0; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.06s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.2s ease;
}
.btn:hover { border-color: #33394a; background: #222736; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.sm { padding: 7px 12px; font-size: 13px; }
.btn.primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 24px -8px var(--accent-glow);
}
.btn.primary:hover { filter: brightness(1.06); background: linear-gradient(180deg, var(--accent-2), var(--accent)); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.04); }
.btn.danger { color: var(--danger); border-color: rgba(255, 92, 114, 0.35); background: var(--danger-bg); }
.btn.danger:hover { background: rgba(255, 92, 114, 0.2); }
.btn.block { width: 100%; }

.icon-btn {
  background: transparent; border: none; color: var(--muted);
  font-size: 24px; line-height: 1; cursor: pointer; padding: 2px 6px; border-radius: 8px;
}
.icon-btn:hover { color: var(--text); background: rgba(255,255,255,0.05); }

/* ---------- Inputs ---------- */
label { display: block; font-size: 13px; color: var(--muted); font-weight: 500; margin-bottom: 12px; }
input, select, textarea {
  font: inherit;
  width: 100%;
  margin-top: 6px;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------- Login ---------- */
.login-view { min-height: 100%; display: grid; place-content: center; gap: 18px; padding: 24px; }
.login-card {
  width: 360px; max-width: 92vw;
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 26px;
  box-shadow: var(--shadow);
  animation: rise 0.4s ease both;
}
.login-card label { color: var(--muted); }
.login-card .btn { margin-top: 6px; }
.footer-note { text-align: center; font-size: 12px; }
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo img { max-width: 80%; max-height: 104px; display: block; margin: 0 auto 10px; }
.login-logo p { margin: 0; font-size: 12px; }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand.small { margin: 0; gap: 10px; }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: -0.02em; }
.brand p { margin: 0; font-size: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  display: grid; place-content: center; font-weight: 800; font-size: 20px; color: #fff;
  background: linear-gradient(145deg, var(--accent-2), var(--accent));
  box-shadow: 0 8px 20px -6px var(--accent-glow);
}
.brand.small .brand-mark { width: 30px; height: 30px; font-size: 15px; border-radius: 9px; }

/* ---------- App shell ---------- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(12, 14, 20, 0.7);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
}
.topbar .brand strong { font-size: 15px; }
.nav { display: flex; gap: 4px; margin-left: 6px; }
.nav button {
  background: transparent; border: none; color: var(--muted);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font: inherit; font-weight: 600; font-size: 13.5px;
  transition: color 0.15s, background 0.15s;
}
.nav button:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.nav button.active { color: #fff; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); }
.nav-count {
  display: inline-grid; place-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: 7px;
  border-radius: 999px; font-size: 11px; font-weight: 800; line-height: 1;
  color: #fff; background: var(--danger);
  box-shadow: 0 0 0 1px rgba(255, 92, 114, 0.35);
  vertical-align: middle;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar-right #who { font-size: 13px; }
.badge {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 3px 8px; border-radius: 999px; border: 1px solid var(--border);
  color: var(--muted); background: var(--surface);
}
.badge.mock { color: var(--warn); border-color: rgba(255,180,84,0.4); background: rgba(255,180,84,0.1); }
.badge.relay { color: var(--ok); border-color: rgba(55,211,153,0.4); background: rgba(55,211,153,0.1); }
.badge.direct { color: var(--accent-2); border-color: rgba(74,222,128,0.4); background: rgba(74,222,128,0.1); }

.main { padding: 26px 22px 60px; max-width: 1080px; width: 100%; margin: 0 auto; animation: fade 0.25s ease; }

/* ---------- Cards / layout ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 22px;
}
.card h2 { margin: 0 0 4px; font-size: 17px; letter-spacing: -0.01em; }
.card .sub { margin: 0 0 18px; font-size: 13px; color: var(--muted); }
.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: 1.1fr 0.9fr; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; }
.page-head h2 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted-2); margin: 0 0 12px; font-weight: 700; }

/* stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 16px 18px; }
.stat .n { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat .n.accent { color: var(--accent-2); }

/* limits bar */
.limit-line { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.meter { height: 8px; border-radius: 999px; background: var(--bg-2); overflow: hidden; border: 1px solid var(--border-soft); }
.meter > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.4s ease; }
.meter.warn > span { background: linear-gradient(90deg, #ff9f43, var(--danger)); }

/* result keys */
.keys-out { margin-top: 16px; }
.keys-box {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px; font-family: 'SFMono-Regular', ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px; white-space: pre; overflow-x: auto; max-height: 260px; overflow-y: auto;
}
.keys-actions { display: flex; gap: 10px; margin-top: 12px; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border-soft); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
th { color: var(--muted-2); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; background: var(--bg-2); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,0.02); }
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.tag.on { color: var(--ok); border-color: rgba(55,211,153,0.35); background: rgba(55,211,153,0.1); }
.tag.off { color: var(--danger); border-color: rgba(255,92,114,0.35); background: rgba(255,92,114,0.1); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; }
.empty { text-align: center; color: var(--muted); padding: 30px; font-size: 13.5px; }

/* checkbox list */
.check-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.check-pill { display: inline-flex; align-items: center; gap: 7px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 999px; cursor: pointer; user-select: none; font-size: 13px; }
.check-pill input { width: auto; margin: 0; }
.check-pill:has(input:checked) { border-color: var(--accent); background: rgba(34,197,94,0.14); color: #fff; }

/* ---------- Modal ---------- */
.modal-root { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(4, 5, 8, 0.6); backdrop-filter: blur(3px); }
.modal {
  position: relative; width: 480px; max-width: 94vw; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); animation: rise 0.25s ease both;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border-soft); position: sticky; top: 0; background: var(--surface); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* ---------- Toast ---------- */
.toast-root { position: fixed; bottom: 22px; right: 22px; z-index: 90; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 16px; border-radius: 11px; box-shadow: var(--shadow); font-size: 13.5px;
  animation: rise 0.2s ease both; min-width: 220px; max-width: 340px;
}
.toast.ok { border-left: 3px solid var(--ok); }
.toast.err { border-left: 3px solid var(--danger); }

/* ---------- misc ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%; display: inline-block; animation: spin 0.7s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 780px) {
  .grid.cols-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .field-row { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 12px; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
}
