/* spatial.jsx — v0.5 typology JSON for intelligence dashboard
   ============================================================
   Per session debrief Section D — manually curated from public industry
   sources + Rootherhub BIA. RSMeans excluded (licensing). Neufert is not
   a database; this is the path forward.

   v0.3 covers Padel, Restaurant, Hotel (the three the dashboard does
   honest math on). Other typologies fall back to a "spatial reality
   check available v0.5" placeholder while still rendering capex/schedule.

   v0.5 additions (May 13 2026):
   - REGIONAL_TIERS map (A+ down to D) with cost multipliers
   - regionTierFromLatLng() heuristic for auto-resolution
   - BRACKET_SCHEDULE_SCALE — fixes "12 → 72 month" bracket-naive math
   - BRACKET_CAPEX_SCALE — economy-of-scale multiplier

   Library audit May 13 2026:
   - Padel benchmarks: VERIFIED against FIP public ranges ✓
   - Restaurant casual/fine $/m²: VERIFIED against Turner & Townsend ✓
   - Hotel limited/full-service $/key: VERIFIED against HVS published ✓
   - Hotel luxury $/key: real but overlaps full-service at low end —
     this is correct (luxury starts where full-service tops out)
   - No broken data found. Gap is BREADTH (39 typologies missing), not
     CORRECTNESS (existing data is honest).

   Schema (from spec):
     typology, size_brackets, spatial_units, ancillary, lighting,
     adjacency_rules, operational_kpis, components (v2 reserved),
     source_citations
*/

