// Pocket Marshal — Florida Fire Prevention Code, 8th Edition (2023): complete chapter index
// Two volumes: NFPA 1-FL (Fire Code) and NFPA 101-FL (Life Safety Code), both based on 2021 editions
// with Florida amendments. Full text is NFPA-copyrighted — this is a navigable index with scope notes;
// reserved (empty) chapters are omitted.

const PM_FFPC_VOLUMES = [
  {
    id: 'vol1',
    title: 'Volume 1 — NFPA 1-FL · Fire Code',
    sub: 'Fire prevention, hazards, and operations · with Florida amendments',
    chapters: [
      { n: 1, t: 'Administration', s: 'Scope, purpose, enforcement authority, permits, inspections, and the appeals process — including Florida\u2019s Fire Code Board of Appeals provisions.' },
      { n: 2, t: 'Referenced Publications', s: 'Every NFPA standard and other document adopted by reference, with the edition that legally applies.' },
      { n: 3, t: 'Definitions', s: 'Defined terms used throughout the Code. When a violation hinges on a word, start here.' },
      { n: 4, t: 'General Requirements', s: 'Fundamental goals and objectives, owner/occupant responsibilities, and change-of-use provisions.' },
      { n: 5, t: 'Performance-Based Option', s: 'Alternative compliance path using engineering analysis instead of prescriptive requirements.' },
      { n: 6, t: 'Classification of Occupancy', s: 'How to classify a building\u2019s occupancy — the decision that drives every other requirement.' },
      { n: 10, t: 'General Safety Requirements', s: 'Open flames, smoking, vacant premises, occupant load posting, fire drills, and general housekeeping.' },
      { n: 11, t: 'Building Services', s: 'Electrical fire safety (extension cords, panels, power taps), HVAC, elevators, and utilities.' },
      { n: 12, t: 'Features of Fire Protection', s: 'Fire-rated construction, fire doors and windows, interior finish, and draft-stopping.' },
      { n: 13, t: 'Fire Protection Systems', s: 'Sprinklers, standpipes, fire alarms, portable extinguishers, and kitchen suppression — installation and ITM.' },
      { n: 14, t: 'Means of Egress', s: 'Exits, exit access, door hardware and locks, exit signs, emergency lighting, and obstruction rules.' },
      { n: 16, t: 'Safeguarding Construction, Alteration & Demolition', s: 'Fire safety during construction work — hot work, temporary heating, access, and standpipe continuity.' },
      { n: 17, t: 'Wildland Urban Interface', s: 'Defensible space and ignition-resistant requirements where development meets wildland.' },
      { n: 18, t: 'Fire Department Access & Water Supply', s: 'Fire lanes, access roads, gates, key boxes, hydrants, and required fire flow.' },
      { n: 19, t: 'Combustible Waste & Refuse', s: 'Storage and handling of rubbish, waste containers near buildings, and dumpster clearances.' },
      { n: 20, t: 'Occupancy Fire Safety', s: 'Occupancy-specific operational rules — assembly crowd managers, health care, mercantile, and more.' },
      { n: 21, t: 'Airports & Heliports', s: 'Aircraft fueling, hangars, and rooftop heliport fire safety.' },
      { n: 22, t: 'Automobile Wrecking Yards', s: 'Salvage yard operations: fluid draining, tire piles, and cutting operations.' },
      { n: 23, t: 'Cleanrooms', s: 'Fire protection for cleanroom facilities and their specialized HVAC.' },
      { n: 25, t: 'Grandstands, Bleachers, Tents & Membrane Structures', s: 'Temporary and permanent seating, tents over thresholds, flame-retardant fabrics, and exiting.' },
      { n: 26, t: 'Laboratories Using Chemicals', s: 'Lab-scale chemical handling, fume hoods, and quantity limits.' },
      { n: 27, t: 'Manufactured Home & Recreational Vehicle Sites', s: 'Site separation, fire access, and utilities for manufactured home and RV communities.' },
      { n: 28, t: 'Marinas, Boatyards, Piers & Wharves', s: 'Shore power, fueling, fire protection, and access at waterfront facilities.' },
      { n: 29, t: 'Parking Garages', s: 'Open and enclosed parking structures, including EV charging considerations.' },
      { n: 30, t: 'Motor Fuel Dispensing & Repair Garages', s: 'Gas stations and repair shops: dispensing, tanks, ventilation, and ignition sources.' },
      { n: 31, t: 'Forest Products', s: 'Lumber yards, woodworking facilities, and outdoor timber storage.' },
      { n: 32, t: 'Motion Picture & TV Production Facilities', s: 'Soundstages and approved production facilities — sets, pyrotechnics, and occupancy rules.' },
      { n: 33, t: 'Outside Storage of Tires', s: 'Tire pile size limits, separation distances, and fire department access.' },
      { n: 34, t: 'General Storage', s: 'Indoor commodity and rack storage, idle pallets, and clearance to sprinkler deflectors.' },
      { n: 35, t: 'Animal Housing Facilities', s: 'Kennels, stables, and shelters — egress and fire protection for animal occupancies.' },
      { n: 40, t: 'Dust Explosion & Fire Prevention', s: 'Combustible dust hazards: housekeeping, ignition control, and explosion protection.' },
      { n: 41, t: 'Welding, Cutting & Other Hot Work', s: 'Hot work permits, fire watch requirements, and safeguarding combustibles.' },
      { n: 43, t: 'Spraying, Dipping & Coating', s: 'Spray booths and finishing operations using flammable or combustible materials.' },
      { n: 45, t: 'Stationary Combustion Engines & Gas Turbines', s: 'Generators and engine installations: fuel, exhaust, and clearances.' },
      { n: 50, t: 'Commercial Cooking Operations', s: 'Hoods, ducts, grease management, and suppression for commercial kitchens (with NFPA 96).' },
      { n: 51, t: 'Industrial Ovens & Furnaces', s: 'Process ovens, furnaces, and their safety controls.' },
      { n: 52, t: 'Energy Storage Systems', s: 'Battery ESS installations — location, size limits, and suppression (with NFPA 855).' },
      { n: 53, t: 'Mechanical Refrigeration', s: 'Refrigeration machinery rooms, refrigerant classification, and detection.' },
      { n: 55, t: 'Cleaning & Purging of Flammable Gas Piping', s: 'Safe procedures for placing gas piping systems in and out of service.' },
      { n: 60, t: 'Hazardous Materials', s: 'The general framework: maximum allowable quantities, control areas, storage, and permits.' },
      { n: 61, t: 'Aerosol Products', s: 'Storage and display of aerosol products by level classification.' },
      { n: 63, t: 'Combustible Metals', s: 'Magnesium, titanium, and other combustible metal storage and processing.' },
      { n: 65, t: 'Explosives, Fireworks & Model Rocketry', s: 'Explosives storage, fireworks displays, and Florida\u2019s consumer fireworks retail sales (CFRS) provisions.' },
      { n: 66, t: 'Flammable & Combustible Liquids', s: 'Tank storage, dispensing, container limits, and classified locations.' },
      { n: 67, t: 'Fumigation', s: 'Structural fumigation operations — notification, warning signs, and watchmen.' },
      { n: 69, t: 'LP-Gas & LNG', s: 'Propane and liquefied natural gas: containers, exchange cabinets, and setbacks.' },
    ],
  },
  {
    id: 'vol2',
    title: 'Volume 2 — NFPA 101-FL · Life Safety Code',
    sub: 'Occupant safety by occupancy type · with Florida amendments',
    chapters: [
      { n: 1, t: 'Administration', s: 'Scope, application to new vs. existing buildings, and equivalency provisions.' },
      { n: 2, t: 'Referenced Publications', s: 'Adopted standards and the editions that apply under this volume.' },
      { n: 3, t: 'Definitions', s: 'Defined terms — including Florida-specific definitions added by amendment.' },
      { n: 4, t: 'General', s: 'Goals, objectives, and fundamental life safety requirements for all occupancies.' },
      { n: 5, t: 'Performance-Based Option', s: 'Engineering-based alternative compliance path.' },
      { n: 6, t: 'Classification of Occupancy & Hazard of Contents', s: 'Occupancy classification and content hazard levels — the starting point of every inspection.' },
      { n: 7, t: 'Means of Egress', s: 'The core egress chapter: components, capacity, arrangement, travel distance, exit marking, and lighting.' },
      { n: 8, t: 'Features of Fire Protection', s: 'Construction compartmentation, vertical openings, smoke barriers, and protection of hazards.' },
      { n: 9, t: 'Building Service & Fire Protection Equipment', s: 'Utilities, HVAC, elevators, alarms, sprinklers, and extinguishment requirements by reference.' },
      { n: 10, t: 'Interior Finish, Contents & Furnishings', s: 'Flame-spread classifications, decorations, and furnishing requirements.' },
      { n: 11, t: 'Special Structures & High-Rise Buildings', s: 'Towers, underground structures, piers, and high-rise provisions.' },
      { n: 12, t: 'New Assembly Occupancies', s: 'Theaters, restaurants, bars, churches, arenas — 50+ occupants, new construction.' },
      { n: 13, t: 'Existing Assembly Occupancies', s: 'The same assembly uses in existing buildings — what you\u2019ll cite on most assembly inspections.' },
      { n: 14, t: 'New Educational Occupancies', s: 'New K-12 schools: egress, alarms, and corridor protection.' },
      { n: 15, t: 'Existing Educational Occupancies', s: 'Existing K-12 schools.' },
      { n: 16, t: 'New Day-Care Occupancies', s: 'New day-care centers — staff ratios, egress, and alarm requirements by client count.' },
      { n: 17, t: 'Existing Day-Care Occupancies', s: 'Existing day-care facilities.' },
      { n: 18, t: 'New Health Care Occupancies', s: 'New hospitals and nursing homes — defend-in-place design.' },
      { n: 19, t: 'Existing Health Care Occupancies', s: 'Existing hospitals and nursing homes.' },
      { n: 20, t: 'New Ambulatory Health Care', s: 'New outpatient surgical and treatment centers.' },
      { n: 21, t: 'Existing Ambulatory Health Care', s: 'Existing outpatient facilities.' },
      { n: 22, t: 'New Detention & Correctional', s: 'New jails and detention facilities — locked egress with staff release.' },
      { n: 23, t: 'Existing Detention & Correctional', s: 'Existing detention facilities.' },
      { n: 24, t: 'One- & Two-Family Dwellings', s: 'Dwelling egress and smoke alarm requirements.' },
      { n: 26, t: 'Lodging or Rooming Houses', s: 'Small lodging operations (16 or fewer occupants).' },
      { n: 28, t: 'New Hotels & Dormitories', s: 'New transient lodging — corridors, alarms, and sprinklers.' },
      { n: 29, t: 'Existing Hotels & Dormitories', s: 'Existing hotels, motels, and dorms.' },
      { n: 30, t: 'New Apartment Buildings', s: 'New multifamily residential.' },
      { n: 31, t: 'Existing Apartment Buildings', s: 'Existing multifamily — including Florida high-rise retrofit provisions.' },
      { n: 32, t: 'New Residential Board & Care', s: 'New assisted living and group homes — evacuation capability drives requirements.' },
      { n: 33, t: 'Existing Residential Board & Care', s: 'Existing ALFs and group homes — a frequent Florida inspection target.' },
      { n: 36, t: 'New Mercantile Occupancies', s: 'New retail — Class A/B/C by floor area, egress, and storage separation.' },
      { n: 37, t: 'Existing Mercantile Occupancies', s: 'Existing retail stores.' },
      { n: 38, t: 'New Business Occupancies', s: 'New offices and service businesses.' },
      { n: 39, t: 'Existing Business Occupancies', s: 'Existing offices — your bread-and-butter routine inspection chapter.' },
      { n: 40, t: 'Industrial Occupancies', s: 'Factories and processing — general, special-purpose, and high-hazard industrial.' },
      { n: 42, t: 'Storage Occupancies', s: 'Warehouses, parking structures as storage, and aircraft storage hangars.' },
      { n: 43, t: 'Building Rehabilitation', s: 'Repair, renovation, modification, change of use — which rules apply when buildings change.' },
    ],
  },
];

