  In the O(n) loop model on random planar maps, we study the depth - in terms
of the number of levels of nesting - of the loop configuration, by means of
analytic combinatorics. We focus on the 'refined' generating series of pointed
disks or cylinders, which keep track of the number of loops separating the
marked point from the boundary (for disks), or the two boundaries (for
cylinders). For the general O(n) loop model, we show that these generating
series satisfy functional relations obtained by a modification of those
satisfied by the unrefined generating series. In a more specific O(n) model
where loops cross only triangles and have a bending energy, we explicitly
compute the refined generating series. We analyse their non generic critical
behavior in the dense and dilute phases, and obtain the large deviations
function of the nesting distribution, which is expected to be universal. Using
the framework of Liouville quantum gravity (LQG), we show that a rigorous
functional KPZ relation can be applied to the multifractal spectrum of extreme
nesting in the conformal loop ensemble (CLE) in the Euclidean unit disk, as
obtained by Miller, Watson and Wilson, or to its natural generalisation to the
Riemann sphere. It allows us to recover the large deviations results obtained
for the critical O(n) random planar map models. This offers, at the refined
level of large deviations theory, a rigorous check of the fundamental fact that
the universal scaling limits of random planar map models as weighted by
partition functions of critical statistical models are given by LQG random
surfaces decorated by independent CLEs.
