# Shareable Deep Links

## Objective

Let people copy a URL that reopens exactly what they were looking at.

Encode the current record, tab, filter set, and selection in the URL so a copied link restores the same view for whoever opens it.

## 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. Audit the app for view state that currently lives only in memory: active tab, applied filters, sort order, expanded rows, selected items, scroll target.
2. Move that state into the URL and make the app read it back on load, so a pasted link reconstructs the view rather than dumping the user on a default screen.
3. Add a visible copy-link affordance on every view that supports it, and confirm the copy so the user knows it worked.
4. Key the URL on stable identifiers, never on display names or labels — a renamed project must not break every link anyone has shared.
5. Do NOT put draft text, unsaved form input, search history, or anything with personal data into the URL. URLs end up in logs, referrers, and chat clients.

## 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 link to a deleted or archived record must say so plainly and offer a way back to the list, not throw a 404 with no context.
- A recipient without permission must get an access message that does not disclose the record's contents or name.
- Complex filter state can outgrow practical URL length. Compress it, or persist the view server-side and put a short key in the URL.
- Old links must keep working after a filter is renamed or removed. Ignore unknown parameters instead of erroring.
- Updating the URL as the user changes filters must use replace, not push, or the back button becomes a filter-by-filter rewind.
- A link opened by a signed-out user must survive the sign-in round trip and land on the intended view.

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

- [ ] Copying a link and opening it in a fresh session reproduces the same tab, filters, sort, and selection.
- [ ] Links are built from stable IDs and survive renames.
- [ ] No draft content or personal data appears in any URL.
- [ ] Deleted, archived, and forbidden targets each have their own message and a next action.
- [ ] Unknown or stale URL parameters are ignored rather than fatal.
- [ ] Filter changes do not flood the browser history.
- [ ] 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.
