/* ==========================================================================
   T+2026 复刻 · 数据网格
   八条铁律落地：
     1. table-layout: fixed     —— 列宽不随内容跳动
     2. colgroup 显式像素宽      —— 不用百分比/auto
     3. border-collapse: separate + border-spacing: 0
     4. 行高固定 30px
     5. 字体 13px 整数像素
     6. 表头 #E8E8E8/700/居中，数据 400/左对齐，隔行 #FAFAFA，合计 #F5F5F5
     7. 边框 1px 下 + 1px 右，#CCC
     8. overflow hidden，不加省略号
   ========================================================================== */

.tpg {
  /* 外层容器：定位上下文，供表头吸顶与后续虚拟滚动使用 */
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--tp-border-color);
  background: #fff;
  overflow: hidden;
}

/* 滚动层：只有它滚，表头不动 */
.tpg-scroll {
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.tpg table {
  /* 铁律 1：固定布局 */
  table-layout: fixed;
  /* 铁律 3：与 T+ 一致 */
  border-collapse: separate;
  border-spacing: 0;
  /* 表格宽度 = 列宽之和（由 colgroup 决定），不拉伸。这是 T+ 的行为 */
  width: auto;
  font-family: var(--tp-font-family);
  font-size: var(--tp-fs-base);
  color: var(--tp-text-color);
}

/* 铁律 4：行高固定。行高由单元格的 height + box-sizing:border-box 决定（含边框），
   tr 不再设 height，否则会与边框叠加成 31px */
.tpg th,
.tpg td {
  /* table-cell 的 height 不含边框，故减 1px，最终视觉行高恰为 30px */
  height: calc(var(--tp-row-h) - var(--tp-cell-border-w));
  line-height: calc(var(--tp-row-h) - var(--tp-cell-border-w));
  padding: 0;
  box-sizing: border-box;
  /* 铁律 8：裁切但不加省略号 */
  overflow: hidden;
  white-space: nowrap;
  text-overflow: clip;
  vertical-align: middle;
  /* 铁律 7：只有下边框与右边框 */
  border-right: 1px solid var(--tp-border-color);
  border-bottom: 1px solid var(--tp-border-color);
  font-weight: var(--tp-row-weight);
  text-align: var(--tp-row-align);
}

/* 最后一列不画右线 */
.tpg tr > *:last-child { border-right: none; }

/* ---- 表头：铁律 6 ---- */
.tpg thead th {
  background: var(--tp-head-bg);
  font-weight: var(--tp-head-weight);
  text-align: var(--tp-head-align);
  position: sticky;
  top: 0;
  z-index: 2;
  /* 表头不参与排序时也不出现指针变化 */
  cursor: default;
}
.tpg thead th.is-sortable { cursor: pointer; }
.tpg thead th .tpg-sort {
  /* 不要用 inline-block：会新建行盒把表头撑高 1px */
  display: inline;
  margin-left: 3px;
  font-size: 10px;
  line-height: 1;
  color: #888;
}

/* ---- 数据行：铁律 6 ---- */
.tpg tbody tr { background: var(--tp-row-bg); }
.tpg tbody tr:nth-child(even) { background: var(--tp-row-alt-bg); }
.tpg tbody tr.is-selected { background: #E6F0FB; }

/* 行号列：冻结在左侧 */
.tpg .tpg-rownum {
  /* 跟随行底色，避免与隔行色冲突 */
  background: transparent;
  text-align: center;
  color: #666;
  position: sticky;
  left: 0;
  z-index: 1;
}
.tpg thead .tpg-rownum { z-index: 3; background: var(--tp-head-bg); }

/* ---- 合计行：铁律 6 ---- */
.tpg tfoot td {
  background: var(--tp-foot-bg);
  font-weight: 700;
  text-align: right;
}
.tpg tfoot td.tpg-foot-label {
  text-align: center;
}

/* ---- 数字列：右对齐 + 等宽数字，保证小数点竖向对齐 ---- */
.tpg .is-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ---- 必填星号：独立 font 元素，11px 红，位于标签左侧 ---- */
.tpg-required {
  color: var(--tp-required-color);
  font-size: 11px;
  line-height: 1;
  margin-right: 2px;
}

/* ---- 空态：保留行高，不塌陷 ---- */
.tpg-empty {
  height: calc(var(--tp-row-h) * 8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--tp-text-placeholder);
  font-size: var(--tp-fs-sm);
  background: #fff;
}

/* ---- 加载态：避免闪烁，只降透明度 ---- */
.tpg.is-loading tbody { opacity: .55; }

/* ---- 可编辑单元格（预留）：只用下边框，与 T+ 录入风格一致 ---- */
.tpg td.is-editable { padding: 0; }
.tpg td.is-editable input {
  width: 100%;
  /* 减 2px：1px 下边框 + 1px 输入框自身，避免把行高撑到 31 */
  height: calc(var(--tp-row-h) - 2px);
  padding: 0 var(--tp-cell-pad-x);
  border: none;
  border-bottom: 1px solid transparent;
  outline: none;
  font: inherit;
  color: inherit;
  background: transparent;
  box-sizing: border-box;
}
.tpg td.is-editable input:focus {
  border-bottom-color: #2D6AA0;
  background: #FFFDF5;
}

/* 空格填充行：让网格铺满容器，像 T+ 一样有连续网格线 */
.tpg tbody tr.tpg-blank td { background: inherit; }

/* 单元格内层裁切容器：table-cell 本身不支持 overflow:hidden，
   内容（尤其含必填星号的表头）会把 fixed 列宽撑开。
   实测：60px 的「采购单位」被 5 字标题撑到 72px。 */
.tpg .tpg-cell {
  display: block;
  width: 100%;
  padding: 0 var(--tp-cell-pad-x);
  box-sizing: border-box;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: clip;
}
/* 表头保持居中，数据按列对齐 */
.tpg thead .tpg-cell { text-align: center; }
.tpg tbody .tpg-cell { text-align: inherit; }
.tpg .is-num .tpg-cell { text-align: right; }
