.fs-spreadsheet {
  --fs-spreadsheet-initial-zoom: 0.8;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  background: var(--fs-color-surface);
  border: 1px solid var(--fs-color-border);
  border-radius: var(--fs-radius-lg);
  box-shadow: var(--fs-shadow-sm);
}

.fs-spreadsheet__viewport {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  max-height: min(76vh, 900px);
  padding-bottom: var(--fs-space-3);
  overflow: auto;
  background: var(--fs-color-surface);
  overscroll-behavior-x: contain;
  overscroll-behavior-y: auto;
}

.fs-spreadsheet__toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-height: 46px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--fs-color-border-subtle);
  background: var(--fs-color-surface-subtle);
}

.fs-spreadsheet__toolbar > span,
.fs-spreadsheet__zoom-label {
  color: var(--fs-color-text-secondary);
  font-size: 11px;
}

.fs-spreadsheet__zoom-label {
  min-width: 42px;
  text-align: center;
}

.fs-spreadsheet__zoom-label-mobile {
  display: none;
}

.fs-spreadsheet__zoom-target {
  display: block;
  width: fit-content;
}

.fs-spreadsheet__zoom-content {
  display: block;
  width: fit-content;
  zoom: var(--fs-spreadsheet-initial-zoom);
}

.fs-spreadsheet__zoom-target.is-compact-transform .fs-spreadsheet__zoom-content {
  transform-origin: left top;
}

.fs-spreadsheet__table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}

.fs-spreadsheet__table th,
.fs-spreadsheet__table td {
  min-width: 112px;
  max-width: 240px;
  padding: 9px 10px;
  overflow: hidden;
  border-right: 1px solid var(--fs-color-border-subtle);
  border-bottom: 1px solid var(--fs-color-border-subtle);
  background: var(--fs-color-surface);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fs-spreadsheet__table.is-sheet {
  min-width: 0;
  table-layout: fixed;
}

.fs-spreadsheet__table.is-sheet td {
  box-sizing: border-box;
  min-width: 0;
  max-width: none;
  overflow: visible;
  padding: 3px 5px;
  text-overflow: clip;
  white-space: nowrap;
}

/*
 * Excel lets an unwrapped value paint through following empty cells without
 * changing the row height. Keep populated cells above blank neighbours so the
 * browser reproduces that visual overflow; an inline white-space:pre-wrap from
 * the workbook still wins for cells whose Excel style explicitly enables wrap.
 */
.fs-spreadsheet__table.is-sheet td:not(.is-blank) {
  position: relative;
  z-index: 1;
}

.fs-spreadsheet__table.is-sheet td.is-blank {
  position: relative;
  z-index: 0;
}

.fs-spreadsheet__table thead th {
  position: sticky;
  z-index: 2;
  top: 0;
  background: var(--fs-color-surface-subtle);
  color: var(--fs-color-primary-hover);
  font-size: var(--fs-text-xs);
  letter-spacing: 0.025em;
  text-transform: uppercase;
}

.fs-spreadsheet__table.is-table tbody tr:hover td,
.fs-spreadsheet__table.is-table tbody tr:hover th {
  background: var(--fs-color-surface-hover);
}

.fs-spreadsheet__table tbody tr.is-selected td,
.fs-spreadsheet__table tbody tr.is-selected th {
  background-color: var(--fs-color-selected) !important;
}

.fs-spreadsheet__table.is-table .is-number {
  font-variant-numeric: tabular-nums;
  text-align: right !important;
}

.fs-spreadsheet__table .is-date,
.fs-spreadsheet__table .is-boolean {
  font-variant-numeric: tabular-nums;
}

.fs-spreadsheet__table .is-error {
  color: var(--fs-color-danger);
  font-weight: 600;
}

.fs-spreadsheet__table .is-blank {
  color: var(--fs-color-text-secondary);
}

.fs-spreadsheet__pagination {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fs-spreadsheet__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  color: var(--fs-color-text-secondary);
  font-size: 11px;
}

.fs-spreadsheet__pagination > span {
  min-width: 48px;
  text-align: center;
}

@media (max-width: 1199px) {
  .fs-spreadsheet:has(.fs-spreadsheet__viewport) {
    display: flex;
    flex-direction: column;
    height: 100dvh;
  }

  .fs-spreadsheet__viewport {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    padding-bottom: calc(
      var(--fs-mobile-bottombar-height) + env(safe-area-inset-bottom) + var(--fs-space-3)
    );
  }
}

@media (max-width: 760px) {
  .fs-spreadsheet {
    --fs-spreadsheet-initial-zoom: 0.5;
  }

  .fs-spreadsheet__zoom-label-desktop {
    display: none;
  }

  .fs-spreadsheet__zoom-label-mobile {
    display: inline;
  }

  .fs-spreadsheet__footer {
    align-items: stretch;
    flex-direction: column;
  }

  .fs-spreadsheet__pagination {
    justify-content: space-between;
  }
}
