:root {
  --bg: #0f1115;
  --bg-soft: #151922;
  --panel: #181d27;
  --line: #242b38;
  --text: #e6e9ef;
  --muted: #8b95a7;
  --accent: #25d366;
  --accent-soft: rgba(37, 211, 102, .1);
  --blue: #4f8cff;
  --red: #ff6b6b;
  --amber: #f0b429;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }

.app { min-height: 100%; display: flex; flex-direction: column; }

/* 顶栏 */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 14px 22px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 168px; }
.logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent); color: #06240f;
  display: grid; place-items: center; font-weight: 800; font-size: 13px;
}
.brand .title { font-weight: 700; letter-spacing: .3px; }
.brand .sub { font-size: 11px; color: var(--muted); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav-btn {
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 12px; border-radius: 8px; cursor: pointer;
}
.nav-btn:hover { color: var(--text); background: rgba(255,255,255,.04); }
.nav-btn.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.conn { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.dot.online { background: var(--accent); box-shadow: 0 0 0 4px rgba(37,211,102,.12); }
.dot.offline { background: var(--red); }

/* 页面 */
.main { padding: 22px; max-width: 1400px; width: 100%; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; }
.page-head h1 { margin: 0 0 4px; font-size: 20px; }
.hint { margin: 0; color: var(--muted); font-size: 12px; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* 按钮与输入 */
.btn {
  border: 1px solid var(--accent); background: var(--accent); color: #05230f;
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 600;
}
.btn:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); font-weight: 500; }
.btn.ghost:hover { border-color: #3a4354; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.input {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; min-width: 120px; outline: none;
}
.input:focus { border-color: var(--blue); }
.input.compact { padding: 6px 9px; font-size: 12px; }
.link-btn {
  border: 0; background: transparent; color: var(--blue); cursor: pointer; padding: 2px 4px;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--red); }

/* 卡片 */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
}
.card .label { color: var(--muted); font-size: 12px; }
.card .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.card .foot { color: var(--muted); font-size: 11px; margin-top: 2px; }

/* 面板与分栏 */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.split.wide-left { grid-template-columns: 1.4fr 1fr; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.panel.narrow { max-width: 560px; }
.panel h2 { margin: 0 0 12px; font-size: 14px; color: var(--text); }
.mini-list { display: flex; flex-direction: column; gap: 8px; }
.mini-item {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-soft);
}
.mini-item .name { font-weight: 600; }
.mini-item .meta { color: var(--muted); font-size: 12px; }

