.head {
  display: flex;
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--head);
  border-bottom: var(--stroke-1) solid var(--line-strong);
}

.head-cell {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--size-4);
  height: var(--size-28);
  padding: 0 var(--size-8);
  border-inline-end: var(--stroke-1) solid var(--line);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.head-cell.r {
  justify-content: flex-end;
}

.head-cell.sorted {
  background-image: linear-gradient(var(--accent-soft), var(--accent-soft));
}

.head-cell em {
  color: var(--muted);
  font-style: normal;
  font-weight: var(--fw-normal);
  font-size: var(--fs-sm);
}

.head-text {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.resize {
  position: absolute;
  inset-block: 0;
  inset-inline-end: calc(var(--size-2) * -1);
  width: var(--size-8);
  cursor: col-resize;
  z-index: 4;
}

.filters {
  display: flex;
  position: sticky;
  top: var(--size-28);
  z-index: 3;
  background: var(--head);
  border-bottom: var(--stroke-1) solid var(--line-strong);
}

.filter-cell {
  display: flex;
  align-items: center;
  height: var(--size-28);
  padding: 0 var(--size-4);
  border-inline-end: var(--stroke-1) solid var(--line);
  background: var(--head);
}

.filter-cell.pinned {
  position: sticky;
  z-index: 1;
  background: var(--head);
}

.filters .gutter {
  z-index: 4;
  background: var(--head);
  cursor: default;
}

.filter-cell input,
.filter-cell .select {
  width: 100%;
  min-width: 0;
  height: var(--size-24);
  border: var(--stroke-1) solid transparent;
  border-radius: var(--radius-xs);
  background: var(--surface);
  font: inherit;
  font-size: var(--fs-sm);
  padding: 0 var(--size-4);
  color: inherit;
}

.filter-cell input::placeholder {
  color: var(--text-3);
}

.filter-cell .select {
  text-align: start;
  padding-inline: var(--size-4) var(--size-16);
  background-position: right var(--size-2) center;
  background-size: var(--size-12);
}

.filter-cell input:disabled,
.filter-cell .select:disabled {
  background-color: transparent;
  color: var(--text-3);
  cursor: not-allowed;
  opacity: 1;
}

.filter-cell.on input,
.filter-cell.on .select {
  background-color: var(--accent-soft);
  color: var(--accent);
  font-weight: var(--fw-medium);
}

.date-filter {
  display: flex;
  flex: 1;
  gap: 0;
  min-width: 0;
}

.date-filter .date-field {
  flex: 1;
  min-width: 0;
}

.filter-cell .date-field input {
  padding-inline-end: var(--size-24);
}

.filter-cell .date-field__open {
  inset-inline-end: calc(-1 * var(--size-4));
}

.date-filter .date-filter__op {
  flex: none;
  width: var(--size-20);
  padding-inline: 0;
  background-image: none;
  text-align: center;
  font-weight: var(--fw-medium);
}

.filter-cell input:focus-visible,
.filter-cell .select:focus-visible,
.filter-cell button:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 var(--stroke-1) var(--accent);
}

.filter-cell.bad input,
.filter-cell.bad .select {
  border-color: var(--bad);
  background-color: var(--bad-soft);
  color: var(--bad);
}

.gutter {
  position: sticky;
  inset-inline-start: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--head);
  border-inline-end: var(--stroke-1) solid var(--line-strong);
  color: var(--muted);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}

.head .gutter {
  z-index: 5;
}

.rows {
  position: relative;
}

.row {
  position: absolute;
  inset-inline: 0;
  display: flex;
  background: var(--surface);
  border-bottom: var(--stroke-1) solid var(--line);
}

.row .gutter {
  cursor: pointer;
  user-select: none;
}

.row.here .gutter {
  background-image: linear-gradient(var(--accent-soft), var(--accent-soft));
  color: var(--accent);
}

.row .gutter.picked {
  background-image: linear-gradient(var(--accent-soft), var(--accent-soft));
  color: var(--accent);
  font-weight: var(--fw-semibold);
}

.row.dirty {
  background: var(--dirty);
}

.row.dirty .gutter {
  background-image: linear-gradient(var(--dirty), var(--dirty));
  color: var(--warn);
}

.viewport.reaching .row:not(.new) .cell:not(.rel) {
  cursor: pointer;
}

.row.new {
  background: var(--accent-soft);
  border-top: var(--stroke-1) dashed var(--accent);
  border-bottom: var(--stroke-1) dashed var(--accent);
}

