:root {
  --bg: #f5f5f4; --panel: #ffffff; --side: #fafaf9; --ink: #18181b; --muted: #71717a; --line: #e4e4e7;
  --accent: #6d4aff; --accent-ink: #ffffff; --accent-bg: #efebff;
  --ok: #15803d; --warn: #a16207; --bad: #b91c1c;
  --ok-bg: #e7f6ec; --warn-bg: #fdf3d8; --bad-bg: #fde8e8; --chip: #f1f1f2; --code: #f4f4f5; --hover: #f1f1f2;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101012; --panel: #18181b; --side: #131316; --ink: #e9e9ec; --muted: #8e8e96; --line: #27272b;
    --accent: #9b85ff; --accent-ink: #0f0b1e; --accent-bg: #231c40;
    --ok: #4ade80; --warn: #facc15; --bad: #f87171;
    --ok-bg: #12291b; --warn-bg: #2d2610; --bad-bg: #331616; --chip: #232327; --code: #1f1f23; --hover: #212125;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
body:has(#side) { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
code, pre, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }
a { color: var(--accent); }

/* --- sidebar --- */
#side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
  background: var(--side); border-right: 1px solid var(--line); padding: 14px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; padding: 2px 8px 14px; }
.logo {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
#nav { display: flex; flex-direction: column; gap: 1px; flex: 1; overflow-y: auto; }
#nav .group { font-size: 11.5px; color: var(--muted); padding: 14px 10px 4px; }
#nav a {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 6px;
  color: var(--muted); text-decoration: none; white-space: nowrap;
}
#nav a svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linejoin: round; flex: none; }
#nav a:hover { color: var(--ink); background: var(--hover); }
#nav a.active { color: var(--ink); background: var(--panel); box-shadow: 0 0 0 1px var(--line); font-weight: 500; }
#nav-wait:not(:empty) {
  margin-left: auto; background: var(--warn-bg); color: var(--warn); font-size: 11.5px; font-weight: 600;
  border-radius: 99px; padding: 0 7px;
}
#side .foot { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 0;
  border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
#side .foot form { margin: 0; }

/* --- page --- */
main { width: 100%; max-width: 1120px; margin: 0 auto; padding: 26px 32px 80px; }
body:has(#side) main { margin: 0; }
.crumb { color: var(--muted); font-size: 12.5px; margin-bottom: 4px; }
.crumb a { color: inherit; text-decoration: none; }
.crumb a:hover { color: var(--ink); }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.head h2 { margin: 0; font-size: 21px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.head p { margin: 4px 0 0; color: var(--muted); max-width: 680px; }
h3 { font-size: 15px; font-weight: 600; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 10px;
}
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row .grow { flex: 1; min-width: 0; }
.title { font-weight: 600; font-size: 14.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.empty { text-align: center; color: var(--muted); padding: 40px 18px; }

/* --- tabs --- */
.tabs { display: flex; gap: 4px; box-shadow: inset 0 -1px var(--line); margin: 0 0 18px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs a {
  padding: 8px 12px; color: var(--muted); text-decoration: none; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tabs a:hover { color: var(--ink); }
.tabs a.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 500; }
.tabs a .n { color: var(--muted); font-size: 12px; margin-left: 4px; }

/* --- stat tiles --- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  text-decoration: none; color: inherit; }
a.stat:hover { border-color: var(--muted); }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .num { font-size: 24px; font-weight: 600; margin-top: 2px; }
.stat.warn { border-color: var(--warn); background: var(--warn-bg); }
.stat.warn .num, .stat.warn .label { color: var(--warn); }

/* --- app grid --- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.tile {
  display: block; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; text-decoration: none; color: inherit; position: relative; min-width: 0;
}
.tile:hover { border-color: var(--accent); }
.tile .top { display: flex; align-items: center; gap: 8px; }
.tile .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .meta { color: var(--muted); font-size: 12.5px; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .url { font-size: 12.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--accent); }
.tile.add { border-style: dashed; color: var(--muted); display: grid; place-items: center; min-height: 104px; text-align: center; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }

/* --- key/value rows --- */
.kv { display: grid; grid-template-columns: 160px minmax(0, 1fr); }
.kv > div { padding: 10px 0; border-top: 1px solid var(--line); min-width: 0; overflow-wrap: anywhere; }
.kv > div:nth-child(-n+2) { border-top: 0; }
.kv .k { color: var(--muted); }
.danger-zone { border-color: var(--bad); }

.chip {
  display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--chip);
  font-size: 12px; color: var(--muted); white-space: nowrap;
}
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }

button, .btn {
  font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); cursor: pointer; white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--muted); }
