/* ========================================================================== */
/* 表格与虚拟滚动行                                                            */
/* ========================================================================== */

/*
 * 原始视图坐标轴位于数据滚动容器之外。轨道由 JavaScript 分别同步 scrollLeft
 * 和 scrollTop，因此触摸板斜向滚动也不会让行号离开左边或列号离开上边。
 */
.raw-axis-layer {
  position: absolute;
  inset: 0;
  z-index: 30;
  overflow: hidden;
  pointer-events: none;
}

.raw-axis-corner {
  width: 42px;
  height: 38px;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 4;
  overflow: hidden;
  border-right: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
  background: #f4f7f6;
  pointer-events: auto;
}

.raw-column-axis {
  height: 38px;
  position: absolute;
  top: 0;
  right: 0;
  left: 42px;
  overflow: hidden;
  border-bottom: 1px solid var(--line-strong);
  background: #f4f7f6;
}

.raw-column-axis-track {
  height: 38px;
  display: grid;
  will-change: transform;
}

.raw-column-pinned-axis,
.raw-row-pinned-axis {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.raw-column-axis-cell {
  min-width: 0;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-right: 1px solid var(--line);
  color: #49625b;
  background: #f4f7f6;
  font-size: 11px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: auto;
}

.raw-column-pinned-axis .raw-column-axis-cell {
  position: absolute;
  top: 0;
  box-shadow: 2px 0 4px rgba(38, 66, 59, 0.1);
}

.raw-row-axis {
  width: 42px;
  position: absolute;
  top: 38px;
  bottom: 0;
  left: 0;
  overflow: hidden;
  border-right: 1px solid var(--line-strong);
  background: #f4f7f6;
}

.raw-row-axis-track {
  width: 42px;
  position: relative;
  will-change: transform;
}

.raw-row-axis-cell {
  width: 42px;
  min-height: 1px;
  position: absolute;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  color: #7b8e88;
  background: #f4f7f6;
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  pointer-events: auto;
}

.raw-row-pinned-axis .raw-row-axis-cell {
  z-index: 2;
  box-shadow: 0 2px 4px rgba(38, 66, 59, 0.1);
}

.raw-axis-layer .is-pinned-axis-copy {
  color: var(--brand-dark);
  background: #dff0ea;
}

.grid-header {
  position: sticky;
  top: 0;
  z-index: 20;
  width: max-content;
  min-width: 100%;
  display: grid;
  border-bottom: 1px solid var(--line-strong);
  background: #f4f7f6;
  box-shadow: 0 2px 5px rgba(38, 66, 59, 0.05);
}

.grid-header-cell {
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  color: #49625b;
  font-size: 11px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: none;
}

button.grid-header-cell {
  border-top: 0;
  border-bottom: 0;
  border-left: 0;
  cursor: pointer;
  background: transparent;
  text-align: left;
}

button.grid-header-cell:hover {
  color: var(--brand-dark);
  background: #eaf3f0;
}

.sort-mark {
  margin-left: auto;
  color: var(--brand);
  font-size: 10px;
}

.grid-body {
  width: max-content;
  min-width: 100%;
  position: relative;
}

/* 空白画布与实际表格分离；单元格原有填充保持不变。 */
.grid-frame.is-raw .grid-viewport {
  background: #f1f4f3;
}

.grid-frame.is-raw .grid-body,
.grid-frame.is-raw .grid-row {
  min-width: 0;
}

.grid-row {
  width: max-content;
  min-width: 100%;
  display: grid;
  contain: layout style;
  border-bottom: 1px solid #e7eeeb;
  background: #fff;
}

.grid-row:nth-child(even) {
  background: #fcfdfd;
}

/*
 * 原始视图不继承数据视图的强制网格。每个单元格是否显示工作表网格线，
 * 由渲染模块根据 Sheet 视图设置和单元格填充状态添加 class 后决定。
 */
.grid-row.is-raw-row {
  border-bottom: 0;
  background: #fff;
}

.grid-row.is-raw-row:nth-child(even) {
  background: #fff;
}

.grid-row.is-raw-row .grid-cell:not(.is-row-number) {
  border-right: 0;
  border-bottom: 0;
}

.grid-row.is-raw-row .grid-cell.has-sheet-gridline {
  border-right: 1px solid #e7eeeb;
  border-bottom: 1px solid #e7eeeb;
}

/* 行号属于查看器坐标轴，不受工作表网格线开关影响。 */
.grid-row.is-raw-row .grid-cell.is-row-number {
  border-right: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line);
}

