:root {
  --paper: #dfe6ec;
  --sheet: #f7f9fb;
  --ink: #1a2730;
  --muted: #5b6c78;
  --line: #c3ced6;
  --signal: #0c5f5c;
  --signal-ink: #f4fbfa;
  --danger: #8e3b32;
  --flash: #e5f3f1;
  --code: #1a2730;
  --code-ink: #d5e3ea;
  --sans: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --serif: "Noto Serif SC", "Songti SC", PMingLiU, serif;
  --mono: "Azeret Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, .brand, .host-name, .dialog header h2 {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.app { display: grid; grid-template-columns: 188px minmax(0, 1fr); width: 100%; min-height: 100vh; }
.rail { padding: 32px 18px; border-right: 1px solid var(--line); }
.brand {
  display: block;
  color: var(--ink);
  text-decoration: none;
  font-size: 1.7rem;
  line-height: 1.1;
  margin: 0 0 32px 12px;
}
.rail nav { display: flex; flex-direction: column; }
.rail a {
  text-decoration: none;
  color: var(--muted);
  padding: 9px 12px;
  border-left: 3px solid transparent;
}
.rail a.is-active { color: var(--ink); border-left-color: var(--signal); }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

.stage { width: 100%; padding: 36px 40px 80px; }
.page-head, .detail-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; }
h1 { margin: 0; font-size: 2rem; line-height: 1.2; }
h2 { margin: 0 0 10px; font-size: 1.25rem; }
.page-head p, .detail-head p, .quiet, .hint, .muted, .ledger { color: var(--muted); }
.page-head p, .ledger { max-width: 38rem; margin: 8px 0 0; }
.quiet { margin: 2px 0 0; }
.primary, button {
  border: 1px solid var(--line);
  background: var(--sheet);
  border-radius: 4px;
  padding: 8px 14px;
}
.primary { background: var(--signal); border-color: var(--signal); color: var(--signal-ink); }
.danger { color: var(--danger); border-color: #e2c8c4; }
.flash { background: var(--flash); padding: 10px 12px; margin-top: 16px; }
.back { display: inline-block; margin-bottom: 16px; color: var(--signal); text-decoration: none; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 28px;
}
.host-card {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  min-height: 156px;
  text-decoration: none;
  background: var(--sheet);
  border: 1px solid var(--line);
}
.host-card:hover { border-color: var(--ink); }
.tab { background: var(--host); }
.host-body { display: flex; flex-direction: column; padding: 16px 16px 14px; }
.host-link { display: flex; flex-direction: column; gap: 3px; flex: 1; text-decoration: none; color: inherit; }
.host-name { font-size: 1.45rem; line-height: 1.2; }
.host-addr, .host-meta, .tags { color: var(--muted); }
.tags { margin-top: 6px; }
.conn { margin-top: 8px; }
.conn-ok { color: var(--signal); }
.conn-fail { color: var(--danger); }
.conn-wait, .conn-unknown { color: var(--muted); }
.card-actions { display: flex; gap: 8px; margin-top: 14px; }
.card-actions button { padding: 6px 10px; }
.empty { margin-top: 28px; color: var(--muted); max-width: 36rem; }

.ledger { margin: 18px 0 16px; }
.table-wrap { overflow-x: auto; background: var(--sheet); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; }
code, pre { font-family: var(--mono); }
code { font-size: 0.86em; }

.detail-head { margin: 4px 0 0; }
.detail-head .tab { width: 14px; align-self: stretch; min-height: 64px; }
.head-actions { display: flex; gap: 8px; }
.tabs { display: flex; gap: 18px; margin: 22px 0 18px; border-bottom: 1px solid var(--line); }
.tabs a { text-decoration: none; padding: 8px 0 10px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.is-active { color: var(--ink); border-bottom-color: var(--signal); }

.chain {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
  counter-reset: step;
}
.chain li {
  counter-increment: step;
  padding: 10px 14px 0 0;
  border-top: 3px solid var(--signal);
  min-height: 72px;
}
.chain li::before {
  content: counter(step);
  display: block;
  font-family: var(--serif);
  color: var(--signal);
  margin-bottom: 4px;
}

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 28px 36px; }
.panel { margin-bottom: 28px; }
.pairs { margin: 0; }
.pairs div { display: grid; grid-template-columns: 4.5rem 1fr; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.pairs dt { color: var(--muted); }
.pairs dd { margin: 0; }
.wild-block { padding: 14px 0; border-top: 1px solid var(--line); }
.wild-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.wild-head .quiet { margin-left: 10px; }
.children, .rows { list-style: none; padding: 0; margin: 8px 0 0; }
.children { margin-left: 12px; padding-left: 14px; border-left: 3px solid var(--signal); }
.suffix { align-self: end; padding-bottom: 8px; color: var(--muted); }
.rows { margin-top: 14px; }
.rows li, .children li, .client header { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.client { margin-top: 8px; }
.client p { margin: 6px 0; }
.inline-form { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.stack-form, fieldset { display: flex; flex-direction: column; gap: 12px; }
.two { display: flex; gap: 12px; }
.two label { flex: 1; }
label, .field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); }
input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 8px 10px;
  background: white;
  color: var(--ink);
  min-width: 0;
}
textarea { resize: vertical; }
.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
.checks { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
pre { background: var(--code); color: var(--code-ink); padding: 14px 16px; overflow-x: auto; line-height: 1.55; }
.is-hidden { display: none; }

.backdrop { position: fixed; inset: 0; background: rgba(26, 39, 48, 0.46); display: grid; place-items: center; padding: 24px; z-index: 5; }
.dialog {
  width: min(500px, 100%);
  max-height: min(860px, calc(100vh - 48px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--sheet);
  border-radius: 8px;
}
.dialog-body { overflow: auto; padding: 0 18px 12px; }
.dialog header, .dialog footer { display: flex; align-items: center; padding: 16px 18px; }
.dialog header { justify-content: space-between; }
.dialog header h2 { margin: 0; font-size: 1.35rem; }
.dialog footer { justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); }
.icon { border: 0; background: transparent; font-size: 1.4rem; line-height: 1; padding: 0 4px; }
fieldset { border: 0; margin: 4px 0 0; padding: 0; }
legend { padding: 0; font-family: var(--serif); font-size: 1.05rem; color: var(--ink); }
.segmented { display: flex; gap: 0; border: 1px solid var(--line); }
.segmented button { flex: 1; border: 0; border-radius: 0; background: transparent; white-space: nowrap; }
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button.is-selected { background: var(--ink); color: white; }
.swatches { display: flex; gap: 10px; }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--sheet); box-shadow: 0 0 0 1px var(--line); padding: 0; }
.swatch.is-selected { box-shadow: 0 0 0 2px var(--signal); }
.form-error { margin: 0 0 8px; color: var(--danger); }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .rail { border-right: 0; border-bottom: 1px solid var(--line); padding: 16px; }
  .brand { margin: 0 0 12px; }
  .rail nav { flex-direction: row; gap: 8px; }
  .chain, .split { grid-template-columns: 1fr; }
  .chain li { border-top: 0; border-left: 3px solid var(--signal); padding: 0 0 12px 12px; min-height: 0; }
  .stage { padding: 20px 16px 48px; }
  .page-head, .detail-head { flex-direction: column; }
}

.row-actions { display: flex; gap: 8px; justify-content: flex-end; }
.row-actions button { padding: 5px 10px; }
.st-pending { color: #8a5a00; }
.st-ready { color: var(--signal); }
.st-rejected { color: var(--danger); }

/* 登录 */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--sheet);
  border: 1px solid var(--line);
  padding: 32px 28px 28px;
}
.login-card .brand { margin: 0 0 4px; }
.login-card h1 { font-size: 1.5rem; margin: 0 0 4px; }
.login-card .primary { margin-top: 4px; padding: 10px 14px; }
.login-error { margin: 0; color: var(--danger); }

/* 左栏底部：当前用户和退出 */
.rail { display: flex; flex-direction: column; }
.rail-user {
  order: 2;
  margin-top: auto;
  padding: 16px 12px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}
.rail-user .link { border: 0; background: none; padding: 0; color: var(--signal); }
.rail-user .link:hover { text-decoration: underline; }
