/* ============================================================
   Design tokens
   ============================================================ */

:root {
  /* 中性色：用带一点蓝的灰，比纯灰更有质感 */
  --c-bg: #f6f7fb;
  --c-surface: #ffffff;
  --c-surface-2: #fbfbfe;
  --c-border: #e6e8f0;
  --c-border-strong: #d6d9e6;

  --c-text: #12141c;
  --c-text-2: #4a5164;
  --c-text-3: #8b93a8;

  /* 主色：靛蓝，配一个更亮的辅助色做渐变 */
  --c-brand: #4f46e5;
  --c-brand-2: #7c6cf2;
  --c-brand-soft: #eef0ff;
  --c-brand-ring: rgba(79, 70, 229, 0.16);

  --c-green: #10b981;
  --c-green-soft: #e7f8f1;
  --c-amber: #f59e0b;
  --c-amber-soft: #fef6e7;
  --c-red: #ef4444;
  --c-red-soft: #fdecec;

  /* 阴影：多层叠加，比单层大阴影更自然 */
  --sh-xs: 0 1px 2px rgba(18, 20, 28, 0.05);
  --sh-sm: 0 1px 3px rgba(18, 20, 28, 0.06), 0 1px 2px rgba(18, 20, 28, 0.04);
  --sh-md: 0 4px 12px rgba(18, 20, 28, 0.07), 0 1px 3px rgba(18, 20, 28, 0.05);
  --sh-lg: 0 12px 32px rgba(18, 20, 28, 0.1), 0 2px 8px rgba(18, 20, 28, 0.05);
  --sh-xl: 0 24px 60px rgba(18, 20, 28, 0.14);

  --r-sm: 8px;
  --r-md: 11px;
  --r-lg: 15px;
  --r-xl: 20px;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --t-fast: 0.14s var(--ease);
  --t: 0.22s var(--ease);

  --side-w: 236px;
}

/* ============================================================
   Base
   ============================================================ */

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums;
}

a { color: var(--c-brand); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, .mono {
  font-family: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

/* 统一滚动条，别用系统默认那种厚灰条 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #cdd1de;
  border-radius: 6px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-clip: content-box; background-color: #aeb4c7; }

/* 图标统一尺寸与描边风格 */
.i {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}
.i-sm { width: 15px; height: 15px; }
.i-lg { width: 22px; height: 22px; }

/* ============================================================
   Layout
   ============================================================ */

.layout {
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  min-height: 100vh;
}

.side {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 18px 12px 14px;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  overflow-y: auto;
}

.side .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--c-text);
}
.side .brand:hover { text-decoration: none; }

.side .brand .mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 11px;
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--c-brand), var(--c-brand-2));
  box-shadow: 0 5px 14px rgba(79, 70, 229, 0.3);
}

.side .group-title {
  padding: 16px 10px 5px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #a8afc0;
}

.side a.nav {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--c-text-2);
  transition: background var(--t-fast), color var(--t-fast);
}
.side a.nav:hover {
  background: var(--c-surface-2);
  color: var(--c-text);
  text-decoration: none;
}
.side a.nav.on {
  background: var(--c-brand-soft);
  color: var(--c-brand);
  font-weight: 600;
}
/* 侧边栏角标（比如「插件审核 3」）。空的时候不占位 */
.nav-badge {
  margin-left: auto;
  padding: 0 7px;
  border-radius: 20px;
  background: var(--c-red);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 17px;
}
.nav-badge:empty { display: none; }
/* 选中项左侧一道竖线，比整块变色更清爽 */
.side a.nav.on::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  border-radius: 0 3px 3px 0;
  background: var(--c-brand);
}
.side a.nav.on .i { stroke-width: 2.1; }
.side a.nav .i { color: #9aa2b5; transition: color var(--t-fast); }
.side a.nav:hover .i { color: var(--c-text-2); }
.side a.nav.on .i { color: var(--c-brand); }

.side .spacer { flex: 1; min-height: 12px; }

/* 底部操作区与主导航之间加一道分隔线，配合分隔线让空白看起来是有意的 */
.side .side-foot {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--c-border);
}

.main {
  min-width: 0;
  padding: 26px 30px 80px;
  max-width: 1320px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 26px;
}
.topbar h1 {
  margin: 0 0 4px;
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -0.7px;
  line-height: 1.25;
}
.topbar p { margin: 0; font-size: 13px; color: var(--c-text-3); }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============================================================
   Card
   ============================================================ */

.card {
  padding: 20px 22px;
  margin-bottom: 16px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
}
.card > h2 {
  margin: 0 0 3px;
  font-size: 15.5px;
  font-weight: 650;
  letter-spacing: -0.25px;
}
.card .card-sub {
  margin: 0 0 16px;
  font-size: 12.5px;
  color: var(--c-text-3);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}
.card-head h2 { margin: 0 0 3px; font-size: 15.5px; font-weight: 650; letter-spacing: -0.25px; }
.card-head .card-sub { margin: 0; }
/* 头部右侧放个淡化的大图标做装饰，视觉上不空 */
.card-head > .i {
  width: 30px; height: 30px;
  color: #e2e5ee;
  stroke-width: 1.6;
}

/* ============================================================
   Stats
   ============================================================ */

/* 统计卡：固定 4 列，窄屏逐级降到 2 列 / 1 列。
   不用 auto-fit —— 它会在某些宽度下算出多余的空列。 */
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.stat {
  position: relative;
  padding: 17px 19px 18px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
  overflow: hidden;
  transition: box-shadow var(--t), border-color var(--t), transform var(--t);
}
.stat:hover {
  box-shadow: var(--sh-md);
  border-color: var(--c-border-strong);
  transform: translateY(-1px);
}
/* 顶部一道彩色细线，作为视觉锚点 */
.stat::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--c-brand), var(--c-brand-2));
  opacity: 0;
  transition: opacity var(--t);
}
.stat:hover::before { opacity: 1; }