.row.new .gutter {
  background-image: linear-gradient(var(--accent-soft), var(--accent-soft));
  color: var(--accent);
  font-weight: var(--fw-semibold);
}

.row.doomed {
  background: var(--bad-soft);
}

.row.doomed .gutter {
  background-image: linear-gradient(var(--bad-soft), var(--bad-soft));
  color: var(--bad);
}

.nothing-found {
  position: absolute;
  inset-inline: 0;
  top: var(--size-40);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--size-12);
  color: var(--muted);
  z-index: 1;
}

.nothing-found b {
  font-size: var(--fs-base);
  color: var(--text);
  font-weight: var(--fw-semibold);
}

.nothing-found button {
  font: inherit;
  padding: var(--size-4) var(--size-12);
  border: var(--stroke-1) solid var(--line-strong);
  border-radius: var(--radius-xs);
  background: var(--surface);
  cursor: pointer;
}

.row.skeleton {
  background: repeating-linear-gradient(
    90deg,
    var(--surface) 0 var(--size-40),
    var(--surface-2) var(--size-40) var(--size-80)
  );
}

.cell {
  display: flex;
  align-items: center;
  padding: 0 var(--size-8);
  user-select: none;
  position: relative;
  cursor: cell;
  border-inline-end: var(--stroke-1) solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.cell > span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell.r {
  justify-content: flex-end;
}

.cell.wrap {
  white-space: normal;
}

.cell.wrap > span {
  padding-block: var(--size-4);
  overflow-wrap: anywhere;
}

.cell.pinned,
.head-cell.pinned {
  position: sticky;
  z-index: 1;
  background: var(--surface);
  border-inline-end: var(--stroke-1) solid var(--line-strong);
}

.head-cell.pinned {
  z-index: 4;
  background: var(--head);
}

.row.dirty .cell.pinned {
  background-image: linear-gradient(var(--dirty), var(--dirty));
}

.cell.frozen {
  background: var(--frozen);
  color: var(--text);
}

.row.dirty .cell.frozen {
  background-image: linear-gradient(var(--dirty), var(--dirty));
}

.cell.rel {
  color: var(--link);
  cursor: pointer;
}

.cell.rel .chev {
  font-style: normal;
  margin-inline-start: var(--size-4);
  opacity: 0.7;
}

.cell.rel:hover {
  text-decoration: underline;
}

.sort-mark {
  display: inline-flex;
  align-items: baseline;
  flex: none;
  font-size: var(--fs-micro);
  font-weight: var(--fw-normal);
}

.sort-mark sub {
  font-size: var(--fs-micro);
  vertical-align: baseline;
  margin-inline-start: var(--stroke-1);
}

.gutter-num {
  transition: opacity 0.12s ease;
}

.row-open {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--size-2);
  visibility: hidden;
  opacity: 0;
  transition:
    opacity 0.12s ease,
    visibility 0.12s;
}

@media (hover: hover) {
  .row:hover .row-open {
    visibility: visible;
    opacity: 1;
  }

  .row:hover .gutter-num:has(+ .row-open) {
    opacity: 0;
  }

  .row:hover .gutter:has(.row-open) {
    background-image: linear-gradient(var(--accent-soft), var(--accent-soft));
  }

  .row:has(> .gutter:hover) > .cell {
    background-image: linear-gradient(var(--accent-soft), var(--accent-soft));
  }

  .row:hover .row-open button {
    color: light-dark(var(--accent), var(--text));
  }
}

.row-open button {
  display: grid;
  place-items: center;
  width: var(--size-24);
  height: var(--size-24);
  padding: 0;
  border: 0;
  border-radius: var(--radius-xs);
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.row-open button svg {
  width: var(--icon-md);
  height: var(--icon-md);
}

.row-open button:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.cell.hl-red {
  --hl-ground: var(--sheet-hl-red);
  --hl-ink: var(--sheet-hl-red-ink);
}

.cell.hl-amber {
  --hl-ground: var(--sheet-hl-amber);
  --hl-ink: var(--sheet-hl-amber-ink);
}

.cell.hl-green {
  --hl-ground: var(--sheet-hl-green);
  --hl-ink: var(--sheet-hl-green-ink);
}

.cell.hl-blue {
  --hl-ground: var(--sheet-hl-blue);
  --hl-ink: var(--sheet-hl-blue-ink);
}

.cell.hl-purple {
  --hl-ground: var(--sheet-hl-purple);
  --hl-ink: var(--sheet-hl-purple-ink);
}

.cell.hl-teal {
  --hl-ground: var(--sheet-hl-teal);
  --hl-ink: var(--sheet-hl-teal-ink);
}

.cell.hl-pink {
  --hl-ground: var(--sheet-hl-pink);
  --hl-ink: var(--sheet-hl-pink-ink);
}

.cell.hl {
  background-image: linear-gradient(var(--hl-ground), var(--hl-ground));
  color: var(--hl-ink);
}

.sheet-tag {
  display: inline-block;
  margin-inline-end: var(--size-4);
  padding: 0 var(--size-6);
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: var(--fs-sm);
  white-space: nowrap;
}

.sheet-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--size-2);
}

