/*
 * 表格统一样式 —— 系统里所有表格的唯一样式源。
 *
 * 用法：把表格 HTML 包在 <div class="fig-table"> 中即可，不再按来源区分文件 / 类名。
 * 来源特有的标记（UpToDate 的 subtitleN / indentN class、JATS 的 rules / frame / align 属性）
 * 在文件末尾按"标记特征"命中，互不冲突，所以一个文件覆盖所有来源；宿主可继续追加
 * fig-table-{source} 类，但没有任何规则依赖它。
 *
 * 同一份文件供以下几处使用，保证缩略图、全屏 HTML、回答正文里的 markdown 表格观感一致：
 *   - Web 前端（index.html 直接 <link>；文献表格与 markdown 表格都套 .fig-table）
 *   - 渲染服务 render/poster_server.py（release.sh 拷贝到 /root/render/table_css/，/render_table 生成缩略图）
 *   - iOS / Android / HarmonyOS 的表格 WebView（运行时从站点 /table-css/table.css 拉取 + 缓存，失败回退内置）
 *     内置副本：iOS 由 project.yml「Sync Table CSS」构建期拷贝；Android 由 Gradle generateEmbedDocAssets
 *     拷贝；鸿蒙需手动 `node harmony/scripts/sync-table-css.mjs`（产物提交进仓库）
 *
 * 只允许通过 --ft-* 变量差异化（深色主题、正文里字号略小等），不要在宿主里另写表格规则。
 * 每条带背景的规则都同时写 color，避免宿主深色文字色叠在浅底上不可读。
 */

.fig-table {
  --ft-bg: #ffffff;
  --ft-text: #1f2a37;
  --ft-heading: #162233;
  --ft-border: #d8e1ea;
  --ft-border-strong: #6b7a90;
  --ft-header-bg: #eef3f9;
  --ft-stripe: #f7faff;
  --ft-accent: #2b5797;
  --ft-accent-fg: #ffffff;
  --ft-accent-soft: #dfe8f3;
  --ft-accent-soft-fg: #162233;
  --ft-muted-bg: #f1f3f5;
  --ft-muted-bg-strong: #dee2e6;
  --ft-font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans CJK SC", "Helvetica Neue", Arial, sans-serif;
  --ft-font-size: 15px;
  --ft-line-height: 1.45;
  --ft-cell-padding: 8px 12px;

  color: var(--ft-text);
  font-family: var(--ft-font);
  font-size: var(--ft-font-size);
  line-height: var(--ft-line-height);
}

.fig-table table {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  table-layout: auto;
  margin: 0;
  background: var(--ft-bg);
  color: inherit;
  font: inherit;
  line-height: inherit;
  border: 1px solid var(--ft-border);
}

.fig-table th,
.fig-table td {
  padding: var(--ft-cell-padding);
  border: 1px solid var(--ft-border);
  vertical-align: top;
  text-align: left;
  font-size: inherit;
  line-height: inherit;
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
}

/* 列头：深色强调底 + 白字（与 UpToDate 的 subtitle1 分区行同一观感），所有来源统一。
 * 列头是否整词不拆由下方 ft-keepall 标记按列自适应决定，这里不写死 word-break。 */
.fig-table th {
  background: var(--ft-accent);
  color: var(--ft-accent-fg);
  font-weight: 700;
}

.fig-table thead th,
.fig-table thead td {
  background: var(--ft-accent);
  color: var(--ft-accent-fg);
  font-weight: 700;
}

/* 无 thead 的表把首行当表头；自带 subtitle 分区语义的表（UpToDate）不套这条 */
.fig-table table:not(:has(thead)):not(:has([class^="subtitle"])) > tbody > tr:first-child > td,
.fig-table table:not(:has(thead)):not(:has([class^="subtitle"])) > tr:first-child > td {
  background: var(--ft-accent);
  color: var(--ft-accent-fg);
  font-weight: 700;
}

/* ── 列宽自适应标记（由宿主 JS fitFigTableColumns 按列内容长度打上） ──────────
 * 中文每个字之间都是换行点，auto 布局眼里短列的最小宽度只有一个字，会把宽度全让给长文本列，
 * "证据分级 / 强烈推荐"这类短列被压成一字一行的竖条。JS 按整列最长内容分档：
 *   ft-nowrap   短列（≤ 约 6 个汉字宽）：整列不换行，列宽 = 内容宽
 *   ft-keepall  中列（≤ 约 14 个汉字宽）：只在标点 / 空格处换行，不按字拆
 *   长文本列不打标记，按字自由换行吃掉剩余宽度；容器装不下时 JS 会把最宽的短列降级，保证长列可读。
 * Web / iOS / Android / 鸿蒙 / 缩略图渲染服务各自内置同一段 JS，规则只在这里定义。 */
.fig-table .ft-nowrap {
  white-space: nowrap;
}

.fig-table .ft-keepall {
  word-break: keep-all;
}

/* 表头里的引用标签、上标等继承白字 */
.fig-table th a,
.fig-table thead a {
  color: inherit;
}

.fig-table colgroup,
.fig-table col {
  max-width: none;
}

.fig-table p {
  margin: 0;
  font: inherit;
  line-height: inherit;
}

.fig-table p + p {
  margin-top: 6px;
}

.fig-table ul,
.fig-table ol {
  margin: 0;
  padding-left: 1.3em;
  list-style-position: outside;
}

.fig-table li {
  margin: 0;
  line-height: inherit;
}

.fig-table li + li {
  margin-top: 4px;
}

.fig-table sup,
.fig-table sub {
  font-size: 0.72em;
  line-height: 0;
}

.fig-table br {
  line-height: inherit;
}

