/* ========================================================================== */
/* 1. 全局设计变量与基础样式                                                   */
/* ========================================================================== */

:root {
  --ink: #18322c;
  --muted: #687b76;
  --line: #dfe8e4;
  --line-strong: #cad8d3;
  --paper: #ffffff;
  --canvas: #f3f7f5;
  --brand: #157a62;
  --brand-dark: #0e5e4b;
  --brand-soft: #e5f4ef;
  --warning: #a46113;
  --warning-soft: #fff5df;
  --danger: #b43b3b;
  --danger-soft: #fff0ef;
  --shadow: 0 18px 50px rgba(27, 61, 52, 0.08);
  --radius-lg: 20px;
  --radius-md: 12px;
  --row-height: 38px;
}

* {
  box-sizing: border-box;
}

/* 部分选择器显式设置了 display，统一规则可确保 hidden 属性始终真正隐藏元素。 */
[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(101, 186, 156, 0.13), transparent 30rem),
    var(--canvas);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/*
 * 地址栏带参数时使用独立的全屏启动层。它在 app.js 执行前即可出现，
 * 因而不会先闪现空状态；多层轨道和流光进度条保持轻量且无需图片资源。
 */
.startup-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 11px;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 42%, rgba(80, 190, 151, 0.2), transparent 28%),
    linear-gradient(145deg, #f9fcfb 0%, #edf7f3 52%, #f8fbfa 100%);
  overflow: hidden;
  isolation: isolate;
}

.is-startup-loading .startup-loader {
  display: flex;
}

.startup-loader::before,
.startup-loader::after {
  position: absolute;
  z-index: -1;
  width: 38vw;
  height: 38vw;
  min-width: 280px;
  min-height: 280px;
  border-radius: 50%;
  content: "";
  filter: blur(3px);
  background: radial-gradient(circle, rgba(21, 122, 98, 0.09), transparent 68%);
  animation: startup-float 5s ease-in-out infinite alternate;
}

.startup-loader::before {
  top: -18vw;
  left: -12vw;
}

.startup-loader::after {
  right: -14vw;
  bottom: -20vw;
  animation-delay: -2.5s;
}

.startup-loader-visual {
  width: 88px;
  height: 88px;
  position: relative;
  display: grid;
  place-items: center;
}

.startup-loader-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(145deg, #20a47f, #0e644f);
  box-shadow: 0 12px 30px rgba(21, 122, 98, 0.28);
  font-size: 25px;
  animation: startup-pulse 1.8s ease-in-out infinite;
}

.startup-orbit {
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(21, 122, 98, 0.2);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: startup-spin 1.35s linear infinite;
}

.startup-orbit::after {
  width: 7px;
  height: 7px;
  position: absolute;
  top: 5px;
  right: 11px;
  border-radius: 50%;
  content: "";
  background: #28aa83;
  box-shadow: 0 0 12px rgba(40, 170, 131, 0.8);
}

.startup-orbit-two {
  inset: 13px;
  border-color: rgba(21, 122, 98, 0.12);
  border-bottom-color: #71c4a7;
  animation-direction: reverse;
  animation-duration: 1.8s;
}

.startup-loader > strong {
  font-size: 15px;
  letter-spacing: 0.04em;
}

