/* afs-cmb.jsx — Asset Film Studio glue for the SHARED CMB sheet (ctm/ctm-cmb.jsx).
   No fork: this mounts window.CmbBuilder in studioApprove mode so the sheet is 1:1 with
   CTM's. Approve-per-piece + per accessory sub-part → when EVERY filled piece is approved the
   character auto-promotes (film-ready) and drops onto the production floor. "blam" = that
   one-action transition. The real cross-surface sync (CTM CMB <-> Studio CMB via the shared
   Supabase client cell) is wired by Codex outside this env; here we own the page + the honest
   local bridge (af1_cmb + af1_charlab_v2 stores, afs_cmb_approvals). */
(function(){
"use strict";
var host, root;
function esc(s){return String(s==null?"":s).replace(/[&<>"]/g,function(c){return{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"}[c];});}
function ensure(){
  if(host) return;
  host=document.createElement("div"); host.id="afs-cmb-root"; document.body.appendChild(host);
  root=ReactDOM.createRoot(host);
}
function render(){
  root.render(React.createElement(window.CmbBuilder,{ studioApprove:true, pid:"studio", mode:"studio", back:close, onPromote:onPromote }));
}
function openCmb(){
  if(!window.CmbBuilder){ if(window.AFR)window.AFR.toast('<b>CMB is still loading.</b> Give it a second and try again.'); return; }
  ensure(); host.style.display="block"; render();
}
function close(){ if(!host)return; root.render(null); host.style.display="none"; }
function onPromote(cid, sheet){
  try{ if(window.AFLIX&&window.AFLIX.reimport) window.AFLIX.reimport(); }catch(e){}
  var name=(sheet&&sheet.dna&&sheet.dna.name)||cid;
  blam(name, cid);
}
function blam(name, cid){
  var o=document.createElement("div"); o.className="afs-blam";
  o.innerHTML='<div class="afs-blam-card"><div class="afs-blam-k">CMB fully approved</div><div class="afs-blam-name">'+esc(name)+'</div><div class="afs-blam-badge">\u25c9 FILM-READY</div><div class="afs-blam-sub">'+esc(cid)+' \u00b7 dropped onto the production floor</div></div>';
  document.body.appendChild(o);
  var card=o.querySelector(".afs-blam-card");
  if(window.AFLIX&&window.AFLIX.springIn) window.AFLIX.springIn(card,26,190,17);
  if(window.AFR)window.AFR.toast('<b>'+esc(name)+' is film-ready.</b> Every CMB piece approved \u2014 cast onto any shot from the floor.');
  setTimeout(function(){ o.classList.add("out"); },1550);
  setTimeout(function(){ o.remove(); close();
    if(window.AFLIX){ window.AFLIX.db.ui.screen="cast"; window.AFLIX.db.ui.castOpen=null; window.AFLIX.save(); }
    if(window.AFAPP) window.AFAPP.render();
  },2150);
}
var css=
".afs-blam{position:fixed;inset:0;z-index:120;display:flex;align-items:center;justify-content:center;"+
"background:radial-gradient(60% 60% at 50% 45%,rgba(52,217,140,.16),transparent 70%),rgba(5,5,6,.82);"+
"backdrop-filter:blur(6px);transition:opacity .5s cubic-bezier(0.16,1,0.3,1)}"+
".afs-blam.out{opacity:0}"+
".afs-blam-card{text-align:center;padding:36px 54px;border-radius:18px;background:linear-gradient(180deg,#0e1512,#080a09);"+
"border:1px solid rgba(52,217,140,.4);box-shadow:0 30px 90px rgba(0,0,0,.6),0 0 60px rgba(52,217,140,.22)}"+
".afs-blam-k{font-family:'IBM Plex Mono',ui-monospace,monospace;font-size:11px;letter-spacing:.24em;text-transform:uppercase;color:#8FB79E}"+
".afs-blam-name{font-family:'Space Grotesk',system-ui,sans-serif;font-weight:700;font-size:46px;letter-spacing:-.01em;color:#F5F1E8;margin:8px 0 14px}"+
".afs-blam-badge{display:inline-block;font-family:'IBM Plex Mono',ui-monospace,monospace;font-size:15px;font-weight:600;letter-spacing:.12em;"+
"color:#0a0f0c;background:linear-gradient(90deg,#34D98C,#7CE8B4);border-radius:999px;padding:9px 22px;box-shadow:0 0 26px rgba(52,217,140,.45)}"+
".afs-blam-sub{font-family:'IBM Plex Mono',ui-monospace,monospace;font-size:11px;letter-spacing:.06em;color:#726E63;margin-top:16px}";
var st=document.createElement("style"); st.id="afs-blam-css"; st.textContent=css; document.head.appendChild(st);
window.AFSCMB={open:openCmb,close:close};
})();