.sheet-pill button {
  display: inline-flex;
  padding: var(--size-2);
  border: 0;
  border-radius: var(--radius-xs);
  background: none;
  color: inherit;
  cursor: pointer;
}

.sheet-pill button:hover {
  background: var(--surface-2);
}

.sheet-tag-red {
  background: var(--sheet-hl-red);
  color: var(--sheet-hl-red-ink);
}

.sheet-tag-amber {
  background: var(--sheet-hl-amber);
  color: var(--sheet-hl-amber-ink);
}

.sheet-tag-green {
  background: var(--sheet-hl-green);
  color: var(--sheet-hl-green-ink);
}

.sheet-tag-blue {
  background: var(--sheet-hl-blue);
  color: var(--sheet-hl-blue-ink);
}

.sheet-tag-purple {
  background: var(--sheet-hl-purple);
  color: var(--sheet-hl-purple-ink);
}

.sheet-tag-teal {
  background: var(--sheet-hl-teal);
  color: var(--sheet-hl-teal-ink);
}

.sheet-tag-pink {
  background: var(--sheet-hl-pink);
  color: var(--sheet-hl-pink-ink);
}

.row.dirty .cell.hl {
  background-image:
    linear-gradient(var(--dirty), var(--dirty)), linear-gradient(var(--hl-ground), var(--hl-ground));
}

.cell.in-sel {
  background-image: linear-gradient(var(--accent-soft), var(--accent-soft));
}

.cell.in-sel.hl {
  background-image:
    linear-gradient(var(--accent-soft), var(--accent-soft)),
    linear-gradient(var(--hl-ground), var(--hl-ground));
}

.cell.changed {
  box-shadow: inset 0 0 0 var(--stroke-1) var(--warn);
}

.cell.bad {
  background-image: linear-gradient(var(--bad-soft), var(--bad-soft));
  color: var(--bad);
  box-shadow: inset 0 0 0 var(--stroke-1) var(--bad);
}

.cell.cursor {
  box-shadow: inset 0 0 0 var(--stroke-2) var(--accent);
}

.cell.in-fill,
.cell.in-copy {
  outline: var(--stroke-1) dashed var(--accent);
  outline-offset: calc(var(--stroke-2) * -1);
}

.fill-handle {
  position: absolute;
  inset-inline-end: 0;
  bottom: 0;
  width: var(--size-8);
  height: var(--size-8);
  background: var(--accent);
  box-shadow: 0 0 0 var(--stroke-1) var(--surface);
  cursor: crosshair;
}

.viewport.filling .cell,
.viewport.filling .fill-handle {
  cursor: crosshair;
}

.editor {
  user-select: text;
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  color: inherit;
  padding: 0;
}

.editor:focus-visible {
  outline: none;
}

.cell.r .editor {
  text-align: end;
}