const SPATIAL = {
  /* ───────────── PADEL ─────────────
     FIP-regulated, fully public source. Anchor reliably.
  */
  padel: {
    typology: 'padel',
    label: 'Padel Court Club',
    size_brackets: {
      XS: { courts: 1,        approx_m2: 320,    seats_bar: 0   },
      S:  { courts_range:[2,4], approx_m2_range:[640,1100], seats_bar_range:[20,40]  },
      M:  { courts_range:[4,8], approx_m2_range:[1100,2200], seats_bar_range:[40,80]  },
      L:  { courts_range:[8,14], approx_m2_range:[2200,3800], seats_bar_range:[60,120] },
      XL: { courts_min:14,    approx_m2_min:3800, seats_bar_range:[80,180] },
    },
    spatial_units: {
      court_play_area_m2: 200,           /* 20m × 10m FIP regulation */
      court_with_buffer_m2: 231,         /* +0.5m perimeter */
      court_recommended_m2: 280,         /* with 1.5m clearance, indoor */
      ceiling_min_m: 6,
      ceiling_recommended_m: 7.5,
      ceiling_ideal_m: 10,
      court_separation_m: 2.5,
      min_site_single_court_m: { length: 25, width: 15 },
    },
    ancillary: {
      reception_m2: { min: 12, typical: 22 },
      lockers_m2_per_court: { min: 8, typical: 14 },
      pro_shop_m2: { min: 20, typical: 28 },
      bar_foh_per_seat_m2: 1.4,
      bar_boh_pct_of_foh: 0.40,
      circulation_pct: 0.18,
    },
    lighting: {
      recreational_lux: 400,
      club_lux: 600,
      tournament_lux: 1000,
    },
    adjacency_rules: [
      { rule: 'separate court access from bar/social entrance', priority: 'recommended', source: 'industry standard operational flow' },
      { rule: 'lockers between reception and courts', priority: 'required' },
      { rule: 'pro shop visible from reception', priority: 'recommended' },
      { rule: 'bar overlooks at least one court', priority: 'preferred' },
    ],
    operational_kpis: {
      court_utilization_peak_pct: 85,
      court_utilization_avg_pct: 45,
      bar_revenue_pct_of_total: 22,
      staff_per_court_at_peak: 0.4,
    },
    cost_benchmarks_usd: {
      court_construction_per_court: { low: 38000, mid: 55000, high: 85000 },
      ancillary_construction_per_m2: { low: 1800, mid: 2600, high: 3800 },
      ffe_per_court: { low: 4000, mid: 7000, high: 12000 },
      bar_ffe_per_seat: { low: 800, mid: 1400, high: 2400 },
    },
    schedule_months: {
      permitting: { low: 2, typical: 4, high: 8 },
      construction: { low: 4, typical: 6, high: 10 },
      ffe_lead: { low: 2, typical: 3, high: 5 },
      operational_ramp: { low: 1, typical: 2, high: 3 },
    },
    components: {
      v0_status: 'deferred to v2',
      v2_target_categories: ['equipment_specifications', 'fixture_placements', 'mep_integration_points'],
      v2_data_format: 'IFC-compatible JSON',
    },
    source_citations: [
      'FIP padel court regulations (public)',
      'Rootherhub BIA library',
      'Public industry compilations on multi-court club operations',
    ],
  },

  /* ───────────── RESTAURANT ─────────────
     Industry-standard ratios, fully public.
  */
  restaurant: {
    typology: 'restaurant',
    label: 'Restaurant',
    size_brackets: {
      XS: { seats_range:[14, 32]  },
      S:  { seats_range:[32, 80]  },
      M:  { seats_range:[80, 140] },
      L:  { seats_range:[140, 220]},
      XL: { seats_min: 220        },
    },
    spatial_units: {
      per_seat_m2: { casual: 1.25, fine: 1.85, fast_casual: 1.05 },
      kitchen_per_foh_seat_m2: 0.46, /* 5 sq ft per seat baseline */
      bar_within_per_stool_m2: { min: 0.6, typical: 1.0 },
      outdoor_seat_addl_m2: { min: 0.93, typical: 1.5 },
    },
    /* v0.9.4 (2026-11-14) — stores and staff rooms, read on the page.
       Neufert 4th ed. p175: for storerooms, staff rooms and the like add about 80% to
       the kitchen area. p179 agrees: a whole kitchen with stores, wash-up and office
       runs 1.3 to 1.675 m² per seat at 80 seats. Before this the Brain added only a
       storage percentage (7 to 10%) and no staff rooms, so the back of house came out
       25 to 40% small. Applied to every restaurant leaf except the food truck, which
       has no dining building and is handled separately. See docs/sources-index.md.
       A GUIDELINE, never a constraint (Jair, 2026-11-14): it sizes the default
       program. When the owner states their own back of house, theirs is used, and
       a bonded brief has its own workflow for settling it. */
    support_of_kitchen: 0.8,
    support_exempt: ['rest_foodtruck'],
    /* v0.9 — per-leaf restaurant profiles. FoH m²/seat + kitchen m²/seat (Neufert: kitchen
       scales with customer seats, 4th ed. p.174-178) + storage/restroom % of (FoH+kitchen).
       Split emerges from these — fine dining is FoH+kitchen heavy, QSR/truck kitchen-dense. */
    leaf_profiles: {
      rest_seafood:   { unit:'seats',  label:'Seafood · destination', per_seat_m2:1.7, kitchen_per_seat_m2:0.65, storage_pct:0.09, restrooms_pct:0.05 },
      rest_fine:      { unit:'seats',  label:'Fine dining',           per_seat_m2:2.0, kitchen_per_seat_m2:0.75, storage_pct:0.08, restrooms_pct:0.05 },
      rest_design:    { unit:'seats',  label:'Design restaurant',     per_seat_m2:1.9, kitchen_per_seat_m2:0.55, storage_pct:0.07, restrooms_pct:0.05 },
      rest_origen:    { unit:'seats',  label:'Gastro hub · origen',   per_seat_m2:1.6, kitchen_per_seat_m2:0.55, storage_pct:0.10, restrooms_pct:0.05 },
      rest_market:    { unit:'seats',  label:'Food market · stalls',  per_seat_m2:1.4, kitchen_per_seat_m2:0.70, storage_pct:0.10, restrooms_pct:0.05 },
      rest_counter:   { unit:'seats',  label:'Counter · QSR',         per_seat_m2:1.0, kitchen_per_seat_m2:0.55, storage_pct:0.10, restrooms_pct:0.05 },
      rest_franchise: { unit:'seats',  label:'Franchise · casual',    per_seat_m2:1.3, kitchen_per_seat_m2:0.55, storage_pct:0.09, restrooms_pct:0.05 },
      rest_foodtruck: { unit:'covers', label:'Food truck · mobile',   per_seat_m2:0.8, kitchen_per_seat_m2:0.90, storage_pct:0.12, restrooms_pct:0.03 },
    },
    ancillary: {
      foh_to_kitchen_ratio: { full_service: 60/40, qsr: 45/55, fast_casual: 50/50 },
      boh_pct_of_total: { full_service_low: 0.30, full_service_high: 0.40 },
      restrooms_pct: 0.06,
      circulation_pct: 0.15,
    },
    lighting: {
      dining_lux: 200,
      kitchen_lux: 500,
      bar_lux: 150,
    },
    adjacency_rules: [
      { rule: 'kitchen adjacent to dining, no public crossing', priority: 'required' },
      { rule: 'service entrance separate from guest entrance', priority: 'required' },
      { rule: 'restrooms accessible without crossing dining', priority: 'recommended' },
      { rule: 'bar within line-of-sight of host stand', priority: 'preferred' },
    ],
    operational_kpis: {
      seat_turnover_lunch: 1.4,
      seat_turnover_dinner: 1.6,
      seat_turnover_fine_dining: 1.0,
      avg_check_lunch_to_dinner_ratio: 0.65,
    },
    cost_benchmarks_usd: {
      construction_per_m2_casual: { low: 2200, mid: 3200, high: 4800 },
      construction_per_m2_fine: { low: 3800, mid: 5400, high: 8200 },
      kitchen_equipment_per_seat: { low: 1200, mid: 2200, high: 4000 },
      ffe_per_seat: { low: 800, mid: 1600, high: 3200 },
    },
    schedule_months: {
      permitting: { low: 2, typical: 4, high: 9 },
      construction: { low: 3, typical: 5, high: 9 },
      ffe_lead: { low: 2, typical: 4, high: 7 },
      operational_ramp: { low: 1, typical: 2, high: 4 },
    },
    components: {
      v0_status: 'deferred to v2',
      v2_target_categories: ['kitchen_equipment_full_specs', 'walk_in_cooler_sizing', 'fryer_hood_mep'],
      v2_data_format: 'IFC-compatible JSON',
    },
    source_citations: [
      'Neufert Architects Data 4th ed. p.174-178 (restaurant areas, kitchen-per-seat scaling)',
      'Industry compilations (per-seat ratios, FoH/BoH splits)',
      'Public restaurant programming research',
      'Rootherhub BIA library',
    ],
  },

  /* ───────────── HOTEL ─────────────
     Cornell Hotel programming research (Jan A. deRoos), industry compilations.
  */
  hotel: {
    typology: 'hotel',
    label: 'Hotel',
    size_brackets: {
      XS: { keys_range:[6, 18]  },
      S:  { keys_range:[18, 48] },
      M:  { keys_range:[48, 96] },
      L:  { keys_range:[96, 160]},
      XL: { keys_min: 160       },
    },
    spatial_units: {
      gross_per_key_m2: {
        limited_service: 35.3,   /* 380 sq ft */
        full_service: 55.7,      /* 600 sq ft */
        resort: 72.5,            /* 780 sq ft */
      },
      single_room_4star_m2: { total: 40, sleep_only: 15 },
      corridor_single_m: { min: 1.6, max: 1.8 },
      corridor_double_m: { min: 1.8, max: 2.4 },
      elevator_ratio: { budget_keys_per_lift: 90, luxury_keys_per_lift: 55 },
    },
    /* v0.9 — per-leaf hotel profiles (gross m²/unit + program split).
       Neufert DEHOGA room areas (4th ed. p.171) + Cornell·deRoos gross/key + HVS class ratios.
       pcts (rooms/public/fb/boh) sum to 1.0; fb_pct:0 drops the F&B segment. */
    leaf_profiles: {
      hotel_boutique:  { unit:'keys',  label:'Boutique · full-service',   gross_per_key_m2: 56, rooms_pct:0.52, public_pct:0.22, fb_pct:0.14, boh_pct:0.12 },
      hotel_signature: { unit:'keys',  label:'Signature brand · full',     gross_per_key_m2: 62, rooms_pct:0.50, public_pct:0.22, fb_pct:0.16, boh_pct:0.12 },
      hotel_franchise: { unit:'keys',  label:'Franchise · select-service', gross_per_key_m2: 42, rooms_pct:0.72, public_pct:0.13, fb_pct:0.06, boh_pct:0.09 },
      hotel_guesthouse:{ unit:'rooms', label:'Guest House · residential',  gross_per_key_m2: 38, rooms_pct:0.75, public_pct:0.15, fb_pct:0.05, boh_pct:0.05 },
      hotel_hostal:    { unit:'beds',  label:'Hostal · bed-led',           gross_per_key_m2: 20, rooms_pct:0.58, public_pct:0.25, fb_pct:0.10, boh_pct:0.07 },
      hotel_airbnb:    { unit:'units', label:'Short-stay · self-check-in', gross_per_key_m2: 48, rooms_pct:0.88, public_pct:0.12, fb_pct:0.00, boh_pct:0.00 },
    },
    ancillary: {
      guest_rooms_pct: { luxury_low: 0.50, luxury_high: 0.60, limited_low: 0.85, limited_high: 0.90 },
      public_areas_pct: { low: 0.04, high: 0.12 },
      function_rooms_pct: { low: 0.04, high: 0.12 },
      back_of_house_pct: { low: 0.09, high: 0.14 },
      administration_pct: { low: 0.01, high: 0.02 },
    },
    lighting: {
      lobby_lux: 200,
      corridor_lux: 100,
      guest_room_ambient_lux: 100,
      function_room_lux: 300,
    },
    adjacency_rules: [
      { rule: 'BoH route never crosses guest path', priority: 'required' },
      { rule: 'lobby visible from registration on entry', priority: 'required' },
      { rule: 'function rooms adjacent to pre-function gather space', priority: 'recommended' },
      { rule: 'spa/pool/fitness clustered in single ancillary core', priority: 'preferred' },
    ],
    operational_kpis: {
      adr_target_by_class: 'derived per region',
      occupancy_break_even_pct: 62,
      staff_per_key_full_service: 0.85,
      staff_per_key_limited: 0.30,
    },
    cost_benchmarks_usd: {
      construction_per_key_limited: { low: 95000, mid: 145000, high: 220000 },
      construction_per_key_full: { low: 220000, mid: 380000, high: 620000 },
      construction_per_key_luxury: { low: 620000, mid: 1100000, high: 2400000 },
      ffe_per_key: { low: 18000, mid: 38000, high: 95000 },
    },
    schedule_months: {
      permitting: { low: 4, typical: 8, high: 18 },
      construction: { low: 14, typical: 22, high: 36 },
      ffe_lead: { low: 4, typical: 7, high: 12 },
      operational_ramp: { low: 2, typical: 4, high: 8 },
    },
    components: {
      v0_status: 'deferred to v2',
      v2_target_categories: ['key_module_libraries', 'public_area_kits', 'mep_risers'],
      v2_data_format: 'IFC-compatible JSON',
    },
    source_citations: [
      'Neufert Architects Data 4th ed. p.170-173 (DEHOGA room areas, hotel categories)',
      'Cornell Hotel programming research (Jan A. deRoos)',
      'Public industry compilations on hotel ratios',
      'Rootherhub BIA library',
    ],
  },

  /* ───────────── BARS ─────────────
     Neufert catering/bars (food bar + fixed stools, counters m²/person, public-house
     toilets, p.174-178) + industry nightlife programming. Bars = seat/stool + standing
     FoH; small bar-back service (no full kitchen); storage swings with beverage program. */
  bar: {
    typology: 'bar',
    label: 'Bar',
    size_brackets: {
      XS: { seats_range:[10, 30]  },
      S:  { seats_range:[30, 70]  },
      M:  { seats_range:[70, 120] },
      L:  { seats_range:[120, 200]},
      XL: { seats_min: 200        },
    },
    spatial_units: {
      bar_counter_per_stool_m2: { min: 0.6, typical: 1.0 },
      standing_per_patron_m2: { min: 0.5, typical: 0.8 },
      lounge_seat_m2: { min: 1.4, typical: 1.8 },
    },
    /* v0.9 — per-leaf bar profiles. per_seat = FoH (bar floor + seating + standing);
       service = bar-back/prep/glasswash (small, no full kitchen); storage = cellar/kegs;
       restrooms % of (FoH+service). 'Bar & service' replaces 'Kitchen' in the split. */
    leaf_profiles: {
      bar_beergarden: { unit:'seats', label:'Beer garden · outdoor',  per_seat_m2:1.6, service_per_seat_m2:0.25, storage_pct:0.12, restrooms_pct:0.06 },
      bar_cocktail:   { unit:'seats', label:'Cocktail · mixology',     per_seat_m2:1.4, service_per_seat_m2:0.45, storage_pct:0.10, restrooms_pct:0.05 },
      bar_wine:       { unit:'seats', label:'Wine bar · enoteca',      per_seat_m2:1.3, service_per_seat_m2:0.30, storage_pct:0.18, restrooms_pct:0.05 },
      bar_speakeasy:  { unit:'seats', label:'Speakeasy · lounge',      per_seat_m2:1.5, service_per_seat_m2:0.40, storage_pct:0.10, restrooms_pct:0.05 },
      bar_karaoke:    { unit:'seats', label:'Karaoke · private rooms', per_seat_m2:2.2, service_per_seat_m2:0.20, storage_pct:0.08, restrooms_pct:0.06 },
      bar_experience: { unit:'seats', label:'Experience · immersive',  per_seat_m2:1.8, service_per_seat_m2:0.35, storage_pct:0.12, restrooms_pct:0.05 },
      bar_signature:  { unit:'seats', label:'Signature franchise',     per_seat_m2:1.3, service_per_seat_m2:0.35, storage_pct:0.10, restrooms_pct:0.05 },
    },
    ancillary: {
      bar_back_pct_of_foh: { min: 0.15, typical: 0.25 },
      circulation_pct: 0.16,
    },
    lighting: {
      bar_lux: 150,
      lounge_lux: 80,
      back_bar_lux: 300,
    },
    adjacency_rules: [
      { rule: 'cellar / keg store adjacent to bar-back, no public crossing', priority: 'required' },
      { rule: 'restrooms accessible without crossing the bar floor', priority: 'recommended' },
      { rule: 'service entrance separate from guest entrance', priority: 'required' },
      { rule: 'karaoke / private rooms acoustically isolated from main bar', priority: 'required' },
    ],
    operational_kpis: {
      seat_turnover_evening: 2.0,
      beverage_revenue_pct_of_total: 80,
      staff_per_50_seats_peak: 4,
    },
    cost_benchmarks_usd: {
      construction_per_m2: { low: 2000, mid: 3000, high: 5200 },
      bar_fitout_per_linear_m: { low: 3500, mid: 6500, high: 14000 },
      ffe_per_seat: { low: 700, mid: 1500, high: 3400 },
    },
    schedule_months: {
      permitting: { low: 2, typical: 4, high: 9 },
      construction: { low: 2, typical: 4, high: 8 },
      ffe_lead: { low: 2, typical: 3, high: 6 },
      operational_ramp: { low: 1, typical: 2, high: 3 },
    },
    components: {
      v0_status: 'deferred to v2',
      v2_target_categories: ['bar_back_equipment', 'cellar_cooling', 'av_acoustic_isolation'],
      v2_data_format: 'IFC-compatible JSON',
    },
    source_citations: [
      'Neufert Architects Data 4th ed. p.174-178 (food bar, counters, public-house facilities)',
      'Industry compilations (bar / nightlife per-seat ratios, beverage program)',
      'Rootherhub BIA library',
    ],
  },

  /* ───────────── FITNESS & SPORT (padel has its own richer entry) ─────────────
     Neufert Sports Halls / Conditioning & Fitness / Climbing Halls (p.356-360):
     fitness floor ~4.5 m²/person (200 m² for 40-45, 3.0 m ceiling); climbing up to
     2500 m² indoor; tennis court ~360 m² indoor with run-off. Gross/unit adds support
     (changing/recovery) + equipment + reception. basis = how the bracket counts. */
  fitness: {
    typology: 'fitness',
    label: 'Fitness & Sport',
    size_brackets: {
      XS: { athletes_range:[10, 30]  },
      S:  { athletes_range:[30, 70]  },
      M:  { athletes_range:[70, 130] },
      L:  { athletes_range:[130, 220]},
      XL: { athletes_min: 220        },
    },
    spatial_units: {
      conditioning_floor_m2_per_person: 4.5,
      conditioning_min_ceiling_m: 3.0,
      tennis_court_indoor_m2: 360,
      climbing_hall_max_m2: 2500,
      hyrox_lane_m: { length: 10, width: 1.0 },   /* adjustable; classes module around moving parts */
      concept2_footprint_m2: { skierg: 1.0, rowerg: 2.4, bikeerg: 1.2 },
    },
    /* v0.9 — per-leaf fitness profiles. basis = bracket counting unit (courts vs athletes).
       gross_per_unit_m2 × count = gross; split activity / support / equipment / reception (sum 1.0). */
    leaf_profiles: {
      /* tightened per operator: functional boxes module classes around the moving parts.
         HYROX ~200 m²/15-20 athletes (~12); CrossFit compact box (~9); Boxing ~11. Tennis
         fixed by court geometry. See spatial_units for Concept2 ergs + 10x1 m adjustable lanes. */
      hyrox:    { unit:'athletes', basis:'athletes', label:'HYROX · stations',    gross_per_unit_m2:12,  activity_pct:0.66, support_pct:0.18, equip_pct:0.10, reception_pct:0.06 },
      tennis:   { unit:'courts',   basis:'courts',   label:'Tennis · courts',     gross_per_unit_m2:360, activity_pct:0.72, support_pct:0.14, equip_pct:0.06, reception_pct:0.08 },
      crossfit: { unit:'athletes', basis:'athletes', label:'CrossFit · box',      gross_per_unit_m2:9,   activity_pct:0.68, support_pct:0.16, equip_pct:0.10, reception_pct:0.06 },
      boxing:   { unit:'athletes', basis:'athletes', label:'Boxing · ring+bags',  gross_per_unit_m2:11,  activity_pct:0.66, support_pct:0.18, equip_pct:0.10, reception_pct:0.06 },
      climbing: { unit:'climbers', basis:'athletes', label:'Climbing · walls',    gross_per_unit_m2:16,  activity_pct:0.68, support_pct:0.16, equip_pct:0.10, reception_pct:0.06 },
    },
    ancillary: {
      changing_lockers_pct: 0.12,
      recovery_pct: { min: 0.04, typical: 0.08 },
      circulation_pct: 0.16,
    },
    lighting: {
      training_lux: 300,
      court_lux: 500,
      climbing_lux: 300,
    },
    adjacency_rules: [
      { rule: 'changing / showers between reception and activity floor', priority: 'required' },
      { rule: 'equipment store adjacent to activity floor', priority: 'recommended' },
      { rule: 'reception oversees activity floor (~15 m sightline, Neufert)', priority: 'recommended' },
      { rule: 'climbing fall-zone matting clear of circulation', priority: 'required' },
    ],
    operational_kpis: {
      peak_concurrent_to_member_ratio: 0.10,
      floor_utilization_peak_pct: 80,
      staff_per_50_athletes_peak: 3,
    },
    cost_benchmarks_usd: {
      construction_per_m2: { low: 1600, mid: 2400, high: 4200 },
      court_construction_per_court: { low: 30000, mid: 48000, high: 78000 },
      equipment_per_athlete_capacity: { low: 600, mid: 1400, high: 3200 },
    },
    schedule_months: {
      permitting: { low: 2, typical: 4, high: 9 },
      construction: { low: 3, typical: 5, high: 10 },
      ffe_lead: { low: 2, typical: 4, high: 8 },
      operational_ramp: { low: 1, typical: 2, high: 4 },
    },
    components: {
      v0_status: 'deferred to v2',
      v2_target_categories: ['rig_equipment_libraries', 'climbing_wall_geometry', 'court_systems'],
      v2_data_format: 'IFC-compatible JSON',
    },
    source_citations: [
      'Neufert Architects Data 4th ed. p.356-360 (Sports Halls, Conditioning & Fitness, Climbing Halls)',
      'Industry compilations (training-floor density, club capacity ratios)',
      'Rootherhub BIA library',
    ],
  },

  /* ───────────── WELLNESS (spa · thermal · recovery · meditation · hammam) ─────────────
     Neufert Spa/Sauna/Wellness (p.372: sauna + massage + relaxation + changing + subsidiary)
     + Swimming Pools/thermal (p.362: changing 0.3-0.4 m²/m² water). Heterogeneous → capacity
     (concurrent guests) × m²/guest. Split: treatment/practice · wet & thermal · changing &
     relaxation · reception & BoH. wet_pct:0 drops the wet segment (dry studios). */
  wellness: {
    typology: 'wellness',
    label: 'Wellness',
    size_brackets: {
      XS: { guests_range:[10, 25]  },
      S:  { guests_range:[25, 50]  },
      M:  { guests_range:[50, 90]  },
      L:  { guests_range:[90, 150] },
      XL: { guests_min: 150        },
    },
    spatial_units: {
      treatment_room_m2: { min: 12, typical: 16 },
      changing_per_m2_water: { min: 0.3, max: 0.4 },
      sauna_cabin_m2: { min: 8, typical: 14 },
      relaxation_per_guest_m2: { min: 1.8, typical: 2.5 },
    },
    leaf_profiles: {
      spa:        { unit:'guests', basis:'guests', label:'Spa · treatment',     gross_per_unit_m2:18, treatment_pct:0.45, wet_pct:0.15, support_pct:0.28, reception_pct:0.12 },
      thermal:    { unit:'guests', basis:'guests', label:'Thermal baths',       gross_per_unit_m2:12, treatment_pct:0.20, wet_pct:0.50, support_pct:0.22, reception_pct:0.08 },
      recovery:   { unit:'guests', basis:'guests', label:'Recovery · stations', gross_per_unit_m2:14, treatment_pct:0.50, wet_pct:0.08, support_pct:0.30, reception_pct:0.12 },
      meditation: { unit:'guests', basis:'guests', label:'Meditation · studio', gross_per_unit_m2:6,  treatment_pct:0.62, wet_pct:0.00, support_pct:0.28, reception_pct:0.10 },
      hammam:     { unit:'guests', basis:'guests', label:'Hammam · steam',      gross_per_unit_m2:10, treatment_pct:0.20, wet_pct:0.45, support_pct:0.23, reception_pct:0.12 },
    },
    ancillary: {
      changing_lockers_pct: 0.12,
      relaxation_pct: { min: 0.12, typical: 0.18 },
      circulation_pct: 0.14,
    },
    lighting: {
      treatment_lux: 150,
      relaxation_lux: 80,
      wet_area_lux: 200,
      reception_lux: 200,
    },
    adjacency_rules: [
      { rule: 'changing / showers between reception and wet/treatment zones', priority: 'required' },
      { rule: 'wet and dry circuits separated; barefoot zone continuous', priority: 'required' },
      { rule: 'relaxation adjacent to treatment/sauna, away from reception noise', priority: 'recommended' },
      { rule: 'plant / heating room adjacent to wet zone, no guest crossing', priority: 'required' },
    ],
    operational_kpis: {
      peak_concurrent_to_capacity_pct: 70,
      treatment_utilization_peak_pct: 80,
      staff_per_30_guests_peak: 3,
    },
    cost_benchmarks_usd: {
      construction_per_m2_dry: { low: 2200, mid: 3400, high: 5600 },
      construction_per_m2_wet: { low: 3800, mid: 6000, high: 11000 },
      equipment_per_treatment_room: { low: 8000, mid: 18000, high: 42000 },
    },
    schedule_months: {
      permitting: { low: 2, typical: 4, high: 9 },
      construction: { low: 4, typical: 7, high: 12 },
      ffe_lead: { low: 3, typical: 5, high: 9 },
      operational_ramp: { low: 1, typical: 3, high: 5 },
    },
    components: {
      v0_status: 'deferred to v2',
      v2_target_categories: ['wet_area_waterproofing', 'sauna_cabin_kits', 'plant_room_mep'],
      v2_data_format: 'IFC-compatible JSON',
    },
    source_citations: [
      'Neufert Architects Data 4th ed. p.362-372 (Swimming Pools, Spa / Sauna / Wellness)',
      'Industry compilations (spa programming, treatment-room ratios)',
      'Rootherhub BIA library',
    ],
  },
};

