/* =================================================================
   Clipspay API 文档站样式
   品牌色：红 #E6442E / 绿 #6DB33F
   整体风格：低饱和暖色调、留白充足、无蓝紫渐变、无高饱和背景
   ================================================================= */

/* ---------- 基础变量 ---------- */
:root {
  --brand-red: #E6442E;
  --brand-red-light: #fdefec;      /* 导航 active 浅红底 */
  --brand-green: #6DB33F;
  --bg-page: #faf9f7;              /* 暖白页面背景 */
  --bg-card: #ffffff;              /* 内容卡片白底 */
  --text-main: #2b2b2b;            /* 正文深灰 */
  --text-muted: #8a8378;           /* 次要文字 */
  --border-color: #e8e3dc;         /* 暖灰边框 */
  --code-bg: #2b2622;              /* 代码块深暖灰底 */
  --code-text: #e8e2da;            /* 代码块浅色字 */
  --sidebar-width: 260px;
  --toc-width: 220px;
}

/* ---------- 全局重置 ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-page);
  color: var(--text-main);
  font-size: 15px;
  line-height: 1.75;
}

/* ---------- 三栏布局 ---------- */
.layout {
  max-width: 1440px;
  margin: 0 auto;
  padding-left: var(--sidebar-width);
  padding-right: var(--toc-width);
  min-height: 100vh;
}

/* =================================================================
   左侧：固定边栏
   ================================================================= */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: #fff;
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  z-index: 100;
  padding-bottom: 24px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
  height: 32px;
  width: auto;
  display: block;
}

.sidebar-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-main);
  letter-spacing: 0.5px;
}

.sidebar-search {
  padding: 14px 16px 6px;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-page);
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s;
}

.sidebar-search input:focus {
  border-color: var(--brand-green);
  background: #fff;
}

/* 仅顶层导航列表有上下留白；嵌套 .nav-children 自行控制缩进 */
#nav-list { list-style: none; padding: 8px 0; margin: 0; }

/* ---------- 树形导航（支持任意层级折叠） ---------- */
.nav-branch {
  list-style: none;
}

/* 顶层分组之间用分隔线 */
#nav-list > .nav-branch {
  border-top: 1px solid var(--border-color);
}

#nav-list > .nav-branch:first-child {
  border-top: none;
}

.nav-branch-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  letter-spacing: 0.3px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.nav-branch-header:hover {
  background: #f6f2ec;
}

/* 折叠箭头（CSS 三角形，展开时旋转朝下） */
.nav-branch-arrow {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid var(--text-muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.2s;
  flex-shrink: 0;
}

.nav-branch:not(.collapsed) > .nav-branch-header > .nav-branch-arrow {
  transform: rotate(90deg);
}

/* 子层容器：每级缩进 14px */
.nav-children {
  list-style: none;
  margin: 0;
  padding: 0 0 0 14px;
}

/* 折叠状态：直接隐藏（避免 max-height 过渡导致的背景色溢出） */
.nav-branch.collapsed > .nav-children {
  display: none;
}

/* 顶层分组标签前的圆点 */
#nav-list > .nav-branch > .nav-branch-header > .nav-branch-label::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand-red);
  margin-right: 8px;
  vertical-align: middle;
}

/* UPI订阅分组：绿色 */
#nav-list > .nav-branch.group-upi > .nav-branch-header > .nav-branch-label::before {
  background: var(--brand-green);
}

#nav-list > .nav-branch.group-upi > .nav-branch-header {
  color: var(--brand-green);
}

/* Payout分组：琥珀色 */
#nav-list > .nav-branch.group-payout > .nav-branch-header > .nav-branch-label::before {
  background: #e0a93e;
}

#nav-list > .nav-branch.group-payout > .nav-branch-header {
  color: #b8862e;
}

/* 叶子节点行：链接 + 删除按钮并排 */
.nav-leaf {
  list-style: none;
  display: flex;
  align-items: stretch;
}

.nav-leaf a {
  flex: 1;
  min-width: 0;
}

.sidebar-nav a {
  display: block;
  padding: 9px 20px;
  font-size: 14px;
  color: var(--text-main);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
}

.sidebar-nav a:hover {
  background: #f6f2ec;
  color: var(--brand-red);
}

/* 导航 active：品牌红左边条 + 浅红底 */
.sidebar-nav a.active {
  border-left-color: var(--brand-red);
  background: var(--brand-red-light);
  color: var(--brand-red);
  font-weight: 600;
}

/* =================================================================
   中间：内容区
   ================================================================= */
.content {
  padding: 32px 36px 80px;
}

.content-card {
  background: var(--bg-card);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(60, 50, 40, 0.06), 0 4px 16px rgba(60, 50, 40, 0.05);
  padding: 40px 48px;
}

