It is going to be tight, but depending on what time you get back to Hanoi after Halong, could you go straight on to Ninh Binh? You can get a bus from Haiphong to Tam coc, but it left Haiphong about midday. You need to be in Tam coc first thing in the morning, i.e. staying there overnight, to make the most of the boat trip at 7 am. Then tour the area by bicycle, returning for the overnight bus to Phong na at about 9 pm. The long hotel in Tam coc will sort all your travel needs. Arrive in Phong na in the middle of the night, but hotels seemed aware of arrivals, and open. Do the caves, and then bus to Hue, which you could do in an afternoon, train to Danang next day to take in the Hoi van pass, and minibus transfer on to Hoi an. Yes, you can do this trip in your timescale, but really I think you need to get back from Halong to Hanoi, and get the last bus out to Ninh Binh/Tam coc, so you are there for the full day, starting early.
As for Sapa, if you have time after Hoi an, then go for it. Really, I think with your time restraints it would be better to forget Sapa, and maybe try and find a more secluded mountain getaway out of Ninh Binh or Phong na, even if just for a daytrip by private taxi. This will give you time to enjoy the rest of your trip, not be racing around like a lunatic, and won't cost you any more than another transfer thru Hanoi, and return to Sapa.. Sapa is beautiful, but hideously touristy, and I'm sure you can find somewhere else just, if not more enjoyable, by taking a 20 dollar taxi tour from Phong na, close to the Lao border, or out of Tam coc.
Just re read your post, flying out of Danang. Leave out Sapa, then you can do all the rest. Accept you can never see everything, and I think you will have seen a really good chunk of Vietnam. I was in Sapa in April, and the rice fields were disappointing. Ninh Binh and Hoi an were much greener.