:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e8eef7;
  --muted: #8b9bb4;
  --accent: #3b82f6;
  --accent2: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --sz: #38bdf8;
  --hk: #a78bfa;
  --us: #34d399;
  --radius: 12px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.55;
  min-height: 100%;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 960px; margin: 0 auto; padding: 0 16px 48px; }

/* nav */
.nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.nav-inner {
  max-width: 960px; margin: 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; flex-wrap: wrap;
}
.brand {
  font-weight: 700; font-size: 1.05rem;
  margin-right: auto; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.brand span.badge {
  font-size: 0.7rem; font-weight: 600;
  background: var(--accent); color: #fff;
  padding: 2px 6px; border-radius: 4px;
}
.nav a.link {
  color: var(--muted); padding: 6px 10px; border-radius: 8px;
  font-size: 0.92rem;
}
.nav a.link:hover, .nav a.link.active {
  color: var(--text); background: var(--surface2); text-decoration: none;
}
.btn, button.btn {
  display: inline-block;
  background: var(--accent); color: #fff; border: none;
  padding: 8px 16px; border-radius: 8px; cursor: pointer;
  font-size: 0.95rem; font-family: inherit;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; color: #fff; }
.btn.secondary { background: var(--surface2); border: 1px solid var(--border); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn.block { display: block; width: 100%; text-align: center; }

h1 { font-size: 1.5rem; margin: 28px 0 8px; }
h2 { font-size: 1.15rem; margin: 24px 0 10px; color: #c5d4eb; }
.lead { color: var(--muted); margin: 0 0 20px; }

/* login */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px; width: 100%; max-width: 380px;
}
.login-card h1 { margin-top: 0; font-size: 1.35rem; }
label { display: block; margin: 14px 0 6px; color: var(--muted); font-size: 0.9rem; }
input[type=password], input[type=text] {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-size: 1rem;
}
.error {
  background: rgba(239,68,68,0.15); color: #fca5a5;
  border: 1px solid rgba(239,68,68,0.35);
  padding: 10px 12px; border-radius: 8px; margin: 12px 0; font-size: 0.9rem;
}

/* topology */
.topo {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 20px; margin: 16px 0;
  overflow-x: auto;
}
.topo-flow {
  display: flex; align-items: stretch; justify-content: center;
  gap: 0; min-width: 700px; flex-wrap: nowrap;
}
.topo-node {
  flex: 0 0 auto; width: 140px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 10px; text-align: center;
}
.topo-node .name { font-weight: 700; font-size: 0.95rem; }
.topo-node .ip { font-size: 0.75rem; color: var(--muted); margin-top: 6px; word-break: break-all; }
.topo-node .role { font-size: 0.72rem; color: var(--muted); margin-top: 4px; }
.topo-node.client { border-color: #64748b; }
.topo-node.sz { border-color: var(--sz); box-shadow: 0 0 0 1px rgba(56,189,248,0.25); }
.topo-node.hk { border-color: var(--hk); box-shadow: 0 0 0 1px rgba(167,139,250,0.25); }
.topo-node.us { border-color: var(--us); box-shadow: 0 0 0 1px rgba(52,211,153,0.25); }

.topo-edge {
  flex: 1 1 40px; min-width: 56px; max-width: 100px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative; padding: 0 4px;
}
.topo-edge .line {
  width: 100%; height: 3px; background: linear-gradient(90deg, #475569, #94a3b8);
  border-radius: 2px; position: relative;
}
.topo-edge .line::after {
  content: ""; position: absolute; right: -1px; top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent; border-left-color: #94a3b8;
}
.topo-edge .cap {
  font-size: 0.68rem; color: var(--warn); margin-top: 8px; text-align: center;
  line-height: 1.3; white-space: nowrap;
}
.topo-edge .cap.enc { color: var(--accent2); }
.topo-edge .cap.plain { color: var(--muted); }

.legend {
  display: flex; flex-wrap: wrap; gap: 12px 20px;
  margin-top: 18px; font-size: 0.85rem; color: var(--muted);
}
.legend i {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 6px;
}
.legend i.sz { background: var(--sz); }
.legend i.hk { background: var(--hk); }
.legend i.us { background: var(--us); }

.path-note {
  background: rgba(59,130,246,0.08); border: 1px solid rgba(59,130,246,0.25);
  border-radius: 10px; padding: 14px 16px; margin-top: 16px;
  font-size: 0.9rem; color: #bfdbfe;
}
.path-note code {
  background: var(--bg); padding: 1px 6px; border-radius: 4px; font-size: 0.85em;
}

/* cards */
.cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px; margin: 16px 0;
}
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.card h3 { margin: 0 0 6px; font-size: 1.05rem; }
.card .meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 10px; }
.card .ip-line {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9rem; margin: 8px 0;
}
.status-pill {
  display: inline-block; font-size: 0.78rem; font-weight: 600;
  padding: 3px 8px; border-radius: 999px; margin-top: 8px;
}
.status-pill.up { background: rgba(34,197,94,0.2); color: #86efac; }
.status-pill.down { background: rgba(239,68,68,0.2); color: #fca5a5; }
.status-pill.skip { background: rgba(148,163,184,0.2); color: #cbd5e1; }

/* config */
.pre {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px; overflow-x: auto;
  font-size: 0.82rem; line-height: 1.45;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; word-break: break-all;
}
.qr-box {
  text-align: center; background: #fff; border-radius: 12px;
  padding: 16px; display: inline-block; margin: 12px 0;
}
.qr-box img { max-width: 260px; height: auto; display: block; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0; }

/* about */
.table-wrap { overflow-x: auto; }
table.compare {
  width: 100%; border-collapse: collapse; font-size: 0.9rem;
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
}
table.compare th, table.compare td {
  border: 1px solid var(--border); padding: 10px 12px; text-align: left; vertical-align: top;
}
table.compare th { background: var(--surface2); color: #c5d4eb; }

.footer {
  margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--border);
  color: var(--muted); font-size: 0.8rem; text-align: center;
}

@media (max-width: 720px) {
  .topo-flow { min-width: 640px; }
  .topo-node { width: 120px; padding: 10px 6px; }
}

/* Phase 1 extras */
.wrap { max-width: 1100px; }
.flash {
  margin: 16px 0 0; padding: 10px 14px; border-radius: 8px; font-size: 0.92rem;
}
.flash.ok { background: rgba(34,197,94,0.12); border: 1px solid rgba(34,197,94,0.35); color: #86efac; }
.flash.err { background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.35); color: #fca5a5; }
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px; margin: 12px 0 20px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px;
}
.stat .n { font-size: 1.4rem; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 0.85rem; }
table.data {
  width: 100%; border-collapse: collapse; font-size: 0.88rem;
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
}
table.data th, table.data td {
  border: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: middle;
}
table.data th { background: var(--surface2); color: #c5d4eb; white-space: nowrap; }
table.data tr.dim { opacity: 0.55; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.84rem; }
.clip { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.form-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; margin: 12px 0; max-width: 720px;
}
.form-card.compact { max-width: none; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
select, textarea, input[type=number], input[type=datetime-local], input[type=file] {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-size: 0.95rem; font-family: inherit;
}
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); margin: 12px 0; }
.check input { width: auto; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.btn.danger { background: var(--danger); }
.status-pill.warn { background: rgba(245,158,11,0.2); color: #fcd34d; }
.inline-edit { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.inline-edit .mini { width: auto; min-width: 110px; padding: 4px 8px; font-size: 0.8rem; }
.nav-inner { max-width: 1100px; }
