The biggest cockup was not confirming a refefendum on the final outcome.
That's not due to the leave campaign, they are such cunts that the main leaders wanted a 2nd referendum, because they thought they would lose the 1st, in Farage's case, he said a 60 40 vote was needed & ironically, 52/48 would not cut it.
It's wankers like Cameron, who assumed they would win & therefore never considered the shitstorm which would be left if they didn't.
But the referendum was flawed for the reasons you state & there should be another one to determine whether the final 'deal' is perferable, to not leaving at all rather. That should always have been the case, as the original was open to interpretation to suit any agenda, & simply because Cameron didn't have the brains to think it through, doesn't make another 'undemocratic'. It's the opposite.
If the parties will state exactly where they stand, at the general election, then that would make it even more democratic.