# Frozen Table Columns

## Objective

Keep key identifiers visible while users scroll across wide data tables.

Sticky leading or trailing columns that stay in place during horizontal scroll on a wide table.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Compute each frozen column's offset from the measured widths of the columns before it, not from hardcoded numbers. One content change and fixed offsets are wrong.
2. Recompute offsets when column widths change — on resize, on column show or hide, on font load, and after data changes cell widths.
3. Define one explicit layer order for frozen cells, frozen headers, the sticky header row, row hover and selection states, and any menu opened from a frozen cell. Ad-hoc z-index values are where this feature usually breaks.
4. Keep header and body cell widths in sync from a single source of truth; two independently sized tables will never stay aligned.
5. Do not freeze more than a couple of columns, and disable freezing entirely when the frozen set would exceed roughly half the viewport width — the user is left with no scrollable area.
6. The small-screen strategy — which columns survive and the collapse to stacked cards — is owned by Responsive Data Tables; defer to it rather than defining a second mobile behaviour.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- A shadow or border marking the frozen boundary must appear only while there is content scrolled underneath it.
- Virtualized rows must apply the same offsets as rendered rows, including rows recycled during fast scrolling.
- Row selection and hover backgrounds must cover frozen cells too, or the frozen column looks detached from its row.
- Menus and tooltips opened from a frozen cell must escape the scroll container rather than being clipped by it.
- Right-to-left layouts freeze from the opposite edge — do not assume the left.
- Keyboard navigation into a non-frozen cell must scroll it into view without hiding it behind a frozen column.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] Multiple frozen columns align correctly at every scroll position.
- [ ] Offsets recompute on resize, column visibility changes, and font load.
- [ ] One documented layer order covers frozen cells, headers, hover, selection, and menus.
- [ ] Header and body widths stay synchronized during resizing.
- [ ] Freezing disables itself when it would leave too little scrollable width.
- [ ] Mobile behaviour is delegated to Responsive Data Tables.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
