const { useState, useMemo, useEffect } = React;

// ??? ROUTING ?????????????????????????????????????????????????????????????????

const LENDERS_BY_STATE = {
  IL: ["Lightreach", "Sunrun", "Cash"],
  OH: ["IGS", "Lightreach", "Cash"],
  VA: ["Lightreach", "IGS", "Cash"],
  FL: ["Lightreach", "IGS", "Cash"],
  MA: ["Lightreach", "IGS", "Cash"],
  ME: ["Lightreach", "IGS", "Cash"],
  RI: ["Lightreach", "IGS", "Cash"],
  CT: ["Lightreach", "IGS", "Cash"],
  NH: ["Lightreach", "IGS", "Cash"],
  NJ: ["Lightreach", "IGS", "Cash"],
  MD: ["Lightreach", "IGS", "Cash"],
  VT: ["Lightreach", "Cash"],
  PA: ["IGS", "Cash"],
  TX: ["IGS_TX", "Cash"],
};
const SALES_TAX_RATE = {
  IL: 0.10, OH: 0.075, VA: 0.053,
  FL: 0.06, MA: 0.0625, ME: 0.055, RI: 0.07,
  CT: 0.0635, NH: 0.00, NJ: 0.06625, MD: 0.06,
  VT: 0.06, PA: 0.06, TX: 0.0625,
};

// ??? DC / FEOC PERCENTAGES (IRS Notice 2025-08) ??????????????????????????????

const PANEL_DC = {
  qcell_c_plus: 7.0, qcell_dca_410: 0.8, qcell_dca_415: 0.8,
  qcell_ac_410: 0.8, hyundai_440: 0,
  longi_hi5_405: 38.5,
};
const INV_DC = {
  enphase_iq8plus: 0, enphase_iq8mc: 0, enphase_iq8ac: 0, enphase_iq8x_nd: 0,
  enphase_iq8x_dom: 24.8, enphase_iq8hc_dom: 24.8,
  enphase_iq8hc_igs: 24.8,
  se_standard: 24.8,
  tesla_pw3_dc: 0,
  tesla_pw3_sh: 0,
};
const RACK_DC = {
  unirac_dom_light_mill: 19.6, unirac_dom_dark: 19.6,
  unirac_nxt_dom: 19.6, snapnrack_dom: 19.6,
  unirac_dom_dark_ndf: 15.0, unirac_nondom_light: 0,
};
const BAT_DC_ELIGIBLE = {
  bat_enp1: true, bat_enpa: true,
  bat_10c_1st: true, bat_10c_add: true,
  bat_sebk: false, bat_segt: false, bat_se_add: false,
  bat_tpw1: true, bat_texp: true, bat_tpwx: true,
  bat_tac1: true, bat_tacx: true, bat_tace: true,
};

// ??? EQUIPMENT CATALOG ???????????????????????????????????????????????????????

const PANELS = {
  qcell_c_plus:   { label: "Q.PEAK DUO BLK ML-G10.C+ 410W ? Dom ($229.60)",          watt: 410, price: 229.60, domestic: true  },
  qcell_dca_410:  { label: "QCell DCA.17 410W ? Dom ($225.50)",                        watt: 410, price: 225.50, domestic: true  },
  qcell_dca_415:  { label: "QCell DCA.17 415W ? Dom ($228.25)",                        watt: 415, price: 228.25, domestic: true  },
  qcell_ac_410:   { label: "QCell AC Module 410W ? Non-Dom ($307.50)",                 watt: 410, price: 307.50, domestic: false },
  hyundai_440:    { label: "Hyundai HIN-T440NF(BK) 440W Bifacial ? Non-Dom ($191.40)", watt: 440, price: 191.40, domestic: false },
  longi_hi5_405:  { label: "LONGi Hi-MO 5 DC LR5-54HPB-405M ? DC 38.5% ($251.10)",   watt: 405, price: 251.10, domestic: false, stateRestrict: ["IL"], shOnly: true },
};

const INVERTERS = {
  enphase_iq8plus:   { label: "Enphase IQ8+ Non-Dom ($82.22)",           price: 82.22,   brand: "enphase",    perPanel: true  },
  enphase_iq8mc:     { label: "Enphase IQ8MC Non-Dom ($95.35)",          price: 95.35,   brand: "enphase",    perPanel: true  },
  enphase_iq8ac:     { label: "Enphase IQ8AC Non-Dom ($103.48)",         price: 103.48,  brand: "enphase",    perPanel: true  },
  enphase_iq8x_nd:   { label: "Enphase IQ8X Non-Dom ($104.65)",          price: 104.65,  brand: "enphase",    perPanel: true  },
  enphase_iq8x_dom:  { label: "Enphase IQ8X Dom ($126.74)",              price: 126.74,  brand: "enphase",    perPanel: true  },
  enphase_iq8hc_dom: { label: "Enphase IQ8HC Dom ($138.37)",             price: 138.37,  brand: "enphase",    perPanel: true  },
  enphase_iq8hc_igs: { label: "Enphase IQ8HC ? IGS SH ($135.00)",        price: 135.00,  brand: "enphase",    perPanel: true  },
  se_standard:       { label: "SolarEdge Single SKU 11.4kW ($581.40)",   price: 581.40,  brand: "solaredge",  perSystem: true, optimizerPrice: 130.48 },
  tesla_pw3_dc:      { label: "Tesla PW3-DC Coupled",                                                        price: 0,    brand: "tesla", perSystem: true, stateRestrict: ["IL"]  },
  tesla_pw3_sh:      { label: "Tesla PW3 Safe Harbor ? 1707000-60-M-LR-2025 ($7,965)",                      price: 0,    brand: "tesla", perSystem: true, stateRestrict: ["IL"], isSH: true, pw3UnitPrice: 7965 },
};

const RACKING = {
  unirac_dom_light_mill: { label: "Unirac Dom Mill Light Rail + Fasteners",    ppw: 0.118, domestic: true  },
  unirac_dom_dark:       { label: "Unirac Dom Dark Rail + Dom Fasteners",      ppw: 0.132, domestic: true  },
  unirac_nxt_dom:        { label: "Unirac NXT Dom Mill",                       ppw: 0.124, domestic: true  },
  snapnrack_dom:         { label: "SnapNrack Dom w/ Dom Fasteners",            ppw: 0.145, domestic: true  },
  unirac_dom_dark_ndf:   { label: "Unirac Dom Dark Rail / Non-Dom Fasteners",  ppw: 0.114, domestic: false },
  unirac_nondom_light:   { label: "Unirac Non-Dom Light Rail",                 ppw: 0.110, domestic: false },
};

// ??? LENDER CONFIG ???????????????????????????????????????????????????????????

const LENDER_CFG = {
  Lightreach: {
    panels: ["qcell_c_plus", "qcell_dca_410", "qcell_dca_415", "qcell_ac_410", "hyundai_440", "longi_hi5_405"],
    inverters: ["enphase_iq8plus", "enphase_iq8mc", "enphase_iq8ac", "enphase_iq8x_nd", "enphase_iq8x_dom", "enphase_iq8hc_dom", "se_standard", "tesla_pw3_dc", "tesla_pw3_sh"],
    dcMandatory: false, dcOptional: true, groundBlock: false, rackingDomRequired: false,
    holdbackStd: 0.10,
    dcBoostPVOnly:    { IL: 0.35, OH: 0.35, VA: 0.35, FL: 0.40, MA: 0.45, ME: 0.45, RI: 0.45, CT: 0.45, NH: 0.45, NJ: 0.45, MD: 0.45, VT: 0.40 },
    dcBoostPVStorage: { IL: 0.45, OH: 0.45, VA: 0.45, FL: 0.50, MA: 0.55, ME: 0.55, RI: 0.55, CT: 0.55, NH: 0.55, NJ: 0.55, MD: 0.55, VT: 0.50 },
    dcThreshold: 50, shDcThreshold: 45, feocThresholdPV: 40, feocThresholdBat: 55,
    badge: "STANDARD", badgeColor: "#0891b2", note: null,
  },
  IGS: {
    panels: ["qcell_c_plus"],
    inverters: ["enphase_iq8hc_igs"],
    dcMandatory: true, dcOptional: false, groundBlock: false, rackingDomRequired: true,
    safeHarbored: true,
    holdbackStd: 0, dcThreshold: 45, feocThresholdPV: 40, feocThresholdBat: 55,
    badge: "SAFE HARBOR", badgeColor: "#d97706",
    note: "Safe harbor required ? IQ8HC at $135 + $20/micro fee. QCell C+ only. Domestic racking mandatory (45% DC).",
    // EC/DC adders by state (VA/OH confirmed; others from IGS pricing matrix)
    ecAdder: { VA: 0.40, OH: 0.40, FL: 0.30, RI: 0.30, NJ: 0.30, CT: 0.30, MA: 0.30, NY: 0.30, MD: 0.30, PA: 0.40, ME: 0.30, NH: 0.30 },
    dcAdder: { VA: 0.60, OH: 0.60, FL: 0.50, RI: 0.50, NJ: 0.50, CT: 0.50, MA: 0.50, NY: 0.50, MD: 0.50, PA: 0.60, ME: 0.50, NH: 0.50 },
  },
  IGS_TX: {
    panels: ["qcell_c_plus", "qcell_dca_410", "qcell_dca_415"],
    inverters: ["enphase_iq8hc_dom", "enphase_iq8x_dom", "se_standard"],
    dcMandatory: false, dcOptional: true, groundBlock: false, rackingDomRequired: false,
    safeHarbored: false, isDraft: true,
    holdbackStd: 0, dcThreshold: 50, feocThresholdPV: 40, feocThresholdBat: 55,
    ecAdder: { TX: 0.30 }, dcAdder: { TX: 0.50 },
    badge: "DRAFT ? Summer 2026", badgeColor: "#6b7280",
    note: "? Draft product ? pricing subject to change. Targeting summer 2026 launch per IGS one-pager.",
  },
  Sunrun: {
    panels: ["qcell_c_plus", "qcell_dca_410", "qcell_dca_415"],
    inverters: ["enphase_iq8hc_dom", "enphase_iq8x_dom", "se_standard", "tesla_pw3_dc"],
    dcMandatory: false, dcOptional: true, groundBlock: true, rackingDomRequired: true,
    safeHarbored: false,
    holdbackStd: 0, dcThreshold: 50, feocThresholdPV: 40, feocThresholdBat: 55,
    badge: "DC AVAILABLE", badgeColor: "#d97706",
    note: "Domestic racking mandatory. DC-approved panels: QCell C+ and QCell DCA.17. Toggle DC enrollment based on whether job is striving for domestic content incentive.",
  },
  GoodLeap: {
    panels: ["qcell_c_plus", "qcell_dca_410", "qcell_dca_415"],
    inverters: ["enphase_iq8plus", "enphase_iq8mc", "enphase_iq8ac", "enphase_iq8x_dom", "enphase_iq8hc_dom", "se_standard"],
    dcMandatory: false, dcOptional: true, groundBlock: true, rackingDomRequired: false,
    holdbackStd: 0, dcThreshold: 50, feocThresholdPV: 40, feocThresholdBat: 55,
    badge: "FEOC REQUIRED", badgeColor: "#7c3aed",
    note: "Ground mount not 2026 FEOC compliant. SE battery not DC-eligible in 2026.",
  },
  Cash: {
    panels: ["qcell_c_plus", "qcell_dca_410", "qcell_dca_415", "qcell_ac_410", "hyundai_440"],
    inverters: ["enphase_iq8plus", "enphase_iq8mc", "enphase_iq8ac", "enphase_iq8x_nd", "enphase_iq8x_dom", "enphase_iq8hc_dom", "se_standard"],
    dcMandatory: false, dcOptional: true, groundBlock: false, rackingDomRequired: false,
    holdbackStd: 0, dcThreshold: 50, feocThresholdPV: 40, feocThresholdBat: 55,
    badge: "FLEXIBLE", badgeColor: "#16a34a", note: null,
  },
};

// ??? COST CONSTANTS ???????????????????????????????????????????????????????????

const GA_PPW_DEFAULT    = 0.23;
const SALESOPS_PPW_DEFAULT = 0.035;
const ANCILLARY_PPW   = 0.06;
const PROPOSAL_PPW    = 0.05;
const BOS_PPW         = 0.14;
const W_STD_INSTALLS  = 13120;
const GA_FIXED_MO     = 0.23 * W_STD_INSTALLS * 100;
const SOPS_FIXED_MO   = 0.035 * W_STD_INSTALLS * 100;
const LEADERSHIP_FIXED_MO = Math.ceil(450000 * 1.21 / 12) + 20000; // $450k + 21% burden ? 12 + $20k/mo = $65,375/mo
const SALES_LEADERSHIP_PPW_DEFAULT = Math.ceil(parseFloat((LEADERSHIP_FIXED_MO / (100 * W_STD_INSTALLS) / 0.005).toFixed(6))) * 0.005;
const roundUpGA   = v => Math.ceil(parseFloat((v / 0.01).toFixed(6))) * 0.01;
const roundUpSops = v => Math.ceil(parseFloat((v / 0.005).toFixed(6))) * 0.005;
const BOS_CUSHION     = 1.15;
const NONFLUSH_PPW    = 0.12;
const DETACH_PPW      = 0.20;
const TESLA_STRING_INV = 1931.82;  // SKU 1538000-45-X ? 7.6kW Inverter w/Site Controller
const MCI_PRICE        = 39.02;    // MCI/RSD Gen 2 15A ? SKU 1879359-15-X
const COMM_RATE_STEP  = 0.005;

// ??? COMMISSIONS MODEL ? UTILITIES / LENDER META ????????????????????????????

const UTILITIES_BY_STATE = {
  IL: ["ComEd", "Ameren"],
  OH: ["AEP", "AES DPL", "Duke", "CEI", "OE", "TED"],
  VA: ["APCO", "Dominion"],
  FL: ["Duke", "FPL", "TECO"],
  MA: ["Eversource East", "Eversource West", "National Grid", "Unitil"],
  ME: ["Central Maine Power", "Versant"],
  RI: ["Rhode Island Energy"],
  CT: ["Eversource CL&P", "United Illuminating"],
  NH: ["Eversource NH", "Unitil NH"],
  NJ: ["ACE", "JCP&L", "O&R", "PSE&G", "Vineland Electric"],
  MD: ["BGE", "Pepco", "Delmarva", "SMECO"],
  VT: ["Green Mountain Power", "Burlington Electric"],
  PA: ["PECO", "PPL", "West Penn", "Duquesne"],
  TX: ["Oncor", "AEP Texas", "CenterPoint", "TNMP"],
};

const INACTIVE_LENDERS = {
  IL: [
    { lender: "Sunrun",     reason: "Partnership terminated March 2026", dot: "#f59e0b" },
    { lender: "EverBright", reason: "Inactive ? data retained for reference", dot: "#0891b2" },
  ],
  OH: [
    { lender: "EverBright", reason: "Inactive ? matrix not yet received", dot: "#0891b2" },
  ],
  VA: [], FL: [], MA: [], ME: [], RI: [], CT: [], NH: [], NJ: [], MD: [], VT: [], PA: [], TX: [],
};

const LENDER_META_COMM = {
  Lightreach: {
    product: "PPA",
    escalators: { IL:["2.99%","0%"], OH:["2.99%","0%"], VA:["2.99%","0%"], FL:["2.99%","0%"], MA:["2.99%","0%"], ME:["2.99%","0%"], RI:["2.99%","0%"], CT:["2.99%","0%"], NH:["2.99%","0%"], NJ:["2.99%","0%"], MD:["2.99%","0%"], VT:["2.99%","0%"] },
    defaultRate: { IL:0.130, OH:0.130, VA:0.130, FL:0.130, MA:0.130, ME:0.130, RI:0.130, CT:0.130, NH:0.130, NJ:0.130, MD:0.130, VT:0.130 },
    rateRangeByEsc: {
      IL:{ "2.99%":[0.10,0.155], "0%":[0.10,0.165] },
      OH:{ "2.99%":[0.10,0.155], "0%":[0.10,0.165] },
      VA:{ "2.99%":[0.10,0.155], "0%":[0.10,0.165] },
      FL:{ "2.99%":[0.10,0.165], "0%":[0.10,0.185] },
      MA:{ "2.99%":[0.26,0.320], "0%":[0.28,0.400] },
      ME:{ "2.99%":[0.18,0.220], "0%":[0.17,0.215] },
      RI:{ "2.99%":[0.20,0.265], "0%":[0.22,0.295] },
      CT:{ "2.99%":[0.14,0.260], "0%":[0.14,0.300] },
      NH:{ "2.99%":[0.15,0.220], "0%":[0.17,0.210] },
      NJ:{ "2.99%":[0.145,0.235],"0%":[0.16,0.260] },
      MD:{ "2.99%":[0.13,0.185], "0%":[0.14,0.210] },
      VT:{ "2.99%":[0.13,0.195], "0%":[0.15,0.215] },
    },
    dot: "#7c3aed",
    note: "EPC is yield-driven ? estimates based on portal data points.",
  },
  IGS: {
    product: "PPA", dcAdder: 0.60,
    escalators: { OH:["2.9%","0%"], VA:["2.9%","0%"], FL:["2.9%","0%"], RI:["2.9%","0%"], NJ:["2.9%","0%"], CT:["2.9%","0%"], MA:["2.9%","0%"], MD:["2.9%","0%"], PA:["2.9%","0%"], ME:["2.9%","0%"], NH:["2.9%","0%"] },
    defaultRate: { OH:0.130, VA:0.130, FL:0.130, RI:0.130, NJ:0.130, CT:0.130, MA:0.130, MD:0.130, PA:0.130, ME:0.130, NH:0.130 },
    rateCapByState: {
      OH: { "AEP":{"2.9%":0.160,"0%":0.180}, "AES DPL":{"2.9%":0.130,"0%":0.145}, "Duke":{"2.9%":0.145,"0%":0.160}, "CEI":{"2.9%":0.140,"0%":0.160}, "OE":{"2.9%":0.165,"0%":0.185}, "TED":{"2.9%":0.145,"0%":0.165} },
      VA: { "APCO":{"2.9%":0.150,"0%":0.165}, "Dominion":{"2.9%":0.125,"0%":0.145} },
      FL: { "Duke":{"2.9%":0.165,"0%":0.185}, "FPL":{"2.9%":0.130,"0%":0.150}, "TECO":{"2.9%":0.145,"0%":0.160} },
      RI: { "Rhode Island Energy":{"2.9%":0.265,"0%":0.295} },
      NJ: { "ACE":{"2.9%":0.235,"0%":0.260}, "JCP&L":{"2.9%":0.150,"0%":0.185}, "O&R":{"2.9%":0.180,"0%":0.230}, "PSE&G":{"2.9%":0.190,"0%":0.240}, "Vineland Electric":{"2.9%":0.150,"0%":0.165} },
      CT: { "Eversource CL&P":{"2.9%":0.235,"0%":0.260}, "United Illuminating":{"2.9%":0.270,"0%":0.300} },
      MA: { "Eversource East":{"2.9%":0.300,"0%":0.320}, "Eversource West":{"2.9%":0.290,"0%":0.310}, "National Grid":{"2.9%":0.320,"0%":0.360}, "Unitil":{"2.9%":0.320,"0%":0.400} },
      MD: { "BGE":{"2.9%":0.185,"0%":0.210}, "Pepco":{"2.9%":0.185,"0%":0.210}, "Delmarva":{"2.9%":0.185,"0%":0.210}, "SMECO":{"2.9%":0.185,"0%":0.210} },
      PA: { "PECO":{"2.9%":0.175,"0%":0.195}, "PPL":{"2.9%":0.155,"0%":0.175}, "West Penn":{"2.9%":0.145,"0%":0.165}, "Duquesne":{"2.9%":0.165,"0%":0.185} },
      ME: { "Central Maine Power":{"2.9%":0.220,"0%":0.240}, "Versant":{"2.9%":0.220,"0%":0.240} },
      NH: { "Eversource NH":{"2.9%":0.205,"0%":0.210}, "Unitil NH":{"2.9%":0.205,"0%":0.210} },
    },
    dot: "#16a34a",
    note: "DC adder +$0.60/W confirms with standard stack. EC requires address-level verification.",
  },
  IGS_TX: {
    product: "PPA (Draft)",
    escalators: { TX:["2.9%","0%"] },
    defaultRate: { TX:0.11 },
    rateRangeByEsc: { TX:{ "2.9%":[0.09,0.13], "0%":[0.11,0.15] } },
    dot: "#6b7280",
    note: "? Draft product ? Summer 2026 target launch. Pricing subject to change.",
    isDraft: true,
  },
  Cash: {
    product: "Cash Purchase", escalators: {},
    dot: "#64748b",
    note: "Sales tax applies per state. All adders available.",
  },
  Sunrun: {
    product: "PPA", batteryRequired: true,
    escalators: { IL:["2.99%","0%"] },
    defaultRate: { IL:0.130 },
    rateRangeByEsc: { IL:{ "2.99%":[0.07,0.130], "0%":[0.07,0.170] } },
    dot: "#f59e0b",
    note: "Battery TK paid separately on top of solar EPC.",
  },
};

const COMM_YIELD_RANGES = {
  Lightreach: { IL:[900,1400], OH:[900,1400], VA:[900,1400], FL:[900,1400], MA:[900,1400], ME:[900,1400], RI:[900,1400], CT:[900,1400], NH:[900,1400], NJ:[900,1400], MD:[900,1400], VT:[900,1400] },
  IGS:        { OH:[900,1300], VA:[1000,1400], FL:[1300,1700], RI:[900,1300], NJ:[900,1300], CT:[900,1300], MA:[900,1300], MD:[1000,1400], PA:[1000,1400], ME:[900,1300], NH:[900,1300] },
  IGS_TX:     { TX:[1100,1500] },
  Cash:       { IL:[800,1500], OH:[800,1500], VA:[800,1500], FL:[800,1500], MA:[800,1400], ME:[800,1400], RI:[800,1400], CT:[800,1400], NH:[800,1400], NJ:[800,1400], MD:[800,1400], VT:[800,1400], PA:[800,1400], TX:[1100,1600] },
  Sunrun:     { IL:[800,1400] },
};

function commLerp(x, x0, x1, y0, y1) {
  const t = Math.max(0, Math.min(1, (x - x0) / (x1 - x0)));
  return y0 + t * (y1 - y0);
}

function commGetRateRange(lender, st, util, esc) {
  const meta = LENDER_META_COMM[lender];
  if (!meta) return [0.10, 0.17];
  const byEsc = meta.rateRangeByEsc?.[st]?.[esc];
  let [mn, mx] = byEsc ? byEsc : [0.10, 0.17];
  if ((lender === "IGS" || lender === "IGS_TX") && meta.rateCapByState?.[st]?.[util]?.[esc]) {
    mx = Math.min(mx, meta.rateCapByState[st][util][esc]);
    mn = 0.09;
  }
  return [mn, mx];
}

function commGetEPC(lender, st, util, esc, rate, yld, dc, ec, kw) {
  if (lender === "Cash") return rate;
  if (lender === "Lightreach") {
    const yRange = COMM_YIELD_RANGES.Lightreach[st] || [940, 1354];
    const rBase  = esc === "2.99%" || esc === "2.9%"
      ? commLerp(yld, yRange[0], yRange[1], 1.80, 3.91)
      : commLerp(yld, yRange[0], yRange[1], 1.50, 3.32);
    return Math.max(0, rBase + (rate - 0.13) * 60);
  }
  if (lender === "IGS" || lender === "IGS_TX") {
    const meta   = LENDER_META_COMM[lender];
    const yRange = COMM_YIELD_RANGES[lender]?.[st] || [900, 1400];
    const refMap = { "AEP":2.65,"AES DPL":2.30,"Duke":2.45,"CEI":2.40,"OE":2.70,"TED":2.45,"APCO":2.85,"Dominion":2.50, "Rhode Island Energy":3.13,"ACE":2.99,"JCP&L":2.99,"O&R":2.99,"PSE&G":2.99,"Vineland Electric":2.99,"Eversource CL&P":2.27,"United Illuminating":2.27,"Eversource East":3.83,"Eversource West":3.83,"National Grid":3.83,"Unitil":3.83,"BGE":2.55,"Pepco":2.55,"Delmarva":2.55,"SMECO":2.55,"PECO":2.55,"PPL":2.55,"West Penn":2.55,"Duquesne":2.55,"Central Maine Power":2.91,"Versant":2.91,"Eversource NH":2.55,"Unitil NH":2.55,"Oncor":2.06,"AEP Texas":2.06,"CenterPoint":2.06,"TNMP":2.06,"FPL":2.52,"TECO":2.52 };
    const base   = (refMap[util] || 2.55) + (rate - 0.13) * 55 + (yld - yRange[0]) / 100 * 0.25;
    const escAdj = esc === "0%" ? -0.50 : 0;
    return Math.max(0, base + escAdj + (dc ? (meta.dcAdder || 0.60) : 0) + (ec ? 0.40 : 0));
  }
  if (lender === "Sunrun") {
    const solar = 3.30 + (rate - 0.13) * 55 + (yld - 1300) / 100 * 0.25 + (esc === "0%" ? -0.60 : 0);
    return Math.max(0, solar);
  }
  return rate;
}

// Finds combo that maximizes EPC while staying within ~5% above the target
// (best achievable spread at or near your target price)
function commSolveForBestSpread(lender, st, util, dc, ec, kw, targetEPC) {
  if (lender === "Cash") return null;
  const meta = LENDER_META_COMM[lender];
  if (!meta) return null;
  const escs   = meta.escalators?.[st] || [];
  const yRange = COMM_YIELD_RANGES[lender]?.[st] || [900, 1400];
  const yMax   = Math.min(yRange[1], 1200);
  const ceiling = targetEPC * 1.05;
  let best = null, bestEPC = -Infinity;
  for (const esc of escs) {
    const [rMin, rMax] = commGetRateRange(lender, st, util, esc);
    for (let yld = yRange[0]; yld <= yMax; yld += 100) {
      for (let r = rMin; r <= rMax + 0.00001; r = Math.round((r + COMM_RATE_STEP) * 1000) / 1000) {
        const rate = Math.min(rMax, r);
        const epc  = commGetEPC(lender, st, util, esc, rate, yld, dc, ec, kw);
        if (epc >= targetEPC - 0.02 && epc <= ceiling && epc > bestEPC) {
          bestEPC = epc;
          best = { escalator: esc, sellRate: rate, yield: yld, epc, monthly: kw > 0 ? kw * yld * rate / 12 : 0 };
        }
      }
    }
  }
  return best;
}

// Finds lowest-rate combo that still achieves targetEPC (minimizes HO monthly)
function commSolveForLowestMonthly(lender, st, util, dc, ec, kw, targetEPC) {
  if (lender === "Cash") return null;
  const meta = LENDER_META_COMM[lender];
  if (!meta) return null;
  const escs   = meta.escalators?.[st] || [];
  const yRange = COMM_YIELD_RANGES[lender]?.[st] || [900, 1400];
  const yMax   = Math.min(yRange[1], 1200);
  let best = null, bestMonthly = Infinity;
  for (const esc of escs) {
    const [rMin, rMax] = commGetRateRange(lender, st, util, esc);
    for (let yld = yRange[0]; yld <= yMax; yld += 100) {
      for (let r = rMin; r <= rMax + 0.00001; r = Math.round((r + COMM_RATE_STEP) * 1000) / 1000) {
        const rate = Math.min(rMax, r);
        const epc  = commGetEPC(lender, st, util, esc, rate, yld, dc, ec, kw);
        if (epc >= targetEPC - 0.015) {
          const monthly = kw > 0 ? kw * yld * rate / 12 : 0;
          if (monthly < bestMonthly) { bestMonthly = monthly; best = { escalator: esc, sellRate: rate, yield: yld, epc, monthly }; }
          break;
        }
      }
    }
  }
  return best;
}
// Returns { escalator, sellRate, yield } for the closest attainable combo
function commSolveForTarget(lender, st, util, dc, ec, kw, targetEPC) {
  if (lender === "Cash") return null; // Cash is a direct input, no solve needed
  const meta = LENDER_META_COMM[lender];
  if (!meta) return null;
  const escs   = meta.escalators?.[st] || ["2.9%"];
  const yRange = COMM_YIELD_RANGES[lender]?.[st] || [900, 1400];
  const yStep  = 100;
  const yMax   = Math.min(yRange[1], 1200);

  let bestCombo = null;
  let bestDiff  = Infinity;

  for (const esc of escs) {
    const [rMin, rMax] = commGetRateRange(lender, st, util, esc);
    // Iterate yields from high to low (higher yield = higher EPC)
    for (let yld = yMax; yld >= yRange[0]; yld -= yStep) {
      // Binary search rate that gets EPC closest to target
      let lo = rMin, hi = rMax;
      for (let i = 0; i < 30; i++) {
        const mid = Math.round((lo + hi) / 2 / COMM_RATE_STEP) * COMM_RATE_STEP;
        const epc = commGetEPC(lender, st, util, esc, mid, yld, dc, ec, kw);
        if (epc < targetEPC) lo = mid + COMM_RATE_STEP;
        else hi = mid;
        if (hi - lo < COMM_RATE_STEP / 2) break;
      }
      // Test both lo and hi, pick closer
      for (const r of [lo, hi, rMax]) {
        const clampedR = Math.min(rMax, Math.max(rMin, Math.round(r / COMM_RATE_STEP) * COMM_RATE_STEP));
        const epc = commGetEPC(lender, st, util, esc, clampedR, yld, dc, ec, kw);
        const diff = Math.abs(epc - targetEPC);
        if (diff < bestDiff) {
          bestDiff  = diff;
          const epc     = commGetEPC(lender, st, util, esc, clampedR, yld, dc, ec, kw);
          const monthly = kw > 0 ? kw * yld * clampedR / 12 : 0;
          bestCombo = { escalator: esc, sellRate: clampedR, yield: yld, epc, monthly };
        }
      }
    }
  }
  return bestCombo;
}

const HIST_PPW = {
  IL: { Lightreach: null, Sunrun: 4.31, Cash: 3.09 },
  OH: { IGS: 3.41, Lightreach: null, Cash: null },
  VA: { Lightreach: null, IGS: 3.63, Cash: null },
  FL: { Lightreach: null, IGS: null, Cash: null },
  MA: { Lightreach: null, IGS: null, Cash: null },
  ME: { Lightreach: null, IGS: null, Cash: null },
  RI: { Lightreach: null, IGS: null, Cash: null },
  CT: { Lightreach: null, IGS: null, Cash: null },
  NH: { Lightreach: null, IGS: null, Cash: null },
  NJ: { Lightreach: null, IGS: null, Cash: null },
  MD: { Lightreach: null, IGS: null, Cash: null },
  VT: { Lightreach: null, Cash: null },
  PA: { IGS: null, Cash: null },
  TX: { IGS_TX: null, Cash: null },
};

const ACTUAL_COGS = {
  // Source: QB_matched_162_2.xlsx ? Jan 1?Apr 14, 2026 ? OWE/partner, panel removal, and Sunrun jobs excluded
  VA: {
    IGS: {
      flush_no:    { jobs: 5,  avg: 1.819, median: 1.725, stddev: 0.318, lowConf: true }, // QB 2026 ? n=5, low confidence
      nonflush_no: { jobs: 9,  avg: 1.506, median: 1.543, stddev: 0.161 }, // prior dataset
      flush_yes:   { jobs: 3,  avg: 1.790, median: 1.785, stddev: 0.195 }, // prior dataset
    },
    Lightreach: {
      flush_no: { jobs: 77, avg: 1.810, median: 1.785, stddev: 0.112 }, // QB 2026 ? n=77, high confidence
    },
    GoodLeap:   { flush_no: { jobs: 3,  avg: 1.669, median: 1.656, stddev: 0.148 } }, // prior dataset
  },
  OH: {
    IGS: {
      flush_no:    { jobs: 9,  avg: 1.607, median: 1.574, stddev: 0.120 }, // QB 2026 ? n=9
      nonflush_no: { jobs: 6,  avg: 1.602, median: 1.618, stddev: 0.164 }, // prior dataset
      flush_yes:   { jobs: 4,  avg: 1.458, median: 1.593, stddev: 0.541, lowConf: true }, // prior dataset
    },
  },
  IL: {
    Sunrun: { flush_no: { jobs: 3, avg: 2.234, median: 2.141, stddev: 0.435 } }, // prior dataset (Sunrun terminated Mar 2026)
  },
};

const getActualCOGS = (state, lender, roofType, detached) => {
  const sd = ACTUAL_COGS[state]; if (!sd) return null;
  const ld = sd[lender]; if (!ld) return null;
  const key = detached ? "flush_yes" : (roofType === "nonflush" ? "nonflush_no" : "flush_no");
  return ld[key] || ld["flush_no"] || null;
};

// ??? ADDER CATALOG ???????????????????????????????????????????????????????????

const ADDERS = [
  // Redline
  { key: "home_repairs", label: "Home Repairs", sea: 1000, int: 1000, list: 1000,
    detail: { summary: "Standard $1,000 budget for minor home repairs on every job. Auto-added to all jobs and folds into the redline floor ? not a spread adder.", crew: "As needed", truckRoll: false, hours: { sea: "N/A", internal: "N/A" }, bom: [{ item: "Home repair budget", cost: "$1,000.00" }], note: "Auto-added to every job. Cost adds to the redline floor ? no markup, no commission impact.", noteType: "ok", rec: "Unselect only if repairs are confirmed not needed." } },

  // Electrical
  { key: "mpu", label: "Main Panel Upgrade (MPU)", sea: 1750, int: 2551.60, list: 3200,
    detail: { summary: "Replaces existing main panel ? typically 100A?200A.", crew: "2 electricians", truckRoll: true, hours: { sea: "SEA flat fee", internal: "8 hrs ? 2 guys ? $61 + $1,000 truck roll = $1,976" }, bom: [{ item: "200A main panel & materials", cost: "$575.60" }, { item: "Internal labor (8 hrs ? 2 ? $61)", cost: "$976.00" }, { item: "Truck roll", cost: "$1,000.00" }], note: "SEA ($1,750) preferred ? internal ($2,552) exceeds list ($2,100).", noteType: "warn", rec: "Use SEA." } },
  { key: "tap_box", label: "Tap Box Adder", sea: 350, int: 400, list: 500,
    detail: { summary: "Installs a tap box for branch circuit connection.", crew: "2 electricians", truckRoll: false, hours: { sea: "SEA flat fee", internal: "~2 hrs" }, bom: [{ item: "Tap box hardware & misc", cost: "included in rate" }], note: "SEA ($350) preferred ? $50 cost advantage over internal ($400).", noteType: "ok", rec: "Use SEA." } },
  { key: "umr", label: "Utility Meter Replacement (UMR)", sea: 1750, int: 2105.80, list: 2700,
    detail: { summary: "Replaces utility meter base with bidirectional smart meter.", crew: "2 electricians", truckRoll: true, hours: { sea: "SEA flat fee", internal: "3 hrs ? 2 guys ? $61 + $1,000 truck roll = $1,366" }, bom: [{ item: "Meter base / socket & materials", cost: "$739.80" }, { item: "Internal labor (3 hrs ? 2 ? $61)", cost: "$366.00" }, { item: "Truck roll", cost: "$1,000.00" }], note: "SEA ($1,750) cheaper than internal ($2,106).", noteType: "ok", rec: "Use SEA." } },
  { key: "mbe", label: "Main Breaker Enclosure (MBE)", sea: 750, int: 1625.98, list: 2050,
    detail: { summary: "Adds main breaker enclosure when existing panel lacks one.", crew: "2 electricians", truckRoll: false, hours: { sea: "SEA flat fee", internal: "2 hrs ? 2 guys ? $61 = $244" }, bom: [{ item: "Main breaker enclosure & materials", cost: "$1,381.98" }, { item: "Internal labor (2 hrs ? 2 ? $61)", cost: "$244.00" }], note: "SEA ($750) dramatically cheaper than internal ($1,626).", noteType: "warn", rec: "Use SEA ? $876 advantage." } },
  { key: "sp", label: "Sub Panel (SP)", sea: 750, int: 857.92, list: 1150,
    detail: { summary: "Installs 125A/60A backup load sub-panel. Standard on ALL full battery backup jobs.", crew: "2 electricians", truckRoll: false, hours: { sea: "SEA flat fee", internal: "4 hrs ? 2 guys ? $61 = $488" }, bom: [{ item: "125A/60A backup load panel & materials", cost: "$369.92" }, { item: "Internal labor (4 hrs ? 2 ? $61)", cost: "$488.00" }], note: "SEA ($750) and internal ($858) both well below list ($1,500). 50%+ gross margin.", noteType: "ok", rec: "Either ? SEA slight edge." } },
  { key: "mbdr", label: "Main Breaker Derate (MBDR)", sea: 400, int: 452.16, list: 600,
    detail: { summary: "Downsizes main breaker per NEC 705.12(B). Standard on Enphase battery jobs.", crew: "2 electricians", truckRoll: false, hours: { sea: "SEA flat fee", internal: "2 hrs ? 2 guys ? $61 = $244" }, bom: [{ item: "Replacement main breaker & materials", cost: "$208.16" }, { item: "Internal labor (2 hrs ? 2 ? $61)", cost: "$244.00" }], note: "Both modes well below list. ~44% gross margin.", noteType: "ok", rec: "Either ? SEA slightly cheaper." } },
  { key: "mmc", label: "Meter Main Combo (MMC)", sea: 1750, int: 3333.75, list: 4250,
    detail: { summary: "Full service replacement ? meter + main breaker combined.", crew: "2 electricians", truckRoll: true, hours: { sea: "SEA flat fee", internal: "3 hrs ? 2 guys ? $61 + $1,000 truck roll = $1,366" }, bom: [{ item: "Meter Main Combo materials", cost: "$1,967.75" }, { item: "Internal labor (3 hrs ? 2 ? $61)", cost: "$366.00" }, { item: "Truck roll", cost: "$1,000.00" }], note: "SEA ($1,750) well below internal ($3,334). Strong margin at list.", noteType: "ok", rec: "Use SEA." } },

  // Install
  { key: "steep", label: "Steep Roof (>35?)", seaW: 0.05, intW: 0.05, listW: 0.06, perW: true,
    detail: { summary: "Applied when pitch exceeds 35?. Adds ~25% to labor time.", crew: "Same as base install", truckRoll: false, hours: { sea: "~25% adder", internal: "~25% adder" }, bom: [], note: "$0.05/W cost, $0.06/W list. ~17% margin.", noteType: "ok", rec: "Standard pass-through." } },
  { key: "high", label: "High Roof (3+ stories)", seaW: 0.05, intW: 0.05, listW: 0.06, perW: true,
    detail: { summary: "Applied when building is 3+ stories.", crew: "Same as base install", truckRoll: false, hours: { sea: "~20% adder", internal: "~20% adder" }, bom: [], note: "Thin margin ? only $0.01/W spread.", noteType: "warn", rec: "Confirm spread is adequate." } },
  { key: "metal_roof", label: "Metal Roof", seaW: 0.056, intW: 0.056, listW: 0.07, perW: true,
    detail: { summary: "Applied when installing on a metal roof.", crew: "Same as base install", truckRoll: false, hours: { sea: "~15% adder", internal: "~15% adder" }, bom: [], note: "$0.056/W cost, $0.07/W list. ~20% margin.", noteType: "ok", rec: "Standard pass-through." } },
  { key: "trench", label: "Trenching", isTrench: true, seaPFt: 25, intPFt: 29, seaBase: 500, listBase: 500, listPFt: 35,
    detail: { summary: "Soft-scape trenching for conduit runs. SEA $500 base + $25/ft ? Internal $29/ft ? List $500 + $35/ft.", crew: "2 electricians", truckRoll: true, hours: { sea: "Flat rate", internal: "~5 hrs @ 120ft" }, bom: [{ item: "Schedule 40 PVC conduit", cost: "~$0.70?$1.00/ft" }, { item: "Fittings & misc", cost: "~$80" }], note: "SEA $500 base + $25/ft. Internal $29/ft. List $500 base + $35/ft.", noteType: "ok", rec: "Compare SEA vs internal at actual footage." } },
  { key: "small_system", label: "Small System (?12 Panels)", sea: 1500, int: 1500, list: 1500, isSmallSystem: true,
    detail: { summary: "Applied when system is 12 panels or fewer. Fixed costs don't scale.", crew: "Standard crew", truckRoll: false, hours: { sea: "Included in base", internal: "Included in base" }, bom: [], note: "Flat $1,500 across both modes.", noteType: "ok", rec: "Apply to all jobs of 12 panels or fewer." } },
  { key: "gm", label: "Ground Mount", seaW: 0.33, intW: 1.14, listW: 1.42, perW: true, blockLenders: ["Lightreach","IGS","Sunrun","GoodLeap"], isGroundMount: true,
    detail: { summary: "Replaces roof racking entirely. Cash lender only. SEA: $0.33/W. Internal: $1.14/W.", crew: "2 electricians + 3 installers", truckRoll: true, hours: { sea: "SEA flat rate", internal: "10 hrs ? (3 installers @ $48.40 + 2 electricians @ $61) + 2 truck rolls + $1,250 equipment" }, bom: [{ item: "Sunmodo SunTurf materials", cost: "$0.50/W" }, { item: "Labor (3 installers + 2 elec.)", cost: "$2,672 flat" }, { item: "2? truck rolls", cost: "$2,000" }, { item: "Equipment rental & delivery", cost: "$1,250" }], note: "SEA ($0.33/W) dramatically cheaper than internal ($1.14/W). Cash lender only.", noteType: "ok", rec: "Use SEA. Cash lender only." } },

  // Misc
  { key: "multi_array", label: "Multiple Array Adder", sea: 280, int: 280, list: 350, isQtyAdder: true,
    detail: { summary: "Applied starting on the 4th array. Enter number of arrays beyond 3.", crew: "Standard crew", truckRoll: false, hours: { sea: "Included in base", internal: "Included in base" }, bom: [], note: "$280 cost / $350 list per array. 20% gross margin.", noteType: "ok", rec: "Apply to all jobs with 4+ arrays." } },
  { key: "boring_base", label: "Boring ? Base Charge", isBoringBase: true, isBoring: true, list: null,
    detail: { summary: "Flat mobilization/setup fee. Customer billed contractor quote + $500.", crew: "Sub / Boring contractor", truckRoll: true, hours: { sea: "Contractor rate", internal: "Contractor rate" }, bom: [{ item: "Boring contractor base charge", cost: "Per quote (enter below)" }], note: "Cost = contractor quote. List = quote + $500. $500 is the only margin.", noteType: "ok", rec: "Always apply on boring jobs alongside material adder." } },
  { key: "boring_0_100", label: "Boring Material ? 0 to 100 ft", isBoringMaterial: true, isBoring: true, seaPFt: 9, intPFt: 10, listPFt: 12,
    detail: { summary: "Wire/material cost for boring runs up to 100 ft.", crew: "Sub / Boring contractor", truckRoll: false, hours: { sea: "$9/ft", internal: "$9/ft" }, bom: [{ item: "Boring wire & materials", cost: "$9/ft" }], note: "$9/ft cost, $12/ft list. $3/ft margin.", noteType: "ok", rec: "Use for runs 100ft and under." } },
  { key: "boring_101_200", label: "Boring Material ? 101 to 200 ft", isBoringMaterial: true, isBoring: true, seaPFt: 8, intPFt: 9, listPFt: 11,
    detail: { summary: "Wire/material cost for boring runs 101?200 ft.", crew: "Sub / Boring contractor", truckRoll: false, hours: { sea: "$8/ft", internal: "$8/ft" }, bom: [{ item: "Boring wire & materials", cost: "$8/ft" }], note: "$8/ft cost, $11/ft list. $3/ft margin.", noteType: "ok", rec: "Use for runs 101?200 ft." } },
  { key: "boring_201_plus", label: "Boring Material ? 201+ ft", isBoringMaterial: true, isBoring: true, seaPFt: 8, intPFt: 8, listPFt: 10,
    detail: { summary: "Wire/material cost for boring runs over 200 ft.", crew: "Sub / Boring contractor", truckRoll: false, hours: { sea: "$8/ft", internal: "$8/ft" }, bom: [{ item: "Boring wire & materials", cost: "$8/ft" }], note: "$8/ft cost, $10/ft list. $2/ft margin ? thinnest boring tier.", noteType: "warn", rec: "Confirm adequate margin on longer runs." } },
  { key: "heat_smoke", label: "Heat & Smoke Detectors", sea: 366.89, int: 366.89, list: 500,
    detail: { summary: "Installation of heat and smoke detectors.", crew: "1 electrician", truckRoll: false, hours: { sea: "SEA flat fee", internal: "~1 hr" }, bom: [{ item: "Heat/smoke detector units + wiring", cost: "included" }], note: "$366.89 cost both modes. $500 list ? ~26.6% margin.", noteType: "ok", rec: "Either mode ? identical cost." } },
  { key: "ground_rods", label: "Ground Rods", sea: 226.50, int: 226.50, list: 300,
    detail: { summary: "Installation of supplemental ground rod(s).", crew: "1 electrician", truckRoll: false, hours: { sea: "~1 hr", internal: "~1 hr" }, bom: [{ item: "Ground rod + clamp & misc", cost: "included" }], note: "$226.50 cost both modes. $300 list ? ~24.5% margin.", noteType: "ok", rec: "Either mode ? identical cost." } },

  // Enphase Batteries
  { key: "bat_10c_1st", label: "Enphase IQ 10C ? 1st Unit w/ Backup", sea: 9678.12, int: 13123.12, list: 15900, seaPartner: 1700, intPartner: 1700, listPartner: null, isBattery: true, blockInvBrand: "solaredge",
    detail: { summary: "First Enphase IQ Battery 10C (10.08kWh) with full backup. Gen 4 system ? no System Controller needed.", crew: "2 electricians", truckRoll: true, hours: { sea: "$1,400 flat (incl. truck roll)", internal: "10 hrs ? 2 guys ? $61 + $1,000 truck roll = $2,220" }, bom: [{ item: "2? Domestic 5kWh Battery Units (B05-C01-US00-1-3-DOM)", cost: "$6,000.00" }, { item: "Domestic ID Cover (B10C-NC-0708-O-DOM)", cost: "$655.56" }, { item: "IQ Meter Collar (MC-200-011-V01)", cost: "$500.00" }, { item: "IQ Combiner 6C upgrade delta (vs. 5C base)", cost: "$622.56" }, { item: "SEA labor + truck roll", cost: "$1,400.00" }, { item: "SEA BOS buffer", cost: "$500.00" }, { item: "Internal BOS", cost: "$3,125.00" }, { item: "Internal labor alt.", cost: "10 hrs ? 2 ? $61 + $1,000 = $2,220.00" }], note: "Hardware subtotal $7,778.12. SEA ($9,678) preferred over internal ($13,123). CED Q1053258 (03/09/26).", noteType: "ok", rec: "Use SEA." } },
  { key: "bat_10c_add", label: "Enphase IQ 10C ? Each Additional 5kWh Unit", sea: 4023.56, int: 4324.56, list: 5300, seaPartner: 500, intPartner: 500, listPartner: null, isBattery: true, blockInvBrand: "solaredge", isQtyAdder: true,
    detail: { summary: "Each additional 5kWh battery module beyond the initial 10C pair. System scales from 10kWh to 80kWh in 5kWh increments.", crew: "2 electricians", truckRoll: false, hours: { sea: "$300 flat (no truck roll)", internal: "2 hrs ? 2 guys ? $61 = $244, no truck roll" }, bom: [{ item: "Domestic 5kWh Battery Unit (B05-C01-US00-1-3-DOM)", cost: "$3,000.00" }, { item: "Domestic ID Cover (B10C-NC-0708-O-DOM)", cost: "$655.56" }, { item: "SEA labor", cost: "$300.00" }, { item: "SEA BOS buffer (16% of $425)", cost: "$68.00" }, { item: "Internal BOS", cost: "$425.00" }, { item: "Internal labor alt.", cost: "2 hrs ? 2 ? $61 = $244.00" }], note: "Hardware subtotal $3,655.56. SEA ($4,024) slightly cheaper than internal ($4,325). CED Q1053258.", noteType: "ok", rec: "Either mode ? essentially equivalent." } },
  { key: "bat_enp1", label: "Enphase IQ 5P ? 1st Unit w/ Backup", sea: 7169.77, int: 11739.77, list: 14150, seaPartner: 1700, intPartner: 1700, listPartner: null, isBattery: true, blockInvBrand: "solaredge",
    detail: { summary: "First Enphase IQ Battery 5P with full backup. Requires IQ System Controller 3 and Backup Load Panel.", crew: "2 electricians", truckRoll: true, hours: { sea: "$1,400 flat (incl. truck roll)", internal: "10 hrs ? 2 guys ? $61 + $1,000 truck roll = $2,220" }, bom: [{ item: "IQ Battery 5P (IQBATTERY-5P-1P-NA)", cost: "$3,550.00" }, { item: "IQ System Controller 3", cost: "$1,719.77" }, { item: "SEA labor + truck roll", cost: "$1,400.00" }, { item: "SEA BOS buffer", cost: "$500.00" }, { item: "Internal BOS", cost: "$4,250.00" }, { item: "Internal labor alt.", cost: "10 hrs ? 2 ? $61 + $1,000 = $2,220.00" }], note: "SEA carries $500 BOS buffer. Internal carries full $4,250 BOS.", noteType: "ok", rec: "Use SEA." } },
  { key: "bat_enpa", label: "Enphase IQ 5P ? Each Additional", sea: 3900.00, int: 4219.00, list: 5100, seaPartner: 500, intPartner: 500, listPartner: null, isBattery: true, blockInvBrand: "solaredge",
    detail: { summary: "Each additional IQ 5P beyond the first. No system controller needed. No truck roll.", crew: "2 electricians", truckRoll: false, hours: { sea: "$300 flat (no truck roll)", internal: "2 hrs ? 2 guys ? $61 = $244" }, bom: [{ item: "IQ Battery 5P (IQBATTERY-5P-1P-NA)", cost: "$3,550.00" }, { item: "SEA labor", cost: "$300.00" }, { item: "SEA BOS buffer", cost: "$50.00" }, { item: "Internal BOS", cost: "$425.00" }, { item: "Internal labor alt.", cost: "2 hrs ? 2 ? $61 = $244.00" }], note: "SEA carries $50 proportionate BOS buffer. Internal carries full $425 BOS.", noteType: "ok", rec: "Either mode ? essentially equivalent." } },

  // SolarEdge Batteries
  { key: "bat_sebk", label: "SolarEdge Bat10K w/ Backup", sea: 9496.71, int: 11816.71, list: 14300, seaPartner: 1700, intPartner: 1700, listPartner: 5000, isBattery: true, blockInvBrand: "enphase",
    detail: { summary: "SE 10kWh battery with full backup. Standard config: Bat10K + BI-EU service side + Energy Net Card + Fast Mount + backup sub-panel.", crew: "2 electricians", truckRoll: true, hours: { sea: "$1,400 flat (incl. truck roll)", internal: "10 hrs ? 2 guys ? $61 + $1,000 truck roll = $2,220" }, bom: [{ item: "SE 10kWh (UBAT-10K1PS0B-03)", cost: "$6,547.62" }, { item: "Backup Interface Service Side (BI-EUSGN-03)", cost: "$752.79" }, { item: "Energy Net Card", cost: "$56.57" }, { item: 'Fast Mount 36"', cost: "$208.33" }, { item: "63A Breaker Kit", cost: "$31.40" }, { item: "SEA labor + truck roll", cost: "$1,400.00" }, { item: "SEA BOS buffer", cost: "$500.00" }, { item: "Internal BOS", cost: "$2,000.00" }, { item: "Internal labor alt.", cost: "10 hrs ? 2 ? $61 + $1,000 = $2,220.00" }], note: "Hardware subtotal (excl. BOS) $7,596.71. SEA carries $500 BOS buffer. Internal carries full $2,000 BOS.", noteType: "ok", rec: "Use SEA." } },
  { key: "bat_segt", label: "SolarEdge Bat10K w/o Backup", sea: 8129.19, int: 8836.19, list: 10650, seaPartner: 1400, intPartner: 1400, listPartner: 3000, isBattery: true, blockInvBrand: "enphase",
    detail: { summary: "SE 10kWh battery without backup ? grid-tied monitoring only.", crew: "2 electricians", truckRoll: true, hours: { sea: "$1,400 flat (incl. truck roll)", internal: "6 hrs ? 2 guys ? $61 + $1,000 truck roll = $1,732" }, bom: [{ item: "SE 10kWh (UBAT-10K1PS0B-03)", cost: "$6,547.62" }, { item: "Energy Net Card", cost: "$56.57" }, { item: "SEA labor + truck roll", cost: "$1,400.00" }, { item: "SEA BOS buffer", cost: "$125.00" }, { item: "Internal BOS", cost: "$500.00" }, { item: "Internal labor alt.", cost: "6 hrs ? 2 ? $61 + $1,000 = $1,732.00" }], note: "Hardware subtotal (excl. BOS) $6,604.19. SEA carries $125 BOS buffer.", noteType: "ok", rec: "Use SEA." } },
  { key: "bat_se_add", label: "SolarEdge Bat10K ? Each Additional", sea: 7897.09, int: 7841.09, list: 9650, seaPartner: 500, intPartner: 500, listPartner: null, isBattery: true, blockInvBrand: "enphase", isQtyAdder: true,
    detail: { summary: "Each additional SE 10kWh battery beyond the first. No new backup interface or sub-panel needed. No truck roll.", crew: "2 electricians", truckRoll: false, hours: { sea: "$300 flat (no truck roll)", internal: "4 hrs ? 2 guys ? $61 = $488, no truck roll" }, bom: [{ item: "SE 10kWh (UBAT-10K1PS0B-03)", cost: "$6,547.62" }, { item: "Energy Net Card", cost: "$56.57" }, { item: "SEA labor", cost: "$300.00" }, { item: "SEA BOS buffer", cost: "$993.50" }, { item: "Internal BOS", cost: "$737.50" }, { item: "Internal labor alt.", cost: "4 hrs ? 2 ? $61 = $488.00" }], note: "SEA ($7,897) and Internal ($7,841) nearly identical cost. 18.2% GM at $9,650 list.", noteType: "ok", rec: "Either mode ? essentially equivalent." } },

  // Tesla Batteries
  { key: "bat_tpw1", label: "Tesla PW3 ? 1st Powerwall w/ Gateway", isTeslaLead: true, isBattery: true, list: 12700, seaPartner: 1150, intPartner: 732,
    detail: { summary: "First Tesla Powerwall 3 with Gateway 3. Inverter portion (Tesla string inv. equiv. + MCI/RSD) split to Equipment in Section 04A. Adder covers battery hardware, Gateway, BOS, and labor.", crew: "2 electricians", truckRoll: false, hours: { sea: "$1,150 flat (all-in)", internal: "6 hrs ? 2 guys ? $61 = $732, no truck roll" }, bom: [{ item: "Tesla Powerwall 3 (1707000-21-Y)", cost: "$7,388.88" }, { item: "Gateway 3 (1841000-01-Y)", cost: "$852.27" }, { item: "BOS", cost: "$500.00 (SEA) / $4,250.00 (internal)" }, { item: "SEA labor", cost: "$1,150.00" }, { item: "? Inverter split to 04A: Tesla Str. Inv. equiv. (1538000-45-X)", cost: "$1,931.82" }, { item: "? Inverter split to 04A: MCI/RSD Gen 2 15A (1879359-15-X)", cost: "$39.02 ? ?panels?3?" }], note: "Inverter proxy cost + MCI shown in Section 04A Equipment. Adder = battery hardware only.", noteType: "ok", rec: "Use SEA." } },
  { key: "bat_texp", label: "Tesla PW3 ? Expansion Battery", isBattery: true, isQtyAdder: true, isTeslaExp: true, list: 7950, seaPartner: 0, intPartner: 0,
    detail: { summary: "Each additional Tesla expansion battery beyond the first Powerwall. No inverter split ? battery only.", crew: "2 electricians", truckRoll: false, hours: { sea: "$300 flat (no truck roll)", internal: "2 hrs ? 2 guys ? $61 = $244, no truck roll" }, bom: [{ item: "Domestic PW3 Expansion (1807000-20-Y)", cost: "$5,738.64" }, { item: "Harness 2M (1875157-20-Y)", cost: "$153.41" }, { item: "SEA labor", cost: "$300.00" }, { item: "SEA BOS buffer", cost: "$50.00" }, { item: "Internal BOS", cost: "$425.00" }, { item: "Internal labor alt.", cost: "2 hrs ? 2 ? $61 = $244.00" }], note: "No 35/65 adjustment on expansion batteries.", noteType: "ok", rec: "SEA slight advantage." } },
  { key: "bat_tpwx", label: "Tesla PW3 ? Additional Powerwall", isBattery: true, isQtyAdder: true, isTeslaPWX: true, list: 8500, seaPartner: 0, intPartner: 0,
    detail: { summary: "Each additional full Powerwall 3 beyond the first. Inverter portion (Tesla string inv. equiv.) split to Equipment in 04A. MCI/RSD already counted at lead unit ? not re-added here. Adder covers PW3 hardware, BOS, and labor.", crew: "2 electricians", truckRoll: false, hours: { sea: "$300 flat (no truck roll)", internal: "4 hrs ? 2 guys ? $61 = $488, no truck roll" }, bom: [{ item: "Tesla Powerwall 3 (1707000-21-Y)", cost: "$7,388.88" }, { item: "BOS", cost: "$59.00 (SEA) / $500.00 (internal)" }, { item: "SEA labor", cost: "$300.00" }, { item: "? Inverter split to 04A: Tesla Str. Inv. equiv. (1538000-45-X)", cost: "$1,931.82 per unit" }], note: "String inverter equivalent per additional PW3 shown in Section 04A. MCI not re-added beyond lead.", noteType: "ok", rec: "Use SEA." } },

  // Tesla AC-Coupled
  { key: "bat_tac1", label: "Tesla PW3 ? AC Coupled, 1st Unit w/ Gateway", isBattery: true, isTeslaACLead: true, list: 12700, seaPartner: 1150, intPartner: 732,
    detail: { summary: "First Tesla Powerwall 3 in AC-coupled configuration. PV inverter is Enphase or SolarEdge ? PW3 handles battery charge/discharge only. No MCI/RSD required. Full hardware cost in adder (no 35/65 split).", crew: "2 electricians", truckRoll: false, hours: { sea: "$1,150 flat (all-in)", internal: "6 hrs ? 2 guys ? $61 = $732, no truck roll" }, bom: [{ item: "Tesla Powerwall 3 (1707000-21-Y)", cost: "$7,388.88" }, { item: "Gateway 3 (1841000-01-Y)", cost: "$852.27" }, { item: "BOS", cost: "$4,250.00 (int) / $500.00 (SEA)" }, { item: "SEA labor", cost: "$1,150.00" }, { item: "No MCI/RSD ? AC coupled", cost: "N/A" }, { item: "No 35/65 split ? full cost in adder", cost: "applied" }], note: "SEA installed: $9,891.15. Internal: $13,223.15. No panel-count scaling.", noteType: "ok", rec: "Use SEA." } },
  { key: "bat_tacx", label: "Tesla PW3 ? AC Coupled, Additional Powerwall", isBattery: true, isQtyAdder: true, isTeslaACPWX: true, list: 8500, seaPartner: 0, intPartner: 0,
    detail: { summary: "Each additional PW3 beyond the first in AC-coupled mode. No Gateway, no MCI/RSD, no 35/65 split.", crew: "2 electricians", truckRoll: false, hours: { sea: "$300 flat (no truck roll)", internal: "4 hrs ? 2 guys ? $61 = $488" }, bom: [{ item: "Tesla Powerwall 3 (1707000-21-Y)", cost: "$7,388.88" }, { item: "SEA labor", cost: "$300.00" }, { item: "SEA BOS buffer", cost: "$59.00" }, { item: "Internal BOS", cost: "$500.00" }], note: "SEA installed: $7,747.88. Internal: $8,376.88. No panel-count scaling.", noteType: "ok", rec: "Use SEA." } },
  { key: "bat_tace", label: "Tesla PW3 ? AC Coupled, Expansion Battery", isBattery: true, isQtyAdder: true, isTeslaExp: true, list: 7950, seaPartner: 0, intPartner: 0,
    detail: { summary: "Expansion battery (no inverter) ? identical cost whether DC or AC coupled.", crew: "2 electricians", truckRoll: false, hours: { sea: "$300 flat (no truck roll)", internal: "2 hrs ? 2 guys ? $61 = $244" }, bom: [{ item: "Domestic PW3 Expansion (1807000-20-Y)", cost: "$5,738.64" }, { item: "Harness 2M (1875157-20-Y)", cost: "$153.41" }, { item: "SEA labor", cost: "$300.00" }, { item: "SEA BOS buffer", cost: "$50.00" }, { item: "Internal BOS", cost: "$425.00" }], note: "Same cost as DC-coupled expansion ? no inverter component.", noteType: "ok", rec: "SEA slight advantage." } },
];

// ??? ADDER SECTIONS + MAP ????????????????????????????????????????????????????

const ADDER_SECTIONS = [
  { title: "Electrical Adders", keys: ["mpu", "umr", "mbe", "sp", "mbdr", "mmc", "tap_box"]                                                       },
  { title: "Install Adders",    keys: ["steep", "high", "metal_roof", "trench", "small_system", "gm"]                                              },
  { title: "Misc Adders",       keys: ["home_repairs", "multi_array", "boring_base", "boring_0_100", "boring_101_200", "boring_201_plus", "heat_smoke", "ground_rods"] },
  { title: "Enphase Batteries", keys: ["bat_10c_1st", "bat_10c_add", "bat_enp1", "bat_enpa"]                                                        },
  { title: "SolarEdge Batteries", keys: ["bat_sebk", "bat_segt", "bat_se_add"]                                                                      },
  { title: "Tesla Batteries ? DC Coupled",  keys: ["bat_tpw1", "bat_texp", "bat_tpwx"]                                                              },
  { title: "Tesla Batteries ? AC Coupled",  keys: ["bat_tac1", "bat_tacx", "bat_tace"]                                                              },
];
const ADDER_MAP = Object.fromEntries(ADDERS.map(a => [a.key, a]));

// ??? HELPERS ?????????????????????????????????????????????????????????????????

const MARGIN_PRESETS = [0, 10, 15, 20, 25, 30, 35];
const fmt    = n => `$${Number(n).toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
const fmtPPW = n => `$${Number(n).toFixed(3)}/W`;
const rl     = (cost, pct) => pct === 0 ? cost : cost / (1 - pct / 100);

const calcTeslaACCost = (a, laborMode) => {
  const isSub = laborMode === "sub" || laborMode === "sea";
  if (a.isTeslaACLead) {
    const bos   = isSub ? 500 : 4250;
    const labor = isSub ? 1150 : (6 * 2 * 61);
    return 7388.88 + 852.27 + bos + labor;
  }
  if (a.isTeslaExp) {
    const bos   = isSub ? 50 : 425;
    const labor = isSub ? 300 : (2 * 2 * 61);
    return 5738.64 + 153.41 + labor + bos;
  }
  if (a.isTeslaACPWX) {
    const bos   = isSub ? 59 : 500;
    const labor = isSub ? 300 : (4 * 2 * 61);
    return 7388.88 + bos + labor;
  }
  return 0;
};

const adderCostFor = (a, labor, W, trenchFt, boringQuote, boringFt, isGroundMount = false, redlineSet = new Set()) => {
  const isSub = labor === "sub" || labor === "sea";
  const isInt = labor === "internal";
  if (redlineSet.has(a.key))   return a.sea || 0;
  if (a.isTrench)         { const ft = trenchFt || 120; const base = isGroundMount ? (a.seaBase ? 250 : 0) : (a.seaBase || 0); return isSub ? base + a.seaPFt * ft : isInt ? a.intPFt * ft : ((a.seaPFt + a.intPFt) / 2) * ft; }
  if (a.isBoringBase)     return boringQuote || 0;
  if (a.isBoringMaterial) { const ft = boringFt || 100; return isSub ? a.seaPFt * ft : isInt ? a.intPFt * ft : a.seaPFt * ft; }
  if (a.perW)             { const r = isSub ? a.seaW : isInt ? a.intW : (a.seaW + a.intW) / 2; return r * W; }
  return isSub ? a.sea : isInt ? a.int : (a.sea + a.int) / 2;
};

const adderListFor = (a, W, trenchFt, boringQuote, boringFt, redlineSet = new Set()) => {
  if (redlineSet.has(a.key))   return a.list || 0;
  if (a.isTrench)         return a.listBase + a.listPFt * (trenchFt || 120);
  if (a.isBoringBase)     return (boringQuote || 0) + 500;
  if (a.isBoringMaterial) return a.listPFt * (boringFt || 100);
  if (a.listW != null)    return a.listW * W;
  return a.list;
};

const calcTeslaCost = (a, laborMode, pCnt, pw3Price = 7388.88) => {
  const isSub = laborMode === "sub" || laborMode === "sea";
  if (a.isTeslaLead) {
    // Adder = PW3 unit + Gateway + BOS + Labor only
    // MCI and string inverter equivalent split off to 04A Equipment
    const bos   = isSub ? 500 : 4250;
    const labor = isSub ? 1150 : (6 * 2 * 61);
    return pw3Price + 852.27 + bos + labor;
  }
  if (a.isTeslaExp) {
    const bos   = isSub ? 50 : 425;
    const labor = isSub ? 300 : (2 * 2 * 61);
    return 5738.64 + 153.41 + labor + bos;
  }
  if (a.isTeslaPWX) {
    // Each additional PW3 ? no Gateway, no MCI (system-level already in lead)
    // String inverter equivalent split to 04A per unit
    const bos   = isSub ? 59 : 500;
    const labor = isSub ? 300 : (4 * 2 * 61);
    return pw3Price + labor + bos;
  }
  return 0;
};

// ??? COMPONENT ???????????????????????????????????????????????????????????????



const BOS_MASTER_DATA = [
  {upc:"78174720101",mfr:"BPT",sku:"101S",description:"1/2 STL CND LOCKNUT",unit_price:18.27,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174720101_101S"},
  {upc:"78174720102",mfr:"BPT",sku:"102S",description:"3/4 STL CND LOCKNUT",unit_price:19.29,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174720102_102S"},
  {upc:"78174720103",mfr:"BPT",sku:"103S",description:"1IN STL CND LOCKNUT",unit_price:23.69,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174720103_103S"},
  {upc:"78174709104",mfr:"BPT",sku:"104DC",description:"1-1/4 D/C LOCKNUT",unit_price:62.64,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174709104_104DC"},
  {upc:"78174709105",mfr:"BPT",sku:"105DC",description:"1-1/2 D/C LOCKNUT",unit_price:81.21,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174709105_105DC"},
  {upc:"78174701063",mfr:"BPT",sku:"1063",description:"1X3/4 RED WASH",unit_price:29.59,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174701063_1063"},
  {upc:"78174709106",mfr:"BPT",sku:"106DC",description:"2-IN D/C LOCKNUT",unit_price:117.39,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174709106_106DC"},
  {upc:"78174720106",mfr:"BPT",sku:"106S",description:"2IN STL CND LOCKNUT",unit_price:112.96,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174720106_106S"},
  {upc:"78174701252",mfr:"BPT",sku:"1252",description:"3/4 CLAMP ENTR CAP",unit_price:517.26,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174701252_1252"},
  {upc:"78174701253",mfr:"BPT",sku:"1253",description:"1-IN CLAMP ENTR CAP",unit_price:596.84,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174701253_1253"},
  {upc:"78174701254",mfr:"BPT",sku:"1254",description:"1-1/4 CLAMP ENTR CAP",unit_price:752.59,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174701254_1254"},
  {upc:"78174701255",mfr:"BPT",sku:"1255",description:"1-1/2 CLAMP ENTR CAP",unit_price:1128.99,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174701255_1255"},
  {upc:"78174701256",mfr:"BPT",sku:"1256",description:"2-IN CLAMP ENTR CAP",unit_price:1632.7,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174701256_1256"},
  {upc:"78174700142",mfr:"BPT",sku:"142",description:"3/4 SEALING LOCKNUT",unit_price:112.57,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174700142_142"},
  {upc:"78174700143",mfr:"BPT",sku:"143",description:"1-IN SEALING LOCKNUT",unit_price:215.71,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174700143_143"},
  {upc:"78174700144",mfr:"BPT",sku:"144",description:"1-1/4 SEALING LOCKNUT",unit_price:325.34,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174700144_144"},
  {upc:"78174700145",mfr:"BPT",sku:"145",description:"1-1/2 SEALING LOCKNUT",unit_price:373.0,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174700145_145"},
  {upc:"78174700146",mfr:"BPT",sku:"146",description:"2-IN SEALING LOCKNUT",unit_price:486.07,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174700146_146"},
  {upc:"78174791521",mfr:"BPT",sku:"1521DC",description:"3/4 D/C OFFSET NIP",unit_price:222.96,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174791521_1521DC"},
  {upc:"78174791522",mfr:"BPT",sku:"1522DC",description:"1-IN OFFSET NIP",unit_price:339.97,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174791522_1522DC"},
  {upc:"78174709152",mfr:"BPT",sku:"152DC",description:"3/4 D/C KO HUB",unit_price:622.2,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174709152_152DC"},
  {upc:"78174709153",mfr:"BPT",sku:"153DC",description:"1-IN D/C KO HUB",unit_price:723.44,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174709153_153DC"},
  {upc:"78174709154",mfr:"BPT",sku:"154DC",description:"1-1/4 D/C KO HUB",unit_price:868.13,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174709154_154DC"},
  {upc:"78174709155",mfr:"BPT",sku:"155DC",description:"1-1/2 D/C KO HUB",unit_price:845.54,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174709155_155DC"},
  {upc:"78174709156",mfr:"BPT",sku:"156DC",description:"2-IN D/C KO HUB",unit_price:1302.21,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174709156_156DC"},
  {upc:"78174701901",mfr:"BPT",sku:"1901",description:"1/2 2H COND STRAP",unit_price:24.29,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174701901_1901"},
  {upc:"78174701902",mfr:"BPT",sku:"1902",description:"3/4 2H COND STRAP",unit_price:27.27,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174701902_1902"},
  {upc:"78174701903",mfr:"BPT",sku:"1903",description:"1-IN 2H COND STRAP",unit_price:39.2,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174701903_1903"},
  {upc:"78174701904",mfr:"BPT",sku:"1904",description:"1-1/4 2H COND STRAP",unit_price:63.09,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174701904_1904"},
  {upc:"78174701905",mfr:"BPT",sku:"1905",description:"1-1/2 2H COND STRAP",unit_price:63.64,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174701905_1905"},
  {upc:"78174701906",mfr:"BPT",sku:"1906",description:"2-IN 2H COND STRAP",unit_price:110.01,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174701906_1906"},
  {upc:"78174702110",mfr:"BPT",sku:"2110",description:"3/4 COND HGR W/BOLT",unit_price:55.79,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174702110_2110"},
  {upc:"78174720211",mfr:"BPT",sku:"2110BN",description:"#1 STEEL 3/4'' COND HANGER",unit_price:66.89,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174720211_2110BN"},
  {upc:"78174718251",mfr:"BPT",sku:"251RT2",description:"3/4 R/T CMPRSN",unit_price:211.37,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174718251_251RT2"},
  {upc:"78174792510",mfr:"BPT",sku:"251RT2XL",description:"3/4 CONNECTOR",unit_price:280.67,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174792510_251RT2XL"},
  {upc:"78174718252",mfr:"BPT",sku:"252RT2",description:"1 R/T CMPRN CONN",unit_price:393.99,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174718252_252RT2"},
  {upc:"78174792520",mfr:"BPT",sku:"252RT2XL",description:"1IN CONNECTOR",unit_price:455.76,unit:"per 100",per:"C",category:"CONNECTOR",source:"Master BOS List 2026",id:"78174792520_252RT2XL"},
  {upc:"78174718253",mfr:"BPT",sku:"253RT2",description:"1-1/4 CMPRSN CONN",unit_price:717.0,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174718253_253RT2"},
  {upc:"78174718254",mfr:"BPT",sku:"254RT2",description:"1-1/2 CMPRSN CONN",unit_price:811.66,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174718254_254RT2"},
  {upc:"78174718255",mfr:"BPT",sku:"255RT2",description:"2IN CMPRSN CONN",unit_price:1179.89,unit:"per 100",per:"C",category:"CONNECTOR",source:"Master BOS List 2026",id:"78174718255_255RT2"},
  {upc:"78174714261",mfr:"BPT",sku:"261RT",description:"3/4 R/T CMPRS CPL",unit_price:219.63,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174714261_261RT"},
  {upc:"78174714262",mfr:"BPT",sku:"262RT",description:"1 R/T CMPRSN CPL",unit_price:386.2,unit:"per 100",per:"C",category:"MISC",source:"Master BOS List 2026",id:"78174714262_262RT"},
  {upc:"78174720262",mfr:"BPT",sku:"262SRT",description:"1IN EMT COUPLING",unit_price:297.8,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"78174720262_262SRT"},
  {upc:"78174714263",mfr:"BPT",sku:"263RT",description:"1-1/4 CMPRSN CPLG",unit_price:737.47,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174714263_263RT"},
  {upc:"78174714264",mfr:"BPT",sku:"264RT",description:"1-1/2 CMPRSN CPLG",unit_price:867.04,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174714264_264RT"},
  {upc:"78174714265",mfr:"BPT",sku:"265RT",description:"2IN CMPRSN CPLG",unit_price:1052.81,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174714265_265RT"},
  {upc:"78174703011",mfr:"BPT",sku:"3001RT",description:"3/4 CONNECTOR",unit_price:913.29,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703011_3001RT"},
  {upc:"78174703012",mfr:"BPT",sku:"3002RT",description:"1IN CONNECTOR",unit_price:1358.49,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703012_3002RT"},
  {upc:"78174703013",mfr:"BPT",sku:"3003RT",description:"1-1/4 CONNECTOR",unit_price:2617.76,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703013_3003RT"},
  {upc:"78174703014",mfr:"BPT",sku:"3004RT",description:"1-1/2 CONNECTOR",unit_price:3435.76,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703014_3004RT"},
  {upc:"78174703015",mfr:"BPT",sku:"3005RT",description:"2IN CONNECTOR",unit_price:7667.57,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703015_3005RT"},
  {upc:"78174703111",mfr:"BPT",sku:"3101RT",description:"3/4 COUPLING",unit_price:1184.57,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703111_3101RT"},
  {upc:"78174703112",mfr:"BPT",sku:"3102RT",description:"1IN COUPLING",unit_price:1972.7,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703112_3102RT"},
  {upc:"78174703113",mfr:"BPT",sku:"3103RT",description:"1-1/4 COUPLING",unit_price:3075.91,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703113_3103RT"},
  {upc:"78174703114",mfr:"BPT",sku:"3104RT",description:"1-1/2 COUPLING",unit_price:4346.96,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703114_3104RT"},
  {upc:"78174703115",mfr:"BPT",sku:"3105RT",description:"2IN COUPLING",unit_price:10443.53,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703115_3105RT"},
  {upc:"78174700322",mfr:"BPT",sku:"322",description:"3/4 105D PLSTC BUSH",unit_price:11.01,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174700322_322"},
  {upc:"78174700323",mfr:"BPT",sku:"323",description:"1-IN 105D PLSTC BUSH",unit_price:21.43,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174700323_323"},
  {upc:"78174700324",mfr:"BPT",sku:"324",description:"1-1/4 105D PLSTC BUSH",unit_price:27.26,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174700324_324"},
  {upc:"78174700325",mfr:"BPT",sku:"325",description:"1-1/2 105D PLSTC BUSH",unit_price:33.29,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174700325_325"},
  {upc:"78174700326",mfr:"BPT",sku:"326",description:"2-IN 105D PLSTC BUSH",unit_price:63.47,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174700326_326"},
  {upc:"78174709382",mfr:"BPT",sku:"382DC",description:"3/4 INS GRND BUSH",unit_price:371.79,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174709382_382DC"},
  {upc:"78174709383",mfr:"BPT",sku:"383DC",description:"1-IN INS GRD BUSH",unit_price:497.73,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174709383_383DC"},
  {upc:"78174709384",mfr:"BPT",sku:"384DC",description:"1-1/4 INS GRD BUSH",unit_price:632.16,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174709384_384DC"},
  {upc:"78174709385",mfr:"BPT",sku:"385DC",description:"1-1/2 INS GRD BUSH",unit_price:630.39,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174709385_385DC"},
  {upc:"78174709386",mfr:"BPT",sku:"386DC",description:"2-IN INS GRD BUSH",unit_price:889.76,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174709386_386DC"},
  {upc:"78174715408",mfr:"BPT",sku:"408DC2",description:"3/4 SQZ FLEX CONN",unit_price:168.7,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174715408_408DC2"},
  {upc:"78174715410",mfr:"BPT",sku:"410DC2",description:"1-IN SQZ FLEX CONN",unit_price:324.96,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174715410_410DC2"},
  {upc:"78174715414",mfr:"BPT",sku:"414DC2",description:"1-1/2 SQZ FLEXCONN",unit_price:1589.1,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174715414_414DC2"},
  {upc:"78174715431",mfr:"BPT",sku:"431LT2",description:"3/4 STR L/T CONN",unit_price:329.84,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174715431_431LT2"},
  {upc:"78174744431",mfr:"BPT",sku:"431NMLTS",description:"3/4 STR L/T CONN",unit_price:183.6,unit:"per 100",per:"C",category:"CONNECTOR",source:"Master BOS List 2026",id:"78174744431_431NMLTS"},
  {upc:"78174715432",mfr:"BPT",sku:"432LT2",description:"1-IN STR L/T CONN",unit_price:564.51,unit:"per 100",per:"C",category:"CONNECTOR",source:"Master BOS List 2026",id:"78174715432_432LT2"},
  {upc:"78174740432",mfr:"BPT",sku:"432NMLT",description:"1-IN NM LT CONN",unit_price:255.41,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174740432_432NMLT"},
  {upc:"78174740433",mfr:"BPT",sku:"433NMLT",description:"1-1/4IN NONMT LQD",unit_price:1144.19,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174740433_433NMLT"},
  {upc:"78174740434",mfr:"BPT",sku:"434NMLT",description:"1-1/2IN NONMT LQD",unit_price:1643.11,unit:"per 100",per:"C",category:"MISC",source:"Master BOS List 2026",id:"78174740434_434NMLT"},
  {upc:"78174740435",mfr:"BPT",sku:"435NMLT",description:"2IN NONMETLC LQDT",unit_price:2366.54,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174740435_435NMLT"},
  {upc:"78174715471",mfr:"BPT",sku:"471LT2",description:"3/4 90D L/T CONN",unit_price:577.06,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174715471_471LT2"},
  {upc:"78174744471",mfr:"BPT",sku:"471NMLTS",description:"3/4 90D L/T CONN",unit_price:298.93,unit:"per 100",per:"C",category:"CONNECTOR",source:"Master BOS List 2026",id:"78174744471_471NMLTS"},
  {upc:"78174715472",mfr:"BPT",sku:"472LT2",description:"1-IN 90D L/T CONN",unit_price:1018.57,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174715472_472LT2"},
  {upc:"78174740472",mfr:"BPT",sku:"472NMLT",description:"1-IN 90D L/T CONN",unit_price:406.94,unit:"per 100",per:"C",category:"CONNECTOR",source:"Master BOS List 2026",id:"78174740472_472NMLT"},
  {upc:"78174740473",mfr:"BPT",sku:"473NMLT",description:"1-1/4IN 90DEG LQD",unit_price:2140.53,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174740473_473NMLT"},
  {upc:"78174740474",mfr:"BPT",sku:"474NMLT",description:"1-1/2IN 90DEG LQD",unit_price:2588.66,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174740474_474NMLT"},
  {upc:"78174740475",mfr:"BPT",sku:"475NMLT",description:"2IN 90 DEG LQDT",unit_price:2853.01,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174740475_475NMLT"},
  {upc:"78174715521",mfr:"BPT",sku:"521DC2",description:"3/4 SCR-IN FLXCONN",unit_price:63.17,unit:"per 100",per:"C",category:"CONNECTOR",source:"Master BOS List 2026",id:"78174715521_521DC2"},
  {upc:"78174715522",mfr:"BPT",sku:"522DC2",description:"1-IN FLEX CONN",unit_price:192.11,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174715522_522DC2"},
  {upc:"78174709582",mfr:"BPT",sku:"582DC",description:"3/4 EMT TO FLX CPLG",unit_price:285.44,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"78174709582_582DC"},
  {upc:"78174709583",mfr:"BPT",sku:"583DC",description:"1-IN EMT-FLEX CPLG",unit_price:358.29,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"78174709583_583DC"},
  {upc:"78174709062",mfr:"BPT",sku:"62DC",description:"3/4 EMT/EMT PULL EL",unit_price:775.89,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174709062_62DC"},
  {upc:"78174715650",mfr:"BPT",sku:"650DC2",description:"3/8 2SCR SEC CONN",unit_price:33.91,unit:"per 100",per:"C",category:"CONNECTOR",source:"Master BOS List 2026",id:"78174715650_650DC2"},
  {upc:"78174715662",mfr:"BPT",sku:"662DC2",description:"1-IN 2SCR SEC CONN",unit_price:249.01,unit:"per 100",per:"C",category:"CONNECTOR",source:"Master BOS List 2026",id:"78174715662_662DC2"},
  {upc:"78174715664",mfr:"BPT",sku:"664DC2",description:"1-1/4 2SCR SEC CON",unit_price:321.99,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174715664_664DC2"},
  {upc:"78174715666",mfr:"BPT",sku:"666DC2",description:"2-IN 2SCR SEC CONN",unit_price:612.63,unit:"per 100",per:"C",category:"CONNECTOR",source:"Master BOS List 2026",id:"78174715666_666DC2"},
  {upc:"78174715670",mfr:"BPT",sku:"670DC2",description:"3/4 2SCR SEC CONN",unit_price:97.99,unit:"per 100",per:"C",category:"CONNECTOR",source:"Master BOS List 2026",id:"78174715670_670DC2"},
  {upc:"78174715807",mfr:"BPT",sku:"807DC2",description:"1-IN 90D FLEX CONN",unit_price:775.61,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174715807_807DC2"},
  {upc:"78174702905",mfr:"BPT",sku:"905S",description:"1-1/2 1H COND STRAP",unit_price:155.13,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174702905_905S"},
  {upc:"78174700921",mfr:"BPT",sku:"921S",description:"3/4 1H STL EMT STRAP",unit_price:19.5,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174700921_921S"},
  {upc:"78174700922",mfr:"BPT",sku:"922S",description:"1-IN 1H STL EMTSTRAP",unit_price:24.64,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174700922_922S"},
  {upc:"78174700923",mfr:"BPT",sku:"923S",description:"1-1/4 1H EMT STRAP",unit_price:45.77,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174700923_923S"},
  {upc:"78174700730",mfr:"BPT",sku:"DS100",description:"1LB NO-ASB DCT SEAL",unit_price:340.04,unit:"per 100",per:"C",category:"MISC",source:"Master BOS List 2026",id:"78174700730_DS100"},
  {upc:"78174701352",mfr:"BPT",sku:"GRC63",description:"5/8 GRND ROD CLMP",unit_price:540.2,unit:"per 100",per:"C",category:"GROUNDING",source:"Master BOS List 2026",id:"78174701352_GRC63"},
  {upc:"78174703642",mfr:"BPT",sku:"LB42CG",description:"3/4 AL BODY ASBLY",unit_price:548.39,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703642_LB42CG"},
  {upc:"78174703643",mfr:"BPT",sku:"LB43CG",description:"1IN AL BODY ASBLY",unit_price:734.73,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703643_LB43CG"},
  {upc:"78174703644",mfr:"BPT",sku:"LB44CG",description:"1-1/4 AL BODY ASSY",unit_price:1328.84,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703644_LB44CG"},
  {upc:"78174703645",mfr:"BPT",sku:"LB45CG",description:"1-1/2 AL BODY ASSY",unit_price:1441.04,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703645_LB45CG"},
  {upc:"78174703646",mfr:"BPT",sku:"LB46CG",description:"2IN AL BODY ASBLY",unit_price:2601.36,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703646_LB46CG"},
  {upc:"78174703542",mfr:"BPT",sku:"LL42CG",description:"3/4IN RGD CNDT BDY",unit_price:548.39,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703542_LL42CG"},
  {upc:"78174703543",mfr:"BPT",sku:"LL43CG",description:"1IN RGD CNDT BDY",unit_price:734.73,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703543_LL43CG"},
  {upc:"78174703544",mfr:"BPT",sku:"LL44CG",description:"1 1/4IN CNDUIT BDY",unit_price:1328.84,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703544_LL44CG"},
  {upc:"78174703545",mfr:"BPT",sku:"LL45CG",description:"1 1/2IN CNDUIT BDY",unit_price:1441.04,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703545_LL45CG"},
  {upc:"78174703546",mfr:"BPT",sku:"LL46CG",description:"2IN RGD CNDT BDY",unit_price:2601.36,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703546_LL46CG"},
  {upc:"78174703742",mfr:"BPT",sku:"LR42CG",description:"3/4IN RGD CNDT BDY",unit_price:548.39,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703742_LR42CG"},
  {upc:"78174703743",mfr:"BPT",sku:"LR43CG",description:"1IN RGD CNDT BDY",unit_price:734.73,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703743_LR43CG"},
  {upc:"78174703744",mfr:"BPT",sku:"LR44CG",description:"1 1/4IN CNDUIT BDY",unit_price:1328.84,unit:"per 100",per:"C",category:"MISC",source:"Master BOS List 2026",id:"78174703744_LR44CG"},
  {upc:"78174703745",mfr:"BPT",sku:"LR45CG",description:"1-1/2 CNDBDY/CVR",unit_price:1441.04,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703745_LR45CG"},
  {upc:"78174703746",mfr:"BPT",sku:"LR46CG",description:"2IN RGD CNDT BDY",unit_price:26.0,unit:"each",per:"E",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703746_LR46CG"},
  {upc:"78174790701",mfr:"BPT",sku:"MWH1",description:"ADJUSTABLE WR HLDR",unit_price:1633.33,unit:"per 100",per:"C",category:"MISC",source:"Master BOS List 2026",id:"78174790701_MWH1"},
  {upc:"78174738114",mfr:"BPT",sku:"NIP075200",description:"3/4X2 STL NIP",unit_price:139.67,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174738114_NIP075200"},
  {upc:"78174738112",mfr:"BPT",sku:"NIP075CL",description:"3/4X1-3/8 NIP",unit_price:109.7,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174738112_NIP075CL"},
  {upc:"78174738131",mfr:"BPT",sku:"NIP100600",description:"1X6 STL NIP",unit_price:356.49,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174738131_NIP100600"},
  {upc:"78174738124",mfr:"BPT",sku:"NIP100CL",description:"1X1-1/2 STL NIP",unit_price:165.97,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174738124_NIP100CL"},
  {upc:"78174738135",mfr:"BPT",sku:"NIP125CL",description:"1-1/4X1-5/8 NIP",unit_price:243.67,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174738135_NIP125CL"},
  {upc:"78174738163",mfr:"BPT",sku:"NIP200600",description:"2X6 STL NIP",unit_price:806.99,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174738163_NIP200600"},
  {upc:"78174738157",mfr:"BPT",sku:"NIP200CL",description:"2X2 STL NIP",unit_price:349.17,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174738157_NIP200CL"},
  {upc:"78174714106",mfr:"BPT",sku:"RF200",description:"2IN ROOF FLASHING",unit_price:2624.87,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174714106_RF200"},
  {upc:"78174740491",mfr:"BPT",sku:"SR075",description:"3/4 SEAL RNG&RTNR",unit_price:77.63,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174740491_SR075"},
  {upc:"78174740492",mfr:"BPT",sku:"SR100",description:"1IN SEAL RNG&RTNR",unit_price:93.59,unit:"per 100",per:"C",category:"MISC",source:"Master BOS List 2026",id:"78174740492_SR100"},
  {upc:"78174703042",mfr:"BPT",sku:"T42CG",description:"3/4IN RGD CNDT BDY",unit_price:692.74,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703042_T42CG"},
  {upc:"78174703043",mfr:"BPT",sku:"T43CG",description:"1IN RIGID CNDT BODY",unit_price:978.13,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703043_T43CG"},
  {upc:"78174703044",mfr:"BPT",sku:"T44CG",description:"1 1/4IN CNDT BDY",unit_price:1623.63,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703044_T44CG"},
  {upc:"78174703045",mfr:"BPT",sku:"T45CG",description:"1 1/2IN CNDT BDY",unit_price:1857.87,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703045_T45CG"},
  {upc:"78174703046",mfr:"BPT",sku:"T46CG",description:"2-IN AL BODY W/CVR",unit_price:2927.56,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174703046_T46CG"},
  {upc:"78174740052",mfr:"BPT",sku:"TWB52",description:"3/4 EMT INSUL BSHG",unit_price:14.04,unit:"per 100",per:"C",category:"MISC",source:"Master BOS List 2026",id:"78174740052_TWB52"},
  {upc:"78174740053",mfr:"BPT",sku:"TWB53",description:"1IN EMT INSUL BSHG",unit_price:50.44,unit:"per 100",per:"C",category:"MISC",source:"Master BOS List 2026",id:"78174740053_TWB53"},
  {upc:"78174740054",mfr:"BPT",sku:"TWB54",description:"1 -1/4 INSUL BSHG",unit_price:88.56,unit:"per 100",per:"C",category:"MISC",source:"Master BOS List 2026",id:"78174740054_TWB54"},
  {upc:"78174740055",mfr:"BPT",sku:"TWB55",description:"1 -1/2 INSUL BSHG",unit_price:161.53,unit:"per 100",per:"C",category:"MISC",source:"Master BOS List 2026",id:"78174740055_TWB55"},
  {upc:"78174740056",mfr:"BPT",sku:"TWB56",description:"2IN INSUL BUSHING",unit_price:163.56,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78174740056_TWB56"},
  {upc:"78590145941",mfr:"SQD",sku:"B075",description:"HUB 0.75 INCHES RAINPROOF",unit_price:8.89,unit:"each",per:"E",category:"FITTINGS",source:"Master BOS List 2026",id:"78590145941_B075"},
  {upc:"78590145942",mfr:"SQD",sku:"B100",description:"HUB 1 INCH RAINPROOF FOR",unit_price:7.78,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590145942_B100"},
  {upc:"78590145944",mfr:"SQD",sku:"B125",description:"HUB 1.25 INCHES RAINPROOF",unit_price:8.89,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590145944_B125"},
  {upc:"78590145945",mfr:"SQD",sku:"B150",description:"HUB 1.50 INCHES RAINPROOF",unit_price:8.89,unit:"each",per:"E",category:"FITTINGS",source:"Master BOS List 2026",id:"78590145945_B150"},
  {upc:"78590145947",mfr:"SQD",sku:"B200",description:"HUB 2 INCHES RAINPROOF FOR",unit_price:19.84,unit:"each",per:"E",category:"FITTINGS",source:"Master BOS List 2026",id:"78590145947_B200"},
  {upc:"78590146058",mfr:"SQD",sku:"D221NRB",description:"SWITCH FUSIBLE GD 240V 30A 2P",unit_price:73.86,unit:"each",per:"E",category:"DISCONNECT",source:"Master BOS List 2026",id:"78590146058_D221NRB"},
  {upc:"78590146064",mfr:"SQD",sku:"D222NRB",description:"SWITCH FUSIBLE GD 240V 60A 2P NEM",unit_price:128.07,unit:"each",per:"E",category:"DISCONNECT",source:"Master BOS List 2026",id:"78590146064_D222NRB"},
  {upc:"78590146070",mfr:"SQD",sku:"D223NRB",description:"SWITCH FUSIBLE GD 240V 100A 2P 3R",unit_price:188.57,unit:"each",per:"E",category:"DISCONNECT",source:"Master BOS List 2026",id:"78590146070_D223NRB"},
  {upc:"78590146074",mfr:"SQD",sku:"D224N",description:"SWITCH FUSIBLE GD 240V",unit_price:454.63,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590146074_D224N"},
  {upc:"78590146076",mfr:"SQD",sku:"D224NRB",description:"SWITCH FUSIBLE GD 240V",unit_price:471.43,unit:"each",per:"E",category:"DISCONNECT",source:"Master BOS List 2026",id:"78590146076_D224NRB"},
  {upc:"78590117452",mfr:"SQD",sku:"DTU224NRB",description:"SW NOT FUSIBLE DT",unit_price:930.94,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590117452_DTU224NRB"},
  {upc:"78590149034",mfr:"SQD",sku:"DU221RB",description:"SWITCH NOT FUSIBLE GD 240V 30A 2P",unit_price:69.54,unit:"each",per:"E",category:"DISCONNECT",source:"Master BOS List 2026",id:"78590149034_DU221RB"},
  {upc:"78590108512",mfr:"SQD",sku:"DU221RBUP1",description:"2P 30A NON-FUSIBLE SAFETY SWITCH",unit_price:46.36,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590108512_DU221RBUP1"},
  {upc:"78590149149",mfr:"SQD",sku:"DU222RB",description:"60A NF 1PH 2P 240V AC NEMA 3",unit_price:138.69,unit:"each",per:"E",category:"DISCONNECT",source:"Master BOS List 2026",id:"78590149149_DU222RB"},
  {upc:"78590175138",mfr:"SQD",sku:"GTK0610",description:"KIT EQUIPMENT GROUND",unit_price:12.16,unit:"each",per:"E",category:"GROUNDING",source:"Master BOS List 2026",id:"78590175138_GTK0610"},
  {upc:"78590100872",mfr:"SQD",sku:"HEPD80",description:"SPD T1 HEPD 80KA",unit_price:112.5,unit:"each",per:"E",category:"MISC",source:"Master BOS List 2026",id:"78590100872_HEPD80"},
  {upc:"78590106520",mfr:"SQD",sku:"HOM115",description:"MINIATURE CIRCUIT",unit_price:5.47,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106520_HOM115"},
  {upc:"78590106536",mfr:"SQD",sku:"HOM115GFI",description:"MINIATURE CIRCUIT",unit_price:52.35,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106536_HOM115GFI"},
  {upc:"78590106521",mfr:"SQD",sku:"HOM120",description:"MINIATURE CIRCUIT",unit_price:5.47,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106521_HOM120"},
  {upc:"78590106537",mfr:"SQD",sku:"HOM120GFI",description:"MINIATURE CIRCUIT",unit_price:52.35,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106537_HOM120GFI"},
  {upc:"78590159447",mfr:"SQD",sku:"HOM120PCAFI",description:"MINIATURE CIRCUIT",unit_price:52.35,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590159447_HOM120PCAFI"},
  {upc:"78590187612",mfr:"SQD",sku:"HOM1224L125PC",description:"HOM INDR 125A MLO",unit_price:40.59,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590187612_HOM1224L125PC"},
  {upc:"78590186367",mfr:"SQD",sku:"HOM1224L125PRB",description:"HOM OUTD 125A",unit_price:81.91,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590186367_HOM1224L125PRB"},
  {upc:"78590186119",mfr:"SQD",sku:"HOM1224M100PRB",description:"HOM OUTD 100A MB",unit_price:115.8,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590186119_HOM1224M100PRB"},
  {upc:"78590106522",mfr:"SQD",sku:"HOM130",description:"MINIATURE CIRCUIT",unit_price:5.47,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106522_HOM130"},
  {upc:"78590106524",mfr:"SQD",sku:"HOM140",description:"MINIATURE CIRCUIT",unit_price:6.8,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106524_HOM140"},
  {upc:"78590107656",mfr:"SQD",sku:"HOM1RK",description:"LOAD CENTER HOM BREAKER",unit_price:2.25,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590107656_HOM1RK"},
  {upc:"78590184755",mfr:"SQD",sku:"HOM2040L125PRB",description:"HOM OUTD 125A",unit_price:109.76,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590184755_HOM2040L125PRB"},
  {upc:"78590197718",mfr:"SQD",sku:"HOM2040M200PRB",description:"HOM OUTD 200A MB",unit_price:219.37,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590197718_HOM2040M200PRB"},
  {upc:"78590106575",mfr:"SQD",sku:"HOM2100",description:"MINIATURE CIRCUIT",unit_price:44.21,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106575_HOM2100"},
  {upc:"78590106526",mfr:"SQD",sku:"HOM215",description:"MINIATURE CIRCUIT",unit_price:12.47,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106526_HOM215"},
  {upc:"78590106528",mfr:"SQD",sku:"HOM220",description:"MINIATURE CIRCUIT",unit_price:12.47,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106528_HOM220"},
  {upc:"78590106588",mfr:"SQD",sku:"HOM2200",description:"MINIATURE CIRCUIT",unit_price:102.67,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106588_HOM2200"},
  {upc:"78590106548",mfr:"SQD",sku:"HOM225",description:"MINIATURE CIRCUIT",unit_price:12.47,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106548_HOM225"},
  {upc:"78590106529",mfr:"SQD",sku:"HOM230",description:"MINIATURE CIRCUIT",unit_price:12.47,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106529_HOM230"},
  {upc:"78590106530",mfr:"SQD",sku:"HOM240",description:"MINIATURE CIRCUIT",unit_price:12.47,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106530_HOM240"},
  {upc:"78590197713",mfr:"SQD",sku:"HOM2448M100PC",description:"HOM INDR 100A MB",unit_price:115.56,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590197713_HOM2448M100PC"},
  {upc:"78590106550",mfr:"SQD",sku:"HOM245",description:"MINIATURE CIRCUIT",unit_price:12.47,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106550_HOM245"},
  {upc:"78590106532",mfr:"SQD",sku:"HOM250",description:"MINIATURE CIRCUIT",unit_price:12.47,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106532_HOM250"},
  {upc:"78590106533",mfr:"SQD",sku:"HOM260",description:"MINIATURE CIRCUIT",unit_price:12.47,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106533_HOM260"},
  {upc:"78590106534",mfr:"SQD",sku:"HOM270",description:"MINIATURE CIRCUIT",unit_price:32.37,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106534_HOM270"},
  {upc:"78590106567",mfr:"SQD",sku:"HOM280",description:"MINIATURE CIRCUIT",unit_price:44.21,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106567_HOM280"},
  {upc:"78590106571",mfr:"SQD",sku:"HOM290",description:"MINIATURE CIRCUIT",unit_price:44.21,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106571_HOM290"},
  {upc:"78590197775",mfr:"SQD",sku:"HOM3060M200PC",description:"HOM INDR 200A MB",unit_price:125.47,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590197775_HOM3060M200PC"},
  {upc:"78590197807",mfr:"SQD",sku:"HOM3060M200PRB",description:"HOM OUTD 200A MB",unit_price:295.8,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590197807_HOM3060M200PRB"},
  {upc:"78590197757",mfr:"SQD",sku:"HOM4080M200PC",description:"HOM INDR 200A MB",unit_price:163.08,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590197757_HOM4080M200PC"},
  {upc:"78590197435",mfr:"SQD",sku:"HOM4284L225PC",description:"HOM INDR 225A MLO",unit_price:158.11,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590197435_HOM4284L225PC"},
  {upc:"78590106119",mfr:"SQD",sku:"HOM612L100S",description:"LOAD CENTER HOM MLO",unit_price:21.69,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106119_HOM612L100S"},
  {upc:"78590197399",mfr:"SQD",sku:"HOM816L125PRB",description:"HOM OUTD 125A MLO",unit_price:69.05,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590197399_HOM816L125PRB"},
  {upc:"78590107655",mfr:"SQD",sku:"HOMFP",description:"LOAD CENTER HOM FILLER",unit_price:1.11,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590107655_HOMFP"},
  {upc:"78590106538",mfr:"SQD",sku:"HOMT1515",description:"MINIATURE CIRCUIT",unit_price:10.8,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106538_HOMT1515"},
  {upc:"78590106540",mfr:"SQD",sku:"HOMT2020",description:"MINIATURE CIRCUIT",unit_price:10.8,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590106540_HOMT2020"},
  {upc:"78590197045",mfr:"SQD",sku:"HOMT230230",description:"MINIATURE CKT BRKR",unit_price:25.31,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590197045_HOMT230230"},
  {upc:"78590106565",mfr:"SQD",sku:"LK70AN",description:"LOAD CENTER NEUTRAL LUG",unit_price:4.56,unit:"each",per:"E",category:"GROUNDING",source:"Master BOS List 2026",id:"78590106565_LK70AN"},
  {upc:"60648053467",mfr:"SQD",sku:"NSYTRAAB35",description:"END BRACKET SNAP-ON",unit_price:2.03,unit:"each",per:"E",category:"FITTINGS",source:"Master BOS List 2026",id:"60648053467_NSYTRAAB35"},
  {upc:"60648053354",mfr:"SQD",sku:"NSYTRAC22",description:"END COVER 2PTS FOR",unit_price:0.83,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"60648053354_NSYTRAC22"},
  {upc:"60648053413",mfr:"SQD",sku:"NSYTRAL42",description:"PLUG-IN BRIDGE 2PTS",unit_price:0.67,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"60648053413_NSYTRAL42"},
  {upc:"60648053217",mfr:"SQD",sku:"NSYTRV352PE",description:"SCREW TERMINAL",unit_price:17.76,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"60648053217_NSYTRV352PE"},
  {upc:"60648053189",mfr:"SQD",sku:"NSYTRV42",description:"SCREW TERMINAL 2PTS",unit_price:2.03,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"60648053189_NSYTRV42"},
  {upc:"78590102641",mfr:"SQD",sku:"PK15GTA",description:"SQD GROUND/NEUTRAL BAR",unit_price:7.73,unit:"each",per:"E",category:"GROUNDING",source:"Master BOS List 2026",id:"78590102641_PK15GTA"},
  {upc:"78590115681",mfr:"SQD",sku:"PK27GTA",description:"LOAD CENTER EQUIPMENT",unit_price:15.27,unit:"each",per:"E",category:"GROUNDING",source:"Master BOS List 2026",id:"78590115681_PK27GTA"},
  {upc:"78590102637",mfr:"SQD",sku:"PK7GTA",description:"LOAD CENTER EQUIPMENT",unit_price:5.29,unit:"each",per:"E",category:"GROUNDING",source:"Master BOS List 2026",id:"78590102637_PK7GTA"},
  {upc:"78590143267",mfr:"SQD",sku:"PKOGTA2",description:"EQUIP GRD ASSY 240V +",unit_price:35.36,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590143267_PKOGTA2"},
  {upc:"78590150130",mfr:"SQD",sku:"QO2100",description:"MINIATURE CIRCUIT",unit_price:69.9,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590150130_QO2100"},
  {upc:"04756951762",mfr:"SQD",sku:"QO2100NRBCP",description:"100A BREAKER ENCLOSURE W MAIN BREAKER",unit_price:57.93,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"04756951762_QO2100NRBCP"},
  {upc:"78590140036",mfr:"SQD",sku:"QO220",description:"MINIATURE CIRCUIT BREAKER",unit_price:22.27,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590140036_QO220"},
  {upc:"78590101241",mfr:"SQD",sku:"QO225",description:"MINIATURE CIRCUIT BREAKER",unit_price:22.27,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590101241_QO225"},
  {upc:"78590140042",mfr:"SQD",sku:"QO230",description:"MINIATURE CIRCUIT BREAKER",unit_price:22.27,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590140042_QO230"},
  {upc:"78590101242",mfr:"SQD",sku:"QO235",description:"MINIATURE CIRCUIT BREAKER",unit_price:22.27,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590101242_QO235"},
  {upc:"78590140048",mfr:"SQD",sku:"QO240",description:"MINIATURE CIRCUIT BREAKER",unit_price:22.27,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590140048_QO240"},
  {upc:"78590140052",mfr:"SQD",sku:"QO250",description:"MINIATURE CIRCUIT BREAKER",unit_price:22.27,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590140052_QO250"},
  {upc:"78590140056",mfr:"SQD",sku:"QO260",description:"MINIATURE CIRCUIT BREAKER",unit_price:22.27,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590140056_QO260"},
  {upc:"78590140058",mfr:"SQD",sku:"QO270",description:"MINIATURE CIRCUIT BREAKER",unit_price:53.53,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590140058_QO270"},
  {upc:"78590150132",mfr:"SQD",sku:"QO280",description:"MINIATURE CIRCUIT BREAKER",unit_price:69.9,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590150132_QO280"},
  {upc:"78590150131",mfr:"SQD",sku:"QO290",description:"MINIATURE CIRCUIT BREAKER",unit_price:69.9,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590150131_QO290"},
  {upc:"78590100403",mfr:"SQD",sku:"QOM100VH",description:"MINIATURE CIRCUIT",unit_price:57.09,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590100403_QOM100VH"},
  {upc:"78590102195",mfr:"SQD",sku:"QOM2100VH",description:"MINIATURE CIRCUIT",unit_price:132.91,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590102195_QOM2100VH"},
  {upc:"78590102197",mfr:"SQD",sku:"QOM2125VH",description:"MINIATURE CIRCUIT",unit_price:132.91,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590102197_QOM2125VH"},
  {upc:"78590100405",mfr:"SQD",sku:"QOM2150VH",description:"MINIATURE CIRCUIT",unit_price:132.91,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590100405_QOM2150VH"},
  {upc:"78590184858",mfr:"SQD",sku:"QOM2175VH",description:"MINIATURE CIRCUIT",unit_price:132.91,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590184858_QOM2175VH"},
  {upc:"78590100406",mfr:"SQD",sku:"QOM2200VH",description:"MINIATURE CIRCUIT",unit_price:132.91,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590100406_QOM2200VH"},
  {upc:"78590137530",mfr:"SQD",sku:"QOM2E2200NRB",description:"200A BREAKER ENCLOSURE W MAIN BREAKER",unit_price:257.87,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"78590137530_QOM2E2200NRB"},
  {upc:"60648589410",mfr:"SQD",sku:"VH363NRB",description:"3P 100A SFTY SWITCH",unit_price:631.27,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"60648589410_VH363NRB"},
  {upc:"60648589451",mfr:"SQD",sku:"VHU361RB",description:"3P 30A SFTY SWITCH",unit_price:165.53,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"60648589451_VHU361RB"},
  {upc:"60648589466",mfr:"SQD",sku:"VHU362RB",description:"3P 60A SFTY SWITCH",unit_price:297.13,unit:"each",per:"E",category:"DISCONNECT",source:"Master BOS List 2026",id:"60648589466_VHU362RB"},
  {upc:"78667636210",mfr:"EATON",sku:"BR120",description:"SP-120/240V-20A CB",unit_price:8.06,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667636210_BR120"},
  {upc:"78667637025",mfr:"EATON",sku:"BR2020",description:"2P 20A CB",unit_price:41.14,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667637025_BR2020"},
  {upc:"78667636325",mfr:"EATON",sku:"BR2100",description:"2P-120/240V-100A CB",unit_price:79.94,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667636325_BR2100"},
  {upc:"78667636705",mfr:"EATON",sku:"BR2125",description:"2P-120/240V-125A CB",unit_price:160.0,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667636705_BR2125"},
  {upc:"78667636280",mfr:"EATON",sku:"BR215",description:"2P-120/240V-15A CB",unit_price:26.67,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667636280_BR215"},
  {upc:"78667600883",mfr:"EATON",sku:"BR215B",description:"2P 15A CB",unit_price:36.51,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667600883_BR215B"},
  {upc:"78667636285",mfr:"EATON",sku:"BR220",description:"2P-120/240V-20A CB",unit_price:15.03,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667636285_BR220"},
  {upc:"78667600884",mfr:"EATON",sku:"BR220B",description:"2P 20A CB",unit_price:36.51,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667600884_BR220B"},
  {upc:"78667636290",mfr:"EATON",sku:"BR225",description:"2P-120/240V-25A CB",unit_price:24.83,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667636290_BR225"},
  {upc:"78667636295",mfr:"EATON",sku:"BR230",description:"2P-120/240V-30A CB",unit_price:24.29,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667636295_BR230"},
  {upc:"78667636300",mfr:"EATON",sku:"BR240",description:"2P-120/240V-40A CB",unit_price:21.74,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667636300_BR240"},
  {upc:"78667636305",mfr:"EATON",sku:"BR250",description:"2P-120/240V-50A CB",unit_price:16.53,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667636305_BR250"},
  {upc:"78667636310",mfr:"EATON",sku:"BR260",description:"2P-120/240V-60A CB",unit_price:23.44,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667636310_BR260"},
  {upc:"78667636315",mfr:"EATON",sku:"BR270",description:"2P-120/240V-70A CB",unit_price:71.43,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667636315_BR270"},
  {upc:"78667636317",mfr:"EATON",sku:"BR280",description:"2P-120/240V-80A CB",unit_price:61.13,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667636317_BR280"},
  {upc:"78667636320",mfr:"EATON",sku:"BR290",description:"2P-120/240V-90A CB",unit_price:74.29,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667636320_BR290"},
  {upc:"78667600135",mfr:"EATON",sku:"BR612L125RP",description:"1PH 125A LD-CTR",unit_price:360.37,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667600135_BR612L125RP"},
  {upc:"78667600147",mfr:"EATON",sku:"BR816L125RP",description:"1PH 125A LD-CTR",unit_price:170.04,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667600147_BR816L125RP"},
  {upc:"78667600722",mfr:"EATON",sku:"BRD220240",description:"4P 20/40A CB",unit_price:105.71,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667600722_BRD220240"},
  {upc:"78667646160",mfr:"EATON",sku:"BRFP",description:"FILLER PLATE",unit_price:2.66,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78667646160_BRFP"},
  {upc:"78668905920",mfr:"EATON",sku:"BRP16L125R",description:"125A LOADCENTER",unit_price:176.73,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78668905920_BRP16L125R"},
  {upc:"78668511606",mfr:"EATON",sku:"C25BNB230T",description:"2P CNCTR",unit_price:41.6,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78668511606_C25BNB230T"},
  {upc:"78211310237",mfr:"EATON",sku:"CH2100",description:"2P 100A PLUG-ON CB",unit_price:121.43,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78211310237_CH2100"},
  {upc:"78211310187",mfr:"EATON",sku:"CH260",description:"2P 60A PLUG-ON CB",unit_price:60.71,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78211310187_CH260"},
  {upc:"78211310189",mfr:"EATON",sku:"CH270",description:"2P 70A PLUG-ON CB",unit_price:119.47,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78211310189_CH270"},
  {upc:"78211310191",mfr:"EATON",sku:"CH290",description:"2P 90A PLUG-ON CB",unit_price:140.39,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78211310191_CH290"},
  {upc:"78668536188",mfr:"EATON",sku:"CHF220",description:"2P 20A CB",unit_price:30.64,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78668536188_CHF220"},
  {upc:"78668536189",mfr:"EATON",sku:"CHF225",description:"2P 25A CB",unit_price:30.64,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78668536189_CHF225"},
  {upc:"78668536190",mfr:"EATON",sku:"CHF230",description:"2P 30A CB",unit_price:19.43,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78668536190_CHF230"},
  {upc:"78668553215",mfr:"EATON",sku:"CHF235",description:"2P 35A CB",unit_price:32.74,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78668553215_CHF235"},
  {upc:"78668553216",mfr:"EATON",sku:"CHF240",description:"2P 40A CB",unit_price:19.43,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78668553216_CHF240"},
  {upc:"78668553217",mfr:"EATON",sku:"CHF250",description:"2P 50A CB",unit_price:19.43,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78668553217_CHF250"},
  {upc:"78211606111",mfr:"EATON",sku:"CSR2100",description:"2P 100A CB",unit_price:178.57,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78211606111_CSR2100"},
  {upc:"78211401973",mfr:"EATON",sku:"CSR2125N",description:"125A MAIN BREAKER KIT",unit_price:185.0,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78211401973_CSR2125N"},
  {upc:"78211309844",mfr:"EATON",sku:"CSR2150N",description:"2P 150A MAIN CB KT",unit_price:408.99,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78211309844_CSR2150N"},
  {upc:"78211309845",mfr:"EATON",sku:"CSR2175N",description:"2P 175A MAIN CB KT",unit_price:408.99,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78211309845_CSR2175N"},
  {upc:"78211309846",mfr:"EATON",sku:"CSR2200N",description:"2P 200A MAIN CB KT",unit_price:239.77,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78211309846_CSR2200N"},
  {upc:"78211312023",mfr:"EATON",sku:"DG221URB",description:"30 240V 3R NF SFT SW",unit_price:106.56,unit:"each",per:"E",category:"DISCONNECT",source:"Master BOS List 2026",id:"78211312023_DG221URB"},
  {upc:"78211314422",mfr:"EATON",sku:"DG222NRB",description:"60A 240V 3R SFTY SW",unit_price:188.57,unit:"each",per:"E",category:"DISCONNECT",source:"Master BOS List 2026",id:"78211314422_DG222NRB"},
  {upc:"78211314423",mfr:"EATON",sku:"DG222URB",description:"60A 240V 3R NF SFT SW",unit_price:168.57,unit:"each",per:"E",category:"DISCONNECT",source:"Master BOS List 2026",id:"78211314423_DG222URB"},
  {upc:"78211314425",mfr:"EATON",sku:"DG223NRB",description:"100A 240V 3R SFTY SW",unit_price:231.43,unit:"each",per:"E",category:"DISCONNECT",source:"Master BOS List 2026",id:"78211314425_DG223NRB"},
  {upc:"78211473115",mfr:"EATON",sku:"DG223URB",description:"100A 240V 3R NF SFT SW",unit_price:270.91,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78211473115_DG223URB"},
  {upc:"78211321350",mfr:"EATON",sku:"DG224NRK",description:"200A 240V 3R SFTY SW",unit_price:430.73,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78211321350_DG224NRK"},
  {upc:"78668523481",mfr:"EATON",sku:"DG224URK",description:"2P 200A NF 3R SFTY SW",unit_price:698.57,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78668523481_DG224URK"},
  {upc:"78211310991",mfr:"EATON",sku:"DS075H1",description:"SFTY SW HUB",unit_price:24.04,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78211310991_DS075H1"},
  {upc:"78211310993",mfr:"EATON",sku:"DS125H1",description:"SFTY SW HUB",unit_price:23.19,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78211310993_DS125H1"},
  {upc:"78211309910",mfr:"EATON",sku:"GBK21",description:"LD-CTR GND BAR KT",unit_price:32.7,unit:"each",per:"E",category:"GROUNDING",source:"Master BOS List 2026",id:"78211309910_GBK21"},
  {upc:"78211309906",mfr:"EATON",sku:"GBK5",description:"LD-CTR GND BAR KT",unit_price:14.29,unit:"each",per:"E",category:"GROUNDING",source:"Master BOS List 2026",id:"78211309906_GBK5"},
  {upc:"78211692590",mfr:"EATON",sku:"XBACUT10",description:"TERM BLOK END CVR",unit_price:1.01,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78211692590_XBACUT10"},
  {upc:"78211689429",mfr:"EATON",sku:"XBAES35C",description:"TERM BLOK END STOP",unit_price:2.61,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78211689429_XBAES35C"},
  {upc:"78211689428",mfr:"EATON",sku:"XBUT4",description:"SCR CON GND BLOK",unit_price:2.39,unit:"each",per:"E",category:"EATON",source:"Master BOS List 2026",id:"78211689428_XBUT4"},
  {upc:"98010033440",mfr:"WIRE",sku:"BARESD6SOL315R",description:"#6 BARE SOLID CU WIRE RL#___",unit_price:832.5,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010033440_BARESD6SOL315R"},
  {upc:"98010016310",mfr:"WIRE",sku:"NMB10/2WG250CL",description:"NM-B-10/2-CU-WG-250CL",unit_price:978.57,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010016310_NMB10/2WG250CL"},
  {upc:"98010023400",mfr:"WIRE",sku:"THHN1/0STRBLK",description:"THHN-1/0-BLK-19STR-CU-500R",unit_price:3357.14,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023400_THHN1/0STRBLK"},
  {upc:"98010022153",mfr:"WIRE",sku:"THHN1/0STRRED",description:"THHN-1/0-RED-19STR-CU-500R",unit_price:3357.14,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010022153_THHN1/0STRRED"},
  {upc:"98010022150",mfr:"WIRE",sku:"THHN1/0STRWHT",description:"THHN-1/0-WHT-19STR-CU-500R",unit_price:3357.14,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010022150_THHN1/0STRWHT"},
  {upc:"98010023000",mfr:"WIRE",sku:"THHN10STRBLK500R",description:"#10 THHN STR BLACK x 500'REEL H10",unit_price:349.06,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023000_THHN10STRBLK500R"},
  {upc:"98010012296",mfr:"WIRE",sku:"THHN10STRGRN",description:"THHN-10-GRN-19STR-CU-2@500CN",unit_price:349.06,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010012296_THHN10STRGRN"},
  {upc:"98010023020",mfr:"WIRE",sku:"THHN10STRRED500R",description:"#10 THHN STR RED x 500' REEL H09",unit_price:349.06,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023020_THHN10STRRED500R"},
  {upc:"98010023010",mfr:"WIRE",sku:"THHN10STRWHT500R",description:"#10 THHN STR WHITE x 500'REEL H10",unit_price:349.06,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023010_THHN10STRWHT500R"},
  {upc:"98010023405",mfr:"WIRE",sku:"THHN2/0STRBLK",description:"THHN-2/0-BLK-19STR-CU-500R",unit_price:4571.43,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023405_THHN2/0STRBLK"},
  {upc:"98010023408",mfr:"WIRE",sku:"THHN2/0STRGRN",description:"THHN-2/0-GRN-19STR-CU-500R",unit_price:4571.43,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023408_THHN2/0STRGRN"},
  {upc:"98010022180",mfr:"WIRE",sku:"THHN2/0STRRED",description:"THHN-2/0-RED-19STR-CU-500R",unit_price:4571.43,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010022180_THHN2/0STRRED"},
  {upc:"98010022175",mfr:"WIRE",sku:"THHN2/0STRWHT",description:"THHN-2/0-WHT-19STR-CU-500R",unit_price:4571.43,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010022175_THHN2/0STRWHT"},
  {upc:"98010012224",mfr:"WIRE",sku:"THHN2STRBLK",description:"THHN-2-BLK-7STR-CU-500R",unit_price:2392.86,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010012224_THHN2STRBLK"},
  {upc:"98010023340",mfr:"WIRE",sku:"THHN2STRGRN",description:"THHN-2-GRN-19STR-CU-500R",unit_price:2392.86,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023340_THHN2STRGRN"},
  {upc:"98010023320",mfr:"WIRE",sku:"THHN2STRRED",description:"THHN-2-RED-19STR-CU-500R",unit_price:2392.86,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023320_THHN2STRRED"},
  {upc:"98010023310",mfr:"WIRE",sku:"THHN2STRWHT",description:"THHN-2-WHT-19STR-CU-500R",unit_price:2392.86,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023310_THHN2STRWHT"},
  {upc:"98010023410",mfr:"WIRE",sku:"THHN3/0STRBLK",description:"THHN-3/0-BLK-19STR-CU-500R",unit_price:5857.14,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023410_THHN3/0STRBLK"},
  {upc:"98010022213",mfr:"WIRE",sku:"THHN3/0STRGRN",description:"THHN-3/0-GRN-19STR-CU-500R",unit_price:5857.14,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010022213_THHN3/0STRGRN"},
  {upc:"98010022203",mfr:"WIRE",sku:"THHN3/0STRRED",description:"THHN-3/0-RED-19STR-CU-500R",unit_price:5857.14,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010022203_THHN3/0STRRED"},
  {upc:"98010022200",mfr:"WIRE",sku:"THHN3/0STRWHT",description:"THHN-3/0-WHT-19STR-CU-500R",unit_price:5857.14,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010022200_THHN3/0STRWHT"},
  {upc:"98010023250",mfr:"WIRE",sku:"THHN3STRBLK500RL",description:"WIRE 3 AWG BLACK THHN STRANDED500",unit_price:2142.86,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023250_THHN3STRBLK500RL"},
  {upc:"98010023290",mfr:"WIRE",sku:"THHN3STRGRN",description:"THHN-3-GRN-19STR-CU-500R",unit_price:2142.86,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023290_THHN3STRGRN"},
  {upc:"98010023270",mfr:"WIRE",sku:"THHN3STRRED",description:"THHN-3-RED-19STR-CU-500R",unit_price:2142.86,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023270_THHN3STRRED"},
  {upc:"98010023260",mfr:"WIRE",sku:"THHN3STRWHT",description:"THHN-3-WHT-19STR-CU-500R",unit_price:2142.86,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023260_THHN3STRWHT"},
  {upc:"98010023415",mfr:"WIRE",sku:"THHN4/0STRBLK",description:"THHN-4/0-BLK-19STR-CU-500R",unit_price:9050.73,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023415_THHN4/0STRBLK"},
  {upc:"98010022230",mfr:"WIRE",sku:"THHN4/0STRRED",description:"THHN-4/0-RED-19STR-CU-500R",unit_price:9050.73,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010022230_THHN4/0STRRED"},
  {upc:"98010022225",mfr:"WIRE",sku:"THHN4/0STRWHT",description:"THHN-4/0-WHT-19STR-CU-500R",unit_price:9050.73,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010022225_THHN4/0STRWHT"},
  {upc:"98010023200",mfr:"WIRE",sku:"THHN4STRBLK500R",description:"THHN-4-BLK-19STR-CU-500R",unit_price:1700.0,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023200_THHN4STRBLK500R"},
  {upc:"98010023240",mfr:"WIRE",sku:"THHN4STRGRN",description:"THHN-4-GRN-19STR-CU-500R",unit_price:1700.0,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023240_THHN4STRGRN"},
  {upc:"98010023220",mfr:"WIRE",sku:"THHN4STRRED",description:"THHN-4-RED-19STR-CU-500R",unit_price:1700.0,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023220_THHN4STRRED"},
  {upc:"98010023210",mfr:"WIRE",sku:"THHN4STRWHT",description:"THHN-4-WHT-19STR-CU-500R",unit_price:1700.0,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023210_THHN4STRWHT"},
  {upc:"98010023153",mfr:"WIRE",sku:"THHN6STRBLK500R",description:"#6 THHN STR BLACK x 500' RL# H05",unit_price:1108.57,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023153_THHN6STRBLK500R"},
  {upc:"98010023192",mfr:"WIRE",sku:"THHN6STRGRN",description:"#6 THHN STR GREEN x 500' REEL",unit_price:996.84,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023192_THHN6STRGRN"},
  {upc:"98010023173",mfr:"WIRE",sku:"THHN6STRRED",description:"#6 THHN STR RED X 500' REEL",unit_price:996.84,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023173_THHN6STRRED"},
  {upc:"98010023162",mfr:"WIRE",sku:"THHN6STRWHT",description:"# 6 THHN WHITE",unit_price:996.84,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023162_THHN6STRWHT"},
  {upc:"98010023100",mfr:"WIRE",sku:"THHN8STRBLK",description:"THHN-8-BLK-19STR-CU-500S/R",unit_price:647.91,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023100_THHN8STRBLK"},
  {upc:"98010023140",mfr:"WIRE",sku:"THHN8STRGRN",description:"THHN-8-GRN-19STR-CU-500S/R",unit_price:647.91,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023140_THHN8STRGRN"},
  {upc:"98010023120",mfr:"WIRE",sku:"THHN8STRRED",description:"THHN-8-RED-19STR-CU-500S/R",unit_price:647.91,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023120_THHN8STRRED"},
  {upc:"98010023110",mfr:"WIRE",sku:"THHN8STRWHT",description:"THHN-8-WHT-19STR-CU-500S/R",unit_price:647.91,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"98010023110_THHN8STRWHT"},
  {upc:"98006006977",mfr:"PVC",sku:"CEMENTCLRQT",description:"1QT-QUICK-SET-CLEAR-PVC-CEMENT",unit_price:155566.86,unit:"per 1000",per:"M",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006977_CEMENTCLRQT"},
  {upc:"98006006002",mfr:"PVC",sku:"COND-3/4",description:"3/4-PVC-SCHED-40-10FT",unit_price:66.67,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98006006002_COND-3/4"},
  {upc:"98006006003",mfr:"PVC",sku:"COND1",description:"1-IN-PVC-SCHED-40-10FT",unit_price:685.14,unit:"per 1000",per:"M",category:"CONDUIT",source:"Master BOS List 2026",id:"98006006003_COND1"},
  {upc:"98006006005",mfr:"PVC",sku:"COND1-1/2",description:"1-1/2-PVC-SCHED-40-10FT",unit_price:162.47,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98006006005_COND1-1/2"},
  {upc:"98006006004",mfr:"PVC",sku:"COND1-1/4",description:"1-1/4-PVC-SCHED-40-10FT",unit_price:101.26,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98006006004_COND1-1/4"},
  {upc:"98006006006",mfr:"PVC",sku:"COND2",description:"2-IN-PVC-SCHED-40-10FT",unit_price:170.84,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98006006006_COND2"},
  {upc:"98006006303",mfr:"PVC",sku:"CONDS801",description:"1-IN-PVC-SCHED-80-10FT",unit_price:300.0,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98006006303_CONDS801"},
  {upc:"98006006304",mfr:"PVC",sku:"CONDS801-1/4",description:"1-1/4-PVC-SCHED-80-10FT",unit_price:429.79,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98006006304_CONDS801-1/4"},
  {upc:"98006006102",mfr:"PVC",sku:"CPL-3/4",description:"3/4-PVC-COND-CPLG",unit_price:22.47,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006102_CPL-3/4"},
  {upc:"98006006103",mfr:"PVC",sku:"CPL1",description:"1-IN-PVC-COND-CPLG",unit_price:34.4,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006103_CPL1"},
  {upc:"98006006105",mfr:"PVC",sku:"CPL1-1/2",description:"1-1/2-PVC-COND-CPLG",unit_price:65.71,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006105_CPL1-1/2"},
  {upc:"98006006104",mfr:"PVC",sku:"CPL1-1/4",description:"1-1/4-PVC-COND-CPLG",unit_price:50.06,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006104_CPL1-1/4"},
  {upc:"98006006106",mfr:"PVC",sku:"CPL2",description:"2-IN-PVC-COND-CPLG",unit_price:82.97,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006106_CPL2"},
  {upc:"98006006042",mfr:"PVC",sku:"EL-3/4",description:"3/4-90D-SCH-40-COND-ELL",unit_price:118.61,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98006006042_EL-3/4"},
  {upc:"98006006062",mfr:"PVC",sku:"EL-3/445",description:"3/4-45D-SCH-40-COND-ELL",unit_price:97.14,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006062_EL-3/445"},
  {upc:"98006006043",mfr:"PVC",sku:"EL1",description:"1-IN-90D-SCH-40-COND-ELL",unit_price:194.7,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006043_EL1"},
  {upc:"98006006045",mfr:"PVC",sku:"EL1-1/2",description:"1-1/2-90D-SCH-40-COND-ELL",unit_price:347.4,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98006006045_EL1-1/2"},
  {upc:"98006006065",mfr:"PVC",sku:"EL1-1/245",description:"1-1/2-45D-SCH-40-COND-ELL",unit_price:352.86,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006065_EL1-1/245"},
  {upc:"98006006044",mfr:"PVC",sku:"EL1-1/4",description:"1-1/4-90D-SCH-40-COND-ELL",unit_price:260.9,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98006006044_EL1-1/4"},
  {upc:"98006006064",mfr:"PVC",sku:"EL1-1/445",description:"1-1/4-45D-SCH-40-COND-ELL",unit_price:288.57,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98006006064_EL1-1/445"},
  {upc:"98006006063",mfr:"PVC",sku:"EL145",description:"1-IN-45D-SCH-40-COND-ELL",unit_price:212.86,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98006006063_EL145"},
  {upc:"98006006046",mfr:"PVC",sku:"EL2",description:"2-IN-90D-SCH-40-COND-ELL",unit_price:473.83,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98006006046_EL2"},
  {upc:"98006006066",mfr:"PVC",sku:"EL245",description:"2-IN-45D-SCH-40-COND-ELL",unit_price:551.57,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98006006066_EL245"},
  {upc:"98006006272",mfr:"PVC",sku:"EXP-3/4",description:"3/4-PVC-EXPAN-CPLG-2-IN-MAX",unit_price:242.86,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006272_EXP-3/4"},
  {upc:"98006006273",mfr:"PVC",sku:"EXP1",description:"1-IN-PVC-EXPAN-CPLG-2-IN-MAX",unit_price:2571.43,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006273_EXP1"},
  {upc:"98006006275",mfr:"PVC",sku:"EXP1-1/2",description:"1-1/2-PVC-EXPAN-CPLG-2-IN-MAX",unit_price:2828.57,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006275_EXP1-1/2"},
  {upc:"98006006274",mfr:"PVC",sku:"EXP1-1/4",description:"1-1/4-PVC-EXPAN-CPLG-2-IN-MAX",unit_price:2614.29,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006274_EXP1-1/4"},
  {upc:"98006006276",mfr:"PVC",sku:"EXP2",description:"2-IN-PVC-EXPAN-CPLG-2-IN-MAX",unit_price:2962.0,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006276_EXP2"},
  {upc:"98006006243",mfr:"PVC",sku:"FA1",description:"1-IN-PVC-FEMALE-ADPT",unit_price:64.29,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006243_FA1"},
  {upc:"98006006245",mfr:"PVC",sku:"FA1-1/2",description:"1-1/2-PVC-FEMALE-ADPT",unit_price:95.7,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006245_FA1-1/2"},
  {upc:"98006006244",mfr:"PVC",sku:"FA1-1/4",description:"1-1/4-PVC-FEMALE-ADPT",unit_price:76.89,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006244_FA1-1/4"},
  {upc:"98006006246",mfr:"PVC",sku:"FA2",description:"2-IN-PVC-FEMALE-ADPT",unit_price:111.51,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006246_FA2"},
  {upc:"98006006683",mfr:"PVC",sku:"JB444",description:"4X4X4-PVC-JCT-BOX-W/CVR",unit_price:7877.08,unit:"per 100",per:"C",category:"J-BOX",source:"Master BOS List 2026",id:"98006006683_JB444"},
  {upc:"98006006690",mfr:"PVC",sku:"JB884",description:"8X8X4-PVC-JCT-BOX-W/CVR",unit_price:4662.31,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006690_JB884"},
  {upc:"ZZ312300015",mfr:"PVC",sku:"JBX664",description:"PVC JUNCTION BOX 6X6X4",unit_price:2670.81,unit:"per 100",per:"C",category:"J-BOX",source:"Master BOS List 2026",id:"ZZ312300015_JBX664"},
  {upc:"98006006542",mfr:"PVC",sku:"LB-3/4",description:"3/4-PVC-TYPE-LB",unit_price:1017.14,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006542_LB-3/4"},
  {upc:"98006006543",mfr:"PVC",sku:"LB1",description:"1-IN-PVC-TYPE-LB",unit_price:495.26,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006543_LB1"},
  {upc:"98006006545",mfr:"PVC",sku:"LB1-1/2",description:"1-1/2-PVC-TYPE-LB",unit_price:900.83,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006545_LB1-1/2"},
  {upc:"98006006544",mfr:"PVC",sku:"LB1-1/4",description:"1-1/4-PVC-TYPE-LB",unit_price:1164.29,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006544_LB1-1/4"},
  {upc:"98006006546",mfr:"PVC",sku:"LB2",description:"2-IN-PVC-TYPE-LB",unit_price:1660.47,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006546_LB2"},
  {upc:"98006006562",mfr:"PVC",sku:"LL-3/4",description:"3/4-PVC-TYPE-LL",unit_price:5.29,unit:"each",per:"E",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006562_LL-3/4"},
  {upc:"98006006563",mfr:"PVC",sku:"LL1",description:"1-IN-PVC-TYPE-LL",unit_price:557.09,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006563_LL1"},
  {upc:"98006006564",mfr:"PVC",sku:"LL1-1/4",description:"1-1/4-PVC-TYPE-LL",unit_price:807.76,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006564_LL1-1/4"},
  {upc:"98006006582",mfr:"PVC",sku:"LR-3/4",description:"3/4-PVC-TYPE-LR",unit_price:5.29,unit:"each",per:"E",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006582_LR-3/4"},
  {upc:"98006006583",mfr:"PVC",sku:"LR1",description:"1-IN-PVC-TYPE-LR",unit_price:552.86,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006583_LR1"},
  {upc:"98006006585",mfr:"PVC",sku:"LR1-1/2",description:"1-1/2-PVC-TYPE-LR",unit_price:924.29,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006585_LR1-1/2"},
  {upc:"98006006584",mfr:"PVC",sku:"LR1-1/4",description:"1-1/4-PVC-TYPE-LR",unit_price:1165.36,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006584_LR1-1/4"},
  {upc:"98006006586",mfr:"PVC",sku:"LR2",description:"2-IN-PVC-TYPE-LR",unit_price:1643.77,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006586_LR2"},
  {upc:"98006006636",mfr:"PVC",sku:"OSN2",description:"2-IN-PVC-METER-OFFSET-NIPPLE",unit_price:18.66,unit:"each",per:"E",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006636_OSN2"},
  {upc:"98006006202",mfr:"PVC",sku:"TA-3/4",description:"3/4-PVC-TERM-ADPT",unit_price:42.61,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006202_TA-3/4"},
  {upc:"98006006203",mfr:"PVC",sku:"TA1",description:"1\" PVC MALE TERM ADAPTER",unit_price:53.3,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006203_TA1"},
  {upc:"98006006205",mfr:"PVC",sku:"TA1-1/2",description:"1-1/2-PVC-TERM-ADPT",unit_price:83.61,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006205_TA1-1/2"},
  {upc:"98006006204",mfr:"PVC",sku:"TA1-1/4",description:"1-1/4-PVC-TERM-ADPT",unit_price:69.03,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006204_TA1-1/4"},
  {upc:"98006006206",mfr:"PVC",sku:"TA2",description:"2-IN-PVC-TERM-ADPT",unit_price:119.33,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98006006206_TA2"},
  {upc:"98001002002",mfr:"COND",sku:"EMT-3/4",description:"CSTEMT34 3/4\" EMT CONDUIT",unit_price:105.6,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98001002002_EMT-3/4"},
  {upc:"98001002003",mfr:"COND",sku:"EMT1",description:"CSTEMT1 1\" EMT CONDUIT",unit_price:174.46,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98001002003_EMT1"},
  {upc:"98001002015",mfr:"COND",sku:"EMT1-1/2RED",description:"1- 1/2 EMT",unit_price:496.1,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98001002015_EMT1-1/2RED"},
  {upc:"98001002004",mfr:"COND",sku:"EMT1-1/4",description:"1-1/4\" EMT CONDUIT STEEL",unit_price:378.57,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98001002004_EMT1-1/4"},
  {upc:"98001002006",mfr:"COND",sku:"EMT2",description:"2\" EMT",unit_price:364.16,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98001002006_EMT2"},
  {upc:"98001002007",mfr:"COND",sku:"EMT2-1/2",description:"2-1/2-EMT",unit_price:718.73,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98001002007_EMT2-1/2"},
  {upc:"98001000102",mfr:"COND",sku:"GALV-3/4",description:"3/4-GALV-STEEL",unit_price:339.96,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98001000102_GALV-3/4"},
  {upc:"98001000103",mfr:"COND",sku:"GALV1",description:"1-IN-GALV-STEEL",unit_price:541.2,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98001000103_GALV1"},
  {upc:"98001000105",mfr:"COND",sku:"GALV1-1/2",description:"1-1/2-GALV-STEEL",unit_price:896.69,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98001000105_GALV1-1/2"},
  {upc:"98001000104",mfr:"COND",sku:"GALV1-1/4",description:"1-1/4-GALV-STEEL",unit_price:796.29,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98001000104_GALV1-1/4"},
  {upc:"98001000106",mfr:"COND",sku:"GALV2",description:"2-IN-GALV-STEEL",unit_price:895.1,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98001000106_GALV2"},
  {upc:"ZZ312400003",mfr:"COND",sku:"SP2X12",description:"2.375 RD 12 60 ZFC",unit_price:86.67,unit:"each",per:"E",category:"FITTINGS",source:"Master BOS List 2026",id:"ZZ312400003_SP2X12"},
  {upc:"ZZ312400004",mfr:"COND",sku:"SP3X12",description:"2.375 RD 12 120 ZFC",unit_price:172.48,unit:"each",per:"E",category:"FITTINGS",source:"Master BOS List 2026",id:"ZZ312400004_SP3X12"},
  {upc:"98002000132",mfr:"FIT",sku:"CPLGAL-3/4",description:"3/4-GALV-CPLG",unit_price:285.67,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000132_CPLGAL-3/4"},
  {upc:"98002000133",mfr:"FIT",sku:"CPLGAL1",description:"1-IN-GALV-CPLG",unit_price:411.3,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000133_CPLGAL1"},
  {upc:"98002000136",mfr:"FIT",sku:"CPLGAL2",description:"2-IN-GALV-CPLG",unit_price:907.21,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000136_CPLGAL2"},
  {upc:"98002002022",mfr:"FIT",sku:"ELEMT-3/4",description:"3/4-90DEG-EMT",unit_price:487.89,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98002002022_ELEMT-3/4"},
  {upc:"98002002023",mfr:"FIT",sku:"ELEMT1",description:"1-IN-90DEG-EMT",unit_price:729.49,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98002002023_ELEMT1"},
  {upc:"98002002024",mfr:"FIT",sku:"ELEMT1-1/4",description:"1-1/4-90DEG-EMT",unit_price:992.4,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98002002024_ELEMT1-1/4"},
  {upc:"98002002026",mfr:"FIT",sku:"ELEMT2",description:"2-IN-90DEG-EMT",unit_price:2152.07,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98002002026_ELEMT2"},
  {upc:"98002002036",mfr:"FIT",sku:"ELEMT245",description:"2-IN-45DEG-EMT",unit_price:1994.17,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98002002036_ELEMT245"},
  {upc:"98002000162",mfr:"FIT",sku:"ELGAL-3/4",description:"3/4-90DEG-GALV-ELBOW",unit_price:840.77,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98002000162_ELGAL-3/4"},
  {upc:"98002000182",mfr:"FIT",sku:"ELGAL-3/445",description:"3/4-45DEG-GALV-ELBOW",unit_price:864.79,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98002000182_ELGAL-3/445"},
  {upc:"98002000163",mfr:"FIT",sku:"ELGAL1",description:"1-IN-90DEG-GALV-ELBOW",unit_price:1313.73,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98002000163_ELGAL1"},
  {upc:"98002000165",mfr:"FIT",sku:"ELGAL1-1/2",description:"1-1/2-90DEG-GALV-ELBOW",unit_price:2234.7,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98002000165_ELGAL1-1/2"},
  {upc:"98002000185",mfr:"FIT",sku:"ELGAL1-1/245",description:"1-1/2-45DEG-GALV-ELBOW",unit_price:2298.54,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98002000185_ELGAL1-1/245"},
  {upc:"98002000164",mfr:"FIT",sku:"ELGAL1-1/4",description:"1-1/4-90DEG-GALV-ELBOW",unit_price:1836.29,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98002000164_ELGAL1-1/4"},
  {upc:"98002000184",mfr:"FIT",sku:"ELGAL1-1/445",description:"1-1/4-45DEG-GALV-ELBOW",unit_price:1888.76,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98002000184_ELGAL1-1/445"},
  {upc:"98002000183",mfr:"FIT",sku:"ELGAL145",description:"1-IN-45DEG-GALV-ELBOW",unit_price:1351.27,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98002000183_ELGAL145"},
  {upc:"98002000166",mfr:"FIT",sku:"ELGAL2",description:"2-IN-90DEG-GALV-ELBOW",unit_price:3409.93,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98002000166_ELGAL2"},
  {upc:"98002000186",mfr:"FIT",sku:"ELGAL245",description:"2-IN-45DEG-GALV-ELBOW",unit_price:3409.93,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98002000186_ELGAL245"},
  {upc:"98002000441",mfr:"FIT",sku:"NIPGAL-3/4X12",description:"3/4X12-GALV-NIP",unit_price:921.13,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000441_NIPGAL-3/4X12"},
  {upc:"98002000432",mfr:"FIT",sku:"NIPGAL-3/4X2",description:"3/4X2-GALV-NIP",unit_price:225.54,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000432_NIPGAL-3/4X2"},
  {upc:"98002000436",mfr:"FIT",sku:"NIPGAL-3/4X4",description:"3/4X4-GALV-NIP",unit_price:308.66,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000436_NIPGAL-3/4X4"},
  {upc:"98002000438",mfr:"FIT",sku:"NIPGAL-3/4X6",description:"3/4X6-GALV-NIP",unit_price:434.34,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000438_NIPGAL-3/4X6"},
  {upc:"98002000431",mfr:"FIT",sku:"NIPGAL-3/4XCL",description:"3/4XCLOSEX1-3/8-GALV-NIP",unit_price:190.91,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000431_NIPGAL-3/4XCL"},
  {upc:"98002000524",mfr:"FIT",sku:"NIPGAL1-1/2X3",description:"1-1/2X3-GALV-NIP",unit_price:874.59,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000524_NIPGAL1-1/2X3"},
  {upc:"98002000521",mfr:"FIT",sku:"NIPGAL1-1/2XCL",description:"1-1/2XCLOSEX1-3/4-GALV-NIP",unit_price:681.74,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000521_NIPGAL1-1/2XCL"},
  {upc:"98002000492",mfr:"FIT",sku:"NIPGAL1-1/4X2",description:"1-1/4X2-GALV-NIP",unit_price:607.41,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000492_NIPGAL1-1/4X2"},
  {upc:"98002000494",mfr:"FIT",sku:"NIPGAL1-1/4X3",description:"1-1/4X3-GALV-NIP",unit_price:600.64,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000494_NIPGAL1-1/4X3"},
  {upc:"98002000498",mfr:"FIT",sku:"NIPGAL1-1/4X6",description:"1-1/4X6-GALV-NIP",unit_price:721.59,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000498_NIPGAL1-1/4X6"},
  {upc:"98002000491",mfr:"FIT",sku:"NIPGAL1-1/4XCL",description:"1-1/4XCLOSEX1-5/8-GALV-NIP",unit_price:362.13,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000491_NIPGAL1-1/4XCL"},
  {upc:"98002000471",mfr:"FIT",sku:"NIPGAL1X12",description:"1X12-GALV-NIP",unit_price:1266.8,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000471_NIPGAL1X12"},
  {upc:"98002000462",mfr:"FIT",sku:"NIPGAL1X2",description:"1X2-GALV-NIP",unit_price:300.11,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000462_NIPGAL1X2"},
  {upc:"98002000466",mfr:"FIT",sku:"NIPGAL1X4",description:"1X4-GALV-NIP",unit_price:442.17,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000466_NIPGAL1X4"},
  {upc:"98002000468",mfr:"FIT",sku:"NIPGAL1X6",description:"1X6-GALV-NIP",unit_price:559.44,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000468_NIPGAL1X6"},
  {upc:"98002000461",mfr:"FIT",sku:"NIPGAL1XCL",description:"1XCLOSEX1-1/2-GALV-NIP",unit_price:286.21,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000461_NIPGAL1XCL"},
  {upc:"98002000553",mfr:"FIT",sku:"NIPGAL2X3",description:"2X3-GALV-NIP",unit_price:713.13,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000553_NIPGAL2X3"},
  {upc:"98002000557",mfr:"FIT",sku:"NIPGAL2X6",description:"2X6-GALV-NIP",unit_price:1220.84,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000557_NIPGAL2X6"},
  {upc:"98002000551",mfr:"FIT",sku:"NIPGAL2XCL",description:"2XCLOSEX2-GALV-NIP",unit_price:536.09,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98002000551_NIPGAL2XCL"},
  {upc:"04089269744",mfr:"SIEM",sku:"EC3GB21",description:"21POS GROUND BAR KIT",unit_price:11.76,unit:"each",per:"E",category:"GROUNDING",source:"Master BOS List 2026",id:"04089269744_EC3GB21"},
  {upc:"78364345087",mfr:"SIEM",sku:"ECGB10",description:"GRND BAR KIT",unit_price:18.07,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364345087_ECGB10"},
  {upc:"78364345512",mfr:"SIEM",sku:"ECHS200",description:"2IN LD CTR RAIN-HUB",unit_price:22.19,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364345512_ECHS200"},
  {upc:"78364314931",mfr:"SIEM",sku:"GF323NR",description:"3P 240V 100A SFTY SW FUSED",unit_price:231.79,unit:"each",per:"E",category:"DISCONNECT",source:"Master BOS List 2026",id:"78364314931_GF323NR"},
  {upc:"78364338798",mfr:"SIEM",sku:"MBK100A",description:"100A RISER MAIN CB KT",unit_price:78.11,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364338798_MBK100A"},
  {upc:"80476670277",mfr:"SIEM",sku:"PN2040B1200C",description:"20 SPACE 200A LD-CTR",unit_price:225.23,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"80476670277_PN2040B1200C"},
  {upc:"80476670288",mfr:"SIEM",sku:"PN3048B1200C",description:"200A LD-CTR",unit_price:241.19,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"80476670288_PN3048B1200C"},
  {upc:"80476670293",mfr:"SIEM",sku:"PN4040B1200C",description:"200A LD-CTR",unit_price:238.56,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"80476670293_PN4040B1200C"},
  {upc:"80476670573",mfr:"SIEM",sku:"PNW3048B1125C",description:"125A LD-CTR",unit_price:533.0,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"80476670573_PNW3048B1125C"},
  {upc:"78364314818",mfr:"SIEM",sku:"Q115",description:"SP 15A 120/240V CB",unit_price:10.46,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364314818_Q115"},
  {upc:"78364314819",mfr:"SIEM",sku:"Q120",description:"SP 20A 120/240V CB",unit_price:10.46,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364314819_Q120"},
  {upc:"78364314821",mfr:"SIEM",sku:"Q130",description:"SP 30A 120/240V CB",unit_price:10.94,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364314821_Q130"},
  {upc:"78364314825",mfr:"SIEM",sku:"Q1520",description:"SP 15/20A 120/240V CB",unit_price:32.3,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364314825_Q1520"},
  {upc:"78364314826",mfr:"SIEM",sku:"Q2020",description:"SP 20/20A 120/240V CB",unit_price:26.53,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364314826_Q2020"},
  {upc:"78364314868",mfr:"SIEM",sku:"Q2100",description:"2P 100A 120/240V CB",unit_price:84.44,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364314868_Q2100"},
  {upc:"78364314869",mfr:"SIEM",sku:"Q2125",description:"2P 125A 120/240V CB",unit_price:74.29,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364314869_Q2125"},
  {upc:"78364314836",mfr:"SIEM",sku:"Q220",description:"2P 20A 120/240V CB",unit_price:22.84,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364314836_Q220"},
  {upc:"78364314837",mfr:"SIEM",sku:"Q225",description:"2P 25A 120/240V CB",unit_price:20.71,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364314837_Q225"},
  {upc:"78364314838",mfr:"SIEM",sku:"Q230",description:"2P 30A 120/240V CB",unit_price:21.27,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364314838_Q230"},
  {upc:"78364316765",mfr:"SIEM",sku:"Q235",description:"35A PLUG ON BKR",unit_price:24.57,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364316765_Q235"},
  {upc:"78364314863",mfr:"SIEM",sku:"Q240",description:"2P 40A 120/240V CB",unit_price:20.24,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364314863_Q240"},
  {upc:"78364314864",mfr:"SIEM",sku:"Q250",description:"2P 50A 120/240V CB",unit_price:22.84,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364314864_Q250"},
  {upc:"78364314865",mfr:"SIEM",sku:"Q260",description:"2P 60A 120/240V CB",unit_price:22.84,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364314865_Q260"},
  {upc:"78364314866",mfr:"SIEM",sku:"Q270",description:"2P 70A 120/240V CB",unit_price:49.64,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364314866_Q270"},
  {upc:"78364315674",mfr:"SIEM",sku:"Q280",description:"2P 80A 120/240V CB",unit_price:71.73,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364315674_Q280"},
  {upc:"78364314867",mfr:"SIEM",sku:"Q290",description:"2P 90A 120/240V CB",unit_price:79.86,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"78364314867_Q290"},
  {upc:"88762121651",mfr:"SIEM",sku:"QF115A",description:"1P 15A CB",unit_price:87.14,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"88762121651_QF115A"},
  {upc:"80476670322",mfr:"SIEM",sku:"SN1224L1125",description:"125A LD-CTR",unit_price:103.2,unit:"each",per:"E",category:"SIEMENS",source:"Master BOS List 2026",id:"80476670322_SN1224L1125"},
  {upc:"ZZ014200090",mfr:"HEYCO",sku:"13151B-P",description:"100 PCS ZIP TIE BAG",unit_price:80.29,unit:"per 1000",per:"M",category:"MISC",source:"Master BOS List 2026",id:"ZZ014200090_13151B-P"},
  {upc:"ZZ014200022",mfr:"HEYCO",sku:"M3219",description:"CORDGRIP FOR ENPHASE",unit_price:111.1,unit:"per 100",per:"C",category:"CONNECTOR",source:"Master BOS List 2026",id:"ZZ014200022_M3219"},
  {upc:"ZZ014200029",mfr:"HEYCO",sku:"M3234GBS-SM",description:"3/4 NPT 3 HOLE PV WIRE CORDGRIP",unit_price:203.91,unit:"per 100",per:"C",category:"CONNECTOR",source:"Master BOS List 2026",id:"ZZ014200029_M3234GBS-SM"},
  {upc:"ZZ014200072",mfr:"HEYCO",sku:"M3234GDA-SM",description:"LT CORDGRIPS FOR ENPHASE QCABLE",unit_price:200.59,unit:"per 100",per:"C",category:"MISC",source:"Master BOS List 2026",id:"ZZ014200072_M3234GDA-SM"},
  {upc:"ZZ014200030",mfr:"HEYCO",sku:"M3317GBZ-SM",description:"1 1/2 NPT 11 HOLE PV WIRE CORDGRI",unit_price:1379.01,unit:"per 100",per:"C",category:"MISC",source:"Master BOS List 2026",id:"ZZ014200030_M3317GBZ-SM"},
  {upc:"ZZ014200035",mfr:"HEYCO",sku:"M4524GBW-SM",description:"1 1/4 NPT 9 HOLE PV WIRE CORDGRIP",unit_price:6.4,unit:"each",per:"E",category:"MISC",source:"Master BOS List 2026",id:"ZZ014200035_M4524GBW-SM"},
  {upc:"ZZ014200037",mfr:"HEYCO",sku:"M8437GBT-SM",description:"1 NPT 5 HOLE PV WIRE CORDGRIP",unit_price:319.04,unit:"per 100",per:"C",category:"MISC",source:"Master BOS List 2026",id:"ZZ014200037_M8437GBT-SM"},
  {upc:"ZZ014200044",mfr:"HEYCO",sku:"S6405",description:"S6405 SUNRUNNER CLIP (100/BAG)",unit_price:25.71,unit:"per 100",per:"C",category:"CONNECTOR",source:"Master BOS List 2026",id:"ZZ014200044_S6405"},
  {upc:"ZZ014200051",mfr:"HEYCO",sku:"S6438",description:"WIRE MESH CLIP;BLACK",unit_price:0.93,unit:"each",per:"E",category:"FITTINGS",source:"Master BOS List 2026",id:"ZZ014200051_S6438"},
  {upc:"ZZ014200076",mfr:"HEYCO",sku:"S6464",description:"SUNSCREEN 4\" PVC COAT 100' 90/PLT",unit_price:42.17,unit:"each",per:"E",category:"FITTINGS",source:"Master BOS List 2026",id:"ZZ014200076_S6464"},
  {upc:"ZZ014200058",mfr:"HEYCO",sku:"S6468",description:"SUN SCREEN WIRE MESH;8\" WIDE;100'",unit_price:93.73,unit:"each",per:"E",category:"MISC",source:"Master BOS List 2026",id:"ZZ014200058_S6468"},
  {upc:"ZZ014200084",mfr:"HEYCO",sku:"S6505",description:"SUNRUNNER 4-2U CLIP 100/BAG",unit_price:64.7,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"ZZ014200084_S6505"},
  {upc:"00000000000",mfr:"MISC",sku:"3022276",description:"PHOENIX TERMINAL END CLAMP",unit_price:1.53,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"00000000000_3022276"},
  {upc:"00000000000",mfr:"MISC",sku:"3030336",description:"PHOENIX TERMINAL PLUG-IN BRIDGE",unit_price:0.8,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"00000000000_3030336"},
  {upc:"00000000000",mfr:"MISC",sku:"3031762",description:"PHOENIX TERMINAL END COVER",unit_price:1.0,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"00000000000_3031762"},
  {upc:"00000000000",mfr:"MISC",sku:"3044102",description:"PHOENIX TERMINAL BLOCK SCREW CON",unit_price:0.91,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"00000000000_3044102"},
  {upc:"00000000000",mfr:"MISC",sku:"3044241",description:"PHOENIX TERMINAL GROUND BLOCK",unit_price:12.43,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"00000000000_3044241"},
  {upc:"00000000000",mfr:"MISC",sku:"FLO-COAT 2.37 X 240",description:"2.375 OD X 12GA X 240",unit_price:122.59,unit:"each",per:"E",category:"MISC",source:"Master BOS List 2026",id:"00000000000_FLO-COAT 2.37 X 240"},
  {upc:"00000000000",mfr:"MISC",sku:"FLO-COAT 2.37 X 244",description:"2.375 OD X 12GA X 244",unit_price:122.59,unit:"each",per:"E",category:"MISC",source:"Master BOS List 2026",id:"00000000000_FLO-COAT 2.37 X 244"},
  {upc:"ZZ299200092",mfr:"MISC",sku:"JKM425N-54HL4-B",description:"425W 108 HC 1000V TOPCON BLK/BLK",unit_price:130.4,unit:"each",per:"E",category:"MISC",source:"Master BOS List 2026",id:"ZZ299200092_JKM425N-54HL4-B"},
  {upc:"00000000000",mfr:"MISC",sku:"PEAK ENERGY SAVER 100",description:"PEAK ENERGY SAVER 100- NIVO",unit_price:128.57,unit:"each",per:"E",category:"MISC",source:"Master BOS List 2026",id:"00000000000_PEAK ENERGY SAVER 100"},
  {upc:"00000000000",mfr:"MISC",sku:"SBS50 + 5 SMOKE ALARMS",description:"X-SENSE SMART SMOKE DETECTORS WIT",unit_price:106.66,unit:"each",per:"E",category:"ALARM",source:"Master BOS List 2026",id:"00000000000_SBS50 + 5 SMOKE ALARMS"},
  {upc:"00000000000",mfr:"MISC",sku:"SOLAR PV PLACARD",description:"SOLAR PV PLACARD",unit_price:25.0,unit:"each",per:"E",category:"STICKER",source:"Master BOS List 2026",id:"00000000000_SOLAR PV PLACARD"},
  {upc:"00000000000",mfr:"MISC",sku:"WATER",description:"CASE OF WATER",unit_price:19.29,unit:"each",per:"E",category:"MISC",source:"Master BOS List 2026",id:"00000000000_WATER"},
  {upc:"00000000000",mfr:"MISC",sku:"XH02-M",description:"HEAT DETECTOR ALARM FOR GARAGE",unit_price:33.32,unit:"each",per:"E",category:"ALARM",source:"Master BOS List 2026",id:"00000000000_XH02-M"},
  {upc:"ZZ301300054",mfr:"PVLBL",sku:"02-314",description:"PV POWER SOURCE REF (COND)",unit_price:1.59,unit:"each",per:"E",category:"STICKER",source:"Master BOS List 2026",id:"ZZ301300054_02-314"},
  {upc:"ZZ301300013",mfr:"PVLBL",sku:"03-110",description:"PV SYSTEM DC DISCONNECT",unit_price:1.5,unit:"each",per:"E",category:"DISCONNECT",source:"Master BOS List 2026",id:"ZZ301300013_03-110"},
  {upc:"ZZ301300068",mfr:"PVLBL",sku:"03-211",description:"WARN: DUAL PWR SUPPLY (RED)",unit_price:1.14,unit:"each",per:"E",category:"STICKER",source:"Master BOS List 2026",id:"ZZ301300068_03-211"},
  {upc:"ZZ301300131",mfr:"PVLBL",sku:"03-301",description:"PV-DC DISCONNECT RED",unit_price:0.96,unit:"each",per:"E",category:"STICKER",source:"Master BOS List 2026",id:"ZZ301300131_03-301"},
  {upc:"ZZ301300168",mfr:"PVLBL",sku:"03-306",description:"AC DISCO RATING STICKER",unit_price:1.35,unit:"each",per:"E",category:"STICKER",source:"Master BOS List 2026",id:"ZZ301300168_03-306"},
  {upc:"ZZ301300322",mfr:"PVLBL",sku:"03-366",description:"BATTERY DC DISCONNECT 4\"X1\" LABEL",unit_price:0.96,unit:"each",per:"E",category:"STICKER",source:"Master BOS List 2026",id:"ZZ301300322_03-366"},
  {upc:"ZZ301300323",mfr:"PVLBL",sku:"03-512",description:"NOMINAL ESS AC/DC VOLT 4\"X2\" WRT-",unit_price:1.14,unit:"each",per:"E",category:"STICKER",source:"Master BOS List 2026",id:"ZZ301300323_03-512"},
  {upc:"ZZ301300309",mfr:"PVLBL",sku:"05-230",description:"WARNING: 3 POWER SOURCES 4\"X2\" LB",unit_price:1.14,unit:"each",per:"E",category:"STICKER",source:"Master BOS List 2026",id:"ZZ301300309_05-230"},
  {upc:"ZZ301300011",mfr:"PVLBL",sku:"05-517",description:"55 STICKER VALUE PACK - NEC 2017",unit_price:23.4,unit:"each",per:"E",category:"STICKER",source:"Master BOS List 2026",id:"ZZ301300011_05-517"},
  {upc:"ZZ301300175",mfr:"PVLBL",sku:"05-520",description:"2020 NEC - ANSI LABEL",unit_price:25.07,unit:"each",per:"E",category:"STICKER",source:"Master BOS List 2026",id:"ZZ301300175_05-520"},
  {upc:"ZZ301300281",mfr:"PVLBL",sku:"3-42",description:"4\" X 2\" RED/WHT EMERGENCY 1 OF 2",unit_price:3.34,unit:"each",per:"E",category:"STICKER",source:"Master BOS List 2026",id:"ZZ301300281_3-42"},
  {upc:"ZZ301300325",mfr:"PVLBL",sku:"4-41ESSDISCON",description:"CUSTOM 4X1 PLACARD - ESS DISCONNECT",unit_price:10.0,unit:"each",per:"E",category:"STICKER",source:"Master BOS List 2026",id:"ZZ301300325_4-41ESSDISCON"},
  {upc:"ZZ990300003",mfr:"STRUT",sku:"SHALGLV10",description:"10' 14G 13/16\" SLOTTED GALV STRUT",unit_price:219.16,unit:"per 100",per:"C",category:"MISC",source:"Master BOS List 2026",id:"ZZ990300003_SHALGLV10"},
  {upc:"ZZ990300009",mfr:"STRUT",sku:"STRAP1-1/4",description:"1-1/4\" EMT STRUT STRAP",unit_price:105.71,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"ZZ990300009_STRAP1-1/4"},
  {upc:"ZZ990300010",mfr:"STRUT",sku:"STRAP2",description:"2\" EMT STRUT STRAP",unit_price:311.81,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"ZZ990300010_STRAP2"},
  {upc:"ZZ990300011",mfr:"STRUT",sku:"STRAP2R",description:"2\" GRC STRUT STRAP",unit_price:144.76,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"ZZ990300011_STRAP2R"},
  {upc:"78457211042",mfr:"MIL",sku:"A7517",description:"2-IN UNIT HUB",unit_price:11.47,unit:"each",per:"E",category:"FITTINGS",source:"Master BOS List 2026",id:"78457211042_A7517"},
  {upc:"78457211046",mfr:"MIL",sku:"A7551",description:"ALUM CLOSING PLATE",unit_price:9.89,unit:"each",per:"E",category:"MILBANK",source:"Master BOS List 2026",id:"78457211046_A7551"},
  {upc:"78457227436",mfr:"MIL",sku:"K4977INT",description:"HEX INTL TAP CONN",unit_price:40.79,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"78457227436_K4977INT"},
  {upc:"78457228821",mfr:"MIL",sku:"U4801XL5T9",description:"200A BYPASS METER SOCKET",unit_price:166.89,unit:"each",per:"E",category:"MILBANK",source:"Master BOS List 2026",id:"78457228821_U4801XL5T9"},
  {upc:"78457272184",mfr:"MIL",sku:"U6193YLQGAMS",description:"125A MSKT",unit_price:295.71,unit:"each",per:"E",category:"MILBANK",source:"Master BOS List 2026",id:"78457272184_U6193YLQGAMS"},
  {upc:"78457213771",mfr:"MIL",sku:"U6281XL1005T9AMS",description:"5 TERM RNGLS SML CLS PLT 2-SGNL P",unit_price:636.69,unit:"each",per:"E",category:"MISC",source:"Master BOS List 2026",id:"78457213771_U6281XL1005T9AMS"},
  {upc:"78457213767",mfr:"MIL",sku:"U6281XL2005T9AMS",description:"5 TERM RNGLS SML CLS PLT LVR BYPS",unit_price:636.69,unit:"each",per:"E",category:"MILBANK",source:"Master BOS List 2026",id:"78457213767_U6281XL2005T9AMS"},
  {upc:"78457214234",mfr:"MIL",sku:"U8949RLTGKKCECHA",description:"200A 1MTRSKT",unit_price:98.67,unit:"each",per:"E",category:"MILBANK",source:"Master BOS List 2026",id:"78457214234_U8949RLTGKKCECHA"},
  {upc:"78457213758",mfr:"MIL",sku:"U9551RXLQG5T9AMS",description:"200A MSKT",unit_price:451.97,unit:"each",per:"E",category:"MILBANK",source:"Master BOS List 2026",id:"78457213758_U9551RXLQG5T9AMS"},
  {upc:"78457272146",mfr:"MIL",sku:"U9551RXLQGAMS",description:"MSKT",unit_price:438.17,unit:"each",per:"E",category:"MILBANK",source:"Master BOS List 2026",id:"78457272146_U9551RXLQGAMS"},
  {upc:"ZZ303900075",mfr:"WIRPV",sku:"1BC-0601SD",description:"BARE CU 7 STRAND WIRE",unit_price:1014.29,unit:"per 1000",per:"M",category:"GROUNDING",source:"Master BOS List 2026",id:"ZZ303900075_1BC-0601SD"},
  {upc:"ZZ303900009",mfr:"WIRPV",sku:"2KVPV10STRBLK500",description:"PV #10 BLK 2000V CU 500",unit_price:650.0,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"ZZ303900009_2KVPV10STRBLK500"},
  {upc:"ZZ303900012",mfr:"WIRPV",sku:"2KVPV10STRRED500",description:"PV #10 RED 2000V CU 500'",unit_price:614.29,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"ZZ303900012_2KVPV10STRRED500"},
  {upc:"ZZ303900060",mfr:"WIRPV",sku:"2KVPV8STRBLK2500",description:"PV #8 BLK 2000V 2500'",unit_price:1117.5,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"ZZ303900060_2KVPV8STRBLK2500"},
  {upc:"ZZ303900015",mfr:"WIRPV",sku:"PV10STRBLK500",description:"10-19 CU PV SINGLE LAYER XLP BLK",unit_price:564.29,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"ZZ303900015_PV10STRBLK500"},
  {upc:"ZZ303900018",mfr:"WIRPV",sku:"PV10STRRED500",description:"10-19 CU PV SINGLE LAYER XLP RED",unit_price:592.5,unit:"per 1000",per:"M",category:"WIRE",source:"Master BOS List 2026",id:"ZZ303900018_PV10STRRED500"},
  {upc:"98005002977",mfr:"FLEX",sku:"LT-3/4NM",description:"3/4-FLEX-NM-LIQ-TITE",unit_price:66.94,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98005002977_LT-3/4NM"},
  {upc:"98005002978",mfr:"FLEX",sku:"LT1NM",description:"1-IN-FLEX-NM-LIQ-TITE",unit_price:98.06,unit:"per 100",per:"C",category:"CONDUIT",source:"Master BOS List 2026",id:"98005002978_LT1NM"},
  {upc:"98005002203",mfr:"FLEX",sku:"RWA-3/4",description:"3/4-FLEX-ALUM-REDUC-WALL",unit_price:92.7,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98005002203_RWA-3/4"},
  {upc:"98005002204",mfr:"FLEX",sku:"RWA1",description:"1-IN-FLEX-ALUM-REDUC-WALL",unit_price:195.54,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98005002204_RWA1"},
  {upc:"98005002206",mfr:"FLEX",sku:"RWA1-1/2",description:"1-1/2-FLEX-ALUM-REDUC-WALL",unit_price:730.54,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98005002206_RWA1-1/2"},
  {upc:"98005002207",mfr:"FLEX",sku:"RWA2",description:"2-IN-FLEX-ALUM-REDUC-WALL",unit_price:932.06,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"98005002207_RWA2"},
  {upc:"78541103557",mfr:"REMKE",sku:"RDC75A",description:"3/4 DRAIN FITTING",unit_price:10.73,unit:"each",per:"E",category:"FITTINGS",source:"Master BOS List 2026",id:"78541103557_RDC75A"},
  {upc:"78456412224",mfr:"CHE",sku:"CPR24",description:"1-1/4 NO-THRD CPLG",unit_price:4504.86,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78456412224_CPR24"},
  {upc:"78227437860",mfr:"CHE",sku:"EYS21",description:"3/4 FEM COND SEAL",unit_price:60.97,unit:"each",per:"E",category:"FITTINGS",source:"Master BOS List 2026",id:"78227437860_EYS21"},
  {upc:"78456474370",mfr:"CHE",sku:"LB25CGN",description:"3/4 AL LB COND BDY",unit_price:816.3,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78456474370_LB25CGN"},
  {upc:"78456474374",mfr:"CHE",sku:"LB65CGN",description:"2-IN AL LB CONDBDY",unit_price:5859.1,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78456474374_LB65CGN"},
  {upc:"78456474410",mfr:"CHE",sku:"LL25CGN",description:"3/4 AL LL CONDBODY",unit_price:816.3,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78456474410_LL25CGN"},
  {upc:"78456474434",mfr:"CHE",sku:"LR65CGN",description:"2IN AL LR CONDBODY",unit_price:49.66,unit:"each",per:"E",category:"FITTINGS",source:"Master BOS List 2026",id:"78456474434_LR65CGN"},
  {upc:"66236450131",mfr:"AMFI",sku:"CG125K",description:"CORD CONNECTOR KIT",unit_price:1738.1,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"66236450131_CG125K"},
  {upc:"66236450133",mfr:"AMFI",sku:"CG200K",description:"CORD CONNECTOR KIT",unit_price:42.84,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"66236450133_CG200K"},
  {upc:"66236450141",mfr:"AMFI",sku:"CG75K",description:"3/4 CONN KIT",unit_price:576.67,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"66236450141_CG75K"},
  {upc:"78636401726",mfr:"UNIST",sku:"P1100T10PG",description:"DEEP SLOT CHANNEL STRUT",unit_price:371.43,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78636401726_P1100T10PG"},
  {upc:"78636411120",mfr:"UNIST",sku:"P1112EG",description:"3/4 STRUT STRAP",unit_price:92.86,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78636411120_P1112EG"},
  {upc:"78636411130",mfr:"UNIST",sku:"P1113EG",description:"1IN STRUT STRAP",unit_price:90.0,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78636411130_P1113EG"},
  {upc:"78636403887",mfr:"UNIST",sku:"P4000T10HG",description:"SHALLOW STRUT 1-5/8X13/16 CHNL",unit_price:219.16,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78636403887_P4000T10HG"},
  {upc:"78636489508",mfr:"UNIST",sku:"UB2PA",description:"2IN U BOLT",unit_price:342.86,unit:"per 100",per:"C",category:"FITTINGS",source:"Master BOS List 2026",id:"78636489508_UB2PA"},
  {upc:"40551437154",mfr:"WAGO",sku:"221-613",description:"3-WIRE CONNECTORS",unit_price:85.71,unit:"per 100",per:"C",category:"CONNECTOR",source:"Master BOS List 2026",id:"40551437154_221-613"},
  {upc:"66238108264",mfr:"NSI",sku:"IPCS4002",description:"INSUL PIERCING CONN",unit_price:33.84,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"66238108264_IPCS4002"},
  {upc:"66238191401",mfr:"NSI",sku:"IPL3503",description:"INSD M-CBL CONN BLOCK",unit_price:57765.04,unit:"per 1000",per:"M",category:"CONNECTOR",source:"Master BOS List 2026",id:"66238191401_IPL3503"},
  {upc:"66238195302",mfr:"NSI",sku:"IT1/0B",description:"1/0-14AWG INSD-TAP CONN",unit_price:23.97,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"66238195302_IT1/0B"},
  {upc:"66238195007",mfr:"NSI",sku:"IT250",description:"250-6AWG INSD-TAP CONN",unit_price:42.99,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"66238195007_IT250"},
  {upc:"66238195008",mfr:"NSI",sku:"IT350",description:"350-6AWG INSD-TAP CONN",unit_price:54.79,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"66238195008_IT350"},
  {upc:"66238195153",mfr:"NSI",sku:"ITG3/0",description:"3/0-6AWG INSD TAP CONN",unit_price:43.43,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"66238195153_ITG3/0"},
  {upc:"66238103428",mfr:"NSI",sku:"L638",description:"#6 CU CMPRSN LUG",unit_price:400.34,unit:"per 100",per:"C",category:"CONNECTOR",source:"Master BOS List 2026",id:"66238103428_L638"},
  {upc:"66238136736",mfr:"NSI",sku:"WW716",description:"60FT ELECTRICAL TAPE",unit_price:0.9,unit:"each",per:"E",category:"MISC",source:"Master BOS List 2026",id:"66238136736_WW716"},
  {upc:"66238136741",mfr:"NSI",sku:"WW716GN",description:"60FT ELECTRICAL TAPE",unit_price:1.06,unit:"each",per:"E",category:"MISC",source:"Master BOS List 2026",id:"66238136741_WW716GN"},
  {upc:"66238136738",mfr:"NSI",sku:"WW716RD",description:"60FT ELECTRICAL TAPE",unit_price:1.06,unit:"each",per:"E",category:"MISC",source:"Master BOS List 2026",id:"66238136738_WW716RD"},
  {upc:"66238136745",mfr:"NSI",sku:"WW716WT",description:"60FT ELECTRICAL TAPE",unit_price:1.06,unit:"each",per:"E",category:"MISC",source:"Master BOS List 2026",id:"66238136745_WW716WT"},
  {upc:"78366952373",mfr:"ILSCO",sku:"IPC2504/0",description:"250MCM-1 CONN",unit_price:60.0,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"78366952373_IPC2504/0"},
  {upc:"78366953269",mfr:"ILSCO",sku:"IPC4/06",description:"4/0-6 CONN",unit_price:21.71,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"78366953269_IPC4/06"},
  {upc:"78366907736",mfr:"ILSCO",sku:"PBTD21/0",description:"2PRT INS TAP CONN",unit_price:34.7,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"78366907736_PBTD21/0"},
  {upc:"78366907788",mfr:"ILSCO",sku:"PBTD2250",description:"2PRT INS TAP CONN",unit_price:47.29,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"78366907788_PBTD2250"},
  {upc:"78366907950",mfr:"ILSCO",sku:"PBTS23/0",description:"2PRT INS TAP CONN",unit_price:37.41,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"78366907950_PBTS23/0"},
  {upc:"ZZ040700010",mfr:"MULTI",sku:"32.0016P0001-UR",description:"MC4 FEMALE CONNECTOR 10PC/BAG",unit_price:1.45,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"ZZ040700010_32.0016P0001-UR"},
  {upc:"ZZ040700012",mfr:"MULTI",sku:"32.0017P0001-UR",description:"MC4 MALE CONNECTOR 10PC/BAG",unit_price:1.45,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"ZZ040700012_32.0017P0001-UR"},
  {upc:"ZZ040700008",mfr:"MULTI",sku:"32.0018",description:"MC4 BRANCH CNCTR 2F/1M",unit_price:8.55,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"ZZ040700008_32.0018"},
  {upc:"ZZ040700009",mfr:"MULTI",sku:"32.0019",description:"MC4 BRANCH CNCTR 2M/1F",unit_price:6.63,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"ZZ040700009_32.0019"},
  {upc:"ZZ040700058",mfr:"MULTI",sku:"44.0002",description:"2' 12AWG 2KV MC4 EXTENSION CABLE",unit_price:7.86,unit:"each",per:"E",category:"CONNECTOR",source:"Master BOS List 2026",id:"ZZ040700058_44.0002"},
  {upc:"07945815071",mfr:"LF",sku:"FLNR020",description:"250V RK5 TD FUSE",unit_price:14.46,unit:"each",per:"E",category:"FUSE",source:"Master BOS List 2026",id:"07945815071_FLNR020"},
  {upc:"07945815073",mfr:"LF",sku:"FLNR030",description:"250V RK5 TD FUSE",unit_price:11.71,unit:"each",per:"E",category:"FUSE",source:"Master BOS List 2026",id:"07945815073_FLNR030"},
  {upc:"07945802381",mfr:"LF",sku:"FLNR040ID",description:"250V INDCATOR FUSE",unit_price:11.71,unit:"each",per:"E",category:"FUSE",source:"Master BOS List 2026",id:"07945802381_FLNR040ID"},
  {upc:"07945802383",mfr:"LF",sku:"FLNR050ID",description:"250V INDCATOR FUSE",unit_price:11.71,unit:"each",per:"E",category:"FUSE",source:"Master BOS List 2026",id:"07945802383_FLNR050ID"},
  {upc:"07945802384",mfr:"LF",sku:"FLNR060ID",description:"250V INDCATOR FUSE",unit_price:11.71,unit:"each",per:"E",category:"FUSE",source:"Master BOS List 2026",id:"07945802384_FLNR060ID"},
  {upc:"07945802385",mfr:"LF",sku:"FLNR070ID",description:"250V INDCATOR FUSE",unit_price:11.71,unit:"each",per:"E",category:"FUSE",source:"Master BOS List 2026",id:"07945802385_FLNR070ID"},
  {upc:"07945802386",mfr:"LF",sku:"FLNR080ID",description:"250V INDCATOR FUSE",unit_price:43.67,unit:"each",per:"E",category:"FUSE",source:"Master BOS List 2026",id:"07945802386_FLNR080ID"},
  {upc:"07945802387",mfr:"LF",sku:"FLNR090ID",description:"250V INDCATOR FUSE",unit_price:25.61,unit:"each",per:"E",category:"FUSE",source:"Master BOS List 2026",id:"07945802387_FLNR090ID"},
  {upc:"07945802388",mfr:"LF",sku:"FLNR100ID",description:"250V IND FUSE",unit_price:24.74,unit:"each",per:"E",category:"FUSE",source:"Master BOS List 2026",id:"07945802388_FLNR100ID"},
  {upc:"07945802390",mfr:"LF",sku:"FLNR125ID",description:"250V IND FUSE",unit_price:65.09,unit:"each",per:"E",category:"FUSE",source:"Master BOS List 2026",id:"07945802390_FLNR125ID"},
  {upc:"07945815086",mfr:"LF",sku:"FLNR150",description:"250V RK5 TD FUSE",unit_price:106.77,unit:"each",per:"E",category:"FUSE",source:"Master BOS List 2026",id:"07945815086_FLNR150"},
  {upc:"07945815087",mfr:"LF",sku:"FLNR175",description:"250V RK5 TD FUSE",unit_price:27.03,unit:"each",per:"E",category:"FUSE",source:"Master BOS List 2026",id:"07945815087_FLNR175"},
  {upc:"07945815088",mfr:"LF",sku:"FLNR200",description:"250V RK5 TD FUSE",unit_price:77.47,unit:"each",per:"E",category:"FUSE",source:"Master BOS List 2026",id:"07945815088_FLNR200"},
  {upc:"07945815096",mfr:"LF",sku:"FLNR500",description:"250V RK5 TD FUSE",unit_price:79.81,unit:"each",per:"E",category:"FUSE",source:"Master BOS List 2026",id:"07945815096_FLNR500"},
  {upc:"07945801070",mfr:"LF",sku:"LRU263R",description:"FUSE REDUCER",unit_price:33.16,unit:"each",per:"E",category:"FUSE",source:"Master BOS List 2026",id:"07945801070_LRU263R"},
  {upc:"50562010055",mfr:"IMO",sku:"BG10P34-11",description:"EMERG STOP STATION 40MM",unit_price:38.07,unit:"each",per:"E",category:"MISC",source:"Master BOS List 2026",id:"50562010055_BG10P34-11"},
  {upc:"50562018525",mfr:"IMO",sku:"PE69-3020",description:"ISOLATOR 3 POLE 20A ENCLOSED IP66",unit_price:34.7,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"50562018525_PE69-3020"},
  {upc:"50562063259",mfr:"IMO",sku:"SI32-PEL64R-4",description:"ENCL DC SWITCH IP66 180X98X107MM",unit_price:86.96,unit:"each",per:"E",category:"DISCONNECT",source:"Master BOS List 2026",id:"50562063259_SI32-PEL64R-4"},
  {upc:"83524302109",mfr:"ORBIT",sku:"12124RNK",description:"12X12X4 ODR N3R ENCL",unit_price:42.06,unit:"each",per:"E",category:"SQUARE D",source:"Master BOS List 2026",id:"83524302109_12124RNK"},
  {upc:"83524302103",mfr:"ORBIT",sku:"664RNK",description:"6X6X4ODR N3R SC ENCL",unit_price:19.59,unit:"each",per:"E",category:"J-BOX",source:"Master BOS List 2026",id:"83524302103_664RNK"},
  {upc:"83524302105",mfr:"ORBIT",sku:"884RNK",description:"8X8X4ODR N3R SC ENCL",unit_price:25.06,unit:"each",per:"E",category:"J-BOX",source:"Master BOS List 2026",id:"83524302105_884RNK"},
  {upc:"83524303251",mfr:"ORBIT",sku:"RN100C",description:"1XCLS COND NIPPLE",unit_price:2.04,unit:"each",per:"E",category:"FITTINGS",source:"Master BOS List 2026",id:"83524303251_RN100C"},
  {upc:"ZZ304500002",mfr:"EZSLR",sku:"JB-1.XL",description:"XL PV JUNCTION BOX",unit_price:41.23,unit:"each",per:"E",category:"J-BOX",source:"Master BOS List 2026",id:"ZZ304500002_JB-1.XL"},
  {upc:"ZZ304500006",mfr:"EZSLR",sku:"JB-3",description:"PV JUNCTION BOX - RAIL MOUNT",unit_price:36.57,unit:"each",per:"E",category:"J-BOX",source:"Master BOS List 2026",id:"ZZ304500006_JB-3"},
  {upc:"78285630609",mfr:"CADDY",sku:"615880",description:"5/8X8FT CU GROUND ROD",unit_price:2817.43,unit:"per 100",per:"C",category:"GROUNDING",source:"Master BOS List 2026",id:"78285630609_615880"},
];

// ??? BOS TAB COMPONENT ???????????????????????????????????????????????????????

const BOS_CATEGORIES = [
  "FITTINGS",
  "SQUARE D",
  "EATON",
  "SIEMENS",
  "CONDUIT",
  "WIRE",
  "CONNECTOR",
  "DISCONNECT",
  "FUSE",
  "GROUNDING",
  "J-BOX",
  "STICKER",
  "MILBANK",
  "ALARM",
  "MISC",
];

function BOSTab({ c, card, fmt, bosItems, setBosItems }) {
  const [parsing, setParsing]       = useState(false);
  const [parseError, setParseError] = useState("");
  const [fileName, setFileName]     = useState("");
  const [pending, setPending]       = useState(null);   // items awaiting review
  const [pendingSel, setPendingSel] = useState({});
  const [lastAdded, setLastAdded]   = useState(0);
  const [search, setSearch]         = useState("");
  const [filterCat, setFilterCat]   = useState("All");

  const parseBOSPDF = async (file) => {
    setParsing(true); setParseError(""); setPending(null);
    try {
      const base64Data = await new Promise((res, rej) => {
        const r = new FileReader();
        r.onload = () => res(r.result.split(",")[1]);
        r.onerror = () => rej(new Error("Read failed"));
        r.readAsDataURL(file);
      });
      const response = await fetch("https://api.anthropic.com/v1/messages", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({
          model: "claude-sonnet-4-20250514",
          max_tokens: 1000,
          messages: [{
            role: "user",
            content: [
              { type: "document", source: { type: "base64", media_type: "application/pdf", data: base64Data } },
              { type: "text", text: `You are parsing a solar BOS (Balance of System) materials quote or price list. Extract ONLY balance-of-system electrical and mounting components ? wire, cable, conduit, fittings, breakers, disconnects, combiner boxes, junction boxes, connectors, splices, grounding hardware, labels, strut, and similar field hardware. Do NOT include solar panels, inverters, microinverters, racking rails, or battery storage units.

Return ONLY a valid JSON array with no markdown, no preamble:
[{"sku":"string","description":"string","unit_price":number,"unit":"each/foot/box/roll","category":"Wire & Cable|Conduit & Fittings|Breakers & Disconnects|Combiner & Junction Boxes|Connectors & Splices|Grounding|Labels & Signage|Mounting & Strut|Other","source":"${file.name}"}]

If a category is unclear, use "Other". Include every BOS line item you find.` }
            ]
          }]
        })
      });
      const data = await response.json();
      const raw = data.content?.find(b => b.type === "text")?.text || "[]";
      const items = JSON.parse(raw.replace(/```json|```/g, "").trim());
      if (!items.length) { setParseError("No BOS items found in this PDF. Make sure it contains electrical/hardware components."); setParsing(false); return; }
      // Mark duplicates vs new
      const existingSkus = new Set(bosItems.map(b => b.sku?.toLowerCase().trim()));
      const tagged = items.map(item => ({
        ...item,
        isDuplicate: existingSkus.has(item.sku?.toLowerCase().trim()),
        id: `${Date.now()}_${Math.random().toString(36).slice(2,7)}`,
      }));
      const sel = {};
      tagged.forEach((t, i) => { sel[i] = !t.isDuplicate; });  // pre-select new, deselect dupes
      setPending(tagged);
      setPendingSel(sel);
    } catch(e) { setParseError("Parse failed: " + e.message); }
    setParsing(false);
  };

  const applyPending = () => {
    if (!pending) return;
    const toAdd = pending.filter((_, i) => pendingSel[i]);
    setBosItems(prev => [...prev, ...toAdd]);
    setLastAdded(toAdd.length);
    setPending(null);
    setPendingSel({});
  };

  const removeItem = (id) => setBosItems(prev => prev.filter(b => b.id !== id));

  const filtered = bosItems.filter(b => {
    const matchCat = filterCat === "All" || b.category === filterCat;
    const matchSearch = !search || b.description?.toLowerCase().includes(search.toLowerCase()) || b.sku?.toLowerCase().includes(search.toLowerCase());
    return matchCat && matchSearch;
  });

  const grouped = BOS_CATEGORIES.reduce((acc, cat) => {
    const items = filtered.filter(b => b.category === cat);
    if (items.length) acc[cat] = items;
    return acc;
  }, {});

  const totalItems = bosItems.length;
  const categories = [...new Set(bosItems.map(b => b.category))].filter(Boolean);

  return (
    <div style={{ paddingBottom: 40 }}>

      {/* ?? HEADER STATS ?????????????????????????????????????????????????? */}
      <div style={{ display:"flex", alignItems:"stretch", gap:12, marginBottom:20 }}>
        <div style={{ flex:1, background:c.surface, border:`1px solid ${c.border}`, borderRadius:10, padding:"14px 18px", display:"flex", flexDirection:"column", gap:4 }}>
          <div style={{ fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3 }}>Total BOS Items</div>
          <div style={{ fontSize:28, fontWeight:800, color:c.accent, fontFamily:c.mono }}>{totalItems}</div>
          <div style={{ fontSize:11, color:c.text3 }}>{categories.length} categories</div>
        </div>
        <div style={{ flex:1, background:c.surface, border:`1px solid ${c.border}`, borderRadius:10, padding:"14px 18px", display:"flex", flexDirection:"column", gap:4 }}>
          <div style={{ fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3 }}>Sources</div>
          <div style={{ fontSize:13, fontWeight:600, color:c.text, marginTop:2 }}>
            {totalItems === 0 ? <span style={{ color:c.text3 }}>No PDFs uploaded yet</span>
              : [...new Set(bosItems.map(b => b.source).filter(Boolean))].map(s => (
                <div key={s} style={{ fontSize:11, color:c.text2, marginBottom:2 }}>? {s}</div>
              ))
            }
          </div>
        </div>
        {lastAdded > 0 && (
          <div style={{ flex:1, background:c.successL, border:`1.5px solid rgba(22,101,52,.2)`, borderRadius:10, padding:"14px 18px", display:"flex", flexDirection:"column", gap:4 }}>
            <div style={{ fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.success }}>Last Import</div>
            <div style={{ fontSize:28, fontWeight:800, color:c.success, fontFamily:c.mono }}>+{lastAdded}</div>
            <div style={{ fontSize:11, color:c.success }}>items added</div>
          </div>
        )}
      </div>

      {/* ?? PDF UPLOADER ?????????????????????????????????????????????????? */}
      <div style={{ margin:"0 0 8px", paddingBottom:8, borderBottom:`2px solid ${c.border}`, display:"flex", alignItems:"center", gap:10 }}>
        <span style={{ fontSize:11, fontWeight:800, letterSpacing:".14em", textTransform:"uppercase", color:c.accent }}>Add BOS Items from PDF</span>
        <span style={{ fontSize:11, color:c.text3 }}>Upload any CED quote or price list - AI extracts BOS items only</span>
      </div>
      <div style={{ ...card, marginBottom:20 }}>
        <label style={{ display:"block", cursor:"pointer" }}>
          <div style={{ border:`2px dashed ${fileName?c.accent:c.border2}`, borderRadius:10, padding:"24px 20px", textAlign:"center", background:fileName?c.accentL:c.surface2, transition:".2s" }}>
            {fileName ? (
              <><div style={{ fontSize:22, marginBottom:5 }}>?</div><div style={{ fontSize:13, fontWeight:700, color:c.accent }}>{fileName}</div><div style={{ fontSize:11, color:c.text3, marginTop:2 }}>Click to upload another</div></>
            ) : (
              <><div style={{ fontSize:22, marginBottom:5 }}>?</div><div style={{ fontSize:13, fontWeight:600, color:c.text2 }}>Drop any CED quote PDF here or click to browse</div><div style={{ fontSize:11, color:c.text3, marginTop:3 }}>AI will extract BOS-only items ? panels, inverters, and racking are automatically excluded</div></>
            )}
          </div>
          <input type="file" accept=".pdf" style={{ display:"none" }} onChange={e => {
            const f = e.target.files?.[0];
            if (f) { setFileName(f.name); parseBOSPDF(f); }
          }} />
        </label>

        {parsing && (
          <div style={{ marginTop:14, padding:"13px 16px", background:c.accentL, border:`1.5px solid rgba(13,110,110,.2)`, borderRadius:8, display:"flex", alignItems:"center", gap:10 }}>
            <div style={{ width:15, height:15, border:`2px solid ${c.accent}`, borderTopColor:"transparent", borderRadius:"50%", animation:"spin 0.8s linear infinite", flexShrink:0 }} />
            <span style={{ fontSize:13, color:c.accent, fontWeight:600 }}>Extracting BOS items from PDF...</span>
          </div>
        )}
        {parseError && <div style={{ marginTop:12, padding:"10px 14px", background:c.dangerL, border:`1.5px solid rgba(185,28,28,.2)`, borderRadius:8, fontSize:12, color:c.danger }}>{parseError}</div>}

        {/* ?? PENDING REVIEW ???????????????????????????????????????????? */}
        {pending && !parsing && (
          <div style={{ marginTop:18 }}>
            <div style={{ display:"flex", alignItems:"center", justifyContent:"space-between", marginBottom:10 }}>
              <div style={{ fontSize:11, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3 }}>
                {pending.length} items found ? {pending.filter((_,i)=>pendingSel[i]).length} selected to add
              </div>
              <div style={{ display:"flex", gap:8 }}>
                <button onClick={()=>setPendingSel(Object.fromEntries(pending.map((_,i)=>[i,true])))} style={{ fontSize:11, color:c.accent, background:"none", border:`1px solid ${c.accent}`, borderRadius:6, padding:"3px 10px", cursor:"pointer" }}>Select All</button>
                <button onClick={()=>setPendingSel(Object.fromEntries(pending.map((_,i)=>[i,false])))} style={{ fontSize:11, color:c.text3, background:"none", border:`1px solid ${c.border}`, borderRadius:6, padding:"3px 10px", cursor:"pointer" }}>Deselect All</button>
              </div>
            </div>
            <table style={{ width:"100%", borderCollapse:"collapse", fontSize:12, marginBottom:14 }}>
              <thead><tr>
                {["Add","SKU","Description","Category","Unit Price","Unit","Status"].map(h => (
                  <th key={h} style={{ padding:"6px 10px", textAlign:h==="Unit Price"?"right":"left", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, borderBottom:`2px solid ${c.border}`, background:c.surface2 }}>{h}</th>
                ))}
              </tr></thead>
              <tbody>
                {pending.map((item, i) => (
                  <tr key={i} style={{ borderBottom:`1px solid ${c.surface3}`, background:pendingSel[i]?(item.isDuplicate?"rgba(180,83,9,.04)":"rgba(13,110,110,.03)"):"transparent", opacity:pendingSel[i]?1:0.5 }}>
                    <td style={{ padding:"7px 10px", textAlign:"center" }}>
                      <input type="checkbox" checked={!!pendingSel[i]} onChange={e=>setPendingSel(p=>({...p,[i]:e.target.checked}))} style={{ width:14, height:14, cursor:"pointer", accentColor:c.accent }} />
                    </td>
                    <td style={{ padding:"7px 10px", fontFamily:c.mono, fontSize:11, color:c.text3 }}>{item.sku||"--"}</td>
                    <td style={{ padding:"7px 10px", fontSize:12, color:c.text2, maxWidth:260 }}>{item.description}</td>
                    <td style={{ padding:"7px 10px" }}>
                      <select value={item.category||"Other"} onChange={e=>{const n=[...pending];n[i]={...n[i],category:e.target.value};setPending(n);}} style={{ fontSize:11, border:`1px solid ${c.border}`, borderRadius:5, padding:"2px 6px", background:c.surface2, color:c.text, outline:"none" }}>
                        {BOS_CATEGORIES.map(cat=><option key={cat}>{cat}</option>)}
                      </select>
                    </td>
                    <td style={{ padding:"7px 10px", textAlign:"right", fontFamily:c.mono, fontSize:12, fontWeight:600, color:c.text }}>${item.unit_price?.toFixed(2)||"--"}</td>
                    <td style={{ padding:"7px 10px", fontSize:11, color:c.text3 }}>{item.unit||"each"}</td>
                    <td style={{ padding:"7px 10px" }}>
                      {item.isDuplicate
                        ? <span style={{ fontSize:9, fontWeight:700, color:c.warn, background:c.warnL, padding:"2px 7px", borderRadius:8 }}>Duplicate</span>
                        : <span style={{ fontSize:9, fontWeight:700, color:c.success, background:c.successL, padding:"2px 7px", borderRadius:8 }}>New</span>}
                    </td>
                  </tr>
                ))}
              </tbody>
            </table>
            {pending.filter((_,i)=>pendingSel[i]).length > 0 && (
              <button onClick={applyPending} style={{ padding:"11px 24px", background:c.accent, color:"#fff", border:"none", borderRadius:9, fontSize:13, fontWeight:700, cursor:"pointer", fontFamily:"inherit", letterSpacing:".04em" }}>
                Add {pending.filter((_,i)=>pendingSel[i]).length} Items to BOS Catalog
              </button>
            )}
          </div>
        )}
      </div>

      {/* ?? CATALOG ??????????????????????????????????????????????????????? */}
      {totalItems > 0 && (
        <>
          <div style={{ margin:"0 0 8px", paddingBottom:8, borderBottom:`2px solid ${c.border}`, display:"flex", alignItems:"center", gap:10 }}>
            <span style={{ fontSize:11, fontWeight:800, letterSpacing:".14em", textTransform:"uppercase", color:c.accent }}>BOS Catalog</span>
            <span style={{ fontSize:10, color:c.text3, background:c.surface3, padding:"2px 8px", borderRadius:10 }}>{totalItems} items</span>
          </div>

          {/* Search + filter bar */}
          <div style={{ display:"flex", gap:10, marginBottom:14, alignItems:"center" }}>
            <input placeholder="Search SKU or description..." value={search} onChange={e=>setSearch(e.target.value)} style={{ flex:1, padding:"8px 12px", border:`1.5px solid ${c.border}`, borderRadius:8, fontSize:13, background:c.surface2, color:c.text, outline:"none", fontFamily:"inherit" }} />
            <select value={filterCat} onChange={e=>setFilterCat(e.target.value)} style={{ padding:"8px 12px", border:`1.5px solid ${c.border}`, borderRadius:8, fontSize:13, background:c.surface2, color:c.text, outline:"none", fontFamily:"inherit" }}>
              <option>All</option>
              {categories.map(cat=><option key={cat}>{cat}</option>)}
            </select>
          </div>

          {Object.entries(grouped).map(([cat, items]) => (
            <div key={cat} style={{ ...card, padding:0, overflow:"hidden", marginBottom:10 }}>
              <div style={{ padding:"9px 14px", background:c.surface2, borderBottom:`1px solid ${c.border}`, display:"flex", alignItems:"center", gap:8 }}>
                <span style={{ fontSize:12, fontWeight:700, color:c.text }}>{cat}</span>
                <span style={{ fontSize:10, color:c.text3, background:c.surface3, padding:"1px 7px", borderRadius:8 }}>{items.length} items</span>
              </div>
              <table style={{ width:"100%", borderCollapse:"collapse" }}>
                <thead><tr>
                  <th style={{ padding:"6px 12px", textAlign:"left", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, borderBottom:`1px solid ${c.border}`, background:c.surface2, width:"18%" }}>SKU</th>
                  <th style={{ padding:"6px 12px", textAlign:"left", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, borderBottom:`1px solid ${c.border}`, background:c.surface2 }}>Description</th>
                  <th style={{ padding:"6px 12px", textAlign:"right", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, borderBottom:`1px solid ${c.border}`, background:c.surface2, width:"12%" }}>Unit Price</th>
                  <th style={{ padding:"6px 12px", textAlign:"right", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, borderBottom:`1px solid ${c.border}`, background:c.surface2, width:"8%" }}>Unit</th>
                  <th style={{ padding:"6px 12px", textAlign:"left", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, borderBottom:`1px solid ${c.border}`, background:c.surface2, width:"14%" }}>Source</th>
                  <th style={{ padding:"6px 12px", width:36, borderBottom:`1px solid ${c.border}`, background:c.surface2 }}></th>
                </tr></thead>
                <tbody>
                  {items.map((item, i) => (
                    <tr key={item.id} style={{ borderBottom:`1px solid ${c.surface3}`, background:i%2===0?"transparent":c.surface2 }}>
                      <td style={{ padding:"7px 12px", fontFamily:c.mono, fontSize:11, color:c.text3 }}>{item.sku||"--"}</td>
                      <td style={{ padding:"7px 12px", fontSize:12, color:c.text2 }}>{item.description}</td>
                      <td style={{ padding:"7px 12px", textAlign:"right", fontFamily:c.mono, fontSize:12, fontWeight:600, color:c.text }}>${item.unit_price?.toFixed(2)||"--"}</td>
                      <td style={{ padding:"7px 12px", textAlign:"right", fontSize:11, color:c.text3 }}>{item.unit||"each"}</td>
                      <td style={{ padding:"7px 12px", fontSize:10, color:c.text3, fontStyle:"italic" }}>{item.source||"--"}</td>
                      <td style={{ padding:"7px 12px", textAlign:"center" }}>
                        <button onClick={()=>removeItem(item.id)} style={{ fontSize:11, color:c.danger, background:"none", border:"none", cursor:"pointer", padding:"2px 4px", borderRadius:4, lineHeight:1 }} title="Remove">?</button>
                      </td>
                    </tr>
                  ))}
                </tbody>
              </table>
            </div>
          ))}
        </>
      )}

      {totalItems === 0 && !pending && !parsing && (
        <div style={{ textAlign:"center", padding:"50px 20px", color:c.text3 }}>
          <div style={{ fontSize:36, marginBottom:12 }}>?</div>
          <div style={{ fontSize:14, fontWeight:600, color:c.text2, marginBottom:6 }}>No BOS items yet</div>
          <div style={{ fontSize:12, maxWidth:380, margin:"0 auto", lineHeight:1.7 }}>Upload a CED quote PDF above. The AI will extract wire, conduit, breakers, disconnects, connectors, grounding hardware, and all other BOS components ? panels, inverters, and racking are automatically filtered out.</div>
        </div>
      )}

      <style>{`@keyframes spin{to{transform:rotate(360deg)}}`}</style>
    </div>
  );
}

// ??? BOM TAB COMPONENT ???????????????????????????????????????????????????????

function BOMTab({ c, card, lbl, fmt, fmtPPW, priceOverrides, pdfParsing, pdfDiff, pdfSelected, setPdfSelected, pdfFileName, setPdfFileName, pdfError, pdfApplied, parsePDF, applyPriceChanges }) {

  const effPrice = (type, key, defaultVal) => priceOverrides?.[type]?.[key] ?? defaultVal;

  const SecHdr = ({ title, sub }) => (
    <div style={{ display:"flex", alignItems:"center", gap:10, margin:"22px 0 10px", paddingBottom:8, borderBottom:`2px solid ${c.border}` }}>
      <span style={{ fontSize:11, fontWeight:800, letterSpacing:".14em", textTransform:"uppercase", color:c.accent }}>{title}</span>
      {sub && <span style={{ fontSize:10, color:c.text3, background:c.surface3, padding:"2px 8px", borderRadius:10 }}>{sub}</span>}
    </div>
  );

  const TH = ({ children, right }) => (
    <th style={{ padding:"7px 12px", textAlign:right?"right":"left", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, borderBottom:`2px solid ${c.border}`, background:c.surface2, whiteSpace:"nowrap" }}>{children}</th>
  );

  const domBadge = dom => dom
    ? <span style={{ fontSize:9, fontWeight:700, color:c.success, background:c.successL, padding:"1px 6px", borderRadius:8, border:"1px solid rgba(22,101,52,.2)" }}>DOM</span>
    : <span style={{ fontSize:9, color:c.text3, background:c.surface3, padding:"1px 6px", borderRadius:8 }}>Non-Dom</span>;

  const lenderBadge = lenders => (
    <div style={{ display:"flex", gap:3, flexWrap:"wrap" }}>
      {lenders.map(l => <span key={l} style={{ fontSize:9, padding:"1px 5px", borderRadius:3, background:c.surface3, color:c.text3, fontWeight:600 }}>{l}</span>)}
    </div>
  );

  const priceCell = (type, key, val, perW) => {
    const over = priceOverrides?.[type]?.[key] !== undefined;
    const display = effPrice(type, key, val);
    return (
      <td style={{ padding:"8px 12px", textAlign:"right", fontFamily:c.mono, fontSize:12, fontWeight:over?700:400, color:over?c.success:c.text, background:over?"rgba(22,101,52,.05)":"transparent", whiteSpace:"nowrap" }}>
        {perW ? `$${display.toFixed(4)}/W` : fmt(display)}
        {over && <span style={{ fontSize:9, marginLeft:4, color:c.success }}>*</span>}
      </td>
    );
  };

  const panelLenders = key => Object.entries(LENDER_CFG).filter(([,cfg]) => (cfg.panels||[]).includes(key)||(cfg.panelsBattery||[]).includes(key)).map(([l])=>l);
  const invLenders   = key => Object.entries(LENDER_CFG).filter(([,cfg]) => (cfg.inverters||[]).includes(key)).map(([l])=>l);

  // ?? Racking groups: individual SKU-level data from CED Q1049075 / Q1061394 ??
  const RACK_GROUPS = [
    {
      group:"SolarMount Light Rail - Dark Domestic", ppw:0.132, ppwKey:"unirac_dom_dark", domestic:true, dcPct:"19.6%",
      note:"Primary domestic dark rail. Use for IGS, Sunrun, Lightreach DC jobs. CED Q1049075.",
      items:[
        { sku:"UNIRC 315168D-US",  desc:"DOM SM Light Rail 168in - Dark",            price:37.39 },
        { sku:"UNIRC 315185D-US",  desc:"DOM SM Light Rail 185in - Dark",            price:44.64 },
        { sku:"UNIRC 303019D-US",  desc:"DOM Bonded Splice Bar Pro Series - Dark",   price:6.22  },
        { sku:"UNIRC 302027D-US",  desc:"DOM SM Bonded Mid Clamp BC - Dark SS",      price:3.50  },
        { sku:"UNIRC 302021D-US",  desc:"DOM SM End Clamp B - Dark AL",              price:2.92  },
        { sku:"UNIRC 004BUTYLD-US",desc:"DOM SolarMount Butyl Attachment Kit - Dark",price:10.17 },
        { sku:"UNIRC 004055D",     desc:"FlashKit Pro - Dark 10pk",                  price:9.31  },
        { sku:"UNIRC 304001D",     desc:"L-Foot Serrated w/ T-Bolt - Dark",          price:3.39  },
        { sku:"UNIRC 309003P",     desc:"SM Rail End Cap Pro UV-Black",               price:0.92  },
        { sku:"UNIRC 008013S",     desc:"Micro Mount Bonding T-Bolt 1/4 x 3/4 SS",  price:0.97  },
        { sku:"UNIRC 330052D",     desc:"Bond T-Bolt and Nut 1/4 x 2.5in Dark SS",  price:1.75  },
        { sku:"UNIRC 008002S",     desc:"WEEB Grounding Lug #1",                     price:7.86  },
        { sku:"UNIRC MLPEMNT-US",  desc:"DOM Universal MLPE Mount",                  price:2.43  },
      ]
    },
    {
      group:"SolarMount Light Rail - Mill Domestic", ppw:0.118, ppwKey:"unirac_dom_light_mill", domestic:true, dcPct:"19.6%",
      note:"Standard domestic mill finish light rail. CED Q1049075.",
      items:[
        { sku:"UNIRC 315168M-US",  desc:"DOM SM Light Rail 168in - Mill",            price:24.08 },
        { sku:"UNIRC 315185M-US",  desc:"DOM SM Light Rail 185in - Mill",            price:31.85 },
        { sku:"UNIRC 303019M-US",  desc:"DOM Bonded Splice Bar Pro Series - Mill",   price:4.72  },
        { sku:"UNIRC 004BUTYLM-US",desc:"DOM SolarMount Butyl Attachment Kit - Mill",price:9.49  },
        { sku:"UNIRC 004055M",     desc:"FlashKit Pro - Mill 10pk",                  price:8.19  },
        { sku:"UNIRC 304001C",     desc:"L-Foot Serrated w/ T-Bolt - Clear",         price:3.22  },
      ]
    },
    {
      group:"SolarMount Standard Dark Rail - Domestic", ppw:0.132, ppwKey:"unirac_dom_dark", domestic:true, dcPct:"19.6%",
      note:"Heavier standard dark rail. CED Q1049075.",
      items:[
        { sku:"UNIRC 310185D-US",  desc:"DOM SM Rail 185in - Dark",                  price:64.36 },
        { sku:"UNIRC 310246D",     desc:"SM Rail 246in - Dark",                       price:88.28 },
        { sku:"UNIRC 303019D",     desc:"Bonded Splice Bar Pro Series - Dark",        price:5.11  },
        { sku:"UNIRC 302027D",     desc:"SM Bonded Mid Clamp BC - Dark SS",           price:3.54  },
        { sku:"UNIRC 302021D",     desc:"SM End Clamp B - Dark AL",                   price:3.46  },
        { sku:"UNIRC 004BUTYLD",   desc:"SolarMount Butyl Attachment Kit - Dark",     price:8.85  },
      ]
    },
    {
      group:"NXT Horizon uMount - Domestic", ppw:0.124, ppwKey:"unirac_nxt_dom", domestic:true, dcPct:"19.6%",
      note:"NXT uMount rail system, domestic. CED Q1049075.",
      items:[
        { sku:"UNIRC 185RLM1-US",    desc:"DOM NXT uMount Rail 185in - Mill",        price:26.43 },
        { sku:"UNIRC 185RLD1-US",    desc:"DOM NXT uMount Rail 185in - Dark",        price:42.11 },
        { sku:"UNIRC RLSPLCM2-US",   desc:"DOM NXT Rail Splice - Mill",              price:7.18  },
        { sku:"UNIRC CCLAMPD1-US",   desc:"DOM NXT Combo Clamp - Dark",              price:4.60  },
        { sku:"UNIRC SHBUTYLD2-US",  desc:"DOM Stronghold Butyl Attachment Kit - Dark",price:10.17},
        { sku:"UNIRC SHBUTYLM2-US",  desc:"DOM Stronghold Butyl Attachment Kit - Mill",price:9.49 },
        { sku:"UNIRC SHCLMPD2-US",   desc:"DOM Stronghold Rail Clamp - Dark",        price:3.97  },
        { sku:"UNIRC SHCLMPM2-US",   desc:"DOM Stronghold Rail Clamp - Mill",        price:3.14  },
        { sku:"UNIRC NUMTLCLMPM-US", desc:"DOM NXT Metal Roof Rail Clamp - Mill",    price:3.53  },
        { sku:"UNIRC NUMTLCLMPD-US", desc:"DOM NXT Metal Roof Rail Clamp - Dark",    price:5.53  },
        { sku:"UNIRC ENDCAPD1",      desc:"NXT Rail and Clamp Cap Kit",              price:0.90  },
        { sku:"UNIRC WRMCLPD1",      desc:"NXT Wire Management Clip",                price:0.31  },
        { sku:"UNIRC NULGMLP1",      desc:"NXT MLPE and Ground Lug Clamp",           price:2.44  },
      ]
    },
    {
      group:"SolarMount Dark Rail / Non-Dom Fasteners", ppw:0.114, ppwKey:"unirac_dom_dark_ndf", domestic:false, dcPct:"15.0%",
      note:"Dark rail with non-domestic fasteners. DC: 15.0%.",
      items:[
        { sku:"UNIRC 310168D",     desc:"SM Rail 168in - Dark",                      price:51.26 },
        { sku:"UNIRC 303019D",     desc:"Bonded Splice Bar Pro Series - Dark",        price:5.11  },
        { sku:"UNIRC 302027D",     desc:"SM Bonded Mid Clamp BC - Dark SS",           price:3.54  },
        { sku:"UNIRC 302021D",     desc:"SM End Clamp B - Dark AL",                   price:3.46  },
        { sku:"UNIRC 004BUTYLD",   desc:"SolarMount Butyl Attachment Kit - Dark",     price:8.85  },
        { sku:"UNIRC 330052S",     desc:"Bond T-Bolt and Nut 1/4 x 2.5in SS",        price:1.53  },
      ]
    },
    {
      group:"SolarMount Non-Dom Light Rail - Mill", ppw:0.11, ppwKey:"unirac_nondom_light", domestic:false, dcPct:"0%",
      note:"Non-domestic light rail. DC: 0%.",
      items:[
        { sku:"UNIRC 315168M",     desc:"SM Light Rail 168in - Mill",                 price:23.42 },
        { sku:"UNIRC 315246M",     desc:"SM Light Rail 246in - Mill",                 price:48.88 },
        { sku:"UNIRC 303019M",     desc:"Bonded Splice Bar Pro Series - Mill",        price:4.49  },
        { sku:"UNIRC 302028C",     desc:"SM Bonded Mid Clamp EF - Mill SS",           price:2.79  },
        { sku:"UNIRC 302025C",     desc:"SM End Clamp F - Clear",                     price:3.42  },
        { sku:"UNIRC 004BUTYLM",   desc:"SolarMount Butyl Attachment Kit - Mill",     price:7.86  },
      ]
    },
    {
      group:"ULA - Universal Layout Adapter", domestic:false, dcPct:"0%",
      note:"ULA mounting components. CED Q1061394.",
      items:[
        { sku:"UNIRC 403200C",     desc:"ULA Brace 2in at 7 ft",                     price:36.25 },
        { sku:"UNIRC 403200C-US",  desc:"DOM ULA Brace 2in at 7 ft",                 price:64.14 },
        { sku:"UNIRC 403201C",     desc:"ULA Brace 2in at 10.5 ft",                  price:59.63 },
        { sku:"UNIRC 403201C-US",  desc:"DOM ULA Brace 2in at 10.5 ft",              price:59.63 },
        { sku:"UNIRC 403202C",     desc:"ULA Brace 2in at 14 ft",                    price:68.72 },
        { sku:"UNIRC 403202C-US",  desc:"DOM ULA Brace 2in at 14 ft",                price:79.06 },
        { sku:"UNIRC 403211C",     desc:"ULA Front Cap 2in AL",                      price:27.63 },
        { sku:"UNIRC 403211C-US",  desc:"DOM ULA Front Cap 2in AL",                  price:26.06 },
        { sku:"UNIRC 403214C",     desc:"ULA Rear Cap 2in AL",                       price:32.38 },
        { sku:"UNIRC 403214C-US",  desc:"DOM ULA Rear Cap 2in AL",                   price:27.54 },
        { sku:"UNIRC 403215C",     desc:"ULA Slider 2in AL",                         price:11.25 },
        { sku:"UNIRC 403215C-US",  desc:"DOM ULA Slider 2in AL",                     price:12.31 },
        { sku:"UNIRC 403216M",     desc:"ULA Rail Bracket",                          price:20.15 },
        { sku:"UNIRC 403216S",     desc:"ULA Threaded Foot 2in Steel",               price:27.11 },
        { sku:"UNIRC 403216S-US",  desc:"DOM ULA Threaded Foot 2in Steel",           price:30.50 },
      ]
    },
    {
      group:"Common Hardware and Accessories", domestic:false, dcPct:"varies",
      note:"Frequently ordered across all system types. CED Q1049075.",
      items:[
        { sku:"UNIRC 004AT1H",   desc:"SolarHook Flat Tile",                         price:6.86  },
        { sku:"UNIRC 004CT1H",   desc:"SolarHook Spanish 7in Base",                  price:8.17  },
        { sku:"UNIRC 004CT2H",   desc:"SolarHook Spanish 9in Base",                  price:9.24  },
        { sku:"UNIRC 004FLAT",   desc:"SolarHook Flashing Flat",                     price:5.11  },
        { sku:"UNIRC 004130M",   desc:"Standing Seam Clamp Mini 1SS",                price:8.81  },
        { sku:"UNIRC 004131M",   desc:"Standing Seam Clamp Standard 2SS",            price:9.63  },
        { sku:"UNIRC 004085D",   desc:"FlashLoc Composite Kit - Dark",               price:8.51  },
        { sku:"UNIRC 004085M",   desc:"FlashLoc Composite Kit - Mill",               price:7.56  },
        { sku:"UNIRC 008000U",   desc:"SFM N/S Bonding Clamp",                       price:2.24  },
        { sku:"UNIRC 008009P",   desc:"ILSCO Lay-In Lug GBL4DBT",                   price:11.63 },
        { sku:"UNIRC 330052S",   desc:"Bond T-Bolt and Nut 1/4 x 2.5in SS",         price:1.53  },
        { sku:"UNIRC 330051S",   desc:"Bond T-Bolt and Nut 1/4 x 2.25in SS",        price:1.40  },
        { sku:"UNIRC 330050S",   desc:"Bond T-Bolt and Nut 1/4 x 2in SS",           price:1.29  },
        { sku:"UNIRC GUARD-M5",  desc:"5in Guardian Critter Mesh 100ft roll",        price:60.67 },
        { sku:"UNIRC GUARD-M6",  desc:"6in Guardian Critter Mesh 100ft roll",        price:72.69 },
        { sku:"UNIRC GUARD-M8",  desc:"8in Guardian Critter Mesh 100ft roll",        price:82.92 },
        { sku:"UNIRC GUARD-CLP", desc:"Guardian Clip",                               price:1.81  },
      ]
    },
  ];

  return (
    <div style={{ paddingBottom: 40 }}>

      {/* PANELS */}
      <SecHdr title="Panels" sub={Object.keys(PANELS).length + " products"} />
      <div style={{ ...card, padding:0, overflow:"hidden" }}>
        <table style={{ width:"100%", borderCollapse:"collapse" }}>
          <thead><tr><TH>Product</TH><TH>Watt</TH><TH right>$/Unit</TH><TH right>$/W</TH><TH>Dom</TH><TH>Lenders</TH></tr></thead>
          <tbody>
            {Object.entries(PANELS).map(([key, p]) => (
              <tr key={key} style={{ borderBottom:`1px solid ${c.surface3}` }}>
                <td style={{ padding:"8px 12px", fontSize:12, color:c.text2 }}>{p.label.split(" -- ")[0].split(" - ")[0]}</td>
                <td style={{ padding:"8px 12px", fontFamily:c.mono, fontSize:12, color:c.text3 }}>{p.watt}W</td>
                {priceCell("panels", key, p.price)}
                <td style={{ padding:"8px 12px", textAlign:"right", fontFamily:c.mono, fontSize:12, color:c.text3 }}>${(effPrice("panels",key,p.price)/p.watt).toFixed(4)}/W</td>
                <td style={{ padding:"8px 12px" }}>{domBadge(p.domestic)}</td>
                <td style={{ padding:"8px 12px" }}>{lenderBadge(panelLenders(key))}</td>
              </tr>
            ))}
          </tbody>
        </table>
      </div>

      {/* MICROINVERTERS */}
      <SecHdr title="Microinverters" sub={Object.entries(INVERTERS).filter(([,v])=>v.perPanel).length + " products"} />
      <div style={{ ...card, padding:0, overflow:"hidden" }}>
        <table style={{ width:"100%", borderCollapse:"collapse" }}>
          <thead><tr><TH>Product</TH><TH right>$/Unit</TH><TH right>DC %</TH><TH>Dom</TH><TH>Lenders</TH></tr></thead>
          <tbody>
            {Object.entries(INVERTERS).filter(([,v])=>v.perPanel).map(([key,inv]) => (
              <tr key={key} style={{ borderBottom:`1px solid ${c.surface3}` }}>
                <td style={{ padding:"8px 12px", fontSize:12, color:c.text2 }}>{inv.label.split(" (")[0]}</td>
                {priceCell("inverters", key, inv.price)}
                <td style={{ padding:"8px 12px", textAlign:"right", fontFamily:c.mono, fontSize:12, color:(INV_DC[key]||0)>0?c.success:c.text3 }}>{(INV_DC[key]||0).toFixed(1)}%</td>
                <td style={{ padding:"8px 12px" }}>{domBadge((INV_DC[key]||0)>0)}</td>
                <td style={{ padding:"8px 12px" }}>{lenderBadge(invLenders(key))}</td>
              </tr>
            ))}
          </tbody>
        </table>
      </div>

      {/* STRING INVERTERS */}
      <SecHdr title="String Inverters" sub={Object.entries(INVERTERS).filter(([,v])=>v.perSystem).length + " products"} />
      <div style={{ ...card, padding:0, overflow:"hidden" }}>
        <table style={{ width:"100%", borderCollapse:"collapse" }}>
          <thead><tr><TH>Product</TH><TH right>$/System</TH><TH right>Optimizer $/ea</TH><TH right>DC %</TH><TH>Lenders</TH></tr></thead>
          <tbody>
            {Object.entries(INVERTERS).filter(([,v])=>v.perSystem).map(([key,inv]) => (
              <tr key={key} style={{ borderBottom:`1px solid ${c.surface3}` }}>
                <td style={{ padding:"8px 12px", fontSize:12, color:c.text2 }}>{inv.label.split(" ($")[0]}</td>
                {priceCell("inverters", key, inv.price)}
                {inv.optimizerPrice ? priceCell("optimizers", key, inv.optimizerPrice) : <td style={{ padding:"8px 12px", textAlign:"right", color:c.text3, fontSize:12 }}>--</td>}
                <td style={{ padding:"8px 12px", textAlign:"right", fontFamily:c.mono, fontSize:12, color:(INV_DC[key]||0)>0?c.success:c.text3 }}>{(INV_DC[key]||0).toFixed(1)}%</td>
                <td style={{ padding:"8px 12px" }}>{lenderBadge(invLenders(key))}</td>
              </tr>
            ))}
          </tbody>
        </table>
      </div>

      {/* RACKING - INDIVIDUAL SKUs */}
      <SecHdr title="Racking - Individual Components" sub="CED Q1049075 / Q1061394" />
      <div style={{ fontSize:11, color:c.text2, marginBottom:12, background:c.accentL, border:`1px solid rgba(13,110,110,.15)`, borderRadius:7, padding:"8px 12px", lineHeight:1.6 }}>
        Individual SKU-level prices from CED Greentech. Use these to verify line items against any CED invoice. Blended $/W figures in the Pricing Calculator are derived from these actuals.
      </div>
      {RACK_GROUPS.map(group => (
        <div key={group.group} style={{ ...card, padding:0, overflow:"hidden", marginBottom:10 }}>
          <div style={{ padding:"9px 14px", background:c.surface2, borderBottom:`1px solid ${c.border}`, display:"flex", alignItems:"center", gap:8, flexWrap:"wrap" }}>
            <span style={{ fontSize:12, fontWeight:700, color:c.text }}>{group.group}</span>
            {domBadge(group.domestic)}
            <span style={{ fontSize:9, color:c.text3, background:c.surface3, padding:"1px 6px", borderRadius:8 }}>DC: {group.dcPct}</span>
            {group.ppw && (
              <span style={{ fontSize:9, fontWeight:700, color:c.accent, background:c.accentL, padding:"1px 8px", borderRadius:8, border:`1px solid rgba(13,110,110,.2)`, fontFamily:c.mono }}>
                ${group.ppw.toFixed(3)}/W &nbsp;?&nbsp; 12.3kW est. ${(group.ppw*12300).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}
              </span>
            )}
            <span style={{ fontSize:10, color:c.text3, marginLeft:"auto", fontStyle:"italic" }}>{group.note}</span>
          </div>
          <table style={{ width:"100%", borderCollapse:"collapse" }}>
            <thead>
              <tr>
                <th style={{ padding:"6px 12px", textAlign:"left", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, borderBottom:`1px solid ${c.border}`, background:c.surface2, width:"20%" }}>SKU</th>
                <th style={{ padding:"6px 12px", textAlign:"left", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, borderBottom:`1px solid ${c.border}`, background:c.surface2 }}>Description</th>
                <th style={{ padding:"6px 12px", textAlign:"right", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, borderBottom:`1px solid ${c.border}`, background:c.surface2, width:"12%" }}>Unit Price</th>
                <th style={{ padding:"6px 12px", textAlign:"right", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, borderBottom:`1px solid ${c.border}`, background:c.surface2, width:"8%" }}>Per</th>
              </tr>
            </thead>
            <tbody>
              {group.items.map((item, i) => (
                <tr key={i} style={{ borderBottom:`1px solid ${c.surface3}`, background:i%2===0?"transparent":c.surface2 }}>
                  <td style={{ padding:"7px 12px", fontFamily:c.mono, fontSize:11, color:c.text3 }}>{item.sku}</td>
                  <td style={{ padding:"7px 12px", fontSize:12, color:c.text2 }}>{item.desc}</td>
                  <td style={{ padding:"7px 12px", textAlign:"right", fontFamily:c.mono, fontSize:12, fontWeight:600, color:c.text }}>${item.price.toFixed(2)}</td>
                  <td style={{ padding:"7px 12px", textAlign:"right", fontSize:11, color:c.text3 }}>each</td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>
      ))}

      {/* BATTERIES */}
      {["Enphase Batteries","SolarEdge Batteries","Tesla Batteries"].map(secTitle => {
        const secAdders = ADDER_SECTIONS.find(s => s.title === secTitle);
        if (!secAdders) return null;
        const batAdders = secAdders.keys.map(k => ADDER_MAP[k]).filter(Boolean);
        return (
          <div key={secTitle}>
            <SecHdr title={secTitle} sub={batAdders.length + " configurations"} />
            <div style={{ ...card, padding:0, overflow:"hidden" }}>
              <table style={{ width:"100%", borderCollapse:"collapse" }}>
                <thead>
                  <tr>
                    <th style={{ padding:"7px 12px", textAlign:"left", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, borderBottom:`2px solid ${c.border}`, background:c.surface2, width:"38%" }}>Component / Config</th>
                    <th style={{ padding:"7px 12px", textAlign:"right", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, borderBottom:`2px solid ${c.border}`, background:c.surface2 }}>Unit Cost</th>
                    <th style={{ padding:"7px 12px", textAlign:"right", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, borderBottom:`2px solid ${c.border}`, background:c.surface2 }}>SEA Installed</th>
                    <th style={{ padding:"7px 12px", textAlign:"right", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, borderBottom:`2px solid ${c.border}`, background:c.surface2 }}>List</th>
                    <th style={{ padding:"7px 12px", textAlign:"center", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, borderBottom:`2px solid ${c.border}`, background:c.surface2 }}>DC</th>
                  </tr>
                </thead>
                <tbody>
                  {batAdders.map(a => {
                    const bom = a.detail?.bom || [];
                    const dcEligible = BAT_DC_ELIGIBLE[a.key];
                    const gm = a.list && a.sea ? ((a.list-a.sea)/a.list*100).toFixed(0) : null;
                    return (
                      <React.Fragment key={a.key}>
                        <tr style={{ background:c.surface2, borderTop:`2px solid ${c.border}` }}>
                          <td colSpan={5} style={{ padding:"8px 12px" }}>
                            <div style={{ display:"flex", alignItems:"center", gap:8 }}>
                              <span style={{ fontSize:12, fontWeight:700, color:c.accent }}>{a.label}</span>
                              {dcEligible===true && <span style={{ fontSize:9, fontWeight:700, color:c.success, background:c.successL, padding:"1px 6px", borderRadius:8 }}>DC Eligible</span>}
                              {dcEligible===false && <span style={{ fontSize:9, fontWeight:700, color:c.danger, background:c.dangerL, padding:"1px 6px", borderRadius:8 }}>Not DC 2026</span>}
                              {(a.isTeslaLead||a.isTeslaExp||a.isTeslaPWX) && <span style={{ fontSize:9, color:c.text3, background:c.surface3, padding:"1px 6px", borderRadius:8 }}>Dynamic - scales with system size</span>}
                            </div>
                          </td>
                        </tr>
                        {bom.map((b, bi) => (
                          <tr key={bi} style={{ borderBottom:`1px solid ${c.surface3}` }}>
                            <td style={{ padding:"6px 12px 6px 24px", fontSize:12, color:c.text2 }}>{b.item}</td>
                            <td style={{ padding:"6px 12px", textAlign:"right", fontFamily:c.mono, fontSize:12, color:c.text, whiteSpace:"nowrap" }}>{b.cost}</td>
                            <td colSpan={3} style={{ padding:"6px 12px" }}></td>
                          </tr>
                        ))}
                        <tr style={{ borderBottom:`2px solid ${c.border}`, background:"rgba(13,110,110,.03)" }}>
                          <td style={{ padding:"7px 12px 7px 24px", fontSize:11, fontStyle:"italic", color:c.text3 }}>Installed total</td>
                          <td style={{ padding:"7px 12px" }}></td>
                          <td style={{ padding:"7px 12px", textAlign:"right", fontFamily:c.mono, fontSize:12, fontWeight:700, color:c.accent }}>{a.sea ? fmt(a.sea) : "Dynamic"}</td>
                          <td style={{ padding:"7px 12px", textAlign:"right", fontFamily:c.mono, fontSize:12, fontWeight:700, color:c.text }}>
                            {a.list ? fmt(a.list) : "Dynamic"}
                            {gm && <span style={{ fontSize:10, marginLeft:5, color:parseInt(gm)>=15?c.success:c.warn }}>({gm}% GM)</span>}
                          </td>
                          <td style={{ padding:"7px 12px", textAlign:"center" }}>
                            {dcEligible===true ? <span style={{ fontSize:10, color:c.success }}>Yes</span> : dcEligible===false ? <span style={{ fontSize:10, color:c.danger }}>No</span> : <span style={{ fontSize:10, color:c.text3 }}>--</span>}
                          </td>
                        </tr>
                      </React.Fragment>
                    );
                  })}
                </tbody>
              </table>
            </div>
          </div>
        );
      })}

      {/* PDF PRICE UPDATER */}
      <div style={{ margin:"32px 0 8px", paddingBottom:8, borderBottom:`2px solid ${c.border}`, display:"flex", alignItems:"center", gap:10 }}>
        <span style={{ fontSize:11, fontWeight:800, letterSpacing:".14em", textTransform:"uppercase", color:c.accent }}>Update Pricing from CED Quote</span>
        <span style={{ fontSize:11, color:c.text3 }}>Upload a PDF from Daniel at CED Greentech</span>
      </div>
      <div style={{ ...card }}>
        <label style={{ display:"block", cursor:"pointer" }}>
          <div style={{ border:`2px dashed ${pdfFileName?c.accent:c.border2}`, borderRadius:10, padding:"28px 20px", textAlign:"center", background:pdfFileName?c.accentL:c.surface2, transition:".2s" }}>
            {pdfFileName ? (
              <><div style={{ fontSize:24, marginBottom:6 }}>?</div><div style={{ fontSize:13, fontWeight:700, color:c.accent }}>{pdfFileName}</div><div style={{ fontSize:11, color:c.text3, marginTop:3 }}>Click to replace</div></>
            ) : (
              <><div style={{ fontSize:24, marginBottom:6 }}>?</div><div style={{ fontSize:13, fontWeight:600, color:c.text2 }}>Drop CED quote PDF here or click to browse</div><div style={{ fontSize:11, color:c.text3, marginTop:4 }}>AI will extract and match all line items</div></>
            )}
          </div>
          <input type="file" accept=".pdf" style={{ display:"none" }} onChange={e => { const f=e.target.files?.[0]; if(f){setPdfFileName(f.name);parsePDF(f);} }} />
        </label>

        {pdfParsing && (
          <div style={{ marginTop:16, padding:"14px 16px", background:c.accentL, border:`1.5px solid rgba(13,110,110,.2)`, borderRadius:8, display:"flex", alignItems:"center", gap:10 }}>
            <div style={{ width:16, height:16, border:`2px solid ${c.accent}`, borderTopColor:"transparent", borderRadius:"50%", animation:"spin 0.8s linear infinite" }} />
            <span style={{ fontSize:13, color:c.accent, fontWeight:600 }}>Analyzing quote with AI...</span>
          </div>
        )}
        {pdfError && <div style={{ marginTop:12, padding:"10px 14px", background:c.dangerL, border:`1.5px solid rgba(185,28,28,.2)`, borderRadius:8, fontSize:12, color:c.danger }}>{pdfError}</div>}
        {pdfApplied && <div style={{ marginTop:12, padding:"10px 14px", background:c.successL, border:`1.5px solid rgba(22,101,52,.2)`, borderRadius:8, fontSize:13, fontWeight:600, color:c.success }}>Prices updated - Pricing Calculator now reflects new CED pricing.</div>}

        {pdfDiff && !pdfParsing && (
          <div style={{ marginTop:18 }}>
            {pdfDiff.matched.length > 0 && (
              <>
                <div style={{ fontSize:11, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, marginBottom:8 }}>
                  Matched Items - {pdfDiff.matched.filter(m=>m.changed).length} price changes found
                </div>
                <table style={{ width:"100%", borderCollapse:"collapse", fontSize:12, marginBottom:16 }}>
                  <thead><tr>
                    {["Apply","Product","Current Price","Quote Price","Change"].map(h => (
                      <th key={h} style={{ padding:"6px 10px", textAlign:h==="Apply"?"center":"left", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.text3, borderBottom:`2px solid ${c.border}`, background:c.surface2 }}>{h}</th>
                    ))}
                  </tr></thead>
                  <tbody>
                    {pdfDiff.matched.map((m, i) => {
                      const delta = m.unit_price - m.currentPrice;
                      const deltaPct = (delta/m.currentPrice*100).toFixed(1);
                      const isSel = !!pdfSelected[`m_${i}`];
                      return (
                        <tr key={i} style={{ borderBottom:`1px solid ${c.surface3}`, background:isSel?(delta<0?"rgba(22,101,52,.04)":"rgba(185,28,28,.04)"):"transparent", opacity:m.changed?1:0.5 }}>
                          <td style={{ padding:"8px 10px", textAlign:"center" }}>
                            {m.changed ? <input type="checkbox" checked={isSel} onChange={e=>setPdfSelected(p=>({...p,[`m_${i}`]:e.target.checked}))} style={{ width:14, height:14, cursor:"pointer", accentColor:c.accent }} /> : <span style={{ fontSize:10, color:c.text3 }}>--</span>}
                          </td>
                          <td style={{ padding:"8px 10px" }}>
                            <div style={{ fontSize:12, color:c.text2, fontWeight:500 }}>{m.catalogLabel}</div>
                            <div style={{ fontSize:10, color:c.text3, fontFamily:"monospace", marginTop:1 }}>{m.sku||m.description?.slice(0,40)}</div>
                          </td>
                          <td style={{ padding:"8px 10px", fontFamily:c.mono, fontSize:12, color:c.text3 }}>${m.currentPrice.toFixed(2)}</td>
                          <td style={{ padding:"8px 10px", fontFamily:c.mono, fontSize:12, fontWeight:700, color:m.changed?(delta<0?c.success:c.danger):c.text3 }}>${m.unit_price.toFixed(2)}</td>
                          <td style={{ padding:"8px 10px", fontFamily:c.mono, fontSize:11 }}>
                            {m.changed ? <span style={{ color:delta<0?c.success:c.danger, fontWeight:700 }}>{delta<0?"down":"up"} {Math.abs(delta).toFixed(2)} ({deltaPct}%)</span> : <span style={{ color:c.text3 }}>No change</span>}
                          </td>
                        </tr>
                      );
                    })}
                  </tbody>
                </table>
              </>
            )}

            {pdfDiff.unmatched.length > 0 && (
              <>
                <div style={{ fontSize:11, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.warn, marginBottom:8 }}>
                  {pdfDiff.unmatched.length} New / Unrecognized Items - Not in current catalog
                </div>
                <div style={{ background:c.warnL, border:`1.5px solid rgba(180,83,9,.2)`, borderRadius:8, overflow:"hidden", marginBottom:16 }}>
                  <table style={{ width:"100%", borderCollapse:"collapse", fontSize:12 }}>
                    <thead><tr>
                      {["SKU","Description","Unit Price"].map(h => <th key={h} style={{ padding:"6px 10px", textAlign:"left", fontSize:10, fontWeight:700, letterSpacing:".1em", textTransform:"uppercase", color:c.warn, borderBottom:`1px solid rgba(180,83,9,.2)` }}>{h}</th>)}
                    </tr></thead>
                    <tbody>
                      {pdfDiff.unmatched.map((u, i) => (
                        <tr key={i} style={{ borderBottom:`1px solid rgba(180,83,9,.1)` }}>
                          <td style={{ padding:"7px 10px", fontFamily:"monospace", fontSize:11, color:c.warn }}>{u.sku||"--"}</td>
                          <td style={{ padding:"7px 10px", fontSize:12, color:c.text2 }}>{u.description}</td>
                          <td style={{ padding:"7px 10px", fontFamily:c.mono, fontSize:12, fontWeight:600, color:c.warn }}>${u.unit_price?.toFixed(2)||"--"}</td>
                        </tr>
                      ))}
                    </tbody>
                  </table>
                  <div style={{ padding:"8px 12px", fontSize:11, color:c.warn, borderTop:`1px solid rgba(180,83,9,.2)` }}>These items were found in the quote but not matched to the current catalog. Bring to dev to add new SKUs.</div>
                </div>
              </>
            )}

            {pdfDiff.matched.some((_,i)=>pdfSelected[`m_${i}`]) && (
              <button onClick={applyPriceChanges} style={{ padding:"11px 24px", background:c.accent, color:"#fff", border:"none", borderRadius:9, fontSize:13, fontWeight:700, cursor:"pointer", fontFamily:"inherit", letterSpacing:".04em" }}>
                Apply {pdfDiff.matched.filter((_,i)=>pdfSelected[`m_${i}`]).length} Price Updates to Calculator
              </button>
            )}
            {pdfDiff.matched.length>0 && !pdfDiff.matched.some(m=>m.changed) && !pdfDiff.unmatched.length && (
              <div style={{ padding:"12px 16px", background:c.successL, border:`1.5px solid rgba(22,101,52,.2)`, borderRadius:8, fontSize:13, color:c.success, fontWeight:600 }}>All prices match - no updates needed.</div>
            )}
          </div>
        )}
      </div>
      <style>{`@keyframes spin{to{transform:rotate(360deg)}}`}</style>
    </div>
  );
}

// ??? COMMISSIONS TAB ?????????????????????????????????????????????????????????

function CommissionsTab({ c, card, lbl, fmt, fmtPPW, C, st, lender, watts, jobType, dcOn, targetM, setTargetM, customMStr, setCustomMStr, effectiveM, setPresetM, soldPPWStr, setSoldPPWStr, setActiveTab, util, setUtil, ecOn, setEcOn, maxPmtStr, setMaxPmtStr, linputs, setLinputs, waterfallLender, setWaterfallLender, selectedOptions, setSelectedOptions, showOptionPicker, setShowOptionPicker, splits, setSplits, showInactive, setShowInactive, commView, setCommView, campaignOn, campaignSalesPPW, campaignDealerMode, escrowOn, setEscrowOn }) {
  const W     = watts || 0;
  const kw    = W / 1000;
  const maxPmt = parseFloat(maxPmtStr) || null;
  const battery = jobType === "storage";
  const redlinePPW = C?.targetSc?.baseRedlinePPW || 2.50;
  const redlineVal = redlinePPW * W;

  const getLI = (l, f) => {
    const meta = LENDER_META_COMM[l];
    const defRate = meta?.defaultRate?.[st] ?? 0.13;
    const snapped = Math.round(defRate / COMM_RATE_STEP) * COMM_RATE_STEP;
    const yRange  = COMM_YIELD_RANGES[l]?.[st] || [900, 1300];
    const defYld  = Math.round((yRange[0] + yRange[1]) / 2 / 100) * 100;
    const def = { escalator: meta?.escalators?.[st]?.[0] || "", sellRate: snapped, yield: defYld };
    return linputs[l]?.[f] ?? def[f];
  };
  const setLI = (l, f, v) => setLinputs(p => ({ ...p, [l]: { ...(p[l]||{}), [f]: v } }));
  const nextId = () => Math.max(0, ...splits.map(s => s.id)) + 1;

  const activeLenders = LENDERS_BY_STATE[st] || [];
  const soldPPW     = parseFloat(soldPPWStr) || 0;
  const soldTotal   = soldPPW * W;
  const hasSoldRate = soldPPW > 0;

  const adderList  = C?.listSum || 0;

  const lCalcs = activeLenders.map(lenderKey => {
    const meta = LENDER_META_COMM[lenderKey];
    if (!meta) return null;
    const esc    = getLI(lenderKey, "escalator");
    const rate   = Number(getLI(lenderKey, "sellRate")) || (lenderKey === "Cash" ? 3.20 : 0.13);
    const lYld   = Number(getLI(lenderKey, "yield")) || 1200;
    const epc    = W > 0 ? commGetEPC(lenderKey, st, util, esc, rate, lYld, dcOn, ecOn, kw) : 0;
    const monthly = (lenderKey !== "Cash" && kw > 0) ? (kw * lYld * rate) / 12 : 0;
    const viable  = epc >= redlinePPW;
    const spread  = epc - redlinePPW;
    const contractVal = epc * W;
    const commission  = viable ? Math.max(0, contractVal - redlineVal - adderList) : 0;
    let rateCap = null, aboveCap = false;
    const caps = LENDER_META_COMM[lenderKey]?.rateCapByState?.[st]?.[util];
    if (caps?.[esc]) { rateCap = caps[esc]; if (rate > rateCap) aboveCap = true; }
    return { lender: lenderKey, product: meta.product, dot: meta.dot, esc, rate, lYld, epc, monthly, viable, spread, contractVal, commission, rateCap, aboveCap, note: meta.note, isDraft: meta.isDraft };
  }).filter(Boolean);

  const viableLCs = lCalcs.filter(l => l.viable && l.lender !== "Cash");
  const bestComm  = [...viableLCs].sort((a, b) => b.commission - a.commission)[0] || null;
  const lowestPmt = [...viableLCs].sort((a, b) => a.monthly - b.monthly)[0] || null;

  // activeWF always uses live lCalcs so manual stepper adjustments reflect immediately
  const wfLenderKey  = waterfallLender ? waterfallLender.replace(/_bestComm$|_lowestPmt$|_closestMatch$/, "") : null;
  const activeWFLive = wfLenderKey ? lCalcs.find(l => l.lender === wfLenderKey) : null;
  const activeWF     = activeWFLive || bestComm || null;
  const wfUseActual  = !!waterfallLender && !!activeWF;
  const wfContractVal = wfUseActual ? activeWF.contractVal : (hasSoldRate ? soldTotal : (activeWF?.contractVal || 0));
  const wfCommission  = wfUseActual
    ? Math.max(0, activeWF.contractVal - redlineVal - adderList)
    : (hasSoldRate ? Math.max(0, soldTotal - redlineVal - adderList) : (activeWF?.commission || 0));
  const isDealer   = campaignDealerMode;
  const escrowAmt  = isDealer || (campaignOn && campaignSalesPPW <= 0)
    ? 0
    : campaignOn && campaignSalesPPW > 0
      ? campaignSalesPPW * W
      : escrowOn ? wfCommission * 0.10 : 0;
  const escrowLabel = isDealer
    ? "Dealer deal ? no withholding"
    : (campaignOn && campaignSalesPPW <= 0)
      ? "Ops covering 100% ? no withholding"
      : campaignOn && campaignSalesPPW > 0
        ? `Campaign ? sales share ? ${fmtPPW(campaignSalesPPW)}/W`
        : escrowOn ? "10% withheld from sales spread" : "No withholding";
  const escrow    = escrowAmt;
  const commPool  = wfCommission - escrow;
  const totalPct  = splits.reduce((s, r) => {
    if (r.mode === "ppw") {
      const ppwVal = parseFloat(r.ppw) || 0;
      return s + (commPool > 0 ? ppwVal * W / commPool * 100 : 0);
    }
    return s + (parseFloat(r.pct) || 0);
  }, 0);
  const pctExact  = Math.abs(totalPct - 100) < 0.01;
  const pctOver   = totalPct > 100;
  const pctColor  = pctExact ? c.success : pctOver ? c.danger : c.warn;

  const seg_s = { display:"flex", gap:3, background:c.surface3, border:`1.5px solid ${c.border}`, borderRadius:9, padding:3 };
  const sb    = (on, col) => ({ flex:1, padding:"7px 4px", borderRadius:7, border:on?`1px solid ${c.border}`:"none", background:on?c.surface:"transparent", color:on?(col||c.accent):c.text3, cursor:"pointer", fontFamily:c.sans, fontSize:12, fontWeight:on?700:600, transition:".12s" });
  const selS  = { background:c.surface2, border:`1.5px solid ${c.border}`, color:c.text, padding:"8px 10px", borderRadius:8, width:"100%", fontFamily:c.sans, fontSize:13, fontWeight:500, outline:"none" };
  const inpS  = { background:c.surface2, border:`1.5px solid ${c.border}`, color:c.text, padding:"8px 10px", borderRadius:8, width:"100%", fontFamily:c.sans, fontSize:13, fontWeight:500, outline:"none" };

  const ROLES = ["Setter","Closer","Setter Manager","Closer Manager","Setter Director","VP","Manager","Other"];

  // HO View
  if (commView === "ho") {
    const viable = lCalcs.filter(l => l.viable && l.lender !== "Cash").sort((a,b) => a.monthly - b.monthly);
    return (
      <div style={{ minHeight:"100vh", background:c.bg, fontFamily:c.sans, color:c.text }}>
        <div style={{ background:c.accent, padding:"24px 32px", display:"flex", justifyContent:"space-between", alignItems:"center" }}>
          <div>
            <div style={{ fontSize:22, fontWeight:800, color:"#fff" }}>eEquals Solar</div>
            <div style={{ fontSize:12, color:"rgba(255,255,255,.75)", marginTop:2 }}>Your Custom Solar Proposal</div>
          </div>
          <button onClick={() => setCommView("sales")} style={{ background:"rgba(255,255,255,.15)", color:"#fff", border:"1px solid rgba(255,255,255,.3)", borderRadius:8, padding:"9px 16px", fontFamily:c.sans, fontSize:12, fontWeight:700, cursor:"pointer" }}>? Back to Sales View</button>
        </div>
        <div style={{ maxWidth:760, margin:"0 auto", padding:"32px 24px" }}>
          <div style={{ display:"grid", gridTemplateColumns:"repeat(4,1fr)", gap:12, marginBottom:28 }}>
            {[["System Size",`${kw.toFixed(2)} kW`],["Battery Storage",battery?"Included":"Solar Only"],["State",st],["Redline",fmtPPW(redlinePPW)]].map(([l,v],i)=>(
              <div key={l} style={{ background:i===0?c.accent:c.surface, border:`1px solid ${i===0?c.accent:c.border}`, borderRadius:12, padding:18 }}>
                <div style={{ fontSize:10, fontWeight:700, textTransform:"uppercase", letterSpacing:".05em", color:i===0?"rgba(255,255,255,.7)":c.text3, marginBottom:6 }}>{l}</div>
                <div style={{ fontSize:18, fontWeight:800, color:i===0?"#fff":c.text }}>{v}</div>
              </div>
            ))}
          </div>
          <div style={{ fontSize:16, fontWeight:700, marginBottom:14 }}>Your Financing Options</div>
          <div style={{ display:"grid", gridTemplateColumns:"1fr 1fr", gap:14 }}>
            {viable.slice(0,4).map((lc,i) => (
              <div key={lc.lender} style={{ background:c.surface, border:`1.5px solid ${i===0?c.accent:c.border}`, borderRadius:14, padding:22 }}>
                {i===0 && <div style={{ fontSize:9, fontWeight:700, background:c.accent, color:"#fff", padding:"2px 8px", borderRadius:20, display:"inline-block", marginBottom:8, letterSpacing:".06em" }}>BEST RATE</div>}
                <div style={{ fontSize:13, fontWeight:700, color:c.text2 }}>{lc.lender}</div>
                <div style={{ fontSize:11, color:c.text3, marginBottom:12 }}>{lc.esc} escalator ? 25-year term</div>
                <div style={{ fontSize:10, fontWeight:700, textTransform:"uppercase", color:c.text3, marginBottom:4 }}>Est. Monthly Payment</div>
                <div style={{ fontSize:32, fontWeight:900, color:i===0?c.accent:c.text, fontFamily:c.mono }}>{fmt(Math.round(lc.monthly))}<span style={{ fontSize:13, fontWeight:500, color:c.text3 }}>/mo</span></div>
                <div style={{ marginTop:8, fontSize:11, color:c.text3 }}>${lc.rate.toFixed(3)}/kWh ? {Math.round(kw*(lc.lYld||1200)).toLocaleString()} kWh/yr</div>
              </div>
            ))}
          </div>
          <div style={{ marginTop:32, textAlign:"center", fontSize:11, color:c.text3 }}>eEquals Solar ? CR Solar LLC ? For discussion purposes only ? subject to final design and approval</div>
        </div>
      </div>
    );
  }

  return (
    <div style={{ paddingBottom:40 }}>
      {/* Header controls */}
      <div style={{ display:"flex", alignItems:"center", justifyContent:"space-between", marginBottom:18 }}>
        <div style={{ fontSize:10, fontWeight:700, letterSpacing:".18em", textTransform:"uppercase", color:c.accent }}>02 ? Commissions Model</div>
        <div style={{ display:"flex", gap:8 }}>
          <button onClick={() => setShowInactive(v => !v)} style={{ padding:"7px 13px", borderRadius:8, border:`1px solid ${showInactive?c.warn:c.border}`, background:showInactive?c.warnL:c.surface2, color:showInactive?c.warn:c.text3, fontFamily:c.sans, fontSize:11, fontWeight:700, cursor:"pointer" }}>? {showInactive?"Hide":"Show"} Inactive</button>
          <button onClick={() => setCommView("ho")} style={{ padding:"7px 13px", borderRadius:8, border:`1px solid ${c.accent}`, background:c.accentL, color:c.accent, fontFamily:c.sans, fontSize:11, fontWeight:700, cursor:"pointer" }}>? HO View</button>
        </div>
      </div>

      <div style={{ display:"grid", gridTemplateColumns:"340px 1fr", gap:18, alignItems:"start" }}>

        {/* ?? LEFT COLUMN ?? */}
        <div>
          {/* Deal Parameters */}
          <div style={card}>
            <div style={{ fontSize:10, fontWeight:700, letterSpacing:".15em", textTransform:"uppercase", color:c.accent, marginBottom:14 }}>Deal Parameters</div>
            <div style={{ marginBottom:10 }}>
              <div style={lbl}>Reference (from Tab 1)</div>
              <div style={{ background:c.surface2, border:`1px solid ${c.border}`, borderRadius:8, padding:"8px 12px", fontSize:12, color:c.text2 }}>
                {st} ? {lender} ? {kw.toFixed(2)} kW ? {battery?"Storage":"Solar Only"} ? Redline: <strong style={{ color:c.accent }}>{fmtPPW(redlinePPW)}</strong>
              </div>
            </div>
            <div style={{ marginBottom:10 }}>
              <div style={lbl}>Utility</div>
              <select style={selS} value={util} onChange={e => setUtil(e.target.value)}>
                {(UTILITIES_BY_STATE[st] || []).map(u => <option key={u}>{u}</option>)}
              </select>
            </div>
            <div style={{ display:"grid", gridTemplateColumns:"1fr 1fr", gap:10, marginBottom:10 }}>
              <div>
                <div style={lbl}>Domestic Content</div>
                <div style={seg_s}><button style={sb(!dcOn)} onClick={()=>{}}>No</button><button style={sb(dcOn, c.success)} onClick={()=>{}}>Yes</button></div>
                <div style={{ fontSize:9, color:c.text3, marginTop:3 }}>Set in Tab 1 ? carries through</div>
              </div>
              <div>
                <div style={lbl}>Energy Community</div>
                <div style={seg_s}><button style={sb(!ecOn)} onClick={() => setEcOn(false)}>No</button><button style={sb(ecOn, c.blue)} onClick={() => setEcOn(true)}>Yes</button></div>
                {ecOn && <div style={{ fontSize:9, color:c.blue, marginTop:3 }}>? Verify per address</div>}
              </div>
            </div>
            <div>
              <div style={lbl}>HO Current Monthly Utility Bill ? Optional</div>
              <input style={inpS} type="number" value={maxPmtStr} onChange={e => setMaxPmtStr(e.target.value)} placeholder="e.g. 220" />
            </div>
            {/* Margin Scenarios ? synced with Tab 1 */}
            <div style={{ marginTop:14, paddingTop:12, borderTop:`1px solid ${c.border}` }}>
              <div style={lbl}>Redline Scenario (synced with Tab 1)</div>
              <div style={{ display:"flex", gap:5, flexWrap:"wrap", marginBottom:8 }}>
                {[0,10,15,20,25,30,35].map(m => {
                  const isActive = effectiveM === m && customMStr === "";
                  return <button key={m} onClick={() => { setPresetM(m); }} style={{ padding:"4px 10px", borderRadius:20, border:`1.5px solid ${isActive?"rgba(13,110,110,.4)":c.border}`, background:isActive?c.accentL:c.surface2, color:isActive?c.accent:c.text3, cursor:"pointer", fontFamily:c.sans, fontSize:11, fontWeight:700 }}>{m===0?"Floor":`${m}%`}</button>;
                })}
              </div>
              <div style={{ display:"flex", alignItems:"center", justifyContent:"space-between", background:c.accentL, border:`1px solid rgba(13,110,110,.2)`, borderRadius:8, padding:"8px 12px" }}>
                <span style={{ fontSize:11, color:c.accent, fontWeight:600 }}>Active Redline</span>
                <span style={{ fontFamily:c.mono, fontSize:16, fontWeight:800, color:c.accent }}>{fmtPPW(redlinePPW)}</span>
              </div>
            </div>
          </div>

          {/* Top Options */}
          <div style={card}>
            <div style={{ fontSize:10, fontWeight:700, letterSpacing:".15em", textTransform:"uppercase", color:c.accent, marginBottom:14 }}>Top Options</div>
            {/* Best Commission */}
            <div style={{ background:bestComm?c.successL:c.surface2, border:`1.5px solid ${bestComm?"rgba(22,101,52,.3)":c.border}`, borderRadius:10, padding:12, marginBottom:10 }}>
              <div style={{ display:"flex", justifyContent:"space-between", alignItems:"center", marginBottom:8 }}>
                <div style={{ fontSize:11, fontWeight:700, color:c.success }}>? Best Commission</div>
                {bestComm && <span style={{ fontSize:10, fontWeight:700, background:c.success, color:"#fff", borderRadius:20, padding:"2px 8px" }}>{bestComm.lender} ? {bestComm.esc}</span>}
              </div>
              {bestComm ? (
                <div style={{ display:"grid", gridTemplateColumns:"1fr 1fr 1fr", gap:8 }}>
                  {[["Commission",fmt(bestComm.commission)],["EPC",fmtPPW(bestComm.epc)],["HO Monthly",`$${Math.round(bestComm.monthly)}/mo`]].map(([l,v])=>(
                    <div key={l}><div style={{ fontSize:9, color:c.text3, textTransform:"uppercase", letterSpacing:".04em", marginBottom:2 }}>{l}</div><div style={{ fontSize:13, fontWeight:800, color:c.success, fontFamily:c.mono }}>{v}</div></div>
                  ))}
                </div>
              ) : <div style={{ fontSize:12, color:c.text3 }}>No viable options at current sell rates.</div>}
            </div>
            {/* Lowest HO Payment */}
            <div style={{ background:lowestPmt?c.blueL:c.surface2, border:`1.5px solid ${lowestPmt?"rgba(26,95,180,.25)":c.border}`, borderRadius:10, padding:12 }}>
              <div style={{ display:"flex", justifyContent:"space-between", alignItems:"center", marginBottom:8 }}>
                <div style={{ fontSize:11, fontWeight:700, color:c.blue }}>? Lowest HO Payment</div>
                {lowestPmt && <span style={{ fontSize:10, fontWeight:700, background:c.blue, color:"#fff", borderRadius:20, padding:"2px 8px" }}>{lowestPmt.lender} ? {lowestPmt.esc}</span>}
              </div>
              {lowestPmt ? (
                <div style={{ display:"grid", gridTemplateColumns:"1fr 1fr 1fr", gap:8 }}>
                  {[["Monthly",`$${Math.round(lowestPmt.monthly)}/mo`],["Solar Rate",`$${lowestPmt.rate.toFixed(3)}/kWh`],["Escalator",lowestPmt.esc]].map(([l,v])=>(
                    <div key={l}><div style={{ fontSize:9, color:c.text3, textTransform:"uppercase", letterSpacing:".04em", marginBottom:2 }}>{l}</div><div style={{ fontSize:13, fontWeight:800, color:c.blue, fontFamily:c.mono }}>{v}</div></div>
                  ))}
                </div>
              ) : <div style={{ fontSize:12, color:c.text3 }}>No viable options.</div>}
            </div>
          </div>
        </div>

        {/* ?? RIGHT COLUMN ?? */}
        <div>
          {showOptionPicker ? (
            /* ?? OPTION PICKER ?? */
            <div>
              <div style={{ display:"flex", alignItems:"center", justifyContent:"space-between", marginBottom:14 }}>
                <div>
                  <div style={{ fontSize:10, fontWeight:700, letterSpacing:".15em", textTransform:"uppercase", color:c.accent }}>03 ? Select Your Options</div>
                  <div style={{ fontSize:11, color:c.text3, marginTop:3 }}>
                    {soldPPW > 0 ? `Target: ${fmtPPW(soldPPW)} ? Pick one or more options to run in the waterfall` : "Enter a Gross EPC Sold in Section 09 first"}
                  </div>
                </div>
                {Object.keys(selectedOptions).length > 0 && (
                  <button onClick={() => { setShowOptionPicker(false); setWaterfallLender(Object.keys(selectedOptions)[0]); }} style={{ padding:"9px 20px", background:c.accent, color:"#fff", border:"none", borderRadius:9, fontFamily:c.sans, fontSize:13, fontWeight:700, cursor:"pointer" }}>
                    Run with {Object.keys(selectedOptions).length} selected ?
                  </button>
                )}
              </div>

              {soldPPW <= 0 ? (
                <div style={{ ...card, textAlign:"center", color:c.text3, fontSize:13, padding:32 }}>Enter a Gross EPC Sold in Section 09 to see lender options.</div>
              ) : (
                activeLenders.filter(l => l !== "Cash").map(lenderKey => {
                  const meta  = LENDER_META_COMM[lenderKey] || {};
                  const kw    = W / 1000;
                  const closestMatch = commSolveForTarget(lenderKey, st, util, dcOn, ecOn, kw, soldPPW);
                  const bestSpread   = commSolveForBestSpread(lenderKey, st, util, dcOn, ecOn, kw, soldPPW);
                  const lowestMo     = commSolveForLowestMonthly(lenderKey, st, util, dcOn, ecOn, kw, soldPPW);
                  const options     = [
                    closestMatch ? { type:"closestMatch", label:"? Closest Match",     color:c.purple || "#7c3aed", colorL:c.purpleL || "#ede9fe", data:closestMatch } : null,
                    bestSpread   ? { type:"bestComm",     label:"? Best Commission",   color:c.success,             colorL:c.successL,             data:bestSpread   } : null,
                    lowestMo     ? { type:"lowestPmt",    label:"? Lowest HO Payment", color:c.blue,                colorL:c.blueL,                data:lowestMo     } : null,
                  ].filter(Boolean);

                  if (!options.length) return null;

                  return (
                    <div key={lenderKey} style={{ ...card, marginBottom:14 }}>
                      <div style={{ display:"flex", alignItems:"center", gap:8, marginBottom:12 }}>
                        <div style={{ width:9, height:9, borderRadius:"50%", background:meta.dot||c.text3, flexShrink:0 }} />
                        <span style={{ fontWeight:800, fontSize:15 }}>{lenderKey === "IGS_TX" ? "IGS (Draft ? TX)" : lenderKey}</span>
                        <span style={{ fontSize:10, color:c.text3, background:c.surface3, padding:"2px 7px", borderRadius:10 }}>{meta.product}</span>
                        {meta.isDraft && <span style={{ fontSize:9, color:"#6b7280", background:"#f3f4f6", padding:"2px 7px", borderRadius:10, fontWeight:700 }}>DRAFT</span>}
                      </div>

                      <div style={{ display:"grid", gridTemplateColumns:"1fr 1fr 1fr", gap:8 }}>
                        {options.map(opt => {
                          const epc        = opt.data.epc;
                          const commission = Math.max(0, epc * W - redlineVal - adderList);
                          const spread     = epc - redlinePPW;
                          const selKey     = `${lenderKey}_${opt.type}`;
                          const isSelected = selectedOptions[selKey];

                          return (
                            <div key={opt.type}
                              onClick={() => {
                                setSelectedOptions(prev => {
                                  const next = { ...prev };
                                  if (isSelected) {
                                    delete next[selKey];
                                  } else {
                                    // Deselect other option from same lender
                                    const otherKey = `${lenderKey}_${opt.type === "bestComm" ? "lowestPmt" : "bestComm"}`;
                                    delete next[otherKey];
                                    next[selKey] = { lender:lenderKey, type:opt.type, ...opt.data, commission };
                                    // Update linputs so waterfall will use this combo
                                    setLinputs(p => ({ ...p, [lenderKey]: { escalator:opt.data.escalator, sellRate:opt.data.sellRate, yield:opt.data.yield } }));
                                  }
                                  return next;
                                });
                              }}
                              style={{ borderRadius:10, border:`2px solid ${isSelected ? opt.color : c.border}`, background:isSelected ? opt.colorL : c.surface, cursor:"pointer", padding:14, transition:".12s", position:"relative" }}>
                              {isSelected && <div style={{ position:"absolute", top:8, right:10, fontSize:9, fontWeight:700, color:opt.color }}>? Selected</div>}
                              <div style={{ fontSize:11, fontWeight:700, color:isSelected?opt.color:c.text2, marginBottom:10 }}>{opt.label}</div>
                              <div style={{ display:"grid", gridTemplateColumns:"1fr 1fr", gap:6, marginBottom:8 }}>
                                {[
                                  { l:"Est. EPC",    v:fmtPPW(epc) },
                                  { l:"HO Monthly",  v:`$${Math.round(opt.data.monthly)}/mo` },
                                  { l:"Sales Spread",v:fmt(commission) },
                                  { l:"Rate",        v:`$${opt.data.sellRate.toFixed(3)}/kWh` },
                                ].map((m,i) => (
                                  <div key={i}>
                                    <div style={{ fontSize:9, color:c.text3, fontWeight:700, textTransform:"uppercase", letterSpacing:".04em", marginBottom:2 }}>{m.l}</div>
                                    <div style={{ fontSize:12, fontWeight:700, color:isSelected?opt.color:c.text, fontFamily:c.mono }}>{m.v}</div>
                                  </div>
                                ))}
                              </div>
                              <div style={{ fontSize:10, color:c.text3, fontFamily:c.mono }}>{opt.data.escalator} ? {opt.data.yield} kWh/kW</div>
                              <div style={{ marginTop:8, height:4, background:c.surface3, borderRadius:3, overflow:"hidden" }}>
                                <div style={{ height:"100%", borderRadius:3, background:spread>=0?opt.color:c.danger, width:`${Math.min(100,Math.max(2,(epc/(redlinePPW*1.5))*100))}%` }} />
                              </div>
                              <div style={{ fontSize:10, color:spread>=0?opt.color:c.danger, fontFamily:c.mono, marginTop:3, fontWeight:600 }}>
                                {spread>=0?"+":""}{spread.toFixed(3)}/W spread
                              </div>
                            </div>
                          );
                        })}
                      </div>
                    </div>
                  );
                })
              )}
            </div>
          ) : (
            /* ?? WATERFALL VIEW ?? */
            <div>
              {/* Selected options toggle + back button */}
              <div style={{ ...card, marginBottom:14 }}>
                <div style={{ display:"flex", alignItems:"center", justifyContent:"space-between", marginBottom:10 }}>
                  <div style={{ fontSize:10, fontWeight:700, letterSpacing:".15em", textTransform:"uppercase", color:c.accent }}>Selected Options</div>
                  <button onClick={() => { setShowOptionPicker(true); }} style={{ fontSize:11, color:c.accent, background:c.accentL, border:`1px solid rgba(13,110,110,.2)`, borderRadius:7, padding:"4px 12px", cursor:"pointer", fontWeight:700, fontFamily:c.sans }}>? Change Selections</button>
                </div>
                <div style={{ display:"flex", gap:8, flexWrap:"wrap" }}>
                  {Object.entries(selectedOptions).map(([selKey, opt]) => {
                    const isActive = waterfallLender === selKey;
                    const meta     = LENDER_META_COMM[opt.lender] || {};
                    const typeIcon = opt.type === "bestComm" ? "?" : opt.type === "closestMatch" ? "?" : "?";
                    return (
                      <button key={selKey} onClick={() => { setWaterfallLender(selKey); setLinputs(p => ({ ...p, [opt.lender]:{ escalator:opt.escalator, sellRate:opt.sellRate, yield:opt.yield } })); }}
                        style={{ display:"flex", alignItems:"center", gap:7, padding:"7px 13px", borderRadius:9, border:`2px solid ${isActive?(meta.dot||c.accent):c.border}`, background:isActive?"#fff":c.surface2, cursor:"pointer", fontFamily:c.sans, transition:".1s" }}>
                        <div style={{ width:8, height:8, borderRadius:"50%", background:meta.dot||c.text3 }} />
                        <span style={{ fontSize:12, fontWeight:isActive?800:600, color:isActive?(meta.dot||c.accent):c.text2 }}>
                          {opt.lender === "IGS_TX" ? "IGS TX" : opt.lender}
                        </span>
                        <span style={{ fontSize:10, color:c.text3 }}>{typeIcon} {opt.escalator}</span>
                        <span style={{ fontSize:11, fontFamily:c.mono, fontWeight:700, color:isActive?(meta.dot||c.accent):c.text3 }}>{fmtPPW(opt.epc)}</span>
                        {isActive && <span style={{ fontSize:9, background:c.success, color:"#fff", borderRadius:10, padding:"1px 6px", fontWeight:700 }}>ACTIVE</span>}
                      </button>
                    );
                  })}
                </div>

                {/* Manual steppers for active lender */}
                {wfLenderKey && (() => {
                  const activeLc = lCalcs.find(l => l.lender === wfLenderKey);
                  if (!activeLc || activeLc.lender === "Cash") return null;
                  const meta    = LENDER_META_COMM[wfLenderKey] || {};
                  const escs    = meta.escalators?.[st] || [];
                  const curEsc  = getLI(wfLenderKey, "escalator");
                  const [rMin, rMax] = commGetRateRange(wfLenderKey, st, util, curEsc);
                  const curRate = Number(getLI(wfLenderKey, "sellRate"));
                  const yRange  = COMM_YIELD_RANGES[wfLenderKey]?.[st] || [900, 1200];
                  const curYld  = Number(getLI(wfLenderKey, "yield")) || Math.round((yRange[0]+yRange[1])/2/100)*100;
                  const stepRate = dir => { const next = Math.round((curRate + dir * COMM_RATE_STEP) * 1000) / 1000; setLI(wfLenderKey, "sellRate", Math.min(rMax, Math.max(rMin, next))); };
                  const stepYld  = dir => setLI(wfLenderKey, "yield", Math.min(yRange[1], Math.max(yRange[0], curYld + dir * 100)));
                  const btnSm = (disabled) => ({ width:26, height:28, borderRadius:6, border:`1.5px solid ${c.border2}`, background:disabled?c.surface3:c.surface2, color:disabled?c.text3:c.text, fontSize:14, fontWeight:700, cursor:disabled?"default":"pointer", flexShrink:0 });
                  return (
                    <div style={{ marginTop:12, paddingTop:10, borderTop:`1px solid ${c.border}`, display:"grid", gridTemplateColumns:"1fr 1fr 1fr", gap:8 }}>
                      {escs.length > 0 && (
                        <div>
                          <div style={{ fontSize:9, color:c.text3, fontWeight:700, textTransform:"uppercase", letterSpacing:".04em", marginBottom:4 }}>Escalator</div>
                          <select style={{ background:c.surface2, border:`1.5px solid ${c.border}`, color:c.text, padding:"5px 8px", borderRadius:7, width:"100%", fontFamily:c.sans, fontSize:11, outline:"none" }} value={curEsc} onChange={e => { setLI(wfLenderKey,"escalator",e.target.value); const [,nm]=commGetRateRange(wfLenderKey,st,util,e.target.value); if(curRate>nm)setLI(wfLenderKey,"sellRate",nm); }}>
                            {escs.map(e => <option key={e}>{e}</option>)}
                          </select>
                        </div>
                      )}
                      <div>
                        <div style={{ fontSize:9, color:c.text3, fontWeight:700, textTransform:"uppercase", letterSpacing:".04em", marginBottom:4 }}>Rate ? {rMin.toFixed(3)}?{rMax.toFixed(3)}</div>
                        <div style={{ display:"flex", alignItems:"center", gap:3 }}>
                          <button onClick={() => stepRate(-1)} disabled={curRate<=rMin} style={btnSm(curRate<=rMin)}>?</button>
                          <div style={{ flex:1, textAlign:"center", fontFamily:c.mono, fontSize:12, fontWeight:700, background:c.surface2, border:`1px solid ${c.border}`, borderRadius:6, padding:"5px 2px" }}>${curRate.toFixed(3)}</div>
                          <button onClick={() => stepRate(+1)} disabled={curRate>=rMax} style={btnSm(curRate>=rMax)}>+</button>
                        </div>
                      </div>
                      <div>
                        <div style={{ fontSize:9, color:c.text3, fontWeight:700, textTransform:"uppercase", letterSpacing:".04em", marginBottom:4 }}>Yield ? {yRange[0]}?{yRange[1]}</div>
                        <div style={{ display:"flex", alignItems:"center", gap:3 }}>
                          <button onClick={() => stepYld(-1)} disabled={curYld<=yRange[0]} style={btnSm(curYld<=yRange[0])}>?</button>
                          <div style={{ flex:1, textAlign:"center", fontFamily:c.mono, fontSize:12, fontWeight:700, background:c.surface2, border:`1px solid ${c.border}`, borderRadius:6, padding:"5px 2px" }}>{curYld}</div>
                          <button onClick={() => stepYld(+1)} disabled={curYld>=yRange[1]} style={btnSm(curYld>=yRange[1])}>+</button>
                        </div>
                      </div>
                    </div>
                  );
                })()}
              </div>

          {showInactive && (INACTIVE_LENDERS[st]||[]).map(({ lender: inL, reason, dot }) => (
            <div key={`inactive_${inL}`} style={{ ...card, opacity:.55, border:`1.5px dashed ${c.border2}`, background:c.surface2, position:"relative" }}>
              <div style={{ position:"absolute", top:10, right:14, background:c.warnL, color:c.warn, borderRadius:12, fontSize:9, fontWeight:800, padding:"2px 9px", letterSpacing:".06em" }}>Inactive</div>
              <div style={{ display:"flex", alignItems:"center", gap:8, marginBottom:6 }}>
                <div style={{ width:9, height:9, borderRadius:"50%", background:dot }} />
                <span style={{ fontWeight:700, fontSize:14 }}>{inL}</span>
              </div>
              <div style={{ fontSize:11, color:c.warn, fontStyle:"italic" }}>{reason}</div>
            </div>
          ))}

          {/* 05 ? Commission Waterfall */}
          {W > 0 && (activeWF || hasSoldRate) && (
            <div style={{ ...card, background:c.successL, border:`1.5px solid rgba(22,101,52,.25)` }}>
              <div style={{ fontSize:10, fontWeight:700, letterSpacing:".15em", textTransform:"uppercase", color:c.success, marginBottom:14 }}>05 ? Commission Waterfall</div>

              {/* Waterfall rows */}
              {[
                { l:"Contract Value",    v:fmt(wfContractVal),                                  sub:hasSoldRate ? `${fmtPPW(soldPPW)} ? ${W.toLocaleString()}W` : `${fmtPPW(activeWF?.epc||0)} ? ${W.toLocaleString()}W`, col:c.text  },
                { l:"- Company Redline", v:`(${fmt(redlineVal)})`,                              sub:`${fmtPPW(redlinePPW)} ? ${st}`,                     col:c.danger },
              ].map((r,i) => (
                <div key={i} style={{ display:"flex", justifyContent:"space-between", alignItems:"center", padding:"9px 0", borderBottom:`1px solid rgba(22,101,52,.15)` }}>
                  <span style={{ fontSize:13, color:c.text2, fontWeight:600 }}>{r.l}</span>
                  <div style={{ textAlign:"right" }}>
                    <span style={{ fontSize:14, fontWeight:700, color:r.col, fontFamily:c.mono }}>{r.v}</span>
                    <span style={{ fontSize:10, color:c.text3, marginLeft:8, fontFamily:c.mono }}>{r.sub}</span>
                  </div>
                </div>
              ))}
              <div style={{ display:"flex", justifyContent:"space-between", padding:"9px 8px", background:c.surface2, borderRadius:7, marginBottom:4 }}>
                <span style={{ fontSize:13, fontWeight:700 }}>Net After Redline</span>
                <span style={{ fontSize:14, fontWeight:800, color:c.accent, fontFamily:c.mono }}>{fmt(wfCommission)}</span>
              </div>

              <div style={{ display:"flex", justifyContent:"space-between", alignItems:"center", paddingTop:12, paddingBottom:14, borderBottom:`2px solid rgba(22,101,52,.2)`, marginBottom:14 }}>
                <div>
                  <div style={{ fontSize:14, fontWeight:800, color:c.success }}>Sales Spread</div>
                  <div style={{ fontSize:10, color:c.success, fontFamily:c.mono, opacity:.8 }}>{W>0&&wfCommission>0?`${fmtPPW(wfCommission/W)} spread`:"?"}</div>
                </div>
                <span style={{ fontSize:28, fontWeight:900, color:c.success, fontFamily:c.mono }}>{fmt(wfCommission)}</span>
              </div>

              {/* Escrow */}
              {(() => {
                const showToggle = !campaignOn && !isDealer;
                const escrowColor  = (isDealer || (campaignOn && campaignSalesPPW <= 0) || (!campaignOn && !escrowOn)) ? c.success : c.warn;
                const escrowBg     = (isDealer || (campaignOn && campaignSalesPPW <= 0) || (!campaignOn && !escrowOn)) ? c.successL : c.warnL;
                const escrowBorder = (isDealer || (campaignOn && campaignSalesPPW <= 0) || (!campaignOn && !escrowOn)) ? "rgba(22,101,52,.2)" : "rgba(180,83,9,.25)";
                return (
                  <div style={{ display:"flex", justifyContent:"space-between", alignItems:"center", padding:"9px 12px", background:escrowBg, border:`1px solid ${escrowBorder}`, borderRadius:8, marginBottom:14 }}>
                    <div>
                      <div style={{ display:"flex", alignItems:"center", gap:8 }}>
                        <span style={{ fontSize:13, fontWeight:700, color:escrowColor }}>Sales Personal Expense</span>
                        {showToggle && (
                          <button onClick={() => setEscrowOn(v => !v)} style={{ padding:"2px 9px", borderRadius:12, border:`1px solid ${escrowOn?"rgba(180,83,9,.35)":"rgba(22,101,52,.3)"}`, background:escrowOn?c.warnL:c.successL, color:escrowOn?c.warn:c.success, fontFamily:c.sans, fontSize:10, fontWeight:700, cursor:"pointer" }}>
                            {escrowOn ? "? 10% ON" : "? OFF"}
                          </button>
                        )}
                      </div>
                      <div style={{ fontSize:10, color:escrowColor, opacity:.8, marginTop:2 }}>{escrowLabel}</div>
                    </div>
                    <span style={{ fontSize:16, fontWeight:800, color:escrowColor, fontFamily:c.mono }}>{escrowAmt > 0 ? `(${fmt(escrowAmt)})` : "$0"}</span>
                  </div>
                );
              })()}

              {/* Commission Pool */}
              <div style={{ display:"flex", justifyContent:"space-between", alignItems:"center", marginBottom:14 }}>
                <div>
                  <div style={{ fontSize:13, fontWeight:800, color:c.accent }}>Commission Pool</div>
                  <div style={{ fontSize:10, color:c.accent, fontFamily:c.mono, opacity:.75 }}>{W>0&&commPool>0?fmtPPW(commPool/W):"?"}</div>
                </div>
                <span style={{ fontSize:20, fontWeight:900, color:c.accent, fontFamily:c.mono }}>{fmt(commPool)}</span>
              </div>

              {/* Split builder */}
              <div style={{ fontSize:10, fontWeight:700, letterSpacing:".12em", textTransform:"uppercase", color:c.accent, marginBottom:10 }}>Commission Pool</div>
              <div style={{ display:"grid", gridTemplateColumns:"110px 1fr auto 90px 28px", gap:6, marginBottom:6 }}>
                {["Role","Label","Split","Amount",""].map((h,i) => <div key={i} style={{ fontSize:9, fontWeight:700, color:c.text3, textTransform:"uppercase", letterSpacing:".04em", textAlign:i>=2?"right":"left" }}>{h}</div>)}
              </div>
              {splits.map(row => {
                const isPPW  = row.mode === "ppw";
                const ppwVal = parseFloat(row.ppw) || 0;
                const pct    = isPPW ? (commPool > 0 ? ppwVal * W / commPool * 100 : 0) : (parseFloat(row.pct) || 0);
                const dollar = isPPW ? ppwVal * W : commPool * pct / 100;
                const updateSplit = (f, v) => setSplits(p => p.map(r => r.id === row.id ? {...r, [f]:v} : r));
                return (
                  <div key={row.id} style={{ display:"grid", gridTemplateColumns:"110px 1fr auto 90px 28px", gap:6, alignItems:"center", marginBottom:6 }}>
                    <select style={{ background:c.surface2, border:`1.5px solid ${c.border}`, color:c.text, padding:"6px 8px", borderRadius:7, fontFamily:c.sans, fontSize:12, outline:"none" }} value={row.role} onChange={e => updateSplit("role", e.target.value)}>
                      {ROLES.map(r => <option key={r}>{r}</option>)}
                    </select>
                    {row.role === "Other"
                      ? <input style={{ background:c.surface2, border:`1.5px solid ${c.border}`, color:c.text, padding:"6px 8px", borderRadius:7, fontFamily:c.sans, fontSize:12, outline:"none" }} placeholder="Label..." value={row.custom} onChange={e => updateSplit("custom", e.target.value)} />
                      : <div style={{ fontSize:12, color:c.text3, padding:"6px 4px", overflow:"hidden", textOverflow:"ellipsis", whiteSpace:"nowrap" }}>{row.role}</div>
                    }
                    {/* Split input ? % or $/W mode */}
                    <div style={{ display:"flex", alignItems:"center", gap:3 }}>
                      {/* Mode toggle */}
                      <button onClick={() => updateSplit("mode", isPPW ? "pct" : "ppw")} style={{ padding:"2px 6px", borderRadius:10, border:`1px solid ${isPPW ? c.accent : c.border2}`, background:isPPW ? c.accentL : c.surface2, color:isPPW ? c.accent : c.text3, fontFamily:c.sans, fontSize:9, fontWeight:700, cursor:"pointer", whiteSpace:"nowrap" }}>
                        {isPPW ? "$/W" : "%"}
                      </button>
                      {isPPW ? (
                        <>
                          <button onClick={() => updateSplit("ppw", Math.max(0, Math.round((ppwVal - 0.005) * 1000) / 1000))} style={{ width:22,height:28,borderRadius:5,border:`1.5px solid ${c.border2}`,background:c.surface2,color:c.text,fontSize:13,fontWeight:700,cursor:"pointer" }}>?</button>
                          <input type="text" inputMode="decimal" value={row.ppw} onChange={e => updateSplit("ppw", e.target.value)} style={{ background:c.accentL, border:`1.5px solid ${c.accent}`, color:c.accent, padding:"4px 3px", borderRadius:6, fontFamily:c.mono, fontSize:11, fontWeight:700, textAlign:"center", width:52, outline:"none" }} />
                          <button onClick={() => updateSplit("ppw", Math.round((ppwVal + 0.005) * 1000) / 1000)} style={{ width:22,height:28,borderRadius:5,border:`1.5px solid ${c.border2}`,background:c.surface2,color:c.text,fontSize:13,fontWeight:700,cursor:"pointer" }}>+</button>
                          {/* Auto-computed % badge */}
                          <span style={{ fontSize:9, color:c.accent, fontFamily:c.mono, fontWeight:700, background:c.accentL, padding:"2px 5px", borderRadius:8, whiteSpace:"nowrap" }}>{pct.toFixed(1)}%</span>
                        </>
                      ) : (
                        <>
                          <button onClick={() => { const cur=parseFloat(row.pct)||0; if(cur>0) updateSplit("pct",Math.max(0,Math.round((cur-1)*10)/10)); }} style={{ width:24,height:32,borderRadius:6,border:`1.5px solid ${c.border2}`,background:c.surface2,color:c.text,fontSize:14,fontWeight:700,cursor:"pointer" }}>?</button>
                          <input type="number" min="0" max="100" step="1" value={row.pct} onChange={e => updateSplit("pct",e.target.value)} style={{ background:c.surface2, border:`1.5px solid ${c.border}`, color:c.text, padding:"6px 4px", borderRadius:7, fontFamily:c.mono, fontSize:12, fontWeight:700, textAlign:"center", width:46, outline:"none" }} />
                          <button onClick={() => updateSplit("pct",Math.min(100,Math.round(((parseFloat(row.pct)||0)+1)*10)/10))} style={{ width:24,height:32,borderRadius:6,border:`1.5px solid ${c.border2}`,background:c.surface2,color:c.text,fontSize:14,fontWeight:700,cursor:"pointer" }}>+</button>
                        </>
                      )}
                    </div>
                    <div style={{ fontSize:13, fontWeight:700, color:dollar>0?c.success:c.text3, fontFamily:c.mono, textAlign:"right" }}>{dollar>0?fmt(dollar):"?"}</div>
                    <button onClick={() => setSplits(p => p.filter(r => r.id !== row.id))} style={{ width:24,height:24,borderRadius:6,border:`1px solid ${c.border2}`,background:c.surface2,color:c.text3,fontSize:12,fontWeight:700,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center" }}>?</button>
                  </div>
                );
              })}
              <button onClick={() => setSplits(p => [...p, { id:nextId(), role:"Closer", custom:"", pct:"", mode:"pct", ppw:"0.010" }])} style={{ marginTop:8, background:"transparent", border:`1.5px dashed ${c.border2}`, borderRadius:8, padding:"7px 14px", width:"100%", color:c.text3, fontFamily:c.sans, fontSize:12, fontWeight:600, cursor:"pointer" }}>+ Add Participant</button>
              <div style={{ display:"flex", justifyContent:"space-between", alignItems:"center", marginTop:10, padding:"8px 12px", background:c.surface, border:`1.5px solid ${pctColor}44`, borderRadius:8 }}>
                <span style={{ fontSize:11, fontWeight:600, color:c.text2 }}>Total Allocated</span>
                <div style={{ display:"flex", alignItems:"center", gap:10 }}>
                  <div style={{ width:80, height:5, background:c.surface3, borderRadius:3, overflow:"hidden" }}>
                    <div style={{ height:"100%", borderRadius:3, background:pctColor, width:`${Math.min(100,totalPct)}%`, transition:".2s" }} />
                  </div>
                  <span style={{ fontSize:13, fontWeight:800, color:pctColor, fontFamily:c.mono }}>{totalPct.toFixed(1)}%</span>
                  {pctExact && <span style={{ fontSize:10, color:c.success, fontWeight:700 }}>OK</span>}
                  {pctOver  && <span style={{ fontSize:10, color:c.danger, fontWeight:700 }}>OVER</span>}
                </div>
              </div>
            </div>
          )}
            </div>
          )}
        </div>
      </div>
    </div>
  );
}

// ??? DEALER / PARTNER TAB ????????????????????????????????????????????????????

function DealerTab({ c, card, lbl, fmt, fmtPPW, C, st, lender, laborMode }) {
  const [dealerName, setDealerName]         = useState("");
  const [dealerModel, setDealerModel]       = useState(1);
  const [dealerTargetM, setDealerTargetM]   = useState(20);
  const [dealerCustomMStr, setDealerCustomMStr] = useState("");
  const [showRateSheet, setShowRateSheet]     = useState(false);
  const [m2RateStr, setM2RateStr]             = useState("0.950");
  const [showM2RateSheet, setShowM2RateSheet] = useState(false);
  const [m3RateStr, setM3RateStr]             = useState("0.750");
  const [showM3RateSheet, setShowM3RateSheet] = useState(false);

  const dealerEffM = useMemo(() => {
    if (dealerCustomMStr === "") return dealerTargetM;
    const n = parseFloat(dealerCustomMStr);
    return isNaN(n) ? dealerTargetM : Math.min(60, Math.max(0, n));
  }, [dealerTargetM, dealerCustomMStr]);

  const W = C?.W || 13120;
  const dealerRedline$ = C ? rl(C.baseAllinNoAdders, dealerEffM) : null;
  const dealerRedlinePPW = dealerRedline$ ? dealerRedline$ / W : null;
  const today = new Date().toLocaleDateString("en-US", { month: "long", day: "numeric", year: "numeric" });

  const seg_s = { display: "flex", gap: 3, background: c.surface3, border: `1.5px solid ${c.border}`, borderRadius: 9, padding: 3 };
  const sb = (on) => ({ flex: 1, padding: "7px 4px", borderRadius: 7, border: on ? `1px solid ${c.border}` : "none", background: on ? c.surface : "transparent", color: on ? c.accent : c.text3, cursor: "pointer", fontFamily: c.sans, fontSize: 12, fontWeight: on ? 700 : 600, transition: ".12s" });

  // Build adder display groups for Model 1 ? full BOM included, full list prices
  const ADDER_DISPLAY_GROUPS = ADDER_SECTIONS.map(sec => ({
    title: sec.title,
    rows: sec.keys.map(key => {
      const a = ADDER_MAP[key];
      if (!a) return null;
      let price = "?";
      if (a.isTrench)                                         price = `$500 base + $35/ft`;
      else if (a.isBoringBase)                                price = `Contractor quote + $500`;
      else if (a.isBoringMaterial)                            price = `$${a.listPFt}/ft`;
      else if (a.perW)                                        price = `$${(a.listW || a.seaW).toFixed(3)}/W`;
      else if (a.isTeslaLead || a.isTeslaPWX || a.isTeslaACLead || a.isTeslaACPWX || a.isTeslaExp)
                                                              price = a.list ? fmt(a.list) : "Dynamic";
      else if (a.list != null)                                price = fmt(a.list);
      return { label: a.label, price };
    }).filter(Boolean)
  })).filter(g => g.rows.length > 0);

  return (
    <div style={{ paddingBottom: 40 }}>

      {/* ?? PARTNER CONFIG ??????????????????????????????????????????????? */}
      <div style={card}>
        <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent, marginBottom: 14 }}>Partner Configuration</div>
        <div style={{ display: "grid", gridTemplateColumns: "1.5fr 1fr", gap: 14, marginBottom: 16 }}>
          <div>
            <div style={lbl}>Partner / Dealer Name</div>
            <input
              value={dealerName} onChange={e => setDealerName(e.target.value)}
              placeholder="e.g. Our World Energy"
              style={{ background: c.surface2, border: `1.5px solid ${c.border}`, color: c.text, padding: "8px 12px", borderRadius: 8, width: "100%", fontFamily: c.sans, fontSize: 13, fontWeight: 500, outline: "none", boxSizing: "border-box" }}
            />
          </div>
          <div>
            <div style={lbl}>Reference ? Tab 1 Config</div>
            <div style={{ background: c.surface2, border: `1.5px solid ${c.border}`, borderRadius: 8, padding: "8px 12px", fontSize: 12, color: c.text2 }}>
              {st} ? {lender} ? {C ? `${(C.W / 1000).toFixed(2)} kW` : "?"} ? {laborMode === "sub" ? "Sub (SEA)" : "Internal"}
            </div>
          </div>
        </div>

        <div style={lbl}>Dealer Model</div>
        <div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
          {[
            { n: 1, label: "Model 1 ? Redline",        sub: "eEquals supplies BOM",           available: true  },
            { n: 2, label: "Model 2 ? Install + Admin", sub: "Dealer supplies BOM",            available: true  },
            { n: 3, label: "Model 3 ? Install Only",    sub: "Dealer manages upstream",        available: true  },
            { n: 4, label: "Model 4 ? ? La Carte",      sub: "OWE / partner-style line items", available: false },
          ].map(m => (
            <button key={m.n} onClick={() => m.available && setDealerModel(m.n)}
              style={{ padding: "10px 16px", borderRadius: 9, textAlign: "left", cursor: m.available ? "pointer" : "not-allowed", border: `1.5px solid ${dealerModel === m.n ? "rgba(13,110,110,.4)" : c.border}`, background: dealerModel === m.n ? c.accentL : m.available ? c.surface2 : c.surface3, opacity: m.available ? 1 : 0.45, fontFamily: c.sans }}>
              <div style={{ fontSize: 12, fontWeight: 700, color: dealerModel === m.n ? c.accent : c.text }}>{m.label}</div>
              <div style={{ fontSize: 10, color: c.text3, marginTop: 2 }}>{m.sub}{!m.available ? " ? coming soon" : ""}</div>
            </button>
          ))}
        </div>
      </div>

      {/* ?? MODEL 1: REDLINE RATE CONFIG ????????????????????????????????? */}
      {dealerModel === 1 && (
        <>
          <div style={card}>
            <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent, marginBottom: 14 }}>Model 1 ? Dealer Redline Rate</div>

            {!C ? (
              <div style={{ background: c.warnL, border: `1.5px solid rgba(180,83,9,.2)`, borderRadius: 8, padding: "10px 14px", fontSize: 12, color: c.warn }}>
                ? Configure a job in the Pricing Calculator tab first ? the dealer redline is derived from your active cost floor.
              </div>
            ) : (
              <>
                {/* Margin selector */}
                <div style={{ marginBottom: 16 }}>
                  <div style={lbl}>Target Gross Margin</div>
                  <div style={{ display: "flex", gap: 6, flexWrap: "wrap", alignItems: "center" }}>
                    {MARGIN_PRESETS.map(m => {
                      const isActive = dealerEffM === m && dealerCustomMStr === "";
                      const isZero = m === 0;
                      return <button key={m} onClick={() => { setDealerTargetM(m); setDealerCustomMStr(""); }}
                        style={{ padding: "5px 13px", borderRadius: 20, border: `1.5px solid ${isActive ? (isZero ? "rgba(109,40,217,.3)" : "rgba(13,110,110,.4)") : c.border}`, background: isActive ? (isZero ? c.purpleL : c.accentL) : c.surface2, color: isActive ? (isZero ? c.purple : c.accent) : c.text3, cursor: "pointer", fontFamily: c.sans, fontSize: 12, fontWeight: 700 }}>
                        {m === 0 ? "Cost Floor" : `${m}%`}
                      </button>;
                    })}
                    <div style={{ display: "flex", alignItems: "center", gap: 6 }}>
                      <span style={{ fontSize: 10, color: c.text3, fontWeight: 700, textTransform: "uppercase", letterSpacing: ".05em" }}>Custom:</span>
                      <input type="number" min={0} max={60} step={0.5} value={dealerCustomMStr} onChange={e => setDealerCustomMStr(e.target.value)} placeholder="%" style={{ width: 60, fontFamily: c.sans, fontSize: 12, fontWeight: 600, padding: "5px 8px", border: `1.5px solid ${c.border}`, borderRadius: 8, background: c.surface2, color: c.text, outline: "none", textAlign: "center" }} />
                      {dealerCustomMStr && <button onClick={() => setDealerCustomMStr("")} style={{ fontSize: 11, color: c.text3, background: "none", border: "none", cursor: "pointer" }}>?</button>}
                    </div>
                  </div>
                </div>

                {/* Redline output cards */}
                <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 10, marginBottom: 14 }}>
                  {[
                    { label: "All-In Cost Floor",  ppw: fmtPPW(C.baseAllinPPW),       sub: fmt(C.baseAllinNoAdders),  col: c.text3,   bg: c.surface2 },
                    { label: "Target Margin",      ppw: `${dealerEffM}%`,              sub: `? (1 ? ${dealerEffM}%)`,  col: c.text2,   bg: c.surface2 },
                    { label: "Dealer Redline",     ppw: fmtPPW(dealerRedlinePPW),      sub: fmt(dealerRedline$),       col: c.accent,  bg: c.accentL  },
                  ].map(item => (
                    <div key={item.label} style={{ background: item.bg, border: `1.5px solid ${item.col === c.accent ? "rgba(13,110,110,.25)" : c.border}`, borderRadius: 10, padding: "14px 16px" }}>
                      <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".1em", textTransform: "uppercase", color: item.col, marginBottom: 5 }}>{item.label}</div>
                      <div style={{ fontSize: 22, fontWeight: 800, fontFamily: "'IBM Plex Mono',monospace", color: item.col, lineHeight: 1, marginBottom: 3 }}>{item.ppw}</div>
                      <div style={{ fontSize: 11, color: c.text3 }}>{item.sub}</div>
                    </div>
                  ))}
                </div>

                <div style={{ background: c.surface2, border: `1px solid ${c.border}`, borderRadius: 8, padding: "10px 14px", fontSize: 11, color: c.text2, lineHeight: 1.7 }}>
                  <strong style={{ color: c.text }}>What the dealer receives:</strong> A flat EPC redline of{" "}
                  <strong style={{ fontFamily: "'IBM Plex Mono',monospace", color: c.accent }}>{fmtPPW(dealerRedlinePPW)}</strong> ? inclusive of all panels, inverters, racking, labor, permitting, design, and overhead. The dealer earns the spread between their sold EPC and this rate. Adder revenues are additional per the schedule below.
                </div>
              </>
            )}
          </div>

          {/* ?? ADDER SCHEDULE ??????????????????????????????????????????? */}
          <div style={card}>
            <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 14 }}>
              <div>
                <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent }}>Adder Schedule ? Model 1</div>
                <div style={{ fontSize: 11, color: c.text3, marginTop: 3 }}>All equipment and materials included</div>
              </div>
              <span style={{ fontSize: 9, fontWeight: 700, padding: "3px 10px", borderRadius: 20, background: c.successL, color: c.success, border: "1px solid rgba(22,101,52,.2)" }}>BOM INCLUDED</span>
            </div>
            {ADDER_DISPLAY_GROUPS.map(group => (
              <div key={group.title} style={{ marginBottom: 12 }}>
                <div style={{ fontSize: 9, fontWeight: 700, letterSpacing: ".12em", textTransform: "uppercase", color: c.text3, padding: "4px 0", borderBottom: `2px solid ${c.border}`, marginBottom: 5 }}>{group.title}</div>
                {group.rows.map((row, i) => (
                  <div key={i} style={{ display: "flex", justifyContent: "space-between", alignItems: "center", padding: "5px 0", borderBottom: `1px solid ${c.surface3}`, fontSize: 12 }}>
                    <span style={{ color: c.text2 }}>{row.label}</span>
                    <span style={{ fontFamily: "'IBM Plex Mono',monospace", fontSize: 12, fontWeight: 600, color: c.text }}>{row.price}</span>
                  </div>
                ))}
              </div>
            ))}
          </div>

          {/* ?? RATE SHEET GENERATOR ????????????????????????????????????? */}
          <div style={{ display: "flex", justifyContent: "center", marginBottom: dealerRedlinePPW ? 20 : 0 }}>
            <button onClick={() => setShowRateSheet(v => !v)} disabled={!dealerRedlinePPW}
              style={{ padding: "12px 32px", background: dealerRedlinePPW ? c.accent : c.surface3, color: dealerRedlinePPW ? "#fff" : c.text3, border: "none", borderRadius: 10, fontSize: 14, fontWeight: 700, cursor: dealerRedlinePPW ? "pointer" : "not-allowed", fontFamily: c.sans, letterSpacing: ".04em" }}>
              {showRateSheet ? "? Collapse Rate Sheet" : "? Generate Rate Sheet"}
            </button>
          </div>

          {showRateSheet && dealerRedlinePPW && C && (
            <div style={{ background: "#fff", border: `2px solid ${c.border}`, borderRadius: 14, overflow: "hidden", boxShadow: "0 4px 24px rgba(0,0,0,.1)", marginBottom: 20 }}>

              {/* Header */}
              <div style={{ background: "#0d6e6e", padding: "24px 32px", display: "flex", justifyContent: "space-between", alignItems: "flex-end" }}>
                <div>
                  <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".2em", textTransform: "uppercase", color: "rgba(255,255,255,.65)", marginBottom: 5 }}>eEquals Solar ? Dealer Rate Sheet</div>
                  <div style={{ fontSize: 24, fontWeight: 800, color: "#fff", marginBottom: 2 }}>{dealerName || "[ Partner Name ]"}</div>
                  <div style={{ fontSize: 12, color: "rgba(255,255,255,.65)" }}>{st} ? {lender} ? Model 1 ? Redline (eEquals supplies BOM)</div>
                </div>
                <div style={{ textAlign: "right" }}>
                  <div style={{ fontSize: 10, color: "rgba(255,255,255,.5)", marginBottom: 2 }}>Issued</div>
                  <div style={{ fontSize: 13, fontWeight: 600, color: "#fff" }}>{today}</div>
                </div>
              </div>

              <div style={{ padding: "28px 32px" }}>

                {/* Base Redline */}
                <div style={{ marginBottom: 28, paddingBottom: 24, borderBottom: "2px solid #edf0f5" }}>
                  <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".15em", textTransform: "uppercase", color: "#8a96aa", marginBottom: 10 }}>Base EPC Redline</div>
                  <div style={{ display: "flex", alignItems: "baseline", gap: 10, marginBottom: 10 }}>
                    <div style={{ fontSize: 52, fontWeight: 900, fontFamily: "'IBM Plex Mono',monospace", color: "#0d6e6e", lineHeight: 1 }}>{fmtPPW(dealerRedlinePPW)}</div>
                  </div>
                  <div style={{ fontSize: 12, color: "#4a5878", lineHeight: 1.7, maxWidth: 560 }}>
                    Flat EPC rate charged by eEquals per watt DC installed. Inclusive of all panels, inverters, racking, balance of systems, labor, permitting, structural and electrical design, and overhead. Dealer retains the spread between the homeowner's sold EPC rate and this redline.
                  </div>
                  <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 10, marginTop: 14 }}>
                    {[
                      ["Reference System",    `${(C.W/1000).toFixed(2)} kW DC ? ${C.pCnt} panels`],
                      ["Target Gross Margin", `${dealerEffM}%`],
                      ["State / Lender",      `${st} ? ${lender}`],
                    ].map(([l, v]) => (
                      <div key={l} style={{ background: "#f5f7fa", borderRadius: 8, padding: "10px 14px" }}>
                        <div style={{ fontSize: 10, color: "#8a96aa", fontWeight: 700, textTransform: "uppercase", letterSpacing: ".08em", marginBottom: 3 }}>{l}</div>
                        <div style={{ fontSize: 13, fontWeight: 700, color: "#1a2640" }}>{v}</div>
                      </div>
                    ))}
                  </div>
                </div>

                {/* Adder Schedule */}
                <div style={{ marginBottom: 24 }}>
                  <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 14 }}>
                    <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".15em", textTransform: "uppercase", color: "#8a96aa" }}>Adder Schedule</div>
                    <span style={{ fontSize: 9, fontWeight: 700, padding: "3px 10px", borderRadius: 20, background: "#dcfce7", color: "#166534", border: "1px solid rgba(22,101,52,.2)" }}>ALL MATERIALS INCLUDED</span>
                  </div>
                  {ADDER_DISPLAY_GROUPS.map(group => (
                    <div key={group.title} style={{ marginBottom: 16 }}>
                      <div style={{ fontSize: 9, fontWeight: 700, letterSpacing: ".12em", textTransform: "uppercase", color: "#0d6e6e", marginBottom: 6, paddingBottom: 4, borderBottom: "1.5px solid #dde3ed" }}>{group.title}</div>
                      {group.rows.map((row, i) => (
                        <div key={i} style={{ display: "flex", justifyContent: "space-between", padding: "5px 0", borderBottom: "1px solid #f5f7fa", fontSize: 12, color: "#4a5878" }}>
                          <span>{row.label}</span>
                          <span style={{ fontFamily: "'IBM Plex Mono',monospace", fontWeight: 600, color: "#1a2640" }}>{row.price}</span>
                        </div>
                      ))}
                    </div>
                  ))}
                </div>

                {/* Terms */}
                <div style={{ marginTop: 20, paddingTop: 18, borderTop: "2px solid #edf0f5", fontSize: 11, color: "#8a96aa", lineHeight: 1.9 }}>
                  <div style={{ fontWeight: 700, color: "#4a5878", marginBottom: 4, fontSize: 12 }}>Terms & Notes</div>
                  <div>? Redline rate reflects the cost floor at the stated target margin and is based on current CED Greentech equipment pricing.</div>
                  <div>? Rates are subject to change with 30 days written notice. Jobs contracted before notice date are honored at the stated rate.</div>
                  <div>? All adder prices include full equipment, materials, and installed labor (BOM included under Model 1).</div>
                  <div>? Per-watt adders are charged at actual installed system wattage.</div>
                  <div>? Trenching and boring adders are charged at actual measured footage. Boring base charge applies in addition to per-foot material charge.</div>
                  <div>? Ground Mount available for Cash lender only. Domestic Content eligibility determined per-job based on installed equipment.</div>
                  <div>? Battery adder prices shown are for fully installed systems inclusive of all BOM, BOS, and labor.</div>
                  <div style={{ marginTop: 10, paddingTop: 10, borderTop: "1px solid #edf0f5", color: "#c0c8d4" }}>eEquals Solar ? CR Solar LLC ? Confidential ? For Dealer Use Only ? {today}</div>
                </div>
              </div>
            </div>
          )}
        </>
      )}

      {/* ?? MODEL 2: INSTALL + ADMIN FEE ????????????????????????????????? */}
      {dealerModel === 2 && (() => {
        const m2Rate      = parseFloat(m2RateStr) || 0;
        const laborPPW    = C?.baseLaborPPW        || 0;
        const gaPPW_v     = C ? C.gaCost          / C.W : 0;
        const sopsPPW_v   = C ? C.sopsCost        / C.W : 0;
        const ancPPW_v    = C ? C.ancillaryCost   / C.W : 0;
        const m2CostFloor = laborPPW + gaPPW_v + sopsPPW_v + ancPPW_v;
        const m2Margin    = m2Rate > 0 ? ((m2Rate - m2CostFloor) / m2Rate * 100) : 0;
        const m2Col       = m2Margin < 0 ? c.danger : m2Margin < 10 ? c.warn : c.success;

        const M2_GROUPS = [
          { title: "Electrical Adders", rows: [
            { label: "Main Panel Replacement",              cost: "$3,200",        unit: "1 Time Charge" },
            { label: "Main Meter Upgrade",                  cost: "$2,700",        unit: "1 Time Charge" },
            { label: "Main Breaker Enclosure",              cost: "$2,050",        unit: "1 Time Charge" },
            { label: "Sub Panel",                           cost: "$1,150",        unit: "1 Time Charge" },
            { label: "Main Breaker Derate/Replacement",     cost: "$600",          unit: "1 Time Charge" },
            { label: "Meter Main Combo",                    cost: "$4,250",        unit: "1 Time Charge" },
            { label: "Tap Box",                             cost: "$500",          unit: "1 Time Charge" },
            { label: "Electrical Stamps Adder",             cost: "$75",           unit: "1 Time Charge" },
            { label: "Ground Rods",                         cost: "$275",          unit: "1 Time Charge" },
          ]},
          { title: "Roof and Ground Mount Adders", rows: [
            { label: "Steep Roof (>35?)",                   cost: "$0.060",        unit: "Per Watt" },
            { label: "High Roof (3 stories or more)",       cost: "$0.060",        unit: "Per Watt" },
            { label: "Metal Roof",                          cost: "$0.070",        unit: "Per Watt" },
            { label: "Trenching ($500 base charge)",        cost: "$35",           unit: "Per Foot" },
            { label: "Boring Labor",                        cost: "Quote + $250",  unit: "Per Foot" },
            { label: "Boring Material Only (0?100 ft)",     cost: "$12",           unit: "Per Foot" },
            { label: "Boring Material Only (101?200 ft)",   cost: "$11",           unit: "Per Foot" },
            { label: "Boring Material Only (201+ ft)",      cost: "$10",           unit: "Per Foot" },
            { label: "Multiple Array Adder",                cost: "$350",          unit: "Per Array",    note: "Starting on 4th array" },
            { label: "Drywall Adders",                      cost: "Quote",         unit: "1 Time Charge" },
            { label: "Small System Adder (12 panels or less)", cost: "$1,500",     unit: "1 Time Charge" },
          ]},
          { title: "Battery Adders ? Labor and BOS Only", bomExcluded: true, rows: [
            { label: "SolarEdge Bat10K w/ Backup",          cost: "$5,000",        unit: "1 Time Charge" },
            { label: "SolarEdge Bat10K (no backup)",        cost: "$3,000",        unit: "1 Time Charge" },
            { label: "SolarEdge Battery (Each Additional)", cost: "$1,400",        unit: "1 Time Charge" },
            { label: "Tesla Powerwall 3",                   cost: "$6,000",        unit: "1 Time Charge" },
            { label: "Tesla Powerwall 3 (Expansion Battery)", cost: "$800",        unit: "1 Time Charge" },
            { label: "Tesla Powerwall 3 (Each Additional)", cost: "$1,200",        unit: "1 Time Charge" },
            { label: "Enphase IQ 10C",                      cost: "$6,450",        unit: "1 Time Charge" },
            { label: "Enphase IQ 10C (Each Additional)",    cost: "$850",          unit: "1 Time Charge" },
            { label: "Enphase IQ 5P",                       cost: "$7,800",        unit: "1 Time Charge" },
            { label: "Enphase IQ 5P (Each Additional)",     cost: "$800",          unit: "1 Time Charge" },
            { label: "Heat and Smoke Detectors",            cost: "$450",          unit: "1 Time Charge" },
          ]},
          { title: "Miscellaneous", rows: [
            { label: "Home Repairs",                        cost: "$1,000",        unit: "1 Time Charge" },
            { label: "Cancel (Post Permit Submitted)",      cost: "$1,000",        unit: "1 Time Charge" },
            { label: "Permit (>$150)",                      cost: "Cost ? $150",   unit: "1 Time Charge" },
            { label: "Interconnection Passthrough",         cost: "NEM fees beyond $150", unit: "1 Time Charge" },
            { label: "Travel Adder (>75 Miles from Warehouse)", cost: "$500",      unit: "1 Time Charge" },
          ]},
        ];

        return (
          <>
            {/* Rate Config */}
            <div style={card}>
              <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent, marginBottom: 14 }}>Model 2 ? Install + Admin Rate</div>
              {!C ? (
                <div style={{ background: c.warnL, border: `1.5px solid rgba(180,83,9,.2)`, borderRadius: 8, padding: "10px 14px", fontSize: 12, color: c.warn }}>
                  ? Configure a job in the Pricing Calculator tab first ? overhead is derived from your active settings.
                </div>
              ) : (
                <>
                  <div style={{ background: c.surface2, border: `1.5px solid ${c.border}`, borderRadius: 8, padding: "10px 14px", fontSize: 11, color: c.text2, lineHeight: 1.7, marginBottom: 16 }}>
                    <strong style={{ color: c.text }}>Model 2:</strong> Dealer purchases all equipment (BOM). eEquals charges a flat $/W rate covering install labor and admin overhead only. Battery adder prices are labor + BOS only ? no hardware included.
                  </div>

                  {/* Base rate input */}
                  <div style={{ marginBottom: 16 }}>
                    <div style={lbl}>Base Install + Admin Rate ($/W)</div>
                    <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
                      <button onClick={() => setM2RateStr(v => (Math.max(0.50, Math.round((parseFloat(v)-0.005)*1000)/1000)).toFixed(3))} style={{ width: 28, height: 28, borderRadius: 6, border: `1.5px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 16, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>?</button>
                      <input type="number" min={0.50} max={2.00} step={0.005} value={m2RateStr}
                        onChange={e => setM2RateStr(e.target.value)}
                        style={{ width: 120, fontFamily: "'IBM Plex Mono',monospace", fontWeight: 700, fontSize: 18, padding: "9px 12px", border: `2px solid ${c.accent}`, borderRadius: 8, background: c.accentL, color: c.accent, outline: "none", textAlign: "center" }} />
                      <button onClick={() => setM2RateStr(v => (Math.min(2.00, Math.round((parseFloat(v)+0.005)*1000)/1000)).toFixed(3))} style={{ width: 28, height: 28, borderRadius: 6, border: `1.5px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 16, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>+</button>
                      {m2RateStr !== "0.950" && <button onClick={() => setM2RateStr("0.950")} style={{ fontSize: 10, color: c.text3, background: "none", border: "none", cursor: "pointer", padding: "0 4px" }}>reset</button>}
                      <span style={{ fontSize: 11, color: c.text3 }}>
                        {m2Rate > 0 ? `${C.W.toLocaleString()}W ? $${m2Rate.toFixed(3)}/W = ${fmt(m2Rate * C.W)} total base charge` : "Enter a rate"}
                      </span>
                    </div>
                  </div>

                  {/* Cost breakdown */}
                  <div style={{ display: "grid", gridTemplateColumns: "repeat(5, 1fr)", gap: 8, marginBottom: 14 }}>
                    {[
                      { label: "Install Labor",    ppw: fmtPPW(laborPPW),    col: c.warn,   bg: c.warnL    },
                      { label: "G&A",              ppw: fmtPPW(gaPPW_v),     col: c.text2,  bg: c.surface2 },
                      { label: "Sales Ops",        ppw: fmtPPW(sopsPPW_v),   col: c.text2,  bg: c.surface2 },
                      { label: "Ancillary COGS",   ppw: fmtPPW(ancPPW_v),    col: c.text2,  bg: c.surface2 },
                      { label: "Total Cost Floor", ppw: fmtPPW(m2CostFloor), col: c.text,   bg: c.surface3 },
                    ].map(item => (
                      <div key={item.label} style={{ background: item.bg, border: `1px solid ${c.border}`, borderRadius: 8, padding: "9px 10px", textAlign: "center" }}>
                        <div style={{ fontSize: 9, color: c.text3, fontWeight: 700, textTransform: "uppercase", letterSpacing: ".08em", marginBottom: 4 }}>{item.label}</div>
                        <div style={{ fontSize: 13, fontWeight: 700, fontFamily: "'IBM Plex Mono',monospace", color: item.col }}>{item.ppw}</div>
                      </div>
                    ))}
                  </div>

                  {/* Margin output */}
                  <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", background: m2Rate > 0 ? `${m2Col}12` : c.surface3, border: `1.5px solid ${m2Rate > 0 ? m2Col + "40" : c.border}`, borderRadius: 9, padding: "13px 16px" }}>
                    <div>
                      <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".1em", textTransform: "uppercase", color: m2Rate > 0 ? m2Col : c.text3, marginBottom: 3 }}>
                        {m2Rate > 0 ? (m2Margin < 0 ? "? Below Cost" : "Gross Margin on Base Rate") : "Enter a rate above"}
                      </div>
                      <div style={{ fontSize: 11, color: c.text3 }}>
                        {m2Rate > 0 ? `$${m2Rate.toFixed(3)}/W charged ? ${fmtPPW(m2CostFloor)} cost = ${fmtPPW(Math.abs(m2Rate - m2CostFloor))} ${m2Margin >= 0 ? "margin" : "shortfall"}` : "Equipment costs excluded ? dealer provides BOM"}
                      </div>
                    </div>
                    {m2Rate > 0 && <div style={{ fontFamily: "'IBM Plex Mono',monospace", fontSize: 32, fontWeight: 800, color: m2Col, lineHeight: 1 }}>{m2Margin.toFixed(1)}%</div>}
                  </div>
                </>
              )}
            </div>

            {/* Adder Schedule */}
            <div style={card}>
              <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 14 }}>
                <div>
                  <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent }}>Adder Schedule ? Model 2</div>
                  <div style={{ fontSize: 11, color: c.text3, marginTop: 3 }}>Battery adders are labor + BOS only ? hardware not included</div>
                </div>
                <span style={{ fontSize: 9, fontWeight: 700, padding: "3px 10px", borderRadius: 20, background: "#fee2e2", color: "#b91c1c", border: "1px solid rgba(185,28,28,.2)" }}>BOM EXCLUDED</span>
              </div>
              {M2_GROUPS.map(group => (
                <div key={group.title} style={{ marginBottom: 12 }}>
                  <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", padding: "4px 0", borderBottom: `2px solid ${c.border}`, marginBottom: 5 }}>
                    <div style={{ fontSize: 9, fontWeight: 700, letterSpacing: ".12em", textTransform: "uppercase", color: c.text3 }}>{group.title}</div>
                    {group.bomExcluded && <span style={{ fontSize: 8, fontWeight: 700, color: "#b91c1c", background: "#fee2e2", padding: "1px 6px", borderRadius: 8 }}>LABOR + BOS ONLY</span>}
                  </div>
                  {group.rows.map((row, i) => (
                    <div key={i} style={{ display: "flex", justifyContent: "space-between", alignItems: "center", padding: "5px 0", borderBottom: `1px solid ${c.surface3}`, fontSize: 12 }}>
                      <span style={{ color: c.text2 }}>{row.label}{row.note ? <span style={{ fontSize: 10, color: c.text3, marginLeft: 6 }}>? {row.note}</span> : null}</span>
                      <div style={{ display: "flex", alignItems: "center", gap: 14 }}>
                        <span style={{ fontSize: 10, color: c.text3, minWidth: 100, textAlign: "right" }}>{row.unit}</span>
                        <span style={{ fontFamily: "'IBM Plex Mono',monospace", fontSize: 12, fontWeight: 600, color: c.text, minWidth: 120, textAlign: "right" }}>{row.cost}</span>
                      </div>
                    </div>
                  ))}
                </div>
              ))}
            </div>

            {/* Rate Sheet Generator */}
            <div style={{ display: "flex", justifyContent: "center", marginBottom: 20 }}>
              <button onClick={() => setShowM2RateSheet(v => !v)}
                style={{ padding: "12px 32px", background: c.accent, color: "#fff", border: "none", borderRadius: 10, fontSize: 14, fontWeight: 700, cursor: "pointer", fontFamily: c.sans, letterSpacing: ".04em" }}>
                {showM2RateSheet ? "? Collapse Rate Sheet" : "? Generate Rate Sheet"}
              </button>
            </div>

            {showM2RateSheet && (
              <div style={{ background: "#fff", border: `2px solid ${c.border}`, borderRadius: 14, overflow: "hidden", boxShadow: "0 4px 24px rgba(0,0,0,.1)", marginBottom: 20 }}>

                {/* Header */}
                <div style={{ background: "#0d6e6e", padding: "20px 32px", display: "flex", justifyContent: "space-between", alignItems: "center" }}>
                  <div>
                    <div style={{ fontSize: 20, fontWeight: 900, color: "#fff" }}>? eEquals</div>
                    <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".14em", textTransform: "uppercase", color: "rgba(255,255,255,.75)", marginTop: 3 }}>
                      Install w/Admin Rate Sheet ? {new Date().toLocaleDateString("en-US",{month:"long",year:"numeric"})}
                    </div>
                  </div>
                  <div style={{ textAlign: "right" }}>
                    {dealerName && <div style={{ fontSize: 14, fontWeight: 700, color: "#fff", marginBottom: 3 }}>{dealerName}</div>}
                    <div style={{ fontSize: 10, color: "rgba(255,255,255,.6)", fontStyle: "italic" }}>Internal Use Only ? Confidential & Proprietary</div>
                  </div>
                </div>

                {/* Table */}
                <div style={{ padding: "0 32px 28px" }}>
                  {/* Column headers */}
                  <div style={{ display: "grid", gridTemplateColumns: "1fr 160px 200px", padding: "10px 8px 6px", borderBottom: "2px solid #1a2640", marginTop: 20 }}>
                    {["ADDER DESCRIPTION", "COST", "UNIT OF MEASURE"].map(h => (
                      <div key={h} style={{ fontSize: 9, fontWeight: 700, letterSpacing: ".1em", color: "#1a2640" }}>{h}</div>
                    ))}
                  </div>

                  {/* Labor & Admin */}
                  <div style={{ borderBottom: "1px solid #edf0f5" }}>
                    <div style={{ fontSize: 9, fontWeight: 700, letterSpacing: ".1em", textTransform: "uppercase", color: "#8a96aa", padding: "8px 8px 4px", background: "#f5f7fa" }}>Labor & Admin</div>
                    <div style={{ display: "grid", gridTemplateColumns: "1fr 160px 200px", padding: "6px 8px 8px", background: "#fff" }}>
                      <div style={{ fontSize: 12, color: "#1a2640" }}>Base Install Labor & Admin</div>
                      <div style={{ fontSize: 12, fontWeight: 700, fontFamily: "'IBM Plex Mono',monospace", color: "#0d6e6e" }}>${m2Rate > 0 ? m2Rate.toFixed(3) : "0.950"}</div>
                      <div style={{ fontSize: 11, color: "#4a5878" }}>Per Watt ? Subject to change per dealer and/or market</div>
                    </div>
                  </div>

                  {/* Adder sections */}
                  {M2_GROUPS.map(group => (
                    <div key={group.title} style={{ borderBottom: "1px solid #edf0f5" }}>
                      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", background: "#f5f7fa", padding: "8px 8px 4px" }}>
                        <div style={{ fontSize: 9, fontWeight: 700, letterSpacing: ".1em", textTransform: "uppercase", color: "#8a96aa" }}>{group.title}</div>
                        {group.bomExcluded && <span style={{ fontSize: 8, background: "#fee2e2", color: "#b91c1c", padding: "1px 8px", borderRadius: 8, fontWeight: 700, letterSpacing: ".05em" }}>LABOR & BOS ONLY ? HARDWARE NOT INCLUDED</span>}
                      </div>
                      {group.rows.map((row, i) => (
                        <div key={i} style={{ display: "grid", gridTemplateColumns: "1fr 160px 200px", padding: "5px 8px", background: i % 2 === 0 ? "#fff" : "#fafbfc", borderBottom: "1px solid #f5f7fa" }}>
                          <div style={{ fontSize: 12, color: "#1a2640" }}>
                            {row.label}
                            {row.note ? <span style={{ fontSize: 10, color: "#8a96aa", marginLeft: 6 }}>? {row.note}</span> : null}
                          </div>
                          <div style={{ fontSize: 12, fontWeight: 600, fontFamily: "'IBM Plex Mono',monospace", color: "#1a2640" }}>{row.cost}</div>
                          <div style={{ fontSize: 11, color: "#4a5878" }}>{row.unit}</div>
                        </div>
                      ))}
                    </div>
                  ))}
                </div>

                {/* NDA Footer */}
                <div style={{ background: "#f5f7fa", borderTop: "2px solid #dde3ed", padding: "20px 32px" }}>
                  <div style={{ fontSize: 10, fontWeight: 700, color: "#1a2640", letterSpacing: ".06em", textTransform: "uppercase", marginBottom: 6 }}>Confidentiality Notice & Non-Disclosure Agreement</div>
                  <div style={{ fontSize: 9, fontWeight: 700, color: "#4a5878", textTransform: "uppercase", letterSpacing: ".05em", marginBottom: 6 }}>Proprietary and Confidential</div>
                  <div style={{ fontSize: 10, color: "#8a96aa", lineHeight: 1.8, marginBottom: 10 }}>This Dealer Adder Rate Sheet (the "Document") is the exclusive and proprietary property of eEquals Solar and contains confidential trade information, pricing structures, and dealer rate schedules that constitute valuable business and trade secrets.</div>
                  <div style={{ fontSize: 9, fontWeight: 700, color: "#4a5878", textTransform: "uppercase", letterSpacing: ".05em", marginBottom: 4 }}>By receiving this document, you agree to the following:</div>
                  <div style={{ fontSize: 10, color: "#8a96aa", lineHeight: 1.9 }}>
                    <div><strong style={{ color: "#4a5878" }}>1. Non-Disclosure:</strong> You shall not disclose, distribute, reproduce, copy, transmit, disseminate, sell, publish, broadcast, or circulate this Document, in whole or in part, to any third party without the prior written consent of eEquals Solar.</div>
                    <div><strong style={{ color: "#4a5878" }}>2. Limited Use:</strong> This Document is provided solely for the authorized business purposes of the designated dealer recipient. Any use beyond the scope of the authorized dealer relationship is strictly prohibited.</div>
                    <div><strong style={{ color: "#4a5878" }}>3. Penalties for Unauthorized Disclosure:</strong> Unauthorized disclosure or misuse of this Document may result in immediate termination of the dealer agreement, civil litigation for damages, injunctive relief, and referral for criminal prosecution under applicable trade secret laws including the Defend Trade Secrets Act (18 U.S.C. ? 1836).</div>
                    <div><strong style={{ color: "#4a5878" }}>4. Return or Destruction:</strong> Upon termination of the dealer relationship or upon written request by eEquals Solar, recipient agrees to promptly return or certifiably destroy all copies of this Document.</div>
                    <div><strong style={{ color: "#4a5878" }}>5. Governing Law:</strong> This non-disclosure obligation shall be governed by the laws of the State in which eEquals Solar is headquartered, without regard to conflict of law principles.</div>
                  </div>
                  <div style={{ marginTop: 12, paddingTop: 10, borderTop: "1px solid #dde3ed", fontSize: 9, color: "#c0c8d4" }}>eEquals ? Dealer Adder Rates ? {today} ? Internal Use Only ? Do Not Distribute</div>
                </div>
              </div>
            )}
          </>
        );
      })()}

      {/* ?? MODEL 3: INSTALL ONLY ???????????????????????????????????????? */}
      {dealerModel === 3 && (() => {
        const m3Rate      = parseFloat(m3RateStr) || 0;
        const laborPPW    = C?.baseLaborPPW        || 0;
        const gaPPW_v     = C ? C.gaCost          / C.W : 0;
        const sopsPPW_v   = C ? C.sopsCost        / C.W : 0;
        // Ancillary excluded from M3 floor ? dealer handles surveys, permits, plan sets
        const m3CostFloor = laborPPW + gaPPW_v + sopsPPW_v;
        const m3Margin    = m3Rate > 0 ? ((m3Rate - m3CostFloor) / m3Rate * 100) : 0;
        const m3Col       = m3Margin < 0 ? c.danger : m3Margin < 10 ? c.warn : c.success;

        const M3_GROUPS = [
          { title: "Electrical Adders", rows: [
            { label: "Main Panel Replacement",              cost: "$3,200",        unit: "1 Time Charge" },
            { label: "Main Meter Upgrade",                  cost: "$2,700",        unit: "1 Time Charge" },
            { label: "Main Breaker Enclosure",              cost: "$2,050",        unit: "1 Time Charge" },
            { label: "Sub Panel",                           cost: "$1,150",        unit: "1 Time Charge" },
            { label: "Main Breaker Derate/Replacement",     cost: "$600",          unit: "1 Time Charge" },
            { label: "Meter Main Combo",                    cost: "$4,250",        unit: "1 Time Charge" },
            { label: "Tap Box",                             cost: "$500",          unit: "1 Time Charge" },
            { label: "Electrical Stamps Adder",             cost: "$75",           unit: "1 Time Charge" },
            { label: "Ground Rods",                         cost: "$275",          unit: "1 Time Charge" },
          ]},
          { title: "Roof and Ground Mount Adders", rows: [
            { label: "Steep Roof (>35?)",                   cost: "$0.060",        unit: "Per Watt" },
            { label: "High Roof (3 stories or more)",       cost: "$0.060",        unit: "Per Watt" },
            { label: "Metal Roof",                          cost: "$0.070",        unit: "Per Watt" },
            { label: "Trenching ($500 base charge)",        cost: "$35",           unit: "Per Foot" },
            { label: "Boring Labor",                        cost: "Quote + $250",  unit: "Per Foot" },
            { label: "Boring Material Only (0?100 ft)",     cost: "$12",           unit: "Per Foot" },
            { label: "Boring Material Only (101?200 ft)",   cost: "$11",           unit: "Per Foot" },
            { label: "Boring Material Only (201+ ft)",      cost: "$10",           unit: "Per Foot" },
            { label: "Multiple Array Adder",                cost: "$350",          unit: "Per Array",    note: "Starting on 4th array" },
            { label: "Drywall Adders",                      cost: "Quote",         unit: "1 Time Charge" },
            { label: "Small System Adder (12 panels or less)", cost: "$1,500",     unit: "1 Time Charge" },
          ]},
          { title: "Battery Adders ? Labor and BOS Only", bomExcluded: true, rows: [
            { label: "SolarEdge Bat10K w/ Backup",          cost: "$5,000",        unit: "1 Time Charge" },
            { label: "SolarEdge Bat10K (no backup)",        cost: "$3,000",        unit: "1 Time Charge" },
            { label: "SolarEdge Battery (Each Additional)", cost: "$1,400",        unit: "1 Time Charge" },
            { label: "Tesla Powerwall 3",                   cost: "$6,000",        unit: "1 Time Charge" },
            { label: "Tesla Powerwall 3 (Expansion Battery)", cost: "$800",        unit: "1 Time Charge" },
            { label: "Tesla Powerwall 3 (Each Additional)", cost: "$1,200",        unit: "1 Time Charge" },
            { label: "Enphase IQ 10C",                      cost: "$6,450",        unit: "1 Time Charge" },
            { label: "Enphase IQ 10C (Each Additional)",    cost: "$850",          unit: "1 Time Charge" },
            { label: "Enphase IQ 5P",                       cost: "$7,800",        unit: "1 Time Charge" },
            { label: "Enphase IQ 5P (Each Additional)",     cost: "$800",          unit: "1 Time Charge" },
            { label: "Heat and Smoke Detectors",            cost: "$450",          unit: "1 Time Charge" },
          ]},
          { title: "Miscellaneous", rows: [
            { label: "Home Repairs",                        cost: "$1,000",        unit: "1 Time Charge" },
            { label: "Cancel (Post Permit Submitted)",      cost: "$1,000",        unit: "1 Time Charge" },
            { label: "Permit (>$150)",                      cost: "Cost ? $150",   unit: "1 Time Charge" },
            { label: "Interconnection Passthrough",         cost: "NEM fees beyond $150", unit: "1 Time Charge" },
            { label: "Travel Adder (>75 Miles from Warehouse)", cost: "$500",      unit: "1 Time Charge" },
          ]},
        ];

        return (
          <>
            {/* Rate Config */}
            <div style={card}>
              <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent, marginBottom: 14 }}>Model 3 ? Install Only Rate</div>
              {!C ? (
                <div style={{ background: c.warnL, border: `1.5px solid rgba(180,83,9,.2)`, borderRadius: 8, padding: "10px 14px", fontSize: 12, color: c.warn }}>
                  ? Configure a job in the Pricing Calculator tab first ? labor cost is derived from your active settings.
                </div>
              ) : (
                <>
                  <div style={{ background: c.surface2, border: `1.5px solid ${c.border}`, borderRadius: 8, padding: "10px 14px", fontSize: 11, color: c.text2, lineHeight: 1.7, marginBottom: 16 }}>
                    <strong style={{ color: c.text }}>Model 3:</strong> Dealer sells, surveys, permits, and designs the job ? sends it to eEquals install-ready. eEquals charges base install labor only. Ancillary COGS (surveys, permits, plan sets) excluded from cost floor ? dealer bears those costs. Battery adder prices are labor + BOS only, no hardware.
                  </div>

                  {/* Base rate input */}
                  <div style={{ marginBottom: 16 }}>
                    <div style={lbl}>Base Install Labor Rate ($/W)</div>
                    <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
                      <button onClick={() => setM3RateStr(v => (Math.max(0.40, Math.round((parseFloat(v)-0.005)*1000)/1000)).toFixed(3))} style={{ width: 28, height: 28, borderRadius: 6, border: `1.5px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 16, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>?</button>
                      <input type="number" min={0.40} max={2.00} step={0.005} value={m3RateStr}
                        onChange={e => setM3RateStr(e.target.value)}
                        style={{ width: 120, fontFamily: "'IBM Plex Mono',monospace", fontWeight: 700, fontSize: 18, padding: "9px 12px", border: `2px solid ${c.accent}`, borderRadius: 8, background: c.accentL, color: c.accent, outline: "none", textAlign: "center" }} />
                      <button onClick={() => setM3RateStr(v => (Math.min(2.00, Math.round((parseFloat(v)+0.005)*1000)/1000)).toFixed(3))} style={{ width: 28, height: 28, borderRadius: 6, border: `1.5px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 16, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>+</button>
                      {m3RateStr !== "0.750" && <button onClick={() => setM3RateStr("0.750")} style={{ fontSize: 10, color: c.text3, background: "none", border: "none", cursor: "pointer", padding: "0 4px" }}>reset</button>}
                      <span style={{ fontSize: 11, color: c.text3 }}>
                        {m3Rate > 0 ? `${C.W.toLocaleString()}W ? $${m3Rate.toFixed(3)}/W = ${fmt(m3Rate * C.W)} total base charge` : "Enter a rate"}
                      </span>
                    </div>
                  </div>

                  {/* Cost breakdown ? no ancillary */}
                  <div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 8, marginBottom: 14 }}>
                    {[
                      { label: "Install Labor",    ppw: fmtPPW(laborPPW),    col: c.warn,   bg: c.warnL    },
                      { label: "G&A",              ppw: fmtPPW(gaPPW_v),     col: c.text2,  bg: c.surface2 },
                      { label: "Sales Ops",        ppw: fmtPPW(sopsPPW_v),   col: c.text2,  bg: c.surface2 },
                      { label: "Total Cost Floor", ppw: fmtPPW(m3CostFloor), col: c.text,   bg: c.surface3 },
                    ].map(item => (
                      <div key={item.label} style={{ background: item.bg, border: `1px solid ${c.border}`, borderRadius: 8, padding: "9px 10px", textAlign: "center" }}>
                        <div style={{ fontSize: 9, color: c.text3, fontWeight: 700, textTransform: "uppercase", letterSpacing: ".08em", marginBottom: 4 }}>{item.label}</div>
                        <div style={{ fontSize: 13, fontWeight: 700, fontFamily: "'IBM Plex Mono',monospace", color: item.col }}>{item.ppw}</div>
                      </div>
                    ))}
                  </div>
                  <div style={{ fontSize: 10, color: c.text3, marginBottom: 14, fontStyle: "italic" }}>
                    ? Ancillary COGS ($0.06/W surveys, permits, plan sets) excluded ? dealer handles these upstream.
                  </div>

                  {/* Margin output */}
                  <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", background: m3Rate > 0 ? `${m3Col}12` : c.surface3, border: `1.5px solid ${m3Rate > 0 ? m3Col + "40" : c.border}`, borderRadius: 9, padding: "13px 16px" }}>
                    <div>
                      <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".1em", textTransform: "uppercase", color: m3Rate > 0 ? m3Col : c.text3, marginBottom: 3 }}>
                        {m3Rate > 0 ? (m3Margin < 0 ? "? Below Cost" : "Gross Margin on Base Rate") : "Enter a rate above"}
                      </div>
                      <div style={{ fontSize: 11, color: c.text3 }}>
                        {m3Rate > 0 ? `$${m3Rate.toFixed(3)}/W charged ? ${fmtPPW(m3CostFloor)} cost = ${fmtPPW(Math.abs(m3Rate - m3CostFloor))} ${m3Margin >= 0 ? "margin" : "shortfall"}` : "Equipment costs excluded ? dealer provides BOM"}
                      </div>
                    </div>
                    {m3Rate > 0 && <div style={{ fontFamily: "'IBM Plex Mono',monospace", fontSize: 32, fontWeight: 800, color: m3Col, lineHeight: 1 }}>{m3Margin.toFixed(1)}%</div>}
                  </div>
                </>
              )}
            </div>

            {/* Adder Schedule */}
            <div style={card}>
              <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 14 }}>
                <div>
                  <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent }}>Adder Schedule ? Model 3</div>
                  <div style={{ fontSize: 11, color: c.text3, marginTop: 3 }}>Battery adders are labor + BOS only ? hardware not included</div>
                </div>
                <span style={{ fontSize: 9, fontWeight: 700, padding: "3px 10px", borderRadius: 20, background: "#fee2e2", color: "#b91c1c", border: "1px solid rgba(185,28,28,.2)" }}>BOM EXCLUDED</span>
              </div>
              {M3_GROUPS.map(group => (
                <div key={group.title} style={{ marginBottom: 12 }}>
                  <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", padding: "4px 0", borderBottom: `2px solid ${c.border}`, marginBottom: 5 }}>
                    <div style={{ fontSize: 9, fontWeight: 700, letterSpacing: ".12em", textTransform: "uppercase", color: c.text3 }}>{group.title}</div>
                    {group.bomExcluded && <span style={{ fontSize: 8, fontWeight: 700, color: "#b91c1c", background: "#fee2e2", padding: "1px 6px", borderRadius: 8 }}>LABOR + BOS ONLY</span>}
                  </div>
                  {group.rows.map((row, i) => (
                    <div key={i} style={{ display: "flex", justifyContent: "space-between", alignItems: "center", padding: "5px 0", borderBottom: `1px solid ${c.surface3}`, fontSize: 12 }}>
                      <span style={{ color: c.text2 }}>{row.label}{row.note ? <span style={{ fontSize: 10, color: c.text3, marginLeft: 6 }}>? {row.note}</span> : null}</span>
                      <div style={{ display: "flex", alignItems: "center", gap: 14 }}>
                        <span style={{ fontSize: 10, color: c.text3, minWidth: 100, textAlign: "right" }}>{row.unit}</span>
                        <span style={{ fontFamily: "'IBM Plex Mono',monospace", fontSize: 12, fontWeight: 600, color: c.text, minWidth: 120, textAlign: "right" }}>{row.cost}</span>
                      </div>
                    </div>
                  ))}
                </div>
              ))}
            </div>

            {/* Rate Sheet Generator */}
            <div style={{ display: "flex", justifyContent: "center", marginBottom: 20 }}>
              <button onClick={() => setShowM3RateSheet(v => !v)}
                style={{ padding: "12px 32px", background: c.accent, color: "#fff", border: "none", borderRadius: 10, fontSize: 14, fontWeight: 700, cursor: "pointer", fontFamily: c.sans, letterSpacing: ".04em" }}>
                {showM3RateSheet ? "? Collapse Rate Sheet" : "? Generate Rate Sheet"}
              </button>
            </div>

            {showM3RateSheet && (
              <div style={{ background: "#fff", border: `2px solid ${c.border}`, borderRadius: 14, overflow: "hidden", boxShadow: "0 4px 24px rgba(0,0,0,.1)", marginBottom: 20 }}>

                {/* Header */}
                <div style={{ background: "#0d6e6e", padding: "20px 32px", display: "flex", justifyContent: "space-between", alignItems: "center" }}>
                  <div>
                    <div style={{ fontSize: 20, fontWeight: 900, color: "#fff" }}>? eEquals</div>
                    <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".14em", textTransform: "uppercase", color: "rgba(255,255,255,.75)", marginTop: 3 }}>
                      Install Only Rate Sheet ? {new Date().toLocaleDateString("en-US", { month: "long", year: "numeric" })}
                    </div>
                  </div>
                  <div style={{ textAlign: "right" }}>
                    {dealerName && <div style={{ fontSize: 14, fontWeight: 700, color: "#fff", marginBottom: 3 }}>{dealerName}</div>}
                    <div style={{ fontSize: 10, color: "rgba(255,255,255,.6)", fontStyle: "italic" }}>Internal Use Only ? Confidential & Proprietary</div>
                  </div>
                </div>

                {/* Table */}
                <div style={{ padding: "0 32px 28px" }}>
                  <div style={{ display: "grid", gridTemplateColumns: "1fr 160px 200px", padding: "10px 8px 6px", borderBottom: "2px solid #1a2640", marginTop: 20 }}>
                    {["ADDER DESCRIPTION", "COST", "UNIT OF MEASURE"].map(h => (
                      <div key={h} style={{ fontSize: 9, fontWeight: 700, letterSpacing: ".1em", color: "#1a2640" }}>{h}</div>
                    ))}
                  </div>

                  {/* Labor section */}
                  <div style={{ borderBottom: "1px solid #edf0f5" }}>
                    <div style={{ fontSize: 9, fontWeight: 700, letterSpacing: ".1em", textTransform: "uppercase", color: "#8a96aa", padding: "8px 8px 4px", background: "#f5f7fa" }}>Labor</div>
                    <div style={{ display: "grid", gridTemplateColumns: "1fr 160px 200px", padding: "6px 8px 8px", background: "#fff" }}>
                      <div style={{ fontSize: 12, color: "#1a2640" }}>Base Install Labor</div>
                      <div style={{ fontSize: 12, fontWeight: 700, fontFamily: "'IBM Plex Mono',monospace", color: "#0d6e6e" }}>${m3Rate > 0 ? m3Rate.toFixed(3) : "0.750"}</div>
                      <div style={{ fontSize: 11, color: "#4a5878" }}>Per Watt ? Subject to change per dealer and/or market</div>
                    </div>
                  </div>

                  {/* Adder sections */}
                  {M3_GROUPS.map(group => (
                    <div key={group.title} style={{ borderBottom: "1px solid #edf0f5" }}>
                      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", background: "#f5f7fa", padding: "8px 8px 4px" }}>
                        <div style={{ fontSize: 9, fontWeight: 700, letterSpacing: ".1em", textTransform: "uppercase", color: "#8a96aa" }}>{group.title}</div>
                        {group.bomExcluded && <span style={{ fontSize: 8, background: "#fee2e2", color: "#b91c1c", padding: "1px 8px", borderRadius: 8, fontWeight: 700, letterSpacing: ".05em" }}>LABOR & BOS ONLY ? HARDWARE NOT INCLUDED</span>}
                      </div>
                      {group.rows.map((row, i) => (
                        <div key={i} style={{ display: "grid", gridTemplateColumns: "1fr 160px 200px", padding: "5px 8px", background: i % 2 === 0 ? "#fff" : "#fafbfc", borderBottom: "1px solid #f5f7fa" }}>
                          <div style={{ fontSize: 12, color: "#1a2640" }}>
                            {row.label}
                            {row.note ? <span style={{ fontSize: 10, color: "#8a96aa", marginLeft: 6 }}>? {row.note}</span> : null}
                          </div>
                          <div style={{ fontSize: 12, fontWeight: 600, fontFamily: "'IBM Plex Mono',monospace", color: "#1a2640" }}>{row.cost}</div>
                          <div style={{ fontSize: 11, color: "#4a5878" }}>{row.unit}</div>
                        </div>
                      ))}
                    </div>
                  ))}
                </div>

                {/* NDA Footer */}
                <div style={{ background: "#f5f7fa", borderTop: "2px solid #dde3ed", padding: "20px 32px" }}>
                  <div style={{ fontSize: 10, fontWeight: 700, color: "#1a2640", letterSpacing: ".06em", textTransform: "uppercase", marginBottom: 6 }}>Confidentiality Notice & Non-Disclosure Agreement</div>
                  <div style={{ fontSize: 9, fontWeight: 700, color: "#4a5878", textTransform: "uppercase", letterSpacing: ".05em", marginBottom: 6 }}>Proprietary and Confidential</div>
                  <div style={{ fontSize: 10, color: "#8a96aa", lineHeight: 1.8, marginBottom: 10 }}>This Dealer Adder Rate Sheet (the "Document") is the exclusive and proprietary property of eEquals Solar and contains confidential trade information, pricing structures, and dealer rate schedules that constitute valuable business and trade secrets.</div>
                  <div style={{ fontSize: 9, fontWeight: 700, color: "#4a5878", textTransform: "uppercase", letterSpacing: ".05em", marginBottom: 4 }}>By receiving this document, you agree to the following:</div>
                  <div style={{ fontSize: 10, color: "#8a96aa", lineHeight: 1.9 }}>
                    <div><strong style={{ color: "#4a5878" }}>1. Non-Disclosure:</strong> You shall not disclose, distribute, reproduce, copy, transmit, disseminate, sell, publish, broadcast, or circulate this Document, in whole or in part, to any third party without the prior written consent of eEquals Solar.</div>
                    <div><strong style={{ color: "#4a5878" }}>2. Limited Use:</strong> This Document is provided solely for the authorized business purposes of the designated dealer recipient. Any use beyond the scope of the authorized dealer relationship is strictly prohibited.</div>
                    <div><strong style={{ color: "#4a5878" }}>3. Penalties for Unauthorized Disclosure:</strong> Unauthorized disclosure or misuse of this Document may result in immediate termination of the dealer agreement, civil litigation for damages, injunctive relief, and referral for criminal prosecution under applicable trade secret laws including the Defend Trade Secrets Act (18 U.S.C. ? 1836).</div>
                    <div><strong style={{ color: "#4a5878" }}>4. Return or Destruction:</strong> Upon termination of the dealer relationship or upon written request by eEquals Solar, recipient agrees to promptly return or certifiably destroy all copies of this Document.</div>
                    <div><strong style={{ color: "#4a5878" }}>5. Governing Law:</strong> This non-disclosure obligation shall be governed by the laws of the State in which eEquals Solar is headquartered, without regard to conflict of law principles.</div>
                  </div>
                  <div style={{ marginTop: 12, paddingTop: 10, borderTop: "1px solid #dde3ed", fontSize: 9, color: "#c0c8d4" }}>eEquals ? Dealer Adder Rates ? {today} ? Internal Use Only ? Do Not Distribute</div>
                </div>
              </div>
            )}
          </>
        );
      })()}

    </div>
  );
}

function PricingTool() {

  // ??? PRICE OVERRIDES (set by PDF parser on BOM tab) ??????????????????????
  const [priceOverrides, setPriceOverrides] = useState({});

  const [activeTab, setActiveTab]         = useState("calculator");
  const [pdfParsing, setPdfParsing]       = useState(false);
  const [pdfDiff, setPdfDiff]             = useState(null);
  const [pdfSelected, setPdfSelected]     = useState({});
  const [pdfFileName, setPdfFileName]     = useState("");
  const [pdfError, setPdfError]           = useState("");
  const [pdfApplied, setPdfApplied]       = useState(false);
  const [bosItems, setBosItems]           = useState(BOS_MASTER_DATA);


  // State
  const [st, setSt]                   = useState("VA");
  const [lender, setLender]           = useState("Lightreach");
  const [wattsStr, setWattsStr]       = useState("13120");
  const [jobType, setJobType]         = useState("solar");
  const [laborRate, setLaborRate]     = useState(0.60);
  const [laborMode, setLaborMode]     = useState("sub");
  const [partnerBOM, setPartnerBOM]   = useState(false);
  const [gaPPW, setGaPPW]             = useState(GA_PPW_DEFAULT);
  const [sopsPPW, setSopsPPW]         = useState(SALESOPS_PPW_DEFAULT);
  const [ancillaryPPW, setAncillaryPPW] = useState(ANCILLARY_PPW);
  const [salesLeadershipPPW, setSalesLeadershipPPW] = useState(SALES_LEADERSHIP_PPW_DEFAULT);
  const [proposalPPW, setProposalPPW] = useState(PROPOSAL_PPW);
  const [overheadOn, setOverheadOn] = useState({ ancillary:true, ga:true, sops:true, leadership:true, proposal:true });
  const [installsPerMonth, setInstallsPerMonth] = useState(100);
  // Campaign cost allocation ? per-line ops/sales coverage
  const [campaignOn, setCampaignOn]   = useState(false);
  const [campaignP, setCampaignP] = useState({
    setters: 9, days: 12, airbnbPerDay: 70, carPerDay: 40, flightPerRep: 700, installs: 15,
    manualOverride: false,
    manualClosers: 4, manualSetterCars: 3, manualCloserCars: 2,
    dealerMode: false,
    coverage: { airbnb: "ops", setterCars: "ops", closerCars: "ops", flights: "ops" },
  });
  // Commissions tab state
  const [util, setUtil]               = useState("APCO");
  const [ecOn, setEcOn]               = useState(true);
  const [maxPmtStr, setMaxPmtStr]     = useState("");
  const [linputs, setLinputs]         = useState({});
  const [waterfallLender, setWaterfallLender] = useState(null);
  const [selectedOptions, setSelectedOptions] = useState({});
  const [showOptionPicker, setShowOptionPicker] = useState(true);
  const [commView, setCommView]       = useState("sales");
  const [showInactive, setShowInactive] = useState(false);
  const [escrowOn, setEscrowOn]       = useState(false);
  const [salesView, setSalesView]     = useState(false);
  const [splits, setSplits]           = useState([
    { id:1, role:"Setter",          custom:"", pct:"30", mode:"pct", ppw:"0.010" },
    { id:2, role:"Closer",          custom:"", pct:"45", mode:"pct", ppw:"0.010" },
    { id:3, role:"Setter Manager",  custom:"", pct:"7",  mode:"pct", ppw:"0.010" },
    { id:4, role:"Closer Manager",  custom:"", pct:"7",  mode:"pct", ppw:"0.010" },
    { id:5, role:"Setter Director", custom:"", pct:"5",  mode:"pct", ppw:"0.010" },
    { id:6, role:"VP",              custom:"", pct:"6",  mode:"ppw", ppw:"0.010" },
  ]);
  const [commMode, setCommMode]       = useState("sold_rate");
  const [soldPPWStr, setSoldPPWStr]   = useState("3.800");
  const [targetCommStr, setTargetCommStr] = useState("");
  const [panelK, setPanelK]           = useState("qcell_c_plus");
  const [invK, setInvK]               = useState("enphase_iq8hc_dom");
  const [rackK, setRackK]             = useState("unirac_nxt_dom");
  const [dcOn, setDcOn]               = useState(true);
  const [targetM, setTargetM]         = useState(25);
  const [customMStr, setCustomMStr]   = useState("");
  const [targetPPWStr, setTargetPPWStr] = useState("");
  const [sel, setSel]                 = useState({});
  const [redlineSet, setRedlineSet]   = useState(new Set());
  const [eqAdj, setEqAdj]             = useState({ panel:0, inv:0, rack:0, bos:0, comb:0 });
  const [qty, setQty]                 = useState({});
  const [expanded, setExpanded]       = useState({});
  const [adderSecExpanded, setAdderSecExpanded] = useState(false);
  const [trenchFtStr, setTrenchFtStr] = useState("120");
  const [boringQuoteStr, setBoringQuoteStr] = useState("0");
  const [boringFtStr, setBoringFtStr] = useState("100");
  const [roofType, setRoofType]       = useState("flush");
  const [detached, setDetached]       = useState(false);

  // Derived scalars
  const watts      = parseInt(wattsStr) || 0;
  const trenchFt   = parseInt(trenchFtStr) || 120;
  const boringQuote = parseFloat(boringQuoteStr) || 0;
  const boringFt   = parseInt(boringFtStr) || 100;
  const cfg        = LENDER_CFG[lender] || LENDER_CFG.Cash;
  const isCash     = lender === "Cash";
  const invBrand   = INVERTERS[invK]?.brand || "enphase";

  // Memos
  const availPanels = useMemo(() => {
    const base = cfg.panels || Object.keys(PANELS);
    return base.filter(k => {
      const p = PANELS[k];
      if (p?.stateRestrict) return p.stateRestrict.includes(st);
      return true;
    });
  }, [lender, st]);

  const availInverters = useMemo(() => {
    const base = cfg.inverters || Object.keys(INVERTERS);
    return base.filter(k => {
      const inv = INVERTERS[k];
      if (inv?.stateRestrict) return inv.stateRestrict.includes(st);
      return true;
    });
  }, [lender, st]);

  const effectiveM = useMemo(() => {
    if (customMStr === "") return targetM;
    const n = parseFloat(customMStr);
    return isNaN(n) ? targetM : Math.min(60, Math.max(0, n));
  }, [targetM, customMStr]);

  const isGroundMount = !!sel["gm"] && !ADDERS.find(a => a.key === "gm")?.blockLenders?.includes(lender);

  // Effects
  useEffect(() => {
    if (!availPanels.includes(panelK)) setPanelK(availPanels[0] || "qcell_c_plus");
    if (!availInverters.includes(invK)) setInvK(availInverters[0] || "enphase_iq8hc_dom");
  }, [lender, jobType, st]);

  useEffect(() => {
    const isTeslaDC = invK === "tesla_pw3_dc" || invK === "tesla_pw3_sh";
    if (isTeslaDC) {
      setSel(p => ({ ...p, bat_tpw1: true }));
      setJobType("storage");
    } else {
      setSel(p => { const n = { ...p }; delete n.bat_tpw1; delete n.bat_texp; delete n.bat_tpwx; return n; });
      setQty(p => { const n = { ...p }; delete n.bat_texp; delete n.bat_tpwx; return n; });
      setSel(p => { const n = {...p}; delete n.bat_tac1; delete n.bat_tacx; delete n.bat_tace; return n; });
    }
    // Clear battery adders incompatible with newly selected inverter brand
    const newBrand = INVERTERS[invK]?.brand || "enphase";
    setSel(p => {
      const n = { ...p };
      ADDERS.forEach(a => { if (a.blockInvBrand && a.blockInvBrand === newBrand) delete n[a.key]; });
      return n;
    });
  }, [invK]);

  useEffect(() => {
    const acKeys = new Set(["bat_tac1","bat_tacx","bat_tace"]);
    const hasAC = Object.keys(sel).some(k => acKeys.has(k) && sel[k]);
    if (hasAC && jobType !== "storage") setJobType("storage");
  }, [sel]);

  useEffect(() => {
    const pw = PANELS[panelK]?.watt || 410;
    const current = parseInt(wattsStr) || 0;
    if (current >= pw) { const snapped = Math.round(current / pw) * pw; if (snapped !== current) setWattsStr(String(snapped)); }
  }, [panelK]);

  // Auto-solve lender card inputs whenever soldPPWStr changes
  useEffect(() => {
    const soldPPW = parseFloat(soldPPWStr) || 0;
    if (soldPPW <= 0 || !watts) return;
    const kw = watts / 1000;
    const solved = {};
    (LENDERS_BY_STATE[st] || []).forEach(l => {
      const combo = commSolveForTarget(l, st, util, dcOn, ecOn, kw, soldPPW);
      if (combo) solved[l] = combo;
    });
    if (Object.keys(solved).length > 0) setLinputs(solved);
    setSelectedOptions({});
    setShowOptionPicker(true);
  }, [soldPPWStr, st, util, dcOn, ecOn, watts]);

  // Handlers
  const handleSt   = s => { setSt(s); setLender(LENDERS_BY_STATE[s][0]); setUtil(UTILITIES_BY_STATE[s]?.[0] || ""); };
  const toggle     = k => setSel(p => ({ ...p, [k]: !p[k] }));
  const setQtyFor  = (k, v) => setQty(p => ({ ...p, [k]: Math.max(1, v) }));
  const toggleExp  = k => setExpanded(p => ({ ...p, [k]: !p[k] }));
  const setPresetM = m => { setTargetM(m); setCustomMStr(""); };

  // Main calculation memo
  const C = useMemo(() => {
    if (!watts || watts < 100) return null;
    const panel = PANELS[panelK], inv = INVERTERS[invK], rack = RACKING[rackK];
    if (!panel || !inv || !rack) return null;

    const W = watts, pCnt = Math.ceil(W / panel.watt);
    const isTeslaInv = invK === "tesla_pw3_dc" || invK === "tesla_pw3_sh";
    const pw3UnitPrice = inv?.pw3UnitPrice || 7388.88;


    // Apply any live price overrides from PDF parser
    const effPanelPrice  = priceOverrides?.panels?.[panelK]   ?? panel.price;
    const effInvPrice    = priceOverrides?.inverters?.[invK]   ?? inv.price;
    const effRackPPW     = priceOverrides?.racking?.[rackK]    ?? rack.ppw;
    const effOptPrice    = priceOverrides?.optimizers?.[invK]  ?? inv.optimizerPrice;

    // Equipment costs ? with per-line $/W adjustments
    const panelCost       = partnerBOM ? 0 : pCnt * effPanelPrice + (eqAdj.panel * W);
    const invCostDisplay  = (!partnerBOM && !isTeslaInv) ? (inv.perSystem ? effInvPrice : pCnt * effInvPrice) + (eqAdj.inv * W) : 0;
    const optCost         = partnerBOM ? 0 : ((inv.brand === "solaredge" && effOptPrice) ? pCnt * effOptPrice : 0);
    const combCost        = partnerBOM ? 0 : (inv.brand === "enphase" ? 910.39 : 0) + (eqAdj.comb * W);
    const rackCost        = (partnerBOM || isGroundMount) ? 0 : (effRackPPW + eqAdj.rack) * W;
    const bosCostBase     = partnerBOM ? 0 : (laborMode === "internal" ? Math.round(BOS_PPW * W * BOS_CUSHION * 100) / 100 : 0);
    const bosCost         = partnerBOM ? 0 : bosCostBase + (eqAdj.bos * W);

    // Lender fees
    let shFee = 0, shFeeLabel = null;
    if (lender === "IGS" && inv.perPanel){ shFee = 20 * pCnt; shFeeLabel = `IGS Safe Harbor Fee ($20 ? ${pCnt} micros)`; }
    const taxRate = isCash ? (SALES_TAX_RATE[st] || 0) : 0;

    // Adders
    const warnings = [], adderRows = [];
    let adderSum = 0, listSum = 0, redlineAdderSum = 0, hasBattery = false, batDCEligible = true;

    ADDERS.forEach(a => {
      if (!sel[a.key]) return;
      if (a.blockLenders?.includes(lender)) {
        warnings.push({ t: "block", m: `? ${a.label} ? not approved for ${lender}` });
        return;
      }
      if (a.blockInvBrand && a.blockInvBrand === invBrand) {
        warnings.push({ t: "block", m: `? ${a.label} ? incompatible with ${invBrand === "enphase" ? "Enphase" : "SolarEdge"} inverter` });
        return;
      }
      if (a.isBattery) hasBattery = true;
      if (a.isBattery && BAT_DC_ELIGIBLE[a.key] === false) batDCEligible = false;

      const q = a.isQtyAdder ? (qty[a.key] || 1) : 1;
      let cost, list;
      if (a.isTeslaACLead || a.isTeslaACPWX || (a.isTeslaExp && (a.key === "bat_tace"))) {
        cost = calcTeslaACCost(a, laborMode);
        list = a.list ?? null;
      } else if (a.isTeslaLead || a.isTeslaExp || a.isTeslaPWX) {
        cost = calcTeslaCost(a, laborMode, pCnt, pw3UnitPrice);
        list = a.list ?? null;
      } else if (partnerBOM && a.isBattery) {
        cost = laborMode === "sub" ? (a.seaPartner || 0) : (a.intPartner || 0);
        list = a.listPartner ?? null;
      } else {
        cost = adderCostFor(a, laborMode, W, trenchFt, boringQuote, boringFt, isGroundMount, redlineSet);
        list = adderListFor(a, W, trenchFt, boringQuote, boringFt, redlineSet);
      }

      const totalCost = (cost || 0) * q;
      const totalList = list != null ? list * q : null;
      const isRedlineAdder = redlineSet.has(a.key);
      if (!isRedlineAdder && totalCost > 0 && totalList != null && totalCost > totalList)
        warnings.push({ t: "cost", m: `? BELOW COST: ${a.label} ? ${fmt(totalCost)} cost vs ${fmt(totalList)} list` });
      adderSum += totalCost;
      if (isRedlineAdder)          redlineAdderSum += totalCost;
      else if (totalList != null)  listSum += totalList;
      adderRows.push({ label: a.label + (q > 1 ? ` ?${q}` : ""), cost: totalCost, list: isRedlineAdder ? null : totalList, isRedline: isRedlineAdder });
    });

    // Campaign cost allocation ? per-line ops/sales assignment
    const cp            = campaignP;
    const campClosers    = cp.manualOverride ? cp.manualClosers    : Math.ceil(cp.setters / 2.5);
    const campSetterCars = cp.manualOverride ? cp.manualSetterCars : Math.ceil(cp.setters / 4);
    const campCloserCars = cp.manualOverride ? cp.manualCloserCars : Math.ceil(campClosers / 2.5);
    const campPeople     = cp.setters + campClosers;
    const campAirbnbAmt   = campPeople * cp.airbnbPerDay * cp.days;
    const campSetCarAmt   = campSetterCars * cp.carPerDay * cp.days;
    const campCloseCarAmt = campCloserCars * cp.carPerDay * cp.days;
    const campFlightsAmt  = campPeople * cp.flightPerRep;
    const campTotalCost   = campAirbnbAmt + campSetCarAmt + campCloseCarAmt + campFlightsAmt;
    const campInstalls    = Math.max(1, cp.installs);
    const campCostPPW     = campInstalls * W > 0 ? campTotalCost / (campInstalls * W) : 0;
    const cov = cp.coverage || { airbnb:"ops", setterCars:"ops", closerCars:"ops", flights:"ops" };
    const campaignOpsPPW   = (campaignOn && !cp.dealerMode)
      ? ((cov.airbnb==="ops"?campAirbnbAmt:0)+(cov.setterCars==="ops"?campSetCarAmt:0)+(cov.closerCars==="ops"?campCloseCarAmt:0)+(cov.flights==="ops"?campFlightsAmt:0)) / (campInstalls * W)
      : 0;
    const campaignSalesPPW = (campaignOn && !cp.dealerMode)
      ? ((cov.airbnb==="sales"?campAirbnbAmt:0)+(cov.setterCars==="sales"?campSetCarAmt:0)+(cov.closerCars==="sales"?campCloseCarAmt:0)+(cov.flights==="sales"?campFlightsAmt:0)) / (campInstalls * W)
      : 0;
    const campaignOpsCost  = campaignOpsPPW * W;

    // Cost rollup
    const equipSubtotal  = panelCost + invCostDisplay + optCost + combCost + rackCost + bosCost + shFee;
    const salesTax       = taxRate * equipSubtotal;
    const equipTotal     = equipSubtotal + salesTax;
    const equipTotalPPW  = equipTotal / W;
    const totalEquip     = equipTotal + adderSum;
    const baseLaborCost  = laborRate * W;
    const gaCost         = (overheadOn.ga ? gaPPW : 0) * W;
    const sopsCost       = (overheadOn.sops ? sopsPPW : 0) * W;
    const ancillaryCost  = (overheadOn.ancillary ? ancillaryPPW : 0) * W;
    const leadershipCost = (overheadOn.leadership ? salesLeadershipPPW : 0) * W;
    const proposalCost   = (overheadOn.proposal ? proposalPPW : 0) * W;
    const nonflushPrem   = (!isGroundMount && roofType === "nonflush") ? NONFLUSH_PPW * W : 0;
    const detachPrem     = (!isGroundMount && detached) ? DETACH_PPW * W : 0;
    const totalAllin     = totalEquip + baseLaborCost + gaCost + sopsCost + ancillaryCost + leadershipCost + proposalCost + nonflushPrem + detachPrem + campaignOpsCost;
    const allInPPW       = totalAllin / W;

    // Redline scenarios ? redline adders stay in floor, spread adders excluded
    const baseAllinNoAdders = totalAllin - (adderSum - redlineAdderSum);
    const mScenarios = MARGIN_PRESETS.map(m => ({
      m,
      equipOnlyPPW:  rl(totalEquip, m) / W,
      baseRedlinePPW: rl(baseAllinNoAdders, m) / W,
      baseRedline$:  rl(baseAllinNoAdders, m),
    }));
    const targetSc = {
      baseRedlinePPW: rl(baseAllinNoAdders, effectiveM) / W,
      baseRedline$:   rl(baseAllinNoAdders, effectiveM),
      allInPPW:       rl(totalAllin, effectiveM) / W,
    };

    // Holdback (Lightreach only)
    let hb = null;
    if (lender === "Lightreach") {
      const boost = dcOn ? (jobType === "storage" ? (cfg.dcBoostPVStorage?.[st] || 0.45) : (cfg.dcBoostPVOnly?.[st] || 0.35)) : 0;
      hb = { std: 0.10, dcBoost: boost, total: 0.10 + boost };
    }

    // DC / FEOC
    const modDC      = PANEL_DC[panelK] || 0;
    const invDCPct   = INV_DC[invK] || 0;
    const rackDCPct  = isGroundMount ? 0 : (RACK_DC[rackK] || 0);
    const pvDC       = modDC + invDCPct + rackDCPct;
    const isSHPanel  = !!PANELS[panelK]?.shOnly;
    const isSHInv    = !!INVERTERS[invK]?.isSH;
    const activeDcThreshold = (isSHPanel || isSHInv) ? (cfg.shDcThreshold || 45) : (cfg.dcThreshold || 50);
    const dcThreshold = activeDcThreshold;
    const storageMode = jobType === "storage";
    const batPending  = storageMode && !hasBattery;
    const batDCNote   = hasBattery
      ? (isTeslaInv ? "Battery DC ? Eligible ? (PW3 ESS qualifies)" : batDCEligible ? "Battery DC ? Eligible ?" : "Battery DC ? Not Eligible 2026 (SE Bat10K)")
      : (storageMode ? "Battery DC ? Pending selection" : null);
    const feocPVThreshold = cfg.feocThresholdPV || 40;
    const feocPVPass = (isTeslaInv && isSHPanel) ? true : isTeslaInv ? true : pvDC >= feocPVThreshold;
    const feocBatPass = !hasBattery || batDCEligible;
    const safeHarbored = !!cfg.safeHarbored || isSHInv;

    // Safe Harbor pairing warnings
    if (isSHPanel && !isSHInv)
      warnings.push({ t: "sh", m: "? FEOC VIOLATION: LONGi Hi-MO 5 DC requires the Tesla PW3 Safe Harbor inverter (1707000-60-M-LR-2025). This panel is only FEOC-compliant when paired with the SH PW3." });
    if (isSHInv && !isSHPanel)
      warnings.push({ t: "sh", m: "? Tesla PW3 Safe Harbor inverter selected ? this must be paired with the LONGi Hi-MO 5 DC (LR5-54HPB-405M) panel for FEOC compliance." });

    // Tesla inverter cost in 04A = string inverter equivalent + MCI/RSD for full system
    const teslaInvCost = isTeslaInv ? (TESLA_STRING_INV + Math.ceil(pCnt / 3) * MCI_PRICE) : 0;

    // Warnings
    const histPPW = HIST_PPW[st]?.[lender] ?? null;
    if (cfg.rackingDomRequired && !RACKING[rackK]?.domestic && !isGroundMount)
      warnings.push({ t: "avl", m: `? ${lender} requires domestic racking` });
    if (histPPW && targetSc.baseRedlinePPW > histPPW)
      warnings.push({ t: "market", m: `? Base redline ($${targetSc.baseRedlinePPW.toFixed(3)}/W) exceeds 2025 market avg ($${histPPW.toFixed(3)}/W)` });

    const actualCOGS = getActualCOGS(st, lender, roofType, detached);

    return {
      W, pCnt, panelCost, invCost: invCostDisplay, isTeslaInv, teslaInvCost,
      optCost, combCost, rackCost, bosCost, isGroundMount, partnerBOM,
      shFee, shFeeLabel, salesTax, taxRate,
      equipSubtotal, equipTotal, equipTotalPPW,
      adderRows, adderSum, listSum,
      totalEquip, baseLaborPPW: laborRate, baseLaborCost,
      gaCost, sopsCost, ancillaryCost, leadershipCost, proposalCost, nonflushPrem, detachPrem,
      campaignOpsPPW, campaignSalesPPW, campTotalCost, campCostPPW, campInstalls,
      campClosers, campSetterCars, campCloserCars, campPeople, campAirbnbAmt, campSetCarAmt, campCloseCarAmt, campFlightsAmt,
      totalAllin, allInPPW, baseAllinNoAdders, baseAllinPPW: baseAllinNoAdders / W,
      mScenarios, targetSc, hb, histPPW, warnings,
      smallSystem: W < 9000, actualCOGS, laborMode,
      pvDC, dcThreshold, batDCNote, batDCEligible,
      hasBattery, batPending, storageMode,
      feocPVPass, feocBatPass, feocPVThreshold,
      safeHarbored, modDC, invDCPct, rackDCPct,
      isSHPanel, isSHInv,
    };
  }, [st, lender, watts, jobType, laborRate, laborMode, partnerBOM, panelK, invK, rackK, dcOn, effectiveM, sel, qty, isCash, trenchFt, boringQuote, boringFt, isGroundMount, invBrand, roofType, detached, priceOverrides, gaPPW, sopsPPW, ancillaryPPW, salesLeadershipPPW, proposalPPW, overheadOn, redlineSet, eqAdj, campaignOn, campaignP]);

  // Shortcuts for selected equipment
  const panel = PANELS[panelK], inv = INVERTERS[invK], rack = RACKING[rackK];

  // ??? THEME + STYLE TOKENS ??????????????????????????????????????????????????

  const c = {
    bg:      "#eef2f7", surface:  "#fff",     surface2: "#f5f7fa", surface3: "#edf0f5",
    border:  "#dde3ed", border2:  "#c8d0de",
    text:    "#1a2640", text2:    "#4a5878",  text3:    "#8a96aa",
    accent:  "#0d6e6e", accentL:  "#e6f4f4",
    warn:    "#b45309", warnL:    "#fef3c7",
    danger:  "#b91c1c", dangerL:  "#fee2e2",
    success: "#166534", successL: "#dcfce7",
    blue:    "#1a5fb4", blueL:    "#e8f0fb",
    purple:  "#6d28d9", purpleL:  "#ede9fe",
    mono:    "'IBM Plex Mono',monospace",
    sans:    "'Inter',system-ui,sans-serif",
  };

  const card     = { background: c.surface, border: `1px solid ${c.border}`, borderRadius: 12, padding: 18, marginBottom: 14, boxShadow: "0 1px 3px rgba(0,0,0,.07)" };
  const lbl      = { fontSize: 10, color: c.text3, marginBottom: 4, letterSpacing: ".05em", fontWeight: 700, textTransform: "uppercase" };
  const sel_s    = { background: c.surface2, border: `1.5px solid ${c.border}`, color: c.text, padding: "8px 30px 8px 10px", borderRadius: 8, width: "100%", fontFamily: c.sans, fontSize: 13, fontWeight: 500, outline: "none", appearance: "none", WebkitAppearance: "none", backgroundImage: "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath fill='%238a96aa' d='M5 6L0 0h10z'/%3E%3C/svg%3E\")", backgroundRepeat: "no-repeat", backgroundPosition: "right 10px center" };
  const inp_s    = { background: c.surface2, border: `1.5px solid ${c.border}`, color: c.text, padding: "8px 10px", borderRadius: 8, width: "100%", fontFamily: c.sans, fontSize: 13, fontWeight: 500, outline: "none", textAlign: "center" };
  const g2       = { display: "grid", gridTemplateColumns: "1fr 1fr", gap: 10, marginBottom: 12 };
  const seg_s    = { display: "flex", gap: 3, background: c.surface3, border: `1.5px solid ${c.border}`, borderRadius: 9, padding: 3, marginBottom: 12 };
  const sb       = (on, warn = false) => ({ flex: 1, padding: "7px 4px", borderRadius: 7, border: on ? `1px solid ${c.border}` : "none", background: on ? (warn ? c.warnL : c.surface) : "transparent", color: on ? (warn ? c.warn : c.accent) : c.text3, cursor: "pointer", fontFamily: c.sans, fontSize: 12, fontWeight: on ? 700 : 600, transition: ".12s", boxShadow: on ? "0 1px 2px rgba(0,0,0,.06)" : "none" });
  const drow     = { display: "flex", justifyContent: "space-between", alignItems: "center", padding: "6px 0", borderBottom: `1px solid ${c.surface3}`, fontSize: 13 };
  const ppwBadge = { fontSize: 10, fontWeight: 500, color: c.text3, background: c.surface3, padding: "2px 5px", borderRadius: 4, whiteSpace: "nowrap", fontFamily: c.mono };

  // ??? RENDER ????????????????????????????????????????????????????????????????


  // ?? SKU match map for PDF parser ??????????????????????????????????????????
  const SKU_MATCH_MAP = [
    { keywords:["Q.PEAK DUO BLK ML-G10.C+","G10.C+"],         type:"panels",    key:"qcell_c_plus",      label:"Q.PEAK DUO BLK ML-G10.C+ 410W" },
    { keywords:["DCA.17 410","DCA.17-410"],                     type:"panels",    key:"qcell_dca_410",     label:"QCell DCA.17 410W" },
    { keywords:["DCA.17 415","DCA.17-415"],                     type:"panels",    key:"qcell_dca_415",     label:"QCell DCA.17 415W" },
    { keywords:["AC Module","QCELL AC"],                        type:"panels",    key:"qcell_ac_410",      label:"QCell AC Module 410W" },
    { keywords:["HIN-T440","BIFACIAL","HYUNDAI 440"],            type:"panels",    key:"hyundai_440",       label:"Hyundai HIN-T440NF 440W" },
    { keywords:["IQ8+-72","IQ8PLUS","IQ8+"],                    type:"inverters", key:"enphase_iq8plus",   label:"Enphase IQ8+" },
    { keywords:["IQ8MC-72","IQ8MC"],                            type:"inverters", key:"enphase_iq8mc",     label:"Enphase IQ8MC" },
    { keywords:["IQ8AC-72","IQ8AC"],                            type:"inverters", key:"enphase_iq8ac",     label:"Enphase IQ8AC" },
    { keywords:["IQ8X-72-2-INT","IQ8X NON"],                    type:"inverters", key:"enphase_iq8x_nd",   label:"Enphase IQ8X Non-Dom" },
    { keywords:["IQ8X-72-M-DOM","IQ8X DOM"],                    type:"inverters", key:"enphase_iq8x_dom",  label:"Enphase IQ8X Dom" },
    { keywords:["IQ8HC-72-M-DOM","IQ8HC DOM"],                  type:"inverters", key:"enphase_iq8hc_dom", label:"Enphase IQ8HC Dom" },
    { keywords:["IQ8HC-72-2-US","IQ8HC IGS","135.00"],          type:"inverters", key:"enphase_iq8hc_igs", label:"Enphase IQ8HC IGS SH" },
    { keywords:["USE11400H","SINGLE SKU","SE SINGLE"],           type:"inverters", key:"se_standard",       label:"SolarEdge Single SKU 11.4kW" },
    { keywords:["P370","P400","P505","P600","P700","OPTIMIZER"], type:"optimizers",key:"se_standard",       label:"SolarEdge Optimizer" },
    { keywords:["315168M-US","DOM SM LIGHT RAIL 168 MILL"],     type:"racking",   key:"unirac_dom_light_mill", label:"Unirac Dom Mill Light Rail" },
    { keywords:["315168D-US","DOM SM LIGHT RAIL 168 DARK"],     type:"racking",   key:"unirac_dom_dark",       label:"Unirac Dom Dark Rail" },
    { keywords:["185RLM1-US","NXT UMOUNT RAIL","NXT DOM"],      type:"racking",   key:"unirac_nxt_dom",        label:"Unirac NXT Dom Mill" },
    { keywords:["SNAPNRACK","SNAP N RACK"],                     type:"racking",   key:"snapnrack_dom",         label:"SnapNrack Dom" },
  ];

  const parsePDF = async (file) => {
    setPdfParsing(true); setPdfError(""); setPdfDiff(null); setPdfApplied(false);
    try {
      const base64Data = await new Promise((res, rej) => {
        const r = new FileReader();
        r.onload = () => res(r.result.split(",")[1]);
        r.onerror = () => rej(new Error("File read failed"));
        r.readAsDataURL(file);
      });
      const response = await fetch("https://api.anthropic.com/v1/messages", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({
          model: "claude-sonnet-4-20250514",
          max_tokens: 1000,
          messages: [{
            role: "user",
            content: [
              { type: "document", source: { type: "base64", media_type: "application/pdf", data: base64Data } },
              { type: "text", text: "Extract every line item with a unit price from this CED Greentech solar equipment quote. Return ONLY a valid JSON array, no markdown, no explanation: [{\"sku\":\"string\",\"description\":\"string\",\"unit_price\":number}]. Include all items." }
            ]
          }]
        })
      });
      const data = await response.json();
      const raw = data.content?.find(b => b.type === "text")?.text || "[]";
      const items = JSON.parse(raw.replace(/```json|```/g, "").trim());
      const matched = [], unmatched = [];
      items.forEach(item => {
        const descUpper = (item.description + " " + item.sku).toUpperCase();
        let found = null;
        for (const entry of SKU_MATCH_MAP) {
          if (entry.keywords.some(kw => descUpper.includes(kw.toUpperCase()))) { found = entry; break; }
        }
        if (found) {
          const obj = found.type === "panels" ? PANELS[found.key] : found.type === "inverters" ? INVERTERS[found.key] : found.type === "racking" ? RACKING[found.key] : null;
          const cur = found.type === "racking" ? obj?.ppw : (obj?.price ?? obj?.optimizerPrice);
          if (cur !== undefined) {
            matched.push({ ...item, catalogKey: found.key, catalogType: found.type, catalogLabel: found.label, currentPrice: cur, changed: Math.abs((item.unit_price - cur) / cur) > 0.001 });
          }
        } else { unmatched.push(item); }
      });
      const sel = {};
      matched.forEach((m, i) => { if (m.changed) sel[`m_${i}`] = true; });
      setPdfDiff({ matched, unmatched });
      setPdfSelected(sel);
    } catch(e) { setPdfError("Parse failed: " + e.message); }
    setPdfParsing(false);
  };

  const applyPriceChanges = () => {
    if (!pdfDiff) return;
    const newOverrides = { ...priceOverrides };
    pdfDiff.matched.forEach((m, i) => {
      if (!pdfSelected[`m_${i}`]) return;
      if (!newOverrides[m.catalogType]) newOverrides[m.catalogType] = {};
      newOverrides[m.catalogType][m.catalogKey] = m.unit_price;
    });
    setPriceOverrides(newOverrides);
    setPdfApplied(true);
  };

  return (
    <div style={{ minHeight: "100vh", padding: "20px 24px", background: c.bg, fontFamily: c.sans, color: c.text }}>

      {/* HEADER */}
      <div style={{ display: "flex", alignItems: "flex-start", justifyContent: "space-between", marginBottom: 20, paddingBottom: 18, borderBottom: `2px solid ${c.border}` }}>
        <div>
          <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent, marginBottom: 3 }}>eEquals Solar ? CR Solar LLC</div>
          <div style={{ fontSize: 21, fontWeight: 700, color: c.text, letterSpacing: "-.02em" }}>Pricing Model</div>
          <div style={{ fontSize: 10, color: c.text3, marginTop: 2 }}>Version 3.5 ? April 2026 ? Internal Use Only</div>
        </div>
        <div style={{ display: "flex", gap: 8, alignItems: "center", flexWrap: "wrap", justifyContent: "flex-end" }}>
          {cfg.badge && <span style={{ fontSize: 10, fontWeight: 700, padding: "4px 11px", borderRadius: 20, letterSpacing: ".07em", textTransform: "uppercase", background: `${cfg.badgeColor}18`, color: cfg.badgeColor, border: `1.5px solid ${cfg.badgeColor}35` }}>{lender}: {cfg.badge}</span>}
          <span style={{ fontSize: 10, fontWeight: 700, padding: "4px 11px", borderRadius: 20, letterSpacing: ".07em", textTransform: "uppercase", background: c.accentL, color: c.accent, border: `1.5px solid rgba(13,110,110,.2)` }}>Cost + Margin Calculator</span>
          <button onClick={() => setSalesView(v => !v)} title="" style={{ width: 26, height: 26, borderRadius: 6, border: `1px solid ${salesView ? c.border2 : "transparent"}`, background: "transparent", color: salesView ? c.text3 : `${c.text3}40`, cursor: "pointer", fontSize: 13, display: "flex", alignItems: "center", justifyContent: "center", flexShrink: 0 }}>?</button>
        </div>
      </div>


      {/* TAB NAVIGATION */}
      <div style={{ display: "flex", gap: 0, borderBottom: `2px solid ${c.border}`, marginBottom: 20, marginTop: 18 }}>
        {[
          { key: "calculator",   label: "Pricing Calculator", icon: "?" },
          { key: "commissions",  label: "Commissions Model",  icon: "?" },
          { key: "dealer",       label: "Dealer / Partner",   icon: "?" },
          { key: "bom",          label: "BOM Pricing",        icon: "?" },
          { key: "bos",          label: "BOS Pricing",        icon: "?" },
        ].map(tab => (
          <button key={tab.key} onClick={() => setActiveTab(tab.key)} style={{ padding: "10px 22px", border: "none", borderBottom: activeTab === tab.key ? `2.5px solid ${c.accent}` : "2.5px solid transparent", background: "transparent", color: activeTab === tab.key ? c.accent : c.text3, cursor: "pointer", fontFamily: c.sans, fontSize: 13, fontWeight: activeTab === tab.key ? 700 : 500, marginBottom: -2, display: "flex", alignItems: "center", gap: 6, transition: ".15s" }}>
            <span>{tab.icon}</span>{tab.label}
          </button>
        ))}
      </div>

      {activeTab === "calculator" && <>
      {/* ?? ROW 1 ? JOB PARAMETERS ??????????????????????????????????????????? */}
      <div style={card}>
        <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 12 }}>
          <span style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent }}>01 ? Job Parameters</span>
          {C && <span style={{ fontSize: 11, color: c.text3 }}>{C.pCnt} panels ? {(watts / 1000).toFixed(2)} kW DC</span>}
        </div>
        {cfg.note && <div style={{ background: c.warnL, border: `1.5px solid rgba(180,83,9,.2)`, borderRadius: 8, padding: "7px 12px", fontSize: 12, color: c.warn, marginBottom: 10, lineHeight: 1.5, fontWeight: 500 }}>{cfg.note}</div>}
        {/* Top row */}
        <div style={{ display: "grid", gridTemplateColumns: "0.7fr 1fr 1fr 1.2fr 1.2fr 1fr", gap: 10, alignItems: "end", marginBottom: 10 }}>
          <div>
            <div style={lbl}>State</div>
            <select style={sel_s} value={st} onChange={e => handleSt(e.target.value)}>{["IL","OH","VA","FL","MA","ME","RI","CT","NH","NJ","MD","VT","PA","TX"].map(s => <option key={s}>{s}</option>)}</select>
          </div>
          <div>
            <div style={lbl}>Lender</div>
            <select style={sel_s} value={lender} onChange={e => setLender(e.target.value)}>{LENDERS_BY_STATE[st].map(l => <option key={l} value={l}>{l === "IGS_TX" ? "IGS (Draft ? TX)" : l}</option>)}</select>
          </div>
          <div>
            <div style={lbl}>System Watts</div>
            <div style={{ display: "flex", alignItems: "center", gap: 4 }}>
              <button onClick={() => { const pw = PANELS[panelK]?.watt || 410; const cur = parseInt(wattsStr) || 0; const p = Math.round(cur / pw); if (p > 1) setWattsStr(String((p - 1) * pw)); }} style={{ width: 28, height: 32, borderRadius: 6, border: `1.5px solid ${c.border2}`, background: c.surface2, color: c.text, fontSize: 14, fontWeight: 700, cursor: "pointer", flexShrink: 0 }}>?</button>
              <input style={{ ...inp_s, padding: "6px 6px", fontSize: 12 }} type="text" inputMode="numeric" value={wattsStr} onChange={e => setWattsStr(e.target.value.replace(/[^0-9]/g, ""))} onBlur={e => { const raw = parseInt(e.target.value) || 0; const pw = PANELS[panelK]?.watt || 410; if (raw < pw) { setWattsStr(""); return; } setWattsStr(String(Math.round(raw / pw) * pw)); }} placeholder="e.g. 12300" />
              <button onClick={() => { const pw = PANELS[panelK]?.watt || 410; const cur = parseInt(wattsStr) || 0; const p = Math.round(cur / pw) || 0; setWattsStr(String((p + 1) * pw)); }} style={{ width: 28, height: 32, borderRadius: 6, border: `1.5px solid ${c.border2}`, background: c.surface2, color: c.text, fontSize: 14, fontWeight: 700, cursor: "pointer", flexShrink: 0 }}>+</button>
            </div>
            {watts > 0 && <div style={{ fontSize: 10, color: c.text3, marginTop: 2 }}>{Math.round(watts / (PANELS[panelK]?.watt || 410))}p ? {PANELS[panelK]?.watt}W</div>}
          </div>
          <div>
            <div style={lbl}>Job Type</div>
            <div style={{ ...seg_s, marginBottom: 0 }}>
              <button style={sb(jobType === "solar")} onClick={() => setJobType("solar")}>? Solar Only</button>
              <button style={sb(jobType === "storage")} onClick={() => setJobType("storage")}>? PV + ESS</button>
            </div>
          </div>
          <div>
            <div style={lbl}>Install Mode</div>
            <div style={{ ...seg_s, marginBottom: 0 }}>
              <button style={sb(laborMode === "sub")} onClick={() => setLaborMode("sub")}>Sub (SEA)</button>
              <button style={sb(laborMode === "internal")} onClick={() => setLaborMode("internal")}>Internal</button>
            </div>
          </div>
          <div>
            <div style={{ ...lbl, color: c.text, fontWeight: 800 }}>? Labor Rate (?/W)</div>
            <div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 6 }}>
              <button onClick={() => setLaborRate(r => Math.max(0.50, Math.round((r - 0.05) * 100) / 100))} style={{ width: 28, height: 28, borderRadius: 6, border: `1.5px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 16, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>?</button>
              <div style={{ background: c.accentL, border: `2px solid ${c.accent}`, borderRadius: 8, padding: "6px 16px", fontFamily: c.mono, fontSize: 20, fontWeight: 800, color: c.accent, minWidth: 72, textAlign: "center" }}>{(laborRate * 100).toFixed(0)}?</div>
              <button onClick={() => setLaborRate(r => Math.min(0.85, Math.round((r + 0.05) * 100) / 100))} style={{ width: 28, height: 28, borderRadius: 6, border: `1.5px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 16, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>+</button>
            </div>
            <div style={{ display: "flex", gap: 4 }}>
              {[0.50, 0.60, 0.75, 0.85].map(r => (
                <button key={r} onClick={() => setLaborRate(r)} style={{ flex: 1, padding: "3px 0", borderRadius: 6, border: `1px solid ${laborRate === r ? c.accent : c.border}`, background: laborRate === r ? c.accentL : c.surface2, color: laborRate === r ? c.accent : c.text3, cursor: "pointer", fontSize: 10, fontWeight: 700, fontFamily: c.sans }}>{(r * 100).toFixed(0)}?</button>
              ))}
            </div>
          </div>
        </div>
        {/* Bottom row */}
        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr 1fr 1fr", gap: 10, alignItems: "end" }}>
          <div>
            <div style={lbl}>BOM Supplied</div>
            <div style={{ ...seg_s, marginBottom: 0, border: partnerBOM ? `2px solid ${c.warn}` : `1.5px solid ${c.border}` }}>
              <button style={sb(!partnerBOM)} onClick={() => setPartnerBOM(false)}>eEquals Supplied</button>
              <button style={sb(partnerBOM, true)} onClick={() => setPartnerBOM(true)}>Partner Supplied</button>
            </div>
          </div>
          <div>
            <div style={lbl}>Domestic Content</div>
            {!cfg.dcMandatory && cfg.dcOptional && <div style={{ ...seg_s, marginBottom: 0 }}><button style={sb(dcOn)} onClick={() => setDcOn(true)}>? DC Enrolled</button><button style={sb(!dcOn)} onClick={() => setDcOn(false)}>Standard</button></div>}
            {cfg.dcMandatory && <div style={{ ...seg_s, marginBottom: 0 }}><button style={{ ...sb(true, true), cursor: "default" }}>? DC Required by {lender}</button></div>}
            {!cfg.dcMandatory && !cfg.dcOptional && <div style={{ fontSize: 11, color: c.text3, padding: "7px 0" }}>N/A for {lender}</div>}
          </div>
          {!isGroundMount && <div>
            <div style={lbl}>Array Layout</div>
            <div style={{ ...seg_s, marginBottom: 0 }}>
              <button style={sb(roofType === "flush")} onClick={() => setRoofType("flush")}>Flush</button>
              <button style={sb(roofType === "nonflush")} onClick={() => setRoofType("nonflush")}>Non-Flush</button>
            </div>
          </div>}
          {!isGroundMount && <div>
            <div style={lbl}>Detached Structure</div>
            <div style={{ ...seg_s, marginBottom: 0 }}>
              <button style={sb(detached)} onClick={() => setDetached(true)}>Yes</button>
              <button style={sb(!detached)} onClick={() => setDetached(false)}>No</button>
            </div>
          </div>}
        </div>
      </div>

      {/* ?? ROW 2 ? EQUIPMENT | DC+FEOC | EQUIPMENT COST ??????????????????? */}
      {C && C.warnings.length > 0 && (
        <div style={{ marginBottom: 14 }}>
          {C.warnings.map((w, i) => {
            const wStyle = { block: { background: c.dangerL, border: `1.5px solid rgba(185,28,28,.25)`, color: c.danger }, cost: { background: c.warnL, border: `1.5px solid rgba(180,83,9,.25)`, color: c.warn }, avl: { background: c.purpleL, border: `1.5px solid rgba(109,40,217,.2)`, color: c.purple }, market: { background: c.blueL, border: `1.5px solid rgba(26,95,180,.2)`, color: c.blue }, sh: { background: "#fef3c7", border: `1.5px solid rgba(146,113,10,.3)`, color: "#92710a" } };
            return <div key={i} style={{ display: "flex", gap: 10, alignItems: "flex-start", padding: "9px 12px", borderRadius: 8, fontSize: 12, marginBottom: 5, lineHeight: 1.5, fontWeight: 500, ...(wStyle[w.t] || wStyle.market) }}><span style={{ fontSize: 13, flexShrink: 0 }}>{w.t === "block" ? "?" : w.t === "cost" ? "?" : w.t === "avl" ? "?" : w.t === "sh" ? "?" : "?"}</span><span>{w.m}</span></div>;
          })}
        </div>
      )}

      <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 18, alignItems: "start" }}>

        {/* 02 ? Equipment */}
        <div style={card}>
          <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 14 }}>
            <span style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent }}>02 ? Equipment</span>
            <span style={{ fontSize: 10, color: c.accent, fontWeight: 600 }}>AVL + FEOC Filtered</span>
          </div>
          <div style={{ marginBottom: 12 }}>
            <div style={lbl}>Solar Panel</div>
            <select style={sel_s} value={panelK} onChange={e => setPanelK(e.target.value)}>{availPanels.map(k => <option key={k} value={k}>{PANELS[k]?.label}</option>)}</select>
          </div>
          <div style={{ marginBottom: 12 }}>
            <div style={lbl}>Inverter / Microinverter</div>
            <select style={sel_s} value={invK} onChange={e => setInvK(e.target.value)}>{availInverters.map(k => <option key={k} value={k}>{INVERTERS[k]?.label}</option>)}</select>
            <div style={{ fontSize: 11, color: c.text3, marginTop: 4 }}>Brand: <strong style={{ color: c.text }}>{invBrand === "enphase" ? "Enphase" : "SolarEdge"}</strong> ? incompatible batteries auto-blocked</div>
            {(invK === "tesla_pw3_dc" || invK === "tesla_pw3_sh") && <div style={{ fontSize: 11, color: c.accent, background: c.accentL, borderRadius: 6, padding: "6px 9px", marginTop: 5, fontWeight: 500 }}>? Tesla PW3-DC Coupled ? Inverter cost = Tesla String Inv. equiv. ($1,931.82) + MCI/RSD ($39.02 ? ?panels?3?). Battery adder covers PW3 unit, Gateway, BOS, and labor.</div>}
            {invK === "tesla_pw3_sh" && <div style={{ fontSize: 11, color: "#92710a", background: "#fef3c7", borderRadius: 6, padding: "6px 9px", marginTop: 5, fontWeight: 600 }}>? Safe Harbor SKU: 1707000-60-M-LR-2025 ? PW3 unit: $7,965.00. Must pair with LONGi Hi-MO 5 DC panel for FEOC compliance.</div>}
            {panelK === "longi_hi5_405" && <div style={{ fontSize: 11, color: "#92710a", background: "#fef3c7", borderRadius: 6, padding: "6px 9px", marginTop: 5, fontWeight: 600 }}>? LONGi Hi-MO 5 DC ? 38.5% DC ? Safe Harbor program ? IL/Lightreach only. Must pair with Tesla PW3 SH inverter for FEOC compliance. DC threshold: 45%.</div>}
          </div>
          <div>
            <div style={lbl}>Racking System{isGroundMount ? " ? ? Ground Mount Override" : ""}</div>
            <select style={{ ...sel_s, opacity: isGroundMount ? .45 : 1 }} value={rackK} onChange={e => setRackK(e.target.value)} disabled={isGroundMount}>
              {Object.entries(RACKING).filter(([, r]) => !cfg.rackingDomRequired || r.domestic).map(([k, r]) => <option key={k} value={k}>{r.label}{r.domestic ? " (Dom)" : ""}</option>)}
            </select>
            {isGroundMount && <div style={{ fontSize: 11, color: c.accent, background: c.accentL, borderRadius: 6, padding: "6px 9px", marginTop: 5, fontWeight: 500 }}>Ground Mount active ? roof racking zeroed in Equipment Cost.</div>}
            {!isGroundMount && cfg.rackingDomRequired && <div style={{ fontSize: 11, color: c.warn, marginTop: 4, fontWeight: 500 }}>? Non-domestic options hidden ? {lender} requires domestic</div>}
          </div>
        </div>

        {/* 04B ? Domestic Content + FEOC */}
        {C && (
          <div style={card}>
            <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent, marginBottom: 12 }}>04B ? Domestic Content + FEOC</div>
            <div style={{ marginBottom: 12 }}>
              <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", marginBottom: 5 }}>
                <span style={{ fontSize: 12, fontWeight: 600, color: c.text2 }}>PV System DC %</span>
                <span style={{ fontSize: 18, fontWeight: 700, fontFamily: c.mono, color: C.safeHarbored ? "#92710a" : C.pvDC >= C.dcThreshold ? c.success : c.danger }}>{C.pvDC.toFixed(1)}%</span>
              </div>
              <div style={{ height: 8, background: c.surface3, borderRadius: 4, overflow: "hidden", position: "relative" }}>
                <div style={{ height: "100%", width: `${Math.min(C.pvDC, 100)}%`, borderRadius: 4, background: C.safeHarbored ? "linear-gradient(90deg,#b38600,#d4a017)" : C.pvDC >= C.dcThreshold ? "linear-gradient(90deg,#16a34a,#22c55e)" : "linear-gradient(90deg,#dc2626,#ef4444)", transition: "width .4s" }} />
                <div style={{ position: "absolute", top: 0, bottom: 0, width: 2, background: "rgba(0,0,0,.2)", left: `${C.dcThreshold}%` }} />
              </div>
              <div style={{ display: "flex", justifyContent: "space-between", fontSize: 10, color: c.text3, marginTop: 3 }}>
                <span>0%</span>
                <span style={{ fontWeight: 600 }}>
                  {C.isSHPanel || C.isSHInv
                    ? `${C.dcThreshold}% ? ? Safe Harbor threshold`
                    : C.safeHarbored
                      ? `${C.dcThreshold}% ? ? Safe Harbor`
                      : `${C.dcThreshold}% threshold`}
                </span>
                <span>100%</span>
              </div>
            </div>
            <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 7, marginBottom: 12 }}>
              {[["Module", C.modDC], ["Inverter", C.invDCPct], ["Racking", C.isGroundMount ? null : C.rackDCPct]].map(([l, v]) => (
                <div key={l} style={{ background: c.surface2, borderRadius: 7, padding: "8px 9px", textAlign: "center" }}>
                  <div style={{ fontSize: 10, color: c.text3, fontWeight: 600, textTransform: "uppercase", letterSpacing: ".06em", marginBottom: 2 }}>{l}</div>
                  <div style={{ fontSize: 14, fontWeight: 700, fontFamily: c.mono, color: C.safeHarbored ? "#92710a" : v === null ? "#8a96aa" : v > 0 ? c.success : c.text3 }}>{v === null ? "?" : `${v.toFixed(1)}%`}</div>
                </div>
              ))}
            </div>
            {C.storageMode && (
              <div style={{ marginBottom: 10, paddingTop: 8, borderTop: `1px solid ${c.border}` }}>
                <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".12em", textTransform: "uppercase", color: c.text3, marginBottom: 7 }}>Battery DC</div>
                {C.batPending
                  ? <div style={{ background: c.surface3, border: `1.5px dashed ${c.border2}`, borderRadius: 7, padding: "9px 12px", fontSize: 12, color: c.text3, textAlign: "center" }}>? Pending ? select a battery adder in Section 04</div>
                  : C.safeHarbored
                    ? <div style={{ background: "#fef9ec", border: "1.5px solid rgba(180,135,9,.25)", borderRadius: 7, padding: "9px 12px" }}><div style={{ fontSize: 13, fontWeight: 600, color: "#92710a" }}>? Safe Harbored ? 2026 rules do not apply</div></div>
                    : <div style={{ background: C.batDCEligible ? c.successL : c.dangerL, border: `1.5px solid ${C.batDCEligible ? "rgba(22,101,52,.2)" : "rgba(185,28,28,.2)"}`, borderRadius: 7, padding: "9px 12px" }}><div style={{ fontSize: 13, fontWeight: 600, color: C.batDCEligible ? c.success : c.danger }}>{C.batDCNote}</div></div>
                }
              </div>
            )}
            {[["FEOC ? PV System", `?${C.feocPVThreshold}%`, C.safeHarbored ? "sh" : C.feocPVPass ? "pass" : "fail", C.safeHarbored ? "? Safe Harbored" : C.feocPVPass ? "? PASS" : "? FAIL"], ...(C.storageMode ? [["FEOC ? Battery", "?55%", C.safeHarbored ? "sh" : C.batPending ? "pend" : C.feocBatPass ? "pass" : "fail", C.safeHarbored ? "? Safe Harbored" : C.batPending ? "? Pending" : C.feocBatPass ? "? PASS" : "? FAIL"]] : [])].map(([l, r, t, badge]) => {
              const fs = { pass: { background: c.successL, color: c.success }, fail: { background: c.dangerL, color: c.danger }, pend: { background: c.surface3, color: c.text3, border: `1.5px dashed ${c.border2}` }, sh: { background: "#fef9ec", color: "#92710a", border: "1.5px solid rgba(180,135,9,.25)" } };
              return <div key={l} style={{ display: "flex", justifyContent: "space-between", alignItems: "center", padding: "7px 11px", borderRadius: 7, fontSize: 12, fontWeight: 600, marginBottom: 7, ...fs[t] }}><span>{l} ({r})</span><span style={{ fontSize: 10, fontWeight: 700, padding: "2px 8px", borderRadius: 20, background: "rgba(0,0,0,.08)" }}>{badge}</span></div>;
            })}
            <div style={{ fontSize: 10, color: c.text3, marginTop: 6, lineHeight: 1.5 }}>IRS Notice 2025-08 APC tables. FEOC 2026: 40% PV, 55% Battery.{C.safeHarbored ? " ? Safe harbor active." : ""}{C.isSHPanel && C.isSHInv ? " ? LONGi + Tesla PW3 SH: Safe harbor pairing ? FEOC resolved. 45% DC threshold applies. PV + ESS holdbacks eligible." : C.isTeslaInv ? " ? Tesla PW3: Inverter contributes 0% to PV DC. ESS battery is DC-eligible. Both PV + ESS are FEOC compliant." : ""}</div>
          </div>
        )}

        {/* 04A ? Equipment Cost */}
        <div style={card}>
          <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent, marginBottom: 14 }}>03 ? Equipment Cost</div>
          {C ? (
            <>
              {partnerBOM ? (
                <div style={{ background: c.warnL, border: `1.5px solid rgba(180,83,9,.2)`, borderRadius: 8, padding: "9px 12px", fontSize: 12, color: c.warn, fontWeight: 600, lineHeight: 1.6 }}>? Partner Supplied BOM ? equipment costs zeroed.</div>
              ) : (
                <>
                  <div style={drow}>
                    <span style={{ color: c.text2 }}>Panels ({C.pCnt} ? {fmt(panel?.price || 0)}){eqAdj.panel !== 0 && <span style={{ fontSize: 9, color: c.warn, marginLeft: 5 }}>{eqAdj.panel > 0 ? "+" : ""}{eqAdj.panel.toFixed(2)}/W</span>}</span>
                    <span style={{ display: "flex", alignItems: "center", gap: 4 }}>
                      <button onClick={() => setEqAdj(p => ({...p, panel: Math.round((p.panel-0.01)*1000)/1000}))} style={{ width:16,height:16,borderRadius:3,border:`1px solid ${c.border2}`,background:c.surface,color:c.text,fontSize:11,fontWeight:700,cursor:"pointer",lineHeight:1 }}>?</button>
                      <button onClick={() => setEqAdj(p => ({...p, panel: Math.round((p.panel+0.01)*1000)/1000}))} style={{ width:16,height:16,borderRadius:3,border:`1px solid ${c.border2}`,background:c.surface,color:c.text,fontSize:11,fontWeight:700,cursor:"pointer",lineHeight:1 }}>+</button>
                      {eqAdj.panel !== 0 && <button onClick={() => setEqAdj(p => ({...p, panel:0}))} style={{ fontSize:9,color:c.text3,background:"none",border:"none",cursor:"pointer",padding:"0 2px" }}>reset</button>}
                      <span style={{ fontFamily:c.mono, fontSize:12, color: eqAdj.panel!==0?c.warn:c.text, marginLeft:2 }}><span style={ppwBadge}>{fmtPPW(C.panelCost/C.W)}</span>{fmt(C.panelCost)}</span>
                    </span>
                  </div>
                  {C.isTeslaInv
                    ? <div style={drow}><span style={{ color: c.text2 }}>Inverter ? Tesla Str. Inv. equiv. (1538000-45-X) + MCI/RSD ? {C.pCnt} panels</span><span style={{ display: "flex", alignItems: "center", gap: 8, fontFamily: c.mono, fontSize: 12, color: c.text }}><span style={ppwBadge}>{fmtPPW(C.teslaInvCost / C.W)}</span>{fmt(C.teslaInvCost)}</span></div>
                    : C.invCost > 0 && <div style={drow}>
                      <span style={{ color: c.text2 }}>{inv?.perPanel ? `Micros (${C.pCnt} ? ${fmt(inv?.price || 0)})` : "Inverter (system)"}{eqAdj.inv !== 0 && <span style={{ fontSize: 9, color: c.warn, marginLeft: 5 }}>{eqAdj.inv > 0 ? "+" : ""}{eqAdj.inv.toFixed(2)}/W</span>}</span>
                      <span style={{ display: "flex", alignItems: "center", gap: 4 }}>
                        <button onClick={() => setEqAdj(p => ({...p, inv: Math.round((p.inv-0.01)*1000)/1000}))} style={{ width:16,height:16,borderRadius:3,border:`1px solid ${c.border2}`,background:c.surface,color:c.text,fontSize:11,fontWeight:700,cursor:"pointer",lineHeight:1 }}>?</button>
                        <button onClick={() => setEqAdj(p => ({...p, inv: Math.round((p.inv+0.01)*1000)/1000}))} style={{ width:16,height:16,borderRadius:3,border:`1px solid ${c.border2}`,background:c.surface,color:c.text,fontSize:11,fontWeight:700,cursor:"pointer",lineHeight:1 }}>+</button>
                        {eqAdj.inv !== 0 && <button onClick={() => setEqAdj(p => ({...p, inv:0}))} style={{ fontSize:9,color:c.text3,background:"none",border:"none",cursor:"pointer",padding:"0 2px" }}>reset</button>}
                        <span style={{ fontFamily:c.mono, fontSize:12, color: eqAdj.inv!==0?c.warn:c.text, marginLeft:2 }}><span style={ppwBadge}>{fmtPPW(C.invCost/C.W)}</span>{fmt(C.invCost)}</span>
                      </span>
                    </div>
                  }
                  {C.optCost > 0 && <div style={drow}><span style={{ color: c.text2 }}>Optimizers ({C.pCnt} ? {fmt(inv?.optimizerPrice || 0)})</span><span style={{ display: "flex", alignItems: "center", gap: 8, fontFamily: c.mono, fontSize: 12, color: c.text }}><span style={ppwBadge}>{fmtPPW(C.optCost / C.W)}</span>{fmt(C.optCost)}</span></div>}
                  {inv?.brand === "enphase" && <div style={drow}>
                    <span style={{ color: c.text2 }}>Combiner w/ Gateway Cell (IQ5C){eqAdj.comb !== 0 && <span style={{ fontSize: 9, color: c.warn, marginLeft: 5 }}>{eqAdj.comb > 0 ? "+" : ""}{eqAdj.comb.toFixed(3)}/W</span>}</span>
                    <span style={{ display: "flex", alignItems: "center", gap: 4 }}>
                      <button onClick={() => setEqAdj(p => ({...p, comb: Math.round((p.comb-0.005)*1000)/1000}))} style={{ width:16,height:16,borderRadius:3,border:`1px solid ${c.border2}`,background:c.surface,color:c.text,fontSize:11,fontWeight:700,cursor:"pointer",lineHeight:1 }}>?</button>
                      <button onClick={() => setEqAdj(p => ({...p, comb: Math.round((p.comb+0.005)*1000)/1000}))} style={{ width:16,height:16,borderRadius:3,border:`1px solid ${c.border2}`,background:c.surface,color:c.text,fontSize:11,fontWeight:700,cursor:"pointer",lineHeight:1 }}>+</button>
                      {eqAdj.comb !== 0 && <button onClick={() => setEqAdj(p => ({...p, comb:0}))} style={{ fontSize:9,color:c.text3,background:"none",border:"none",cursor:"pointer",padding:"0 2px" }}>reset</button>}
                      <span style={{ fontFamily:c.mono, fontSize:12, color: eqAdj.comb!==0?c.warn:c.text, marginLeft:2 }}><span style={ppwBadge}>{fmtPPW(C.combCost/C.W)}</span>{fmt(C.combCost)}</span>
                    </span>
                  </div>}
                  {C.isGroundMount
                    ? <div style={{ ...drow, color: c.text3 }}><span style={{ fontStyle: "italic" }}>Roof Racking ? excluded (Ground Mount)</span><span style={{ fontFamily: c.mono }}>$0.00</span></div>
                    : <div style={drow}>
                      <span style={{ color: c.text2 }}>Racking ({rack?.ppw?.toFixed(3)}/W){eqAdj.rack !== 0 && <span style={{ fontSize: 9, color: c.warn, marginLeft: 5 }}>{eqAdj.rack > 0 ? "+" : ""}{eqAdj.rack.toFixed(3)}/W</span>}</span>
                      <span style={{ display: "flex", alignItems: "center", gap: 4 }}>
                        <button onClick={() => setEqAdj(p => ({...p, rack: Math.round((p.rack-0.005)*1000)/1000}))} style={{ width:16,height:16,borderRadius:3,border:`1px solid ${c.border2}`,background:c.surface,color:c.text,fontSize:11,fontWeight:700,cursor:"pointer",lineHeight:1 }}>?</button>
                        <button onClick={() => setEqAdj(p => ({...p, rack: Math.round((p.rack+0.005)*1000)/1000}))} style={{ width:16,height:16,borderRadius:3,border:`1px solid ${c.border2}`,background:c.surface,color:c.text,fontSize:11,fontWeight:700,cursor:"pointer",lineHeight:1 }}>+</button>
                        {eqAdj.rack !== 0 && <button onClick={() => setEqAdj(p => ({...p, rack:0}))} style={{ fontSize:9,color:c.text3,background:"none",border:"none",cursor:"pointer",padding:"0 2px" }}>reset</button>}
                        <span style={{ fontFamily:c.mono, fontSize:12, color: eqAdj.rack!==0?c.warn:c.text, marginLeft:2 }}><span style={ppwBadge}>{fmtPPW(C.rackCost/C.W)}</span>{fmt(C.rackCost)}</span>
                      </span>
                    </div>
                  }
                  {C.laborMode === "internal"
                    ? <div style={drow}>
                      <span style={{ color: c.text2 }}>BOS ($0.14/W + 15% cushion){eqAdj.bos !== 0 && <span style={{ fontSize: 9, color: c.warn, marginLeft: 5 }}>{eqAdj.bos > 0 ? "+" : ""}{eqAdj.bos.toFixed(3)}/W</span>}</span>
                      <span style={{ display: "flex", alignItems: "center", gap: 4 }}>
                        <button onClick={() => setEqAdj(p => ({...p, bos: Math.round((p.bos-0.01)*1000)/1000}))} style={{ width:16,height:16,borderRadius:3,border:`1px solid ${c.border2}`,background:c.surface,color:c.text,fontSize:11,fontWeight:700,cursor:"pointer",lineHeight:1 }}>?</button>
                        <button onClick={() => setEqAdj(p => ({...p, bos: Math.round((p.bos+0.01)*1000)/1000}))} style={{ width:16,height:16,borderRadius:3,border:`1px solid ${c.border2}`,background:c.surface,color:c.text,fontSize:11,fontWeight:700,cursor:"pointer",lineHeight:1 }}>+</button>
                        {eqAdj.bos !== 0 && <button onClick={() => setEqAdj(p => ({...p, bos:0}))} style={{ fontSize:9,color:c.text3,background:"none",border:"none",cursor:"pointer",padding:"0 2px" }}>reset</button>}
                        <span style={{ fontFamily:c.mono, fontSize:12, color: eqAdj.bos!==0?c.warn:c.text, marginLeft:2 }}><span style={ppwBadge}>{fmtPPW(C.bosCost/C.W)}</span>{fmt(C.bosCost)}</span>
                      </span>
                    </div>
                    : <div style={drow}>
                      <span style={{ color: c.text3, fontStyle: "italic" }}>BOS ? included in sub rate{eqAdj.bos !== 0 && <span style={{ fontSize: 9, color: c.warn, marginLeft: 5, fontStyle: "normal" }}>{eqAdj.bos > 0 ? "+" : ""}{eqAdj.bos.toFixed(3)}/W</span>}</span>
                      <span style={{ display: "flex", alignItems: "center", gap: 4 }}>
                        <button onClick={() => setEqAdj(p => ({...p, bos: Math.round((p.bos-0.01)*1000)/1000}))} style={{ width:16,height:16,borderRadius:3,border:`1px solid ${c.border2}`,background:c.surface,color:c.text,fontSize:11,fontWeight:700,cursor:"pointer",lineHeight:1 }}>?</button>
                        <button onClick={() => setEqAdj(p => ({...p, bos: Math.round((p.bos+0.01)*1000)/1000}))} style={{ width:16,height:16,borderRadius:3,border:`1px solid ${c.border2}`,background:c.surface,color:c.text,fontSize:11,fontWeight:700,cursor:"pointer",lineHeight:1 }}>+</button>
                        {eqAdj.bos !== 0 && <button onClick={() => setEqAdj(p => ({...p, bos:0}))} style={{ fontSize:9,color:c.text3,background:"none",border:"none",cursor:"pointer",padding:"0 2px" }}>reset</button>}
                        <span style={{ fontFamily:c.mono, fontSize:12, color: eqAdj.bos!==0?c.warn:c.text3, marginLeft:2 }}>{fmt(C.bosCost)}</span>
                      </span>
                    </div>
                  }
                </>
              )}
              {C.shFee > 0 && <div style={{ ...drow, color: c.warn }}><span>{C.shFeeLabel}</span><span style={{ fontFamily: c.mono }}>{fmt(C.shFee)}</span></div>}
              {C.salesTax > 0 && <div style={{ ...drow, color: c.blue }}><span>Sales Tax ({(C.taxRate * 100).toFixed(1)}% ? Cash ? {st})</span><span style={{ fontFamily: c.mono }}>{fmt(C.salesTax)}</span></div>}
              <div style={{ background: `linear-gradient(135deg,${c.accentL},rgba(230,244,244,.5))`, border: `1.5px solid rgba(13,110,110,.2)`, borderRadius: 10, padding: "12px 14px", marginTop: 10, display: "flex", justifyContent: "space-between", alignItems: "center" }}>
                <div>
                  <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".12em", textTransform: "uppercase", color: c.accent, marginBottom: 2 }}>Total Equipment</div>
                  <div style={{ fontSize: 11, color: c.text3, fontFamily: c.mono }}>{fmtPPW(C.equipTotalPPW)}</div>
                </div>
                <div style={{ fontSize: 24, fontWeight: 700, color: c.accent }}>{fmt(C.equipTotal)}</div>
              </div>
            </>
          ) : <div style={{ color: c.text3, fontSize: 13, padding: "6px 0" }}>Configure job parameters above.</div>}
        </div>

      </div>{/* end row 2 grid */}

      {/* ?? ROW 3 ? ADDERS ?????????????????????????????????????????????????? */}
      <div style={card}>
        <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 14 }}>
          <span style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent }}>04 ? Adders</span>
          <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
            <span style={{ fontSize: 11, color: c.text3 }}>Toggle ? ? for detail</span>
            <button onClick={() => setAdderSecExpanded(v => !v)} style={{ padding: "4px 12px", borderRadius: 20, border: `1px solid ${c.border2}`, background: adderSecExpanded ? c.accentL : c.surface2, color: adderSecExpanded ? c.accent : c.text3, fontFamily: c.sans, fontSize: 11, fontWeight: 700, cursor: "pointer" }}>
              {adderSecExpanded ? "? Collapse" : "? Show All Sections"}
            </button>
          </div>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 5 }}>
          {/* Dynamic Redline Adders section */}
          {redlineSet.size > 0 && (
            <React.Fragment>
              <div style={{ fontSize: 9, fontWeight: 700, letterSpacing: ".14em", textTransform: "uppercase", color: c.success, padding: "6px 0 3px 1px", gridColumn: "1/-1", marginTop: 0 }}>
                ? Redline Adders <span style={{ fontSize: 9, fontWeight: 600, marginLeft: 6, color: c.success, opacity: .7 }}>? included in redline floor ? {redlineSet.size} active</span>
              </div>
              {[...redlineSet].map(key => {
                const a = ADDER_MAP[key]; if (!a) return null;
                return (
                  <div key={`rl_${key}`} style={{ borderRadius: 7, background: c.successL, border: "1.5px solid rgba(22,101,52,.3)", padding: "5px 8px", display: "flex", alignItems: "center", justifyContent: "space-between", gap: 6 }}>
                    <span style={{ fontSize: 11, color: c.success, fontWeight: 600, flex: 1 }}>{a.label}</span>
                    <button onClick={() => setRedlineSet(prev => { const n = new Set(prev); n.delete(key); return n; })} style={{ fontSize: 9, color: c.success, background: "none", border: "none", cursor: "pointer", padding: "0 2px", fontWeight: 700 }} title="Remove from redline">? remove</button>
                  </div>
                );
              })}
            </React.Fragment>
          )}
          {ADDER_SECTIONS.filter(sec => {
            if (adderSecExpanded) return true;
            // Always show electrical and battery sections; collapse the rest
            const alwaysVisible = ["Electrical Adders", "Enphase Batteries", "SolarEdge Batteries", "Tesla Batteries ? DC Coupled", "Tesla Batteries ? AC Coupled"];
            // Also show if any adder in this section is currently selected
            const hasActive = sec.keys.some(k => sel[k]);
            return alwaysVisible.includes(sec.title) || hasActive;
          }).map(sec => (
            <React.Fragment key={sec.title}>
              <div style={{ fontSize: 9, fontWeight: 700, letterSpacing: ".14em", textTransform: "uppercase", color: c.text3, padding: "6px 0 3px 1px", gridColumn: "1/-1", borderTop: `1px solid ${c.border}`, marginTop: 2 }}>
                {sec.title}
              </div>
              {sec.keys.map(key => {
                const a = ADDER_MAP[key]; if (!a) return null;
                const isOn = !!sel[a.key], isExp = !!expanded[a.key];
                const isTeslaDCInv    = invK === "tesla_pw3_dc" || invK === "tesla_pw3_sh";
                const teslaLocked    = !!a.isTeslaLead && isTeslaDCInv;
                const requiresTesla  = (a.isTeslaLead || a.key === "bat_texp" || a.key === "bat_tpwx") && !isTeslaDCInv;
                const blockedByTesla = (a.isTeslaACLead || a.isTeslaACPWX || a.key === "bat_tace") && isTeslaDCInv;
                const blockedLender  = a.blockLenders?.includes(lender);
                const blockedInv     = a.blockInvBrand && a.blockInvBrand === invBrand;
                const isInRedline    = redlineSet.has(a.key);
                const blocked        = blockedLender || blockedInv || requiresTesla || blockedByTesla;
                const W  = watts || 11500;
                const pC = Math.ceil(W / (PANELS[panelK]?.watt || 410));
                let cost, list;
                if (a.isTeslaACLead || a.isTeslaACPWX || (a.isTeslaExp && a.key === "bat_tace")) { cost = calcTeslaACCost(a, laborMode); list = a.list ?? null; }
                else if (a.isTeslaLead || a.isTeslaExp || a.isTeslaPWX) { cost = calcTeslaCost(a, laborMode, pC, INVERTERS[invK]?.pw3UnitPrice || 7388.88); list = a.list ?? null; }
                else if (partnerBOM && a.isBattery)                  { cost = laborMode === "sub" ? (a.seaPartner || 0) : (a.intPartner || 0); list = a.listPartner ?? null; }
                else                                                  { cost = adderCostFor(a, laborMode, W, trenchFt, boringQuote, boringFt, isGroundMount, redlineSet); list = adderListFor(a, W, trenchFt, boringQuote, boringFt, redlineSet); }
                const q       = a.isQtyAdder ? (qty[a.key] || 1) : 1;
                const isBad   = isOn && !blocked && list != null && (cost || 0) * q > (list * q);
                const d       = a.detail;
                const blockReason = requiresTesla ? "Requires Tesla PW3-DC Coupled in Section 02" : blockedByTesla ? "? AC Coupled ? incompatible with Tesla DC-Coupled inverter" : blockedLender ? `? ${lender} ? not approved` : blockedInv ? `? Incompatible with ${invBrand === "enphase" ? "Enphase" : "SolarEdge"} inverter` : "";

                return (
                  <div key={a.key} style={{ borderRadius: 7, overflow: "hidden", border: `1.5px solid ${blocked ? c.border : isBad ? "rgba(180,83,9,.4)" : isOn ? "rgba(13,110,110,.4)" : c.border}`, opacity: blocked ? .35 : 1, pointerEvents: blocked ? "none" : "auto", background: c.surface, boxShadow: isOn && !blocked ? "0 0 0 2px rgba(13,110,110,.06)" : "none" }}>
                    {/* Adder header row */}
                    <div style={{ display: "flex", alignItems: "flex-start", gap: 6, padding: "6px 8px", cursor: teslaLocked ? "default" : "pointer", background: isOn ? (isBad ? c.warnL : c.accentL) : c.surface, userSelect: "none" }} onClick={() => !blocked && !teslaLocked && toggle(a.key)}>
                      <div style={{ width: 13, height: 13, borderRadius: 3, border: `1.5px solid ${isOn ? (isBad ? c.warn : c.accent) : c.border2}`, display: "flex", alignItems: "center", justifyContent: "center", flexShrink: 0, marginTop: 1, background: isOn ? (isBad ? c.warn : c.accent) : c.surface }}>
                        {isOn && !blocked && <span style={{ fontSize: 8, color: "#fff", fontWeight: 700 }}>?</span>}
                      </div>
                      <div style={{ flex: 1, minWidth: 0 }}>
                        <div style={{ fontSize: 11, color: isOn && !blocked ? (isBad ? c.warn : c.accent) : c.text2, fontWeight: isOn && !blocked ? 600 : 500, lineHeight: 1.3 }}>
                          {a.label}
                          {teslaLocked && <span style={{ fontSize: 8, marginLeft: 5, color: c.accent, fontWeight: 700, background: c.accentL, padding: "1px 4px", borderRadius: 3, border: `1px solid rgba(13,110,110,.2)` }}>AUTO</span>}
                          {isInRedline && <span style={{ fontSize: 8, marginLeft: 5, color: "#166534", fontWeight: 700, background: "#dcfce7", padding: "1px 4px", borderRadius: 3, border: "1px solid rgba(22,101,52,.2)" }}>REDLINE</span>}
                        </div>
                        {blocked && <div style={{ fontSize: 9, color: c.danger, marginTop: 1 }}>{blockReason}</div>}
                        {isOn && !blocked && !a.isTrench && !a.isBoring && !isInRedline && <div style={{ fontSize: 9, color: isBad ? c.warn : c.text3, marginTop: 1, fontFamily: c.mono }}>{cost != null ? `${fmt((cost || 0) * q)} cost` : "? pending"}{list != null ? ` ? ${fmt(list * q)} list` : ""}</div>}
                        {isOn && !blocked && isInRedline && <div style={{ fontSize: 9, color: c.success, marginTop: 1, fontFamily: c.mono }}>{fmt(cost || 0)} ? adds to redline floor</div>}
                        {isOn && !blocked && a.isTrench && <div style={{ fontSize: 9, color: c.text3, marginTop: 1, fontFamily: c.mono }}>{trenchFt}ft ? {laborMode === "sub" || laborMode === "sea" ? `SEA ${fmt((a.seaBase || 0) + a.seaPFt * trenchFt)}` : `Int ${fmt(a.intPFt * trenchFt)}`} ? List {fmt(a.listBase + a.listPFt * trenchFt)}</div>}
                        {isOn && !blocked && a.isBoringBase && <div style={{ fontSize: 9, color: c.text3, marginTop: 1, fontFamily: c.mono }}>Quote ${boringQuote.toFixed(2)} ? List {fmt(boringQuote + 500)}</div>}
                        {isOn && !blocked && a.isBoringMaterial && <div style={{ fontSize: 9, color: c.text3, marginTop: 1, fontFamily: c.mono }}>{boringFt}ft ? {fmt(cost)} cost ? {fmt(list)} list</div>}
                      </div>
                      <button
                        title={isInRedline ? "Remove from redline floor" : "Add to redline floor"}
                        onClick={e => { e.stopPropagation(); setRedlineSet(prev => { const n = new Set(prev); n.has(a.key) ? n.delete(a.key) : n.add(a.key); return n; }); }}
                        style={{ flexShrink: 0, width: 17, height: 17, borderRadius: 4, border: `1.5px solid ${isInRedline ? "rgba(22,101,52,.4)" : c.border}`, background: isInRedline ? c.successL : c.surface2, color: isInRedline ? c.success : c.text3, cursor: "pointer", fontSize: 9, display: "flex", alignItems: "center", justifyContent: "center", marginTop: 1, fontWeight: isInRedline ? 700 : 400 }}>
                        ?
                      </button>
                      {d && <button style={{ flexShrink: 0, width: 17, height: 17, borderRadius: 4, border: `1.5px solid ${c.border}`, background: isExp ? c.accentL : c.surface2, color: isExp ? c.accent : c.text3, cursor: "pointer", fontSize: 9, display: "flex", alignItems: "center", justifyContent: "center", marginTop: 1 }} onClick={e => { e.stopPropagation(); toggleExp(a.key); }}>{isExp ? "?" : "?"}</button>}
                    </div>
                    {/* Inline inputs */}
                    {isOn && !blocked && a.isBoringBase && (
                      <div style={{ display: "flex", alignItems: "center", gap: 6, padding: "5px 8px", background: c.accentL, borderTop: `1px solid rgba(13,110,110,.15)` }}>
                        <span style={{ fontSize: 10, color: c.accent, fontWeight: 600, whiteSpace: "nowrap" }}>Quote $:</span>
                        <input style={{ background: c.surface, border: `1.5px solid rgba(13,110,110,.3)`, color: c.accent, padding: "3px 6px", borderRadius: 5, fontFamily: c.mono, fontSize: 12, fontWeight: 700, outline: "none", width: 80, textAlign: "center" }} type="text" inputMode="decimal" value={boringQuoteStr} onChange={e => setBoringQuoteStr(e.target.value.replace(/[^0-9.]/g, ""))} onBlur={e => { const n = parseFloat(e.target.value) || 0; setBoringQuoteStr(String(n)); }} />
                        <span style={{ fontSize: 9, color: c.text3, fontFamily: c.mono }}>List: {fmt((parseFloat(boringQuoteStr) || 0) + 500)}</span>
                      </div>
                    )}
                    {isOn && !blocked && a.isBoringMaterial && (
                      <div style={{ display: "flex", alignItems: "center", gap: 6, padding: "5px 8px", background: c.accentL, borderTop: `1px solid rgba(13,110,110,.15)` }}>
                        <span style={{ fontSize: 10, color: c.accent, fontWeight: 600, whiteSpace: "nowrap" }}>Footage:</span>
                        <input style={{ background: c.surface, border: `1.5px solid rgba(13,110,110,.3)`, color: c.accent, padding: "3px 6px", borderRadius: 5, fontFamily: c.mono, fontSize: 12, fontWeight: 700, outline: "none", width: 60, textAlign: "center" }} type="text" inputMode="numeric" value={boringFtStr} onChange={e => setBoringFtStr(e.target.value.replace(/[^0-9]/g, ""))} onBlur={e => { const n = parseInt(e.target.value) || 100; setBoringFtStr(String(n)); }} />
                        <span style={{ fontSize: 9, color: c.text3, fontFamily: c.mono }}>{boringFt}ft ? ${a.seaPFt}/ft ? ${a.listPFt}/ft list</span>
                      </div>
                    )}
                    {isOn && !blocked && a.isQtyAdder && (
                      <div style={{ display: "flex", alignItems: "center", gap: 6, padding: "5px 8px", background: c.accentL, borderTop: `1px solid rgba(13,110,110,.15)` }}>
                        <span style={{ fontSize: 10, color: c.accent, fontWeight: 600, whiteSpace: "nowrap" }}>Qty:</span>
                        <button onClick={() => setQtyFor(a.key, (qty[a.key] || 1) - 1)} style={{ width: 20, height: 20, borderRadius: 5, border: `1.5px solid rgba(13,110,110,.3)`, background: c.surface, color: c.accent, fontSize: 13, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>?</button>
                        <span style={{ fontFamily: c.mono, fontSize: 13, fontWeight: 700, color: c.accent, minWidth: 16, textAlign: "center" }}>{qty[a.key] || 1}</span>
                        <button onClick={() => setQtyFor(a.key, (qty[a.key] || 1) + 1)} style={{ width: 20, height: 20, borderRadius: 5, border: `1.5px solid rgba(13,110,110,.3)`, background: c.surface, color: c.accent, fontSize: 13, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>+</button>
                      </div>
                    )}
                    {isOn && !blocked && a.isTrench && (
                      <div style={{ display: "flex", alignItems: "center", gap: 6, padding: "5px 8px", background: c.accentL, borderTop: `1px solid rgba(13,110,110,.15)` }}>
                        <span style={{ fontSize: 10, color: c.accent, fontWeight: 600, whiteSpace: "nowrap" }}>Footage:</span>
                        <input style={{ background: c.surface, border: `1.5px solid rgba(13,110,110,.3)`, color: c.accent, padding: "3px 6px", borderRadius: 5, fontFamily: c.mono, fontSize: 12, fontWeight: 700, outline: "none", width: 60, textAlign: "center" }} type="text" inputMode="numeric" value={trenchFtStr} onChange={e => setTrenchFtStr(e.target.value.replace(/[^0-9]/g, ""))} onBlur={e => { const n = parseInt(e.target.value) || 120; setTrenchFtStr(String(n)); }} />
                        <span style={{ fontSize: 9, color: c.text3, fontFamily: c.mono }}>{trenchFt}ft ? {laborMode === "internal" ? `Int $${(a.intPFt * trenchFt).toFixed(0)}` : `Sub $${(a.seaPFt * trenchFt).toFixed(0)}`}</span>
                      </div>
                    )}
                    {/* Expand detail */}
                    {isExp && d && (
                      <div style={{ background: c.surface2, borderTop: `1px solid ${c.border}`, padding: 9 }}>
                        <p style={{ fontSize: 11, color: c.text2, lineHeight: 1.5, marginBottom: 8 }}>{d.summary}</p>
                        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 5, marginBottom: 8 }}>
                          {[["Crew", d.crew], ["Truck Roll", d.truckRoll ? "Yes (~$500?$1k)" : "No"], ["SEA Labor", d.hours.sea], ["Internal", d.hours.internal]].map(([l, v]) => (
                            <div key={l} style={{ background: c.surface, border: `1px solid ${c.border}`, borderRadius: 6, padding: "5px 7px" }}>
                              <div style={{ fontSize: 9, color: c.text3, fontWeight: 700, textTransform: "uppercase", letterSpacing: ".06em", marginBottom: 1 }}>{l}</div>
                              <div style={{ fontSize: 11, color: c.text, fontWeight: 500 }}>{v}</div>
                            </div>
                          ))}
                        </div>
                        {d.bom && d.bom.length > 0 && (
                          <>
                            <div style={{ fontSize: 9, color: c.text3, fontWeight: 700, textTransform: "uppercase", letterSpacing: ".06em", marginBottom: 4 }}>Bill of Materials</div>
                            {d.bom.map((b, i) => <div key={i} style={{ display: "flex", justifyContent: "space-between", padding: "2px 0", borderBottom: `1px solid ${c.border}`, fontSize: 10 }}><span style={{ color: c.text2 }}>{b.item}</span><span style={{ fontFamily: c.mono, color: c.text, fontWeight: 500 }}>{b.cost}</span></div>)}
                          </>
                        )}
                        {d.note && <div style={{ marginTop: 7, padding: "6px 8px", borderRadius: 6, fontSize: 10, lineHeight: 1.5, fontWeight: 500, ...(d.noteType === "warn" ? { background: c.warnL, borderLeft: `3px solid ${c.warn}`, color: c.warn } : { background: c.successL, borderLeft: `3px solid ${c.success}`, color: c.success }) }}>{d.note}</div>}
                        {d.rec && <div style={{ marginTop: 5, fontSize: 10, fontWeight: 700, color: d.rec.includes("?") ? c.danger : c.accent }}>? {d.rec}</div>}
                      </div>
                    )}
                  </div>
                );
              })}
            </React.Fragment>
          ))}
          {/* Collapsed hint */}
          {!adderSecExpanded && (() => {
            const hiddenSecs = ADDER_SECTIONS.filter(sec => {
              const alwaysVisible = ["Electrical Adders", "Enphase Batteries", "SolarEdge Batteries", "Tesla Batteries ? DC Coupled", "Tesla Batteries ? AC Coupled"];
              const hasActive = sec.keys.some(k => sel[k]);
              return !alwaysVisible.includes(sec.title) && !hasActive;
            });
            return hiddenSecs.length > 0 ? (
              <div style={{ gridColumn: "1/-1", marginTop: 8, padding: "8px 12px", background: c.surface2, border: `1px dashed ${c.border2}`, borderRadius: 8, display: "flex", alignItems: "center", justifyContent: "space-between" }}>
                <span style={{ fontSize: 11, color: c.text3 }}>{hiddenSecs.map(s => s.title).join(" ? ")} ? hidden</span>
                <button onClick={() => setAdderSecExpanded(true)} style={{ fontSize: 11, color: c.accent, background: "none", border: "none", cursor: "pointer", fontWeight: 700, padding: 0 }}>Show All ?</button>
              </div>
            ) : null;
          })()}
        </div>
      </div>
      <div>

        {/* 05 ? Adder Income */}
        {C && (
          <div style={card}>
            <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 14 }}>
              <span style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent }}>05 ? Adder Income</span>
              <span style={{ fontSize: 11, color: c.text3 }}>Cost ? List ? Margin</span>
            </div>
            {C.adderRows.filter(r => !r.isRedline).length > 0 ? (
              <>
                <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 12 }}>
                  <thead><tr>{(salesView ? ["Adder", "List Price"] : ["Adder", "Cost", "List", "Margin"]).map(h => <th key={h} style={{ textAlign: "left", padding: "6px 8px", color: c.text3, fontWeight: 700, fontSize: 10, letterSpacing: ".1em", textTransform: "uppercase", borderBottom: `2px solid ${c.border}` }}>{h}</th>)}</tr></thead>
                  <tbody>
                    {C.adderRows.filter(r => !r.isRedline).map((r, i) => {
                      const gm = r.list != null ? ((r.list - r.cost) / r.list * 100) : null;
                      return salesView
                        ? <tr key={i}><td style={{ padding: "7px 8px", borderBottom: `1px solid ${c.surface3}`, color: c.text2 }}>{r.label}</td><td style={{ padding: "7px 8px", borderBottom: `1px solid ${c.surface3}`, fontFamily: c.mono, fontSize: 11, color: c.text3 }}>{r.list != null ? fmt(r.list) : "?"}</td></tr>
                        : <tr key={i}><td style={{ padding: "7px 8px", borderBottom: `1px solid ${c.surface3}`, color: c.text2 }}>{r.label}</td><td style={{ padding: "7px 8px", borderBottom: `1px solid ${c.surface3}`, fontFamily: c.mono, fontSize: 11, color: c.text3 }}>{fmt(r.cost)}</td><td style={{ padding: "7px 8px", borderBottom: `1px solid ${c.surface3}`, fontFamily: c.mono, fontSize: 11, color: c.text3 }}>{r.list != null ? fmt(r.list) : "?"}</td><td style={{ padding: "7px 8px", borderBottom: `1px solid ${c.surface3}`, fontFamily: c.mono, fontSize: 11, color: gm == null ? c.text3 : gm < 0 ? c.danger : c.success }}>{gm != null ? `${gm.toFixed(0)}%` : "?"}</td></tr>;
                    })}
                  </tbody>
                  <tfoot>
                    {salesView
                      ? <tr style={{ borderTop: `2px solid ${c.border}` }}><td style={{ padding: "8px", fontWeight: 700, color: c.text }}>Total List</td><td style={{ padding: "8px", fontFamily: c.mono, fontWeight: 700 }}>{fmt(C.listSum)}</td></tr>
                      : <>
                          <tr style={{ borderTop: `2px solid ${c.border}` }}><td style={{ padding: "8px", fontWeight: 700, color: c.text }}>Total</td><td style={{ padding: "8px", fontFamily: c.mono }}>{fmt(C.adderSum)}</td><td style={{ padding: "8px", fontFamily: c.mono }}>{fmt(C.listSum)}</td><td style={{ padding: "8px", fontFamily: c.mono, color: C.listSum > C.adderSum ? c.success : c.danger }}>{C.listSum > 0 ? `${(((C.listSum - C.adderSum) / C.listSum) * 100).toFixed(0)}%` : "?"}</td></tr>
                          <tr><td style={{ padding: "8px", fontWeight: 700, color: c.success }}>Net Adder Income</td><td colSpan={2} style={{ padding: "8px", fontSize: 11, color: c.text3 }}>List ? Cost</td><td style={{ padding: "8px", fontFamily: c.mono, fontSize: 13, fontWeight: 700, color: C.listSum - C.adderSum >= 0 ? c.success : c.danger }}>{fmt(C.listSum - C.adderSum)}</td></tr>
                        </>
                    }
                  </tfoot>
                </table>
                <div style={{ background: c.warnL, border: `1.5px solid rgba(180,83,9,.2)`, borderRadius: 8, padding: "9px 12px", marginTop: 9, fontSize: 11, color: c.warn, lineHeight: 1.6 }}><strong>Rep note:</strong> Adder list ({fmt(C.listSum)}) comes out of gross spread before commission.</div>
              </>
            ) : <div style={{ background: c.surface3, border: `1.5px dashed ${c.border2}`, borderRadius: 8, padding: "11px 13px", fontSize: 12, color: c.text3, textAlign: "center" }}>No spread adders toggled ? activate adders in Section 04.</div>}
          </div>
        )}
      </div>

      <div>
        {/* 06 ? Business Overhead */}
        <div style={card}>
          <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 14 }}>
            <span style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent }}>06 ? Business Overhead</span>
            <span style={{ fontSize: 11, color: c.text3 }}>2026 Budget</span>
          </div>
          {C && (
            <>
              <div style={{ background: c.surface2, borderRadius: 9, padding: "12px 14px", border: `1.5px solid ${c.border}` }}>
                {[
                  ["Equipment", fmtPPW(C.equipTotalPPW), c.text],
                  ["Install Labor ? " + (laborMode === "sub" ? "Sub" : "Internal") + " ? " + (laborRate * 100).toFixed(0) + "?/W", "+ " + fmtPPW(C.baseLaborPPW), c.warn],
                  ...(C.nonflushPrem > 0 ? [["Non-Flush Premium (+$0.12/W)", "+ " + fmtPPW(NONFLUSH_PPW), c.warn]] : []),
                  ...(C.detachPrem > 0  ? [["Detached Structure (+$0.20/W)",  "+ " + fmtPPW(DETACH_PPW),   c.warn]] : []),
                ].map(([l, v, col]) => (
                  <div key={l} style={{ display: "flex", justifyContent: "space-between", fontSize: 12, padding: "3px 0", color: c.text2 }}><span>{l}</span><span style={{ fontFamily: c.mono, fontWeight: 500, color: col }}>{v}</span></div>
                ))}
                {/* Ancillary COGS ? adjustable $0.005/W increments */}
                <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", fontSize: 12, padding: "4px 0", opacity: overheadOn.ancillary ? 1 : 0.45 }}>
                  <div style={{ display: "flex", alignItems: "center", gap: 5, flexWrap: "wrap" }}>
                    <button onClick={() => setOverheadOn(p => ({...p, ancillary: !p.ancillary}))} style={{ width: 28, padding: "1px 0", borderRadius: 10, border: `1px solid ${overheadOn.ancillary ? c.accent : c.border2}`, background: overheadOn.ancillary ? c.accentL : c.surface2, color: overheadOn.ancillary ? c.accent : c.text3, fontSize: 9, fontWeight: 700, cursor: "pointer" }}>{overheadOn.ancillary ? "ON" : "OFF"}</button>
                    <span style={{ color: overheadOn.ancillary ? c.text2 : c.text3 }}>Ancillary Cost of Goods (surveys, permits, plan sets)</span>
                    <div style={{ display: "flex", alignItems: "center", gap: 2 }}>
                      <button onClick={() => setAncillaryPPW(v => Math.max(0, Math.round((v - 0.005) * 1000) / 1000))} style={{ width: 18, height: 18, borderRadius: 4, border: `1px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 12, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>?</button>
                      <button onClick={() => setAncillaryPPW(v => Math.round((v + 0.005) * 1000) / 1000)} style={{ width: 18, height: 18, borderRadius: 4, border: `1px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 12, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>+</button>
                      {ancillaryPPW !== ANCILLARY_PPW && <button onClick={() => setAncillaryPPW(ANCILLARY_PPW)} style={{ fontSize: 9, color: c.text3, background: "none", border: "none", cursor: "pointer", padding: "0 2px" }}>reset</button>}
                    </div>
                  </div>
                  <span style={{ fontFamily: c.mono, fontWeight: 500, color: !overheadOn.ancillary ? c.text3 : ancillaryPPW !== ANCILLARY_PPW ? c.warn : c.text2 }}>{overheadOn.ancillary ? `+ ${fmtPPW(ancillaryPPW)}` : "?"}</span>
                </div>
                {/* G&A ? adjustable $0.01/W increments */}
                <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", fontSize: 12, padding: "4px 0", opacity: overheadOn.ga ? 1 : 0.45 }}>
                  <div style={{ display: "flex", alignItems: "center", gap: 5, flexWrap: "wrap" }}>
                    <button onClick={() => setOverheadOn(p => ({...p, ga: !p.ga}))} style={{ width: 28, padding: "1px 0", borderRadius: 10, border: `1px solid ${overheadOn.ga ? c.accent : c.border2}`, background: overheadOn.ga ? c.accentL : c.surface2, color: overheadOn.ga ? c.accent : c.text3, fontSize: 9, fontWeight: 700, cursor: "pointer" }}>{overheadOn.ga ? "ON" : "OFF"}</button>
                    <span style={{ color: overheadOn.ga ? c.text2 : c.text3 }}>G&A Expenses</span>
                    <span style={{ fontSize: 9, color: c.text3, background: c.surface3, padding: "1px 6px", borderRadius: 8, fontStyle: "italic" }}>100-install avg</span>
                    <div style={{ display: "flex", alignItems: "center", gap: 2 }}>
                      <button onClick={() => setGaPPW(v => Math.max(0, Math.round((v - 0.01) * 1000) / 1000))} style={{ width: 18, height: 18, borderRadius: 4, border: `1px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 12, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>?</button>
                      <button onClick={() => setGaPPW(v => Math.round((v + 0.01) * 1000) / 1000)} style={{ width: 18, height: 18, borderRadius: 4, border: `1px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 12, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>+</button>
                      {gaPPW !== GA_PPW_DEFAULT && <button onClick={() => setGaPPW(GA_PPW_DEFAULT)} style={{ fontSize: 9, color: c.text3, background: "none", border: "none", cursor: "pointer", padding: "0 2px" }}>reset</button>}
                    </div>
                  </div>
                  <span style={{ fontFamily: c.mono, fontWeight: 500, color: !overheadOn.ga ? c.text3 : gaPPW !== GA_PPW_DEFAULT ? c.warn : c.text2 }}>{overheadOn.ga ? `+ ${fmtPPW(gaPPW)}` : "?"}</span>
                </div>
                {/* Sales Ops ? adjustable $0.005/W increments */}
                <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", fontSize: 12, padding: "4px 0", opacity: overheadOn.sops ? 1 : 0.45 }}>
                  <div style={{ display: "flex", alignItems: "center", gap: 5, flexWrap: "wrap" }}>
                    <button onClick={() => setOverheadOn(p => ({...p, sops: !p.sops}))} style={{ width: 28, padding: "1px 0", borderRadius: 10, border: `1px solid ${overheadOn.sops ? c.accent : c.border2}`, background: overheadOn.sops ? c.accentL : c.surface2, color: overheadOn.sops ? c.accent : c.text3, fontSize: 9, fontWeight: 700, cursor: "pointer" }}>{overheadOn.sops ? "ON" : "OFF"}</button>
                    <span style={{ color: overheadOn.sops ? c.text2 : c.text3 }}>Sales Ops (excl. commissions)</span>
                    <span style={{ fontSize: 9, color: c.text3, background: c.surface3, padding: "1px 6px", borderRadius: 8, fontStyle: "italic" }}>100-install avg</span>
                    <div style={{ display: "flex", alignItems: "center", gap: 2 }}>
                      <button onClick={() => setSopsPPW(v => Math.max(0, Math.round((v - 0.005) * 1000) / 1000))} style={{ width: 18, height: 18, borderRadius: 4, border: `1px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 12, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>?</button>
                      <button onClick={() => setSopsPPW(v => Math.round((v + 0.005) * 1000) / 1000)} style={{ width: 18, height: 18, borderRadius: 4, border: `1px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 12, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>+</button>
                      {sopsPPW !== SALESOPS_PPW_DEFAULT && <button onClick={() => setSopsPPW(SALESOPS_PPW_DEFAULT)} style={{ fontSize: 9, color: c.text3, background: "none", border: "none", cursor: "pointer", padding: "0 2px" }}>reset</button>}
                    </div>
                  </div>
                  <span style={{ fontFamily: c.mono, fontWeight: 500, color: !overheadOn.sops ? c.text3 : sopsPPW !== SALESOPS_PPW_DEFAULT ? c.warn : c.text2 }}>{overheadOn.sops ? `+ ${fmtPPW(sopsPPW)}` : "?"}</span>
                </div>
                {/* Sales Leadership G&A ? scales with installs, $0.005/W increments */}
                <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", fontSize: 12, padding: "4px 0", opacity: overheadOn.leadership ? 1 : 0.45 }}>
                  <div style={{ display: "flex", alignItems: "center", gap: 5, flexWrap: "wrap" }}>
                    <button onClick={() => setOverheadOn(p => ({...p, leadership: !p.leadership}))} style={{ width: 28, padding: "1px 0", borderRadius: 10, border: `1px solid ${overheadOn.leadership ? c.accent : c.border2}`, background: overheadOn.leadership ? c.accentL : c.surface2, color: overheadOn.leadership ? c.accent : c.text3, fontSize: 9, fontWeight: 700, cursor: "pointer" }}>{overheadOn.leadership ? "ON" : "OFF"}</button>
                    <span style={{ color: overheadOn.leadership ? c.text2 : c.text3 }}>Sales Leadership G&A</span>
                    <span style={{ fontSize: 9, color: c.text3, background: c.surface3, padding: "1px 6px", borderRadius: 8, fontStyle: "italic" }}>$450k + 21% burden ? 100-install avg</span>
                    <div style={{ display: "flex", alignItems: "center", gap: 2 }}>
                      <button onClick={() => setSalesLeadershipPPW(v => Math.max(0, Math.round((v - 0.005) * 1000) / 1000))} style={{ width: 18, height: 18, borderRadius: 4, border: `1px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 12, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>?</button>
                      <button onClick={() => setSalesLeadershipPPW(v => Math.round((v + 0.005) * 1000) / 1000)} style={{ width: 18, height: 18, borderRadius: 4, border: `1px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 12, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>+</button>
                      {salesLeadershipPPW !== SALES_LEADERSHIP_PPW_DEFAULT && <button onClick={() => setSalesLeadershipPPW(SALES_LEADERSHIP_PPW_DEFAULT)} style={{ fontSize: 9, color: c.text3, background: "none", border: "none", cursor: "pointer", padding: "0 2px" }}>reset</button>}
                    </div>
                  </div>
                  <span style={{ fontFamily: c.mono, fontWeight: 500, color: !overheadOn.leadership ? c.text3 : salesLeadershipPPW !== SALES_LEADERSHIP_PPW_DEFAULT ? c.warn : c.text2 }}>{overheadOn.leadership ? `+ ${fmtPPW(salesLeadershipPPW)}` : "?"}</span>
                </div>
                {/* Proposal & Sales Software ? flat constant, $0.005/W increments */}
                <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", fontSize: 12, padding: "4px 0", opacity: overheadOn.proposal ? 1 : 0.45 }}>
                  <div style={{ display: "flex", alignItems: "center", gap: 5, flexWrap: "wrap" }}>
                    <button onClick={() => setOverheadOn(p => ({...p, proposal: !p.proposal}))} style={{ width: 28, padding: "1px 0", borderRadius: 10, border: `1px solid ${overheadOn.proposal ? c.accent : c.border2}`, background: overheadOn.proposal ? c.accentL : c.surface2, color: overheadOn.proposal ? c.accent : c.text3, fontSize: 9, fontWeight: 700, cursor: "pointer" }}>{overheadOn.proposal ? "ON" : "OFF"}</button>
                    <span style={{ color: overheadOn.proposal ? c.text2 : c.text3 }}>Proposal & Sales Software Ancillary Costs</span>
                    <span style={{ fontSize: 9, color: c.text3, background: c.surface3, padding: "1px 6px", borderRadius: 8, fontStyle: "italic" }}>flat rate</span>
                    <div style={{ display: "flex", alignItems: "center", gap: 2 }}>
                      <button onClick={() => setProposalPPW(v => Math.max(0, Math.round((v - 0.005) * 1000) / 1000))} style={{ width: 18, height: 18, borderRadius: 4, border: `1px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 12, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>?</button>
                      <button onClick={() => setProposalPPW(v => Math.round((v + 0.005) * 1000) / 1000)} style={{ width: 18, height: 18, borderRadius: 4, border: `1px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 12, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>+</button>
                      {proposalPPW !== PROPOSAL_PPW && <button onClick={() => setProposalPPW(PROPOSAL_PPW)} style={{ fontSize: 9, color: c.text3, background: "none", border: "none", cursor: "pointer", padding: "0 2px" }}>reset</button>}
                    </div>
                  </div>
                  <span style={{ fontFamily: c.mono, fontWeight: 500, color: !overheadOn.proposal ? c.text3 : proposalPPW !== PROPOSAL_PPW ? c.warn : c.text2 }}>{overheadOn.proposal ? `+ ${fmtPPW(proposalPPW)}` : "?"}</span>
                </div>
                {/* Installs per month slider */}
                <div style={{ marginTop: 10, padding: "10px 12px", background: c.surface3, borderRadius: 8, border: `1px solid ${c.border}` }}>
                  <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 6 }}>
                    <span style={{ fontSize: 11, fontWeight: 700, color: c.text2 }}>Installs / Month</span>
                    <div style={{ display: "flex", alignItems: "center", gap: 6 }}>
                      <span style={{ fontFamily: c.mono, fontSize: 14, fontWeight: 700, color: c.accent }}>{installsPerMonth}</span>
                      {installsPerMonth !== 100 && <button onClick={() => { setInstallsPerMonth(100); setGaPPW(GA_PPW_DEFAULT); setSopsPPW(SALESOPS_PPW_DEFAULT); setSalesLeadershipPPW(SALES_LEADERSHIP_PPW_DEFAULT); }} style={{ fontSize: 9, color: c.text3, background: "none", border: "none", cursor: "pointer", padding: "0 2px" }}>reset</button>}
                    </div>
                  </div>
                  <input type="range" min={1} max={1000} step={1} value={installsPerMonth}
                    onChange={e => {
                      let n = parseInt(e.target.value);
                      const snap = Math.round(n / 100) * 100;
                      if (snap >= 100 && Math.abs(n - snap) <= 8) n = snap;
                      else if (n <= 8) n = 1;
                      setInstallsPerMonth(n);
                      setGaPPW(Math.min(0.50, roundUpGA(GA_FIXED_MO / (n * W_STD_INSTALLS))));
                      setSopsPPW(Math.min(0.070, roundUpSops(SOPS_FIXED_MO / (n * W_STD_INSTALLS))));
                      setSalesLeadershipPPW(Math.min(0.15, roundUpSops(LEADERSHIP_FIXED_MO / (n * W_STD_INSTALLS))));
                    }}
                    style={{ width: "100%", accentColor: c.accent, cursor: "pointer", marginBottom: 6 }}
                  />
                  <div style={{ position: "relative", height: 16 }}>
                    {[1, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000].map(v => {
                      const pct = (v - 1) / (1000 - 1) * 100;
                      const offset = 8 * (0.5 - pct / 100);
                      const isActive = installsPerMonth === v;
                      return (
                        <span key={v} onClick={() => { setInstallsPerMonth(v); setGaPPW(Math.min(0.50, roundUpGA(GA_FIXED_MO / (v * W_STD_INSTALLS)))); setSopsPPW(Math.min(0.070, roundUpSops(SOPS_FIXED_MO / (v * W_STD_INSTALLS)))); setSalesLeadershipPPW(Math.min(0.15, roundUpSops(LEADERSHIP_FIXED_MO / (v * W_STD_INSTALLS)))); }}
                          style={{ position: "absolute", left: `calc(${pct}% + ${offset}px)`, transform: "translateX(-50%)", fontSize: 9, cursor: "pointer", color: isActive ? c.accent : c.text3, fontWeight: isActive ? 700 : 400, whiteSpace: "nowrap" }}>
                          {v === 1 ? "1" : v}
                        </span>
                      );
                    })}
                  </div>
                </div>
                <div style={{ height: 1, background: c.border, margin: "7px 0" }} />
                <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
                  <span style={{ fontSize: 11, fontWeight: 700, textTransform: "uppercase", letterSpacing: ".1em", color: c.text3 }}>All-In Cost Floor</span>
                  <span style={{ fontFamily: c.mono, fontSize: 18, fontWeight: 700, color: c.accent }}>{fmtPPW(C.baseAllinPPW)}</span>
                </div>
              </div>
              <div style={{ fontSize: 11, color: c.text3, marginTop: 7 }}>? Commissions ($0.60/W ? 1099 reps ? excluded from floor)</div>
              {/* Campaign Cost Allocation */}
              {(() => {
                const cp = campaignP;
                const setP = (field, val) => setCampaignP(prev => ({ ...prev, [field]: Math.max(0, val) }));
                const stepP = (field, delta) => setP(field, cp[field] + delta);
                const cov = cp.coverage || {};

                const autoClosers    = Math.ceil(cp.setters / 2.5);
                const autoSetterCars = Math.ceil(cp.setters / 4);
                const autoCloserCars = Math.ceil(autoClosers / 2.5);

                const dispClosers    = cp.manualOverride ? cp.manualClosers    : autoClosers;
                const dispSetterCars = cp.manualOverride ? cp.manualSetterCars : autoSetterCars;
                const dispCloserCars = cp.manualOverride ? cp.manualCloserCars : autoCloserCars;

                const inputBox = (label, value, onMinus, onPlus, onChange, disabled = false, highlight = false) => (
                  <div style={{ background: disabled ? c.surface3 : highlight ? c.accentL : c.surface2, border: `1px solid ${highlight ? c.accent : c.border}`, borderRadius: 7, padding: "6px 8px", opacity: disabled ? 0.45 : 1 }}>
                    <div style={{ fontSize: 9, color: highlight ? c.accent : c.text3, fontWeight: 700, textTransform: "uppercase", letterSpacing: ".04em", marginBottom: 4 }}>{label}</div>
                    <div style={{ display: "flex", alignItems: "center", gap: 3 }}>
                      <button disabled={disabled} onClick={onMinus} style={{ width: 20, height: 20, borderRadius: 4, border: `1px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 12, fontWeight: 700, cursor: disabled ? "default" : "pointer", lineHeight: 1, flexShrink: 0 }}>?</button>
                      <input type="text" inputMode="decimal" disabled={disabled} value={value} onChange={onChange} style={{ flex: 1, textAlign: "center", fontFamily: c.mono, fontSize: 12, fontWeight: 700, background: "transparent", border: "none", outline: "none", color: highlight ? c.accent : c.text, minWidth: 0 }} />
                      <button disabled={disabled} onClick={onPlus} style={{ width: 20, height: 20, borderRadius: 4, border: `1px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 12, fontWeight: 700, cursor: disabled ? "default" : "pointer", lineHeight: 1, flexShrink: 0 }}>+</button>
                    </div>
                  </div>
                );

                return (
                  <div style={{ marginTop: 12, paddingTop: 12, borderTop: `1px solid ${c.border}` }}>
                    {/* Header row */}
                    <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 10 }}>
                      <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
                        <span style={{ fontSize: 11, fontWeight: 700, color: c.text2 }}>Campaign Cost Allocation</span>
                        <span style={{ fontSize: 9, color: c.text3, background: c.surface3, padding: "1px 6px", borderRadius: 8, fontStyle: "italic" }}>direct deals only</span>
                      </div>
                      <button onClick={() => setCampaignOn(v => !v)} style={{ padding: "4px 12px", borderRadius: 20, border: `1.5px solid ${campaignOn ? c.accent : c.border2}`, background: campaignOn ? c.accentL : c.surface2, color: campaignOn ? c.accent : c.text3, fontFamily: c.sans, fontSize: 11, fontWeight: 700, cursor: "pointer" }}>
                        {campaignOn ? "? ON" : "? OFF"}
                      </button>
                    </div>
                    {campaignOn && C && (
                      <>
                        {/* Internal / Dealer selector */}
                        <div style={{ display:"flex", gap:4, marginBottom:14, background:c.surface3, border:`1px solid ${c.border}`, borderRadius:9, padding:3 }}>
                          {[{k:false,l:"Internal Deal"},{k:true,l:"Dealer Deal"}].map(({k,l})=>(
                            <button key={String(k)} onClick={() => setCampaignP(prev=>({...prev, dealerMode:k}))}
                              style={{ flex:1, padding:"7px 4px", borderRadius:7, border:cp.dealerMode===k?`1px solid ${c.border}`:"none", background:cp.dealerMode===k?c.surface:"transparent", color:cp.dealerMode===k?(k?c.blue:c.accent):c.accent, cursor:"pointer", fontFamily:c.sans, fontSize:12, fontWeight:cp.dealerMode===k?700:600 }}>
                              {l}
                            </button>
                          ))}
                        </div>

                        {cp.dealerMode ? (
                          <div style={{ background:c.blueL, border:`1px solid rgba(26,95,180,.2)`, borderRadius:8, padding:"12px 14px", fontSize:12, color:c.blue, lineHeight:1.6 }}>
                            <strong>Dealer mode:</strong> Dealer covers their own campaign costs. No amount is withheld from the commission pool on this deal.
                          </div>
                        ) : (
                          <>
                            {/* Manual Override toggle */}
                            <div style={{ display:"flex", alignItems:"center", justifyContent:"space-between", marginBottom:12, padding:"7px 10px", background:cp.manualOverride?c.warnL:c.surface3, border:`1px solid ${cp.manualOverride?"rgba(180,83,9,.25)":c.border}`, borderRadius:8 }}>
                              <div>
                                <span style={{ fontSize:11, fontWeight:700, color:cp.manualOverride?c.warn:c.text2 }}>Manual Override</span>
                                <span style={{ fontSize:9, color:cp.manualOverride?c.warn:c.text3, marginLeft:6 }}>{cp.manualOverride?"Free-form inputs active":"Auto-calculating from constraints"}</span>
                              </div>
                              <button onClick={() => {
                                if (!cp.manualOverride) setCampaignP(prev=>({...prev, manualOverride:true, manualClosers:autoClosers, manualSetterCars:autoSetterCars, manualCloserCars:autoCloserCars}));
                                else setCampaignP(prev=>({...prev, manualOverride:false}));
                              }} style={{ padding:"4px 10px", borderRadius:16, border:`1px solid ${cp.manualOverride?c.warn:c.border2}`, background:cp.manualOverride?c.warn:c.surface2, color:cp.manualOverride?"#fff":c.text3, fontFamily:c.sans, fontSize:10, fontWeight:700, cursor:"pointer" }}>
                                {cp.manualOverride?"? Manual":"? Auto"}
                              </button>
                            </div>

                            {/* Headcount */}
                            <div style={{ fontSize:9, fontWeight:700, color:c.text3, textTransform:"uppercase", letterSpacing:".1em", marginBottom:6 }}>Headcount</div>
                            <div style={{ display:"grid", gridTemplateColumns:"1fr 1fr", gap:6, marginBottom:12 }}>
                              {inputBox("Setters", cp.setters, ()=>stepP("setters",-1), ()=>stepP("setters",1), e=>{const v=parseInt(e.target.value);if(!isNaN(v))setP("setters",v);}, false, true)}
                              {cp.manualOverride
                                ? inputBox("Closers (manual)", cp.manualClosers, ()=>setP("manualClosers",cp.manualClosers-1), ()=>setP("manualClosers",cp.manualClosers+1), e=>{const v=parseInt(e.target.value);if(!isNaN(v))setP("manualClosers",v);})
                                : <div style={{ background:c.surface2, border:`1px solid ${c.border}`, borderRadius:7, padding:"6px 8px" }}>
                                    <div style={{ fontSize:9, color:c.text3, fontWeight:700, textTransform:"uppercase", letterSpacing:".04em", marginBottom:4 }}>Closers <span style={{ fontWeight:400, textTransform:"none" }}>(auto)</span></div>
                                    <div style={{ fontFamily:c.mono, fontSize:14, fontWeight:800, color:c.text, textAlign:"center" }}>{autoClosers}</div>
                                    <div style={{ fontSize:9, color:c.text3, textAlign:"center" }}>ceil({cp.setters} ? 2.5)</div>
                                  </div>
                              }
                              {cp.manualOverride
                                ? inputBox("Setter Cars", cp.manualSetterCars, ()=>setP("manualSetterCars",cp.manualSetterCars-1), ()=>setP("manualSetterCars",cp.manualSetterCars+1), e=>{const v=parseInt(e.target.value);if(!isNaN(v))setP("manualSetterCars",v);})
                                : <div style={{ background:c.surface2, border:`1px solid ${c.border}`, borderRadius:7, padding:"6px 8px" }}>
                                    <div style={{ fontSize:9, color:c.text3, fontWeight:700, textTransform:"uppercase", letterSpacing:".04em", marginBottom:4 }}>Setter Cars <span style={{ fontWeight:400, textTransform:"none" }}>(auto)</span></div>
                                    <div style={{ fontFamily:c.mono, fontSize:14, fontWeight:800, color:c.text, textAlign:"center" }}>{autoSetterCars}</div>
                                    <div style={{ fontSize:9, color:c.text3, textAlign:"center" }}>ceil({cp.setters} ? 4)</div>
                                  </div>
                              }
                              {cp.manualOverride
                                ? inputBox("Closer Cars", cp.manualCloserCars, ()=>setP("manualCloserCars",cp.manualCloserCars-1), ()=>setP("manualCloserCars",cp.manualCloserCars+1), e=>{const v=parseInt(e.target.value);if(!isNaN(v))setP("manualCloserCars",v);})
                                : <div style={{ background:c.surface2, border:`1px solid ${c.border}`, borderRadius:7, padding:"6px 8px" }}>
                                    <div style={{ fontSize:9, color:c.text3, fontWeight:700, textTransform:"uppercase", letterSpacing:".04em", marginBottom:4 }}>Closer Cars <span style={{ fontWeight:400, textTransform:"none" }}>(auto)</span></div>
                                    <div style={{ fontFamily:c.mono, fontSize:14, fontWeight:800, color:c.text, textAlign:"center" }}>{autoCloserCars}</div>
                                    <div style={{ fontSize:9, color:c.text3, textAlign:"center" }}>ceil({autoClosers} ? 2.5)</div>
                                  </div>
                              }
                            </div>

                            {/* Rates */}
                            <div style={{ fontSize:9, fontWeight:700, color:c.text3, textTransform:"uppercase", letterSpacing:".1em", marginBottom:6 }}>Rates</div>
                            <div style={{ display:"grid", gridTemplateColumns:"1fr 1fr", gap:6, marginBottom:14 }}>
                              {inputBox("Days", cp.days, ()=>stepP("days",-1), ()=>stepP("days",1), e=>{const v=parseInt(e.target.value);if(!isNaN(v))setP("days",v);})}
                              {inputBox("Est. Installs", cp.installs, ()=>stepP("installs",-1), ()=>stepP("installs",1), e=>{const v=parseInt(e.target.value);if(!isNaN(v))setP("installs",v);})}
                              {inputBox("Airbnb/Night ($)", cp.airbnbPerDay, ()=>stepP("airbnbPerDay",-5), ()=>stepP("airbnbPerDay",5), e=>{const v=parseFloat(e.target.value);if(!isNaN(v))setP("airbnbPerDay",v);})}
                              {inputBox("Car/Day ($)", cp.carPerDay, ()=>stepP("carPerDay",-5), ()=>stepP("carPerDay",5), e=>{const v=parseFloat(e.target.value);if(!isNaN(v))setP("carPerDay",v);})}
                              {inputBox("Flight/Rep ($)", cp.flightPerRep, ()=>stepP("flightPerRep",-50), ()=>stepP("flightPerRep",50), e=>{const v=parseFloat(e.target.value);if(!isNaN(v))setP("flightPerRep",v);})}
                            </div>

                            {/* Per-line ops/sales coverage table */}
                            <div style={{ fontSize:9, fontWeight:700, color:c.text3, textTransform:"uppercase", letterSpacing:".1em", marginBottom:6 }}>Cost Coverage ? Ops or Sales</div>
                            <div style={{ border:`1px solid ${c.border}`, borderRadius:8, overflow:"hidden", marginBottom:12 }}>
                              {[
                                { key:"airbnb",     label:"Airbnb",       amt:C.campAirbnbAmt,   sub:`${dispClosers+cp.setters} ppl ? $${cp.airbnbPerDay} ? ${cp.days}d` },
                                { key:"setterCars", label:"Setter Cars",  amt:C.campSetCarAmt,   sub:`${dispSetterCars} cars ? $${cp.carPerDay} ? ${cp.days}d` },
                                { key:"closerCars", label:"Closer Cars",  amt:C.campCloseCarAmt, sub:`${dispCloserCars} cars ? $${cp.carPerDay} ? ${cp.days}d` },
                                { key:"flights",    label:"Flights",      amt:C.campFlightsAmt,  sub:`${dispClosers+cp.setters} ppl ? $${cp.flightPerRep}` },
                              ].map(({ key, label, amt, sub }, i, arr) => {
                                const isOps = cov[key] === "ops";
                                return (
                                  <div key={key} style={{ display:"flex", alignItems:"center", justifyContent:"space-between", padding:"9px 12px", borderBottom:i<arr.length-1?`1px solid ${c.border}`:"none", background:isOps?"rgba(185,28,28,.03)":"rgba(180,83,9,.03)" }}>
                                    <div>
                                      <div style={{ fontSize:12, fontWeight:600, color:c.text }}>{label}</div>
                                      <div style={{ fontSize:9, color:c.text3, marginTop:1 }}>{sub} = <span style={{ fontFamily:c.mono, fontWeight:700 }}>${amt.toLocaleString("en-US",{maximumFractionDigits:0})}</span></div>
                                    </div>
                                    <div style={{ display:"flex", alignItems:"center", gap:8 }}>
                                      <span style={{ fontFamily:c.mono, fontSize:12, fontWeight:700, color:c.text2 }}>${amt.toLocaleString("en-US",{maximumFractionDigits:0})}</span>
                                      <div style={{ display:"flex", background:c.surface3, border:`1px solid ${c.border}`, borderRadius:20, padding:2 }}>
                                        <button onClick={() => setCampaignP(prev=>({...prev,coverage:{...prev.coverage,[key]:"ops"}}))}
                                          style={{ padding:"3px 10px", borderRadius:16, border:"none", background:isOps?"#fee2e2":"transparent", color:isOps?c.danger:c.text3, fontFamily:c.sans, fontSize:10, fontWeight:700, cursor:"pointer" }}>Ops</button>
                                        <button onClick={() => setCampaignP(prev=>({...prev,coverage:{...prev.coverage,[key]:"sales"}}))}
                                          style={{ padding:"3px 10px", borderRadius:16, border:"none", background:!isOps?c.warnL:"transparent", color:!isOps?c.warn:c.text3, fontFamily:c.sans, fontSize:10, fontWeight:700, cursor:"pointer" }}>Sales</button>
                                      </div>
                                    </div>
                                  </div>
                                );
                              })}
                            </div>

                            {/* Summary totals */}
                            <div style={{ display:"grid", gridTemplateColumns:"1fr 1fr 1fr", gap:8 }}>
                              {[
                                { label:"Total Campaign", val:`$${C.campTotalCost.toLocaleString("en-US",{maximumFractionDigits:0})}`, col:c.text },
                                { label:"Ops ? Redline", val:`+${fmtPPW(C.campaignOpsPPW)}`, col:c.danger },
                                { label:"Sales ? Escrow", val:C.campaignSalesPPW>0?fmtPPW(C.campaignSalesPPW):"$0.000/W", col:C.campaignSalesPPW>0?c.warn:c.text3 },
                              ].map(({label,val,col})=>(
                                <div key={label} style={{ background:c.surface2, border:`1px solid ${c.border}`, borderRadius:8, padding:"8px 10px", textAlign:"center" }}>
                                  <div style={{ fontSize:9, color:c.text3, fontWeight:700, textTransform:"uppercase", letterSpacing:".04em", marginBottom:3 }}>{label}</div>
                                  <div style={{ fontFamily:c.mono, fontSize:13, fontWeight:800, color:col }}>{val}</div>
                                </div>
                              ))}
                            </div>
                          </>
                        )}
                      </>
                    )}
                  </div>
                );
              })()}
              {C.smallSystem && <div style={{ background: c.warnL, border: `1.5px solid rgba(180,83,9,.25)`, borderRadius: 8, padding: "8px 12px", marginTop: 9, fontSize: 11, color: c.warn, fontWeight: 500, lineHeight: 1.5 }}>? Small system (&lt;9kW) ? fixed costs don't scale. Floor likely understated.</div>}
              {!salesView && C.hb && (
                <div style={{ background: "linear-gradient(135deg,#f0fdf4,#dcfce7)", border: "1.5px solid rgba(22,101,52,.2)", borderRadius: 9, padding: 13, marginTop: 10 }}>
                  <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".12em", textTransform: "uppercase", color: c.success, marginBottom: 9 }}>? Lightreach Holdback + DC Boost</div>
                  <div style={{ display: "flex", justifyContent: "space-between", fontSize: 12, padding: "3px 0", color: c.text2 }}><span>Standard Holdback</span><span style={{ fontFamily: c.mono, fontWeight: 600, color: c.success }}>+$0.10/W</span></div>
                  {dcOn && <div style={{ display: "flex", justifyContent: "space-between", fontSize: 12, padding: "3px 0", color: c.text2 }}><span>DC Boost ? {jobType === "storage" ? "PV+Storage" : "PV Only"} ? {st}</span><span style={{ fontFamily: c.mono, fontWeight: 600, color: c.success }}>+${C.hb.dcBoost.toFixed(2)}/W</span></div>}
                  <div style={{ display: "flex", justifyContent: "space-between", marginTop: 9, paddingTop: 9, borderTop: "1px solid rgba(22,101,52,.2)", fontWeight: 700, fontSize: 13, color: c.success }}><span>Total M4 Add-Back</span><span>+${C.hb.total.toFixed(2)}/W</span></div>
                  {C.targetSc && <div style={{ marginTop: 5, fontSize: 11, color: c.success, fontFamily: c.mono }}>At {effectiveM}%: portal {fmtPPW(C.targetSc.baseRedlinePPW)} ? backend {fmtPPW(C.targetSc.baseRedlinePPW + C.hb.total)}</div>}
                </div>
              )}
            </>
          )}
        </div>

      </div>{/* end row 5 Business Overhead */}

      {/* ?? ROW 6 ? TARGET MARGIN (thin full-width bar) ????????????????????? */}
      <div style={card}>
        <div style={{ display: "flex", alignItems: "center", gap: 18, flexWrap: "wrap" }}>
          <span style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent, whiteSpace: "nowrap" }}>07 ? Target Margin</span>
          <div style={{ display: "flex", gap: 6, flexWrap: "wrap", flex: 1 }}>
            {MARGIN_PRESETS.map(m => {
              const isActive = effectiveM === m && customMStr === "", isZero = m === 0;
              return <button key={m} onClick={() => setPresetM(m)} style={{ padding: "5px 13px", borderRadius: 20, border: `1.5px solid ${isActive ? (isZero ? "rgba(109,40,217,.3)" : "rgba(13,110,110,.4)") : c.border}`, background: isActive ? (isZero ? c.purpleL : c.accentL) : c.surface2, color: isActive ? (isZero ? c.purple : c.accent) : c.text3, cursor: "pointer", fontFamily: c.sans, fontSize: 12, fontWeight: 700 }}>{m === 0 ? "Cost Floor" : `${m}%`}</button>;
            })}
          </div>
          <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
            <span style={{ ...lbl, margin: 0, whiteSpace: "nowrap" }}>Custom %:</span>
            <input style={{ ...inp_s, width: 70, fontFamily: c.mono, fontSize: 13, fontWeight: 600 }} type="number" min={0} max={60} step={0.5} value={customMStr} onChange={e => setCustomMStr(e.target.value)} placeholder="e.g. 22" />
            {customMStr && <button style={{ fontSize: 11, color: c.text3, background: "none", border: "none", cursor: "pointer" }} onClick={() => setCustomMStr("")}>?</button>}
          </div>
          {C && (
            <div style={{ display: "flex", alignItems: "center", gap: 8, background: c.surface2, border: `1.5px solid ${c.border}`, borderRadius: 8, padding: "6px 14px", minWidth: 200 }}>
              <span style={{ ...lbl, margin: 0, whiteSpace: "nowrap" }}>Target $/W:</span>
              <input style={{ ...inp_s, width: 85, fontFamily: c.mono, fontSize: 13, fontWeight: 600, padding: "4px 8px" }} type="number" min={1.00} max={6.00} step={0.025} value={targetPPWStr} onChange={e => setTargetPPWStr(e.target.value)} placeholder="e.g. 2.75" />
              {targetPPWStr && parseFloat(targetPPWStr) > 0 && C.baseAllinNoAdders > 0 && (() => {
                const ppw = parseFloat(targetPPWStr);
                const impliedMargin = (1 - C.baseAllinNoAdders / (ppw * C.W)) * 100;
                const col = impliedMargin < 0 ? c.danger : impliedMargin < 10 ? c.warn : c.success;
                return <span style={{ fontFamily: c.mono, fontSize: 13, fontWeight: 700, color: col, whiteSpace: "nowrap" }}>{impliedMargin.toFixed(1)}% GM</span>;
              })()}
              {targetPPWStr && <button style={{ fontSize: 11, color: c.text3, background: "none", border: "none", cursor: "pointer", marginLeft: 2 }} onClick={() => setTargetPPWStr("")}>?</button>}
            </div>
          )}
          <div style={{ display: "flex", alignItems: "center", gap: 12, background: c.accentL, border: `1.5px solid rgba(13,110,110,.2)`, borderRadius: 9, padding: "7px 14px" }}>
            <div style={{ fontSize: 10, fontWeight: 700, textTransform: "uppercase", letterSpacing: ".1em", color: c.accent }}>Active Target</div>
            {C && <div style={{ fontSize: 11, color: c.text3, fontFamily: c.mono }}>{fmtPPW(C.targetSc.baseRedlinePPW)}</div>}
            <div style={{ fontSize: 22, fontWeight: 800, color: c.accent, lineHeight: 1 }}>{effectiveM}%</div>
          </div>
        </div>
      </div>

      {/* ?? ROW 7 ? REDLINE SCENARIOS ??????????????????????????????????????? */}
      <div style={card}>
        <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 14 }}>
          <span style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent }}>08 ? Redline Scenarios</span>
          <span style={{ fontSize: 10, color: c.text3 }}>Base system rate only ? Click any row to switch target</span>
        </div>
        {C ? (
          <>
            {(() => {
              // Build display scenarios ? presets + injected custom row, sorted by margin
              const customM   = customMStr !== "" ? parseFloat(customMStr) : null;
              const validCustomM = customM != null && !isNaN(customM) && !MARGIN_PRESETS.includes(customM) && customM >= 0 && customM <= 60;
              const tPPW      = parseFloat(targetPPWStr);
              const validTPPW = targetPPWStr !== "" && !isNaN(tPPW) && tPPW > 0 && C.baseAllinNoAdders > 0;
              const impliedM  = validTPPW ? (1 - C.baseAllinNoAdders / (tPPW * C.W)) * 100 : null;
              const validImpliedM = impliedM != null && !MARGIN_PRESETS.includes(Math.round(impliedM * 10) / 10);

              const allScenarios = [
                ...C.mScenarios.map(s => ({ ...s, type: "preset" })),
                ...(validCustomM ? [{ m: customM, type: "custom", label: `${customM}%`, equipOnlyPPW: C.equipTotalPPW, baseRedlinePPW: rl(C.baseAllinNoAdders, customM) / C.W }] : []),
                ...(validImpliedM && validTPPW ? [{ m: impliedM, type: "targetppw", label: `${impliedM.toFixed(1)}%`, equipOnlyPPW: C.equipTotalPPW, baseRedlinePPW: tPPW }] : []),
              ].sort((a, b) => a.m - b.m);

              const chipStyle = { 0: { background: c.purpleL, color: c.purple, border: `1px solid rgba(109,40,217,.2)` }, low: { background: c.warnL, color: c.warn, border: `1px solid rgba(180,83,9,.2)` }, good: { background: c.accentL, color: c.accent, border: `1px solid rgba(13,110,110,.2)` }, high: { background: c.dangerL, color: c.danger, border: `1px solid rgba(185,28,28,.2)` } };

              return (
                <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 12 }}>
                  <thead><tr>{["Margin", "Equip Only PPW", "Base Redline PPW"].map(h => <th key={h} style={{ textAlign: "left", padding: "6px 8px", color: c.text3, fontWeight: 700, fontSize: 10, letterSpacing: ".12em", textTransform: "uppercase", borderBottom: `2px solid ${c.border}` }}>{h}</th>)}</tr></thead>
                  <tbody>
                    {allScenarios.map((s, i) => {
                      const isActive  = Math.abs(s.m - effectiveM) < 0.01;
                      const isCustom  = s.type === "custom";
                      const isTPPW    = s.type === "targetppw";
                      const isSpecial = isCustom || isTPPW;
                      const chipK     = s.m === 0 ? "0" : s.m <= 15 ? "low" : s.m <= 25 ? "good" : "high";
                      const rowBg     = isActive ? c.accentL : isSpecial ? `${c.accentL}88` : "transparent";
                      const handleClick = () => {
                        if (isTPPW) { setCustomMStr(s.m.toFixed(4)); setTargetPPWStr(""); }
                        else if (isCustom) { /* already active ? no-op */ }
                        else setPresetM(s.m);
                      };
                      return (
                        <tr key={`${s.type}-${s.m}`}
                          style={{ background: rowBg, cursor: isCustom ? "default" : "pointer" }}
                          onClick={handleClick}>
                          <td style={{ padding: "7px 8px", borderBottom: `1px solid ${c.surface3}` }}>
                            <span style={{ fontSize: 10, padding: "2px 8px", borderRadius: 20, fontWeight: 700, ...chipStyle[chipK] }}>
                              {s.m === 0 && !isSpecial ? "Cost Floor" : `${isSpecial ? s.m.toFixed(1) : s.m}%`}
                            </span>
                            {isCustom && <span style={{ fontSize: 9, marginLeft: 6, color: c.accent, fontWeight: 700, background: c.accentL, padding: "1px 5px", borderRadius: 4, border: `1px solid rgba(13,110,110,.2)` }}>CUSTOM</span>}
                            {isTPPW  && <span style={{ fontSize: 9, marginLeft: 6, color: c.accent, fontWeight: 700, background: c.accentL, padding: "1px 5px", borderRadius: 4, border: `1px solid rgba(13,110,110,.2)` }}>$/W TARGET</span>}
                          </td>
                          <td style={{ padding: "7px 8px", borderBottom: `1px solid ${c.surface3}`, fontFamily: c.mono, color: c.text3 }}>{fmtPPW(s.equipOnlyPPW)}</td>
                          <td style={{ padding: "7px 8px", borderBottom: `1px solid ${c.surface3}`, fontFamily: c.mono, fontWeight: isActive ? 700 : 400, color: isActive ? c.accent : c.text2 }}>{fmtPPW(s.baseRedlinePPW)}</td>
                        </tr>
                      );
                    })}
                  </tbody>
                </table>
              );
            })()}
            {!salesView && <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 14, marginTop: 12 }}>
              {C.actualCOGS ? (
                <div style={{ background: c.blueL, border: `1.5px solid rgba(26,95,180,.2)`, borderRadius: 8, padding: "12px 14px" }}>
                  <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".12em", textTransform: "uppercase", color: c.blue, marginBottom: 9 }}>? Actual COGS ? {st} / {lender} / {roofType === "flush" ? "Flush" : "Non-Flush"}{detached ? " / Detached" : ""}</div>
                  <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 7, marginBottom: 9 }}>
                    {[["Median", fmtPPW(C.actualCOGS.median)], ["Avg", fmtPPW(C.actualCOGS.avg)], ["Std Dev", `?${C.actualCOGS.stddev.toFixed(3)}`]].map(([l, v]) => (
                      <div key={l} style={{ background: c.surface, border: `1px solid ${c.border}`, borderRadius: 7, padding: "8px 9px", textAlign: "center" }}>
                        <div style={{ fontSize: 10, color: c.text3, fontWeight: 600, textTransform: "uppercase", letterSpacing: ".06em", marginBottom: 2 }}>{l}</div>
                        <div style={{ fontSize: 15, fontWeight: 700, fontFamily: c.mono, color: c.blue }}>{v}</div>
                      </div>
                    ))}
                  </div>
                  <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", paddingTop: 7, borderTop: "1px solid rgba(26,95,180,.1)" }}>
                    <div style={{ fontSize: 11, color: c.text2 }}>Model floor vs. median: <span style={{ fontFamily: c.mono, fontWeight: 700, color: (C.allInPPW - C.actualCOGS.median) >= 0 ? c.success : c.danger }}>{(C.allInPPW - C.actualCOGS.median) >= 0 ? "+" : ""}{(C.allInPPW - C.actualCOGS.median).toFixed(3)}/W</span></div>
                    <div style={{ fontSize: 10, color: c.text3 }}>{C.actualCOGS.jobs} jobs{C.actualCOGS.lowConf ? " ? ? low confidence" : ""}</div>
                  </div>
                </div>
              ) : (
                <div style={{ background: c.surface3, border: `1.5px dashed ${c.border2}`, borderRadius: 8, padding: "9px 12px", fontSize: 11, color: c.text3, textAlign: "center" }}>No COGS benchmark for {st} / {lender} yet.</div>
              )}
              {C.histPPW && (
                <div style={{ background: c.blueL, border: `1.5px solid rgba(26,95,180,.15)`, borderRadius: 7, padding: "11px 13px" }}>
                  <div style={{ display: "flex", justifyContent: "space-between", fontSize: 12, padding: "3px 0", borderBottom: "1px solid rgba(26,95,180,.1)", marginBottom: 5 }}><span style={{ color: c.text2 }}>2025 Market Avg ? {st} / {lender}</span><span style={{ fontFamily: c.mono, fontWeight: 600 }}>{fmtPPW(C.histPPW)}</span></div>
                  <div style={{ display: "flex", justifyContent: "space-between", fontSize: 12 }}><span style={{ color: c.text2 }}>Cushion @ {effectiveM}% redline</span><span style={{ fontFamily: c.mono, fontWeight: 700, color: (C.histPPW - C.targetSc.baseRedlinePPW) >= 0 ? c.success : c.danger }}>{(C.histPPW - C.targetSc.baseRedlinePPW) >= 0 ? "+" : ""}{(C.histPPW - C.targetSc.baseRedlinePPW).toFixed(3)}/W</span></div>
                </div>
              )}
            </div>}
          </>
        ) : <div style={{ color: c.text3, fontSize: 13 }}>No data ? configure job parameters above.</div>}
      </div>

      {/* ?? ROW 8 ? COMMISSION CALCULATOR | OPS P&L ????????????????????????? */}
      <div style={{ display: "grid", gridTemplateColumns: salesView ? "1fr" : "1fr 1fr", gap: 18, alignItems: "start" }}>

        {/* 09 ? Commission Calculator */}
        {C && (() => {
          const W         = C.W;
          const base$     = C.targetSc.baseRedline$;
          const adderList$ = C.listSum;
          const floor$    = base$ + adderList$;
          const floorPPW  = floor$ / W;
          const soldPPW   = parseFloat(soldPPWStr) || 0;
          const soldTotal = soldPPW * W;
          const grossSpread = soldTotal - base$;
          const commTotal = grossSpread - adderList$;
          const commPPW   = commTotal / W;
          const commPct   = soldTotal > 0 ? (commTotal / soldTotal * 100) : 0;
          const targetComm = parseFloat(targetCommStr) || 0;
          const reqTotal  = base$ + adderList$ + targetComm;
          const reqPPW    = reqTotal / W;
          const reqCommPct = reqTotal > 0 ? (targetComm / reqTotal * 100) : 0;

          return (
            <div style={card}>
              <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 14 }}>
                <span style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent }}>09 ? Commission Calculator</span>
                <div style={{ display:"flex", alignItems:"center", gap:10 }}>
                  <span style={{ fontSize: 11, color: c.text3 }}>Spread ? Adder List = Commission</span>
                  <button onClick={() => {
                    // Solve lender inputs to hit soldPPW before switching tabs
                    if (soldPPW > 0 && C) {
                      const kw = C.W / 1000;
                      const solved = {};
                      (LENDERS_BY_STATE[st] || []).forEach(l => {
                        const combo = commSolveForTarget(l, st, util, dcOn, ecOn, kw, soldPPW);
                        if (combo) solved[l] = combo;
                      });
                      if (Object.keys(solved).length > 0) setLinputs(solved);
                    }
                    setActiveTab("commissions");
                  }} style={{ padding:"5px 12px", background:c.accentL, border:`1.5px solid rgba(13,110,110,.3)`, borderRadius:8, color:c.accent, fontFamily:c.sans, fontSize:11, fontWeight:700, cursor:"pointer", letterSpacing:".03em" }}>? Open Commissions Model ?</button>
                </div>
              </div>
              {/* Summary strip */}
              <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 8, marginBottom: 14, background: c.surface2, borderRadius: 8, padding: "10px 12px" }}>
                {[["Base Redline", fmtPPW(C.targetSc.baseRedlinePPW), fmt(base$), c.accent], ["Adder List", adderList$ > 0 ? fmt(adderList$) : "$0", adderList$ > 0 ? "Out of spread" : "No adders", c.warn], ["Floor", fmtPPW(floorPPW), fmt(floor$), c.text]].map(([l, v, s, col]) => (
                  <div key={l} style={{ textAlign: "center" }}><div style={{ fontSize: 10, color: c.text3, fontWeight: 700, textTransform: "uppercase", letterSpacing: ".07em", marginBottom: 3 }}>{l}</div><div style={{ fontFamily: c.mono, fontSize: 13, fontWeight: 700, color: col }}>{v}</div><div style={{ fontSize: 10, color: c.text3, marginTop: 2 }}>{s}</div></div>
                ))}
              </div>
              {/* Mode toggle */}
              <div style={{ ...seg_s, marginBottom: 14 }}>
                <button style={sb(commMode === "sold_rate")} onClick={() => setCommMode("sold_rate")}>Option 1 ? Set Sold EPC</button>
                <button style={sb(commMode === "target_comm")} onClick={() => setCommMode("target_comm")}>Option 2 ? Target Commission</button>
              </div>
              {commMode === "sold_rate" ? (
                <>
                  <div style={{ marginBottom: 14 }}>
                    <div style={{ marginBottom: 7 }}>
                      <div style={lbl}>Gross EPC Sold ($/W)</div>
                      <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
                        <button onClick={() => setSoldPPWStr(v => { const n = parseFloat(v) || 0; const d = parseFloat((n / 0.05).toFixed(6)); const f = Math.floor(d); const snapped = Math.abs(f - d) < 0.0001 ? n - 0.05 : f * 0.05; return Math.max(2.50, snapped).toFixed(3); })} style={{ width: 28, height: 28, borderRadius: 6, border: `1.5px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 16, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>?</button>
                        <input type="text" inputMode="decimal" value={soldPPWStr} onChange={e => setSoldPPWStr(e.target.value.replace(/[^0-9.]/g, ""))} style={{ width: 100, textAlign: "center", fontFamily: c.mono, fontWeight: 700, fontSize: 16, padding: "5px 8px", border: `2px solid ${c.accent}`, borderRadius: 7, background: c.accentL, color: c.accent, outline: "none" }} />
                        <button onClick={() => setSoldPPWStr(v => { const n = parseFloat(v) || 0; const d = parseFloat((n / 0.05).toFixed(6)); const ce = Math.ceil(d); const snapped = Math.abs(ce - d) < 0.0001 ? n + 0.05 : ce * 0.05; return Math.min(5.00, snapped).toFixed(3); })} style={{ width: 28, height: 28, borderRadius: 6, border: `1.5px solid ${c.border2}`, background: c.surface, color: c.text, fontSize: 16, fontWeight: 700, cursor: "pointer", lineHeight: 1 }}>+</button>
                        <span style={{ fontSize: 10, color: c.text3 }}>$0.05/W increments</span>
                      </div>
                    </div>
                    <input type="range" min={2.50} max={5.00} step={0.05} value={Math.min(5.00, Math.max(2.50, parseFloat(soldPPWStr) || 3.80))} onChange={e => setSoldPPWStr(parseFloat(e.target.value).toFixed(3))} style={{ width: "100%", accentColor: c.accent, cursor: "pointer" }} />
                    <div style={{ display: "flex", justifyContent: "space-between", fontSize: 10, color: c.text3, marginTop: 3 }}><span>$2.50/W</span><span>$5.00/W</span></div>
                  </div>
                  <div style={{ background: c.surface2, border: `1px solid ${c.border}`, borderRadius: 8, padding: "11px 13px", marginBottom: 10 }}>
                    {[
                      [`Gross EPC Sold (${fmtPPW(soldPPW)})`, fmt(soldTotal), c.text, false],
                      ["Less Base Redline", `(${fmt(base$)})`, c.danger, false],
                      ...(adderList$ > 0 ? [["Less Adder List", `(${fmt(adderList$)})`, c.warn, false]] : []),
                      ["= Gross Sales Spread", fmt(commTotal), commTotal >= 0 ? c.text : c.danger, true],
                    ].map(([l, v, col, bold], i, arr) => (
                      <div key={i} style={{ display: "flex", justifyContent: "space-between", fontSize: 12, padding: "4px 0", borderBottom: i < arr.length - 1 ? `1px solid ${c.border}` : "none", fontWeight: bold ? 700 : 400 }}><span style={{ color: c.text2 }}>{l}</span><span style={{ fontFamily: c.mono, color: col }}>{v}</span></div>
                    ))}
                  </div>
                  <div style={{ background: commTotal >= 0 ? c.successL : c.dangerL, border: `1.5px solid ${commTotal >= 0 ? "rgba(22,101,52,.25)" : "rgba(185,28,28,.25)"}`, borderRadius: 9, padding: "13px 15px" }}>
                    <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
                      <div>
                        <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".1em", textTransform: "uppercase", color: commTotal >= 0 ? c.success : c.danger, marginBottom: 3 }}>Rep Commission</div>
                        <div style={{ fontSize: 11, color: commTotal >= 0 ? c.success : c.danger, opacity: .8 }}>{fmtPPW(Math.abs(commPPW))} ? {Math.abs(commPct).toFixed(1)}% of sold</div>
                      </div>
                      <div style={{ fontFamily: c.mono, fontSize: 28, fontWeight: 800, color: commTotal >= 0 ? c.success : c.danger, lineHeight: 1 }}>{fmt(Math.abs(commTotal))}</div>
                    </div>
                    {commTotal < 0 && <div style={{ fontSize: 11, color: c.danger, fontWeight: 600, marginTop: 7 }}>? Sold price is below floor ? deal is at a loss.</div>}
                  </div>
                </>
              ) : (
                <>
                  <div style={{ marginBottom: 14 }}>
                    <div style={lbl}>Target Commission ($)</div>
                    <input type="number" min={0} step={100} value={targetCommStr} onChange={e => setTargetCommStr(e.target.value)} placeholder="e.g. 3000" style={{ width: "100%", fontFamily: c.mono, fontWeight: 600, fontSize: 14, padding: "9px 13px", border: `1.5px solid ${c.accent}`, borderRadius: 8, background: c.accentL, color: c.accent, outline: "none" }} />
                  </div>
                  {targetComm > 0 ? (
                    <div style={{ background: c.successL, border: "1.5px solid rgba(22,101,52,.25)", borderRadius: 9, padding: "13px 15px" }}>
                      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
                        <div><div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".1em", textTransform: "uppercase", color: c.success, marginBottom: 3 }}>Required Sold EPC</div><div style={{ fontSize: 11, color: c.success, opacity: .8 }}>{fmt(reqTotal)} total ? {reqCommPct.toFixed(1)}% commission rate</div></div>
                        <div style={{ fontFamily: c.mono, fontSize: 28, fontWeight: 800, color: c.success, lineHeight: 1 }}>{fmtPPW(reqPPW)}</div>
                      </div>
                    </div>
                  ) : (
                    <div style={{ background: c.surface3, border: `1.5px dashed ${c.border2}`, borderRadius: 8, padding: "11px 13px", fontSize: 12, color: c.text3, textAlign: "center" }}>Enter a target commission to see required EPC.</div>
                  )}
                </>
              )}
              <div style={{ fontSize: 10, color: c.text3, marginTop: 9, lineHeight: 1.6 }}>Gross EPC Sold ? less Base Redline ({effectiveM}% GM) = Gross Spread ? less Adder List = Rep Commission.</div>
            </div>
          );
        })()}

        {/* 10 ? Operations P&L */}
        {!salesView && C && (() => {
          const W         = C.W;
          // If a lender option is locked in the commissions tab, use that option's actual EPC
          const lockedOpt = waterfallLender ? selectedOptions[waterfallLender] : null;
          const lockedEPC = lockedOpt ? lockedOpt.epc : null;
          const effectiveSoldPPW = lockedEPC || parseFloat(soldPPWStr) || 0;
          const soldTotal = effectiveSoldPPW * W;
          const hasSoldRate = commMode === "sold_rate" && effectiveSoldPPW > 0;
          const base$     = C.targetSc.baseRedline$;
          const adderList$ = C.listSum;
          const grossSpread = soldTotal - base$;
          const commTotal = hasSoldRate ? Math.max(0, grossSpread - adderList$) : 0;
          const allInCost = C.totalAllin;
          const grossOpsIncome = hasSoldRate ? soldTotal - allInCost - commTotal : base$ + adderList$ - allInCost;
          const opsMarginPct   = hasSoldRate && soldTotal > 0 ? (grossOpsIncome / soldTotal * 100) : 0;
          const hbPct          = C.hb?.total || 0;
          const hbAmt          = hbPct * W;
          const atFunding      = hasSoldRate ? soldTotal - allInCost - commTotal : null;
          const totalOpsIncome = hasSoldRate ? atFunding + hbAmt : grossOpsIncome;
          const equipCost      = C.equipTotal;
          const laborCost      = C.baseLaborCost;
          const gaCost         = C.gaCost;
          const sopsCost       = C.sopsCost;
          const ancillaryCost  = C.ancillaryCost;
          const adderCostTotal = C.adderSum;
          const premCost       = (C.nonflushPrem || 0) + (C.detachPrem || 0);

          return (
            <div style={card}>
              <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 14 }}>
                <span style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".18em", textTransform: "uppercase", color: c.accent }}>10 ? Operations P&L</span>
                <div style={{ display:"flex", alignItems:"center", gap:8 }}>
                  {waterfallLender && lockedEPC && <span style={{ fontSize: 10, fontWeight: 700, padding:"2px 9px", borderRadius:20, background:c.accentL, color:c.accent, border:`1px solid rgba(13,110,110,.2)` }}>? {lockedOpt?.lender === "IGS_TX" ? "IGS TX" : (lockedOpt?.lender || waterfallLender)} ? {lockedOpt?.type === "bestComm" ? "?" : lockedOpt?.type === "closestMatch" ? "?" : "?"} ? {fmtPPW(lockedEPC)}</span>}
                  <span style={{ fontSize: 11, color: c.text3 }}>Expected ops return on this deal</span>
                </div>
              </div>
              {!hasSoldRate ? (
                <div style={{ background: c.surface3, border: `1.5px dashed ${c.border2}`, borderRadius: 8, padding: "14px", fontSize: 12, color: c.text3, textAlign: "center" }}>Set a Sold EPC in Section 09 to see ops P&L.</div>
              ) : (
                <>
                  {/* Top metric strip */}
                  <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 8, marginBottom: 14, background: c.surface2, borderRadius: 8, padding: "10px 12px" }}>
                    {[
                      ["Net Funding",       hasSoldRate ? fmt(atFunding) : "?", fmtPPW((atFunding || 0) / W), atFunding >= 0 ? c.success : c.danger],
                      ["+ Holdback Bonus",  hbPct > 0 ? fmt(hbAmt) : "None",   hbPct > 0 ? `${fmtPPW(hbPct)} post-PTO` : "No holdback this lender", hbPct > 0 ? c.warn : c.text3],
                      ["Total Ops Income",  hasSoldRate ? fmt(totalOpsIncome) : "?", hbPct > 0 ? `${((totalOpsIncome / soldTotal) * 100).toFixed(1)}% of sold` : `${opsMarginPct.toFixed(1)}% of sold`, totalOpsIncome >= 0 ? c.success : c.danger],
                    ].map(([l, v, s, col]) => (
                      <div key={l} style={{ textAlign: "center" }}>
                        <div style={{ fontSize: 10, color: c.text3, fontWeight: 700, textTransform: "uppercase", letterSpacing: ".07em", marginBottom: 3 }}>{l}</div>
                        <div style={{ fontFamily: c.mono, fontSize: 13, fontWeight: 700, color: col }}>{v}</div>
                        <div style={{ fontSize: 10, color: c.text3, marginTop: 2 }}>{s}</div>
                      </div>
                    ))}
                  </div>
                  {/* Waterfall */}
                  <div style={{ background: c.surface2, border: `1px solid ${c.border}`, borderRadius: 8, padding: "11px 13px", marginBottom: 12 }}>
                    <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".1em", textTransform: "uppercase", color: c.text3, marginBottom: 8 }}>Revenue & Cost Waterfall</div>
                    {[
                      [`Gross EPC Sold (${fmtPPW(effectiveSoldPPW)}${lockedEPC ? ` ? ${lockedOpt?.lender === "IGS_TX" ? "IGS TX" : lockedOpt?.lender} actual` : ""})`, fmt(soldTotal), c.text, false],
                      ["Less: Equipment & Materials", `(${fmt(equipCost)})`, c.text2, false],
                      ["Less: Install Labor", `(${fmt(laborCost)})`, c.text2, false],
                      ["Less: G&A", `(${fmt(gaCost)})`, c.text2, false],
                      ["Less: Sales Ops", `(${fmt(sopsCost)})`, c.text2, false],
                      ["Less: Ancillary COGS", `(${fmt(ancillaryCost)})`, c.text2, false],
                      ...(adderCostTotal > 0 ? [["Less: Adder Costs", `(${fmt(adderCostTotal)})`, c.text2, false]] : []),
                      ...(premCost > 0 ? [["Less: Roof Premiums", `(${fmt(premCost)})`, c.text2, false]] : []),
                      ["= Gross Margin", fmt(soldTotal - allInCost), soldTotal - allInCost >= 0 ? c.text : c.danger, true],
                      ["Less: Rep Commission", `(${fmt(commTotal)})`, c.warn, false],
                      ["= Net Funding", fmt(atFunding || 0), (atFunding || 0) >= 0 ? c.success : c.danger, true],
                      ...(hbPct > 0 ? [[`+ Holdback Bonus (${fmtPPW(hbPct)} post-PTO)`, fmt(hbAmt), c.warn, false], ["= Total Ops Income", fmt(totalOpsIncome), totalOpsIncome >= 0 ? c.success : c.danger, true]] : []),
                    ].map(([l, v, col, bold], i, arr) => (
                      <div key={i} style={{ display: "flex", justifyContent: "space-between", fontSize: 12, padding: "4px 0", borderBottom: i < arr.length - 1 ? `1px solid ${c.border}` : "none", fontWeight: bold ? 700 : 400 }}>
                        <span style={{ color: c.text2 }}>{l}</span>
                        <span style={{ fontFamily: c.mono, color: col }}>{v}</span>
                      </div>
                    ))}
                  </div>
                  {hbPct > 0 && (
                    <div style={{ background: totalOpsIncome >= 0 ? c.successL : c.dangerL, border: `1.5px solid ${totalOpsIncome >= 0 ? "rgba(22,101,52,.25)" : "rgba(185,28,28,.25)"}`, borderRadius: 9, padding: "13px 15px" }}>
                      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
                        <div>
                          <div style={{ fontSize: 10, fontWeight: 700, letterSpacing: ".1em", textTransform: "uppercase", color: totalOpsIncome >= 0 ? c.success : c.danger, marginBottom: 3 }}>Total Ops Income</div>
                          <div style={{ fontSize: 11, color: totalOpsIncome >= 0 ? c.success : c.danger, opacity: .8 }}>{fmt(atFunding || 0)} at funding + {fmt(hbAmt)} holdback bonus</div>
                        </div>
                        <div style={{ fontFamily: c.mono, fontSize: 28, fontWeight: 800, color: totalOpsIncome >= 0 ? c.success : c.danger, lineHeight: 1 }}>{fmt(totalOpsIncome)}</div>
                      </div>
                    </div>
                  )}
                </>
              )}
            </div>
          );
        })()}

      </div>{/* end row 7 grid */}

      <div style={{ textAlign: "center", color: c.text3, fontSize: 10, marginTop: 20, letterSpacing: ".1em" }}>eEquals Solar ? CR Solar LLC ? Pricing Model v2.5 ? March 2026 ? Internal Use Only</div>
      </>}{/* end Tab 1 */}

      {activeTab === "commissions" && <CommissionsTab c={c} card={card} lbl={lbl} fmt={fmt} fmtPPW={fmtPPW} C={C} st={st} lender={lender} watts={watts} jobType={jobType} dcOn={dcOn} targetM={targetM} setTargetM={setTargetM} customMStr={customMStr} setCustomMStr={setCustomMStr} effectiveM={effectiveM} setPresetM={setPresetM} soldPPWStr={soldPPWStr} setSoldPPWStr={setSoldPPWStr} setActiveTab={setActiveTab} util={util} setUtil={setUtil} ecOn={ecOn} setEcOn={setEcOn} maxPmtStr={maxPmtStr} setMaxPmtStr={setMaxPmtStr} linputs={linputs} setLinputs={setLinputs} waterfallLender={waterfallLender} setWaterfallLender={setWaterfallLender} selectedOptions={selectedOptions} setSelectedOptions={setSelectedOptions} showOptionPicker={showOptionPicker} setShowOptionPicker={setShowOptionPicker} splits={splits} setSplits={setSplits} showInactive={showInactive} setShowInactive={setShowInactive} commView={commView} setCommView={setCommView} campaignOn={campaignOn} campaignSalesPPW={C?.campaignSalesPPW || 0} campaignDealerMode={campaignP?.dealerMode || false} escrowOn={escrowOn} setEscrowOn={setEscrowOn} />}
      {activeTab === "dealer" && <DealerTab c={c} card={card} lbl={lbl} fmt={fmt} fmtPPW={fmtPPW} C={C} st={st} lender={lender} laborMode={laborMode} />}
      {activeTab === "bom" && <BOMTab c={c} card={card} lbl={lbl} fmt={fmt} fmtPPW={fmtPPW} priceOverrides={priceOverrides} pdfParsing={pdfParsing} pdfDiff={pdfDiff} pdfSelected={pdfSelected} setPdfSelected={setPdfSelected} pdfFileName={pdfFileName} setPdfFileName={setPdfFileName} pdfError={pdfError} pdfApplied={pdfApplied} parsePDF={parsePDF} applyPriceChanges={applyPriceChanges} />}

      {activeTab === "bos" && <BOSTab c={c} card={card} fmt={fmt} bosItems={bosItems} setBosItems={setBosItems} />}

    </div>
  );
}

ReactDOM.createRoot(document.getElementById('root')).render(React.createElement(PricingTool));
