On the production side, the rise of US shale caused low prices and therefore low investment in oil and gas production worldwide since 2015. Companies needed to pull back to get out of debt and return money to investors. Then COVID collapsed demand and shut down exploration world wide. Supply chain problems are messing things up some more. Then Russia invaded Ukraine and send Europe scrambling for supply alternatives.
In refining, US refineries have been a bad investment for a long time. Many refineries have shut down as environmental and safety regulations tightened. Due to the poor financial environment, refiners have been disinvesting, pushing a bit more capacity here, stretching old equipment to run just a little longer there. Eventually many sold or shut down. A new refinery takes tens of billions of $ and five or more years to build and since fuels demand is declining in the US, it wouldn't be built here.
Think you are going to restart an idle refinery? Nah, these things don't shut down until they are worn out. It can take more to fix one up than to start over somewhere else.
Fundamentally, the low elasticity of demand and long project cycles mean we always have either too much supply to make industry happy or too little to make customers happy. Fortunately, we can go 15 years or longer between times when we have too little. Unfortunately, when we hit one of those supply crunches, it is painful since energy is in everything.