a.btn { text-decoration: none; color: inherit; display: inline-block; }
button.primary, a.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 500; }
button.danger { color: var(--bad); }
button.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 6px; }
#side button.link { color: var(--muted); padding: 0; }
#side button.link:hover { color: var(--ink); }
button:disabled { opacity: .5; cursor: default; }

pre, .codebox {
  background: var(--code); border-radius: 6px; padding: 10px 12px; margin: 10px 0 0;
  white-space: pre-wrap; word-break: break-all; max-height: 420px; overflow: auto;
}
pre.logs { max-height: 65vh; margin: 0; font-size: 12px; line-height: 1.45; }
.copyline { display: flex; gap: 8px; align-items: stretch; margin-top: 10px; }
.copyline .codebox { flex: 1; margin: 0; }
.prompt { font-family: inherit; font-size: 14px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12.5px; padding: 0 10px 8px; }
td { padding: 10px; border-top: 1px solid var(--line); vertical-align: top; }
tr.clickable:hover td { background: var(--hover); cursor: pointer; }

dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 32px));
  background: var(--panel); color: var(--ink);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog form { padding: 20px 22px; }
dialog h3 { margin: 0 0 14px; }
label { display: block; margin: 12px 0 4px; font-weight: 500; font-size: 13px; }
label.inline { display: flex; align-items: center; gap: 8px; font-weight: 400; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; font: inherit; padding: 7px 10px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink);
}
textarea { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; min-height: 70px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 3px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.error { color: var(--bad); margin-top: 10px; min-height: 1em; }
.checks label { margin: 4px 0; }

details.setup > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
details.setup > summary::-webkit-details-marker { display: none; }
details.setup > summary::after { content: "▸"; color: var(--muted); margin-left: auto; }
details.setup[open] > summary::after { content: "▾"; }
details.setup[open] > summary { margin-bottom: 14px; }

.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: s; position: relative; padding: 0 0 14px 34px; display: flex; gap: 12px;
  align-items: flex-start; flex-wrap: wrap; }
.steps li .grow { flex: 1; min-width: 220px; }
.steps li > .btn, .steps li > button { flex: none; }
.steps li.optional::before { background: none; border: 1px dashed var(--line); }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: 0; width: 22px; height: 22px; border-radius: 50%;
  background: var(--chip); display: grid; place-items: center; font-size: 12px; font-weight: 600;
}
.steps li.done::before { content: "✓"; background: var(--ok-bg); color: var(--ok); }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 8px 14px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20;
}
#toast.show { opacity: 1; }
.card.banner { border-color: var(--warn); }

@media (max-width: 800px) {
  body:has(#side) { grid-template-columns: minmax(0, 1fr); }
  #side {
    position: sticky; top: 0; z-index: 5; height: auto; flex-direction: row; align-items: center;
    padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--line); gap: 8px;
  }
  .brand { padding: 0; }
  .brand span:last-child, #nav .group, #side .foot #version { display: none; }
  #nav { flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  #nav a { padding: 6px 8px; }
  #side .foot { border: 0; padding: 0; }
  main { padding: 20px 16px 60px; }
  .grid2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .kv .k { padding-bottom: 0; }
  .kv .k + div { border-top: 0; padding-top: 2px; }
  .head { flex-direction: column; align-items: stretch; }
  .hide-sm { display: none; }
}