.grid-row.is-virtual {
  position: absolute;
  left: 0;
  top: 0;
}

.grid-cell {
  min-width: 0;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  overflow: hidden;
  border-right: 1px solid #e7eeeb;
  color: #263d37;
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grid-cell.is-row-number,
.grid-header-cell.is-row-number {
  justify-content: center;
  position: sticky;
  left: 0;
  z-index: 4;
  color: #7b8e88;
  background: #f4f7f6;
  font-variant-numeric: tabular-nums;
}

/*
 * 原始视图的行号和列号同时也是“固定/取消固定”控制。激活状态只强调轴标题，
 * 不覆盖工作簿单元格自身的背景色；Enter/空格键焦点样式与鼠标操作一致。
 */
[data-pin-axis] {
  cursor: pointer;
  user-select: none;
}

[data-pin-axis]:hover {
  color: var(--brand-dark) !important;
  background-color: #e7f3ef !important;
}

[data-pin-axis]:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--brand);
}

[data-pin-axis="column"].is-pinned-axis {
  color: var(--brand-dark) !important;
  background-color: #dff0ea !important;
  box-shadow: inset 0 -3px 0 var(--brand);
}

[data-pin-axis="row"].is-pinned-axis {
  color: var(--brand-dark) !important;
  background-color: #dff0ea !important;
  box-shadow: inset 3px 0 0 var(--brand);
}

/* 固定列必须拥有不透明底色，否则横向滚动时后方文字会透过单元格。 */
.grid-cell.is-pinned-column-cell {
  position: sticky;
  background-color: #fff;
  box-shadow: 2px 0 4px rgba(38, 66, 59, 0.08);
}

.grid-cell.is-pinned-row-cell {
  position: sticky;
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(38, 66, 59, 0.09);
}

/* 多个固定行在虚拟大表中由一个始终挂载的粘性层承载。 */
.raw-pinned-rows {
  position: sticky;
  top: 0;
  z-index: 18;
  width: max-content;
  background: #fff;
  box-shadow: 0 3px 7px rgba(38, 66, 59, 0.1);
}

.raw-pinned-rows .grid-row {
  position: relative;
  background: #fff;
}

.grid-cell.is-empty {
  color: transparent;
}

.grid-cell.is-formula-missing::after {
  width: 5px;
  height: 5px;
  margin-left: 6px;
  flex: 0 0 auto;
  border-radius: 50%;
  content: "";
  background: #d58b2b;
}

.grid-cell[title] {
  cursor: default;
}

.grid-empty-result {
  width: 100%;
  min-height: 220px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
}

/*
 * 原始小表使用标准 table，以完整支持跨行、跨列合并。
 * 表头需要保持独立的粘性背景，因此不能使用 collapse：折叠边框会让表体
 * 单元格的深色竖线参与表头边框冲突，进而污染 A/B/C/D 的分割线。
 * 相邻数据单元格的重复边框改由渲染模块在绘制时只保留右、下两侧解决。
 */
