/* ztmesh control panel
   Identity: a network blueprint. Cool paper, ink navy, cable blue for action,
   signal amber for things that need attention. The topology drawing is the one
   loud element; everything else stays quiet so it can carry the page. */

:root {
  --paper: #f1f4f4;
  --paper-deep: #e7ecec;
  --panel: #fbfcfc;
  --panel-2: #f5f8f7;
  --ink: #0f1b21;
  --muted: #55686e;
  --faint: #86979a;
  --line: #d3dcdc;
  --line-soft: #e3e9e8;
  --cable: #0b6e99;

  --cable-hover: #095a7e;
  --cable-soft: #e3eff5;
  --signal: #e39a2b;
  --signal-soft: #fbf0dc;
  --ok: #157f5b;
  --ok-soft: #e2f2ec;
  --danger: #b3261e;
  --danger-soft: #fbe7e5;
  --shadow: 0 1px 2px rgba(15, 27, 33, .05), 0 10px 30px -18px rgba(15, 27, 33, .35);
  --r-card: 16px;
  --r-inset: 10px;
  --r-pill: 999px;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --step: 4px;
}

[data-theme="dark"] {
  --paper: #0c1418;
  --paper-deep: #0a1115;
  --panel: #111c21;
  --panel-2: #0e181c;
  --ink: #e7efec;
  --muted: #93a7ab;
  --faint: #6c8085;
  --line: #1f3037;
  --line-soft: #18262c;
  --cable: #5fb3d4;
  --cable-hover: #7cc4e0;
  --cable-soft: #102a35;
  --signal: #f0b455;
  --signal-soft: #2a2114;
  --ok: #46c795;
  --ok-soft: #0f2a21;
  --danger: #f2776b;
  --danger-soft: #2b1614;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 18px 40px -24px rgba(0, 0, 0, .8);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  background-image:
    linear-gradient(to right, color-mix(in srgb, var(--line) 42%, transparent) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--line) 42%, transparent) 1px, transparent 1px);
  background-size: 48px 48px;
  background-position: -1px -1px;
}

[data-theme="dark"] body { background-image: none; }

a { color: var(--cable); text-decoration: none; }
a:hover { color: var(--cable-hover); text-decoration: underline; text-underline-offset: 3px; }

h1, h2, h3, h4 { margin: 0; font-weight: 640; letter-spacing: -.018em; line-height: 1.2; }
p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: .92em; }

.skip {
  position: absolute; left: -9999px; top: 8px; z-index: 100;
  background: var(--panel); color: var(--ink); padding: 10px 14px; border-radius: 8px;
  border: 1px solid var(--line);
}
.skip:focus { left: 8px; }

:focus-visible {
  outline: 2px solid var(--cable);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- shell ---------- */

.shell {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 26px 18px 20px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper-deep) 78%, transparent);
  backdrop-filter: blur(6px);
}

.brand {
  display: flex; align-items: center; gap: 11px;
  color: var(--ink); text-decoration: none;
}
.brand:hover { text-decoration: none; color: var(--ink); }
.brand-mark { width: 34px; height: 34px; flex: 0 0 auto; }
.mark-bg { fill: var(--cable); }
.mark-line { fill: none; stroke: var(--paper); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mark-dot { fill: var(--paper); }
.brand strong { display: block; font-size: 16px; letter-spacing: -.02em; }
.brand small { display: block; font-size: 11.5px; color: var(--muted); letter-spacing: .01em; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: var(--r-inset);
  color: var(--muted); font-size: 14px; font-weight: 520;
  text-decoration: none;
  transition: background .14s ease, color .14s ease;
}
.nav a:hover { background: color-mix(in srgb, var(--line) 30%, transparent); color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--panel); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.nav-ico { width: 16px; height: 16px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; color: var(--faint); }
.nav a.active .nav-ico { color: var(--cable); }

.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.status-line { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: 0 0 auto; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); }
.dot.bad { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent); }
.rail-actions { display: flex; gap: 8px; }

