.workbench {
  min-width: 0;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.push-right {
  margin-left: auto;
}
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
}
.toggle input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--green);
}

.sheet {
  background: var(--surface);
  border: 2px solid var(--ink);
  box-shadow: 10px 10px 0 var(--head-hl);
}

/* ---------- formula bar ---------- */
.fx-bar {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--grid);
  background: var(--paper);
}
.name-box {
  display: grid;
  place-items: center;
  min-width: 5.5rem;
  padding: 0.4rem 0.75rem;
  border-right: 1px solid var(--grid);
  background: var(--surface);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.9rem;
}
.fx-label {
  display: grid;
  place-items: center;
  padding: 0 0.75rem;
  color: var(--green);
  font-family: var(--font-mono);
  font-style: italic;
  font-weight: 600;
}
.fx-input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.92rem;
}
.fx-input:focus {
  outline: none;
}

/* ---------- grid ---------- */
.grid-scroll {
  overflow: auto;
  max-height: min(70vh, 640px);
}
.grid-scroll:focus-visible {
  outline-offset: -3px;
}

.grid {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  user-select: none;
  -webkit-user-select: none;
  font-size: 0.95rem;
}
.col-rowhead {
  width: 2.75rem;
}
.col-first {
  width: 9.5rem;
}
.col-data {
  width: 7rem;
}

.grid th,
.grid td {
  height: 2.1rem;
  padding: 0 0.6rem;
  border: 1px solid var(--grid);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grid th {
  background: var(--head);
  color: var(--ink-soft);
  font-weight: 500;
  font-size: 0.8rem;
  text-align: center;
}
.grid thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}
.grid tbody th {
  position: sticky;
  left: 0;
  z-index: 1;
}
.grid .corner {
  left: 0;
  z-index: 3;
}
.grid th.hl {
  background: var(--head-hl);
  color: var(--ink);
  font-weight: 600;
}

.cell {
  background: var(--surface);
  cursor: cell;
  text-align: left;
}
.cell.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.cell.bool,
.cell.err {
  text-align: center;
}
.cell.err {
  color: var(--error);
  font-weight: 600;
}
.cell.formula-text {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--green-deep);
}

.cell.sel {
  background: var(--green-wash);
}
.cell.active {
  background: var(--surface);
  box-shadow: inset 0 0 0 2.5px var(--ink);
}
.cell.ref {
  background: #fff4c2;
  box-shadow: inset 0 0 0 2px var(--signal);
}
.cell.editing {
  padding: 0;
  overflow: visible;
  background: var(--surface);
  box-shadow: inset 0 0 0 2.5px var(--green);
}
.cell-input {
  width: 100%;
  height: 100%;
  padding: 0 0.6rem;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.92rem;
  user-select: text;
  -webkit-user-select: text;
}
.cell-input:focus {
  outline: none;
}

.grid-status {
  margin: 0;
  padding: 0.45rem 0.75rem;
  border-top: 1px solid var(--grid);
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 0.85rem;
  min-height: 2.2rem;
}

.sheet-note {
  margin: var(--space-4) 0 0;
  color: var(--ink-soft);
  font-size: 0.88rem;
  max-width: 64ch;
}
