(function(){
var T=8,R=9,s=0,a={};
function init(){
document.querySelectorAll('#cap-quiz-wrap [data-captype="radio"]').forEach(function(g){g.querySelectorAll('.option-card').forEach(function(c){c.addEventListener('click',function(e){e.preventDefault();g.querySelectorAll('.option-card').forEach(function(x){x.classList.remove('selected');});this.classList.add('selected');var i=this.querySelector('input');if(i)i.checked=true;capVal();});});});
document.querySelectorAll('#cap-quiz-wrap [data-captype="checkbox"]').forEach(function(g){g.querySelectorAll('.option-card').forEach(function(c){c.addEventListener('click',function(e){e.preventDefault();this.classList.toggle('selected');var i=this.querySelector('input');if(i)i.checked=this.classList.contains('selected');capVal();});});});
}
window.capStart=function(){go(1);};
window.capNext=function(){save();if(s0)go(s===R?T:s-1);};
window.capVal=function(){
switch(s){
case 1:tb('cB1',document.getElementById('cap_addr').value.trim().length>=5);break;
case 2:tb('cB2',!!document.querySelector('#cOT .selected'));break;
case 3:tb('cB3',!!document.querySelector('#cOP .selected'));break;
case 4:tb('cB4',!!document.querySelector('#cOH .selected'));break;
case 5:tb('cB5',!!document.querySelector('#cOTL .selected')&&!!document.querySelector('#cOB .selected'));break;
case 6:tb('cB6',document.getElementById('cap_fn').value.trim().length>0&&document.getElementById('cap_ln').value.trim().length>0);break;
case 7:var e=document.getElementById('cap_em').value.trim();tb('cB7',e.includes('@')&&e.includes('.'));break;
}
};
function tb(id,on){var b=document.getElementById(id);if(b)b.disabled=!on;}
function sel(id){var e=document.querySelector('#'+id+' .selected');return e?e.dataset.value:'';}
function selAll(id){return Array.from(document.querySelectorAll('#'+id+' .selected')).map(function(e){return e.dataset.value;});}
function save(){
switch(s){
case 1:a.addr=document.getElementById('cap_addr').value.trim();break;
case 2:a.type=sel('cOT');break;
case 3:a.purp=sel('cOP');break;
case 4:a.hoa=sel('cOH');a.feat=selAll('cOF');break;
case 5:a.tl=sel('cOTL');a.bud=sel('cOB');break;
case 6:a.fn=document.getElementById('cap_fn').value.trim();a.ln=document.getElementById('cap_ln').value.trim();break;
case 7:a.em=document.getElementById('cap_em').value.trim();break;
case 8:a.nt=document.getElementById('cap_nt').value.trim();break;
}
}
function go(n){
document.querySelectorAll('#cap-quiz-wrap .cap-step').forEach(function(el){el.classList.remove('active');});
s=n;
var t=document.querySelector('#cap-quiz-wrap [data-step="'+n+'"]');
if(t){t.classList.add('active');}
var pb=document.getElementById('capPB');
if(n===0||n===R){pb.style.display='none';}
else{pb.style.display='block';document.getElementById('capPBFill').style.width=((n/T)*100)+'%';document.getElementById('capPBLabel').textContent='Step '+n+' of '+T;}
window.scrollTo({top:0,behavior:'smooth'});
capVal();
}
window.capSubmit=function(){save();showR();};
function showR(){
document.getElementById('r_addr').textContent=a.addr||'-';
document.getElementById('r_purp').textContent=a.purp||'-';
document.getElementById('r_hoa').textContent=a.hoa==='Yes HOA'?'HOA present - eligible under HB 24-1152':'No HOA - fewer restrictions';
var rt=a.type;
if(rt==='Not Sure'){if(a.feat&&a.feat.indexOf('Walk-out Basement')>-1)rt='Basement Conversion';else if(a.feat&&a.feat.indexOf('Detached Garage')>-1)rt='Garage Conversion';else rt='Detached Backyard Cottage';}
var cost,time,rent;
if(rt.indexOf('Basement')>-1){cost='$40,000 to $120,000';time='2 to 5 months';rent='$1,200 to $1,800/mo';}
else if(rt.indexOf('Garage')>-1){cost='$50,000 to $150,000';time='3 to 6 months';rent='$1,400 to $1,800/mo';}
else{cost='$200,000 to $400,000';time='6 to 10 months';rent='$1,600 to $2,500/mo';}
document.getElementById('r_type').textContent=rt;
document.getElementById('r_cost').textContent=cost;
document.getElementById('r_time').textContent=time;
document.getElementById('r_rent').textContent=rent;
document.getElementById('cRT').textContent=(a.fn?a.fn+', ':'')+'Your Property May Be a Good ADU Candidate';
document.getElementById('cRS').textContent='Based on your answers, a '+rt.toLowerCase()+' may be a good fit. Final feasibility depends on zoning, lot conditions, utilities, budget, HOA rules, and professional review.';
var sum=buildSum();
document.getElementById('cEL').href='mailto:website@coloradoadupro.com?subject='+encodeURIComponent('ADU quiz summary')+'&body='+encodeURIComponent(sum);
go(R);
}
function buildSum(){return['Colorado ADU Pro quiz summary','','Name: '+(a.fn||'')+' '+(a.ln||''),'Email: '+(a.em||''),'Property: '+(a.addr||''),'ADU type: '+(document.getElementById('r_type').textContent||''),'Primary use: '+(a.purp||''),'HOA: '+(a.hoa||''),'Features: '+((a.feat||[]).join(', ')||'None'),'Timeline: '+(a.tl||''),'Budget: '+(a.bud||''),'Estimate: '+(document.getElementById('r_cost').textContent||''),'Notes: '+(a.nt||''),'','I would like Colorado ADU Pro to follow up about ADU guidance and referrals.'].join('\n');}
window.capCopy=function(){if(navigator.clipboard)navigator.clipboard.writeText(buildSum()).then(function(){var b=document.getElementById('cCB');if(b){b.textContent='Copied!';setTimeout(function(){b.textContent='Copy Summary';},1200);}});};
init();
})();