/* ---------- 文档排版 ---------- */
.doc-page h3 {
  font-size: 19px;
  margin: 36px 0 14px;
  padding-left: 12px;
  border-left: 4px solid var(--brand-red);  /* h3 左边框强调 */
  line-height: 1.4;
  scroll-margin-top: 16px;
}

.doc-page h3:first-child { margin-top: 0; }

.doc-page p { margin: 12px 0; }

.doc-page ul, .doc-page ol {
  margin: 12px 0;
  padding-left: 24px;
}

.doc-page li { margin: 4px 0; }

.doc-page a { color: var(--brand-green); }

.doc-page code {
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: 13.5px;
  background: #f4f0ea;
  padding: 2px 6px;
  border-radius: 4px;
  color: #b5432f;
}

/* ---------- 接口 URL 展示条 ---------- */
.api-endpoint {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--code-bg);
  border-radius: 8px;
  padding: 10px 16px;
  margin: 14px 0;
  overflow-x: auto;
}

.api-endpoint code {
  background: transparent;
  padding: 0;
  color: var(--code-text);
  font-size: 13.5px;
  white-space: nowrap;
}

.method {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 3px 10px;
  border-radius: 4px;
  color: #fff;
}

.method-post { background: var(--brand-green); }  /* POST 绿色徽章 */
.method-get  { background: #9a958c; }             /* GET 灰色徽章 */

/* ---------- 表格 ---------- */
.doc-page table.doc-table { width: 100%; }

/* 容器横向滚动，窄屏表格可滑动 */
.doc-page .doc-table,
.doc-page table {
  border-collapse: collapse;
  margin: 16px 0;
  display: block;
  overflow-x: auto;
}

.doc-table th, .doc-table td,
.doc-page table th, .doc-page table td {
  border: 1px solid var(--border-color);
  padding: 8px 14px;
  font-size: 14px;
  text-align: left;
  white-space: nowrap;
}

.doc-table th, .doc-page table th {
  background: #f2eee7;        /* 表头浅灰 */
  font-weight: 600;
}

/* 斑马纹 */
.doc-table tbody tr:nth-child(even),
.doc-page table tbody tr:nth-child(even) {
  background: #faf7f2;
}

.doc-table tbody tr:hover,
.doc-page table tbody tr:hover {
  background: #f4efe7;
}

/* 必填红色小徽章 */
.badge-required {
  display: inline-block;
  background: var(--brand-red);
  color: #fff;
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 4px;
}

/* ---------- 代码块 ---------- */
pre.code-block {
  position: relative;           /* 容纳右上角复制按钮 */
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 8px;
  padding: 16px 18px;
  margin: 16px 0;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.6;
}

pre.code-block code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-family: Consolas, Monaco, "Courier New", monospace;
}

/* 复制按钮 */
.copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 12px;
  padding: 4px 12px;
  border: none;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.14);
  color: #d8d2c8;
  cursor: pointer;
  transition: background 0.2s;
  font-family: inherit;
}

.copy-btn:hover {
  background: var(--brand-green);
  color: #fff;
}

/* ---------- 提示框 ---------- */
.callout {
  border-radius: 6px;
  padding: 12px 16px;
  margin: 16px 0;
  font-size: 14px;
}

.callout-warning {
  background: #fdf6e3;                      /* 浅黄底 */
  border-left: 4px solid #e0a93e;           /* 左侧暖黄边框 */
  color: #7a6220;
}

/* =================================================================
   右侧：页内目录 TOC
   ================================================================= */
.toc {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--toc-width);
  height: 100vh;
  overflow-y: auto;
  padding: 32px 20px;
}

.toc-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.toc ul { list-style: none; }

.toc a {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  padding: 5px 0 5px 12px;
  border-left: 2px solid var(--border-color);
  transition: color 0.15s, border-color 0.15s;
}

.toc a:hover { color: var(--brand-green); }

/* scroll-spy 当前项高亮 */
.toc a.active {
  color: var(--brand-green);
  border-left-color: var(--brand-green);
  font-weight: 600;
}

/* =================================================================
   移动端：汉堡按钮 + 抽屉式侧边栏
   ================================================================= */
.menu-toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 200;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(60, 50, 40, 0.18);
  cursor: pointer;
  padding: 10px;
}

.menu-toggle span {
  display: block;
  height: 2px;
  background: var(--text-main);
  margin: 4px 0;
  border-radius: 2px;
}

.sidebar-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(43, 38, 34, 0.4);
  z-index: 90;
}

.sidebar-mask.show { display: block; }

/* =================================================================
   响应式
   ================================================================= */

