Step 1: Rewrite the trig part.
The term $\frac{1}{\cos^2 x}$ is the same as $\sec^2 x$. So the integral becomes $\int \frac{\sec^2 x}{(1-\tan x)^2}\,dx$. This form hints at a substitution.
Step 2: Choose a substitution.
Notice that $\sec^2 x$ is exactly the derivative of $\tan x$. So let $u = 1 - \tan x$. This makes the bottom simply $u^2$.
Step 3: Find $du$.
Differentiate $u = 1 - \tan x$. The derivative of $1$ is zero and of $\tan x$ is $\sec^2 x$.
\[ du = -\sec^2 x\,dx \implies \sec^2 x\,dx = -du \]
Step 4: Replace everything.
Swap the pieces into the integral. The top $\sec^2 x\,dx$ becomes $-du$, and the bottom becomes $u^2$.
\[ \int \frac{-du}{u^2} = -\int u^{-2}\,du \]
Step 5: Integrate the power.
The integral of $u^{-2}$ is $\frac{u^{-1}}{-1} = -\frac{1}{u}$. The minus signs make it positive.
\[ -\left(-\frac{1}{u}\right) + C = \frac{1}{u} + C \]
Step 6: Put back the original variable.
Replace $u$ with $1 - \tan x$.
\[ \frac{1}{1 - \tan x} + C \]
\[ \boxed{\dfrac{1}{1 - \tan x} + C} \]