/* RacesCanada - Side-rail ad units v1
   Shared geometry for the gutter ad rails. Pair with /side-rails.js, which
   injects the actual units — this file only positions the empty columns.

   Previously this lived in four near-identical copies (guide.css,
   athlete.css, my-calendar.css, results.css) that had drifted apart on
   offsets and breakpoints. Pages adopt this file one at a time; the old
   copies stay put until their page is migrated.
   ============================================================ */

/* The host container must be a containing block, and must declare its own
   max-width so the offset maths below knows how wide the gutter is.
   Default assumes an 800px content column (.guide-container et al);
   wider containers set --rail-container-w themselves. */
.ad-side-rail-wrap {
    --rail-container-w: 800px;

    position: absolute;
    top: 0;
    bottom: 0;
    width: 160px;
    display: none;
}

/* Float the rail in the *middle* of its gutter rather than hugging the prose.
   gutter = (100vw - container)/2, so centring a 160px rail in it puts the
   rail's outer edge at 80px + (100vw - container)/4 beyond the container.
   At the show-breakpoint that resolves to roughly "flush with a small gap"
   (all the room there is); on a wide desktop it pulls the ads well clear of
   the text. Capped at 320px so they don't drift to the screen edges on
   ultrawides. */
.ad-side-rail-wrap-left {
    left: max(-320px, calc(-80px - (100vw - var(--rail-container-w)) / 4));
}

.ad-side-rail-wrap-right {
    right: max(-320px, calc(-80px - (100vw - var(--rail-container-w)) / 4));
}

/* Each injected unit. Absolutely placed down the column by side-rails.js,
   which sets `top` per unit.

   No `position: sticky`: the ad scrolls away with the page like any other
   content. Sticky isn't needed for the impression — AdSense counts one when
   the unit renders — it only buys extra viewable seconds, and the constant
   motion beside the prose read as distracting. Coverage on long pages comes
   from injecting *more* units instead, which is the whole point of the JS. */
.ad-side-rail {
    position: absolute;
    left: 0;
    width: 160px;
}

/* Shown only where the gutter can hold a 160px rail with >=16px of margin,
   i.e. viewport >= container + 352px. Media queries can't read custom
   properties, so there are three fixed tiers and a page picks the one its
   column width needs. Set --rail-container-w to the real width on top (see
   club.css et al) or the offset maths misjudges the gutter.

     (default)  up to  840px column — /guides landing tail unit  (800px)
     -wide      up to 1040px column — /club/:slug, /athlete, /results (1000-1040px)
     -xwide     up to 1140px column — /clubs, /my-calendar     (1100px)

   The 1400px tier matters: it's where a 1440px laptop sits, so pushing the
   1000px-column pages up to 1500 would cost them their rails on the most
   common desktop size we see.

   /race/:id and /guides/:slug used to carry gutter rails too; both were
   removed 2026-09 (near-zero revenue, they were the "wall of ads" the pages
   were being criticised for). Those pages keep only their in-content units. */
@media (min-width: 1200px) {
    .ad-side-rail-wrap {
        display: block;
    }
}

.ad-side-rail-wrap-wide,
.ad-side-rail-wrap-xwide {
    display: none;
}

@media (min-width: 1400px) {
    .ad-side-rail-wrap-wide {
        display: block;
    }
}

@media (min-width: 1500px) {
    .ad-side-rail-wrap-xwide {
        display: block;
    }
}

/* ============================================================
   TAIL UNIT — the single in-content ad, at the foot of the page
   ============================================================ */

/* Stays empty — and takes no space — until side-rails.js decides the page
   is tall enough to carry a unit.

   Note this hides via :empty rather than the `height: 0; overflow: hidden`
   collapse the older units use. That pattern does not work here: AdSense
   sizes an ad from its container, and a zero-height clipped box gets no fill
   at all (verified in production — the <ins> came back
   data-adsbygoogle-status="done" with no data-ad-status and zero height).
   The older units get away with it because they're in the markup and pushed
   at parse time; this one is injected, so the box has to be real by the time
   the push lands. */
.ad-tail:empty {
    display: none;
}

.ad-tail {
    margin: 56px 0 0;
}

/* The divider and its gap appear only once there's a real ad behind them,
   so a slot that comes back empty never leaves a rule with nothing under
   it. The space itself is what makes the ad read as something below the
   content rather than the last row of it — the failure mode when it sat
   flush against the bottom of a results table.

   An <ins> that doesn't fill still reserves its own height, and this can't
   claw that back (collapsing the box pre-fill is what stopped AdSense
   serving into it in the first place). side-rails.js removes the whole
   element instead if no fill is reported. */
.ad-tail:has(ins[data-ad-status="filled"]) {
    padding: 40px 0 0;
    border-top: 1px solid var(--rs-border, #e1e7ec);
}
