:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --line: #e3e6ea;
  --text: #23272e;
  --muted: #79808a;
  --primary: #2f6feb;
  --danger: #d64545;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  height: 56px;
  background: #1f2430;
  color: #fff;
}

.brand { font-weight: 600; }
.brand small { color: #9aa3b2; font-weight: 400; margin-left: 8px; }

.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  color: #c7cddb;
  padding: 6px 12px;
  border-radius: 6px;
}
.topbar nav a:hover { background: #2b3242; text-decoration: none; }
.topbar nav a.active { background: var(--primary); color: #fff; }
.topbar .user { display: flex; gap: 12px; align-items: center; }
.topbar .user a { color: #c7cddb; }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
h2 { margin: 0 0 16px; font-size: 20px; }
h3 { margin: 24px 0 12px; font-size: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.page-head h2 { margin: 0; }
.head-ops { display: flex; gap: 10px; align-items: center; }

/* 表格 */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
th, td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
th { background: #fafbfc; font-weight: 600; color: #4a5260; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.empty, .empty { text-align: center; color: var(--muted); padding: 24px; }
code { background: #f0f2f5; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
code.ellipsis { display: inline-block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.muted { color: var(--muted); }

/* 按钮 */
.btn {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  line-height: 1.4;
}
.btn:hover { background: #f2f4f7; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #245bbd; }

button.link {
  border: none;
  background: none;
  padding: 0;
  color: var(--primary);
  cursor: pointer;
  font-size: 14px;
}
button.link.danger, .danger { color: var(--danger); }
button.link[disabled] { color: #b8bec7; cursor: not-allowed; }

td.ops { white-space: nowrap; }
td.ops > * { vertical-align: middle; }
td.ops form { display: inline; margin-left: 10px; }

/* 表单 */
.form label { display: block; margin: 14px 0 5px; font-weight: 500; }
.form label:first-child { margin-top: 0; }
.form input, .form select, .form textarea {
  width: 100%;
  max-width: 460px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.form .hint { color: var(--muted); margin: 4px 0 0; font-size: 12.5px; }
.form input[readonly], .form input[disabled] { background: #f4f6f9; color: #6b7280; }
.form .req { color: var(--danger); }
.form .actions { margin-top: 22px; display: flex; gap: 10px; }

.filter {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}
.filter label { color: var(--muted); }
.filter input, .filter select {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
}
.filter input[name="keyword"] { min-width: 200px; }

/* 登录 */
.login-wrap { display: flex; justify-content: center; padding-top: 8vh; }
.login { width: 340px; }
.login h1 { font-size: 18px; margin: 0 0 16px; }
.login label { display: block; margin: 12px 0 5px; }
.login input { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; }
.login .btn { width: 100%; margin-top: 20px; }

/* 概览卡片 */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.stat { text-align: center; }
.stat .num { display: block; font-size: 26px; font-weight: 600; }
.stat .label { color: var(--muted); font-size: 13px; }

/* 状态标签 */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  background: #eef1f5;
  color: #4a5260;
  white-space: nowrap;
}
.tag.s0, .tag.r0 { background: #fff3d6; color: #9a6b00; }
.tag.s1, .tag.r1 { background: #e2f5e6; color: #1e7a37; }
.tag.s2, .tag.r2 { background: #fde5e5; color: #b52d2d; }
.tag.s3 { background: #ececf0; color: #6b7280; }
.tag.t1 { background: #e7f0ff; color: #2f6feb; }
.tag.t2 { background: #f3e8ff; color: #7a3fbf; }

/* 详情 */
.detail { display: grid; grid-template-columns: 110px 1fr; gap: 8px 16px; margin: 0; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; word-break: break-all; }
.detail dd.pre { white-space: pre-wrap; }

.flash {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 14px;
  border: 1px solid;
}
.flash.ok { background: #e2f5e6; border-color: #b6e2c1; color: #1e7a37; }
.flash.error { background: #fde5e5; border-color: #f3c2c2; color: #b52d2d; }

.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 16px; }

/* 提示条 */
.notice {
  padding: 11px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  border: 1px solid #f0d9a8;
  border-left: 4px solid #e2a93b;
  background: #fffaf0;
  color: #8a6100;
}

/* ============ 审批人层级：群 → 平台账号 → 业务 → 审批人 ============ */
.tree-group {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  margin-bottom: 16px;
  overflow: hidden;
}

.tree-group > summary,
.tree-acct > summary,
.tree-biz > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-height: 46px;
  cursor: pointer;
  list-style: none;
}
.tree-group > summary::-webkit-details-marker,
.tree-acct > summary::-webkit-details-marker,
.tree-biz > summary::-webkit-details-marker { display: none; }

/* 折叠箭头：固定宽度，避免不同字号下文字列左右抖动 */
.tree-group > summary::before,
.tree-acct > summary::before,
.tree-biz > summary::before {
  content: '▸';
  flex: 0 0 auto;
  width: 14px;
  text-align: center;
  color: #97a1b0;
  font-size: 12px;
  transition: transform .15s;
}
.tree-group[open] > summary::before,
.tree-acct[open] > summary::before,
.tree-biz[open] > summary::before { transform: rotate(90deg); }

.tree-group > summary:hover,
.tree-acct > summary:hover,
.tree-biz > summary:hover { background: #f3f6fb; }

/* 一级：群 */
.tree-group > summary {
  padding: 10px 16px;
  font-size: 15.5px;
  background: linear-gradient(180deg, #f8fafd, #eef3fb);
  border-bottom: 1px solid var(--line);
}
.tree-group > summary:hover { background: linear-gradient(180deg, #f1f5fc, #e6eefa); }

/* 二级：平台账号（缩进导轨） */
.tree-acct {
  margin-left: 22px;
  border-left: 2px solid var(--line);
  border-top: 1px solid var(--line);
}
.tree-group > .tree-acct:first-of-type { border-top: none; }
.tree-acct > summary { padding: 10px 16px 10px 14px; font-size: 14px; }

/* 三级：业务（导轨继续，整条覆盖该节点与其下审批人行） */
.tree-acct > .tree-biz {
  margin-left: 22px;
  border-left: 2px solid var(--line);
}
.tree-biz + .tree-biz { border-top: 1px solid #f1f4f9; }
.tree-biz > summary { padding: 8px 16px 8px 14px; font-size: 13px; }

/* 兜底块：该群下没有审批人的业务，不属于任何平台账号 */
.tree-void {
  margin-left: 22px;
  border-top: 1px solid var(--line);
  border-left: 2px solid #f0d9a8;
  background: #fffdf7;
}
.void-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 16px;
}
.void-list { list-style: none; margin: 0; padding: 0 0 4px; }
.void-list > li {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 16px 8px 36px;
}
.void-list > li + li { border-top: 1px dashed #f0e4c8; }

/* 节点右侧的操作按钮 */
.tree-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.tree-actions form { display: inline; margin: 0; }

/* 业务群绑定：群 → 业务 二级 */
.biz-list {
  list-style: none;
  margin: 0 0 0 22px;
  padding: 0;
  border-left: 2px solid var(--line);
}

/* 四级：审批人列表（无外框无独立导轨，文字与业务节点标题对齐） */
.member-list { list-style: none; margin: 0; padding: 0; }
.member-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 16px 9px 38px;
}
.member-row + .member-row { border-top: 1px dashed #eef1f5; }
.member-tg {
  flex: 0 0 auto;
  min-width: 150px;
  padding: 2px 9px;
  border-radius: 6px;
  background: #eef3fe;
  color: #1f5fd0;
  font: 600 13px/1.6 ui-monospace, Consolas, "Microsoft YaHei", monospace;
}
.member-time { color: var(--muted); font-size: 12.5px; }
.member-ops { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.member-ops form { display: inline; }

.tree-name { font-weight: 600; }
.tree-meta { color: var(--muted); font-size: 12.5px; }
.pill {
  padding: 2px 10px;
  border-radius: 999px;
  background: #e7f0ff;
  color: #2f6feb;
  font-size: 12px;
}
.user-chip {
  padding: 2px 12px;
  border-radius: 999px;
  border: 1px solid #e0e5ec;
  background: #eef1f5;
  color: #3a4353;
  font: 600 13px/1.5 ui-monospace, Consolas, "Microsoft YaHei", monospace;
}

.btn.tiny { padding: 3px 10px; font-size: 12.5px; }

/* 新增审批人弹窗 */
.add-dialog {
  width: 480px;
  max-width: calc(100vw - 40px);
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 18px 48px rgba(31, 36, 48, .18);
}
.add-dialog::backdrop { background: rgba(31, 36, 48, .45); }
.add-dialog h3 { margin: 0; font-size: 16px; }

.biz-picker {
  max-height: 190px;
  overflow: auto;
  margin-top: 5px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.biz-picker label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 5px 0;
  font-weight: 400;
  cursor: pointer;
}
.biz-picker input { width: auto; }

/* ============ 通知模板 ============ */
main.wide { max-width: none; padding: 20px 24px; }

.template-card { margin-bottom: 16px; }
.template-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.template-head h3 { margin: 0; font-size: 15.5px; }
.template-head h3 code { margin-left: 4px; font-weight: 400; }

.template-help {
  margin: 12px 0 16px;
  padding: 10px 14px;
  border: 1px solid #e8edf5;
  border-radius: 8px;
  background: #f7f9fc;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 2;
}
.template-help > div + div { margin-top: 2px; }
.template-help code { margin-right: 3px; }
.help-label {
  display: inline-block;
  min-width: 64px;
  margin-right: 6px;
  color: #4a5260;
  font-weight: 600;
}

.template-editor { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.template-pane { display: flex; flex-direction: column; min-width: 0; }
.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 30px;
  margin-bottom: 6px;
}
.pane-head label { color: #4a5260; font-size: 13px; font-weight: 600; }
.pane-head .muted { font-size: 12px; }

.template-toolbar { display: flex; gap: 4px; }
.tool {
  min-width: 30px;
  height: 26px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #4a5260;
  font-size: 12.5px;
  line-height: 1;
  cursor: pointer;
}
.tool:hover { background: #f2f5fa; border-color: #ccd6e6; color: var(--primary); }
.tool:active { background: #e6eefa; }
.tool-b { font-weight: 700; }
.tool-i { font-style: italic; }
.tool-u { text-decoration: underline; }
.tool-s { text-decoration: line-through; }
.tool-code { font-family: ui-monospace, Consolas, monospace; }
.tool-quote { font-size: 14px; }

.template-editor textarea,
.template-preview {
  box-sizing: border-box;
  height: 360px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: 13.5px/1.75 ui-monospace, Consolas, "Microsoft YaHei", monospace;
  color: var(--text);
}
.template-editor textarea { width: 100%; resize: vertical; background: #fff; }
.template-editor textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 111, 235, .12);
}
.template-preview {
  overflow: auto;
  background: #f7f8fa;
  white-space: pre-wrap;
  word-break: break-word;
}

/* 预览区按 Telegram 样式呈现模板里的标签 */
.tg-preview b, .tg-preview strong { font-weight: 700; }
.tg-preview i, .tg-preview em { font-style: italic; }
.tg-preview u, .tg-preview ins { text-decoration: underline; }
.tg-preview s, .tg-preview strike, .tg-preview del { text-decoration: line-through; }
.tg-preview code {
  padding: 1px 6px;
  border-radius: 4px;
  background: #e9edf3;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12.5px;
}
.tg-preview pre {
  margin: 6px 0;
  padding: 10px 12px;
  border-radius: 6px;
  background: #e9edf3;
  overflow-x: auto;
  white-space: pre-wrap;
}
.tg-preview blockquote {
  margin: 6px 0;
  padding: 2px 0 2px 12px;
  border-left: 3px solid #c6cedb;
  color: #4a5260;
}
.tg-preview .tg-spoiler {
  border-radius: 4px;
  background: #d5dae3;
  color: transparent;
  text-shadow: 0 0 9px rgba(0, 0, 0, .5);
}
.tg-preview .tg-link { color: var(--primary); text-decoration: underline; }
.tg-preview .tg-emoji { font-style: normal; }

.actions { margin-top: 20px; display: flex; gap: 10px; }

/* 表单控件继承页面字体，否则按钮会回落成 Arial */
button, input, select, textarea { font-family: inherit; }

@media (max-width: 1100px) {
  .template-editor { grid-template-columns: 1fr; }
  .template-editor textarea, .template-preview { height: 300px; }
}

/* ============ 接口文档 ============ */
.doc-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.doc-toc {
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.doc-toc-title { margin-bottom: 10px; font-size: 13px; font-weight: 600; color: #4a5260; }
.doc-toc ul { margin: 0; padding: 0; list-style: none; }
.doc-toc li { margin: 2px 0; }
.doc-toc a {
  display: block;
  padding: 5px 9px;
  border-radius: 6px;
  color: #4a5260;
  font-size: 12.5px;
  line-height: 1.5;
}
.doc-toc a:hover { background: #f2f5fa; color: var(--primary); text-decoration: none; }
.doc-toc .toc-level-1 > a { margin-top: 6px; color: var(--text); font-weight: 600; font-size: 13px; }
.doc-toc .toc-level-2 > a { padding-left: 16px; }
.doc-toc-foot {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: #4a5260;
  line-height: 1.9;
  word-break: break-all;
}
.doc-toc-foot code { font-size: 11.5px; }

.doc-body {
  padding: 24px 28px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-width: 0;
}
.markdown-body h1 {
  margin: 0 0 18px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  font-size: 20px;
}
.markdown-body h1 + h1,
.markdown-body h1:not(:first-child) { margin-top: 44px; }
.markdown-body h2 { margin: 28px 0 12px; font-size: 16px; }
.markdown-body h3 { margin: 20px 0 10px; font-size: 14.5px; }
.markdown-body p { margin: 10px 0; }
.markdown-body strong { font-weight: 600; }
.markdown-body ul, .markdown-body ol { margin: 10px 0; padding-left: 22px; }
.markdown-body li { margin: 4px 0; }
.markdown-body hr { margin: 24px 0; border: none; border-top: 1px solid var(--line); }
.markdown-body a { color: var(--primary); }
.markdown-body table {
  width: 100%;
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.markdown-body th, .markdown-body td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  vertical-align: top;
}
.markdown-body th { background: #f7f9fc; color: #4a5260; font-weight: 600; white-space: nowrap; }
.markdown-body tr:last-child td { border-bottom: none; }
.markdown-body code {
  padding: 1px 5px;
  border-radius: 4px;
  background: #f0f2f5;
  font: 12.5px ui-monospace, Consolas, monospace;
  word-break: break-word;
}
.markdown-body pre {
  margin: 12px 0;
  padding: 13px 15px;
  background: #1f2430;
  border-radius: 8px;
  overflow-x: auto;
}
.markdown-body pre code {
  padding: 0;
  background: none;
  color: #e6e9f0;
  font: 12.5px/1.7 ui-monospace, Consolas, monospace;
}
.markdown-body blockquote {
  margin: 12px 0;
  padding: 9px 15px;
  border-left: 3px solid #c6cedb;
  border-radius: 0 6px 6px 0;
  background: #f7f9fc;
  color: #4a5260;
}
.markdown-body blockquote p { margin: 0; }

@media (max-width: 1100px) {
  .doc-layout { grid-template-columns: minmax(0, 1fr); }
  .doc-toc { position: static; max-height: none; }
}
