[step:Evaluate the reduced residue sum by the Ramanujan identity]
We prove the elementary identity
\begin{align*}
\sum_{\substack{r\bmod q, \gcd(r, q)=1}}e(ar/q)=\mu(q)
\end{align*}
under the hypothesis $\gcd(a,q)=1$.
[claim:Ramanujan sum at a reduced frequency]
If $q\in\mathbb N$ and $\gcd(a,q)=1$, then
\begin{align*}
\sum_{\substack{r\bmod q, \gcd(r, q)=1}}e(ar/q)=\mu(q).
\end{align*}
[/claim]
[proof]
Define the Ramanujan sum map $c_q:\mathbb Z\to\mathbb C$ by
\begin{align*}
c_q(a'):=\sum_{\substack{r\bmod q, \gcd(r, q)=1}}e(a'r/q)
\end{align*}
for each $a'\in\mathbb Z$.
Define $\delta_q:\mathbb Z/q\mathbb Z\to\{0,1\}$ by setting $\delta_q(r)=1$ when $\gcd(r,q)=1$ and $\delta_q(r)=0$ otherwise. Using the identity
\begin{align*}
\delta_q(r)=\sum_{d\mid \gcd(r,q)}\mu(d),
\end{align*}
we obtain
\begin{align*}
c_q(a)=\sum_{r\bmod q}e(ar/q)\sum_{d\mid \gcd(r,q)}\mu(d).
\end{align*}
Interchanging the finite sums gives
\begin{align*}
c_q(a)=\sum_{d\mid q}\mu(d)\sum_{\substack{r\bmod q, d\mid r}}e(ar/q).
\end{align*}
For a fixed divisor $d\mid q$, write $r=dm$ with $m\bmod q/d$. Then
\begin{align*}
\sum_{\substack{r\bmod q, d\mid r}}e(ar/q)=\sum_{m\bmod q/d}e(am/(q/d)).
\end{align*}
This finite geometric sum equals $q/d$ if $q/d\mid a$, and equals $0$ otherwise. Since $\gcd(a,q)=1$, the condition $q/d\mid a$ holds only when $d=q$. Hence
\begin{align*}
c_q(a)=\mu(q).
\end{align*}
[/proof]
Summing the reduced-class formula from the previous step over all reduced $r\bmod q$ gives
\begin{align*}
S_{\mathrm{red}}=\frac{\mu(q)}{\varphi(q)}M_\beta+\sum_{\substack{r\bmod q, \gcd(r, q)=1}}e(ar/q)R_r.
\end{align*}
Using $\varphi(q)\le q\le(\log N)^A$ and the bound for $R_r$, we obtain
\begin{align*}
\left|\sum_{\substack{r\bmod q, \gcd(r, q)=1}}e(ar/q)R_r\right|\le q C_2N\exp(-c_2\sqrt{\log N}).
\end{align*}
After reducing the exponential constant once more and increasing $N_A$, this is bounded by
\begin{align*}
C_3N\exp(-c_3\sqrt{\log N})
\end{align*}
for constants $C_3=C_3(A)>0$ and $c_3=c_3(A)>0$.
[/step]