/* Climate impact heuristics (per session debrief — capex/timeline adjustments by climate × typology) */
const CLIMATE_IMPACT = {
  freeze_thaw: { capex_pct: 0.04, schedule_months: 1, note: 'Foundation depth + insulation upgrade' },
  hurricane:   { capex_pct: 0.06, schedule_months: 1, note: 'Wind-load structural premium' },
  coastal_salt:{ capex_pct: 0.05, schedule_months: 0, note: 'Material durability spec — stainless, marine-grade' },
  seismic:     { capex_pct: 0.08, schedule_months: 2, note: 'Lateral system + non-structural bracing' },
  arid_heat:   { capex_pct: 0.03, schedule_months: 0, note: 'Cooling load + envelope thermal mass' },
  tropical_humid: { capex_pct: 0.04, schedule_months: 0, note: 'Mold resilience + dehumidification' },
};

/* Coarse latitude-based climate flags — v0.3, refine with proper zone DB later. */
const climateFlagsFromLatLng = (lat, lng) => {
  if (lat == null) return [];
  const flags = [];
  const a = Math.abs(lat);
  if (a > 38) flags.push('freeze_thaw');
  if (a < 30 && (lng > -90 && lng < -60)) flags.push('hurricane'); /* Atlantic basin */
  /* v0.9.1: one heat flag per site. Before, every tropical site was charged both (+7%). */
  if (a < 23.5) flags.push('tropical_humid');
  else if (a < 35) flags.push('arid_heat');
  /* Coastal salt — left to where-fold to flag explicitly via site-type. */
  return flags;
};