.icon-btn, .text-btn {
  font: inherit; font-size: 13px;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-inset);
  padding: 7px 11px; cursor: pointer;
  transition: background .14s ease, border-color .14s ease;
}
.icon-btn { padding: 7px 9px; display: inline-flex; align-items: center; justify-content: center; }
.ico { width: 16px; height: 16px; display: block; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
[data-theme="light"] .theme-sun { display: none; }
[data-theme="dark"] .theme-moon { display: none; }
.icon-btn:hover, .text-btn:hover { background: var(--panel-2); border-color: var(--muted); }
.text-btn { color: var(--muted); }
.text-btn:hover { color: var(--ink); }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: none;
  align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 620; font-size: 15px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.topbar-actions .theme-toggle, .topbar-actions .token-btn { display: none; }

[data-theme="dark"] .btn-primary { color: #06222e; }
[data-theme="dark"] .btn-primary:hover { color: #06222e; }
[data-theme="dark"] {
  background-image: none;
}
[data-theme="dark"] body {
  background-image:
    linear-gradient(to right, rgba(255,255,255,.022) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,.022) 1px, transparent 1px);
  background-size: 48px 48px;
}
[data-theme="dark"] .rail { background: color-mix(in srgb, var(--paper-deep) 92%, #000); }

#main { padding: 34px 40px 80px; outline: none; }
.page { max-width: 1120px; margin: 0 auto; }

/* ---------- page furniture ---------- */

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 26px; flex-wrap: wrap; }
.page-head h1 { font-size: clamp(24px, 2.6vw, 31px); }
.page-head .lede { color: var(--muted); margin-top: 7px; max-width: 62ch; font-size: 14.5px; }
.page-actions { display: flex; gap: 9px; flex-wrap: wrap; }

.btn {
  font: inherit; font-size: 13.5px; font-weight: 560;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--r-inset);
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  cursor: pointer; text-decoration: none;
  transition: transform .12s ease, background .14s ease, border-color .14s ease;
}
.btn:hover { background: var(--panel-2); border-color: var(--muted); text-decoration: none; color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--cable); border-color: var(--cable); color: #fff; }
.btn-primary:hover { background: var(--cable-hover); border-color: var(--cable-hover); color: #fff; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 560; letter-spacing: .005em;
  padding: 3px 9px; border-radius: var(--r-pill);
  border: 1px solid var(--line); color: var(--muted); background: var(--panel-2);
}
.badge-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 32%, var(--line)); background: var(--ok-soft); }
.badge-warn { color: var(--signal); border-color: color-mix(in srgb, var(--signal) 38%, var(--line)); background: var(--signal-soft); }
.badge-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 32%, var(--line)); background: var(--danger-soft); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 18px 20px 0; flex-wrap: wrap; }
.card-head h2 { font-size: 15px; }
.card-head .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.card-body { padding: 18px 20px 20px; }
.card-body.tight { padding-top: 8px; }
.wizard-form { max-width: 780px; }

/* ---------- stats ---------- */

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-card); overflow: hidden; margin-bottom: 24px; }
.stat { background: var(--panel); padding: 16px 18px 15px; }
.stat-k { font-size: 12px; color: var(--muted); }
.stat-v { font-size: 27px; font-weight: 640; letter-spacing: -.03em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-v small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 5px; letter-spacing: 0; }
.stat-note { font-size: 12px; color: var(--faint); margin-top: 3px; }

/* ---------- topology ---------- */

.topo-card { padding: 6px 10px 12px; }
.topo-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 4px; gap: 12px; flex-wrap: wrap; }
.topo-head h2 { font-size: 15px; }
.topo-head .hint { font-size: 12.5px; color: var(--muted); }
.topo { width: 100%; height: auto; display: block; overflow: visible; }