.startup-loader > span:not(.startup-loading-bar) {
  max-width: min(80vw, 520px);
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.startup-loading-bar {
  width: 150px;
  height: 3px;
  margin-top: 4px;
  position: relative;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(21, 122, 98, 0.12);
}

.startup-loading-bar i {
  width: 45%;
  height: 100%;
  position: absolute;
  left: -45%;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, #20a47f, transparent);
  animation: startup-slide 1.1s ease-in-out infinite;
}

@keyframes startup-spin {
  to { transform: rotate(360deg); }
}

@keyframes startup-pulse {
  50% { transform: scale(1.06); box-shadow: 0 15px 34px rgba(21, 122, 98, 0.36); }
}

@keyframes startup-slide {
  to { left: 100%; }
}

@keyframes startup-float {
  to { transform: translate3d(3vw, 2vw, 0) scale(1.08); }
}

button,
input,
select {
  font: inherit;
}

button,
label,
select {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ========================================================================== */
/* 2. 顶部品牌栏                                                               */
/* ========================================================================== */

.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(202, 216, 211, 0.8);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 34px;
  height: 34px;
  padding: 7px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  border-radius: 11px;
  background: var(--brand);
  box-shadow: 0 7px 18px rgba(21, 122, 98, 0.24);
}

.brand-mark span {
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.88);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 15px;
  letter-spacing: 0.08em;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.privacy-note {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.privacy-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3eb38d;
  box-shadow: 0 0 0 4px rgba(62, 179, 141, 0.12);
}

/* ========================================================================== */
/* 3. 文件来源面板                                                             */
/* ========================================================================== */

.workspace {
  width: 100%;
  min-height: 0;
  margin: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.source-panel,
.viewer-card {
  border: 0;
  background: var(--paper);
  box-shadow: none;
}

/*
 * 文件来源从大卡片压缩为一条应用工具栏。
 * 它只占固定高度，把绝大部分视口留给下方表格。
 */
.source-panel {
  min-height: 50px;
  padding: 5px 12px;
  flex: 0 0 50px;
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  opacity: 1;
  transition: min-height 160ms ease, flex-basis 160ms ease, padding 160ms ease, opacity 120ms ease;
}

.panel-heading {
  display: block;
  margin: 0;
}

.eyebrow {
  display: none;
  color: var(--brand);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.panel-heading h1 {
  margin: 0;
  font-family: inherit;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0;
  white-space: nowrap;
}

.panel-heading p:not(.eyebrow) {
  display: none;
}

.format-badge {
  display: none;
}

.source-grid {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(225px, 0.48fr) minmax(500px, 1.52fr);
  gap: 8px;
}

.drop-zone {
  min-height: 38px;
  height: 38px;
  padding: 5px 7px 5px 10px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px dashed #9ec4b6;
  border-radius: 9px;
  background: linear-gradient(135deg, #f4fbf8, #fbfdfc);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.drop-zone:hover,
.drop-zone.is-dragging {
  border-color: var(--brand);
  background: #edf9f5;
  transform: translateY(-1px);
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.upload-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 0;
  border-radius: 50%;
  color: var(--brand);
  background: transparent;
  font-size: 18px;
  line-height: 1;
}

.drop-copy {
  min-width: 0;
  flex: 1;
}

.drop-copy strong,
.drop-copy small {
  display: block;
}

.drop-copy strong {
  font-size: 12px;
}

.drop-copy small {
  display: none;
}

.remote-source {
  min-width: 0;
  min-height: 38px;
  padding: 0;
  display: grid;
  grid-template-columns: minmax(210px, 0.7fr) minmax(300px, 1.3fr);
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 0;
}

.remote-source > label,
.remote-source > .field-label {
  display: none;
}

.input-row {
  display: flex;
  gap: 8px;
}

.input-row input,
.input-row select {
  min-width: 0;
  height: 38px;
  flex: 1;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  outline: none;
  color: var(--ink);
  background: #fff;
}

/* 自定义预置文件下拉：弹层完全由站点绘制，不再调用系统原生 select 菜单。 */
.preset-select {
  min-width: 0;
  flex: 1;
  position: relative;
}

.preset-trigger {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  outline: none;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
  text-align: left;
}

.preset-trigger:hover:not(:disabled) {
  border-color: #9ebdb2;
  background: #fbfdfc;
}

.preset-trigger:focus-visible,
.preset-select.is-open .preset-trigger {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(21, 122, 98, 0.1);
}

.preset-trigger:disabled {
  cursor: not-allowed;
  color: #93a19d;
  background: #f6f8f7;
}

.preset-value {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preset-chevron {
  width: 8px;
  height: 8px;
  margin: -4px 3px 0 0;
  flex: 0 0 auto;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 150ms ease, margin 150ms ease;
}

.preset-select.is-open .preset-chevron {
  margin-top: 4px;
  transform: rotate(225deg);
}

.preset-options {
  width: 100%;
  max-height: 220px;
  padding: 5px;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 80;
  overflow-y: auto;
  border: 1px solid #c8d9d3;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 14px 36px rgba(27, 61, 52, 0.18);
  scrollbar-width: thin;
  scrollbar-color: #b4c9c1 transparent;
}

.preset-option {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 9px;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.preset-option::before {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border: 1px solid #a9c8bc;
  border-radius: 50%;
  content: "";
}

.preset-option span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preset-option:hover,
.preset-option:focus-visible {
  outline: none;
  color: var(--brand-dark);
  background: #eef8f4;
}

.preset-option[aria-selected="true"] {
  color: var(--brand-dark);
  background: var(--brand-soft);
  font-weight: 750;
}

.preset-option[aria-selected="true"]::before {
  border-color: var(--brand);
  background: var(--brand);
  box-shadow: 0 0 0 3px rgba(21, 122, 98, 0.12);
}

.input-row input {
  padding: 0 12px;
}

.input-row select {
  padding: 0 34px 0 11px;
}

.input-row input:focus,
.input-row select:focus,
.search-box:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(21, 122, 98, 0.1);
}

.divider {
  display: none;
}

.divider::before,
.divider::after {
  height: 1px;
  flex: 1;
  content: "";
  background: var(--line);
}

.button {
  min-height: 36px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease, transform 150ms ease;
}

.button:active {
  transform: translateY(1px);
}

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

.button-primary {
  color: #fff;
  background: var(--brand);
}

.button-primary:hover {
  background: var(--brand-dark);
}

.button-secondary {
  min-width: 64px;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  background: #f7faf9;
}

.button-secondary:hover {
  border-color: #a8beb7;
  background: #eef4f2;
}

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

.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;
  border-radius: 10px;
  color: var(--brand-dark);
  background: var(--brand-soft);
  font-size: 18px;
}

.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 #b9d4ca;
  border-radius: 8px;
  color: var(--brand-dark);
  background: #f1f8f5;
  font-size: 11px;
  font-weight: 750;
  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: 11px;
  font-weight: 750;
  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: 0 4px 12px rgba(21, 122, 98, 0.2);
}

.segmented {
  padding: 3px;
  display: flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f4f7f6;
}

.segmented button {
  height: 28px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  cursor: pointer;
}

.segmented button.is-active {
  color: var(--brand-dark);
  background: #fff;
  box-shadow: 0 2px 8px rgba(36, 71, 62, 0.1);
  font-weight: 750;
}

.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: 10px;
  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-height: 36px;
  padding: 3px 12px 0;
  flex: 0 0 36px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfc;
}

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

.sheet-tabs {
  min-width: 0;
  display: flex;
  gap: 3px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.sheet-tab {
  height: 33px;
  padding: 0 12px;
  flex: 0 0 auto;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  cursor: pointer;
}

.sheet-tab:hover {
  color: var(--brand-dark);
}

.sheet-tab.is-active {
  border-bottom-color: var(--brand);
  color: var(--brand-dark);
  font-weight: 750;
}

.status-line {
  min-height: 36px;
  padding: 0 12px;
  flex: 0 0 36px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  color: #567068;
  background: #f6faf8;
  font-size: 10px;
}

/* 状态文字单独靠右显示，过长内容使用省略号，避免挤压工作表标签。 */
.status-feedback {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  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;
}

/* ========================================================================== */
/* 5. 空状态、加载状态与表格容器                                               */
/* ========================================================================== */

.grid-empty {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
}

.grid-empty strong {
  margin-top: 17px;
  color: #405851;
  font-size: 14px;
}

.grid-empty p {
  margin: 6px 0 0;
  font-size: 12px;
}

.empty-illustration {
  width: 78px;
  height: 58px;
  padding: 7px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 4px;
  transform: rotate(-3deg);
  border: 1px solid #bfd5cd;
  border-radius: 8px;
  background: #eff8f4;
  box-shadow: 9px 8px 0 #f7faf9, 9px 8px 0 1px #d6e3df;
}

.empty-illustration span {
  border-radius: 2px;
  background: #c4dfd5;
}

.grid-viewport {
  height: auto;
  min-height: 0;
  flex: 1;
  position: relative;
  overflow: auto;
  outline: none;
  background: #fff;
  scrollbar-color: #b9c9c4 #f1f5f3;
}

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

.loading-overlay {
  position: absolute;
  inset: 48px 0 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(5px);
}

.loading-overlay[hidden] {
  display: none;
}

.loading-overlay strong {
  margin-top: 5px;
  font-size: 14px;
}

.loading-overlay span:not(.spinner) {
  color: var(--muted);
  font-size: 11px;
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid #dcebe6;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 750ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

.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-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;
}

.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;
}

.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，以完整支持跨行、跨列合并。 */
.raw-table {
  min-width: 100%;
  width: max-content;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.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: 56px;
  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;
}

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

/*
 * 原始视图搜索只改变视觉标记，不隐藏行。
 * 使用 !important 覆盖工作簿自带填充色，同时以更深描边区分当前导航结果。
 */
.grid-cell.is-search-match,
.raw-table td.is-search-match {
  position: relative;
  z-index: 1;
  background: #fff2ad !important;
  box-shadow: inset 0 0 0 2px #e7b52f;
}

.grid-cell.is-search-current,
.raw-table td.is-search-current {
  z-index: 2;
  background: #ffe078 !important;
  box-shadow: inset 0 0 0 3px #c66d08, 0 0 0 1px rgba(198, 109, 8, 0.2);
}

.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);
}

/* 复制反馈悬浮在表格底部，不改变表格可用高度。 */
.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);
}