/* 表格 */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.table-wrap.tall { max-height: 520px; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid thead th {
  position: sticky; top: 0; background: #1b212c; color: var(--muted);
  font-weight: 600; font-size: 12px; z-index: 1;
}
table.grid tbody tr:hover { background: rgba(255,255,255,.02); }
table.grid td.mono, .mono { font-family: var(--mono); font-size: 12px; }
table.grid .right, .right { text-align: right; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
table.logs td { font-size: 12px; }
table.logs td.msg { max-width: 520px; word-break: break-word; }
.cell-null { color: #5d6779; font-style: italic; }
.empty { padding: 26px; text-align: center; color: var(--muted); }

/* 徽标 */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; border: 1px solid transparent; }
.badge.running { color: var(--accent); background: var(--accent-soft); border-color: rgba(37,211,102,.25); }
.badge.error { color: var(--red); background: rgba(255,107,107,.1); border-color: rgba(255,107,107,.25); }
.badge.stopped { color: var(--muted); background: rgba(255,255,255,.04); border-color: var(--line); }
.badge.blue { color: var(--blue); background: rgba(79,140,255,.1); border-color: rgba(79,140,255,.25); }
.badge.warn { color: var(--amber); background: rgba(240,180,41,.1); border-color: rgba(240,180,41,.28); }

/* 日志 */
.log-meta { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.level-debug { color: #8b95a7; }
.level-info { color: var(--blue); }
.level-warn { color: var(--amber); }
.level-error { color: var(--red); }

/* 数据页 */
.messages { max-height: 520px; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.msg-row { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--bg-soft); }
.msg-row .msg-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.msg-row .msg-text { white-space: pre-wrap; word-break: break-word; }
.msg-row.out { border-left: 3px solid var(--accent); background: rgba(37, 211, 102, .06); }
.msg-row.in { border-left: 3px solid var(--blue); background: rgba(79, 140, 255, .07); }
.msg-row.unknown { border-left: 3px solid var(--line); }

/* 消息方向标签：弹窗与会话预览共用 */
.dir-tag {
  display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 10px;
  margin-right: 6px; border: 1px solid transparent; white-space: nowrap;
}
.dir-tag.out { color: var(--accent); background: var(--accent-soft); border-color: rgba(37, 211, 102, .25); }
.dir-tag.in { color: var(--blue); background: rgba(79, 140, 255, .1); border-color: rgba(79, 140, 255, .25); }
.dir-tag.unknown { color: var(--muted); background: rgba(255, 255, 255, .04); border-color: var(--line); }

/* 文档 */
.docs-group { margin-bottom: 18px; }
.docs-group h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.docs-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  border-bottom: 1px solid var(--line); font-size: 12px;
}
.docs-item:last-child { border-bottom: 0; }
.docs-example {
  margin: 0 0 10px 62px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--muted); font-family: var(--mono); font-size: 12px;
  white-space: pre-wrap; word-break: break-word;
}
.method { font-family: var(--mono); font-weight: 700; width: 52px; }
.method.get { color: var(--accent); }
.method.post { color: var(--blue); }
.method.patch, .method.put { color: var(--amber); }
.method.delete { color: var(--red); }
.raw {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; overflow: auto; font-family: var(--mono); font-size: 12px; max-height: 560px;
}

/* 表单 */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { color: var(--muted); font-size: 12px; }
.field-inline { display: flex; align-items: center; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.form-error { color: var(--red); font-size: 12px; min-height: 16px; }
.textarea { min-height: 96px; resize: vertical; font-family: inherit; }
.publish-fields { display: flex; flex-direction: column; gap: 14px; }
.publish-fields[hidden] { display: none; }
.publish-content { white-space: pre-wrap; word-break: break-word; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 14px; margin: 0; }
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 0; word-break: break-all; }

/* 任务详情：失败原因 / 期望实际 / 步骤时间线 */
tr.task-row.open td { background: rgba(255, 255, 255, .02); }
tr.task-detail-row td { background: var(--bg-soft); padding: 0; }
.task-detail {
  display: grid; grid-template-columns: minmax(260px, 1fr) minmax(320px, 1.4fr);
  gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.task-kv { grid-template-columns: 88px 1fr; align-content: start; }
.task-timeline {
  list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column;
  gap: 8px; max-height: 300px; overflow: auto;
}
.task-timeline .tl-item { border-left: 2px solid var(--line); padding-left: 10px; }
.task-timeline .tl-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.task-timeline .tl-time { color: var(--muted); }
.task-timeline .tl-step { color: var(--blue); font-weight: 600; }
.task-timeline .tl-status { font-size: 11px; color: var(--muted); }
.task-timeline .tl-attempt { color: var(--muted); font-size: 11px; }
.task-timeline .tl-extra { color: var(--muted); font-size: 12px; margin-top: 2px; word-break: break-word; }
.task-timeline .empty { padding: 12px; }
@media (max-width: 860px) {
  .task-detail { grid-template-columns: 1fr; }
}
.cfg-block {
  margin-top: 14px; padding: 12px; border-radius: 8px; background: var(--bg);
  border: 1px solid var(--line); font-family: var(--mono); font-size: 12px; white-space: pre-wrap;
}

/* 数据库页 */
.db-layout { display: grid; grid-template-columns: 240px 1fr; gap: 14px; }
.db-side { max-height: 620px; overflow: auto; }
.table-list { display: flex; flex-direction: column; gap: 4px; }
.table-item {
  display: flex; justify-content: space-between; gap: 8px; border: 1px solid transparent;
  background: transparent; color: var(--muted); padding: 7px 9px; border-radius: 7px;
  cursor: pointer; text-align: left; font-size: 12px;
}
.table-item:hover { background: rgba(255,255,255,.03); color: var(--text); }
.table-item.active { background: var(--accent-soft); color: var(--accent); border-color: rgba(37,211,102,.25); }
.table-item .count { color: var(--muted); font-family: var(--mono); }
.db-main-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.pager { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }

/* 弹窗与提示 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal[hidden] { display: none; }
.modal-card {
  width: min(620px, 100%); max-height: 86vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); }
.toast {
  position: fixed; right: 22px; bottom: 22px; z-index: 80;
  background: #1e2532; border: 1px solid var(--line); color: var(--text);
  padding: 10px 14px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.4); font-size: 13px;
}
.toast.error { border-color: rgba(255,107,107,.5); color: #ffb4b4; }

@media (max-width: 900px) {
  .split, .split.wide-left, .db-layout { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
}
