# Screenshot Capture Tool

## Objective

Let people capture what they are looking at, mark it up, and attach it to a report.

An in-app capture control that produces an annotated image of the current screen and attaches it to a report or message.

## 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. Lead with the flow the user sees: a capture control, a still image they can draw on, and a send. Offer a small fixed set of markup tools — rectangle, arrow, freehand, and a solid block for hiding something — and nothing more.
2. Redact before you store. Password fields, payment inputs, and any element the app already marks as sensitive must be painted over in the captured bitmap itself, not merely hidden by a layer the recipient can peel back.
3. Attach the context an image cannot carry on its own: the page URL, the viewport size, the browser and platform, and the identifier of the signed-in user. A screenshot without those is a support ticket that needs three follow-up questions.
4. Reuse the app's existing file upload and attachment handling — including its size limits, storage location, access rules, and malware scanning — rather than adding a second upload path for images. If an Attachment Gallery already exists, captures appear there like any other attachment.
5. Do not attempt a pixel-perfect capture of arbitrary third-party embeds and cross-origin frames. Capture what you can, mark the area that could not be read, and say so in the UI instead of shipping a silently blank rectangle.

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

- Password, card number, and other sensitive fields must be masked in the stored image before it leaves the browser. A capture that reveals a customer's card details is worse than no capture at all.
- Screen capture permission can be refused at the start or revoked mid-session by the operating system. Detect both, keep the report form and everything already typed into it, and let the user continue without an image.
- Content below the fold and inside scrolling panes is routinely the part that matters. Either stitch the full scrollable region or state plainly that only the visible viewport was captured, so nobody assumes the missing part was fine.
- A raw capture from a high-density display is enormous. Downscale and compress on the client before upload, enforce the size ceiling on the server as well, and reject rather than truncate anything over it.
- Record the page URL and viewport dimensions alongside the image, since the same screen looks different at different widths and the report is useless without knowing which one was seen.
- A capture interrupted part way — the tab closed, the network dropped, the user cancelled — must leave no orphaned half-written file in storage.
- Markup must be undoable step by step, and the user must be able to start the annotation over without recapturing the screen.
- Screenshots often contain other people's personal data. Apply the same retention window and read permissions as the report they are attached to, and delete them when the report is deleted.

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

- [ ] A user can capture the current screen, annotate it, and attach it to a report without leaving the page.
- [ ] Sensitive fields are painted out of the stored bitmap and cannot be recovered from the file.
- [ ] Every capture carries the page URL, viewport size, and client details.
- [ ] Denied or revoked capture permission leaves the report usable and the typed content intact.
- [ ] Captures land in the attachment surface users already know, under the same access rules as files they attached by hand.
- [ ] Oversized captures are compressed client-side and rejected server-side above the limit.
- [ ] Deleting a report deletes its captures.
- [ ] 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.