/* 图标和文字左右并排，比上下堆叠更省纵向空间、也更紧凑 */
.stat .ico {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  margin-bottom: 11px;
  border-radius: 10px;
  background: var(--c-brand-soft);
  color: var(--c-brand);
}
.stat .ico .i { width: 19px; height: 19px; stroke-width: 2; }

/* 不同语义的统计卡用不同色调，一眼能区分 */
.stat.tone-green .ico { background: var(--c-green-soft); color: var(--c-green); }
.stat.tone-green::before { background: linear-gradient(90deg, var(--c-green), #34d399); }
.stat.tone-amber .ico { background: var(--c-amber-soft); color: var(--c-amber); }
.stat.tone-amber::before { background: linear-gradient(90deg, var(--c-amber), #fbbf24); }
.stat.tone-sky .ico { background: #e8f4fe; color: #0d8bd9; }
.stat.tone-sky::before { background: linear-gradient(90deg, #0d8bd9, #38bdf8); }

.stat .label {
  display: block;
  margin-bottom: 2px;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--c-text-3);
  letter-spacing: 0.1px;
}

.stat .value {
  font-size: 29px;
  font-weight: 720;
  letter-spacing: -1.2px;
  line-height: 1.05;
  color: var(--c-text);
}

.stat .sub {
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px solid #f2f4f9;
  font-size: 11.5px;
  color: var(--c-text-3);
}

/* 等宽两栏：让两栏高度一致，避免底部出现一块空缺 */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: stretch;
  margin-bottom: 16px;
}
.grid-2 > .card {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
/* 卡片内容区撑满剩余高度，内部自己滚动，不会在底部留白 */
.grid-2 > .card > .logs {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  /* 内容不够长时不强制撑高，只是最长不超过卡片 */
  max-height: 100%;
}
.grid-2 > .card > .env-grid { flex: 1; align-content: start; }

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; align-items: stretch; }
.grid-3 > .card { margin-bottom: 0; }

/* 日志滚动区：给个下限高度，内容少时也不会塌成一条 */
.scroll-y {
  max-height: 400px;
  min-height: 200px;
  overflow-y: auto;
  margin: 0 -6px -2px 0;
  padding-right: 6px;
}

/* ============================================================
   Button
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 37px;
  padding: 0 14px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-sm);
  background: var(--c-surface);
  color: var(--c-text-2);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--sh-xs);
  transition: background var(--t-fast), border-color var(--t-fast),
              color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
}
.btn:hover:not(:disabled) {
  background: var(--c-surface-2);
  border-color: var(--c-border-strong);
  color: var(--c-text);
  box-shadow: var(--sh-sm);
}
.btn:active:not(:disabled) { transform: translateY(0.5px); box-shadow: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(135deg, var(--c-brand), var(--c-brand-2));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.28);
}
.btn.primary:hover:not(:disabled) {
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.36);
  color: #fff;
  filter: brightness(1.05);
}

.btn.danger { color: var(--c-red); border-color: #f6d4d4; }
.btn.danger:hover:not(:disabled) { background: var(--c-red-soft); color: var(--c-red); }

.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; gap: 5px; }
.btn.sm .i { width: 13px; height: 13px; }
.btn.block { width: 100%; height: 42px; font-size: 14px; }
.btn.icon { width: 37px; padding: 0; }
.btn.sm.icon { width: 30px; }

/* ============================================================
   Form
   ============================================================ */

.field { margin-bottom: 15px; }

/*
 * 普通字段标签：块级 + 小号加粗。
 *
 * `:not(.switch)` 是必须的 —— 开关用的也是 <label>，但它得是 inline-flex
 * （里面的 .track 是个 span，父级不是 flex 的话宽高会失效，开关就变成一条线）。
 * 不加这条例外的话，`.field > label`（0,1,1）会压过 `.switch`（0,1,0）。
 */
.field > label:not(.switch) {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--c-text-2);
}

/*
 * .field 里的控件样式。
 * 通用外观（边框、圆角、聚焦环）在下面「通用表单控件」那段统一处理，
 * 这里只管 .field 特有的：占满宽度、字号大一号。
 */
.field input,
.field select,
.field textarea,
.input {
  width: 100%;
}
.field textarea { min-height: 84px; resize: vertical; line-height: 1.65; }
.field textarea.mono { font-size: 12.5px; }

.field input::placeholder,
.field textarea::placeholder { color: #b3b9c9; }

.field .hint {
  margin-top: 5px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--c-text-3);
}
.field .hint code {
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  font-size: 11px;
}

/* ============================================================
   通用表单控件
   ------------------------------------------------------------
   上面那套样式挂在 .field 上，所以只要不在 .field 里的控件
   （比如按钮编辑器、模板库的输入框）就还是浏览器默认外观 ——
   一个页面里两种输入框，很丑。这里给所有没有别样式的原生控件兜底。
   ============================================================ */

/*
 * 注意 input:not([type]) —— 没写 type 的 <input> 浏览器按 text 处理，
 * 但 `input[type="text"]` 是选不到它的。按钮编辑器里的输入框全都没有 type，
 * 漏掉这一条会导致同一个弹窗里 select 是圆角的、input 还是原生凹陷边框。
 */
input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
input[type="search"],
input[type="url"],
input[type="date"],
input[type="datetime-local"],
input:not([type]),
select,
textarea {
  padding: 7px 10px;
  border: 1px solid var(--c-border-strong);
  border-radius: 7px;
  background: var(--c-surface);
  color: var(--c-text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--c-brand);
  box-shadow: 0 0 0 3px var(--c-brand-ring);
}

input::placeholder,
textarea::placeholder { color: #b3b9c9; }

input:disabled,
select:disabled,
textarea:disabled {
  background: var(--c-surface-2);
  color: var(--c-text-3);
  cursor: not-allowed;
}

/* 下拉箭头统一（原生箭头各系统长得不一样） */
select:not([multiple]) {
  appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b93a8' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
}

/* 复选框 / 单选框统一配色，保留原生语义 */
input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--c-brand);
  width: 15px;
  height: 15px;
  cursor: pointer;
}
input[type="checkbox"]:disabled,
input[type="radio"]:disabled { cursor: not-allowed; }

/* .field 里的控件要更大一号，覆盖上面的兜底值 */
.field input[type="text"],
.field input[type="password"],
.field input[type="number"],
.field input[type="email"],
.field input[type="search"],
.field input[type="url"],
.field select,
.field textarea {
  padding: 9px 12px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
}

/* checkbox：用 accent-color 保持原生语义但统一配色 */
.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--c-text-2);
  cursor: pointer;
  user-select: none;
}
.checkbox input {
  width: 16px; height: 16px;
  accent-color: var(--c-brand);
  cursor: pointer;
  flex: 0 0 auto;
}

/* 开关式 checkbox */
.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  position: relative;
  width: 38px; height: 22px;
  border-radius: 999px;
  background: #d3d7e3;
  transition: background var(--t);
  flex: 0 0 auto;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--sh-sm);
  transition: transform var(--t);
}
.switch input:checked + .track { background: var(--c-brand); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--c-brand-ring); }
.switch .switch-label { font-size: 13px; color: var(--c-text-2); }

