/* ==========================================================================
   等保标准查询系统 — 标准文档浏览器模块 (doc.css)
   --------------------------------------------------------------------------
   颜色一律取自 site.css 的 CSS 变量, 不硬编码任何色值。
   布局移植自 templates/doc_tree.html 的 flex 满高 + 左右各自滚动方案。
   ========================================================================== */

/* ============================== 模块外壳 ============================== */

.doc-module {
  /* 站点外壳 (顶栏 + 标签栏 + 页面留白) 占掉的高度, 可被页面覆盖 */
  --doc-shell-offset: 180px;

  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--doc-shell-offset));
  min-height: 420px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* ============================== 头部 ============================== */

.doc-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  flex-shrink: 0;
}
.doc-head-main { min-width: 0; }
.doc-head-title {
  font-size: 16px;
  font-weight: 650;
  color: var(--ink);
  line-height: 1.4;
}
.doc-head-sub {
  font-size: 12.5px;
  color: var(--sub);
  margin-top: 2px;
}
.doc-head-stats {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
  padding-top: 2px;
}

/* 移动端"目录"按钮条 (桌面隐藏) */
.doc-mobile-bar { display: none; }

/* ============================== 主体布局 ============================== */

.doc-layout {
  position: relative;
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ============================== 左侧目录树 ============================== */

.doc-toc {
  width: 340px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--card-2);
  border-right: 1px solid var(--line);
}
.doc-toc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--line-soft);
  flex-shrink: 0;
}
.doc-toc-title {
  font-size: 13px;
  font-weight: 650;
  color: var(--ink);
}
.doc-toc-stats {
  font-size: 11px;
  color: var(--muted);
}
.doc-toc-search {
  padding: 8px 10px;
  background: var(--card);
  border-bottom: 1px solid var(--line-soft);
  flex-shrink: 0;
}
.doc-toc-search-input {
  width: 100%;
  font-size: 13px;
}
.doc-toc-filter-info {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--muted);
}
.doc-toc-list {
  list-style: none;
  margin: 0;
  padding: 8px 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.doc-toc-item {
  display: flex;
  align-items: center;
  padding: 4px 12px 4px 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
  border-left: 3px solid transparent;
  transition: background 0.12s;
  user-select: none;
  line-height: 1.4;
  outline: none;
}
.doc-toc-item:hover { background: var(--blue-bg); }
.doc-toc-item:focus-visible {
  background: var(--blue-bg);
  box-shadow: inset 0 0 0 1px var(--blue-line);
}
.doc-toc-item.is-active {
  background: var(--blue-bg);
  color: var(--blue-d);
  font-weight: 600;
  border-left-color: var(--blue);
}
.doc-toc-toggle {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  margin-right: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.12s;
}
.doc-toc-toggle.is-empty { visibility: hidden; }
.doc-toc-toggle.is-open { transform: rotate(90deg); }
.doc-toc-num {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  margin-right: 10px;
  min-width: 30px;
  flex-shrink: 0;
  text-align: left;
}
.doc-toc-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 0 1 auto;
  min-width: 0;
}

/* 层级缩进 (按 level) */
.doc-toc-h1 { padding-left: 8px; font-weight: 600; }
.doc-toc-h2 { padding-left: 26px; font-size: 12.5px; }
.doc-toc-h3 { padding-left: 46px; font-size: 12px; color: var(--sub); }
.doc-toc-h4 { padding-left: 66px; font-size: 12px; color: var(--sub); }
.doc-toc-h5 { padding-left: 86px; font-size: 11.5px; color: var(--muted); }

/* 子节默认隐藏 */
.doc-toc-children {
  display: none;
  margin: 0;
  padding-left: 0;
  list-style: none;
}
.doc-toc-children.is-open { display: block; }

/* ============================== 右侧正文 ============================== */

.doc-content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 26px 48px 64px;
  background: var(--card);
}
.doc-content-inner {
  max-width: 860px;
  margin: 0 auto;
}