.raw-table {
  width: max-content;
  min-width: 0;
  background: #fff;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

/* 原始视图左上角的自适应开关，同时适用于标准 table 和虚拟滚动表头。 */
.raw-fit-corner {
  padding: 0 !important;
}

/* 标准 table 的左上角需要同时固定横向和纵向位置，原始宽度滚动时图标不离开视口。 */
.raw-table thead th.raw-fit-corner {
  left: 0;
  z-index: 30;
}

.raw-fit-toggle {
  width: 100%;
  height: 100%;
  min-height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  color: #6f8580;
  background: transparent;
  cursor: pointer;
  transition: color 150ms ease, background 150ms ease, box-shadow 150ms ease;
}

.raw-fit-toggle svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.raw-fit-toggle:hover {
  color: var(--brand-dark);
  background: #e8f3ef;
}

.raw-fit-toggle:focus-visible {
  position: relative;
  z-index: 2;
  outline: none;
  box-shadow: inset 0 0 0 2px var(--brand);
}

.raw-fit-toggle.is-active {
  color: #fff;
  background: var(--brand);
}

.raw-fit-toggle.is-active:hover {
  background: var(--brand-dark);
}

.raw-table thead th {
  height: 38px;
  position: sticky;
  top: 0;
  z-index: 20;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line-strong);
  color: #49625b;
  background: #f4f7f6;
  font-size: 11px;
  font-weight: 750;
}

.raw-table tbody th {
  width: 42px;
  min-width: 42px;
  max-width: 42px;
  position: sticky;
  left: 0;
  z-index: 4;
  border-right: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line);
  color: #7b8e88;
  background: #f4f7f6;
  font-size: 11px;
  font-weight: 500;
}

/* 标准 table 的固定行/列使用单元格级 sticky，以兼容 colspan/rowspan。 */
.raw-table .is-pinned-row-cell,
.raw-table .is-pinned-column-cell {
  position: sticky;
  background-color: #fff;
  background-clip: border-box;
}

.raw-table .is-pinned-row-cell {
  box-shadow: 0 2px 4px rgba(38, 66, 59, 0.09);
}

.raw-table .is-pinned-column-cell {
  box-shadow: 2px 0 4px rgba(38, 66, 59, 0.08);
}

.raw-table td {
  padding: 7px 9px;
  overflow: hidden;
  border-right: 0;
  border-bottom: 0;
  color: #263d37;
  background-clip: padding-box;
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
}

/* 标准 table 与虚拟表使用同一套原始视图网格线判定。 */
.raw-table td.has-sheet-gridline {
  border-right: 1px solid #e7eeeb;
  border-bottom: 1px solid #e7eeeb;
}

/*
 * 原始视图搜索只改变视觉标记，不隐藏行。
 * 普通匹配使用柔和底色，只有当前导航结果显示强调边框。
 */
.grid-cell.is-search-match,
.raw-table td.is-search-match {
  position: relative;
  z-index: 1;
  background: #d9eee8 !important;
  box-shadow: none;
}

.grid-cell.is-search-current,
.raw-table td.is-search-current {
  z-index: 2;
  background: #d9eee8 !important;
  box-shadow: inset 0 0 0 2px #287d68;
}

.viewer-card.is-copy-mode .grid-cell:not(.is-row-number),
.viewer-card.is-copy-mode .raw-table td {
  cursor: copy;
}

.viewer-card.is-copy-mode .grid-cell:not(.is-row-number):hover,
.viewer-card.is-copy-mode .raw-table td:hover {
  box-shadow: inset 0 0 0 2px rgba(21, 122, 98, 0.65);
}

/* 复制悬停时仍保留当前搜索项的定位边框。 */
.viewer-card.is-copy-mode .grid-cell.is-search-current:hover,
.viewer-card.is-copy-mode .raw-table td.is-search-current:hover {
  box-shadow: inset 0 0 0 2px #287d68;
}

/* 复制反馈悬浮在表格底部，不改变表格可用高度。 */
.copy-toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 60;
  max-width: calc(100% - 32px);
  padding: 9px 14px;
  transform: translateX(-50%);
  border: 1px solid #b9d7cc;
  border-radius: 9px;
  color: #fff;
  background: rgba(14, 94, 75, 0.94);
  box-shadow: 0 10px 28px rgba(20, 58, 48, 0.22);
  font-size: 12px;
  white-space: nowrap;
}

.copy-toast.is-error {
  border-color: #e3aaa5;
  background: rgba(180, 59, 59, 0.95);
}