/* <1100px：隐藏右侧 TOC，内容区占满 */
@media (max-width: 1100px) {
  .layout { padding-right: 0; }
  .toc { display: none; }
}

/* <860px：侧边栏变抽屉，默认隐藏 */
@media (max-width: 860px) {
  .layout { padding-left: 0; }

  .menu-toggle { display: block; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 2px 0 12px rgba(60, 50, 40, 0.15);
  }

  .sidebar.open { transform: translateX(0); }

  .content { padding: 68px 16px 60px; }

  .content-card { padding: 24px 20px; }
}

/* =================================================================
   管理模式（admin mode）
   - 开关按钮 / 新增页面按钮 / 导航删除小按钮
   - 编辑器：顶部工具条 + 左源码右预览双栏
   - 轻量提示条 toast
   显隐统一由 body.admin-mode 控制，延续暖色低饱和风格
   ================================================================= */

/* ---------- 边栏底部区域 ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
}

.sidebar-nav { flex: 1; }

.sidebar-footer {
  padding: 8px 16px 16px;
  border-top: 1px solid var(--border-color);
}

/* 管理模式开关：低调小按钮 */
#admin-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 8px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

#admin-toggle:hover {
  color: var(--brand-red);
  border-color: var(--brand-red);
  background: var(--brand-red-light);
}

/* 管理模式开启状态：绿色提示（编辑=可写，用品牌绿） */
#admin-toggle.active {
  color: var(--brand-green);
  border-color: var(--brand-green);
  background: #f2f8ec;
}

/* 「＋ 新增页面」按钮：仅管理模式下显示 */
.admin-only { display: none; }

body.admin-mode .admin-only { display: block; }

#new-page-btn {
  width: 100%;
  padding: 8px 12px;
  font-size: 13.5px;
  color: var(--brand-green);
  background: #f2f8ec;
  border: 1px dashed var(--brand-green);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

#new-page-btn:hover { background: #e8f2dd; }

/* ---------- 导航项删除小按钮 ✕ ---------- */
.sidebar-nav li { position: relative; }

.nav-del-btn {
  display: none;
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  line-height: 18px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.nav-del-btn:hover {
  color: #fff;
  background: var(--brand-red);
}

body.admin-mode .nav-del-btn { display: block; }

/* 管理模式下给删除按钮留出位置，避免与标题重叠 */
body.admin-mode .sidebar-nav a { padding-right: 38px; }

/* ---------- 「✏️ 编辑本页」按钮 ---------- */
#edit-page-btn {
  margin-bottom: 20px;
  padding: 7px 16px;
  font-size: 13.5px;
  color: var(--brand-red);
  background: #fff;
  border: 1px solid var(--brand-red);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

#edit-page-btn:hover {
  background: var(--brand-red);
  color: #fff;
}

/* ---------- 编辑器：工具条 ---------- */
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border-color);
}

.editor-toolbar button {
  padding: 7px 18px;
  font-size: 13.5px;
  color: var(--text-main);
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.editor-toolbar button:hover {
  border-color: var(--brand-green);
  color: var(--brand-green);
  background: #f6faf2;
}

/* 「保存」主按钮：品牌绿实心 */
.editor-toolbar .editor-btn-primary {
  color: #fff;
  background: var(--brand-green);
  border-color: var(--brand-green);
}

.editor-toolbar .editor-btn-primary:hover { background: #5da233; }

.editor-toolbar button:disabled {
  opacity: 0.6;
  cursor: default;
}

.editor-status {
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- 编辑器：双栏（左源码 / 右预览） ---------- */
.editor-body {
  display: flex;
  gap: 16px;
  height: 68vh;
  min-height: 420px;
}

#editor-source {
  flex: 1;
  min-width: 0;
  padding: 14px 16px;
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text-main);
  background: var(--bg-page);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}

#editor-source:focus { border-color: var(--brand-green); }

.editor-preview {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 20px 24px;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

/* 「仅预览」模式：隐藏源码栏，预览占满 */
.page-editor.preview-only #editor-source { display: none; }

/* 窄屏：双栏改上下排列 */
@media (max-width: 860px) {
  .editor-body {
    flex-direction: column;
    height: auto;
  }

  #editor-source { height: 40vh; }

  .editor-preview { max-height: 50vh; }
}

/* ---------- 轻量提示条 toast ---------- */
.admin-toast {
  position: fixed;
  left: 50%;
  bottom: 36px;
  transform: translateX(-50%) translateY(12px);
  padding: 9px 22px;
  font-size: 13.5px;
  color: #fff;
  background: var(--code-bg);
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(60, 50, 40, 0.22);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 300;
  pointer-events: none;
}

.admin-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
