This is what happens to your brain after a bad night’s sleep – and how to deal with it