# Container Width System

## Objective

Give pages a few defined widths instead of a different max-width on every screen.

A small set of named page widths — narrow, standard, wide, and full-bleed — applied consistently across the app.

## 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. Measure the max-width used on every top-level page and group them. Settings forms, prose, dashboards, and data tables usually want three or four distinct widths between them, not the eleven the codebase currently has.
2. Pick each width from the content it holds. A reading column is bounded by comfortable line length, a settings form by field width, and a table by the number of columns that must stay visible.
3. Make horizontal page padding part of the container rather than something each page adds, so content never touches the viewport edge on a narrow screen even at the widest setting.
4. Give full-bleed sections a defined way to escape the container and return, so a hero band or a full-width table can span the viewport while the text above and below stays aligned to the same column.
5. Do not force data-heavy screens into the reading width. Wide tables, canvases, and dashboards need the viewport, and constraining them to a prose column trades a real workflow for a typographic preference.

## 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

- Horizontal padding must survive at every width. A container that only sets max-width will let text run into the screen edge on small viewports, where the constraint is padding rather than the maximum.
- Some sections legitimately need to break out — full-bleed images, sticky table headers, edge-to-edge banners — so there must be a supported escape rather than each page reaching for negative margins.
- Modals, drawers, and side panels need widths drawn from the same set, or a dialog containing the same form as a page will render it at a different measure and look like a different product.
- Article and documentation screens should stay narrow while data screens go wide, and a single global maximum cannot serve both, so the width belongs to the page rather than to the layout shell.
- Nested containers silently compound their padding, so a container placed inside another must detect that and contribute nothing rather than doubling the inset.
- Breakpoint values used to switch between widths come from Breakpoint Token System, and column counts and gutters inside a container come from Responsive Grid Tokens; this feature owns the outer boundary only.
- A width expressed only in pixels will not respond to the user's root font size, which matters on screens that are mostly text.

## 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

- [ ] The app defines no more than five named page widths and every page uses one of them.
- [ ] No page declares its own max-width outside the system.
- [ ] Content keeps its horizontal padding at every viewport size and never touches the screen edge.
- [ ] There is a supported full-bleed escape that returns to the same alignment afterwards.
- [ ] Modals, drawers, and panels draw their widths from the same set as pages.
- [ ] Data-heavy screens are not constrained to the reading width.
- [ ] Nested containers do not double their padding.
- [ ] 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.
