Integrating Markov processes with structural causal modeling enables counterfactual inference in complex systems