:root {
  color-scheme: light;
  --bg: #f6f7f3;
  --ink: #1b1d21;
  --muted: #6a7079;
  --line: #d8ddd5;
  --panel: #ffffff;
  --panel-soft: #fbfcfa;
  --panel-strong: #edf0eb;
  --input-bg: #ffffff;
  --shadow: rgba(27, 29, 33, .04);
  --green: #208f5b;
  --yellow: #b7791f;
  --red: #c2413a;
  --blue: #2458d3;
  --blue-dark: #193f9b;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111412;
  --ink: #f0f3ef;
  --muted: #a8afa8;
  --line: #394139;
  --panel: #1b1f1c;
  --panel-soft: #202621;
  --panel-strong: #303830;
  --input-bg: #151916;
  --shadow: rgba(0, 0, 0, .28);
  --green: #42b979;
  --yellow: #d8a13a;
  --red: #e15f57;
  --blue: #5f8df7;
  --blue-dark: #9bb8ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
.file-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--input-bg);
  color: var(--ink);
  padding: 8px 12px;
  cursor: pointer;
}

a {
  color: var(--blue);
  font-weight: 700;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.primary:not(:disabled):hover {
  background: var(--blue-dark);
}

.danger {
  background: #8f1d1d;
  border-color: #8f1d1d;
  color: #fff;
}

.danger:not(:disabled):hover {
  background: #6f1515;
}

.ghost-danger {
  background: transparent;
  color: var(--red);
  border-color: color-mix(in srgb, var(--red) 45%, var(--line));
}

.ghost-danger:not(:disabled):hover {
  background: color-mix(in srgb, var(--red) 10%, var(--panel));
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  max-width: 100%;
  margin: 0 auto;
  padding: 28px 0 48px;
}

.topbar,
.band,
.panel,
.log-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 22px;
  margin-bottom: 16px;
}

.topbar > div:first-child,
.panel,
.log-panel,
.item,
.kv,
.panel-head {
  min-width: 0;
}