/* ─────────────────────────────────────────────────────────────
   REGIONAL COST TIERS — v0.5 (added May 13 2026)
   Public-sourced construction cost multipliers vs. a US-A baseline (1.0).
   Sources: Turner & Townsend ICC Report, Arcadis IRCC, Rider Levett
   Bucknall, JLL Construction Outlook — averaged. Treat as
   ±15% accurate — designed for concept-phase provocation, not procurement.

   Tier definition:
     A+ : 1.7×  (Tokyo, NYC, London, San Francisco, Hong Kong, Zurich)
     A  : 1.0×  (US baseline — Madrid, Mexico City CBD, Austin, Berlin, Paris secondary)
     B  : 0.78× (Guadalajara, Buenos Aires, Lisbon, Athens, Mexico secondary, US tertiary)
     C  : 0.55× (Oaxaca, smaller Mexican cities, Bogotá, Bali, smaller LatAm capitals)
     D  : 0.40× (rural Mexico, rural LatAm, low-cost-of-construction markets)

   Toggle in Band 03 lets visitor preview different tiers without re-pin.
   Resolution via lat/lng is coarse on purpose — visitor can override. */
const REGIONAL_TIERS = {
  'A+': { label: 'A+ · TIER 1 GLOBAL', mult: 1.70, note: 'Tokyo · NYC · London · SF · HK · Zurich tier — highest global construction costs' },
  'A':  { label: 'A · US BASELINE',    mult: 1.00, note: 'Madrid · CDMX · Austin · Berlin · Paris secondary — US/EU baseline' },
  'B':  { label: 'B · NEAR-MARKET',    mult: 0.78, note: 'Guadalajara · Buenos Aires · Lisbon · Athens — near-market cost basis' },
  'C':  { label: 'C · EMERGING',       mult: 0.55, note: 'Oaxaca · Mexico secondary · Bogotá · Bali — emerging market basis' },
  'D':  { label: 'D · LOW-COST',       mult: 0.40, note: 'Rural construction · low-cost markets — directional only' },
};

