:root {
  --bg: #0b0e14;
  --bg-soft: #0e131b;
  --panel: #141a24;
  --panel-2: #1a2230;
  --panel-3: #202a3a;
  --border: #232c3b;
  --border-hi: #2f3b4e;
  --text: #d6dee9;
  --muted: #7d8b9e;
  --dim: #5b6779;
  --accent: #ffd60a;
  --accent-dim: rgba(255, 214, 10, 0.1);
  --ok: #3fd18b;
  --warn: #f0a93b;
  --err: #f4645f;
  --info: #56a8ff;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a3446; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #3a475c; }

button, input, select, textarea { font-family: inherit; font-size: 14px; color: var(--text); }
a { color: var(--info); text-decoration: none; }
code, pre { font-family: var(--mono); }

/* ---------------- 布局 ---------------- */

.app { display: flex; height: 100vh; }

.sidebar {
  width: 252px;
  flex: 0 0 252px;
  background: linear-gradient(180deg, #0e131b 0%, #0b0e14 100%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
}

.sidebar::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.7;
}

.brand {
  padding: 22px 18px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: #0b0e14;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 15px;
  box-shadow: 0 0 20px rgba(255, 214, 10, 0.25);
}

.brand-text { line-height: 1.2; }
.brand-text b { font-size: 14px; letter-spacing: 0.3px; }
.brand-text span { display: block; font-size: 11px; color: var(--dim); letter-spacing: 0.6px; }

.side-actions { padding: 0 14px 12px; }

.side-label {
  padding: 14px 18px 8px;
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--dim);
  text-transform: uppercase;
}

.bot-nav { flex: 1; overflow-y: auto; padding: 0 10px 10px; }

.bot-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  margin-bottom: 2px;
  transition: background 0.15s, border-color 0.15s;
}
.bot-item:hover { background: var(--panel); }
.bot-item.active { background: var(--panel-2); border-color: var(--border-hi); }
.bot-item.active .bot-name { color: var(--accent); }

.bot-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--dim);
  flex: 0 0 7px;
}
.bot-dot.on { background: var(--ok); box-shadow: 0 0 8px rgba(63, 209, 139, 0.6); }
.bot-dot.off { background: var(--dim); }

.bot-name {
  flex: 1;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bot-tag {
  font-size: 10px;
  color: var(--dim);
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.side-foot { padding: 10px; border-top: 1px solid var(--border); }

.side-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
}
.side-link:hover { background: var(--panel); color: var(--text); }
.side-link.active { color: var(--accent); background: var(--accent-dim); }

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

.topbar {
  height: 58px;
  flex: 0 0 58px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  background: rgba(11, 14, 20, 0.8);
  backdrop-filter: blur(10px);
}

.topbar h1 { font-size: 15px; font-weight: 600; letter-spacing: 0.2px; }
.topbar .sub { font-size: 12px; color: var(--dim); }

.spacer { flex: 1; }

.content { flex: 1; overflow-y: auto; padding: 24px; }

/* ---------------- 通用组件 ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border-hi);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.btn:hover { background: var(--panel-3); border-color: #3a475c; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; filter: grayscale(0.7); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0e14;
  font-weight: 600;
}
.btn.primary:hover { background: #ffe14d; border-color: #ffe14d; }

.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover { background: var(--panel); }

.btn.danger { color: var(--err); border-color: rgba(244, 100, 95, 0.4); background: rgba(244, 100, 95, 0.08); }
.btn.danger:hover { background: rgba(244, 100, 95, 0.16); }

.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 6px; }
.btn.block { width: 100%; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title .hint { font-weight: 400; color: var(--dim); font-size: 12px; }

.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 1100px) {
  .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.c3, .grid.c2 { grid-template-columns: 1fr; }
}

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
}
.stat::after {
  content: "";
  position: absolute;
  right: -16px; top: -16px;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 214, 10, 0.14), transparent 68%);
}
.stat .k { font-size: 11px; color: var(--dim); letter-spacing: 0.8px; text-transform: uppercase; }
.stat .v { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -0.5px; }
.stat .v small { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 4px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 7px;
  border-radius: 5px;
  font-size: 11px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--panel-2);
  white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: rgba(63, 209, 139, 0.35); background: rgba(63, 209, 139, 0.08); }
.badge.warn { color: var(--warn); border-color: rgba(240, 169, 59, 0.35); background: rgba(240, 169, 59, 0.08); }
.badge.err { color: var(--err); border-color: rgba(244, 100, 95, 0.35); background: rgba(244, 100, 95, 0.08); }
.badge.info { color: var(--info); border-color: rgba(86, 168, 255, 0.35); background: rgba(86, 168, 255, 0.08); }
.badge.gold { color: var(--accent); border-color: rgba(255, 214, 10, 0.35); background: var(--accent-dim); }

/* ---------------- 表单 ---------------- */

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field > label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: 0.2px;
}
.field .desc { font-size: 11px; color: var(--dim); margin-top: 5px; line-height: 1.5; }