.topbar-side {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.admin-toggle {
  min-width: 28px;
  min-height: 28px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  opacity: .18;
  padding: 0;
  line-height: 1;
}

.admin-toggle:hover,
.admin-toggle:focus-visible {
  opacity: .75;
  background: var(--panel-strong);
  outline: none;
}

.theme-toggle {
  min-width: 86px;
  min-height: 32px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

p,
span,
strong,
dd,
dt,
li,
button,
.file-button {
  overflow-wrap: anywhere;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1;
}

h2 {
  font-size: 18px;
}

.muted,
.small {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.eyebrow {
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status-pill {
  border-radius: 999px;
  color: #fff;
  background: var(--red);
  padding: 7px 12px;
  white-space: nowrap;
  font-weight: 700;
}

.status-pill.green {
  background: var(--green);
}

.status-pill.yellow {
  background: var(--yellow);
}

.status-pill.red {
  background: var(--red);
}

.band {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 18px;
  margin-bottom: 16px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.grid.locked-grid {
  grid-template-columns: minmax(0, 520px);
  justify-content: center;
}

.guide {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.panel,
.log-panel {
  padding: 18px;
}

.wide {
  min-height: 280px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head > * {
  min-width: 0;
}

.stack {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

input,
select {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#copyConfigBtn {
  font-weight: 700;
}

.copy-status {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  font-size: 13px;
  font-weight: 700;
}

.copy-status.ok {
  color: var(--green);
}

.copy-status.pending {
  color: var(--yellow);
}

.copy-status.error {
  color: var(--red);
}

.file-button {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.restore-box {
  display: grid;
  gap: 8px;
  border: 1px solid var(--panel-strong);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 12px;
}

.restore-box.expired {
  border-color: #efc7bf;
  background: #fff8f6;
}

.restore-status {
  min-height: 18px;
}

.restore-status.pending {
  color: var(--yellow);
}

.restore-status.ok {
  color: var(--green);
}

.restore-status.error {
  color: var(--red);
}

.small.ok {
  color: var(--green);
}

.small.pending {
  color: var(--yellow);
}

.small.error {
  color: var(--red);
}

.captcha-field {
  display: grid;
  grid-template-columns: auto minmax(90px, 140px);
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.captcha-field input {
  min-height: 36px;
}

.config-help {
  display: grid;
  gap: 10px;
  border: 1px solid var(--panel-strong);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 12px;
}

.manual-copy {
  display: grid;
  gap: 8px;
  border: 1px solid #efc7bf;
  border-radius: 8px;
  background: #fff8f6;
  padding: 12px;
}

.manual-copy textarea {
  min-height: 116px;
  width: 100%;
  border: 1px solid #efc7bf;
  border-radius: 7px;
  padding: 10px;
  color: var(--ink);
  background: #fff;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
}

.identity-key-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--panel-strong);
  border-radius: 8px;
  background: color-mix(in srgb, var(--yellow) 10%, var(--panel));
  padding: 12px;
}

.admin-panel {
  margin-bottom: 16px;
}

.admin-login {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.admin-stats div,
.admin-root,
.provisioner-key {
  display: grid;
  gap: 3px;
  border: 1px solid var(--panel-strong);
  border-radius: 7px;
  background: var(--panel-soft);
  padding: 9px;
}

.admin-stats span,
.admin-root span,
.provisioner-key span {
  color: var(--muted);
  font-size: 12px;
}

.admin-root code,
.provisioner-key code {
  max-width: 100%;
}

.admin-provisioner {
  display: grid;
  gap: 10px;
  border: 1px solid var(--panel-strong);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 12px;
}

.node-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  align-items: end;
  gap: 8px;
}

.node-form button {
  min-height: 42px;
}

.node-facts,
.node-plan,
.node-routing,
.node-ip-roles {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.node-routing,
.node-ip-roles {
  border: 1px solid #e6eae3;
  border-radius: 6px;
  background: #f7f9f5;
  padding: 8px;
}

.node-ip-roles {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.node-plan ul {
  margin: 0;
  padding-left: 18px;
}

.route-plan {
  border: 1px solid #e1e6dd;
  border-radius: 6px;
  padding: 8px;
  background: var(--panel-soft);
}

.route-plan summary {
  cursor: pointer;
  font-weight: 700;
}

.route-plan code {
  display: block;
  max-width: 100%;
  margin-top: 6px;
  padding: 6px 7px;
  white-space: normal;
  overflow-wrap: anywhere;
  background: #f0f3ee;
  color: var(--ink);
  border-radius: 5px;
}

.route-plan pre {
  max-width: 100%;
  margin: 8px 0 0;
  padding: 8px;
  overflow-x: auto;
  white-space: pre;
  background: #151816;
  color: #f2f6ef;
  border-radius: 5px;
}

.jobs-box {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.jobs-box h3 {
  margin: 0;
  font-size: 16px;
}

.job-item {
  gap: 8px;
}

.job-log {
  display: grid;
  gap: 4px;
}

.job-log code {
  display: block;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  color: var(--ink);
  background: #f5f7f4;
  border: 1px solid #e5e8e1;
  border-radius: 6px;
  padding: 5px 7px;
}

.admin-split {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(260px, .6fr);
  gap: 14px;
}

.admin-split h2 {
  margin-bottom: 8px;
}

.admin-user.disabled-user {
  background: #fff8f6;
  border-color: #efc7bf;
}

.compact-head {
  margin-bottom: 0;
}

.kv {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  border-bottom: 1px solid var(--panel-strong);
  padding: 9px 0;
}

code {
  display: inline-block;
  max-width: 62%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
  color: var(--blue-dark);
}

.meter {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7eae4;
  margin: 14px 0;
}

.meter div {
  width: 0%;
  height: 100%;
  background: var(--green);
  transition: width .2s ease;
}

.list {
  display: grid;
  gap: 8px;
}

.item {
  display: grid;
  gap: 6px;
  border: 1px solid var(--panel-strong);
  border-radius: 7px;
  padding: 10px;
  background: var(--panel-soft);
}

.invite-item {
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

.invite-item.new-invite {
  border-color: #8eaae9;
  background: color-mix(in srgb, var(--blue) 8%, var(--panel));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 18%, transparent);
}

.item-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.invite-copy-status,
.new-invite-label {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

.new-invite-label {
  color: var(--blue-dark);
}

.badge {
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  color: #fff;
  background: var(--muted);
}

.badge.created,
.badge.visited {
  background: var(--yellow);
}

.badge.consumed {
  background: var(--green);
}

.badge.expired {
  background: var(--red);
}

.explain-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.explain-list div {
  display: grid;
  gap: 3px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--panel-strong);
}

.explain-list div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.explain-list dt {
  font-weight: 800;
}

.explain-list dd {
  margin: 0;
  color: var(--muted);
}

.steps {
  counter-reset: step;
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.steps li {
  position: relative;
  display: grid;
  gap: 4px;
  min-height: 42px;
  padding: 0 0 10px 44px;
  border-bottom: 1px solid var(--panel-strong);
}

.steps li:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.steps li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--blue) 14%, var(--panel));
  color: var(--blue-dark);
  font-weight: 800;
}

.steps strong {
  font-size: 15px;
}

.steps span {
  color: var(--muted);
}

.steps a {
  color: var(--blue);
}

.compact-steps {
  gap: 8px;
}

.compact-steps li {
  min-height: 34px;
  padding-left: 38px;
  padding-bottom: 8px;
}

.compact-steps li::before {
  width: 28px;
  height: 28px;
}

.tree-head-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tree-head-actions button {
  min-height: 32px;
}

.tree {
  overflow: auto;
  padding: 8px 4px 4px;
}

.tree-fullscreen {
  position: fixed;
  inset: 12px;
  z-index: 50;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .28);
}

.tree-fullscreen .tree {
  min-height: 0;
  padding: 18px;
}

body.tree-expanded {
  overflow: hidden;
}

body.tree-expanded::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 49;
  background: rgba(0, 0, 0, .42);
}

.tree-group {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 150px;
}

.tree-node {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 148px;
  max-width: 190px;
  min-height: 54px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 8px;
  padding: 8px 10px;
  box-shadow: 0 1px 0 var(--shadow);
}

.tree-node.pending {
  border-style: dashed;
  background: color-mix(in srgb, var(--yellow) 10%, var(--panel));
  color: var(--muted);
}

.tree-avatar {
  display: inline-grid;
  place-items: center;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--blue) 14%, var(--panel));
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 800;
}

.tree-text {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.tree-text strong,
.tree-text code {
  display: block;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-text code {
  font-size: 11px;
}

.tree-text em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
}

.tree-children {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 18px;
  padding-top: 30px;
}

.tree-children::before {
  content: "";
  position: absolute;
  top: 14px;
  left: 50%;
  width: 1px;
  height: 16px;
  background: var(--line);
}

.tree-branch {
  position: relative;
  display: flex;
  justify-content: center;
}

.tree-branch::before {
  content: "";
  position: absolute;
  top: -16px;
  left: 50%;
  width: calc(100% + 18px);
  height: 1px;
  transform: translateX(-50%);
  background: var(--line);
}

.tree-branch:first-child::before {
  left: 50%;
  width: 50%;
  transform: none;
}

.tree-branch:last-child::before {
  right: 50%;
  left: auto;
  width: 50%;
  transform: none;
}

.tree-branch:only-child::before {
  display: none;
}

.tree-branch::after {
  content: "";
  position: absolute;
  top: -16px;
  left: 50%;
  width: 1px;
  height: 16px;
  background: var(--line);
}

.log-panel pre {
  min-height: 90px;
  max-height: 220px;
  overflow: auto;
  margin: 0;
  white-space: pre-wrap;
  color: var(--ink);
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 14px;
  padding: 14px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.site-footer strong {
  color: var(--ink);
}

.hidden {
  display: none !important;
}

.empty {
  color: var(--muted);
}

@media (max-width: 1100px) {
  .shell {
    width: min(960px, calc(100vw - 28px));
  }

  .admin-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .admin-split {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
  }
}

@media (max-width: 640px) {
  .shell {
    width: calc(100vw - 16px);
    padding-top: 10px;
    padding-bottom: 28px;
  }

  .topbar,
  .band,
  .guide {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar {
    display: grid;
    gap: 12px;
    padding: 16px;
  }

  .topbar-side {
    justify-content: space-between;
  }

  .panel,
  .log-panel {
    padding: 14px;
  }

  h1 {
    font-size: 30px;
  }

  .panel-head,
  .item-row {
    align-items: flex-start;
  }

  .panel-head {
    flex-wrap: wrap;
  }

  .kv {
    display: grid;
    grid-template-columns: 1fr;
    align-items: flex-start;
    gap: 4px;
  }

  .kv strong,
  .kv code {
    justify-self: start;
    max-width: 100%;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  button,
  .file-button {
    width: 100%;
    justify-content: center;
  }

  .theme-toggle,
  .admin-toggle,
  .tree-head-actions button {
    width: auto;
  }

  .tree-head-actions {
    width: 100%;
    justify-content: space-between;
  }

  .tree-fullscreen {
    inset: 8px;
  }

  .copy-status,
  .invite-copy-status,
  .new-invite-label {
    min-height: 24px;
  }

  .captcha-field {
    grid-template-columns: 1fr;
  }

  code {
    max-width: 100%;
  }

  .identity-key-box {
    grid-template-columns: 1fr;
  }

  .admin-login,
  .admin-stats,
  .admin-split,
  .node-form {
    grid-template-columns: 1fr;
  }

  .tree {
    padding-left: 0;
  }

  .tree-group,
  .tree-children,
  .tree-branch {
    display: grid;
    justify-content: stretch;
    justify-items: stretch;
    min-width: 0;
  }

  .tree-group {
    align-items: stretch;
  }

  .tree-node {
    width: 100%;
    max-width: none;
  }

  .tree-children {
    gap: 10px;
    margin-left: 18px;
    padding-top: 10px;
    padding-left: 14px;
    border-left: 1px solid var(--line);
  }

  .tree-children::before,
  .tree-branch::before,
  .tree-branch::after {
    display: none;
  }
}