.doc-chapter-title {
  font-size: 25px;
  font-weight: 700;
  color: var(--blue-d);
  padding-bottom: 12px;
  border-bottom: 2px solid var(--blue-d);
  margin: 0 0 20px;
}
.doc-sec-title { color: var(--ink); }
.doc-sec-title-h2 {
  font-size: 20px;
  font-weight: 650;
  margin: 28px 0 14px;
  padding-left: 12px;
  border-left: 4px solid var(--blue);
}
.doc-sec-title-h3 {
  font-size: 16px;
  font-weight: 650;
  color: var(--sub);
  margin: 20px 0 10px;
  padding-left: 10px;
  border-left: 3px solid var(--muted);
}
.doc-sec-title-h4 {
  font-size: 14px;
  font-weight: 650;
  color: var(--muted);
  margin: 16px 0 8px;
  padding-left: 8px;
  border-left: 2px solid var(--line);
}
.doc-sec-title-h5 {
  font-size: 13px;
  font-weight: 600;
  color: var(--sub);
  margin: 12px 0 6px;
}

.doc-content p {
  font-size: 14px;
  line-height: 1.85;
  color: var(--ink);
  margin: 0 0 10px;
  text-indent: 2em;
}
.doc-content p.no-indent { text-indent: 0; }

/* ---- 表格 ---- */
.doc-content .tbl-wrap { margin: 14px 0 24px; }
.doc-content table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  background: var(--card);
  margin: 0;
}
.doc-content table.tbl th {
  background: var(--blue-d);
  color: var(--card);
  font-weight: 650;
  padding: 8px 10px;
  text-align: left;
  border: 1px solid var(--blue-d);
  white-space: nowrap;
}
.doc-content table.tbl td {
  padding: 8px 10px;
  border: 1px solid var(--line);
  vertical-align: top;
  line-height: 1.65;
}
.doc-content table.tbl tbody tr:nth-child(even) td { background: var(--card-2); }
.doc-content table.tbl tbody tr:hover td { background: var(--blue-bg); }
.doc-content table.notrigger { table-layout: fixed; }
.doc-content table.notrigger td,
.doc-content table.notrigger th { word-break: break-word; }

/* ---- 列表项 (a) b) c) 1) 2) 3)) ---- */
.doc-content .doc-list {
  display: flex;
  align-items: flex-start;
  margin: 4px 0 4px 1em;
  font-size: 14px;
  line-height: 1.8;
  color: var(--ink);
}
.doc-content .doc-list-marker {
  color: var(--sub);
  font-weight: 600;
  margin-right: 8px;
  flex-shrink: 0;
  min-width: 24px;
  font-family: var(--mono);
}
.doc-content .doc-list-alpha .doc-list-marker { color: var(--blue); }
.doc-content .doc-list-num .doc-list-marker { color: var(--green); }
.doc-content .doc-list-text { flex: 1; }

/* ---- 案例折叠列表 ---- */
.doc-content .case-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: 16px 0 10px;
  font-size: 12.5px;
  color: var(--sub);
}
.doc-content .case-actions { display: flex; gap: 8px; }
.doc-content .case-actions button {
  font-family: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--blue-d);
  cursor: pointer;
}
.doc-content .case-actions button:hover {
  background: var(--blue-bg);
  border-color: var(--blue-line);
}
.doc-content .case-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}
.doc-content .case-item > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
}
.doc-content .case-item > summary::-webkit-details-marker { display: none; }
.doc-content .case-seq {
  flex: 0 0 auto;
  min-width: 24px;
  height: 24px;
  padding: 0 4px;
  border-radius: var(--radius-sm);
  background: var(--blue-bg);
  color: var(--blue-d);
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.doc-content .case-title {
  flex: 1;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--ink);
}
.doc-content .case-flag {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--amber);
  background: var(--amber-bg);
  border: 1px solid var(--amber-line);
  border-radius: 4px;
  padding: 2px 6px;
  white-space: nowrap;
}
.doc-content .case-item[open] > summary {
  border-bottom: 1px solid var(--line);
  background: var(--card-2);
}
.doc-content .case-body { padding: 12px 14px 14px; }
.doc-content .case-label {
  font-size: 11px;
  color: var(--sub);
  margin-bottom: 4px;
}
.doc-content .case-text {
  font-size: 13px;
  line-height: 1.85;
  color: var(--ink);
}
.doc-content .case-meta {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  font-size: 12px;
  color: var(--sub);
  display: grid;
  gap: 4px;
  line-height: 1.7;
}
.doc-content .case-meta b { color: var(--ink); font-weight: 600; }