/* Coarse lat/lng → regional tier lookup. v0.5 heuristic.
   Anchored on a handful of named city zones; everywhere else falls back to
   continent-level tier averages. Visitor can override via the toggle. */
const regionTierFromLatLng = (lat, lng) => {
  if (lat == null || lng == null) return 'A';
  /* A+ city zones — small boxes around the highest-cost metros */
  const APLUS_ZONES = [
    { name: 'NYC',    lat: [40.5, 41.0],  lng: [-74.3, -73.6] },
    { name: 'SF',     lat: [37.6, 37.9],  lng: [-122.6, -122.3] },
    { name: 'London', lat: [51.3, 51.7],  lng: [-0.5, 0.3] },
    { name: 'Tokyo',  lat: [35.5, 35.85], lng: [139.5, 139.95] },
    { name: 'HK',     lat: [22.2, 22.5],  lng: [114.0, 114.4] },
    { name: 'Zurich', lat: [47.3, 47.5],  lng: [8.4, 8.7] },
    { name: 'Boston', lat: [42.2, 42.5],  lng: [-71.2, -70.9] },
    { name: 'Paris',  lat: [48.8, 48.95], lng: [2.25, 2.45] }, /* Paris CBD only, secondary drops to A */
  ];
  for (const z of APLUS_ZONES) {
    if (lat >= z.lat[0] && lat <= z.lat[1] && lng >= z.lng[0] && lng <= z.lng[1]) return 'A+';
  }
  /* Crude regional fallbacks by continent / country guess */
  if (lng > -125 && lng < -65 && lat > 24 && lat < 50) return 'A';   /* CONUS */
  if (lng > -10 && lng < 25 && lat > 36 && lat < 60) return 'A';     /* Western EU */
  if (lat > 20 && lat < 33 && lng > -118 && lng < -86) return 'B';   /* Mexico (most), Texas border */
  if (lat > -35 && lat < 15 && lng > -85 && lng < -34) return 'C';   /* South America (most) */
  if (lat > -25 && lat < 25 && lng > 95 && lng < 145) return 'B';    /* SE Asia */
  if (lat > 20 && lat < 50 && lng > 100 && lng < 150) return 'A';    /* East Asia (excl A+ zones) */
  return 'B'; /* default fallback */
};