.fig-table img {
  max-width: 100%;
  height: auto;
  vertical-align: middle;
}

.fig-table hr {
  border: 0;
  border-top: 1px solid var(--ft-border);
  margin: 4px 0;
}

/* ── 通用 HTML 对齐属性（JATS / 历史 HTML 常见） ─────────────────────────── */

.fig-table [align="center"] { text-align: center; }
.fig-table [align="right"] { text-align: right; }
.fig-table [align="left"] { text-align: left; }
.fig-table [valign="middle"] { vertical-align: middle; }
.fig-table [valign="bottom"] { vertical-align: bottom; }

/* JATS 的 align="char" 用于小数点对齐，浏览器不支持，退化为右对齐 */
.fig-table [align="char"] { text-align: right; }

/* ── JATS（PubMed / PMC）表格属性：rules / frame ─────────────────────────── */

/* rules="groups"：只在 thead / tbody 分组之间画粗线，组内不画竖线 */
.fig-table table[rules="groups"] th,
.fig-table table[rules="groups"] td {
  border-left: 0;
  border-right: 0;
}

.fig-table table[rules="groups"] thead {
  border-bottom: 2px solid var(--ft-border-strong);
}

/* rules="rows" / "none"：横线为主 */
.fig-table table[rules="rows"] th,
.fig-table table[rules="rows"] td,
.fig-table table[rules="none"] th,
.fig-table table[rules="none"] td {
  border-left: 0;
  border-right: 0;
}

/* frame="hsides" / "void"：去掉外框竖边 */
.fig-table table[frame="hsides"],
.fig-table table[frame="void"] {
  border-left: 0;
  border-right: 0;
}

/* ── CALS 转换（Elsevier）：子项行以空首格表示缩进层级，空首格弱化边线 ──── */

.fig-table tbody > tr:not(:first-child) > td:first-child:empty {
  border-right-color: transparent;
}

/* ── UpToDate 抓取片段的 class 语义 ──────────────────────────────────────────
 * 抓取时只保留了 <table> 片段，站点 CSS 未随同抓取，这里按 class 名语义近似还原：
 *   subtitle1*  深色底白字分区行 / 表头
 *   subtitle2*  浅色底粗体列头
 *   subtitle3*  粗体小标题
 *   indent1-3   层级缩进
 *   centered / divider_* / border_*_thick / highlight_*_gray_text / nowrap_whitespace 等
 * 配色走 --ft-* 变量，不是 UpToDate 官方色。
 */

.fig-table .subtitle1,
.fig-table .subtitle1_left,
.fig-table .subtitle1_single {
  background: var(--ft-accent);
  color: var(--ft-accent-fg);
  font-weight: 700;
  text-align: center;
}

.fig-table .subtitle1_left {
  text-align: left;
}

.fig-table .subtitle2,
.fig-table .subtitle2_left,
.fig-table .subtitle2_single {
  background: var(--ft-accent-soft);
  color: var(--ft-accent-soft-fg);
  font-weight: 700;
  text-align: center;
}

.fig-table .subtitle2_left {
  text-align: left;
}

.fig-table .subtitle2_left_white {
  background: var(--ft-bg);
  color: var(--ft-heading);
  font-weight: 700;
  text-align: left;
}

.fig-table .subtitle3,
.fig-table .subtitle3_left,
.fig-table .subtitle3_left_align {
  background: var(--ft-stripe);
  color: var(--ft-heading);
  font-weight: 700;
}

.fig-table .subtitle3 {
  text-align: center;
}

.fig-table .heading {
  font-weight: 700;
}

.fig-table .centered {
  text-align: center;
}

.fig-table td.indent1 { padding-left: calc(12px + 1.4em); }
.fig-table td.indent2 { padding-left: calc(12px + 2.6em); }
.fig-table td.indent3 { padding-left: calc(12px + 3.8em); }

.fig-table p.indent1,
.fig-table li.indent1 { padding-left: 1.4em; }
.fig-table p.indent2,
.fig-table li.indent2 { padding-left: 2.6em; }
.fig-table p.indent3,
.fig-table li.indent3 { padding-left: 3.8em; }

.fig-table .divider_bottom { border-bottom: 2px solid var(--ft-border-strong); }
.fig-table .divider_top { border-top: 2px solid var(--ft-border-strong); }
.fig-table .border_right_thick { border-right: 2px solid var(--ft-border-strong); }
.fig-table .border_bottom_thick { border-bottom: 2px solid var(--ft-border-strong); }
.fig-table .border_bottom_white { border-bottom-color: var(--ft-bg); }

.fig-table .highlight_lght_gray_text {
  background: var(--ft-muted-bg);
  color: var(--ft-text);
}

.fig-table .highlight_gray_text {
  background: var(--ft-muted-bg-strong);
  color: var(--ft-text);
}

.fig-table .primarybox_left {
  border: 2px solid var(--ft-accent);
}

.fig-table .nowrap_whitespace {
  white-space: nowrap;
}

.fig-table .large_checkmark {
  font-size: 1.3em;
  font-weight: 700;
  color: #1f7a3d;
}

.fig-table .arrow {
  font-weight: 700;
}

.fig-table .extra_spacing_top { margin-top: 8px; }
.fig-table .extra_spacing { margin: 6px 0; }

.fig-table ul.sublist1,
.fig-table ul.sublist1_start,
.fig-table ul.sublist_other { list-style: disc; }
.fig-table ul.sublist2,
.fig-table ul.sublist2_start { list-style: circle; }
.fig-table ol.numbers_to_nine,
.fig-table ol.numbers_no_heading,
.fig-table ol.decimal_heading { list-style: decimal; }
.fig-table .none { list-style: none; padding-left: 0; }
