// RULEBOOK PLATFORM — Extended data layer (FRE, FRAP, state, judge orders, analytics)
// Pattern: CalendarData.jsx + RiskData.jsx
(function () {
  const T = window.ArbiterTokens;

  // Rulebook accent — navy (matches existing  icon gradient)
  const rb = {
    navy: '#1E3A5F',
    navyDark: '#0A1628',
    navyBg: 'rgba(30,58,95,0.06)',
    crimson: '#C23030',
    crimsonBg: 'rgba(194,48,48,0.06)',
    amber: '#D97706',
    amberBg: 'rgba(217,119,6,0.06)',
    teal: '#0D9488',
    tealBg: 'rgba(13,148,136,0.06)',
    green: '#1B7A4A',
    greenBg: 'rgba(27,122,74,0.06)',
    card: { background: T.color.bg.card, border: `1px solid ${T.color.border.light}`, borderRadius: T.radius.lg, overflow: 'hidden', marginBottom: '16px' },
    cardH: { padding: '10px 16px', borderBottom: `1px solid ${T.color.border.light}`, fontSize: '12px', fontWeight: 600, color: T.color.text.primary, display: 'flex', alignItems: 'center', justifyContent: 'space-between', background: T.color.bg.secondary },
    stat: { display: 'flex', flexDirection: 'column', gap: '2px', padding: '12px 16px', background: T.color.bg.secondary, borderRadius: '6px', border: `1px solid ${T.color.border.light}` },
    statLabel: { fontSize: '10px', fontWeight: 600, color: T.color.text.tertiary, textTransform: 'uppercase', letterSpacing: '0.08em' },
    statValue: { fontSize: '22px', fontWeight: 700, letterSpacing: '-0.02em', lineHeight: 1.1, color: T.color.text.primary },
    tag: { display: 'inline-flex', alignItems: 'center', padding: '2px 8px', borderRadius: '10px', fontSize: '10px', fontWeight: 600 },
    btn: { padding: '4px 10px', borderRadius: T.radius.md, border: `1px solid ${T.color.border.light}`, background: T.color.bg.card, fontSize: '11px', fontWeight: 500, color: T.color.text.secondary, cursor: 'pointer', fontFamily: T.font.family },
    btnActive: { background: '#1E3A5F', color: '#fff', borderColor: '#1E3A5F' },
    input: { height: '32px', border: `1px solid ${T.color.border.light}`, borderRadius: T.radius.md, padding: '0 12px', fontSize: '12px', fontFamily: T.font.family, background: T.color.bg.card, color: T.color.text.primary, outline: 'none' },
  };
  window.rb = rb;

  // ── FEDERAL RULES OF EVIDENCE (abridged, deadline-relevant) ──
  const FRE_RULES = [
    { id: 'FRE102', rule: 'FRE 102', title: 'Purpose', summary: 'Rules construed to administer every proceeding fairly, eliminate unjustifiable expense/delay.', category: 'general' },
    { id: 'FRE103', rule: 'FRE 103', title: 'Rulings on Evidence', summary: 'Error preserved only if timely objection and specific ground stated. Offer of proof required for excluded evidence.', category: 'objections', critical: true, practiceNote: 'Must object contemporaneously and state specific ground. Plain-error review otherwise.' },
    { id: 'FRE401', rule: 'FRE 401', title: 'Test for Relevant Evidence', summary: 'Evidence is relevant if it has any tendency to make a fact more or less probable and fact is of consequence.', category: 'relevance' },
    { id: 'FRE403', rule: 'FRE 403', title: 'Excluding Relevant Evidence', summary: 'Court may exclude if probative value substantially outweighed by unfair prejudice, confusion, delay, or cumulative.', category: 'relevance', critical: true },
    { id: 'FRE404', rule: 'FRE 404', title: 'Character Evidence; Other Acts', summary: '404(b) — prior bad acts admissible for motive, opportunity, intent, preparation, plan, knowledge, identity, absence of mistake.', category: 'character', critical: true, deadlines: [{ desc: 'Prosecution must provide reasonable notice of 404(b) evidence in criminal case', days: 0, trigger: 'Pretrial/Request', type: 'notice' }] },
    { id: 'FRE407', rule: 'FRE 407', title: 'Subsequent Remedial Measures', summary: 'Remedial measures inadmissible to prove negligence but may be admitted for impeachment, feasibility, ownership.', category: 'exclusions' },
    { id: 'FRE408', rule: 'FRE 408', title: 'Compromise Offers', summary: 'Settlement offers/negotiations inadmissible to prove liability but admissible to prove bias, negate delay claim, or obstruction.', category: 'exclusions', critical: true },
    { id: 'FRE502', rule: 'FRE 502', title: 'Attorney-Client Privilege; Waiver', summary: 'Limited waiver for inadvertent disclosure. 502(d) orders eliminate subject-matter waiver in federal proceedings.', category: 'privilege', critical: true, practiceNote: '502(d) orders are the single most powerful ESI protection — negotiate early.' },
    { id: 'FRE602', rule: 'FRE 602', title: 'Need for Personal Knowledge', summary: 'Witness may testify only if evidence supports finding personal knowledge. Does not apply to expert testimony.', category: 'witnesses' },
    { id: 'FRE615', rule: 'FRE 615', title: 'Excluding Witnesses', summary: 'Court must, at a party\'s request, order witnesses excluded so they cannot hear other testimony.', category: 'witnesses' },
    { id: 'FRE701', rule: 'FRE 701', title: 'Opinion Testimony by Lay Witnesses', summary: 'Lay opinion limited to: (a) rationally based on perception, (b) helpful to fact-finding, (c) not based on specialized knowledge.', category: 'opinion' },
    { id: 'FRE702', rule: 'FRE 702', title: 'Testimony by Expert Witnesses', summary: 'Qualified expert may testify if (a) knowledge helps, (b) sufficient facts/data, (c) reliable principles/methods, (d) reliably applied. (Daubert)', category: 'opinion', critical: true, deadlines: [{ desc: 'Daubert motion timing set by scheduling order; typically 30-60 days before trial', days: -45, trigger: 'Trial Date', type: 'before-trial', critical: true }], practiceNote: 'Daubert challenges are high-stakes — file motion in limine with detailed record.' },
    { id: 'FRE801', rule: 'FRE 801', title: 'Definitions; Hearsay', summary: 'Out-of-court statement offered for truth. 801(d) — party-opponent statements and prior consistent/inconsistent statements not hearsay.', category: 'hearsay', critical: true },
    { id: 'FRE803', rule: 'FRE 803', title: 'Hearsay Exceptions — Availability Immaterial', summary: '23 exceptions: present sense impression, excited utterance, then-existing state, business records, public records, learned treatises, etc.', category: 'hearsay', critical: true },
    { id: 'FRE804', rule: 'FRE 804', title: 'Hearsay Exceptions — Unavailable Declarant', summary: 'Former testimony, dying declaration, statement against interest, statement of personal/family history, forfeiture by wrongdoing.', category: 'hearsay' },
    { id: 'FRE807', rule: 'FRE 807', title: 'Residual Exception', summary: 'Not covered by 803/804 but has guarantees of trustworthiness and is more probative than other available evidence. Notice required.', category: 'hearsay', deadlines: [{ desc: 'Reasonable notice before trial of intent to use 807 evidence', days: -14, trigger: 'Trial Date', type: 'before-trial', critical: true }] },
    { id: 'FRE901', rule: 'FRE 901', title: 'Authenticating Evidence', summary: 'Proponent must produce evidence sufficient to support finding that item is what proponent claims.', category: 'authentication' },
    { id: 'FRE902', rule: 'FRE 902', title: 'Self-Authenticating', summary: 'Self-authenticating: public docs, trade inscriptions, 902(13)/(14) electronic records with certification.', category: 'authentication', critical: true, practiceNote: '902(13)/(14) self-authenticate ESI via written certification — saves custodian depositions.' },
    { id: 'FRE1006', rule: 'FRE 1006', title: 'Summaries to Prove Content', summary: 'Voluminous writings may be presented as summary/chart. Originals must be made available.', category: 'best-evidence' },
  ];

  // ── FRAP (Federal Rules of Appellate Procedure) ──
  const FRAP_RULES = [
    { id: 'FRAP3', rule: 'FRAP 3', title: 'Appeal as of Right — How Taken', summary: 'Filing notice of appeal with district clerk. Content requirements: party, judgment, court.', critical: true, deadlines: [{ desc: 'Notice of appeal filed in district court', days: 0, trigger: 'Judgment + 30 days', type: 'jurisdictional', critical: true }] },
    { id: 'FRAP4', rule: 'FRAP 4', title: 'Appeal as of Right — When Taken', summary: '30 days after judgment (60 if US is party). Post-trial motions reset the clock.', critical: true, deadlines: [{ desc: 'Civil appeal: 30 days', days: 30, trigger: 'Judgment Entered', type: 'calendar', critical: true }, { desc: 'US as party: 60 days', days: 60, trigger: 'Judgment Entered', type: 'calendar', critical: true }, { desc: 'Cross-appeal: 14 days after first appeal', days: 14, trigger: 'First Appeal Filed', type: 'calendar', critical: true }] },
    { id: 'FRAP5', rule: 'FRAP 5', title: 'Appeal by Permission', summary: 'Interlocutory appeals under 28 USC 1292(b). Petition within 10 days of certification.', deadlines: [{ desc: 'Petition for permission to appeal: 10 days', days: 10, trigger: 'Certification Order', type: 'calendar', critical: true }] },
    { id: 'FRAP10', rule: 'FRAP 10', title: 'Record on Appeal', summary: 'Composed of original papers and exhibits, transcript, clerk\'s certified copy. Appellant orders transcript.', deadlines: [{ desc: 'Transcript order: within 14 days of filing notice of appeal', days: 14, trigger: 'Notice of Appeal', type: 'calendar', critical: true }] },
    { id: 'FRAP25', rule: 'FRAP 25', title: 'Filing and Service', summary: 'Electronic filing required. Service on counsel complete on transmission.', category: 'service' },
    { id: 'FRAP27', rule: 'FRAP 27', title: 'Motions', summary: 'Motion with supporting papers. Response within 10 days; reply within 7.', deadlines: [{ desc: 'Response to motion: 10 days', days: 10, trigger: 'Motion Served', type: 'calendar' }, { desc: 'Reply: 7 days', days: 7, trigger: 'Response Served', type: 'calendar' }] },
    { id: 'FRAP28', rule: 'FRAP 28', title: 'Briefs', summary: 'Content requirements: jurisdictional statement, issues, facts, argument, conclusion. Appendix required.', category: 'briefs' },
    { id: 'FRAP31', rule: 'FRAP 31', title: 'Serving and Filing Briefs', summary: 'Appellant brief: 40 days after record filed. Appellee: 30 days after appellant. Reply: 21 days.', critical: true, deadlines: [{ desc: 'Appellant opening brief: 40 days', days: 40, trigger: 'Record Filed', type: 'calendar', critical: true }, { desc: 'Appellee brief: 30 days', days: 30, trigger: 'Appellant Brief Served', type: 'calendar', critical: true }, { desc: 'Reply brief: 21 days', days: 21, trigger: 'Appellee Brief Served', type: 'calendar', critical: true }] },
    { id: 'FRAP32', rule: 'FRAP 32', title: 'Form of Briefs', summary: 'Word limits: opening/answering 13,000; reply 6,500. Length certificate required.', category: 'briefs' },
    { id: 'FRAP35', rule: 'FRAP 35', title: 'En Banc Determination', summary: 'Petition for rehearing en banc — 45 days after panel decision. High bar for rehearing.', deadlines: [{ desc: 'Petition for rehearing en banc: 45 days', days: 45, trigger: 'Panel Decision', type: 'calendar', critical: true }] },
    { id: 'FRAP40', rule: 'FRAP 40', title: 'Petition for Panel Rehearing', summary: 'Rehearing petition — 14 days after judgment (45 if US is party).', deadlines: [{ desc: 'Panel rehearing: 14 days (45 if US party)', days: 14, trigger: 'Panel Judgment', type: 'calendar', critical: true }] },
  ];

  // ── JUDGE STANDING ORDERS ──
  const JUDGE_ORDERS = [
    { id: 'J-REYN', judge: 'Hon. E. Reynolds', court: 'S.D.N.Y.', chambers: 'Courtroom 14C', orders: [
      { topic: 'Motion Practice', text: 'All non-dispositive discovery motions require pre-motion conference. File 3-page letter request first.' },
      { topic: 'Summary Judgment', text: 'Single consolidated MSJ brief, 25-page limit. Separate 56.1 statement required.' },
      { topic: 'Page Limits', text: 'Memoranda: 25 pages; reply: 10 pages. No extensions absent extraordinary cause.' },
      { topic: 'Exhibits', text: 'Electronic exhibits via ECF. Bench binders required for all hearings.' },
      { topic: 'Settlement', text: 'Mandatory settlement conference before magistrate within 60 days of discovery close.' },
    ], tendencies: { msjGrantRate: 0.34, avgTimeToRuling: 87, motionToCompelGrantRate: 0.52, trialDaysAvg: 6.2 }},
    { id: 'J-CHENG', judge: 'Hon. L. Cheng', court: 'N.D. Cal.', chambers: 'Courtroom 8', orders: [
      { topic: 'Discovery', text: 'All discovery disputes by joint letter, 5 pages max. Courts will not review extended correspondence.' },
      { topic: 'Case Management', text: 'Initial CMC at 90 days. Trial date set at first CMC — continuances disfavored.' },
      { topic: 'ESI', text: 'ESI protocol required by Rule 26(f) conference. Form 37 checklist must be completed.' },
      { topic: 'Patent Cases', text: 'Patent L.R. 3 contentions on strict schedule. Markman hearing at 8 months.' },
    ], tendencies: { msjGrantRate: 0.28, avgTimeToRuling: 64, motionToCompelGrantRate: 0.41, trialDaysAvg: 8.1 }},
    { id: 'J-PATEL', judge: 'Hon. R. Patel', court: 'E.D. Tex.', chambers: 'Tyler Division', orders: [
      { topic: 'Rocket Docket', text: 'Trial typically within 12 months of filing. Continuances require "exceptional cause."' },
      { topic: 'Discovery', text: 'Infringement contentions 14 days after CMC; invalidity 45 days later. No extensions.' },
      { topic: 'Motions', text: 'All motions decided within 30 days of full briefing. No hearings absent request.' },
    ], tendencies: { msjGrantRate: 0.19, avgTimeToRuling: 28, motionToCompelGrantRate: 0.68, trialDaysAvg: 7.4 }},
    { id: 'J-MORR', judge: 'Hon. D. Morrison', court: 'E.D. Va.', chambers: 'Alexandria', orders: [
      { topic: 'Scheduling', text: 'Rocket Docket. Trial within 6-9 months. Discovery capped at 120 days.' },
      { topic: 'Motions', text: 'Failure to file timely opposition = motion granted as unopposed. Strict enforcement.' },
      { topic: 'Extensions', text: 'Extensions denied absent extraordinary circumstances.' },
    ], tendencies: { msjGrantRate: 0.42, avgTimeToRuling: 18, motionToCompelGrantRate: 0.73, trialDaysAvg: 4.8 }},
    { id: 'J-OKAFOR', judge: 'Hon. A. Okafor', court: 'D.N.J.', chambers: 'Newark', orders: [
      { topic: 'Meet and Confer', text: 'Required before any discovery motion. Certification with specific dates of conferences.' },
      { topic: 'Letter Briefs', text: 'Preference for letter briefs on discovery issues, 5 pages max.' },
      { topic: 'ADR', text: 'Mandatory mediation referral at scheduling conference.' },
    ], tendencies: { msjGrantRate: 0.31, avgTimeToRuling: 92, motionToCompelGrantRate: 0.47, trialDaysAvg: 5.9 }},
  ];

  // ── STATE RULES — parallel provisions ──
  const STATE_RULES = [
    { topic: 'Answer Deadline', frcp: '21 days (Rule 12(a))', ca: '30 days (CCP §412.20)', ny: '20 or 30 days (CPLR §3012)', tx: 'Monday after 20 days (TRCP 99)', note: 'Most state courts give longer response window than federal.' },
    { topic: 'Service of Process', frcp: '90 days (Rule 4(m))', ca: '60 days after filing', ny: '120 days (CPLR §306-b)', tx: 'No specific time limit, but diligence required', note: 'State deadlines vary significantly. Calendar as soon as case filed.' },
    { topic: 'Discovery Limits', frcp: '25 interrogatories (Rule 33)', ca: '35 special interrogatories (CCP §2030.030)', ny: 'No fixed limit (CPLR §3130)', tx: '25 interrogatories (TRCP 190)', note: 'NY has no cap by default — judge may limit.' },
    { topic: 'MSJ Standard', frcp: 'No genuine dispute (Celotex)', ca: 'No triable issue (CCP §437c)', ny: 'No material issues of fact (CPLR §3212)', tx: 'No genuine issue of material fact (TRCP 166a)', note: 'CA requires 75-day notice; NY requires MSJ within 120 days of note of issue.' },
    { topic: 'Appeal Deadline', frcp: '30 days (FRAP 4)', ca: '60 days from notice of entry (Cal. Rules of Court 8.104)', ny: '30 days from service with notice (CPLR §5513)', tx: '30 days (TRAP 26.1)', note: 'All are JURISDICTIONAL — cannot be extended.' },
    { topic: 'RFA Deemed Admitted', frcp: '30 days — deemed admitted (Rule 36)', ca: '30 days — responses required, no auto-admit (CCP §2033.280)', ny: '20 days (CPLR §3123)', tx: '30 days — deemed admitted (TRCP 198.2)', note: 'CA is a trap for federal practitioners — no auto-admit, must move to deem.' },
    { topic: 'Statute of Limitations (personal injury)', frcp: 'Borrows state law', ca: '2 years (CCP §335.1)', ny: '3 years (CPLR §214)', tx: '2 years (TCPRC §16.003)', note: 'Federal courts borrow the forum state\'s SOL. Always verify per cause of action.' },
  ];

  // ── HISTORICAL AMENDMENTS ──
  const AMENDMENTS = [
    { rule: 'Rule 1', year: 2015, change: 'Added emphasis that parties share responsibility for just/speedy/inexpensive determination.', impact: 'Cultural shift toward cooperation.' },
    { rule: 'Rule 4(m)', year: 2015, change: 'Service deadline reduced from 120 days to 90 days.', impact: 'Faster case progression; more dismissals for failure to serve.', critical: true },
    { rule: 'Rule 26(b)(1)', year: 2015, change: 'Added proportionality as core scope limit — not just burden/cost/importance.', impact: 'Major shift — proportionality now first-line limit, not just objection.', critical: true },
    { rule: 'Rule 37(e)', year: 2015, change: 'New ESI spoliation framework. Two-tier intent/prejudice analysis replaces common-law framework.', impact: 'Uniform federal ESI sanctions standard. Intent-to-deprive required for adverse inference.', critical: true },
    { rule: 'Rule 5', year: 2018, change: 'Electronic service presumed. Mail/paper service requires special justification.', impact: 'Eliminates 3-day rule in most cases.' },
    { rule: 'Rule 30(b)(6)', year: 2020, change: 'Parties must confer on organization topics before deposition.', impact: 'Forced pre-deposition negotiation on scope.' },
    { rule: 'Rule 16/26', year: 2022, change: 'Expanded magistrate authority over discovery disputes.', impact: 'More referrals to magistrate judges.' },
    { rule: 'Rule 6(d)', year: 2024, change: 'Eliminated 3-day rule for electronic service in most contexts.', impact: 'Simplification — deadlines triggered by e-service run from service date.' },
  ];

  // ── PROPOSED AMENDMENTS (pending Advisory Committee) ──
  const PROPOSED_AMENDMENTS = [
    { rule: 'Rule 16.1', status: 'Pending', effective: '2026-12-01', change: 'Mandatory MDL management framework. Initial organization, leadership selection, bellwether process.', stage: 'Published for comment' },
    { rule: 'Rule 17(c)', status: 'Pending', effective: '2026-12-01', change: 'Parent/guardian cross-border representation for foreign-domiciled minors.', stage: 'Public hearing scheduled' },
    { rule: 'Rule 45(c)', status: 'Committee review', effective: '2027-12-01', change: 'Clarify 100-mile rule for remote depositions and virtual appearances.', stage: 'Subcommittee draft' },
    { rule: 'Rule 702', status: 'Adopted', effective: '2023-12-01', change: 'Clarified that expert opinion must reliably apply principles/methods — rejecting "more likely than not" framing.', stage: 'Effective' },
  ];

  // ── MOTION TEMPLATES ──
  const MOTION_TEMPLATES = [
    { id: 'MT-12B6', rule: 'Rule 12(b)(6)', name: 'Motion to Dismiss — Failure to State a Claim', sections: ['Introduction', 'Factual Background', 'Legal Standard (Twombly/Iqbal)', 'Argument', 'Conclusion'], standardLength: 20, meetConferReq: false },
    { id: 'MT-56', rule: 'Rule 56', name: 'Motion for Summary Judgment', sections: ['Statement of Undisputed Facts', 'Introduction', 'Legal Standard (Celotex)', 'Argument', 'Conclusion'], standardLength: 25, meetConferReq: false, localRequirements: 'Local Rule 56.1 statement required in SDNY/EDNY/NDCA/DNJ' },
    { id: 'MT-37A', rule: 'Rule 37(a)', name: 'Motion to Compel', sections: ['Meet-and-Confer Certification', 'Introduction', 'Discovery Request/Response at Issue', 'Argument', 'Relief Requested', 'Fees Request'], standardLength: 15, meetConferReq: true, critical: 'Must include Rule 37(a)(1) good-faith certification' },
    { id: 'MT-26C', rule: 'Rule 26(c)', name: 'Motion for Protective Order', sections: ['Meet-and-Confer Certification', 'Good Cause Showing', 'Protection Sought', 'Proposed Order'], standardLength: 15, meetConferReq: true },
    { id: 'MT-15A', rule: 'Rule 15(a)', name: 'Motion for Leave to Amend', sections: ['Introduction', 'Good Cause / Foman Factors', 'Proposed Amendment (redline)', 'Conclusion'], standardLength: 10, meetConferReq: false },
    { id: 'MT-45D', rule: 'Rule 45(d)', name: 'Motion to Quash Subpoena', sections: ['Standing', 'Grounds (Undue Burden / Privilege / Geographic)', 'Argument', 'Proposed Relief'], standardLength: 12, meetConferReq: false },
    { id: 'MT-59', rule: 'Rule 59', name: 'Motion for New Trial / Alter Judgment', sections: ['Introduction', 'Grounds (Manifest Error / New Evidence / Manifest Injustice)', 'Argument', 'Conclusion'], standardLength: 15, meetConferReq: false, critical: '28-day jurisdictional deadline' },
    { id: 'MT-DAUBERT', rule: 'FRE 702', name: 'Daubert Motion (Motion in Limine)', sections: ['Introduction', 'Daubert Standard', 'Expert\'s Qualifications', 'Reliability Analysis', 'Fit / Relevance', 'Conclusion'], standardLength: 20, meetConferReq: false },
  ];

  // ── SANCTIONS FACTORS (Rule 11, 26(g), 37(e), 45) ──
  const SANCTIONS_FACTORS = [
    { id: 'SF-R11', rule: 'Rule 11', factors: [
      { q: 'Filing had no evidentiary basis after reasonable inquiry?', weight: 30, critical: true },
      { q: 'Filing asserted legal position contrary to existing law with no good-faith argument for extension?', weight: 25 },
      { q: 'Filing made for improper purpose (harass, delay, increase cost)?', weight: 30, critical: true },
      { q: 'Attorney failed to comply with 21-day safe harbor?', weight: -20, favorable: true },
    ], safeHarbor: '21-day safe harbor (Rule 11(c)(2)) — mandatory', riskTiers: { critical: 60, high: 40, low: 20 } },
    { id: 'SF-R26G', rule: 'Rule 26(g)', factors: [
      { q: 'Discovery response lacked reasonable inquiry by attorney?', weight: 25 },
      { q: 'Objection lacked specific grounds (boilerplate)?', weight: 25 },
      { q: 'Disclosure incomplete (missed custodians or sources)?', weight: 30, critical: true },
      { q: 'Served without signature or certification?', weight: 20 },
    ], safeHarbor: 'None — automatic signature certification', riskTiers: { critical: 70, high: 40, low: 20 } },
    { id: 'SF-R37E', rule: 'Rule 37(e)', factors: [
      { q: 'Duty to preserve existed (litigation reasonably anticipated)?', weight: 20, critical: true },
      { q: 'Reasonable steps were NOT taken to preserve?', weight: 25 },
      { q: 'ESI cannot be restored or replaced?', weight: 25 },
      { q: 'Prejudice to opposing party shown?', weight: 15 },
      { q: 'Intent to deprive (required for adverse inference)?', weight: 30, critical: true },
    ], safeHarbor: '37(e)(1) cure measures; 37(e)(2) requires intent', riskTiers: { critical: 75, high: 45, low: 25 } },
    { id: 'SF-R45', rule: 'Rule 45', factors: [
      { q: 'Subpoena imposed undue burden?', weight: 25 },
      { q: 'Subpoena served outside 100-mile rule without good cause?', weight: 25 },
      { q: 'Failed to tender witness fees?', weight: 20 },
      { q: 'Sought privileged material?', weight: 30, critical: true },
    ], safeHarbor: 'Rule 45(d)(1) — serving party must take reasonable steps to avoid imposing burden', riskTiers: { critical: 60, high: 35, low: 15 } },
  ];

  // ── DEADLINE INCIDENT LOG (for heatmap) ──
  const DEADLINE_INCIDENTS = [
    { id: 'INC-001', rule: 'Rule 36(a)(3)', court: 'S.D.N.Y.', date: '2026-02-10', matter: 'M-2024-0312', severity: 'critical', outcome: 'Deemed admitted — 7 facts', resolved: true },
    { id: 'INC-002', rule: 'Rule 26(a)(1)', court: 'N.D. Cal.', date: '2026-01-22', matter: 'M-2024-0451', severity: 'high', outcome: 'Sanctions motion denied — cured', resolved: true },
    { id: 'INC-003', rule: 'FRAP 4(a)', court: '9th Cir.', date: '2025-11-14', matter: 'M-2023-0289', severity: 'critical', outcome: 'Appeal waived — jurisdictional', resolved: true },
    { id: 'INC-004', rule: 'Rule 38(b)', court: 'D.N.J.', date: '2025-09-03', matter: 'M-2025-0108', severity: 'critical', outcome: 'Jury trial waived', resolved: true },
    { id: 'INC-005', rule: 'Rule 56(b)', court: 'E.D.N.Y.', date: '2025-08-19', matter: 'M-2024-0672', severity: 'high', outcome: 'MSJ filed late — denied on merits', resolved: true },
    { id: 'INC-006', rule: 'Rule 59(b)', court: 'E.D. Va.', date: '2026-03-04', matter: 'M-2025-0311', severity: 'critical', outcome: 'Motion untimely — lost on appeal', resolved: true },
    { id: 'INC-007', rule: 'Rule 33(b)(2)', court: 'S.D.N.Y.', date: '2026-03-28', matter: 'M-2024-0312', severity: 'high', outcome: 'Objections waived', resolved: true },
    { id: 'INC-008', rule: 'Rule 36(a)(3)', court: 'D. Del.', date: '2026-02-18', matter: 'M-2025-0077', severity: 'critical', outcome: 'Deemed admitted — 12 facts', resolved: false },
    { id: 'INC-009', rule: 'Rule 54(d)', court: 'N.D. Cal.', date: '2026-01-30', matter: 'M-2024-0451', severity: 'high', outcome: 'Attorney fees motion waived', resolved: true },
    { id: 'INC-010', rule: 'Rule 45(d)(2)(B)', court: 'C.D. Cal.', date: '2026-04-02', matter: 'M-2025-0298', severity: 'high', outcome: 'Objections to subpoena waived', resolved: false },
    { id: 'INC-011', rule: 'Rule 26(a)(2)(D)', court: 'E.D. Tex.', date: '2026-02-25', matter: 'M-2025-0154', severity: 'critical', outcome: 'Expert excluded', resolved: true },
    { id: 'INC-012', rule: 'Rule 4(m)', court: 'S.D.N.Y.', date: '2026-03-11', matter: 'M-2026-0018', severity: 'critical', outcome: 'Dismissed without prejudice', resolved: true },
  ];

  // ── RULE-PIN PLACEHOLDERS (populated by store) ──
  const MATTER_PINS = [
    { id: 'PIN-001', matterId: 'M-2024-0312', ruleId: 'R36', pinnedBy: 'M. Kirkland', date: '2026-03-20', reason: 'RFA deadline — critical', context: 'Discovery phase' },
    { id: 'PIN-002', matterId: 'M-2024-0312', ruleId: 'R56', pinnedBy: 'M. Kirkland', date: '2026-04-01', reason: 'Pending MSJ', context: 'Dispositive motion phase' },
    { id: 'PIN-003', matterId: 'M-2024-0451', ruleId: 'R26', pinnedBy: 'L. Torres', date: '2026-02-14', reason: 'ESI protocol', context: 'Rule 26(f) prep' },
    { id: 'PIN-004', matterId: 'M-2025-0154', ruleId: 'FRE702', pinnedBy: 'M. Kirkland', date: '2026-04-10', reason: 'Daubert anticipated', context: 'Expert disclosure approaching' },
  ];

  // ── SUBSCRIPTIONS ──
  const RULE_SUBSCRIPTIONS = [
    { id: 'SUB-001', ruleId: 'R37', user: 'M. Kirkland', topic: 'amendments', created: '2026-01-15' },
    { id: 'SUB-002', ruleId: 'R26', user: 'L. Torres', topic: 'amendments', created: '2026-02-20' },
    { id: 'SUB-003', ruleId: 'FRE702', user: 'M. Kirkland', topic: 'case-law', created: '2026-03-10' },
  ];

  const RULEBOOK_DATA = {
    fre: FRE_RULES,
    frap: FRAP_RULES,
    judgeOrders: JUDGE_ORDERS,
    stateRules: STATE_RULES,
    amendments: AMENDMENTS,
    proposedAmendments: PROPOSED_AMENDMENTS,
    motionTemplates: MOTION_TEMPLATES,
    sanctionsFactors: SANCTIONS_FACTORS,
    deadlineIncidents: DEADLINE_INCIDENTS,
    matterPins: MATTER_PINS,
    subscriptions: RULE_SUBSCRIPTIONS,
  };

  window.RULEBOOK_DATA = RULEBOOK_DATA;
})();