.input, .select, .textarea {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: rgba(255, 214, 10, 0.5);
  box-shadow: 0 0 0 3px rgba(255, 214, 10, 0.08);
}
.input::placeholder, .textarea::placeholder { color: #465266; }
.textarea { min-height: 96px; resize: vertical; line-height: 1.6; font-family: var(--mono); font-size: 12.5px; }
.select { appearance: none; cursor: pointer; }

.row { display: flex; gap: 12px; align-items: center; }
.row > * { min-width: 0; }

.switch {
  position: relative;
  width: 38px; height: 21px;
  border-radius: 11px;
  background: #18202c;
  border: 1px solid var(--border-hi);
  cursor: pointer;
  flex: 0 0 38px;
  transition: background 0.18s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 17px; height: 17px;
  border-radius: 50%;
  background: #8496ae;
  transition: transform 0.18s, background 0.18s;
}
.switch.on { background: rgba(255, 214, 10, 0.28); border-color: rgba(255, 214, 10, 0.45); }
.switch.on::after { transform: translateX(17px); background: var(--accent); }

.checkline { display: flex; align-items: center; gap: 10px; padding: 7px 0; cursor: pointer; }
.checkline input[type="checkbox"] {
  appearance: none;
  width: 16px; height: 16px;
  border: 1px solid var(--border-hi);
  border-radius: 4px;
  background: var(--bg-soft);
  cursor: pointer;
  position: relative;
  flex: 0 0 16px;
}
.checkline input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.checkline input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 5px; top: 1px;
  width: 4px; height: 9px;
  border: solid #0b0e14;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ---------------- bot 卡片 ---------------- */

.bot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }

.bot-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 158px;
}
.bot-card:hover {
  border-color: var(--border-hi);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.bot-card-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.bot-avatar {
  width: 36px; height: 36px;
  border-radius: 9px;
  display: grid; place-items: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  background: linear-gradient(135deg, rgba(255, 214, 10, 0.16), rgba(255, 214, 10, 0.03));
  border: 1px solid rgba(255, 214, 10, 0.18);
  flex: 0 0 36px;
}
.bot-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.bot-card .slug { font-size: 11px; color: var(--dim); font-family: var(--mono); }
.bot-card .desc {
  font-size: 12px;
  color: var(--muted);
  flex: 1;
  overflow: hidden;
  margin-bottom: 12px;
  line-height: 1.6;
}
.bot-card-foot {
  display: flex; align-items: center; gap: 8px;
  padding-top: 11px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--dim);
  margin-top: auto;
}
.bot-card-foot > span { white-space: nowrap; }

.empty {
  text-align: center;
  padding: 70px 20px;
  color: var(--dim);
}
.empty .big { font-size: 30px; margin-bottom: 14px; color: var(--border-hi); font-weight: 300; }
.empty h2 { font-size: 15px; color: var(--muted); font-weight: 500; margin-bottom: 6px; }
.empty p { font-size: 12px; margin-bottom: 18px; }

/* ---------------- tabs ---------------- */

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab {
  padding: 9px 14px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------------- 代码块 / 复制 ---------------- */

.copybox {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--info);
  word-break: break-all;
}
.copybox .val { flex: 1; min-width: 0; }
.copybox button {
  background: transparent;
  border: 1px solid var(--border-hi);
  color: var(--muted);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
  flex: 0 0 auto;
}
.copybox button:hover { color: var(--accent); border-color: var(--accent); }

pre.log {
  background: #080b10;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 11.5px;
  line-height: 1.7;
  overflow: auto;
  max-height: 460px;
  color: #9aa8bb;
}