/* ─────────────────────────────────────────────────────────────
   BRACKET SCALE — fixes the "12 → 72 month" complaint (May 13 2026)
   The schedule_months ranges in SPATIAL are bracket-naive (worst-case
   covers full XL projects). For XS/S brackets, the upper end is misleading.
   This scale multiplies the HIGH end only — low/typical stay anchored. */
const BRACKET_SCHEDULE_SCALE = {
  XS: 0.50, /* tiny projects — high end caps at half of XL high */
  S:  0.70,
  M:  1.00, /* baseline — the schedule_months as-stored matches M */
  L:  1.20,
  XL: 1.40,
};

/* Same idea but for area-based capex amplification.
   Smaller projects have worse $/m² (less economy of scale).
   Larger projects often achieve better $/m² via bulk procurement. */
const BRACKET_CAPEX_SCALE = {
  XS: 1.20, /* +20% — small projects pay overhead penalty */
  S:  1.08,
  M:  1.00,
  L:  0.95,
  XL: 0.90, /* -10% — economies of scale */
};

/* ─────────────────────────────────────────────────────────────
   GREENFIELD / LOT FOOTPRINT DEFAULTS — v0.6 (May 15 2026)
   Default building-footprint-to-lot ratios by country, sourced from
   public zonificación / planning code research:

   - Mexico (RCDF, NOM-CDMX local variants): typical 60-70% for commercial
     hospitality, ~50% in colonias with green-area mandates. Default: 60%.
   - Spain (PGOU municipal codes): ranges 40-60% urban, 30-50% peri-urban.
     Default: 50%.
   - USA (varies by municipality, FAR-driven): typical 50-70% commercial
     suburban, 80%+ urban core. Default: 65% (suburban norm).
   - Japan (kenpei-ritsu): 60% commercial typical, 80% urban core.
     Default: 70%.
   - France (PLU): typical 40-60% Paris secondary. Default: 50%.
   - UK (varies): 50-70% urban, 30-50% green belt. Default: 55%.
   - Italy (rapporto di copertura): 40-60% standard. Default: 50%.
   - Germany (GRZ — Grundflächenzahl): commercial 60-80%. Default: 65%.
   - Argentina (CPU Buenos Aires): 50-65% commercial. Default: 55%.
   - Brazil (taxa de ocupação): 50-70% varies by municipality. Default: 60%.
   - Costa Rica: green-area mandate keeps ~50-55%. Default: 50%.
   - Colombia (POT): 50-65%. Default: 55%.
   - Chile (PRC): 55-70%. Default: 60%.
   - Peru: 60-70% commercial. Default: 65%.
   - Australia (varies by LGA): 50-70%. Default: 60%.
   - Canada (varies by zoning): 40-65%. Default: 55%.
   - Portugal (PDM): 40-55% typical. Default: 50%.
   - Netherlands (BVO): 60-75% urban. Default: 65%.
   - Switzerland (BGF): 50-65%. Default: 55%.
   - Greece: 60-70% urban. Default: 65%.
   - UAE (Dubai municipality): 60-80%. Default: 70%.
   - Singapore (URA): 60-80% commercial. Default: 70%.
   - Thailand: 60-75%. Default: 65%.
   - Indonesia (KDB — Bali specific): 40-60%, eco-tourism ~40%. Default: 50%.
   - Vietnam: 60-75%. Default: 65%.
   - New Zealand: 50-65%. Default: 55%.
   - Uruguay: 55-65%. Default: 60%.
   - Dominican Republic: 60-70%. Default: 65%.

   All defaults marked NOT FOR PERMITTING — verify with local code.
   Each entry includes minRatio + typical + maxRatio so the UI can show
   a range (rare case operator pushes a tight max). */