/* ============================================================
   Table
   ============================================================ */

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}

th {
  padding: 0 12px 10px;
  text-align: left;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: #9aa2b5;
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
}

td {
  padding: 14px 12px;
  border-bottom: 1px solid #f2f4f9;
  vertical-align: middle;
}
tbody tr { transition: background var(--t-fast); }
tbody tr:hover { background: var(--c-surface-2); }
tbody tr:last-child td { border-bottom: 0; }
/* 第一列和最后一列贴边不留白，视觉上更整齐 */
th:first-child, td:first-child { padding-left: 4px; }
th:last-child, td:last-child { padding-right: 4px; }

td.actions { text-align: right; white-space: nowrap; }
td.actions .btn + .btn { margin-left: 6px; }

.cell-title { font-weight: 620; color: var(--c-text); }
.cell-sub {
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--c-text-3);
}

/* ============================================================
   Badge / status
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 620;
  background: #f1f2f7;
  color: var(--c-text-2);
  white-space: nowrap;
}
.badge.online { background: var(--c-green-soft); color: #0a7d5a; }
.badge.offline { background: #f1f2f7; color: #7d8496; }
.badge.connecting { background: var(--c-amber-soft); color: #a16207; }
.badge.err { background: var(--c-red-soft); color: #c02e2e; }
.badge.info { background: var(--c-brand-soft); color: var(--c-brand); }
.badge.admin { background: #fff3e2; color: #a16207; }

.dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}
.badge.online .dot { animation: pulse 2s var(--ease) infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}

/* ============================================================
   Empty state
   ============================================================ */

.empty {
  padding: 52px 20px;
  text-align: center;
  color: var(--c-text-3);
  font-size: 13.5px;
}
.empty .icon-circle {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--c-brand-soft);
  color: var(--c-brand);
}
.empty .icon-circle .i { width: 26px; height: 26px; }
.empty b { display: block; color: var(--c-text-2); font-size: 14px; margin-bottom: 4px; }
.empty .btn { margin-top: 16px; }

/* ============================================================
   Auth pages
   ============================================================ */

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 720px 420px at 12% -5%, rgba(124, 108, 242, 0.16), transparent 62%),
    radial-gradient(ellipse 640px 420px at 92% 105%, rgba(56, 189, 248, 0.13), transparent 62%),
    var(--c-bg);
}

.auth-card {
  width: min(408px, 100%);
  padding: 32px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-xl);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 6px;
  font-size: 17px;
  font-weight: 750;
  letter-spacing: -0.4px;
}
.auth-logo .mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 12px;
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--c-brand), var(--c-brand-2));
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.32);
}

.auth-sub {
  margin: 0 0 24px;
  font-size: 12.5px;
  color: var(--c-text-3);
}

.tabs {
  position: relative;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  padding: 3px;
  margin-bottom: 22px;
  border-radius: 10px;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
}
.tabs button {
  padding: 7px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--c-text-3);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
}
.tabs button:hover { color: var(--c-text-2); }
.tabs button.on {
  background: var(--c-surface);
  color: var(--c-brand);
  box-shadow: var(--sh-sm);
}

/* ============================================================
   Modal
   ============================================================ */

.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(18, 20, 28, 0.42);
  backdrop-filter: blur(3px);
  animation: fade 0.15s var(--ease);
}

.modal {
  width: min(540px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px;
  background: var(--c-surface);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-xl);
  animation: rise 0.2s var(--ease);
}
.modal.wide { width: min(760px, 100%); }
.modal h3 { margin: 0 0 4px; font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }
.modal .modal-sub { margin: 0 0 20px; font-size: 12.5px; color: var(--c-text-3); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--c-border);

  /*
   * 内容超过 max-height 时整块弹窗会一起滚，连带这行按钮 ——
   * 审核那种「几百行源码 + 底部按钮」的场景，按钮就被顶到视口外，
   * 得先滚到底才能点「通过」，很容易让人以为没有这个操作。
   *
   * 所以把它钉在底部：源码区照常滚，按钮始终看得见。
   * 负的 bottom/margin-bottom 抵消 .modal 自己的 24px 内边距（否则会露一条缝），
   * 下圆角跟着弹窗走，免得把圆角切成直角。
   */
  position: sticky;
  bottom: -24px;
  z-index: 1;
  margin-bottom: -24px;
  padding-bottom: 24px;
  background: var(--c-surface);
  border-radius: 0 0 var(--r-xl) var(--r-xl);
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise {
  from { opacity: 0; transform: translateY(10px) scale(0.99); }
  to { opacity: 1; transform: none; }
}

/* ============================================================
   Toast / Alert
   ============================================================ */

