The word ultimate takes it the highest degree inadequacy.
ultimate flawed idea = very bad idea.
I don't know a specific word or phrase for a late night idea. Here's information on an idiom which relates to the subject:
Light bulb moment - Idiom Definition - UsingEnglish.com
I am not a teacher.
- For Teachers