-- Fix: items insert was blocked when invoice status = 'submitted' at creation time.
-- Allow insert on own invoices regardless of status (ownership check is sufficient).
drop policy if exists "Sub insert draft invoice items" on public.subcontractor_invoice_items;

create policy "Sub insert own invoice items" on public.subcontractor_invoice_items
  for insert with check (
    invoice_id in (select id from public.subcontractor_invoices where profile_id = auth.uid())
  );