/* ---- 文档图片 ---- */
.doc-content .doc-image {
  margin: 14px 0;
  text-align: center;
}
.doc-content .doc-image img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
}
.doc-content .doc-image-caption {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  font-style: italic;
}

/* ---- docx 矢量图 (vml) ---- */
.doc-content .doc-vml-diagram {
  padding: 20px;
  background: var(--card-2);
  border: 2px dashed var(--line);
  border-radius: 4px;
  margin: 14px 0;
}
.doc-content .doc-vml-placeholder {
  font-size: 18px;
  color: var(--sub);
  font-weight: 600;
  margin-bottom: 8px;
}
.doc-content .doc-vml-header {
  font-size: 13px;
  color: var(--sub);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.doc-content .doc-vml-canvas {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  overflow: auto;
}
/* 模式 A (有底图): 文字层透明, 不挡底图箭头 */
.doc-content .doc-vml-canvas.has-bg {
  border: none;
  background: transparent;
}
.doc-content .doc-vml-node {
  padding: 2px 4px;
  background: var(--card);
  border: 1px solid var(--sub);
  border-radius: 2px;
  font-size: 9px;
  line-height: 1.2;
  color: var(--ink);
  text-align: center;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  word-break: break-all;
  white-space: normal;
}
/* 模式 A 文字节点: 透明背景, 大字号, 不加框, 让底图箭头穿透 */
.doc-content .doc-vml-canvas.has-bg .doc-vml-node {
  background: transparent;
  border: none;
  box-shadow: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  padding: 0;
  line-height: 1.25;
}
/* 4.1 风险要素关系 (fxpg, 隐藏错图) 文字节点: 显示方框 */
.doc-content .doc-vml-canvas.has-bg.no-bg-img .doc-vml-node {
  background: var(--card);
  border: 1.5px solid var(--red);
  border-radius: 3px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  padding: 4px 8px;
  line-height: 1.2;
}
.doc-content .doc-vml-canvas.has-bg .doc-vml-main {
  background: transparent;
  color: var(--blue-d);
}
.doc-content .doc-vml-main {
  font-weight: 600;
  background: var(--blue-bg);
  border-color: var(--blue-d);
}
/* SVG 箭头 / 边框配色 (变量化, 不用行内色值) */
.doc-content .doc-vml-svg-a .arrow-red { stroke: var(--red); }
.doc-content .doc-vml-svg-a marker polygon.arrow-red { fill: var(--red); }
.doc-content .doc-vml-svg-b .arrow-gray { stroke: var(--sub); }
.doc-content .doc-vml-svg-b marker polygon.arrow-gray { fill: var(--sub); }
.doc-content .doc-vml-svg-b rect.border-gray { stroke: var(--sub); }

/* ---- 文字流程图 (fxpg 4.1/4.3/5.2.1 等) ---- */
.doc-content .flow-diagram {
  margin: 20px 0;
  padding: 18px 22px;
  background: var(--card-2);
  border: 1.5px dashed var(--blue);
  border-radius: var(--radius-sm);
  text-align: center;
}
.doc-content .fd-title {
  font-size: 15px;
  font-weight: 650;
  color: var(--blue-d);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--blue-line);
  text-align: left;
}
.doc-content .fd-body {
  font-size: 14px;
  line-height: 1.8;
  color: var(--ink);
}
.doc-content .fd-top-row { margin: 6px 0; text-align: center; }
.doc-content .fd-main-chain { margin: 6px 0; text-align: center; }
.doc-content .fd-connector {
  color: var(--amber);
  font-size: 18px;
  font-weight: 700;
  margin: 8px 0;
  letter-spacing: 12px;
  text-align: center;
}
.doc-content .fd-nodes {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.doc-content .fd-node-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.doc-content .fd-node {
  display: inline-block;
  padding: 6px 14px;
  background: var(--card);
  border: 2px solid var(--blue);
  border-radius: 4px;
  font-weight: 600;
  color: var(--blue);
  white-space: nowrap;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
}
.doc-content .fd-arrow {
  color: var(--blue);
  font-weight: 600;
  padding: 0 4px;
}
.doc-content .fd-arrow-back { color: var(--amber); }
.doc-content .fd-hint {
  color: var(--sub);
  font-size: 13px;
}
.doc-content .fd-arrow-row {
  color: var(--blue);
  font-size: 16px;
  font-weight: 700;
  padding: 2px 0;
}
.doc-content .fd-branches {
  margin-top: 10px;
  text-align: left;
}
.doc-content .fd-branch {
  color: var(--sub);
  font-size: 13px;
  padding: 4px 8px;
  background: var(--blue-bg);
  border-radius: 4px;
  margin: 3px 0;
}
.doc-content .fd-branch-single {
  margin-top: 10px;
  color: var(--sub);
  font-size: 13px;
  text-align: left;
  padding: 4px 8px;
  background: var(--blue-bg);
  border-radius: 4px;
}

/* ---- 上一章 / 下一章 ---- */
.doc-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 36px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.doc-nav-btn { min-width: 108px; }

/* ============================== 移动端 (≤900px) ============================== */

@media (max-width: 900px) {
  .doc-module {
    --doc-shell-offset: 190px;
    min-height: 360px;
  }
  .doc-head {
    padding: 10px 14px;
    gap: 10px;
  }
  .doc-head-title { font-size: 15px; }
  .doc-head-stats { font-size: 11px; }

  .doc-mobile-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
  }
  .doc-mobile-bar .doc-toc-btn { flex-shrink: 0; }
  .doc-mobile-title {
    font-size: 12.5px;
    color: var(--sub);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* 目录树收成抽屉 */
  .doc-toc {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(78vw, 300px);
    z-index: 60;
    /* 收起时用 visibility 彻底移出视线 (translateX(-100%) 会留一条缝) */
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
    box-shadow: var(--shadow-lg);
  }
  .doc-layout.is-toc-open .doc-toc {
    transform: none;
    visibility: visible;
    transition: transform 0.2s ease;
  }
  .doc-toc-mask {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    background: var(--ink);
    opacity: 0.35;
  }
  .doc-toc-mask[hidden] { display: none; }

  /* 正文占满宽度 */
  .doc-content { padding: 18px 14px 44px; }
  .doc-chapter-title { font-size: 20px; }
  .doc-sec-title-h2 { font-size: 17px; }
  .doc-sec-title-h3 { font-size: 15px; }
  .doc-content p { font-size: 13.5px; }
  .doc-content .doc-list { font-size: 13.5px; }
  .doc-content table.tbl { font-size: 12px; }
  .doc-content .doc-vml-diagram { padding: 10px; }
  .doc-content .flow-diagram { padding: 14px 12px; }
  .doc-nav-btn { min-width: 0; padding: 8px 12px; }
}

/* ============================== 打印 ============================== */

@media print {
  .doc-module {
    height: auto;
    min-height: 0;
    border: none;
    box-shadow: none;
  }
  .doc-content { overflow: visible; padding: 0; }
}