const LOT_FOOTPRINT_DEFAULTS = {
  MX: { typical: 0.60, min: 0.40, max: 0.70, label: 'Mexico', note: 'RCDF / CDMX zonificación ranges', code_ref: 'RCDF Art. 95 + NOM-CDMX' },
  ES: { typical: 0.50, min: 0.30, max: 0.60, label: 'Spain', note: 'PGOU municipal codes', code_ref: 'Plan General de Ordenación Urbana' },
  US: { typical: 0.65, min: 0.40, max: 0.80, label: 'United States', note: 'Varies by municipality + zoning', code_ref: 'IBC + local zoning ordinance' },
  CA: { typical: 0.55, min: 0.35, max: 0.70, label: 'Canada', note: 'Varies by provincial + municipal zoning', code_ref: 'NBC + provincial codes' },
  JP: { typical: 0.70, min: 0.50, max: 0.80, label: 'Japan', note: 'Kenpei-ritsu — building coverage ratio', code_ref: 'Building Standards Act §53' },
  FR: { typical: 0.50, min: 0.30, max: 0.60, label: 'France', note: 'PLU — Plan Local d\'Urbanisme', code_ref: 'Code de l\'urbanisme' },
  GB: { typical: 0.55, min: 0.35, max: 0.70, label: 'United Kingdom', note: 'Permitted Development + Use Class', code_ref: 'TCPA 1990 + local plans' },
  IT: { typical: 0.50, min: 0.30, max: 0.60, label: 'Italy', note: 'Rapporto di copertura fondiaria', code_ref: 'PRG/PUC comunale' },
  DE: { typical: 0.65, min: 0.40, max: 0.80, label: 'Germany', note: 'GRZ — Grundflächenzahl', code_ref: 'BauNVO §17' },
  AR: { typical: 0.55, min: 0.40, max: 0.65, label: 'Argentina', note: 'CPU Buenos Aires + provincial codes', code_ref: 'CPU' },
  BR: { typical: 0.60, min: 0.40, max: 0.70, label: 'Brazil', note: 'Taxa de ocupação', code_ref: 'Plano Diretor Municipal' },
  CR: { typical: 0.50, min: 0.40, max: 0.55, label: 'Costa Rica', note: 'Green-area mandate keeps coverage moderate', code_ref: 'Reglamento de Construcciones' },
  CO: { typical: 0.55, min: 0.35, max: 0.65, label: 'Colombia', note: 'POT — Plan de Ordenamiento Territorial', code_ref: 'POT municipal' },
  CL: { typical: 0.60, min: 0.40, max: 0.70, label: 'Chile', note: 'PRC — Plan Regulador Comunal', code_ref: 'OGUC' },
  PE: { typical: 0.65, min: 0.45, max: 0.70, label: 'Peru', note: 'RNE — Reglamento Nacional', code_ref: 'RNE A.040' },
  AU: { typical: 0.60, min: 0.40, max: 0.70, label: 'Australia', note: 'Varies by LGA — site coverage controls', code_ref: 'Local LEP/DCP' },
  PT: { typical: 0.50, min: 0.30, max: 0.55, label: 'Portugal', note: 'PDM — Plano Director Municipal', code_ref: 'PDM' },
  NL: { typical: 0.65, min: 0.45, max: 0.75, label: 'Netherlands', note: 'Bestemmingsplan / BVO', code_ref: 'Wet ruimtelijke ordening' },
  CH: { typical: 0.55, min: 0.35, max: 0.65, label: 'Switzerland', note: 'BGF — Geschossflächenziffer', code_ref: 'BZO kantonal' },
  GR: { typical: 0.65, min: 0.40, max: 0.70, label: 'Greece', note: 'Building coverage ratio', code_ref: 'GOK' },
  AE: { typical: 0.70, min: 0.50, max: 0.80, label: 'UAE', note: 'Dubai/Abu Dhabi municipality coverage', code_ref: 'Municipality regulations' },
  SG: { typical: 0.70, min: 0.50, max: 0.80, label: 'Singapore', note: 'URA development control', code_ref: 'URA Master Plan' },
  TH: { typical: 0.65, min: 0.45, max: 0.75, label: 'Thailand', note: 'Land use plan coverage', code_ref: 'Town Planning Act 1975' },
  ID: { typical: 0.50, min: 0.30, max: 0.60, label: 'Indonesia', note: 'KDB — Koefisien Dasar Bangunan, Bali eco-tourism stricter', code_ref: 'PERDA + RDTR' },
  VN: { typical: 0.65, min: 0.45, max: 0.75, label: 'Vietnam', note: 'Building coverage per local plan', code_ref: 'QCVN 01:2021' },
  NZ: { typical: 0.55, min: 0.35, max: 0.65, label: 'New Zealand', note: 'District plan site coverage', code_ref: 'RMA District Plan' },
  UY: { typical: 0.60, min: 0.40, max: 0.65, label: 'Uruguay', note: 'POT departamental', code_ref: 'Ley 18.308' },
  DO: { typical: 0.65, min: 0.45, max: 0.70, label: 'Dominican Republic', note: 'Norma R-007 + municipal', code_ref: 'MOPC R-007' },
};

/* Coarse lat/lng → country code lookup. v0.6 heuristic — coordinate boxes.
   Not perfect but covers the 28 markets above. Falls back to 'unknown' for
   anywhere outside — UI shows ARRIVING v0.7 placeholder. */
const countryCodeFromLatLng = (lat, lng) => {
  if (lat == null || lng == null) return 'unknown';
  /* Americas */
  if (lat > 24 && lat < 50  && lng > -125 && lng < -65) return 'US';
  if (lat > 41 && lat < 70  && lng > -141 && lng < -52) return 'CA';
  if (lat > 14 && lat < 33  && lng > -118 && lng < -86) return 'MX';
  if (lat > 8  && lat < 12  && lng > -86  && lng < -82) return 'CR';
  if (lat > 17 && lat < 20  && lng > -72  && lng < -68) return 'DO';
  if (lat > -5 && lat < 13  && lng > -82  && lng < -66) return 'CO';
  if (lat > -19&& lat < 0   && lng > -82  && lng < -68) return 'PE';
  if (lat > -56&& lat < -17 && lng > -76  && lng < -66) return 'CL';
  if (lat > -56&& lat < -21 && lng > -74  && lng < -53) return 'AR';
  if (lat > -35&& lat < -29 && lng > -59  && lng < -53) return 'UY';
  if (lat > -34&& lat < 6   && lng > -75  && lng < -34) return 'BR';
  /* Europe */
  if (lat > 36 && lat < 44  && lng > -10  && lng < 4)   return 'ES';
  if (lat > 36 && lat < 43  && lng > -10  && lng < -6)  return 'PT';
  if (lat > 42 && lat < 51  && lng > -5   && lng < 9)   return 'FR';
  if (lat > 36 && lat < 47  && lng > 6    && lng < 19)  return 'IT';
  if (lat > 47 && lat < 55  && lng > 6    && lng < 15)  return 'DE';
  if (lat > 49 && lat < 59  && lng > -8   && lng < 2)   return 'GB';
  if (lat > 50 && lat < 54  && lng > 3    && lng < 7)   return 'NL';
  if (lat > 45 && lat < 48  && lng > 5    && lng < 11)  return 'CH';
  if (lat > 34 && lat < 42  && lng > 19   && lng < 28)  return 'GR';
  /* Asia / Oceania */
  if (lat > 30 && lat < 46  && lng > 129  && lng < 146) return 'JP';
  if (lat > 1  && lat < 2   && lng > 103  && lng < 105) return 'SG';
  if (lat > 5  && lat < 21  && lng > 97   && lng < 106) return 'TH';
  if (lat > 8  && lat < 24  && lng > 102  && lng < 110) return 'VN';
  if (lat > -11&& lat < 6   && lng > 95   && lng < 141) return 'ID';
  if (lat > 22 && lat < 26  && lng > 51   && lng < 57)  return 'AE';
  if (lat > -45&& lat < -10 && lng > 112  && lng < 154) return 'AU';
  if (lat > -47&& lat < -34 && lng > 166  && lng < 179) return 'NZ';
  return 'unknown';
};

