/* =============================================================================
 * page-rail.css — reusable "content + sticky right rail" layout primitive.
 *
 * Gives wide viewports a *purpose* instead of dead gutters: a flexible main
 * column beside a 320px rail that holds a contextual CTA card and our own
 * placed, labeled ad units (via {% ad_slot %}). This replaces AdSense Auto
 * Ads' low-quality gutter/anchor units with intentional inventory.
 *
 * Usage (template):
 *   <div class="page-shell">
 *     <div class="page-shell__main"> ...page content... </div>
 *     {% include "partials/page_rail.html" %}
 *   </div>
 *
 * The rail collapses below the content under 1024px. All values use design
 * tokens from main.css. Two design languages (editorial + dashboard) both
 * read fine because the cards are neutral white surfaces.
 * ========================================================================== */

.page-shell {
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 var(--space-6);
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: var(--space-10);
    align-items: start;
}

/* min-width:0 lets the main column shrink instead of forcing horizontal
 * overflow when it contains wide children (tables, code, ad units). */
.page-shell__main {
    min-width: 0;
}

/* The rail is the sticky grid item. align-items:start on the grid keeps it
 * pinned while the longer main column scrolls past. top clears the 72px
 * sticky nav plus a little breathing room. */
.page-shell__rail {
    position: sticky;
    top: 88px;
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

/* ---- Contextual CTA card (the rail's UX value, not just ads) ---- */
.rail-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.rail-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* A slim gold rule at the top ties the card to the editorial palette. */
.rail-card--accent {
    border-top: 3px solid var(--color-accent);
}

.rail-card__eyebrow {
    font-size: 0.7rem;
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-secondary);
    margin: 0 0 var(--space-2, 0.5rem);
}

.rail-card__title {
    font-family: var(--font-serif, Georgia, serif);
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
    line-height: 1.25;
    color: var(--color-text);
    margin: 0 0 var(--space-3, 0.75rem);
}

.rail-card__text {
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
    color: var(--color-text-muted);
    margin: 0 0 var(--space-5, 1.25rem);
}

.rail-card__cta {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    justify-content: center;
    padding: 0.7rem var(--space-4);
    background: var(--color-primary);
    color: #fff;
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    border-radius: var(--radius-md, 0.5rem);
    text-decoration: none;
    transition: background var(--transition-base), transform var(--transition-base);
}

.rail-card__cta:hover {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
}

.rail-card__cta--ghost {
    background: transparent;
    color: var(--color-primary);
    border: 1px solid var(--color-border);
}

.rail-card__cta--ghost:hover {
    background: var(--color-primary-50);
    border-color: var(--color-primary-200);
}

/* ---- Ad unit framing (label + container) ---- */
.ad-rail {
    /* Center the 300px-class responsive unit inside the 320px track. */
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* "Advertisement" eyebrow: AdSense policy compliance + reader trust.
 * Hidden automatically when the slot renders nothing (see :has below). */
.ad-rail__label {
    font-size: 0.625rem;
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--color-text-light);
    margin: 0 0 0.4rem;
    align-self: stretch;
    text-align: left;
}

.ad-rail .adsbygoogle {
    width: 300px;
    max-width: 100%;
}

/* When the {% ad_slot %} tag renders nothing (no fill / blocked path), the
 * wrapper is empty — collapse it so we never ship an orphan "Advertisement"
 * label or empty gap. The second rule also collapses the block when AdSense
 * loaded the unit but returned NO ad (it stamps data-ad-status="unfilled"),
 * so we never show an "Advertisement" label hovering over blank space. */
.ad-rail:not(:has(.adsbygoogle)),
.ad-rail:has(ins.adsbygoogle[data-ad-status="unfilled"]) {
    display: none;
}

/* In-content ad (between article sections). Same label treatment, full
 * width of the reading column, generous vertical rhythm. */
.ad-incontent {
    margin: var(--space-10) 0;
    text-align: center;
}

.ad-incontent__label {
    font-size: 0.625rem;
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--color-text-light);
    margin: 0 0 0.4rem;
}

.ad-incontent:not(:has(.adsbygoogle)),
.ad-incontent:has(ins.adsbygoogle[data-ad-status="unfilled"]) {
    display: none;
}

/* ---- Responsive: collapse the rail below the content ---- */
@media (max-width: 1024px) {
    .page-shell {
        grid-template-columns: 1fr;
        gap: var(--space-8);
    }

    .page-shell__rail {
        position: static;
        /* Lay the rail cards out in a row on tablet so they don't form a
         * long lonely column; wraps to stack on phones. */
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .page-shell__rail > * {
        flex: 1 1 300px;
        max-width: 360px;
    }
}

@media (max-width: 640px) {
    .page-shell {
        padding: 0 var(--space-4);
    }

    .page-shell__rail {
        flex-direction: column;
    }
}
