# W1-FE-1 — visit-shell bug fixes + small layout-engine fixes (FE)

Read _COMMON.md first. Review rows: A bugs 1-3 + #46; B bugs B1-B6, #11, #13a, #62, #76; D bug 1. You own visit-shell.component.{ts,html,scss} in this wave.

FE root `VS` = /home/moonui3/public_html/moon-erp/src/app/features/clinic/visit-shell/.

## Tasks
1. **Insurance (B1).** BE (W1-BE-A, in parallel) will return `summary.insurance = {company_name, contract_id, contract_name, coverage_percent}` or null. Update the TS type `ClinicPatientInsurance` (features/clinic/services/clinic-patient.service.ts ~69) and make BOTH headers read it robustly (also accept a legacy array `[{contract_name}]` → `[0].contract_name`): `VS/visit-header.component.ts:~105` and the classic `features/clinic/shared/clinic-patient-header/clinic-patient-header.component.html:~97`. Put the normalisation in ONE shared helper (e.g. in clinic-patient.service.ts) used by both.
2. **Latest results (B2).** `VS/visit-start-rail.component.ts:~53-65`: BE will send `flag`, `unit`, `date`. Colour red for H/L/HH/LL/A (critical HH/LL stronger), green only when flag is null AND a value exists; show unit and a small date tag. Current meds (row 29): render the `sentence` under the drug name.
3. **Lost note (B5).** `cards/visit-complaint-card.component.ts` (debounce 800 ms) and `cards/visit-exam-card.component.ts` (~133): flush the pending save on destroy, and expose a `flush(): Promise<void>` the shell awaits BEFORE signing (use VisitShellBus — e.g. a `beforeSign` hook registry the cards register into, awaited by the sign flow in visit-shell.component.ts ~840). Signing must not lock the card before the flush resolves.
4. **GYN inpatient duplicates (D bug 1).** Add `remove?: string[]` to VisitContext (visit-layout.model.ts) and support it in resolve-layout.ts (dropped, tagged in `dropped`). In contexts/inpatient.context.ts: replace both `followup` and `gyn_followup` by `inp_discharge`, and remove `gyn_discharge` (inp_discharge is the admission discharge; mention the GYN discharge summary stays reachable from the summary-generator card). Make sure two ids replaced to the same target don't produce two inp_discharge cards. Update resolve-layout.check.ts / inpatient.context.check.ts with cases.
5. **Numbering (B6).** visit-summary-rail: number lines with the card's station index (same as card heads); non-station lines show the card icon, no number.
6. **Insured diagnosis (B4, decision: force the card).** When the encounter is insured (`encounter.is_insured`), `diagnosis` behaves as required: resolveLayout re-inserts it if a client/doctor layout removed it (pass an `insured` flag in the resolve input; tag `from:'required'`), and it cannot be hidden in edit mode. Then the DX_NOT_ON_SCREEN dead end disappears. Keep the hard block only for "no coded primary diagnosis" and align with the BE rule (B3): primary must have an ICD `code`. Finish-panel title: hard blocks listed separately under a «لازم قبل التوقيع» heading, soft warnings under the existing «لا تمنع التوقيع» heading (i18n).
7. **Layout editor fixes (A bugs 1-3).** Editor count = whole draft card count (not the open tab). `layout-edit.ts:~74-84` ↑↓ swaps only with the neighbour in the same column AND the same tab. `specialties/dental.cards.ts:~23` dent_workspace `required: true`.
8. **Context cards while editing (#46).** In edit mode on an inpatient/emergency visit, show the context cards as read-only dimmed placeholders (title + «سياق الإقامة — مش بيتحفظ في الشكل») in their resolved position instead of hiding them. Persistence stays context-free.
9. **Summaries refresh (#62, #11).** Bind `(saved)` of app-clinic-prescription (and the lab/rad/vitals save outputs if they exist) to refresh that card's summary line + the live summary rail immediately; trigger the «حفظ تلقائي» pulse from every card save, not only complaint.
10. **Flow-state wrap (#13a).** After the last station is done, don't wrap to the first undone; leave none active and focus the finish button.
11. **Shell route gate (#76).** When `clinic.visit_shell` is off, opening /clinic/encounter/:id/shell redirects to the classic consultation screen (keep `?force=1` as an escape for admins/testing, doc it in a comment).
12. **Signer (#45).** If the encounter payload has `signed_by_name` (W1-BE-A adds it), show «موقّعة من <name> · <time>» in the locked bar.

Run `npx ng build --base-href /app/` at the end (if it fails only because of a file another agent is editing, report it). Do NOT deploy.

## Out of scope
Picker/lookup files, vitals panel, nutrition board, settings UI (later waves).
