/* ========================================================================== */
/* 查看器工具栏与工作表标签                                                    */
/* ========================================================================== */

.viewer-card {
  min-height: 0;
  margin: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  border-radius: 0;
}

.viewer-toolbar {
  min-height: 48px;
  padding: 6px 12px;
  flex: 0 0 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
}

.file-summary {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.file-icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: url("../../favicon.svg") center / contain no-repeat;
}

.file-summary strong,
.file-summary span:not(.file-icon) {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-summary strong {
  max-width: min(38vw, 540px);
  font-size: 13px;
}

.file-summary span:not(.file-icon) {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.source-toggle {
  height: 34px;
  padding: 0 11px;
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: #536a63;
  background: #fff;
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.source-toggle:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

/* 点击复制默认保持低调，开启后使用品牌色明确表示当前处于可复制模式。 */
.copy-toggle {
  height: 34px;
  padding: 0 11px;
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: #536a63;
  background: #fff;
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.copy-toggle:hover {
  border-color: #9db7ae;
  background: #f5f9f7;
}

.copy-toggle.is-active {
  border-color: var(--brand);
  color: #fff;
  background: var(--brand);
  box-shadow: none;
}

.segmented {
  height: 32px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  flex: 0 0 auto;
  align-items: center;
  gap: 0;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #eef0f2;
}

.segmented button {
  height: 30px;
  min-width: 0;
  position: relative;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  color: #59636d;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.segmented button.is-active {
  color: #fff;
  background: var(--brand);
  box-shadow: none;
  font-weight: 600;
}

.viewer-card :is(.source-toggle, .copy-toggle, .segmented button) {
  font-family: inherit;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

.viewer-card :is(.source-toggle, .copy-toggle, .segmented button):focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

.segmented button:not(.is-active):not(:disabled):hover {
  background: #dfe8e3;
  color: var(--brand-dark);
}

.viewer-card .segmented button.is-active:focus-visible {
  outline-color: #fff;
  outline-offset: -4px;
}

.segmented button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.search-box {
  width: 300px;
  height: 34px;
  padding: 0 6px 0 11px;
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: #78908a;
  background: #fff;
}

.search-box input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-size: 12px;
}

.search-count {
  min-width: 34px;
  flex: 0 0 auto;
  color: #60756e;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.search-nav {
  width: 24px;
  height: 24px;
  padding: 0;
  display: grid;
  place-items: center;
  flex: 0 0 24px;
  border: 0;
  border-radius: 6px;
  color: #49635b;
  background: #edf4f1;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}

.search-nav:hover:not(:disabled) {
  color: var(--brand-dark);
  background: var(--brand-soft);
}

.search-nav:disabled {
  cursor: default;
  opacity: 0.38;
}

.search-box:has(input:disabled) {
  opacity: 0.55;
  background: #f5f7f6;
}

.sheet-bar {
  min-width: 0;
  min-height: 0;
  height: 100%;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  border: 0;
  background: transparent;
}

.sheet-label {
  padding: 0 2px;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.sheet-tabs-shell {
  min-width: 0;
  height: 100%;
  flex: 1;
  position: relative;
  overflow: hidden;
}

.sheet-tabs {
  width: 100%;
  height: 100%;
  padding: 0 1px;
  display: flex;
  align-items: stretch;
  gap: 2px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.sheet-tabs::-webkit-scrollbar {
  display: none;
}

.sheet-tabs-shell::before,
.sheet-tabs-shell::after {
  width: 22px;
  position: absolute;
  z-index: 2;
  top: 0;
  bottom: 5px;
  opacity: 0;
  pointer-events: none;
  content: "";
  transition: opacity 140ms ease;
}

.sheet-tabs-shell::before {
  left: 0;
  background: linear-gradient(90deg, #f6f9f7 8%, rgba(246, 249, 247, 0));
}

.sheet-tabs-shell::after {
  right: 0;
  background: linear-gradient(270deg, #f6f9f7 8%, rgba(246, 249, 247, 0));
}

.sheet-tabs-shell.can-scroll-left::before,
.sheet-tabs-shell.can-scroll-right::after {
  opacity: 1;
}

.sheet-scroll-track {
  height: 5px;
  position: absolute;
  z-index: 3;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: hidden;
  border-radius: 999px;
  outline: 0;
  background: var(--line);
  cursor: pointer;
  touch-action: none;
}

.sheet-scroll-track:focus-visible {
  box-shadow: 0 0 0 2px rgba(21, 122, 98, 0.25);
}

.sheet-scroll-thumb {
  height: 100%;
  display: block;
  border-radius: inherit;
  background: #829e95;
  box-shadow: 0 0 0 1px rgba(14, 94, 75, 0.08);
  cursor: grab;
  transform: translate3d(0, 0, 0);
  transform-origin: left center;
  will-change: transform;
}

.sheet-scroll-thumb:hover {
  background: #678a7e;
}

.sheet-scroll-thumb.is-dragging {
  background: var(--brand);
  cursor: grabbing;
}

.sheet-tab {
  height: 39px;
  padding: 0 11px;
  flex: 0 0 auto;
  position: relative;
  border: 0;
  border-radius: 0;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: color 120ms ease, background-color 120ms ease;
}

.sheet-tab::after {
  height: 2px;
  position: absolute;
  right: 8px;
  bottom: 1px;
  left: 8px;
  border-radius: 999px;
  background: var(--brand);
  opacity: 0;
  content: "";
  transition: bottom 120ms ease, opacity 120ms ease;
}

.status-line.has-sheet-overflow .sheet-tab::after {
  bottom: 6px;
}

.sheet-tab:hover {
  color: var(--brand-dark);
  background: rgba(21, 122, 98, 0.06);
}

.sheet-tab.is-active {
  color: var(--brand-dark);
  background: rgba(21, 122, 98, 0.08);
  font-weight: 800;
}

.sheet-tab.is-active::after {
  opacity: 1;
}

.status-line {
  min-height: 40px;
  padding: 0 12px;
  flex: 0 0 40px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: center;
  gap: 14px;
  overflow: hidden;
  border-bottom: 0;
  color: #567068;
  background: linear-gradient(180deg, #f9fbfa 0%, #f3f8f6 100%);
  box-shadow: inset 0 -1px var(--line);
  font-size: 10px;
}

/* 状态文字单独靠右显示，过长内容使用省略号，避免挤压工作表标签。 */
.status-feedback {
  min-width: 0;
  font-size: 12px;
  line-height: 1.5;
  max-width: min(46vw, 620px);
  padding-left: 12px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  border-left: 1px solid var(--line);
  white-space: nowrap;
}

.status-feedback #status-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-line.is-warning {
  color: var(--warning);
  background: var(--warning-soft);
}

.status-line.is-error {
  color: var(--danger);
  background: var(--danger-soft);
}

.status-icon {
  width: 14px;
  height: 14px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 9px;
  font-weight: 800;
}

/* ========================================================================== */
/* 状态提示与表格容器                                                          */
/* ========================================================================== */

.grid-frame {
  min-height: 0;
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #fff;
}

.grid-viewport {
  position: absolute;
  inset: 0;
  overflow: auto;
  outline: none;
  background: #fff;
  scrollbar-color: #b9c9c4 #f1f5f3;
}

/* 原始视图把上、左坐标轴留在滚动区外，数据区只占右下区域。 */
.grid-frame.is-raw .grid-viewport {
  top: 38px;
  left: 42px;
}

.grid-viewport:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(21, 122, 98, 0.35);
}

/* 自适应宽度已经严格限制在视口内，不显示因边框舍入产生的横向滚动条。 */
.grid-viewport.is-raw-fit {
  overflow-x: hidden;
}