/* ========================================================================== */
/* 7. 页脚与响应式适配                                                         */
/* ========================================================================== */

footer {
  display: none;
}

@media (max-width: 900px) {
  .source-panel {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    overflow-x: auto;
  }

  .panel-heading {
    display: none;
  }

  .source-grid {
    min-width: 760px;
    grid-template-columns: 230px 1fr;
  }

  .file-summary strong {
    max-width: 32vw;
  }

  .toolbar-actions {
    min-width: 0;
  }

  .search-box {
    min-width: 160px;
    flex: 1;
  }

}

@media (max-width: 620px) {
  .privacy-note {
    display: none;
  }

  .source-panel {
    min-height: 48px;
    padding: 5px 8px;
    flex-basis: 48px;
  }

  .drop-zone {
    padding: 5px 7px;
  }

  .drop-zone .button {
    width: auto;
  }

  .viewer-toolbar {
    min-height: 82px;
    padding: 6px 8px;
    flex-basis: 82px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 5px 8px;
  }

  .file-summary strong {
    max-width: calc(100vw - 80px);
  }

  .toolbar-actions {
    grid-column: 1 / -1;
    align-items: stretch;
    flex-direction: row;
  }

  .segmented button {
    flex: 1;
  }

  .search-box {
    min-width: 100px;
    width: auto;
    flex: 1;
  }

  .sheet-bar,
  .status-line {
    padding-left: 12px;
    padding-right: 12px;
  }

  .loading-overlay {
    inset: 82px 0 0;
  }
}