.topo-link { fill: none; stroke: color-mix(in srgb, var(--muted) 40%, transparent); stroke-width: 1.5; }
.topo-link.live { stroke: color-mix(in srgb, var(--ok) 70%, transparent); }
.topo-node-label { font-family: var(--font); font-size: 11.5px; fill: var(--ink); font-weight: 560; }
.topo-node-sub { font-family: var(--mono); font-size: 10px; fill: var(--muted); }
.topo-box { fill: var(--panel-2); stroke: var(--line); }
.topo-box.controller { fill: var(--cable-soft); stroke: color-mix(in srgb, var(--cable) 40%, var(--line)); }
.topo-dot { fill: var(--faint); }
.topo-dot.ok { fill: var(--ok); }
.topo-dev-label { font-family: var(--mono); font-size: 10.5px; fill: var(--muted); }
.topo-hit { fill: transparent; cursor: pointer; }
.topo-group:hover .topo-box { stroke: var(--cable); }
.topo-group:focus-visible .topo-box { stroke: var(--cable); stroke-width: 2; }

@media (prefers-reduced-motion: no-preference) {
  .topo-link { stroke-dasharray: 400; stroke-dashoffset: 400; animation: draw .9s cubic-bezier(.2, .7, .2, 1) forwards; }
  .topo-link:nth-child(2) { animation-delay: .06s; }
  .topo-link:nth-child(3) { animation-delay: .12s; }
  .topo-link:nth-child(4) { animation-delay: .18s; }
  @keyframes draw { to { stroke-dashoffset: 0; } }
}

/* ---------- steps ---------- */

.steps { display: grid; gap: 1px; background: var(--line); border-radius: var(--r-card); overflow: hidden; border: 1px solid var(--line); }
.step { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; gap: 14px; align-items: start; background: var(--panel); padding: 16px 18px; }
.step-num {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 12px; font-weight: 600;
  color: var(--muted); border: 1px solid var(--line); background: var(--panel-2);
}
.step.is-done .step-num { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); background: var(--ok-soft); }
.step.is-active .step-num { color: #fff; background: var(--cable); border-color: var(--cable); }
.step h3 { font-size: 14.5px; }
.step p { color: var(--muted); font-size: 13.5px; margin-top: 3px; max-width: 70ch; }
.step-side { align-self: center; }

/* ---------- forms ---------- */

.field { display: grid; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 560; color: var(--ink); }
.field .hint { font-size: 12px; color: var(--muted); }
input[type="text"], input[type="password"], select, textarea {
  font: inherit; font-size: 13.5px;
  width: 100%; padding: 10px 12px;
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--line); border-radius: 9px;
  transition: border-color .14s ease, box-shadow .14s ease;
}
input::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--cable);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cable) 16%, transparent);
}
.form-row { display: grid; gap: 14px; grid-template-columns: 1.4fr 1fr; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; }
.check input { margin-top: 3px; accent-color: var(--cable); }
.check span small { display: block; color: var(--muted); font-size: 12.5px; }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; font-weight: 560; font-size: 12px; color: var(--muted);
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--panel-2) 70%, transparent); }
td.right, th.right { text-align: right; }

.copy {
  font-family: var(--font); font-size: 11.5px; line-height: 1;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 8px; cursor: pointer; color: var(--muted);
  transition: color .14s ease, border-color .14s ease;
}
.copy:hover { color: var(--cable); border-color: var(--cable); }
.copy.copied { color: var(--ok); border-color: var(--ok); }

/* ---------- code ---------- */

.code-block { border: 1px solid var(--line); border-radius: var(--r-inset); overflow: hidden; background: var(--paper-deep); }
.code-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel-2); font-size: 12px; color: var(--muted); }
.code-body { margin: 0; padding: 13px 14px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; line-height: 1.7; color: var(--ink); white-space: pre; }
.code-body .cmt { color: var(--faint); }

