Getting out of my head

I had a car accident today, while I was driving on freeway I didn’t realized fast enough that the car in front of me slowed down suddenly. The moment I realized, I hit the breaks hard, but that wasn’t enough, I crashed into the car in front of me and created a big damage for both cars. Thankfully everybody was okay. Because of the accident I misaed the concert I have been waiting for months. So why did the accident happen? It happened because I was thinking about work, playing past conversations in my head and trying to find solutions. That’s why I didn’t realize what was happening faster. It was completely my fault. How do I get out of my head? I find myself constantly thinking about work even outside of the work hours and having a hard time paying attention to other things. This time I got lucky, so nobody got hurt. But what will happen next time? How should I think about this? What should I do? Thank you!