Optical path followed by a light ray in a medium with non-uniform refractive index

I'm trying to deduce the intensity distribution resulting from the interference of reflected and transmitted light in a medium with a non-uniform refractive index, as shown in the image below. The refractive index depends on $$z$$, such that $$n(z)=n_0-cz$$, where $$n_0$$ and $$c$$ are positive constants. The medium is surrounded by air and $$n(z)>n_{air}$$ at all its points.

I know that I must calculate the optical path length of followed by the second ray inside the medium in order to get the phase difference. However, as n is not uniform, I see that the path won't be straight. How could this distance be calculated?

From Snell's Law, we know that: $$n(z)\sin\theta=\text{constant}$$ where $$C$$ is a constant. We can represent $$\sin\theta$$ as: $$1+\cot^2\theta=\csc^2\theta \implies 1+\left(\frac{dz}{dx}\right)^2=\frac{1}{\sin^2\theta}$$ Therefore, our differential equation becomes: $$\frac{dz}{dx}=\sqrt{Cn(z)^2-1}$$ where $$C$$ is a constant dependent on initial conditions. The optical path length from $$x=0$$ to $$x=a$$ would then be: $$OPL = \sqrt{C}\int_0^a n(z)^2dx$$