// ESIGN PLATFORM — mock data

window.ESIGN_DATA = (() => {

  const envelopes = [
    {
      id: 'ENV-001', subject: 'Settlement Agreement — Redstone v. Meridian Capital',
      matter: 'Redstone v. Meridian', matterId: 'M-001',
      status: 'Completed', sentAt: '2026-04-15T09:12:00Z', completedAt: '2026-04-16T14:22:00Z',
      expiresAt: null, template: 'Settlement Agreement', sender: 'M. Kirkland',
      turnaround: '1d 5h', pages: 18, fields: 12,
      recipients: [
        { id: 'R-1', name: 'David Ashworth', email: 'd.ashworth@meridian.com', role: 'Signer', order: 1, status: 'Signed', signedAt: '2026-04-15T14:08:00Z', ip: '192.168.1.101', device: 'Chrome / macOS' },
        { id: 'R-2', name: 'Sarah Redstone', email: 's.redstone@counsel.com', role: 'Signer', order: 2, status: 'Signed', signedAt: '2026-04-16T14:22:00Z', ip: '10.0.0.44', device: 'Safari / iOS' },
        { id: 'R-3', name: 'M. Kirkland', email: 'm.kirkland@arbiter.law', role: 'CC', order: null, status: 'Delivered', signedAt: null, ip: null, device: null },
      ],
      auditTrail: [
        { ts: '2026-04-15T09:12:00Z', event: 'Envelope created', actor: 'M. Kirkland', detail: 'Created from Settlement Agreement template' },
        { ts: '2026-04-15T09:14:00Z', event: 'Sent', actor: 'M. Kirkland', detail: 'Sent to 2 signers' },
        { ts: '2026-04-15T13:55:00Z', event: 'Viewed', actor: 'David Ashworth', detail: 'Opened via email link' },
        { ts: '2026-04-15T14:08:00Z', event: 'Signed', actor: 'David Ashworth', detail: 'Completed 6 of 6 fields · IP 192.168.1.101' },
        { ts: '2026-04-16T09:01:00Z', event: 'Viewed', actor: 'Sarah Redstone', detail: 'Opened via email link' },
        { ts: '2026-04-16T14:22:00Z', event: 'Signed', actor: 'Sarah Redstone', detail: 'Completed 6 of 6 fields · IP 10.0.0.44' },
        { ts: '2026-04-16T14:22:05Z', event: 'Completed', actor: 'System', detail: 'All signers complete · Certificate generated' },
      ],
    },
    {
      id: 'ENV-002', subject: 'Engagement Letter — Harmon Family Trust',
      matter: 'Harmon Family Trust', matterId: 'M-002',
      status: 'Waiting', sentAt: '2026-04-18T11:30:00Z', completedAt: null,
      expiresAt: '2026-05-18T11:30:00Z', template: 'Engagement Letter', sender: 'S. Chen',
      turnaround: null, pages: 6, fields: 8,
      recipients: [
        { id: 'R-4', name: 'Gerald Harmon', email: 'g.harmon@hfamilytrust.com', role: 'Signer', order: 1, status: 'Signed', signedAt: '2026-04-18T16:44:00Z', ip: '74.125.0.1', device: 'Chrome / Windows' },
        { id: 'R-5', name: 'Patricia Harmon', email: 'p.harmon@hfamilytrust.com', role: 'Signer', order: 2, status: 'Viewed', signedAt: null, ip: '74.125.0.1', device: 'Safari / iPad' },
      ],
      auditTrail: [
        { ts: '2026-04-18T11:30:00Z', event: 'Sent', actor: 'S. Chen', detail: 'Sent to 2 signers in order' },
        { ts: '2026-04-18T15:12:00Z', event: 'Viewed', actor: 'Gerald Harmon', detail: 'Opened via email link' },
        { ts: '2026-04-18T16:44:00Z', event: 'Signed', actor: 'Gerald Harmon', detail: 'Completed 4 of 4 fields' },
        { ts: '2026-04-19T08:30:00Z', event: 'Viewed', actor: 'Patricia Harmon', detail: 'Opened via email link · Pending signature' },
      ],
    },
    {
      id: 'ENV-003', subject: 'NDA — Vertex Biomedical (Confidential)',
      matter: 'Vertex Biomedical', matterId: 'M-003',
      status: 'Sent', sentAt: '2026-04-20T14:05:00Z', completedAt: null,
      expiresAt: '2026-05-20T14:05:00Z', template: 'Mutual NDA', sender: 'M. Kirkland',
      turnaround: null, pages: 4, fields: 6,
      recipients: [
        { id: 'R-6', name: 'James Wyatt', email: 'j.wyatt@vertexbio.com', role: 'Signer', order: 1, status: 'Sent', signedAt: null, ip: null, device: null },
        { id: 'R-7', name: 'Linda Tran', email: 'l.tran@vertexbio.com', role: 'Signer', order: 2, status: 'Pending', signedAt: null, ip: null, device: null },
      ],
      auditTrail: [
        { ts: '2026-04-20T14:05:00Z', event: 'Sent', actor: 'M. Kirkland', detail: 'Sent to 2 signers in order' },
      ],
    },
    {
      id: 'ENV-004', subject: 'Expert Witness Retainer — Dr. Chen Wei',
      matter: 'Kellerman v. Novaris', matterId: 'M-004',
      status: 'Completed', sentAt: '2026-04-10T08:00:00Z', completedAt: '2026-04-10T09:45:00Z',
      expiresAt: null, template: 'Expert Retainer', sender: 'R. Torres',
      turnaround: '1h 45m', pages: 3, fields: 5,
      recipients: [
        { id: 'R-8', name: 'Dr. Chen Wei', email: 'c.wei@expertwitness.io', role: 'Signer', order: 1, status: 'Signed', signedAt: '2026-04-10T09:45:00Z', ip: '203.0.113.5', device: 'Chrome / macOS' },
      ],
      auditTrail: [
        { ts: '2026-04-10T08:00:00Z', event: 'Sent', actor: 'R. Torres', detail: 'Sent to 1 signer' },
        { ts: '2026-04-10T09:40:00Z', event: 'Viewed', actor: 'Dr. Chen Wei', detail: 'Opened via email link' },
        { ts: '2026-04-10T09:45:00Z', event: 'Signed', actor: 'Dr. Chen Wei', detail: 'Completed 5 fields' },
        { ts: '2026-04-10T09:45:02Z', event: 'Completed', actor: 'System', detail: 'Certificate generated · PKI seal applied' },
      ],
    },
    {
      id: 'ENV-005', subject: 'Deposition Transcript Stipulation',
      matter: 'Redstone v. Meridian', matterId: 'M-001',
      status: 'Declined', sentAt: '2026-04-12T10:00:00Z', completedAt: null,
      expiresAt: null, template: null, sender: 'M. Kirkland',
      turnaround: null, pages: 2, fields: 4,
      recipients: [
        { id: 'R-9', name: 'David Ashworth', email: 'd.ashworth@meridian.com', role: 'Signer', order: 1, status: 'Declined', signedAt: null, ip: '192.168.1.101', device: 'Chrome / macOS' },
      ],
      auditTrail: [
        { ts: '2026-04-12T10:00:00Z', event: 'Sent', actor: 'M. Kirkland', detail: 'Sent to 1 signer' },
        { ts: '2026-04-12T11:30:00Z', event: 'Viewed', actor: 'David Ashworth', detail: 'Opened via email link' },
        { ts: '2026-04-12T11:35:00Z', event: 'Declined', actor: 'David Ashworth', detail: 'Reason: "Requires revision to paragraph 3"' },
      ],
    },
    {
      id: 'ENV-006', subject: 'Fee Agreement — Okafor Estate',
      matter: 'Okafor Estate', matterId: 'M-005',
      status: 'Draft', sentAt: null, completedAt: null,
      expiresAt: null, template: 'Fee Agreement', sender: 'A. Williams',
      turnaround: null, pages: 5, fields: 9,
      recipients: [
        { id: 'R-10', name: 'Emeka Okafor', email: 'e.okafor@gmail.com', role: 'Signer', order: 1, status: 'Pending', signedAt: null, ip: null, device: null },
      ],
      auditTrail: [],
    },
    {
      id: 'ENV-007', subject: 'Joint Defense Agreement — Vargas Cartel Matter',
      matter: 'United States v. Vargas', matterId: 'M-006',
      status: 'Completed', sentAt: '2026-04-05T07:00:00Z', completedAt: '2026-04-07T16:00:00Z',
      expiresAt: null, template: null, sender: 'M. Kirkland',
      turnaround: '2d 9h', pages: 12, fields: 18,
      recipients: [
        { id: 'R-11', name: 'Thomas Reilly', email: 't.reilly@reillylaw.com', role: 'Signer', order: 1, status: 'Signed', signedAt: '2026-04-06T10:00:00Z', ip: '74.0.0.1', device: 'Firefox / Windows' },
        { id: 'R-12', name: 'Nina Vasquez', email: 'n.vasquez@vlaw.com', role: 'Signer', order: 2, status: 'Signed', signedAt: '2026-04-07T16:00:00Z', ip: '68.0.0.5', device: 'Safari / macOS' },
        { id: 'R-13', name: 'M. Kirkland', email: 'm.kirkland@arbiter.law', role: 'Signer', order: 3, status: 'Signed', signedAt: '2026-04-05T08:00:00Z', ip: '10.0.0.1', device: 'Chrome / macOS' },
      ],
      auditTrail: [],
    },
    {
      id: 'ENV-008', subject: 'Litigation Hold Notice — Pinnacle Tech',
      matter: 'Pinnacle Tech IP', matterId: 'M-007',
      status: 'Expired', sentAt: '2026-03-01T09:00:00Z', completedAt: null,
      expiresAt: '2026-04-01T09:00:00Z', template: 'Litigation Hold', sender: 'S. Chen',
      turnaround: null, pages: 3, fields: 2,
      recipients: [
        { id: 'R-14', name: 'Kevin Blake', email: 'k.blake@pinnacletech.io', role: 'Signer', order: 1, status: 'Pending', signedAt: null, ip: null, device: null },
      ],
      auditTrail: [],
    },
  ];

  const templates = [
    { id: 'T-001', name: 'Settlement Agreement', category: 'Litigation', fields: 12, uses: 47, lastUsed: '2026-04-15', pages: 18, description: 'Comprehensive settlement and release agreement with mutual covenants', requiredFields: ['signature', 'date', 'initials', 'text'] },
    { id: 'T-002', name: 'Engagement Letter', category: 'Client Intake', fields: 8, uses: 124, lastUsed: '2026-04-18', pages: 6, description: 'Standard attorney-client engagement with fee structure and scope', requiredFields: ['signature', 'date', 'initials'] },
    { id: 'T-003', name: 'Mutual NDA', category: 'Agreements', fields: 6, uses: 89, lastUsed: '2026-04-20', pages: 4, description: 'Bilateral non-disclosure with IP carve-outs and 3-year term', requiredFields: ['signature', 'date'] },
    { id: 'T-004', name: 'Expert Retainer', category: 'Litigation', fields: 5, uses: 31, lastUsed: '2026-04-10', pages: 3, description: 'Expert witness retention with fee schedule and confidentiality terms', requiredFields: ['signature', 'date', 'initials'] },
    { id: 'T-005', name: 'Fee Agreement', category: 'Client Intake', fields: 9, uses: 78, lastUsed: '2026-04-19', pages: 5, description: 'Hourly and contingency fee structures with billing authorization', requiredFields: ['signature', 'date', 'checkbox', 'text'] },
    { id: 'T-006', name: 'Litigation Hold', category: 'Discovery', fields: 2, uses: 22, lastUsed: '2026-03-01', pages: 3, description: 'Legal hold notice with acknowledgment and scope definition', requiredFields: ['signature', 'date'] },
    { id: 'T-007', name: 'Co-Counsel Agreement', category: 'Agreements', fields: 10, uses: 14, lastUsed: '2026-04-07', pages: 8, description: 'Fee sharing and responsibility allocation between co-counsel', requiredFields: ['signature', 'date', 'initials', 'text'] },
    { id: 'T-008', name: 'Medical Authorization', category: 'Personal Injury', fields: 7, uses: 56, lastUsed: '2026-04-14', pages: 2, description: 'HIPAA-compliant release for medical records and information', requiredFields: ['signature', 'date', 'text'] },
    { id: 'T-009', name: 'Deposition Notice', category: 'Litigation', fields: 3, uses: 38, lastUsed: '2026-04-11', pages: 2, description: 'Notice of deposition with attendance confirmation', requiredFields: ['signature', 'date'] },
    { id: 'T-010', name: 'Joint Defense Agreement', category: 'Criminal', fields: 18, uses: 9, lastUsed: '2026-04-05', pages: 12, description: 'Multi-party joint defense with privilege preservation provisions', requiredFields: ['signature', 'date', 'initials', 'text'] },
  ];

  const inbox = envelopes.filter(e =>
    e.recipients.some(r => r.email === 'm.kirkland@arbiter.law' && r.status !== 'Signed' && r.role === 'Signer')
  ).concat([
    {
      id: 'ENV-INB-1', subject: 'Co-Counsel Engagement — Chen & Park Associates',
      matter: 'External', matterId: null, status: 'Waiting',
      sentAt: '2026-04-20T16:00:00Z', completedAt: null, expiresAt: '2026-05-20T16:00:00Z',
      template: null, sender: 'J. Park (Chen & Park Associates)',
      turnaround: null, pages: 8, fields: 6,
      recipients: [{ id: 'R-IN-1', name: 'M. Kirkland', email: 'm.kirkland@arbiter.law', role: 'Signer', order: 2, status: 'Sent', signedAt: null, ip: null, device: null }],
      auditTrail: [],
    },
    {
      id: 'ENV-INB-2', subject: 'Amended Protective Order — Pinnacle Tech IP',
      matter: 'Pinnacle Tech IP', matterId: 'M-007', status: 'Waiting',
      sentAt: '2026-04-21T08:00:00Z', completedAt: null, expiresAt: '2026-04-28T08:00:00Z',
      template: null, sender: 'Opposing Counsel (A. Robertson)',
      turnaround: null, pages: 6, fields: 4,
      recipients: [{ id: 'R-IN-2', name: 'M. Kirkland', email: 'm.kirkland@arbiter.law', role: 'Signer', order: 1, status: 'Viewed', signedAt: null, ip: null, device: null }],
      auditTrail: [],
    },
  ]);

  const bulkJobs = [
    { id: 'BLK-001', name: 'Q1 Annual Retainer Renewals', status: 'Completed', sent: 38, completed: 35, declined: 1, pending: 2, sentAt: '2026-03-15', completedAt: '2026-03-28', template: 'Engagement Letter', sender: 'M. Kirkland' },
    { id: 'BLK-002', name: 'Litigation Hold Notices — Discovery Freeze', status: 'In Progress', sent: 12, completed: 8, declined: 0, pending: 4, sentAt: '2026-04-10', completedAt: null, template: 'Litigation Hold', sender: 'S. Chen' },
    { id: 'BLK-003', name: 'Expert Witness Onboarding Q2', status: 'Draft', sent: 0, completed: 0, declined: 0, pending: 0, sentAt: null, completedAt: null, template: 'Expert Retainer', sender: 'R. Torres' },
  ];

  const contacts = [
    { id: 'C-001', name: 'David Ashworth', email: 'd.ashworth@meridian.com', org: 'Meridian Capital', envelopes: 5, lastSigned: '2026-04-16', role: 'Opposing Party' },
    { id: 'C-002', name: 'Sarah Redstone', email: 's.redstone@counsel.com', org: 'Self', envelopes: 3, lastSigned: '2026-04-16', role: 'Client' },
    { id: 'C-003', name: 'Dr. Chen Wei', email: 'c.wei@expertwitness.io', org: 'Expert Witness Group', envelopes: 4, lastSigned: '2026-04-10', role: 'Expert' },
    { id: 'C-004', name: 'Gerald Harmon', email: 'g.harmon@hfamilytrust.com', org: 'Harmon Family Trust', envelopes: 7, lastSigned: '2026-04-18', role: 'Client' },
    { id: 'C-005', name: 'James Wyatt', email: 'j.wyatt@vertexbio.com', org: 'Vertex Biomedical', envelopes: 2, lastSigned: '2026-03-10', role: 'Counterparty' },
    { id: 'C-006', name: 'Thomas Reilly', email: 't.reilly@reillylaw.com', org: 'Reilly Law', envelopes: 3, lastSigned: '2026-04-07', role: 'Co-Counsel' },
  ];

  const analytics = {
    monthly: [
      { month: 'Nov', sent: 24, completed: 21, declined: 1 },
      { month: 'Dec', sent: 18, completed: 16, declined: 0 },
      { month: 'Jan', sent: 31, completed: 28, declined: 2 },
      { month: 'Feb', sent: 27, completed: 25, declined: 1 },
      { month: 'Mar', sent: 42, completed: 39, declined: 2 },
      { month: 'Apr', sent: 29, completed: 19, declined: 1 },
    ],
    avgTurnaround: '18.4h',
    completionRate: 91,
    topTemplate: 'Engagement Letter',
    envelopesThisMonth: 29,
    completedThisMonth: 19,
    pendingNow: 6,
    declinedRate: 4,
  };

  const kpis = {
    awaitingMySig: inbox.length,
    pendingOthers: envelopes.filter(e => e.status === 'Sent' || e.status === 'Delivered' || e.status === 'Waiting').length,
    completedMonth: envelopes.filter(e => e.status === 'Completed' && e.completedAt?.startsWith('2026-04')).length,
    totalTemplates: templates.length,
    avgTurnaround: '18.4h',
    completionRate: '91%',
  };

  // ── Privilege / matter binding extensions ──────────────────────────────────
  envelopes.forEach(e => {
    const privilegeMap = {
      'M-001': 'Attorney-Client',
      'M-002': 'Work Product',
      'M-003': 'Trade Secret',
      'M-004': 'Work Product',
      'M-005': 'Attorney-Client',
      'M-006': 'Joint Defense',
      'M-007': 'Attorney-Client',
    };
    e.privilege = e.matterId ? (privilegeMap[e.matterId] || 'None') : 'External';
    e.ethicalWall = ['M-003', 'M-006'].includes(e.matterId);
    e.paymentLinked = ['ENV-002', 'ENV-006'].includes(e.id);
    e.hasRedlines = ['ENV-002', 'ENV-003'].includes(e.id);
    e.esignConsent = e.status !== 'Draft';
    e.notarized = e.id === 'ENV-002' || e.id === 'ENV-007';
    e.witnessed = e.id === 'ENV-007';
  });

  // ── Notary (RON / IPEN / Witness) ──────────────────────────────────────────
  const notarySessions = [
    {
      id: 'NOT-001', envelopeId: 'ENV-002', subject: 'Engagement Letter — Harmon Family Trust',
      type: 'RON', status: 'Scheduled', scheduledAt: '2026-04-23T15:00:00Z',
      notary: 'Rita Calloway, NNA #284117', commissionState: 'CA', commissionExpires: '2028-03-14',
      participants: [
        { name: 'Gerald Harmon', role: 'Signer', kba: 'Passed', id: 'Verified (Driver License · CA)', webcam: 'Ready' },
        { name: 'Patricia Harmon', role: 'Signer', kba: 'Pending', id: 'Not Started', webcam: 'Not Tested' },
      ],
      recording: null, journal: null, seal: null,
    },
    {
      id: 'NOT-002', envelopeId: 'ENV-007', subject: 'Joint Defense Agreement — Vargas Cartel Matter',
      type: 'IPEN + Witness', status: 'Completed', scheduledAt: '2026-04-05T10:00:00Z',
      notary: 'David Moreno, NNA #198402', commissionState: 'NY', commissionExpires: '2027-11-30',
      participants: [
        { name: 'Thomas Reilly', role: 'Signer', kba: 'Passed', id: 'Verified', webcam: 'Session Recorded' },
        { name: 'Nina Vasquez', role: 'Signer', kba: 'Passed', id: 'Verified', webcam: 'Session Recorded' },
        { name: 'Robert Chen', role: 'Witness', kba: 'N/A', id: 'Verified', webcam: 'Session Recorded' },
        { name: 'Lisa Park', role: 'Witness', kba: 'N/A', id: 'Verified', webcam: 'Session Recorded' },
      ],
      recording: '00:42:18 · 186 MB · SHA-256 e4a2...9c7f',
      journal: 'Entry #2026-00341 · NY Notary Journal',
      seal: 'Applied · Digital Seal #NY-198402-00341',
    },
    {
      id: 'NOT-003', envelopeId: null, subject: 'Last Will & Testament — Okafor Estate',
      type: 'Witness (2x)', status: 'Pending Setup', scheduledAt: '2026-04-24T11:00:00Z',
      notary: null, commissionState: null, commissionExpires: null,
      participants: [
        { name: 'Emeka Okafor', role: 'Testator', kba: 'Not Started', id: 'Not Started', webcam: 'Not Tested' },
      ],
      recording: null, journal: null, seal: null,
    },
  ];

  const notaryStats = {
    sessionsThisMonth: 8,
    completed: 6,
    scheduled: 2,
    avgSessionTime: '38m',
    ronAvailable: true,
    commissionStates: ['CA', 'NY', 'TX', 'FL', 'IL'],
  };

  // ── Workflows (Conditional Routing DAG + Rules + SLA) ──────────────────────
  const workflows = [
    {
      id: 'WF-001', name: 'High-Value Contract Approval',
      description: 'Routes contracts > $250K through managing partner review before sending',
      active: true, executions: 34, avgSlaHours: 14,
      triggers: 'Envelope created from "Settlement Agreement" or "Co-Counsel"',
      nodes: [
        { id: 'n1', type: 'trigger', label: 'Envelope Created', x: 0 },
        { id: 'n2', type: 'condition', label: 'Value > $250K?', x: 1 },
        { id: 'n3', type: 'approver', label: 'Managing Partner', x: 2, sla: 24 },
        { id: 'n4', type: 'approver', label: 'Compliance Officer', x: 3, sla: 24 },
        { id: 'n5', type: 'action', label: 'Send to Signers', x: 4 },
      ],
      rules: [
        'IF contract_value > 250000 THEN require_partner_approval',
        'IF matter.practice = "Criminal" THEN notify_ethics_counsel',
        'IF signer.jurisdiction != "US" THEN add_apostille_step',
      ],
    },
    {
      id: 'WF-002', name: 'Client Intake Pipeline',
      description: 'Automated engagement + conflict check + fee agreement chain',
      active: true, executions: 124, avgSlaHours: 6,
      triggers: 'Envelope created from "Engagement Letter"',
      nodes: [
        { id: 'n1', type: 'trigger', label: 'Intake Submitted', x: 0 },
        { id: 'n2', type: 'action', label: 'Conflict Check', x: 1, sla: 2 },
        { id: 'n3', type: 'parallel', label: 'Fee Agreement + NDA', x: 2, sla: 24 },
        { id: 'n4', type: 'action', label: 'Matter Created', x: 3 },
      ],
      rules: [
        'Parallel: Fee Agreement AND Mutual NDA',
        'IF conflict_check.result = "FAIL" THEN halt + notify_partner',
      ],
    },
    {
      id: 'WF-003', name: 'Expert Witness Onboarding',
      description: 'Retainer + W-9 + confidentiality agreement in sequence',
      active: true, executions: 31, avgSlaHours: 9,
      triggers: 'Envelope created from "Expert Retainer"',
      nodes: [
        { id: 'n1', type: 'trigger', label: 'Expert Identified', x: 0 },
        { id: 'n2', type: 'action', label: 'Retainer', x: 1, sla: 24 },
        { id: 'n3', type: 'action', label: 'W-9 Collection', x: 2, sla: 12 },
        { id: 'n4', type: 'action', label: 'NDA Execution', x: 3, sla: 24 },
      ],
      rules: ['Sequential execution · each step blocks next'],
    },
    {
      id: 'WF-004', name: 'Cross-Border Apostille Flow',
      description: 'Adds Hague Convention apostille step for international counterparties',
      active: false, executions: 4, avgSlaHours: 72,
      triggers: 'Signer country ≠ US',
      nodes: [
        { id: 'n1', type: 'trigger', label: 'Non-US Signer', x: 0 },
        { id: 'n2', type: 'action', label: 'Translate to Local Lang', x: 1, sla: 48 },
        { id: 'n3', type: 'approver', label: 'Apostille Authority', x: 2, sla: 120 },
        { id: 'n4', type: 'action', label: 'Send to Signer', x: 3 },
      ],
      rules: ['IF signer.country IN hague_members THEN apostille_step'],
    },
  ];

  const workflowSlaMonitors = [
    { id: 'SLA-001', envelope: 'ENV-003', workflow: 'High-Value Contract Approval', step: 'Compliance Officer', due: '2026-04-22T14:00:00Z', hoursLeft: 26, status: 'On Track' },
    { id: 'SLA-002', envelope: 'ENV-INB-1', workflow: 'Client Intake Pipeline', step: 'Fee Agreement', due: '2026-04-21T20:00:00Z', hoursLeft: 8, status: 'At Risk' },
    { id: 'SLA-003', envelope: 'ENV-006', workflow: 'High-Value Contract Approval', step: 'Managing Partner', due: '2026-04-22T09:00:00Z', hoursLeft: 21, status: 'On Track' },
    { id: 'SLA-004', envelope: 'ENV-INB-2', workflow: 'Client Intake Pipeline', step: 'Signer Response', due: '2026-04-21T12:00:00Z', hoursLeft: -2, status: 'Breached' },
  ];

  // ── Clause Library + Risk Scanner (AI Intelligence) ───────────────────────
  const clauseLibrary = [
    { id: 'CL-001', name: 'Standard Indemnification (Mutual)', category: 'Indemnity', status: 'Approved', version: '3.2', lastReviewed: '2026-02-10', usage: 142, reviewedBy: 'M. Kirkland' },
    { id: 'CL-002', name: 'Limitation of Liability (Net Fees)', category: 'Liability', status: 'Approved', version: '2.8', lastReviewed: '2026-01-22', usage: 189, reviewedBy: 'M. Kirkland' },
    { id: 'CL-003', name: 'Choice of Law — Delaware', category: 'Jurisdiction', status: 'Approved', version: '1.4', lastReviewed: '2025-11-15', usage: 98, reviewedBy: 'S. Chen' },
    { id: 'CL-004', name: 'Auto-Renewal (30-day opt-out)', category: 'Term', status: 'Flagged', version: '2.1', lastReviewed: '2026-03-04', usage: 27, reviewedBy: 'S. Chen' },
    { id: 'CL-005', name: 'Arbitration — AAA Commercial', category: 'Dispute Resolution', status: 'Approved', version: '4.1', lastReviewed: '2026-02-28', usage: 76, reviewedBy: 'M. Kirkland' },
    { id: 'CL-006', name: 'Assignment Restriction (Consent)', category: 'Assignment', status: 'Approved', version: '1.9', lastReviewed: '2026-01-08', usage: 112, reviewedBy: 'R. Torres' },
    { id: 'CL-007', name: 'Force Majeure (Broad)', category: 'Performance', status: 'Under Review', version: '3.5-draft', lastReviewed: '2026-04-12', usage: 0, reviewedBy: 'A. Williams' },
    { id: 'CL-008', name: 'Non-Solicit (12mo post-term)', category: 'Restrictive', status: 'Approved', version: '2.3', lastReviewed: '2026-02-18', usage: 45, reviewedBy: 'M. Kirkland' },
  ];

  const riskScans = [
    {
      id: 'SCAN-001', envelopeId: 'ENV-003', subject: 'NDA — Vertex Biomedical',
      scannedAt: '2026-04-20T14:03:00Z', overallRisk: 'Medium',
      findings: [
        { severity: 'High', category: 'Jurisdiction', clause: '§ 14 Governing Law', finding: 'Jurisdiction shifted to Delaware; firm library specifies counterparty state', recommendation: 'Revert to New York or escalate to partner' },
        { severity: 'Medium', category: 'Term', clause: '§ 3 Term & Renewal', finding: 'Auto-renewal with 90-day notice (library standard is 30 days)', recommendation: 'Counter to 30-day opt-out window' },
        { severity: 'Low', category: 'Indemnity', clause: '§ 9 Indemnification', finding: 'Matches firm library CL-001 v3.2', recommendation: 'No action needed' },
      ],
    },
    {
      id: 'SCAN-002', envelopeId: 'ENV-006', subject: 'Fee Agreement — Okafor Estate',
      scannedAt: '2026-04-20T16:22:00Z', overallRisk: 'Low',
      findings: [
        { severity: 'Low', category: 'Fees', clause: '§ 4 Fee Structure', finding: 'Standard contingency-fee language, library match', recommendation: 'No action needed' },
        { severity: 'Medium', category: 'Liability', clause: '§ 11 Limitation', finding: 'Cap set at 2x fees (library standard is 1x net fees)', recommendation: 'Consider negotiating to 1x' },
      ],
    },
    {
      id: 'SCAN-003', envelopeId: 'ENV-001', subject: 'Settlement Agreement — Redstone v. Meridian',
      scannedAt: '2026-04-15T09:08:00Z', overallRisk: 'Low',
      findings: [
        { severity: 'Low', category: 'Release', clause: '§ 2 Mutual Release', finding: 'Language matches firm library', recommendation: 'No action needed' },
      ],
    },
  ];

  const aiFieldTraining = {
    totalCorrections: 847,
    accuracy: 94.2,
    last30d: 128,
    byField: [
      { field: 'Signature', accuracy: 98.1, corrections: 21 },
      { field: 'Date', accuracy: 96.4, corrections: 38 },
      { field: 'Initials', accuracy: 92.7, corrections: 45 },
      { field: 'Text (name)', accuracy: 89.5, corrections: 84 },
      { field: 'Checkbox', accuracy: 95.2, corrections: 18 },
    ],
  };

  // ── Integrations (SDK + Webhooks + Connected Apps + Payment) ──────────────
  const webhooks = [
    { id: 'WH-001', name: 'Clio Matter Sync', url: 'https://api.clio.com/v4/arbiter/hook', events: ['envelope.completed', 'envelope.declined'], active: true, lastFired: '2026-04-16T14:22:00Z', failures: 0 },
    { id: 'WH-002', name: 'NetDocuments Filing', url: 'https://vault.netdocuments.com/hook/arbiter', events: ['envelope.completed'], active: true, lastFired: '2026-04-16T14:22:05Z', failures: 0 },
    { id: 'WH-003', name: 'Zapier — Slack Alerts', url: 'https://hooks.zapier.com/hooks/catch/38/arbiter-signdesk', events: ['envelope.declined', 'envelope.expired'], active: true, lastFired: '2026-04-12T11:35:00Z', failures: 0 },
    { id: 'WH-004', name: 'svc-financials Payment Sync', url: 'https://internal.arbiter.law/svc-financials/hooks/esign', events: ['payment.captured', 'envelope.completed'], active: true, lastFired: '2026-04-18T16:44:00Z', failures: 0 },
    { id: 'WH-005', name: 'Dev Sandbox', url: 'https://dev.arbiter.law/hooks/test', events: ['envelope.*'], active: false, lastFired: '2026-04-02T08:12:00Z', failures: 12 },
  ];

  const sdkKeys = [
    { id: 'KEY-001', name: 'Client Portal — Production', type: 'Embed SDK', created: '2026-01-14', lastUsed: '2026-04-20', requests30d: 14820, scope: 'send, sign, status' },
    { id: 'KEY-002', name: 'Intake Form iframe', type: 'iframe', created: '2026-02-03', lastUsed: '2026-04-20', requests30d: 3412, scope: 'sign' },
    { id: 'KEY-003', name: 'Court Filing Pipeline', type: 'REST API', created: '2025-11-20', lastUsed: '2026-04-19', requests30d: 892, scope: 'send, status, certificate' },
    { id: 'KEY-004', name: 'Mobile App', type: 'Embed SDK', created: '2026-03-01', lastUsed: '2026-04-21', requests30d: 8240, scope: 'sign, status' },
  ];

  const connectedApps = [
    { id: 'APP-001', name: 'Clio', category: 'Practice Management', status: 'Connected', since: '2025-09-12', description: 'Bi-directional matter + document sync' },
    { id: 'APP-002', name: 'NetDocuments', category: 'Document Management', status: 'Connected', since: '2025-10-04', description: 'Auto-file completed envelopes to matter folder' },
    { id: 'APP-003', name: 'Outlook + M365', category: 'Email', status: 'Connected', since: '2025-08-22', description: 'Compose envelopes directly from email' },
    { id: 'APP-004', name: 'LawPay', category: 'Payments', status: 'Connected', since: '2026-01-18', description: 'Payment-on-signature for retainers' },
    { id: 'APP-005', name: 'Stripe', category: 'Payments', status: 'Connected', since: '2026-02-10', description: 'General commercial payment collection' },
    { id: 'APP-006', name: 'Zapier', category: 'Automation', status: 'Connected', since: '2025-07-01', description: '5,000+ app integrations via triggers' },
    { id: 'APP-007', name: 'Microsoft Teams', category: 'Collaboration', status: 'Available', since: null, description: 'Envelope notifications in Teams channels' },
    { id: 'APP-008', name: 'Salesforce', category: 'CRM', status: 'Available', since: null, description: 'Sync signed envelopes to Salesforce records' },
  ];

  const payments = [
    { id: 'PAY-001', envelopeId: 'ENV-002', client: 'Harmon Family Trust', amount: '$12,500', status: 'Captured', method: 'ACH via LawPay', capturedAt: '2026-04-18T16:44:02Z' },
    { id: 'PAY-002', envelopeId: 'ENV-006', client: 'Okafor Estate', amount: '$5,000', status: 'Pending Signature', method: 'Card via Stripe', capturedAt: null },
    { id: 'PAY-003', envelopeId: 'ENV-004', client: 'Kellerman v. Novaris', amount: '$8,400', status: 'Captured', method: 'ACH via LawPay', capturedAt: '2026-04-10T09:45:03Z' },
    { id: 'PAY-004', envelopeId: 'ENV-INB-1', client: 'Chen & Park Associates', amount: '$15,000', status: 'Authorization Hold', method: 'Wire via LawPay', capturedAt: null },
  ];

  // ── Compliance (SOC2 / HIPAA / 21 CFR Part 11 / eIDAS / ESIGN / UETA) ─────
  const compliancePosture = [
    { id: 'C-SOC2', framework: 'SOC 2 Type II', status: 'Certified', renewal: '2026-09-12', score: 100, controls: 147, findings: 0 },
    { id: 'C-HIPAA', framework: 'HIPAA BAA', status: 'Compliant', renewal: '2026-07-01', score: 100, controls: 52, findings: 0 },
    { id: 'C-21CFR', framework: '21 CFR Part 11', status: 'Compliant', renewal: '2026-12-01', score: 98, controls: 34, findings: 1 },
    { id: 'C-EIDAS', framework: 'eIDAS QES (EU)', status: 'Qualified', renewal: '2027-03-15', score: 100, controls: 68, findings: 0 },
    { id: 'C-ESIGN', framework: 'ESIGN Act / UETA', status: 'Compliant', renewal: 'N/A (statutory)', score: 100, controls: 12, findings: 0 },
    { id: 'C-GDPR', framework: 'GDPR', status: 'Compliant', renewal: 'Continuous', score: 96, controls: 89, findings: 2 },
    { id: 'C-CCPA', framework: 'CCPA', status: 'Compliant', renewal: 'Continuous', score: 100, controls: 41, findings: 0 },
  ];

  const vaultSettings = {
    enabled: true,
    matterKeks: 7,
    zeroKnowledgeMatters: ['M-003', 'M-006'],
    keyRotation: 'Every 90 days · next 2026-06-15',
    breakGlassEvents: [
      { ts: '2026-03-22T14:12:00Z', actor: 'M. Kirkland', matter: 'M-006', reason: 'Court-ordered production', approvedBy: 'Managing Partner + Compliance Officer' },
    ],
  };

  const delegations = [
    { id: 'DEL-001', from: 'Patricia Harmon', to: 'Gerald Harmon', scope: 'All Harmon Family Trust matters', basis: 'Durable POA', effective: '2024-05-12', expires: null, status: 'Active', docRef: 'POA-00148' },
    { id: 'DEL-002', from: 'Corporate Officer', to: 'David Ashworth', scope: 'Meridian Capital (up to $500K)', basis: 'Board Resolution', effective: '2025-01-01', expires: '2026-12-31', status: 'Active', docRef: 'BR-2025-003' },
    { id: 'DEL-003', from: 'Emeka Okafor', to: 'Amara Okafor', scope: 'Estate matters only', basis: 'Healthcare POA', effective: '2023-08-14', expires: '2026-01-14', status: 'Expired', docRef: 'POA-00092' },
  ];

  // ── Redlines (pre-signature negotiation) ──────────────────────────────────
  const redlines = [
    { id: 'RL-001', envelopeId: 'ENV-002', proposer: 'Gerald Harmon', clause: '§ 4 Fee Structure', status: 'Pending Review', proposed: '2026-04-19T10:12:00Z', summary: 'Propose monthly capped billing in lieu of hourly' },
    { id: 'RL-002', envelopeId: 'ENV-003', proposer: 'James Wyatt', clause: '§ 3 Term & Renewal', status: 'Accepted', proposed: '2026-04-20T17:30:00Z', summary: 'Shortened renewal notice from 90 to 30 days' },
    { id: 'RL-003', envelopeId: 'ENV-003', proposer: 'James Wyatt', clause: '§ 14 Governing Law', status: 'Rejected', proposed: '2026-04-20T17:32:00Z', summary: 'Rejected jurisdiction shift to CA; held at DE' },
  ];

  // ── Template Governance ────────────────────────────────────────────────────
  const templateGovernance = templates.map(t => {
    const map = {
      'T-001': { stage: 'Published', approver: 'M. Kirkland', approvedAt: '2026-01-10', completionRate: 96, avgTimeToSign: '14h', dropOffField: null, lockedRegions: 5 },
      'T-002': { stage: 'Published', approver: 'S. Chen', approvedAt: '2025-11-20', completionRate: 94, avgTimeToSign: '6h', dropOffField: null, lockedRegions: 3 },
      'T-003': { stage: 'Published', approver: 'M. Kirkland', approvedAt: '2025-09-14', completionRate: 89, avgTimeToSign: '18h', dropOffField: null, lockedRegions: 4 },
      'T-004': { stage: 'Published', approver: 'R. Torres', approvedAt: '2026-02-01', completionRate: 98, avgTimeToSign: '2h', dropOffField: null, lockedRegions: 2 },
      'T-005': { stage: 'Published', approver: 'M. Kirkland', approvedAt: '2025-12-04', completionRate: 92, avgTimeToSign: '8h', dropOffField: null, lockedRegions: 4 },
      'T-006': { stage: 'Published', approver: 'S. Chen', approvedAt: '2025-10-18', completionRate: 78, avgTimeToSign: '48h', dropOffField: 'Receipt Acknowledgement', lockedRegions: 2 },
      'T-007': { stage: 'In Review', approver: 'M. Kirkland', approvedAt: null, completionRate: null, avgTimeToSign: null, dropOffField: null, lockedRegions: 6 },
      'T-008': { stage: 'Published', approver: 'A. Williams', approvedAt: '2026-01-02', completionRate: 91, avgTimeToSign: '24h', dropOffField: null, lockedRegions: 3 },
      'T-009': { stage: 'Published', approver: 'R. Torres', approvedAt: '2025-11-01', completionRate: 97, avgTimeToSign: '3h', dropOffField: null, lockedRegions: 2 },
      'T-010': { stage: 'Deprecated', approver: 'M. Kirkland', approvedAt: '2024-08-10', completionRate: 82, avgTimeToSign: '72h', dropOffField: '§ 7 Privilege Waiver', lockedRegions: 8 },
    };
    return { ...t, ...(map[t.id] || { stage: 'Draft', approver: null, approvedAt: null, completionRate: null, avgTimeToSign: null, dropOffField: null, lockedRegions: 0 }) };
  });

  // ── Nudge Ladders (smart reminders) ───────────────────────────────────────
  const nudgeLadders = [
    { envelopeId: 'ENV-002', signer: 'Patricia Harmon', status: 'Viewed-not-signed', lastNudge: '2026-04-20T10:00:00Z', nextNudge: '2026-04-22T10:00:00Z', channel: 'Email → SMS', attempts: 2 },
    { envelopeId: 'ENV-003', signer: 'James Wyatt', status: 'Never-opened', lastNudge: '2026-04-21T09:00:00Z', nextNudge: '2026-04-22T09:00:00Z', channel: 'Email', attempts: 1 },
    { envelopeId: 'ENV-003', signer: 'Linda Tran', status: 'Never-opened', lastNudge: null, nextNudge: '2026-04-22T09:00:00Z', channel: 'Email', attempts: 0 },
    { envelopeId: 'ENV-INB-1', signer: 'M. Kirkland', status: 'Delegated', lastNudge: '2026-04-20T18:00:00Z', nextNudge: '2026-04-22T18:00:00Z', channel: 'Teams → SMS', attempts: 1 },
  ];

  // ── Court-Ready Certificate (extended for ENV-001) ────────────────────────
  const courtCertificates = {
    'ENV-001': {
      id: 'CERT-ENV-001',
      generatedAt: '2026-04-16T14:22:05Z',
      sha256: 'c3a9e2f1b85d4762a0e8f3c9d1b4a5e6f7c8d9e0a1b2c3d4e5f6a7b8c9d0e1f2',
      signingKeyFingerprint: 'ARBITER-2026-C2-QES · RSA-4096 · FIPS 140-3 L3',
      tlsCipher: 'TLS_AES_256_GCM_SHA384',
      totpEvents: 2,
      hashChain: [
        { seq: 1, ts: '2026-04-15T09:12:00Z', event: 'Created', hash: 'a1b2c3...' },
        { seq: 2, ts: '2026-04-15T09:14:00Z', event: 'Sent', hash: 'b2c3d4...' },
        { seq: 3, ts: '2026-04-15T14:08:00Z', event: 'Signed (Ashworth)', hash: 'c3d4e5...' },
        { seq: 4, ts: '2026-04-16T14:22:00Z', event: 'Signed (Redstone)', hash: 'd4e5f6...' },
        { seq: 5, ts: '2026-04-16T14:22:05Z', event: 'Sealed', hash: 'e5f6a7...' },
      ],
      evidentiary: {
        admissibility: 'Federal Rules of Evidence 901(b)(9) · compliant',
        retention: '7 years · matter-bound',
        witnessedBy: null,
        notarizedBy: null,
      },
    },
  };

  return {
    envelopes, templates, inbox, bulkJobs, contacts, analytics, kpis,
    notarySessions, notaryStats,
    workflows, workflowSlaMonitors,
    clauseLibrary, riskScans, aiFieldTraining,
    webhooks, sdkKeys, connectedApps, payments,
    compliancePosture, vaultSettings, delegations,
    redlines, templateGovernance, nudgeLadders, courtCertificates,
  };
})();
