/* === Fit map to current roofs (esp. mobile) === */
function fitMapToCurrentRoofs(paddingPx){
try{
const rr = (window.roofs||[]).filter(r=>r.included && r.closed && r.pts && r.pts.length>=3);
if(!rr.length) return;
let all = [];
rr.forEach(r=> r.pts.forEach(p=> all.push([p.lng,p.lat])));
const bb = turf.bbox({ type:'FeatureCollection', features: rr.map(r=>({type:'Feature',geometry:{type:'Polygon',coordinates:[r.pts.map(pt=>[pt.lng,pt.lat]).concat([[r.pts[0].lng,r.pts[0].lat]])]}})) });
const pad = paddingPx || (window.matchMedia('(max-width: 768px)').matches ? {top:12, right:12, left:12, bottom:220} : 40);
map.fitBounds([[bb[0],bb[1]],[bb[2],bb[3]]], { padding: pad, maxZoom: 19, duration: 500 });
}catch(e){}
}