// Florida Building Code — cross-reference volume. NOT inspection authority: the FBC governs how
// buildings are constructed; the FFPC governs fire prevention inspections. Included so inspectors
// can understand WHY a building is built the way it is. Fire-relevant chapters only; index + scope
// notes (full text is ICC/Florida Building Commission copyrighted).
const PM_FBC_VOLUMES = [
  {
    id: 'fbcb',
    title: 'Florida Building Code — Building',
    sub: 'Construction requirements · fire-relevant chapters · 8th Edition (2023)',
    short: 'FBC',
    askName: 'the Florida Building Code',
    startOpen: true,
    chapters: [
      { n: 3, t: 'Occupancy Classification & Use', s: 'The FBC’s occupancy groups (A, B, E, F, H, I, M, R, S, U). These don’t map one-to-one onto NFPA 101 occupancy chapters — when classifications seem to conflict, that’s an AHJ coordination question, not a coin flip.' },
      { n: 4, t: 'Special Detailed Requirements', s: 'Extra construction rules for special uses: high-rises, atriums, covered malls, stages, hospitals. Explains unusual features you’ll encounter — smoke control, fire command centers, atrium separation.' },
      { n: 5, t: 'General Building Heights & Areas', s: 'Why the building is the size it is: allowable height and area by construction type and occupancy, including the sprinkler increases that may be the entire reason the building is sprinklered.' },
      { n: 6, t: 'Types of Construction', s: 'Type I–V construction: what the structure is built of and the fire-resistance it owes. Context for any question about whether a wall, floor, or column was supposed to be rated.' },
      { n: 7, t: 'Fire & Smoke Protection Features', s: 'Where wall and barrier ratings come from: fire walls, fire barriers, partitions, shaft enclosures, and opening protectives (door/damper ratings). The construction-side companion to your FFPC Ch. 12 inspection.' },
      { n: 8, t: 'Interior Finishes', s: 'Flame-spread and smoke-developed classes required at construction — cross-check against NFPA 101 Ch. 10 when finish materials look wrong for the occupancy.' },
      { n: 9, t: 'Fire Protection & Life Safety Systems', s: 'Where sprinklers, standpipes, and alarms were REQUIRED when the building was built or renovated. Answers “should this building even have a system?” — your ITM inspection of that system stays under FFPC Ch. 13.' },
      { n: 10, t: 'Means of Egress', s: 'Egress as designed at construction. Where FBC and NFPA 101 differ on an existing building, the conflict goes to the AHJ — flag it rather than picking a side.' },
      { n: 33, t: 'Safeguards During Construction', s: 'The construction-side rules for active job sites — pairs with FFPC Ch. 16 when you inspect buildings under construction or renovation.' },
    ],
  },
];