.toast-host {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: 380px;
  padding: 11px 15px;
  border-radius: 10px;
  background: #1b1e28;
  color: #fff;
  font-size: 13px;
  box-shadow: var(--sh-lg);
  animation: slidein 0.2s var(--ease);
}
.toast.ok { background: #0d7a56; }
.toast.err { background: #c02e2e; }

@keyframes slidein {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.alert {
  padding: 11px 14px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-size: 13px;
  line-height: 1.65;
  margin-bottom: 14px;
}
.alert:last-child { margin-bottom: 0; }
.alert.err { background: var(--c-red-soft); border-color: #f8dada; color: #9f2020; }
.alert.info { background: #eef4ff; border-color: #dbe6fb; color: #2354c4; }
.alert.ok { background: var(--c-green-soft); border-color: #cdeee0; color: #0a7d5a; }
.alert.warn { background: var(--c-amber-soft); border-color: #f9e6c4; color: #92610b; }
.alert code {
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.06);
  font-size: 11.5px;
}

/* ============================================================
   Logs
   ============================================================ */

.logs { display: flex; flex-direction: column; gap: 4px; }

.logline {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 12px;
  align-items: baseline;
  padding: 9px 12px;
  border-radius: 8px;
  border-left: 2px solid #e4e7f0;
  background: var(--c-surface-2);
  font-size: 12.5px;
  line-height: 1.6;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.logline:hover { background: #f4f5fa; }
.logline.warn { border-left-color: var(--c-amber); background: var(--c-amber-soft); }
.logline.error { border-left-color: var(--c-red); background: var(--c-red-soft); }

.logline .t {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
  color: #a8afbe;
  letter-spacing: -0.3px;
  text-align: right;
  white-space: nowrap;
}
.logline .s {
  display: inline-block;
  margin-right: 8px;
  padding: 1px 6px;
  border-radius: 5px;
  background: #eceefb;
  color: #5b52d6;
  font-size: 11px;
  font-weight: 600;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  vertical-align: 1px;
}
.logline .m { color: var(--c-text-2); word-break: break-word; }

.logline .body { min-width: 0; }
/* 日志行之间不需要 hover 位移，避免列表滚动时晃动 */
.logline:hover { transform: none; }

/* ============================================================
   聊天
   ============================================================ */

.chat-layout {
  display: grid;
  grid-template-columns: 268px 1fr;
  gap: 16px;
  /* 固定高度，两栏各自滚动，页面不会跟着一起滚 */
  height: calc(100vh - 168px);
  min-height: 420px;
}

.chat-list {
  margin-bottom: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.chat-list-head {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 14px 16px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  font-size: 13px;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 14px;
  border-bottom: 1px solid #f4f5f9;
  cursor: pointer;
  transition: background var(--t-fast);
}
.chat-item:hover { background: var(--c-surface-2); }
.chat-item.on { background: var(--c-brand-soft); }
.chat-item.on .ci-avatar { background: var(--c-brand); color: #fff; }

.ci-avatar {
  width: 38px; height: 38px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 11px;
  background: #f0f1f7;
  color: var(--c-text-3);
  transition: background var(--t-fast), color var(--t-fast);
}
.ci-avatar .i { width: 17px; height: 17px; }

.ci-body { flex: 1; min-width: 0; }
.ci-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.ci-top b {
  font-size: 13px;
  font-weight: 620;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ci-top span { font-size: 11px; color: var(--c-text-3); flex: 0 0 auto; }
.ci-preview {
  margin-top: 2px;
  font-size: 12px;
  color: var(--c-text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ci-unread {
  flex: 0 0 auto;
  min-width: 18px;
  padding: 0 5px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--c-red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

.chat-main {
  margin-bottom: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--c-border);
  flex: 0 0 auto;
}
.chat-head > div:first-child {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}
.chat-head b {
  font-size: 14px;
  /* 这里以前显示的是 openid（等宽字体），现在显示群名/备注，用普通字体更好看 */
  font-family: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 标题后面的 openid 提示：小、灰、悬停能看全 */
.chat-id-hint {
  font-size: 11px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  color: var(--c-text-3);
  cursor: help;
}

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  background: var(--c-surface-2);
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* 消息少时贴近输入框，不要浮在顶部留一大片空白 */
  justify-content: flex-end;
}

.bubble-row { display: flex; }
.bubble-row.out { justify-content: flex-end; }

.bubble {
  max-width: min(560px, 78%);
  padding: 9px 13px;
  border-radius: 13px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  box-shadow: var(--sh-xs);
}
.bubble-row.out .bubble {
  background: linear-gradient(135deg, var(--c-brand), var(--c-brand-2));
  border-color: transparent;
  color: #fff;
}

.bubble-text { font-size: 13.5px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.bubble-time {
  margin-top: 4px;
  font-size: 10.5px;
  color: var(--c-text-3);
  text-align: right;
}
.bubble-row.out .bubble-time { color: rgba(255, 255, 255, 0.72); }

.chat-input {
  flex: 0 0 auto;
  display: flex;
  /* 换行：让上面那排模式切换按钮（纯文本/Markdown/按钮）独占一行，
     输入框和发送按钮在下一行 —— 不然它们会挤在输入框左边，输入框只剩百来像素宽 */
  flex-wrap: wrap;
  gap: 9px;
  padding: 13px 16px;
  border-top: 1px solid var(--c-border);
  background: var(--c-surface);
  align-items: flex-end;
}

/* 模式切换那一排：占满整行 */
.chat-input .compose-tabs {
  flex: 1 0 100%;
  margin-bottom: 2px;
}

/* 输入框容器要能长开：flex:1 + min-width:0 才会占满剩余宽度 */
.chat-plain {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
}
.chat-plain textarea { width: 100%; }

/* Markdown 模式的富文本编辑器容器，同样占满 */
#chatRich {
  flex: 1 1 auto;
  min-width: 0;
}

.chat-input textarea {
  flex: 1;
  /* 默认给 3-4 行的高度：之前是 40px，写两行就出滚动条，太憋屈 */
  min-height: 78px;
  max-height: 260px;
  padding: 10px 12px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.55;
  /* 允许自己往下拖；内容多时也会自动长高（见 console.html 的 autoGrowChat） */
  resize: vertical;
  overflow-y: auto;
}
.chat-input textarea:focus {
  outline: none;
  border-color: var(--c-brand);
  box-shadow: 0 0 0 3px var(--c-brand-ring);
}

/* 群消息里的 @某人（QQ 原文是 <@openid>，鼠标悬停能看到原始 openid） */
.mention {
  display: inline-block;
  padding: 0 5px;
  border-radius: 5px;
  background: var(--c-brand-soft);
  color: var(--c-brand);
  font-size: 0.94em;
  font-weight: 600;
  cursor: help;
}
.bubble-row.out .mention {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

/* ============================================================
   词条 / 变量展示
   ============================================================ */

.chip {
  display: inline-block;
  margin: 1px 4px 1px 0;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--c-brand-soft);
  color: var(--c-brand);
  font-size: 11.5px;
  font-weight: 600;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

.reply-cand {
  padding: 2px 0;
  font-size: 12.5px;
  color: var(--c-text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-cand + .reply-cand { border-top: 1px dashed #eef0f6; }

.var-value {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .chat-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  .chat-list { max-height: 260px; }
  .chat-main { height: 70vh; }
}

/* ============================================================
   Misc blocks
   ============================================================ */

/* 键值对展示（旧样式，兼容其他页面） */
.kv {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 9px 14px;
  font-size: 13px;
}
.kv dt { color: var(--c-text-3); }
.kv dd {
  margin: 0;
  color: var(--c-text);
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
}

/* 运行环境：两列小卡片，比一长串文字更有结构感 */
.env-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  flex: 1;
  align-content: start;
  /* 行高均分，卡片少时也不会挤在顶部 */
  grid-auto-rows: minmax(58px, auto);
}
.env-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 14px;
  border-radius: var(--r-md);
  background: #fff;
  border: 1px solid var(--c-border);
  box-shadow: var(--sh-xs);
  min-width: 0;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.env-item:hover { border-color: var(--c-border-strong); box-shadow: var(--sh-sm); }

.env-item .eico {
  width: 32px; height: 32px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--c-brand-soft);
  color: var(--c-brand);
}
.env-item .eico .i { width: 16px; height: 16px; stroke-width: 2; }
/* 内容区撑满剩余宽度，避免右侧空一截 */
.env-item .ebody { flex: 1; min-width: 0; }
.env-item .ebody small {
  display: block;
  font-size: 11px;
  color: var(--c-text-3);
  margin-bottom: 2px;
}
.env-item .ebody b {
  display: block;
  font-size: 13px;
  font-weight: 620;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: -0.2px;
  word-break: break-all;
  line-height: 1.35;
}
/* 长字符串（比如数据库连接串）允许折成两行 */
.env-item .ebody b.wrap {
  white-space: normal;
  overflow-wrap: anywhere;
}

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

/* 垂直流程预览 */
.flow { display: flex; flex-direction: column; gap: 0; }
.flow .arrow {
  display: grid;
  place-items: center;
  height: 20px;
  color: #c3c8d6;
}
.flow .arrow .i { width: 13px; height: 13px; }

.flow-node {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 13px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface);
  box-shadow: var(--sh-xs);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.flow-node:hover { border-color: var(--c-border-strong); box-shadow: var(--sh-sm); }

.flow-node .ntype {
  flex: 0 0 auto;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--c-brand-soft);
  color: var(--c-brand);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.flow-node .ndesc {
  min-width: 0;
  font-size: 12.5px;
  color: var(--c-text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.flow-node .ndesc b { color: var(--c-text); font-weight: 600; }

/* 插件卡片 */
.plugin-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 18px;
  margin-bottom: 12px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.plugin-card:hover { border-color: var(--c-border-strong); box-shadow: var(--sh-md); }

.plugin-card .picon {
  width: 42px; height: 42px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--c-brand-soft);
  color: var(--c-brand);
}
.plugin-card .picon .i { width: 20px; height: 20px; }
.plugin-card .pbody { flex: 1; min-width: 0; }
.plugin-card h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 4px;
  font-size: 14.5px;
  font-weight: 650;
}
.plugin-card p { margin: 0 0 8px; font-size: 12.5px; color: var(--c-text-3); }
.plugin-card .pmeta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 11.5px;
  color: var(--c-text-3);
}
.plugin-card .pmeta code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  font-size: 11px;
}

/* 工具条 */
.toolbar {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar select { width: auto; }

/* 搜索框：给个合理上限，不要撑满整行 */
.search-wrap {
  position: relative;
  flex: 1 1 220px;
  max-width: 340px;
  min-width: 170px;
}
.search-wrap .i {
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--c-text-3);
  pointer-events: none;
  width: 15px; height: 15px;
}
.search-wrap .input { padding-left: 34px; width: 100%; }

/* ============================================================
   Install wizard
   ============================================================ */

.wizard { width: min(720px, 100%); }

.steps-bar {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
  margin-bottom: 24px;
}
.steps-bar .step-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 8px;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  background: var(--c-surface);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--c-text-3);
  transition: all var(--t);
}
.steps-bar .step-item .num {
  width: 19px; height: 19px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: #eff1f6;
  font-size: 11px;
  font-weight: 700;
}
.steps-bar .step-item.on {
  background: linear-gradient(135deg, var(--c-brand), var(--c-brand-2));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.28);
}
.steps-bar .step-item.on .num { background: rgba(255, 255, 255, 0.24); color: #fff; }
.steps-bar .step-item.done {
  background: var(--c-green-soft);
  border-color: #cdeee0;
  color: #0a7d5a;
}
.steps-bar .step-item.done .num { background: var(--c-green); color: #fff; }

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 11px 0;
  border-bottom: 1px solid #f2f3f8;
}
.check-row:last-child { border-bottom: 0; }
.check-row .ico { flex: 0 0 auto; margin-top: 1px; }
.check-row .ico.ok { color: var(--c-green); }
.check-row .ico.bad { color: var(--c-red); }
.check-row .body { flex: 1; min-width: 0; }
.check-row .body b { display: block; font-size: 13px; font-weight: 620; }
.check-row .body small {
  display: block;
  margin-top: 1px;
  font-size: 11.5px;
  color: var(--c-text-3);
  word-break: break-all;
}

.grid-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 15px;
}

.result-box {
  padding: 12px 14px;
  margin-top: 14px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-size: 13px;
  line-height: 1.7;
}
.result-box.ok { background: var(--c-green-soft); border-color: #cdeee0; color: #0a7d5a; }
.result-box.err { background: var(--c-red-soft); border-color: #f8dada; color: #9f2020; }
.result-box code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.06);
  font-size: 11.5px;
}

/* 完成页 */
.done-hero { text-align: center; padding: 14px 0 22px; }
.done-hero .ring {
  width: 62px; height: 62px;
  margin: 0 auto 16px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--c-green-soft);
  color: var(--c-green);
  animation: pop 0.4s var(--ease);
}
.done-hero .ring .i { width: 30px; height: 30px; stroke-width: 2.2; }
.done-hero h2 { margin: 0 0 5px; font-size: 19px; font-weight: 720; letter-spacing: -0.4px; }
.done-hero p { margin: 0; font-size: 13px; color: var(--c-text-3); }

@keyframes pop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

.steps-list { counter-reset: s; margin: 0; padding: 0; list-style: none; }
.steps-list li {
  position: relative;
  padding: 0 0 14px 30px;
  font-size: 13px;
  color: var(--c-text-2);
}
.steps-list li:last-child { padding-bottom: 0; }
.steps-list li::before {
  counter-increment: s;
  content: counter(s);
  position: absolute;
  left: 0; top: 1px;
  width: 19px; height: 19px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--c-brand-soft);
  color: var(--c-brand);
  font-size: 11px;
  font-weight: 700;
}

/* ============================================================
   Responsive
   ============================================================ */

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

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

  .side {
    position: sticky;
    top: 0;
    z-index: 50;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--c-border);
    box-shadow: var(--sh-sm);
  }
  .side .brand { padding: 0 12px 0 2px; font-size: 14px; }
  .side .brand .mark { width: 28px; height: 28px; font-size: 13px; }
  .side .group-title { display: none; }
  .side a.nav { padding: 7px 11px; white-space: nowrap; }
  .side .spacer { display: none; }

  .main { padding: 18px 16px 60px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .stats { grid-template-columns: minmax(0, 1fr); }
  .grid-form { grid-template-columns: 1fr; }
  .auth-card { padding: 24px 20px; }
  .topbar h1 { font-size: 19px; }
  .steps-bar { grid-auto-flow: row; grid-auto-columns: auto; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .btn { flex: 1; }
  .logline { grid-template-columns: 52px 1fr; }
}

/* 打印/无动画偏好 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   Markdown 渲染（.md）—— 消息预览、插件简介
   ============================================================ */

.md { font-size: 13.5px; line-height: 1.8; color: var(--c-text); word-wrap: break-word; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 {
  margin: 18px 0 9px; font-weight: 700; letter-spacing: -0.3px; line-height: 1.35;
}
.md h1 { font-size: 20px; }
.md h2 { font-size: 17px; }
.md h3 { font-size: 15px; }
.md h4 { font-size: 13.5px; color: var(--c-text-2); }
.md p { margin: 0 0 11px; }
.md ul, .md ol { margin: 0 0 11px; padding-left: 21px; }
.md li { margin-bottom: 4px; }
.md blockquote {
  margin: 0 0 11px; padding: 8px 13px;
  border-left: 3px solid var(--c-brand); border-radius: 0 7px 7px 0;
  background: var(--c-brand-soft); color: var(--c-text-2);
}
.md code {
  padding: 1.5px 5px; border-radius: 5px;
  background: var(--c-surface-2); color: #c02e2e;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px;
}
.md pre {
  margin: 0 0 12px; padding: 12px 14px; border-radius: var(--r-sm);
  background: #1b1e28; overflow-x: auto;
}
.md pre code { padding: 0; background: none; color: #e4e6ef; font-size: 12px; line-height: 1.65; }
.md pre[data-lang]::after {
  content: attr(data-lang); float: right; color: #6b7280;
  font-size: 10px; letter-spacing: 0.5px; text-transform: uppercase;
}
.md a { color: var(--c-brand); }
.md img { max-width: 100%; border-radius: var(--r-sm); margin: 4px 0 11px; }
.md hr { margin: 16px 0; border: 0; border-top: 1px solid var(--c-border); }
.md strong { font-weight: 680; }

/* ============================================================
   QQ 按钮编辑器（.qb-*）
   ============================================================ */

.qb-rows { display: flex; flex-direction: column; gap: 12px; }
.qb-row {
  padding: 11px 12px; border-radius: var(--r-sm);
  background: var(--c-surface-2); border: 1px dashed #dfe3ee;
}
.qb-row-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 9px; font-size: 12px; font-weight: 650; color: var(--c-text-3);
}
.qb-row-btn {
  padding: 2px 9px; border-radius: 6px; border: 1px solid var(--c-border);
  background: #fff; font-size: 11.5px; color: var(--c-text-2); cursor: pointer;
}
.qb-row-btn:hover { border-color: var(--c-brand); color: var(--c-brand); }
.qb-row-btn.danger:hover { border-color: var(--c-red); color: var(--c-red); }
.qb-row-btn:disabled { opacity: .45; cursor: not-allowed; }
.qb-row-btn.active { border-color: var(--c-brand); color: var(--c-brand); background: var(--c-brand-soft); }
.qb-row-empty { padding: 9px; text-align: center; font-size: 12px; color: var(--c-text-3); }

.qb-card {
  margin-bottom: 9px; padding: 11px; border-radius: var(--r-sm);
  background: #fff; border: 1px solid var(--c-border);
}
.qb-card:last-child { margin-bottom: 0; }
.qb-head { display: flex; align-items: center; gap: 7px; margin-bottom: 10px; }
.qb-num {
  flex: 0 0 auto; min-width: 28px; text-align: center;
  font-size: 10.5px; font-weight: 700; color: var(--c-text-3);
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.qb-label-in { flex: 1 1 auto; min-width: 0; font-weight: 600; }
.qb-style-in { flex: 0 0 auto; width: 108px; }
.qb-del {
  flex: 0 0 auto; width: 24px; height: 24px; border-radius: 6px;
  border: 1px solid var(--c-border); background: #fff;
  color: var(--c-text-3); cursor: pointer; font-size: 12px; line-height: 1;
}
.qb-del:hover { border-color: var(--c-red); color: var(--c-red); background: var(--c-red-soft); }

.qb-body { display: flex; flex-direction: column; gap: 9px; }
.qb-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.qb-f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.qb-f > span { font-size: 11px; font-weight: 600; color: var(--c-text-3); }
.qb-f input, .qb-f select { width: 100%; }
.qb-checks { display: flex; flex-wrap: wrap; gap: 12px; }
.qb-check { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--c-text-2); }
.qb-check:has(input:disabled) { opacity: .45; }
.qb-hint { font-size: 10.5px; color: var(--c-text-3); }
.qb-more { margin-top: 2px; }
.qb-more summary {
  cursor: pointer; font-size: 11.5px; color: var(--c-text-3);
  padding: 4px 0; user-select: none;
}
.qb-more summary:hover { color: var(--c-brand); }
.qb-more > *:not(summary) { margin-top: 9px; }
.qb-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.qb-warn { margin: 9px 0 0; font-size: 11.5px; color: #92610b; }
.qb-vars { margin: 9px 0 0; font-size: 11.5px; color: var(--c-text-3); }
.qb-vars code {
  margin-right: 3px; padding: 1px 5px; border-radius: 4px;
  background: var(--c-brand-soft); color: var(--c-brand); font-size: 11px;
}

/* 按钮预览：模拟手机上的样子 */
.kb-phone { padding: 13px; border-radius: 11px; background: #fff; border: 1px solid var(--c-border); }
.kb-row { display: flex; gap: 6px; margin-bottom: 6px; }
.kb-row:last-child { margin-bottom: 0; }
.kb-btn {
  flex: 1 1 0; min-width: 0; padding: 8px 6px; border-radius: 7px;
  text-align: center; font-size: 12.5px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kb-btn.ql-0 { background: #f4f5f8; color: #4b5565; border: 1px solid #dcdfe8; }
.kb-btn.ql-1 { background: #eef2ff; color: #4338ca; border: 1px solid #c7d2fe; }
.kb-btn.ql-3 { background: #fff; color: #c02e2e; border: 1px solid #f0c9c9; }
.kb-btn.ql-4 { background: #4f46e5; color: #fff; border: 1px solid #4f46e5; }
.kb-empty { padding: 18px; text-align: center; font-size: 12.5px; color: var(--c-text-3); }

/* 编辑器 + 预览并排 */
.kb-layout { display: grid; grid-template-columns: minmax(0, 1fr) 268px; gap: 16px; align-items: start; }
.kb-side { position: sticky; top: 16px; }
.kb-side h4 { margin: 0 0 9px; font-size: 12px; color: var(--c-text-3); font-weight: 650; }
@media (max-width: 900px) {
  .kb-layout { grid-template-columns: 1fr; }
  .kb-side { position: static; }
  .qb-grid { grid-template-columns: 1fr; }
}

/* 聊天输入区的模式切换 */
.compose-tabs { display: flex; gap: 3px; align-items: center; }
.compose-tabs button {
  padding: 4px 10px; border-radius: 7px; border: 1px solid transparent;
  background: none; font-size: 12px; color: var(--c-text-3); cursor: pointer;
}
.compose-tabs button:hover { background: var(--c-surface-2); color: var(--c-text); }
.compose-tabs button.on { background: var(--c-brand-soft); color: var(--c-brand); font-weight: 650; }
.compose-preview {
  max-height: 190px; overflow: auto; padding: 10px 12px;
  border-radius: var(--r-sm); background: var(--c-surface-2);
}

/* 消息气泡里的按钮 / markdown 标记 */.bubble-btns { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.bubble-btns .kb-row { gap: 4px; }
.bubble-btn {
  padding: 4px 8px; border-radius: 5px; font-size: 11px;
  background: rgba(127,127,127,.12); border: 1px solid rgba(127,127,127,.2);
}
.bubble .md { font-size: 13px; }

/* ============================================================
   机器人切换器（页面顶部那一排小卡片）
   ============================================================ */

.bot-switch {
  display: flex; gap: 8px;
  padding: 10px 12px; margin-bottom: 16px;
  border-radius: var(--r-md);
  background: #fff; border: 1px solid var(--c-border);
  overflow-x: auto;
  scrollbar-width: thin;
}
.bot-switch::-webkit-scrollbar { height: 5px; }
.bot-switch::-webkit-scrollbar-thumb { background: #dfe3ee; border-radius: 3px; }

.bot-chip {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 5px;
  border: 1px solid var(--c-border); border-radius: 22px;
  background: #fff; cursor: pointer;
  transition: all var(--t-fast);
}
.bot-chip:hover { border-color: #c9cfe0; background: var(--c-surface-2); }
.bot-chip.on {
  border-color: var(--c-brand);
  background: var(--c-brand-soft);
  box-shadow: 0 0 0 3px var(--c-brand-ring);
}
.bot-chip-av {
  position: relative; flex: 0 0 auto;
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #fff;
}
.bot-chip-dot {
  position: absolute; right: -1px; bottom: -1px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--c-green); border: 2px solid #fff;
}
.bot-chip-dot.off { background: #c3c9d6; }
.bot-chip-dot.connecting { background: var(--c-amber); animation: botPulse 1.2s ease-in-out infinite; }
.bot-chip-name {
  max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px; font-weight: 600; color: var(--c-text-2);
}
.bot-chip.on .bot-chip-name { color: var(--c-brand); }

/* ============================================================
   机器人卡片（.bot-*）
   ============================================================ */

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

.bot-card {
  display: flex; flex-direction: column;
  border-radius: var(--r-lg, 14px);
  background: #fff;
  border: 1px solid var(--c-border);
  overflow: hidden;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
}
.bot-card:hover {
  border-color: #c9cfe0;
  box-shadow: 0 8px 26px rgba(28,34,58,.08);
  transform: translateY(-2px);
}
.bot-card.offline { background: #fcfcfe; }
.bot-card.disabled { opacity: .62; }

/* 顶部：头像 + 名字 + 状态 */
.bot-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 16px 16px 13px;
}
.bot-avatar {
  flex: 0 0 auto; width: 46px; height: 46px; border-radius: 13px;
  display: grid; place-items: center;
  font-size: 20px; font-weight: 700; color: #fff;
  letter-spacing: -0.5px;
  position: relative;
}
/* 在线时头像右下角挂个小绿点 */
.bot-avatar .dot-on {
  position: absolute; right: -2px; bottom: -2px;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--c-green); border: 2.5px solid #fff;
}
.bot-avatar .dot-on.off { background: #c3c9d6; }
.bot-avatar .dot-on.connecting { background: var(--c-amber); animation: botPulse 1.2s ease-in-out infinite; }
@keyframes botPulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

.bot-id { flex: 1 1 auto; min-width: 0; }
.bot-id h3 {
  margin: 0; font-size: 15px; font-weight: 680; letter-spacing: -0.2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bot-id p {
  margin: 3px 0 0; font-size: 12px; color: var(--c-text-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bot-state {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 650;
}
.bot-state .d { width: 6px; height: 6px; border-radius: 50%; }
.bot-state.online { background: var(--c-green-soft); color: #0a7d5a; }
.bot-state.online .d { background: var(--c-green); }
.bot-state.offline { background: #f1f3f7; color: #6b7280; }
.bot-state.offline .d { background: #b6bdcc; }
.bot-state.connecting { background: var(--c-amber-soft); color: #92610b; }
.bot-state.connecting .d { background: var(--c-amber); }

/* 中部：凭证与标签 */
.bot-body { padding: 0 16px 14px; flex: 1 1 auto; }
.bot-kv {
  display: flex; align-items: baseline; gap: 8px;
  padding: 5px 0; font-size: 12px;
}
.bot-kv > span { flex: 0 0 52px; color: var(--c-text-3); }
.bot-kv > code {
  flex: 1 1 auto; min-width: 0;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px; color: var(--c-text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bot-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 11px; }
.bot-tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px;
  background: var(--c-surface-2); border: 1px solid var(--c-border);
  font-size: 11px; color: var(--c-text-2);
}
.bot-tag .i { width: 12px; height: 12px; }
.bot-tag.info { background: #eef4ff; border-color: #dbe6fb; color: #2354c4; }
.bot-tag.warn { background: var(--c-amber-soft); border-color: #f9e6c4; color: #92610b; }

/* 底部：操作条 */
.bot-foot {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 14px;
  border-top: 1px solid #f2f4f9;
  background: #fdfdfe;
}
.bot-foot .spacer { flex: 1 1 auto; }

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

/* ============================================================
   Markdown 编辑器（.mde-*）—— 带工具栏，替代裸 textarea
   ============================================================ */

.mde {
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: #fff;
  overflow: hidden;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.mde:focus-within { border-color: var(--c-brand); box-shadow: 0 0 0 3px var(--c-brand-soft); }

.mde-bar {
  display: flex; align-items: center; gap: 2px;
  padding: 5px 6px;
  background: var(--c-surface-2);
  border-bottom: 1px solid var(--c-border);
  flex-wrap: wrap;
}
.mde-tool {
  min-width: 27px; height: 26px; padding: 0 6px;
  border: 1px solid transparent; border-radius: 6px;
  background: none; color: var(--c-text-2); cursor: pointer;
  font-size: 12.5px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.mde-tool:hover { background: #fff; border-color: var(--c-border); color: var(--c-text); }
.mde-tool:active { transform: translateY(1px); }
.mde-mode.on { background: var(--c-brand-soft); border-color: #d5d9f5; color: var(--c-brand); }
.mde-sep { width: 1px; height: 16px; background: var(--c-border); margin: 0 4px; }

.mde-body { display: grid; grid-template-columns: 1fr 1fr; }
.mde-input {
  width: 100%; padding: 11px 12px;
  border: 0; outline: none; resize: vertical;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.7; color: var(--c-text);
  background: #fff;
}
.mde-preview {
  padding: 11px 12px;
  border-left: 1px solid var(--c-border);
  background: var(--c-surface-2);
  overflow: auto; max-height: 460px;
}
.mde-empty { color: var(--c-text-3); font-size: 12.5px; }

/* 三种视图模式 */
.mde[data-mode="write"] .mde-body { grid-template-columns: 1fr; }
.mde[data-mode="write"] .mde-preview { display: none; }
.mde[data-mode="preview"] .mde-body { grid-template-columns: 1fr; }
.mde[data-mode="preview"] .mde-input { display: none; }
.mde[data-mode="preview"] .mde-preview { border-left: 0; max-height: 520px; }

.mde-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 10px;
  border-top: 1px solid var(--c-border);
  background: var(--c-surface-2);
  font-size: 10.5px; color: var(--c-text-3);
}
.mde-count { font-variant-numeric: tabular-nums; }

@media (max-width: 720px) {
  .mde-body { grid-template-columns: 1fr; }
  .mde-preview { border-left: 0; border-top: 1px solid var(--c-border); max-height: 240px; }
  .mde-foot .mde-hint { display: none; }
}