.status {
  display: flex;
  align-items: center;
  gap: var(--size-16);
  padding: var(--size-6) var(--size-12);
  background:
    linear-gradient(to right, var(--head) 60%, transparent) 0 0 / var(--size-28) 100% no-repeat
      local,
    linear-gradient(to left, var(--head) 60%, transparent) 100% 0 / var(--size-28) 100% no-repeat
      local,
    radial-gradient(farthest-side at 0 50%, var(--scroll-edge), transparent) 0 0 / var(--size-12)
      100% no-repeat,
    radial-gradient(farthest-side at 100% 50%, var(--scroll-edge), transparent) 100% 0 /
      var(--size-12) 100% no-repeat,
    var(--head);
  border-top: var(--stroke-1) solid var(--line-strong);
  font-size: var(--fs-sm);
  min-height: var(--size-32);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.status > span {
  white-space: nowrap;
  flex: none;
}

.status .stats {
  display: flex;
  align-items: center;
  gap: var(--size-14);
  margin-inline-start: auto;
  color: var(--text);
}

.status .stats > span {
  white-space: nowrap;
}

@media (max-width: 720px) {
  .status .actions .to-first,
  .status .where,
  .status .extent,
  .status .unsaved .unsaid,
  .status .unsaved .key {
    display: none;
  }

  :is(.cell, .head-cell, .filter-cell).pinned {
    position: relative;
    inset-inline-start: auto !important;
  }
}

.status .stat i {
  font-style: normal;
  color: var(--muted);
  margin-inline-end: var(--size-4);
}

.status .filtered {
  font-style: normal;
  color: var(--accent);
}

.status .unsaved {
  position: sticky;
  inset-inline-end: calc(var(--size-12) * -1);
  display: flex;
  align-items: center;
  gap: var(--size-8);
  margin-inline: auto calc(var(--size-12) * -1);
  padding-inline: var(--size-12);
  align-self: stretch;
  background: var(--head);
  box-shadow: calc(var(--size-10) * -1) 0 var(--size-10) calc(var(--size-10) * -1)
    var(--scroll-edge);
  color: var(--warn);
}

.status .unsaved .saving {
  display: flex;
  align-items: center;
  gap: var(--size-8);
  color: var(--text);
  white-space: nowrap;
}

.status .unsaved .saving .bar {
  width: var(--size-128);
  height: var(--size-6);
  border-radius: var(--radius-xs);
  background: var(--line);
  overflow: hidden;
}

.status .unsaved .saving .bar i {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 0.2s;
}

.status button {
  font: inherit;
  padding: var(--size-2) var(--size-8);
  border: var(--stroke-1) solid var(--line-strong);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.status .actions {
  display: flex;
  align-items: center;
  gap: var(--size-6);
}

.status .actions button {
  display: grid;
  place-items: center;
  min-width: var(--size-24);
  min-height: var(--size-24);
  padding: var(--size-2);
}

.status .actions svg {
  width: var(--icon-md);
  height: var(--icon-md);
}

.status .confirm {
  display: flex;
  align-items: center;
  gap: var(--size-8);
  margin-inline-start: auto;
  color: var(--bad);
}

.status .confirm b {
  font-weight: var(--fw-semibold);
}

.status button.danger {
  border-color: var(--bad);
  color: var(--bad);
}

.status button:disabled {
  opacity: 0.6;
  cursor: default;
}

.sheet-pick {
  position: fixed;
  z-index: 61;
  overflow-y: auto;
  padding: var(--size-4);
  border: var(--stroke-1) solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  max-width: min(var(--size-440), 90vw);
}

.sheet-pick-item {
  display: block;
  width: 100%;
  height: var(--size-32);
  padding-inline: var(--size-8);
  border: 0;
  border-radius: var(--radius-xs);
  background: none;
  color: var(--text);
  font: inherit;
  text-align: start;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.sheet-pick-item.on {
  background: var(--accent-soft);
  color: var(--accent);
}

.add-row {
  position: absolute;
  inset-inline: 0;
  display: flex;
  align-items: center;
  padding-inline-start: var(--size-12);
  border: none;
  background: none;
  cursor: pointer;
  font: inherit;
  font-size: var(--fs-sm);
  color: var(--muted);
  text-align: start;
}

.add-row-label {
  position: sticky;
  inset-inline-start: var(--size-12);
  display: flex;
  align-items: center;
  gap: var(--size-6);
  background: var(--bg);
}

.add-row:hover {
  background: var(--head);
  color: var(--text);
}

.add-row:hover .add-row-label {
  background: var(--head);
}

.sheet-loading {
  position: absolute;
  inset-inline: 0;
  top: var(--size-56);
  z-index: 3;
  height: 0;
  background: var(--surface);
  pointer-events: none;
}

.sheet-loading-bar {
  position: absolute;
  inset-inline: 0;
  top: 0;
  height: var(--size-2);
  background-image: linear-gradient(90deg, var(--accent), var(--accent));
  background-size: 30% 100%;
  background-repeat: no-repeat;
  animation: sheet-reading 1.2s ease-in-out infinite;
}

@keyframes sheet-reading {
  0% {
    background-position: -50% 0;
  }
  100% {
    background-position: 150% 0;
  }
}

.sheet-loading-label {
  position: absolute;
  width: var(--stroke-1);
  height: var(--stroke-1);
  clip-path: inset(50%);
  white-space: nowrap;
}

.rows.stale {
  opacity: 0.5;
}