// Resolve a citation like "NFPA 1-FL §13.6.5.2" to the exact chapter to open.
// Returns { entry } to expand a chapter, or { q } to fall back to a text search.
function pmCiteTarget(cite) {
  const s = String(cite || '').trim();
  const nf = s.match(/NFPA\s*(\d+)/i);
  const sec = s.match(/[§\u00a7]\s*(\d+)/);
  if (nf) {
    const num = nf[1];
    const volId = num === '1' ? 'vol1' : num === '101' ? 'vol2' : null;
    if (volId) {
      const vol = PM_FFPC_VOLUMES.find((v) => v.id === volId);
      const chN = sec ? Number(sec[1]) : null;
      if (vol && chN && vol.chapters.some((ch) => ch.n === chN)) {
        return { entry: volId + '-' + chN, q: '' };
      }
      // Known volume, unknown/absent chapter — open the volume rather than guess.
      return { entry: null, q: num === '1' ? 'NFPA 1-FL' : 'NFPA 101-FL' };
    }
    return { entry: null, q: 'NFPA ' + num }; // standalone standard (NFPA 13, 25, 72...)
  }
  if (/\bguide\b/i.test(s)) return { entry: null, q: 'Guide' };
  if (/\bFBC\b/i.test(s)) return { entry: null, q: 'Florida Building Code' };
  return { entry: null, q: s };
}

Object.assign(window, { PM_FFPC_VOLUMES, PM_FBC_VOLUMES, pmCiteTarget });
