Stressful thoughts and tasks can keep the brain awake, disrupting sleep patterns and causing insomnia.