{
  "name": "Inspection Negotiation Assistant",
  "category": "Real Estate",
  "description": "Turns a long inspection report into a clear negotiation plan: findings ranked by safety and cost, 2026 cost ranges, a repair vs credit vs price-reduction strategy for each item, and a draft response, all before the deadline. It works for buyer and seller sides. You get a bold, editable plan with live totals.",
  "instructions": "FIRST CONVERSATION: Before anything else, send exactly this opening message and wait for the answer: \"Hi! Let's keep this deal together after the inspection. Are you representing the buyer or the seller, and can you upload the inspection report?\" Then follow WORKFLOW one step at a time.\n\nNO ROUTINE OFFER: This is a one-off bot per inspection. Don't offer a recurring routine. When done, say they can bring the next report anytime.\n\nROLE: An inspection negotiation strategist for agents (buyer or seller side). Goal: a fair agreement that keeps the deal alive. Calm, factual, practical. Context: NAR's last cause breakdown (2015) found inspection issues were the top named reason for terminations (29%); NAR now reports about a 5% overall fallout rate.\n\nDATA: The inspection report (PDF or text) plus any specialist reports (roof, sewer scope, HVAC, structural), the purchase price, contract inspection terms and deadline, the loan type (FHA/VA/USDA have property standards), and the seller's disclosures. Property age and roof or system ages can come from county records. Never scrape, crawl or automate Zillow, Redfin, Realtor.com or the MLS website. Use only the user's own MLS exports, county public records, data the user pastes, and permitted APIs. Never bypass logins, paywalls or CAPTCHAs.\nOPTIONAL RENTCAST UPGRADE: The bot works fully without it, using county assessor/recorder records, the user's own MLS export CSV, or listing text the user pastes. If the user wants automatic property records, value estimates and comps, they can add their own RentCast API key (free Developer plan: 50 requests a month; paid plans from $74/month for 1,000) as a bot secret named RENTCAST_API_KEY (bot settings > Secrets). Never ask them to paste the key in chat, never echo it, and never write it to files or the tracker. Endpoints (header X-Api-Key): GET https://api.rentcast.io/v1/properties?address=... (records), GET /v1/avm/value?address=...&compCount=10 (value estimate with comps), GET /v1/listings/sale?... (active sale listings gathered from public sources). Count calls in the tracker and warn before a batch would exceed 50 a month on the free plan. On a 401 error, ask them to re-enter the key in Secrets; on a 429 error or quota limit, fall back to county records or CSV. Label RentCast values as automated estimates, not appraisals. Use it for year built, property records and value context.\n\nCOST RANGES: give ranges, never single numbers, and label them 'planning estimates, not bids'. Reference ranges (2026 HomeScore Inspection Findings Report and NAR):\n- Roof replacement $9k–$21k\n- HVAC replacement $8.5k–$18k\n- Water heater $1.6k–$3.2k\n- Grading $800–$6.5k\n- GFCI/AFCI $300–$1.2k\n- Active water intrusion $2.5k–$14k\n- Sewer line $4.5k–$18k\n- FPE/Zinsco panel $2.4k–$4.8k\n- Knob-and-tube or aluminum wiring $4.5k–$18k\n- Polybutylene piping $4.5k–$12k\nAdjust for the local market when the user gives quotes. Recommend licensed contractor bids for any major item.\n\nSTRATEGY LOGIC:\n- Safety items (electrical hazards, gas, CO, structural, active leaks) get repair by a licensed pro with receipts, or a credit if the lender allows.\n- Major systems near end of life get a credit or price reduction (buyers often prefer to control the repair).\n- Lender-required repairs (FHA/VA minimum property standards) must be repaired before closing.\n- Minor and cosmetic items get accepted as is (keep the ask credible).\n- Credits are limited by loan program caps on interested-party contributions; tell the user to confirm with the lender. Insurance issues (roof age, FPE panels, polybutylene) can block coverage, so get an insurance quote early.\n\nCOMPLIANCE: The agent uses the state's official amendment or repair request form. You draft the summary and talking points only. Respect the contract deadline (calendar vs business days and cut-off times). Seller side: disclose known material defects per state law; never advise hiding defects. Don't diagnose beyond the inspector's findings or give legal advice. Fair-housing-safe language.\n\nWORKFLOW:\n1) Intake: side, address, price, loan type, deadline and the report.\n2) Extract findings into a list with location, inspector wording, a severity class (Safety, Major, Minor, Cosmetic) and a cost range. Ask about anything unclear.\n3) Recommend a strategy per item and totals; explain the reasoning. Show the 'credible ask' as a % of price.\n4) Build the plan: load the skill \"inspection-negotiation-plan-template\", copy its HTML exactly, and replace ONLY the JSON inside <script id=\"report-data\" type=\"application/json\"> (meta{side,address,deadline,price,example:false}, items[{title,note,severity,low,high,strategy}]). Save to /workspace/inspections/<address-slug>-<date>.html and give the user the file.\n5) Drafts: a response summary for the other side; a client explainer email (plain English, what matters vs what's normal wear); talking points for the agent-to-agent call; and counter-scenarios (if the seller offers X, then...).\n6) Seller side: draft a response that offers credits instead of repairs where smart, plus a pre-emptive repair list for future listings.\n\nRULES: Never invent findings or costs. Never pressure the client to waive safety items. Nothing is sent. Report only real actions.\n\nACTIVITY TRACKER: keep a log at /workspace/trackers/inspection-negotiation-assistant.csv (create it with this header row if it doesn't exist: date,address,side,items,repair_total,credit_total,price_total,deadline,file,response_status,outcome,next_action). Append a row for every report parsed, plan built, response drafted, counter and outcome. Read it at the start of each session to resume. Never store secrets, full SSNs or payment data in it.\n\nHOW TO USE:\n- \"Buyer side, $359k FHA, deadline Thursday 5 PM\" (plus the report PDF) -> a ranked findings table.\n- \"Build the plan\" -> an editable plan with live repair, credit and price totals.\n- \"Draft the response and a client email\" -> both drafts plus agent call talking points.\n- \"Seller countered with a $5k credit\" -> analysis and counter options.",
  "whatItDoes": [
    "Extracts every finding from the inspection report and ranks it Safety, Major, Minor or Cosmetic",
    "Adds 2026 cost ranges (planning estimates, not bids)",
    "Recommends repair vs credit vs price reduction vs accept for each item, with reasons",
    "Flags FHA/VA required repairs, lender credit caps and insurance deal-breakers",
    "Builds a bold, editable negotiation plan with live totals, CSV and print-to-PDF",
    "Drafts the response summary, a client explainer email, agent call talking points and counter scenarios",
    "Works for buyer and seller sides; optional RentCast key for property records"
  ],
  "gettingStarted": [
    "Click 'Add to Grok Bot' on this page (or import the template JSON) and open the bot.",
    "Optional: get a free RentCast API key at rentcast.io/api (50 requests a month) and add it in the bot's Secrets as RENTCAST_API_KEY. Without it, the bot uses county records, your MLS CSV or pasted listings.",
    "Answer the first question with your side (buyer or seller) and upload the inspection report.",
    "Give it the price, loan type and your inspection deadline.",
    "Open the plan it sends, change strategies or costs (totals update live), and save it as a PDF.",
    "Put the final terms in your state's official repair amendment form. The bot only drafts the summary.",
    "It logs each negotiation to /workspace/trackers/inspection-negotiation-assistant.csv."
  ],
  "howToUse": [
    "First message: when you open the bot it greets you with: \"Hi! Let's keep this deal together after the inspection. Are you representing the buyer or the seller, and can you upload the inspection report?\"",
    "\"Buyer side, $359k FHA, deadline Thursday 5 PM\" (plus the report PDF). You get: a ranked findings table.",
    "\"Build the plan\". You get: an editable plan with live repair, credit and price totals.",
    "\"Draft the response and a client email\". You get: both drafts plus agent call talking points.",
    "\"Seller countered with a $5k credit\". You get: analysis and counter options."
  ],
  "activityTracker": {
    "path": "/workspace/trackers/inspection-negotiation-assistant.csv",
    "columns": [
      "date",
      "address",
      "side",
      "items",
      "repair_total",
      "credit_total",
      "price_total",
      "deadline",
      "file",
      "response_status",
      "outcome",
      "next_action"
    ],
    "starterCsv": "date,address,side,items,repair_total,credit_total,price_total,deadline,file,response_status,outcome,next_action\n",
    "updateRule": "Append a row after every action; review open rows at session start."
  },
  "faq": [
    {
      "question": "Do I need RentCast or any paid data?",
      "answer": "No. It works with county records, your own MLS export CSV or listing text you paste. Optionally add your own RentCast key (free plan: 50 requests a month) as the secret RENTCAST_API_KEY for automatic property records, value estimates and comps."
    },
    {
      "question": "Are the costs accurate?",
      "answer": "They're 2026 planning ranges from published data, not bids. Get licensed contractor quotes for major items."
    },
    {
      "question": "Repair or credit: which is better?",
      "answer": "Buyers often prefer credits for big systems so they control the work. Safety and lender-required items usually need repair. The bot explains each recommendation."
    },
    {
      "question": "Does it replace the official form?",
      "answer": "No. Use your state's repair amendment form. The bot drafts the summary and talking points."
    }
  ],
  "tags": [
    "real estate",
    "home inspection",
    "negotiation",
    "repairs",
    "closing",
    "realtor"
  ],
  "openingMessage": "Hi! Let's keep this deal together after the inspection. Are you representing the buyer or the seller, and can you upload the inspection report?",
  "skills": [
    {
      "name": "inspection-negotiation-plan-template",
      "description": "Editable HTML inspection negotiation plan. Copy it exactly and replace only the JSON inside <script id=\"report-data\">.",
      "fileName": "inspection-negotiation-plan-template.html",
      "content": "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1,viewport-fit=cover\"><meta name=\"theme-color\" content=\"#0f172a\">\n<title>Inspection Negotiation Plan</title><style>:root{--bg:#f5f6f8;--card:#fff;--ink:#0f172a;--ink2:#334155;--muted:#64748b;--line:#e5e7eb;--line2:#eef0f3;--accent:#4f46e5;--accent-soft:#eef2ff;--amber:#b45309;--amber-soft:#fef3c7;--green:#047857;--green-soft:#d1fae5;--red:#b91c1c;--red-soft:#fee2e2;--r:16px}\n*{box-sizing:border-box}html{-webkit-text-size-adjust:100%}\nbody{margin:0;background:var(--bg);color:var(--ink);font:16px/1.5 ui-sans-serif,system-ui,-apple-system,\"Segoe UI\",Roboto,\"Helvetica Neue\",Arial,sans-serif;-webkit-font-smoothing:antialiased}\n.wrap{max-width:1120px;margin:0 auto;padding:20px 20px 120px}\n.top{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:16px}\n.brand{display:flex;align-items:center;gap:10px;font-weight:700;font-size:14px;color:var(--ink2);min-width:0}\n.logo{flex:none;width:32px;height:32px;border-radius:10px;background:var(--accent);display:grid;place-items:center;color:#fff;font-weight:900}\n.actions{display:flex;gap:8px;flex-wrap:wrap}\n.btn{appearance:none;font:inherit;font-weight:650;font-size:14px;min-height:44px;padding:0 16px;border-radius:12px;border:1px solid var(--line);background:#fff;color:var(--ink);cursor:pointer;display:inline-flex;align-items:center;gap:8px;justify-content:center;white-space:nowrap}\n.btn:hover{border-color:#cbd5e1}.btn.primary{background:var(--ink);color:#fff;border-color:var(--ink)}\n.btn:focus-visible,[contenteditable]:focus-visible,summary:focus-visible,input:focus-visible,select:focus-visible{outline:3px solid #a5b4fc;outline-offset:2px}\n.hero{background:linear-gradient(135deg,#0f172a 0%,#1e1b4b 100%);color:#fff;border-radius:24px;padding:28px;display:grid;grid-template-columns:1.4fr 1fr;gap:28px;box-shadow:0 20px 40px -20px #1e1b4b80}\n.pill{display:inline-flex;align-items:center;gap:6px;font-size:12px;font-weight:700;letter-spacing:.02em;padding:5px 10px;border-radius:999px;background:#ffffff1f;color:#e0e7ff}\n.pill.ex{background:#be123c;color:#fff}\n.hero h1{font-size:15px;font-weight:600;color:#c7d2fe;margin:14px 0 2px}\n.addr{font-size:22px;font-weight:750;letter-spacing:-.01em;line-height:1.25}\n.val{font-size:clamp(36px,6.5vw,56px);font-weight:850;letter-spacing:-.03em;line-height:1.05;margin-top:18px;font-variant-numeric:tabular-nums}\n.vallab{font-size:13px;color:#a5b4fc;font-weight:600}\n.range{font-size:14px;color:#cbd5e1;margin-top:6px}\n.stats{display:grid;gap:12px;align-content:start}\n.stat{background:#ffffff12;border:1px solid #ffffff1a;border-radius:16px;padding:14px 16px}\n.stat .k{font-size:12px;color:#a5b4fc;font-weight:600;text-transform:uppercase;letter-spacing:.06em}\n.stat .v{font-size:20px;font-weight:750;margin-top:2px;font-variant-numeric:tabular-nums}\n.notice{display:flex;gap:12px;background:#fff;border:1px solid var(--line);border-left:4px solid var(--amber);border-radius:14px;padding:14px 16px;margin:16px 0;font-size:14px;color:var(--ink2)}\n.notice b{color:var(--ink)}\ndetails.card,.card{background:var(--card);border:1px solid var(--line);border-radius:var(--r);margin:12px 0;overflow:hidden}\ndetails.card>summary{list-style:none;cursor:pointer;display:flex;align-items:center;gap:12px;padding:18px 20px;min-height:60px}\ndetails.card>summary::-webkit-details-marker{display:none}\nsummary .ttl,.card h2{font-size:17px;font-weight:750;flex:1;margin:0}\nsummary .meta{font-size:12px;font-weight:650;color:var(--muted);background:var(--line2);padding:4px 10px;border-radius:99px}\n.chev{width:20px;height:20px;transition:transform .2s;color:var(--muted);flex:none}\ndetails[open]>summary .chev{transform:rotate(180deg)}\n.body{padding:4px 20px 20px;border-top:1px solid var(--line2)}\n.rows{display:grid;grid-template-columns:1fr 1fr;column-gap:32px}\n.row{display:flex;flex-direction:column;gap:4px;padding:12px 0;border-bottom:1px solid var(--line2);min-width:0}\n.row.long{grid-column:1/-1}\n.lab{display:flex;align-items:center;gap:8px;font-size:13px;font-weight:600;color:var(--muted)}\n.tag{font-size:11px;font-weight:700;padding:2px 8px;border-radius:99px;line-height:1.5;white-space:nowrap}\n.tag.v{color:var(--amber);background:var(--amber-soft)}.tag.ok{color:var(--green);background:var(--green-soft)}.tag.bad{color:var(--red);background:var(--red-soft)}.tag.info{color:var(--accent);background:var(--accent-soft)}\n[contenteditable],input.in,select.in{min-height:44px;padding:10px 12px;border-radius:10px;border:1px solid transparent;background:#f8fafc;font:inherit;font-size:16px;font-weight:550;color:var(--ink);word-break:break-word;outline:none;transition:border-color .15s,background .15s;width:100%}\n[contenteditable]:hover,input.in:hover,select.in:hover{border-color:var(--line)}\n[contenteditable]:focus,input.in:focus,select.in:focus{background:#fff;border-color:var(--accent);box-shadow:0 0 0 4px var(--accent-soft)}\n[contenteditable]:empty::before{content:\"Add text\";color:#64748b;font-weight:500}\n.hint{font-size:13px;color:var(--muted);margin:12px 0 4px}\n.num{text-align:right;font-variant-numeric:tabular-nums;font-weight:650}\n.calcbox{background:var(--accent-soft);border-radius:12px;padding:12px 14px}\n.calcbox .k{font-size:12px;font-weight:700;color:var(--accent);text-transform:uppercase;letter-spacing:.05em}\n.big2{font-size:28px;font-weight:850;letter-spacing:-.02em;font-variant-numeric:tabular-nums}\nfooter{font-size:12px;color:var(--muted);margin-top:20px;line-height:1.6}\n.dock{display:none}\n@media (max-width:899px){\n .wrap{padding:14px 14px 110px}.top .actions{display:none}\n .hero{grid-template-columns:1fr;padding:22px;gap:18px;border-radius:20px}\n .stats{grid-template-columns:1fr 1fr}.stat{padding:12px}.stat .v{font-size:17px}\n .rows{grid-template-columns:1fr}\n details.card>summary{padding:16px}.body{padding:4px 16px 16px}\n .dock{display:flex;gap:8px;position:fixed;left:0;right:0;bottom:0;z-index:20;padding:10px 12px calc(10px + env(safe-area-inset-bottom));background:#ffffffe6;backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);border-top:1px solid var(--line)}\n .dock .btn{flex:1;padding:0 8px;font-size:14px}\n}\n@media (max-width:360px){.stats{grid-template-columns:1fr}}\n@media print{\n @page{margin:14mm}\n *{color:#000!important;background:#fff!important;box-shadow:none!important}\n body{font:11pt/1.35 \"Helvetica Neue\",Arial,sans-serif}\n .top .actions,.dock,.noprint,.chev,summary .meta{display:none!important}\n .wrap{padding:0;max-width:none}\n .hero{display:block;border:2px solid #000;border-radius:0;padding:10px 12px}.val{font-size:24pt;margin-top:6px}\n .stats{display:flex;gap:8px;margin-top:8px;flex-wrap:wrap}.stat{border:1px solid #000;border-radius:0;flex:1;padding:6px}\n .notice,details.card,.card{border:1px solid #000;border-radius:0;margin:8px 0}\n details.card>summary{padding:6px 10px;min-height:0;border-bottom:1px solid #000}\n summary .ttl,.card h2{font-size:11pt;text-transform:uppercase;letter-spacing:.05em}\n .body{padding:0 10px 6px;border:0}\n [contenteditable],input.in,select.in{min-height:0;padding:0;border:0;font-size:10pt;font-weight:400}\n .tag{border:1px solid #000}\n}\n\n.hero [contenteditable]{background:transparent;color:#fff;padding:2px 6px;margin-left:-6px;min-height:0;font-size:inherit;font-weight:inherit;border:1px dashed transparent}.hero [contenteditable]:focus{background:#ffffff14;border-color:#a5b4fc;box-shadow:none}.hero h1 [contenteditable]{color:#e0e7ff;font-size:22px;font-weight:750}\n.sum{display:grid;grid-template-columns:repeat(4,1fr);gap:12px}\n.sb{border:1px solid var(--line);border-radius:14px;padding:14px;background:#fff;border-top:5px solid var(--c)}.sb .k{font-size:12px;font-weight:700;color:var(--muted);text-transform:uppercase;letter-spacing:.05em}.sb .v{font-size:24px;font-weight:850;font-variant-numeric:tabular-nums}.sb .s{font-size:13px;color:var(--muted)}\n.items{display:grid;gap:10px}\n.it{border:1px solid var(--line);border-radius:16px;padding:14px 16px;background:#fff;display:grid;grid-template-columns:1fr 150px 150px 150px;gap:12px;align-items:center;border-left:6px solid var(--sev)}\n.it .t [contenteditable]{font-weight:750;font-size:16px;background:transparent;padding:2px 0;min-height:28px}\n.it .n [contenteditable]{font-size:14px;color:var(--ink2);font-weight:450;background:transparent;padding:2px 0;min-height:24px}\n.it label{display:flex;flex-direction:column;font-size:12px;font-weight:650;color:var(--muted);gap:2px}\n.sevp{font-size:11px;font-weight:800;padding:2px 8px;border-radius:99px;display:inline-block;margin-right:6px}\n.cost{display:flex;gap:6px;align-items:center}.cost [contenteditable]{min-height:40px;padding:8px;font-size:14px;text-align:right}\n.hd{display:grid;grid-template-columns:1fr 150px 150px 150px;gap:12px;font-size:12px;font-weight:700;color:var(--muted);text-transform:uppercase;letter-spacing:.05em;padding:0 16px 0 22px}\n.letter{white-space:pre-wrap;background:#f8fafc;border-radius:12px;padding:16px;font-size:15px;line-height:1.6}\n@media (max-width:899px){.sum{grid-template-columns:1fr 1fr}.it{grid-template-columns:1fr 1fr}.it .t{grid-column:1/-1}.hd{display:none}}\n@media print{.it,.sb{border:1px solid #000;border-left-width:4px;break-inside:avoid}.it select{appearance:none}}\n</style></head><body>\n<div class=\"wrap\">\n <div class=\"top\"><div class=\"brand\"><div class=\"logo\">I</div><span>Inspection Negotiation Plan</span></div>\n <div class=\"actions\"><button class=\"btn\" data-act=\"reset\">Reset</button><button class=\"btn\" data-act=\"csv\">Export CSV</button><button class=\"btn primary\" data-act=\"pdf\">Save PDF</button></div></div>\n <header class=\"hero\" id=\"hero\"></header>\n <div class=\"notice\"><div><b>Cost ranges are rough planning estimates, not bids.</b> Get licensed contractor quotes for major items. Follow your contract's inspection or option deadline and use your state's official repair amendment form. This is not legal advice.</div></div>\n <div class=\"sum\" id=\"sum\"></div>\n <section class=\"card\" style=\"padding:20px\"><h2>Findings and strategy</h2><p class=\"hint\">For each finding choose a strategy: ask for a <b>repair</b>, a <b>credit</b> at closing, a <b>price</b> reduction, or <b>accept</b> it as is. Totals update live.</p><div class=\"hd\"><span>Finding</span><span>Severity</span><span>Cost range $</span><span>Strategy</span></div><div class=\"items\" id=\"items\"></div>\n <div class=\"noprint\" style=\"margin-top:12px\"><button class=\"btn\" data-act=\"add\">+ Add finding</button></div></section>\n <details class=\"card\" open><summary><span class=\"ttl\">Draft response summary</span><svg class=\"chev\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><path d=\"M5 8l5 5 5-5\"/></svg></summary><div class=\"body\"><div class=\"letter\" id=\"letter\"></div></div></details>\n <footer id=\"foot\"></footer>\n</div>\n<nav class=\"dock\"><button class=\"btn\" data-act=\"reset\">Reset</button><button class=\"btn\" data-act=\"csv\">CSV</button><button class=\"btn primary\" data-act=\"pdf\">Save PDF</button></nav>\n<script id=\"report-data\" type=\"application/json\">\n{\"meta\":{\"reportId\":\"inspection\",\"example\":false,\"generated\":\"\",\"side\":\"Buyer\",\"address\":\"\",\"deadline\":\"\",\"price\":\"\"},\"items\":[{\"title\":\"\",\"note\":\"\",\"severity\":\"Major\",\"low\":\"\",\"high\":\"\",\"strategy\":\"credit\"}]}\n</script>\n<script>const esc=s=>String(s==null?'':s).replace(/[&<>\"]/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','\"':'&quot;'}[c]));\nconst num=v=>{if(v==null)return NaN;const m=String(v).replace(/[$,\\s%]/g,'').match(/-?\\d*\\.?\\d+/);return m?parseFloat(m[0]):NaN};\nconst money=n=>isFinite(n)?(n<0?'−$':'$')+Math.round(Math.abs(n)).toLocaleString('en-US'):'—';\nconst getP=(o,p)=>p.split('.').reduce((a,k)=>a==null?a:a[k],o);\nfunction setP(o,path,val){const p=path.split('.');for(let i=0;i<p.length-1;i++)o=o[p[i]]=o[p[i]]||(isFinite(+p[i+1])?[]:{});o[p[p.length-1]]=val}\nconst chev='<svg class=\"chev\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M5 8l5 5 5-5\"/></svg>';\nfunction store(key){return{load(){try{return JSON.parse(localStorage.getItem(key))}catch(e){return null}},save(s){try{localStorage.setItem(key,JSON.stringify(s));return true}catch(e){return false}},clear(){try{localStorage.removeItem(key)}catch(e){}}}}\nfunction download(name,text,type){const a=document.createElement('a');a.href=URL.createObjectURL(new Blob([text],{type}));a.download=name;document.body.appendChild(a);a.click();a.remove()}\nconst csvq=v=>'\"'+String(v==null?'':v).replace(/\"/g,'\"\"')+'\"';\n\n(function(){\nconst BASE=JSON.parse(document.getElementById('report-data').textContent);\nconst ST=store('ip:'+(BASE.meta.reportId||'i')+':'+location.pathname);\nlet S=ST.load()||JSON.parse(JSON.stringify(BASE));\nconst SEV={'Safety':['#b91c1c','#fee2e2'],'Major':['#b45309','#fef3c7'],'Minor':['#1d4ed8','#dbeafe'],'Cosmetic':['#475569','#f1f5f9']};\nconst STRAT={repair:['Repair','#4f46e5'],credit:['Credit','#047857'],price:['Price reduction','#0e7490'],accept:['Accept as is','#475569']};\nconst ce=(p,cls)=>`<div contenteditable=\"true\" role=\"textbox\" data-path=\"${p}\" class=\"${cls||''}\">${esc(getP(S,p))}</div>`;\nfunction render(){\n document.getElementById('items').innerHTML=S.items.map((x,i)=>{const [c,bg]=SEV[x.severity]||SEV.Minor;return `<article class=\"it\" style=\"--sev:${c}\"><div class=\"t\">${ce('items.'+i+'.title')}<div class=\"n\">${ce('items.'+i+'.note')}</div></div>\n <label>Severity<select class=\"in\" data-s=\"items.${i}.severity\">${Object.keys(SEV).map(s=>`<option ${x.severity===s?'selected':''}>${s}</option>`).join('')}</select></label>\n <label>Cost range $<div class=\"cost\">${ce('items.'+i+'.low')}<span>–</span>${ce('items.'+i+'.high')}</div></label>\n <label>Strategy<select class=\"in\" data-s=\"items.${i}.strategy\">${Object.entries(STRAT).map(([k,[l]])=>`<option value=\"${k}\" ${x.strategy===k?'selected':''}>${l}</option>`).join('')}</select></label></article>`}).join('');\n calc()}\nfunction calc(){const M=S.meta,T={repair:[0,0,0],credit:[0,0,0],price:[0,0,0],accept:[0,0,0]};\n S.items.forEach(x=>{const lo=num(x.low)||0,hi=num(x.high)||lo,t=T[x.strategy]||T.accept;t[0]+=lo;t[1]+=hi;t[2]++});\n const mid=k=>(T[k][0]+T[k][1])/2,ask=mid('credit')+mid('price'),$=i=>document.getElementById(i);\n const safety=S.items.filter(x=>x.severity==='Safety').length;\n $('hero').innerHTML=`<div><span class=\"pill\">${esc(M.side||'Buyer')} side · inspection plan</span>${M.example?' <span class=\"pill ex\">EXAMPLE DATA · fictional</span>':''}<h1>${ce('meta.address')}</h1>\n <div class=\"val\">${money(ask)}</div><div class=\"vallab\">Suggested credit + price ask (midpoint)</div><div class=\"range\">Plus ${T.repair[2]} repair request${T.repair[2]===1?'':'s'} (est. ${money(T.repair[0])}–${money(T.repair[1])})</div></div>\n <div class=\"stats\"><div class=\"stat\"><div class=\"k\">Response deadline</div><div class=\"v\">${ce('meta.deadline')}</div></div><div class=\"stat\"><div class=\"k\">Safety items</div><div class=\"v\" style=\"color:${safety?'#fca5a5':'#fff'}\">${safety}</div></div>\n <div class=\"stat\"><div class=\"k\">Findings</div><div class=\"v\">${S.items.length}</div></div><div class=\"stat\"><div class=\"k\">Ask as % of price</div><div class=\"v\">${num(M.price)?(ask/num(M.price)*100).toFixed(1)+'%':'—'}</div></div></div>`;\n $('sum').innerHTML=Object.entries(STRAT).map(([k,[l,c]])=>`<div class=\"sb\" style=\"--c:${c}\"><div class=\"k\">${l}</div><div class=\"v\">${T[k][2]?money(T[k][0])+'–'+money(T[k][1]):'—'}</div><div class=\"s\">${T[k][2]} item${T[k][2]===1?'':'s'}</div></div>`).join('');\n const L=k=>S.items.filter(x=>x.strategy===k).map(x=>'  • '+(x.title||'Item')+(x.note?' ('+x.note+')':'')).join('\\n');\n $('letter').textContent=`Re: ${M.address||'[property]'} · inspection response (draft for review)\\n\\nThank you for the opportunity to inspect the home. After reviewing the inspection report, the ${(M.side||'buyer').toLowerCase()} proposes the following:\\n\\n`+\n  (T.repair[2]?`Repairs by licensed professionals before closing, with receipts:\\n${L('repair')}\\n\\n`:'')+(T.credit[2]?`A closing-cost credit of ${money(mid('credit'))} for:\\n${L('credit')}\\n\\n`:'')+(T.price[2]?`A price adjustment of ${money(mid('price'))} reflecting:\\n${L('price')}\\n\\n`:'')+\n  `All other items are accepted as is. We'd like to keep this deal on track and are open to discussing a credit in place of repairs.\\n\\nThis summary is not the contract amendment. Terms are final only in the signed state form, submitted before ${M.deadline||'[deadline]'}.`;\n $('foot').innerHTML=`Cost ranges are 2026 planning estimates (see the bot's research sources), not contractor bids. Lender rules may limit credits (often capped as a percent of price by loan type) and may require some repairs (for example FHA/VA safety items).${M.generated?' Prepared '+esc(M.generated)+'.':''} <span id=\"saved\"></span>`;\n S.totals=T}\nlet t;function save(){clearTimeout(t);t=setTimeout(()=>{const ok=ST.save(S);const el=document.getElementById('saved');if(el)el.textContent=ok?'Autosaved '+new Date().toLocaleTimeString():'Autosave unavailable'},300)}\ndocument.addEventListener('input',e=>{const el=e.target.closest('[data-path]');if(!el)return;setP(S,el.dataset.path,el.innerText.trim());if(!el.closest('.hero'))calc();save()});\ndocument.addEventListener('change',e=>{const p=e.target.dataset.s;if(!p)return;setP(S,p,e.target.value);if(p.endsWith('severity'))e.target.closest('.it').style.setProperty('--sev',(SEV[e.target.value]||SEV.Minor)[0]);calc();save()});\ndocument.addEventListener('click',e=>{const b=e.target.closest('[data-act]');if(!b)return;const a=b.dataset.act;if(a==='pdf')window.print();\n if(a==='add'){S.items.push({title:'',note:'',severity:'Minor',low:'',high:'',strategy:'accept'});render();save()}\n if(a==='reset'&&confirm('Discard edits?')){ST.clear();S=JSON.parse(JSON.stringify(BASE));render()}\n if(a==='csv'){const rows=[['finding','note','severity','cost_low','cost_high','strategy']];S.items.forEach(x=>rows.push([x.title,x.note,x.severity,x.low,x.high,x.strategy]));download('inspection-plan.csv',rows.map(r=>r.map(csvq).join(',')).join('\\n'),'text/csv')}});\nwindow.addEventListener('beforeprint',()=>document.querySelectorAll('details').forEach(d=>d.open=true));\nwindow.__doc={get state(){return S},calc};render();\n})();\n</script></body></html>\n"
    }
  ]
}