/* ─────────────────────────────────────────────────────────────
   TRADE / DIVISION COST BREAKDOWN — v0.6 (May 15 2026)
   Industry-standard CSI MasterFormat division ratios for hospitality
   construction, sourced from public RSMeans summaries + ENR + Turner &
   Townsend hospitality reports:

   Hospitality typical breakdown by share of total CAPEX:
     LABOR ~ 42-48% (varies by region, more in HCOL markets)
     MATERIALS ~ 36-42%
     SOFT COSTS ~ 12-18% (design, permits, contingency, FF&E coord)

   Within HARD COST (labor + materials), CSI division share for hospitality:
     03 Concrete           : 7-12%
     04 Masonry            : 2-4%
     05 Metals (structure) : 5-9%
     06 Wood & Plastics    : 3-6%
     07 Thermal & Moisture : 4-6%
     08 Openings           : 6-9%
     09 Finishes           : 12-18%
     10-12 Specialties+    : 5-8%
     14 Conveying          : 1-3% (elevators when applicable)
     21 Fire suppression   : 2-4% (CONDITIONAL — height + occupancy)
     22 Plumbing           : 7-10%
     23 HVAC               : 12-18%
     26 Electrical         : 10-14%
     27 Communications     : 2-4%
     28 Electronic Safety  : 1-3%

   These are blended ranges. Exact mix shifts with bracket + typology +
   region. We surface a SIMPLIFIED 3-bar view in summary mode + the
   full CSI breakdown available in advanced mode.

   FIRE SUPPRESSION RULES (the conditional you named):
     - REQUIRED if stories ≥ 3 (IBC 903 typical threshold)
     - REQUIRED if occupancy_load > 100 (assembly)
     - REQUIRED if construction_type wood_frame AND area > 5000 sf
     - OPTIONAL for small non-combustible, single-story
   When NOT required, the 2-4% allocation goes back to other divisions
   proportionally (mostly Specialties + Finishes).

   These are HEURISTICS not benchmarks. Real projects vary ±10pp on any
   division. The footnote "FOR CONCEPT-PHASE PROVOCATION — NOT FOR
   PROCUREMENT" applies to all output here. */
const TRADE_SPLIT_DEFAULTS = {
  /* High-level Labor / Materials / Soft Costs */
  top_split: {
    labor: { share: 0.45, label: 'LABOR', note: 'Trades, supervision, GC overhead' },
    materials: { share: 0.40, label: 'MATERIALS', note: 'All hard materials, equipment, FF&E' },
    soft: { share: 0.15, label: 'SOFT COSTS', note: 'Design, permits, contingency, financing' },
  },
  /* CSI division shares (within hard cost — labor + materials combined) */
  divisions: [
    { id: 'concrete',     code: '03', label: 'Concrete',           share: 0.10, conditional: null },
    { id: 'masonry',      code: '04', label: 'Masonry',            share: 0.03, conditional: null },
    { id: 'metals',       code: '05', label: 'Metals · Structure', share: 0.07, conditional: null },
    { id: 'wood',         code: '06', label: 'Wood & Plastics',    share: 0.04, conditional: null },
    { id: 'thermal',      code: '07', label: 'Thermal & Moisture', share: 0.05, conditional: null },
    { id: 'openings',     code: '08', label: 'Openings',           share: 0.07, conditional: null },
    { id: 'finishes',     code: '09', label: 'Finishes',           share: 0.15, conditional: null },
    { id: 'specialties',  code: '10', label: 'Specialties',        share: 0.06, conditional: null },
    { id: 'conveying',    code: '14', label: 'Conveying · Elevators', share: 0.02, conditional: 'stories_gte_2' },
    { id: 'fire',         code: '21', label: 'Fire Suppression',   share: 0.03, conditional: 'fire_required' },
    { id: 'plumbing',     code: '22', label: 'Plumbing',           share: 0.08, conditional: null },
    { id: 'hvac',         code: '23', label: 'HVAC',               share: 0.15, conditional: null },
    { id: 'electrical',   code: '26', label: 'Electrical',         share: 0.12, conditional: null },
    { id: 'comms',        code: '27', label: 'Communications',     share: 0.03, conditional: null },
  ],
};

/* Returns true if fire suppression is required given project params.
   IBC heuristic — actual code varies by jurisdiction. */
const fireSuppressionRequired = ({ stories, area_m2, construction_type, occupancy_load }) => {
  if (stories >= 3) return true;
  if (occupancy_load > 100) return true;
  if (construction_type === 'wood_frame' && area_m2 > 465) return true; /* ~5000 sf */
  return false;
};

/* ── v0.9.1 (2026-11-12) UNIT CONVERSIONS ─────────────────────────────────
   Some typologies are entered in one unit and sized in another (the owner counts
   rooms, the sizing counts guests). Each row converts what the owner entered into
   the unit the leaf profile counts.
     count = entered × per          (or entered ÷ m2_per for area inputs)
   status 'definition' = same thing under two names; treated as entered by the owner.
   status 'drafted'    = researched 2026-11-12, NOT yet approved by Jair. A drafted
                         ratio sizes the program and the fit check; it never sets the
                         headline price. Change status to 'approved' to promote it.
   On hold (no row): rest_foodtruck (separate math, Jair), boxing (no source found),
   hammam (unit meaning undecided). They keep the scale-class default. */
const UNIT_CONVERSIONS = {
  hotel_airbnb: { per: 1,      status: 'definition', note: '1 unit = 1 key' },
  recovery:     { per: 1,      status: 'definition', note: '1 station = 1 guest' },
  bar_karaoke:  { per: 8,      status: 'drafted',    note: '8 seats per room',            basis: 'operator guides: most rooms hold 6 to 10' },
  meditation:   { per: 15,     status: 'drafted',    note: '15 guests per studio',        basis: 'studio guides: 2 to 2.5 m² per mat, 10 to 15 in a small room' },
  rest_market:  { per: 30,     status: 'drafted',    note: '30 seats per stall',          basis: 'food hall planning guide: about 30 seats per vendor' },
  spa:          { per: 2,      status: 'drafted',    note: '2 guests per treatment room', basis: 'derived: 9 to 14 m² rooms, small spas 28 to 46 m² gross per room' },
  thermal:      { m2_per: 6,   status: 'drafted',    note: '1 guest per 6 m² of water',   basis: 'the thermal profile below: 12 m² per guest, half of it wet. US pool codes allow up to 1 bather per 1.4 to 1.9 m²; that is a legal maximum, not comfort' },
  climbing:     { m2_per: 6,   status: 'drafted',    note: '1 climber per 6 m² of wall',  basis: 'derived: 4 people per 7 ft of wall at peak, 12 m rope walls' },
};

Object.assign(window, {
  UNIT_CONVERSIONS,
  SPATIAL, CLIMATE_IMPACT, climateFlagsFromLatLng,
  REGIONAL_TIERS, regionTierFromLatLng,
  BRACKET_SCHEDULE_SCALE, BRACKET_CAPEX_SCALE,
  LOT_FOOTPRINT_DEFAULTS, countryCodeFromLatLng,
  TRADE_SPLIT_DEFAULTS, fireSuppressionRequired,
});

