# Voice Notes

## Objective

Say it instead of typing it, and attach the recording where the conversation is.

In-app recording of short audio notes attached to a record, comment, 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. Add recording to the places where people already leave text, most likely alongside Comments and Mentions, so a voice note is another kind of comment rather than a separate feed nobody checks.
2. Store the recording through the app's existing file upload path so a voice note inherits the same retention and access rules as any other attachment on the record, and disappears with the record when it is deleted.
3. Show a live duration and a simple level meter while recording, and let the user review and discard before it is sent. Nobody should be committed to a recording the instant they stop.
4. Run the recording through the app's existing Voice Transcription so every note carries a searchable text version alongside the audio.
5. Do not start capturing until the user explicitly presses record. A microphone that opens on page load, even without saving, is the kind of thing that ends a customer relationship.

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

- Microphone permission may be denied at the browser or operating system level, or revoked mid-session. Detect it and explain how to re-enable it rather than showing a record button that does nothing.
- Enforce a maximum recording length and warn the speaker as the cutoff approaches, then stop cleanly and keep what was captured instead of discarding the take.
- A dropped connection mid-recording must not lose the audio. Buffer locally and upload on reconnect, and tell the user the note is pending rather than pretending it sent.
- Browsers record in different container and codec combinations. Normalise on the server to one format every target browser can play, and keep the original until the conversion succeeds.
- Recipients who cannot play audio, are in a meeting, or use a screen reader need the transcript shown alongside the player, not hidden behind a second click.
- Reserve the player's dimensions in the layout so a list of comments does not jump as audio elements load.
- Voice notes are user-generated content and need the same deletion, retention, and access rules as any other attachment, including removal when the parent record is deleted.
- Recording while another tab is already using the microphone, or while the device is on a call, must fail with a clear message rather than producing a silent file.

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

- [ ] Users can record, review, discard, and attach an audio note from the places they already comment.
- [ ] Recording only begins on an explicit user action.
- [ ] Denied or revoked microphone permission produces a clear explanation and recovery path.
- [ ] A maximum length is enforced with a warning before the cutoff, and the captured audio is kept.
- [ ] Audio is normalised server-side and plays in every supported browser.
- [ ] Each note carries a transcript displayed alongside the player.
- [ ] Notes follow the app's existing storage, retention, and access rules.
- [ ] 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.