/* ---------------- 聊天调试 ---------------- */

.chat {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 260px);
  min-height: 340px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.chat-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}
.chat-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.chat-foot { padding: 10px; border-top: 1px solid var(--border); display: flex; gap: 8px; }

.msg { display: flex; gap: 8px; max-width: 82%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg .bubble {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.65;
}
.msg.user .bubble { background: rgba(255, 214, 10, 0.1); border-color: rgba(255, 214, 10, 0.25); }
.msg .meta { font-size: 10px; color: var(--dim); margin-top: 4px; }
.msg.sys { align-self: center; max-width: 100%; }
.msg.sys .bubble { background: transparent; border: 1px dashed var(--border); color: var(--dim); font-size: 11px; }

.typing::after {
  content: "···";
  animation: blink 1.2s infinite;
}
@keyframes blink { 0%, 100% { opacity: 0.2; } 50% { opacity: 1; } }

/* ---------------- 模板选择 ---------------- */

.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.tpl {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all 0.15s;
}
.tpl:hover { border-color: var(--border-hi); background: var(--panel-2); }
.tpl.sel { border-color: var(--accent); background: var(--accent-dim); box-shadow: 0 0 0 1px var(--accent) inset; }
.tpl .ico {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  background: linear-gradient(135deg, rgba(255, 214, 10, 0.16), rgba(255, 214, 10, 0.03));
  border: 1px solid rgba(255, 214, 10, 0.18);
  margin-bottom: 10px;
}
.tpl h3 { font-size: 13.5px; margin-bottom: 4px; }
.tpl .tl { font-size: 11.5px; color: var(--accent); margin-bottom: 8px; }
.tpl p { font-size: 11.5px; color: var(--muted); line-height: 1.55; }

/* ---------------- 步骤条 ---------------- */

.steps { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; }
.step { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--dim); }
.step .n {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border-hi);
  display: grid; place-items: center;
  font-size: 11px;
}
.step.on { color: var(--accent); }
.step.on .n { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.step.done .n { background: var(--ok); border-color: var(--ok); color: #0b0e14; }
.step-line { width: 34px; height: 1px; background: var(--border); }

/* ---------------- toast ---------------- */

.toast-wrap {
  position: fixed;
  top: 16px; right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
}
.toast {
  background: var(--panel-2);
  border: 1px solid var(--border-hi);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12.5px;
  min-width: 220px;
  max-width: 400px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: slidein 0.2s ease;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
@keyframes slidein { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

/* ---------------- 弹层 ---------------- */

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.72);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 500;
  padding: 24px;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border-hi);
  border-radius: 14px;
  width: min(560px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}
.modal-head {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.modal-head h2 { font-size: 14px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.kv { display: flex; gap: 14px; padding: 7px 0; font-size: 12.5px; border-bottom: 1px dashed var(--border); }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--dim); flex: 0 0 110px; }
.kv .v { color: var(--text); flex: 1; word-break: break-all; }

.help {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.75;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-left: 2px solid var(--info);
  border-radius: 8px;
  padding: 12px 14px;
}
.help b { color: var(--text); font-weight: 600; }
.help ol { padding-left: 18px; }
.help li { margin: 4px 0; }

/* 后端掉线横幅：让"连不上"变成一句能照做的话，而不是 failed fetch */
.netbar {
  position: fixed;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(720px, 92vw);
  padding: 9px 12px 9px 14px;
  background: #1b180e;
  border: 1px solid rgba(255, 214, 10, 0.42);
  border-radius: 10px;
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.55);
  font-size: 12.5px;
  color: #e6e0cd;
}
.netbar[hidden] { display: none; }
.netbar-dot {
  flex: 0 0 7px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 214, 10, 0.15);
}
.netbar-text { line-height: 1.55; }
.netbar-btn {
  flex: 0 0 auto;
  margin-left: 2px;
  padding: 4px 11px;
  border-radius: 7px;
  border: 1px solid rgba(255, 214, 10, 0.42);
  background: rgba(255, 214, 10, 0.12);
  color: var(--accent);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.netbar-btn:hover { background: rgba(255, 214, 10, 0.2); }
.netbar-btn:disabled { opacity: 0.5; cursor: default; }
