The following is an approach inspired by Selberg's treatment of the large sieve, and more directly by a sketch in Granville-Harper-Soundararajan (on the case of prime support). There remains an optimization problem to be solved at the end.
Let $\Phi:\mathbb{R}\to \mathbb{R}$ be a real-valued, symmetric, non-negative function such that $\Phi(t)\geq 1$ for $|t|\leq 1/2$, $\widehat{\Phi}(t)$ is non-increasing for $t\geq 0$, and the support of $\widehat{\Phi}(t)$ is contained in a compact interval $[-\ell,\ell]$.
Let $\varphi(x) = \Phi(x/T)$; then $\widehat{\varphi}(t) = T \widehat{\Phi}(T t)$. Clearly
$$\int_{-T/2}^{T/2} \left|\sum_{n=1}^\infty a_n n^{-i t}\right|^2 dt \leq
\int_{-\infty}^\infty \varphi(t) \left|\sum_{n=1}^\infty a_n n^{-i t}\right|^2 dt.$$
Now we proceed in the usual way (as in, say, Iwaniec-Kowalski, proof of Thm. 9.1): expanding the square and inverting the order of summation and integration, and writing $e(t)=e^{2\pi i t}$, we see that
$$\begin{aligned}\int_{-\infty}^\infty \varphi(t) \left|\sum_{n=1}^\infty a_n n^{-i t}\right|^2 dt &=
\sum_{n_1=1}^\infty \sum_{n_2=1}^\infty a_{n_1} \overline{a}_{n_2}
\int_{-\infty}^\infty \varphi(t) e\left(-\frac{\log(n_1/n_2)}{2\pi} t\right) dt\\
&= \sum_{n_1=1}^\infty \sum_{n_2=1}^\infty a_{n_1} \overline{a}_{n_2} \widehat{\varphi}\left(\frac{\log (n_1/n_2)}{2\pi}\right)
\end{aligned}$$
Of course, $|a_{n_1} \overline{a}_{n_2}|\leq \frac{|a_{n_1}|^2 + |a_{n_2}|^2}{2}$, and $\varphi$ is real-valued and symmetric, as $\Phi$ is, as well as being non-negative. Hence
$$\left|\sum_{n_1=1}^\infty \sum_{n_2=1}^\infty a_{n_1} \overline{a}_{n_2} \widehat{\varphi}\left(\frac{\log (n_1/n_2)}{2\pi}\right)
\right|\leq \sum_{n_1=1}^\infty |a_{n_1}|^2 \sum_{n_2=1}^\infty \widehat{\varphi}\left(\frac{\log (n_1/n_2)}{2\pi}\right).$$
It is easy to see that the sum over the integers of a function $F$ of compact support with its only maximum at some $t=t_1$ such that $F(t)$ non-increasing for $t\geq t_1$ and non-decreasing for $t\leq t_1$ is at most
$$F(0) + \int_0^\infty F(x) dx + \int_{-\infty}^0 F(x) dx =F(0) + \int_{-\infty}^\infty F(x) dx.$$
We apply this simple statement to the function $f(t) = \widehat{\varphi}\left(\frac{\log(n_1/t)}{n_2}\right)$.
We obtain
$$\sum_{n_2=1}^\infty \widehat{\varphi}\left(\frac{\log (n_1/n_2)}{2\pi}\right) = \widehat{\varphi}(0) + \int_{-\infty}^\infty
\widehat{\varphi}\left(\frac{\log(n_1/t)}{2\pi}\right) dt.$$
It is clear that $\widehat{\varphi}(0) = T \widehat{\Phi}(0)$.
Now, in general, for $f:\mathbb{R}\to [0,\infty)$ of compact support and $g:\mathbb{R}\to \mathbb{R}$ differentiable and monotonic,
$$|f\circ g|_1 \leq \frac{|f|_1}{\inf_{t: f(g(t))\ne 0} |g'(t)|}.$$
Let $f = \widehat{\varphi}$ and $g(t) = \log(n_1/t)/2\pi$. Then $f(g(t))\ne 0$ implies $|g(t)|\leq \ell/T$, and hence
$$ e^{-\frac{2\pi \ell}{T}} n_1 \leq t\leq e^{\frac{2\pi \ell}{T}} n_1,$$
and so
$$|g'(t)| = \frac{1}{2\pi |t|} \geq \frac{e^{-\frac{2\pi \ell}{T}}}{2\pi n_1}.$$
Hence, $|f\circ g|_1 \leq e^{\frac{2\pi \ell}{T}} 2\pi n_1 |f|_1$, i.e.,
$$\int_{-\infty}^\infty
\widehat{\varphi}\left(\frac{\log(n_1/t)}{2\pi}\right) dt
\leq e^{\frac{2\pi \ell}{T}} 2\pi n_1 \int_{-\infty}^\infty
\widehat{\varphi}(t) dt.$$
Finally,
$$\int_{-\infty}^\infty
\widehat{\varphi}(t) dt = \varphi(0) = \Phi(0).$$
We conclude that
$$\int_{-T/2}^{T/2} \left|\sum_{n=1}^\infty a_n n^{-i t}\right|^2 dt \leq \widehat{\Phi}(0) T \sum_n \left|a_n\right|^2 + e^{\frac{2\pi \ell}{T}} 2\pi \Phi(0) \sum_n \left|a_n\right|^2 n.$$
(We can replace the integral from $-T/2$ to $T/2$ by an integral from $0$ to $T$ if we prefer, simply by applying the above with $a_n n^{-i T/2}$ instead of $a_n$.)
It is clear, given our assumptions, that $\Phi(0)\geq 1$ and $\widehat{\Phi}(0) = |\Phi|_1 \geq 1$.
It remains to choose $\Phi$. One option is to let $\Phi = \widehat{F\ast F}$, where $F$ is a non-negative symmetric function of compact support with $F(x)$ non-increasing for $x\geq 0$. Then $\Phi$ equals $\widehat{F}^2 = |\widehat{F}|^2$, and so is non-negative and real-valued, besides being symmetric; since $\widehat{\Phi} = F\ast F$, we see easily that $\widehat{\Phi}$ is of compact support and $\widehat{\Phi}(t)$ is non-increasing for $t\geq 0$. Clearly $\Phi(0) = |F|_1^2$ and $\widehat{\Phi}(0) = |F|_2^2$. It would remain to verify the condition $\Phi(t) \geq 1$ for $|t|\leq 1/2$, i.e., $|\widehat{F}(t)|\geq 1$ for $|t|\leq 1/2$.