I have phases where I get ideas when I am trying to get to sleep. I call them “creative surges”. I try not to moan about them as I’m sure it would be much more distressing if I didn’t get any ideas.
When they happen I get out of bed, find a pen and paper and scribble them down. Sometimes I end up getting up several times. I then either put the ideas on my topic spreadsheet or I write them up over the next few days in my morning writing sessions.