.tabbar { display: inline-flex; gap: 2px; padding: 3px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-pill); }
.tab { font: inherit; font-size: 12.5px; padding: 5px 12px; border-radius: var(--r-pill); border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.tab[aria-selected="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- empty ---------- */

.empty { text-align: center; padding: 34px 20px; }
.empty h3 { font-size: 16px; margin-bottom: 6px; }
.empty p { color: var(--muted); font-size: 13.5px; max-width: 52ch; margin: 0 auto 16px; }

/* ---------- guide ---------- */

.guide { display: grid; gap: 20px; max-width: 860px; }
.guide section { padding-top: 4px; }
.guide h2 { font-size: 19px; margin-bottom: 8px; }
.guide h3 { font-size: 15px; margin: 18px 0 6px; }
.guide p { color: var(--muted); font-size: 14px; max-width: 74ch; }
.guide p + p { margin-top: 9px; }
.guide ul, .guide ol { color: var(--muted); font-size: 14px; padding-left: 20px; margin: 8px 0 0; }
.guide li + li { margin-top: 5px; }
.guide strong { color: var(--ink); font-weight: 600; }
.guide code { background: var(--panel-2); border: 1px solid var(--line-soft); padding: 1px 5px; border-radius: 5px; color: var(--ink); }

.glossary { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.glossary div { border: 1px solid var(--line); border-radius: var(--r-inset); padding: 13px 14px; background: var(--panel); }
.glossary dt { font-weight: 600; font-size: 13.5px; margin-bottom: 3px; }
.glossary dd { margin: 0; color: var(--muted); font-size: 13px; }

/* ---------- toast & modal ---------- */

#toast { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 60; }
.toast-item {
  background: var(--ink); color: var(--paper);
  border-radius: 10px; padding: 11px 14px; font-size: 13px;
  box-shadow: var(--shadow); max-width: 40ch;
  animation: toast-in .18s ease;
}
.toast-item.err { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

.modal-back {
  position: fixed; inset: 0; background: color-mix(in srgb, #06121a 62%, transparent);
  display: grid; place-items: center; padding: 20px; z-index: 70;
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal-card {
  width: min(520px, 100%); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--r-card);
  box-shadow: var(--shadow); padding: 22px;
}
.modal-card h2 { font-size: 17px; margin-bottom: 6px; }
.modal-card p { color: var(--muted); font-size: 13.5px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }

/* ---------- misc ---------- */

.skeleton { background: linear-gradient(90deg, var(--panel-2), var(--line-soft), var(--panel-2)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border-radius: 6px; color: transparent; }
@keyframes shimmer { to { background-position: -200% 0; } }

.note {
  display: flex; gap: 10px; align-items: flex-start;
  border: 1px solid color-mix(in srgb, var(--signal) 34%, var(--line));
  background: var(--signal-soft); border-radius: var(--r-inset);
  padding: 12px 14px; font-size: 13px; color: var(--ink);
}
.note strong { font-weight: 600; }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.kv > div { border: 1px solid var(--line-soft); border-radius: var(--r-inset); padding: 11px 13px; background: var(--panel-2); }
.kv .k { font-size: 11.5px; color: var(--muted); }
.kv .v { font-family: var(--mono); font-size: 12.5px; margin-top: 4px; word-break: break-all; }

.grid-2 { display: grid; gap: 20px; grid-template-columns: 1.35fr 1fr; align-items: start; }
.stack { display: grid; gap: 20px; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; background: var(--paper); color: var(--ink); font-size: 15px; }

/* ---------- responsive ---------- */

@media (max-width: 1080px) {
  .grid-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .main { min-width: 0; }
  .rail {
    position: static; height: auto; flex-direction: row; align-items: center;
    gap: 14px; padding: 12px 14px; border-right: 0; border-bottom: 1px solid var(--line);
    overflow-x: auto;
  }
  .brand small { display: none; }
  .nav { flex-direction: row; gap: 4px; }
  .nav a { padding: 7px 10px; font-size: 13px; white-space: nowrap; }
  .nav-ico { display: none; }
  .rail-foot { display: none; }
  .rail { flex-wrap: nowrap; min-width: 0; }
  .nav { flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .topbar { display: flex; justify-content: flex-end; }
  .topbar-title { display: none; }
  .topbar-actions .theme-toggle, .topbar-actions .token-btn { display: inline-flex; }
  .stat { padding: 13px 15px; }
  .stat-v { font-size: 23px; }
  #main { padding: 22px 16px 64px; }
  .page-head { margin-bottom: 18px; }
  .step { grid-template-columns: 34px minmax(0, 1fr); }
  .step-side { grid-column: 2; }
  .form-row { grid-template-columns: 1fr; }
  table { font-size: 13px; }
  th, td { padding: 10px 10px; }
}

@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr; }
  .topbar-actions .text-btn { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