/* ========================================================================== */
/* 8. 居中文件空状态与单行查看器工具栏                                       */
/* ========================================================================== */

/*
 * workspace 作为初始选择卡片的定位容器。
 * 文件未打开时，下面的 viewer-card 只提供安静的满屏画布，不显示多余工具栏。
 */
.workspace {
  position: relative;
}

.viewer-card.is-empty {
  background:
    linear-gradient(rgba(21, 122, 98, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(21, 122, 98, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 50% 42%, #ffffff 0, #f6faf8 60%, #eef5f2 100%);
  background-size: 32px 32px, 32px 32px, auto;
}

.viewer-card.is-empty .viewer-toolbar,
.viewer-card.is-empty .status-line,
.viewer-card.is-empty .grid-empty {
  display: none;
}

/*
 * 初始选择区属于页面空状态，而不是模态弹窗：没有遮罩和关闭按钮。
 * 使用绝对定位避免卡片占据表格布局高度；打开文件后直接通过 hidden 移除。
 */
.source-panel {
  width: min(860px, calc(100vw - 40px));
  max-height: calc(100vh - 40px);
  min-height: 0;
  padding: 28px;
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 10;
  transform: translate(-50%, -50%);
  overflow: auto;
  border: 1px solid rgba(190, 211, 203, 0.95);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 24px 70px rgba(20, 65, 53, 0.16);
  opacity: 1;
  pointer-events: auto;
}

.source-panel .panel-heading {
  margin: 0 0 22px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.source-panel .eyebrow {
  margin: 0 0 5px;
  display: block;
}

.source-panel .panel-heading h1 {
  font-family: Georgia, "Songti SC", serif;
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.source-panel .panel-heading p:not(.eyebrow) {
  margin: 7px 0 0;
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.source-panel .format-badge {
  margin-top: 2px;
  padding: 7px 10px;
  display: inline-flex;
}

/* 加载或校验失败后就地显示原因，让用户可以马上修正输入并重试。 */
.source-message {
  margin: -6px 0 18px;
  padding: 10px 12px;
  border: 1px solid #efc7c3;
  border-radius: 10px;
  color: var(--danger);
  background: var(--danger-soft);
  font-size: 12px;
  line-height: 1.55;
}

.source-panel .source-grid {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(340px, 1.1fr);
  gap: 18px;
}

.source-panel .drop-zone {
  min-height: 170px;
  height: auto;
  padding: 24px;
  gap: 16px;
  border: 1.5px dashed #9ec4b6;
  border-radius: 12px;
}

.source-panel .upload-icon {
  width: 46px;
  height: 46px;
  border: 1px solid #cae4db;
  background: #fff;
  font-size: 24px;
}

.source-panel .drop-copy strong {
  font-size: 15px;
}

.source-panel .drop-copy small {
  margin-top: 5px;
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.source-panel .remote-source {
  min-height: 170px;
  padding: 18px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.source-panel .remote-source > label,
.source-panel .remote-source > .field-label {
  margin-bottom: 6px;
  display: block;
  color: #486059;
  font-size: 11px;
  font-weight: 750;
}

.source-panel .divider {
  height: 26px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #9aa9a4;
  font-size: 10px;
}

.source-panel .button,
.source-panel .input-row input,
.source-panel .input-row select,
.source-panel .preset-trigger {
  min-height: 38px;
  height: 38px;
}

/*
 * 宽屏第一行只保留文件信息和常用操作；工作表标签下移到第二行状态栏。
 * 这样 Sheet 数量变化不会挤压视图切换与搜索框，整体结构也更接近表格软件。
 */
.viewer-toolbar {
  width: 100%;
  min-height: 52px;
  padding: 5px 12px;
  flex: 0 0 52px;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) max-content;
  align-items: center;
  gap: 12px;
  overflow: hidden;
}

.viewer-toolbar .file-summary > div {
  min-width: 0;
}

.viewer-toolbar .file-summary strong {
  max-width: min(48vw, 520px);
}

/* 状态栏左侧承载 Sheet，右侧显示当前渲染状态。 */
.status-line .sheet-bar {
  min-width: 0;
  min-height: 0;
  height: 35px;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  border: 0;
  background: transparent;
}

.status-line .sheet-label {
  padding: 0;
  flex: 0 0 auto;
}

.status-line .sheet-tabs {
  height: 100%;
  align-items: stretch;
}

.status-line .sheet-tab {
  height: 35px;
}

.status-line .status-feedback {
  max-width: min(52vw, 680px);
}

.viewer-toolbar .toolbar-actions {
  min-width: 0;
  gap: 8px;
}

.loading-overlay {
  inset: 52px 0 0;
}

/* 中等宽度仍采用单行，只适度压缩文件信息和搜索框。 */
@media (max-width: 1100px) {
  .viewer-toolbar {
    grid-template-columns: minmax(150px, 1fr) max-content;
    gap: 8px;
  }

  .viewer-toolbar .file-summary strong {
    max-width: 34vw;
  }

  .viewer-toolbar .search-box {
    width: 240px;
    min-width: 180px;
  }

  .status-line {
    gap: 8px;
  }

  .status-line .status-feedback {
    max-width: 48vw;
  }
}

@media (max-width: 820px) {
  .source-panel {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
    padding: 18px;
  }

  .source-panel .panel-heading {
    margin-bottom: 14px;
  }

  .source-panel .format-badge {
    display: none;
  }

  .source-panel .source-grid {
    min-width: 0;
    grid-template-columns: 1fr;
  }

  .source-panel .drop-zone {
    min-height: 104px;
    padding: 16px;
  }

  .source-panel .remote-source {
    min-height: 0;
  }

  /*
   * 手机端第一行只放文件信息和“更换文件”；复制、视图切换、搜索位于第二行。
   * 四列中的第三列负责吸收剩余宽度，使超长文件名能够稳定显示省略号。
   * toolbar-actions 使用 display: contents，让四个子控件能直接参与父级网格布局。
   */
  .viewer-toolbar {
    min-height: 80px;
    padding: 4px 8px;
    flex-basis: 80px;
    display: grid;
    grid-template-columns: max-content max-content minmax(0, 1fr) max-content;
    grid-template-rows: 34px 34px;
    align-items: center;
    gap: 4px 8px;
    overflow: hidden;
  }

  .viewer-toolbar .file-summary {
    min-width: 0;
    gap: 8px;
    grid-column: 1 / 4;
    grid-row: 1;
  }

  .viewer-toolbar .file-summary strong {
    max-width: 100%;
    font-size: 12px;
  }

  .viewer-toolbar .file-summary span:not(.file-icon) {
    display: none;
  }

  .viewer-toolbar .toolbar-actions {
    display: contents;
  }

  .viewer-toolbar .copy-toggle {
    grid-column: 1;
    grid-row: 2;
    justify-self: start;
  }

  .viewer-toolbar .source-toggle {
    grid-column: 4;
    grid-row: 1;
    justify-self: end;
  }

  .viewer-toolbar .segmented {
    grid-column: 2;
    grid-row: 2;
    justify-self: start;
  }

  .viewer-toolbar .search-box {
    width: 100%;
    min-width: 0;
    grid-column: 3 / 5;
    grid-row: 2;
  }

  /* Sheet 保持在左侧，右侧状态信息单行省略，二者都不会撑宽页面。 */
  .status-line {
    min-height: 36px;
    padding: 0 8px;
    flex-basis: 36px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 52%);
    gap: 8px;
  }

  .status-line .sheet-label {
    display: none;
  }

  .status-line .sheet-tabs {
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }

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

  .status-line .sheet-tab {
    padding: 0 10px;
  }

  .status-line .status-feedback {
    width: 100%;
    max-width: none;
  }

  .loading-overlay {
    inset: 80px 0 0;
  }
}

@media (max-width: 430px) {
  .source-panel {
    padding: 15px;
    border-radius: 16px;
  }

  .source-panel .panel-heading h1 {
    font-size: 22px;
  }

  .source-panel .panel-heading p:not(.eyebrow) {
    font-size: 12px;
  }

  .source-panel .source-grid {
    gap: 12px;
  }

  .source-panel .drop-zone {
    min-height: 96px;
    padding: 12px;
  }

  .viewer-toolbar {
    grid-template-columns: max-content max-content minmax(0, 1fr) max-content;
  }

  .viewer-toolbar .file-icon {
    width: 28px;
    height: 28px;
  }

  .viewer-toolbar .source-toggle {
    padding: 0 8px;
  }

  .viewer-toolbar .copy-toggle {
    padding: 0 8px;
  }

  .viewer-toolbar .segmented button {
    padding: 0 8px;
    font-size: 11px;
  }

  .viewer-toolbar .search-box {
    padding: 0 8px;
  }

  .viewer-toolbar .search-box > span[aria-hidden="true"] {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
