/* 网格色彩、字体、间距和阴影统一引用 C1 编辑器令牌。 */
.sg-grid {
  display: flex; flex-direction: column; position: relative; width: 100%; min-width: 0;
  height: min(720px, calc(100dvh - 150px)); min-height: 300px;
  overflow: hidden; background: var(--ed-neutral-0); color: var(--ed-neutral-800);
  font: var(--ed-font-size-ui)/var(--ed-line-height-ui) var(--ed-font);
}
.sg-grid *, .sg-grid *::before, .sg-grid *::after { box-sizing: border-box; }
.sg-formula-bar {
  display: flex; align-items: center; flex: 0 0 44px; min-width: 0;
  border-bottom: 1px solid var(--ed-neutral-300); background: var(--ed-neutral-0);
}
.sg-name-box {
  width: 136px; flex: 0 0 136px; height: 100%; border: 0;
  border-right: 1px solid var(--ed-neutral-300); padding: 0 var(--ed-space-3);
  background: var(--ed-neutral-0); color: var(--ed-neutral-700);
  font: var(--ed-font-size-caption)/var(--ed-line-height-ui) var(--ed-font-mono);
}
.sg-fx {
  flex: 0 0 44px; text-align: center; color: var(--ed-neutral-600);
  font-family: var(--ed-font-mono); font-style: italic;
}
.sg-formula-input {
  min-width: 0; width: 100%; height: 100%; border: 0; padding: 0 var(--ed-space-3) 0 0;
  background: var(--ed-neutral-0); color: var(--ed-neutral-800);
  font: var(--ed-font-size-ui)/var(--ed-line-height-ui) var(--ed-font-mono);
}
.sg-name-box:focus, .sg-formula-input:focus { outline: 2px solid var(--ed-blue); outline-offset: -2px; }
.sg-scroll {
  position: relative; flex: 1; min-height: 0; min-width: 0; overflow: auto;
  overscroll-behavior: contain; touch-action: pan-x pan-y; outline: none;
  background: var(--ed-neutral-100); scrollbar-color: var(--ed-neutral-400) var(--ed-neutral-100);
}
.sg-scroll:focus-visible { box-shadow: inset 0 0 0 2px var(--ed-blue); }
.sg-spacer { position: relative; }
.sg-plane { position: sticky; top: 0; left: 0; overflow: hidden; }
.sg-cells, .sg-headers, .sg-selection-layer { position: absolute; inset: 0; pointer-events: none; }
.sg-cell, .sg-col-header, .sg-row-header, .sg-corner {
  position: absolute; top: 0; left: 0; overflow: hidden; white-space: pre;
  border-right: 1px solid var(--sg-line, #e9ebf1); border-bottom: 1px solid var(--sg-line, #e9ebf1);
  pointer-events: auto; user-select: none;
}
.sg-cell {
  padding: var(--ed-space-1) var(--ed-space-2); background: var(--ed-neutral-0);
  font-variant-numeric: tabular-nums; text-overflow: ellipsis;
}
.sg-cell.sg-selected { background: var(--ed-active-bg); }
.sg-cell.sg-active { background: var(--ed-neutral-0); }
.sg-cell.sg-error { color: var(--ed-conflict-fg); font-weight: 600; }
.sg-headers { z-index: 5; }
.sg-col-header, .sg-row-header, .sg-corner {
  display: flex; align-items: center; justify-content: center; background: var(--ed-neutral-100);
  color: var(--ed-neutral-600); font-size: var(--ed-font-size-caption); border-color: var(--ed-neutral-300);
}
.sg-col-header.sg-col-titled { justify-content: flex-start; gap: 6px; padding: 0 var(--ed-space-3); color: var(--ed-neutral-800); font-weight: 600; }
.sg-col-header.sg-col-titled::before { content: attr(data-letter); flex: none; color: var(--ed-neutral-500); font: 500 10px/16px var(--ed-font-mono); }
.sg-col-header:hover, .sg-row-header:hover, .sg-corner:hover { background: var(--ed-active-bg); color: var(--ed-saving-fg); }
.sg-corner { color: var(--ed-neutral-600); border-right-color: var(--ed-neutral-400); }
.sg-resize-handle { position: absolute; inset: 0 -1px 0 auto; width: 9px; cursor: col-resize; touch-action: none; z-index: 1; }
.sg-resize-handle:hover { border-right: 2px solid var(--ed-blue); }
.sg-selection-layer { z-index: 4; overflow: hidden; }
.sg-selection-outline, .sg-active-outline, .sg-copy-outline {
  position: absolute; top: 0; left: 0; border: 1px solid var(--ed-blue); pointer-events: none;
}
.sg-active-outline { border-width: 2px; }
.sg-fill-handle {
  position: absolute; width: 6px; height: 6px; right: -3px; bottom: -3px;
  background: var(--ed-blue); border: 1px solid var(--ed-neutral-0);
}
.sg-copy-outline { border: 2px dashed var(--ed-blue); opacity: .75; }
.sg-freeze-line { position: absolute; z-index: 6; pointer-events: none; background: var(--ed-neutral-400); }
.sg-freeze-line[hidden] { display: none; }
.sg-freeze-x { bottom: 0; width: 1px; box-shadow: 2px 0 4px #0c113014; }
.sg-freeze-y { right: 0; height: 1px; box-shadow: 0 2px 4px #0c113014; }
.sg-inline-editor {
  position: absolute; top: 0; left: 0; z-index: 8; resize: none; min-width: 0;
  margin: 0; padding: var(--ed-space-1) var(--ed-space-2); border: 2px solid var(--ed-blue);
  border-radius: 0; outline: none; background: var(--ed-neutral-0); color: var(--ed-neutral-900);
  font: var(--ed-font-size-ui)/var(--ed-line-height-ui) var(--ed-font-mono);
  box-shadow: var(--ed-shadow-sm);
}
.sg-inline-editor[hidden] { display: none; }
.sg-footer {
  display: flex; align-items: center; gap: var(--ed-space-3); flex: 0 0 44px;
  min-width: 0; border-top: 1px solid var(--ed-neutral-300); background: var(--ed-neutral-100);
  padding: 0 var(--ed-space-3);
}
.sg-tabs { position: relative; min-width: 0; flex: 1; }
.sg-tabs .ed-tab-strip { border: 0; background: var(--ed-neutral-100); }
.sg-summary { flex-shrink: 0; color: var(--ed-neutral-700); font-size: var(--ed-font-size-caption); white-space: nowrap; font-variant-numeric: tabular-nums; }
.sg-sheet-name-input {
  position: absolute; inset: 0 auto 0 0; z-index: 10; width: min(220px, 100%);
  border: 2px solid var(--ed-blue); border-radius: var(--ed-radius-sm);
  color: var(--ed-neutral-900); background: var(--ed-neutral-0); padding: var(--ed-space-2);
  font: inherit;
}
.sg-notice { color: var(--ed-conflict-fg); background: var(--ed-conflict-bg); padding: var(--ed-space-2) var(--ed-space-3); }
.sg-notice[hidden] { display: none; }
@media (max-width: 700px) {
  .sg-grid { height: calc(100dvh - 260px); }
  .sg-name-box { width: 108px; flex-basis: 108px; padding-inline: var(--ed-space-2); }
  .sg-fx { flex-basis: 32px; }
  .sg-footer { flex-wrap: wrap; flex-basis: auto; gap: 0; padding: 0 var(--ed-space-2); }
  .sg-tabs { flex-basis: 100%; }
  .sg-summary { max-width: 100%; overflow: hidden; text-overflow: ellipsis; padding-bottom: var(--ed-space-1); }
}
