/*
 * Sponsored ads: side rails on wide screens, one inline slot in the events grid otherwise.
 * Markup: Views/Shared/_AdRail.cshtml, _AdInline.cshtml, _AdCard.cshtml. Close: wwwroot/js/ad-cards.js.
 */
:root {
    --ad-content-w: 1140px;  /* Bootstrap 4.6 .container max-width at >=1200px (1110px content + 2 x 15px padding) */
    --ad-gap: 16px;
    --ad-header-h: 60px;     /* fixed-top navbar; same offset as .splash { margin-top: 60px } in _Layout */
    --sp-card-max: 220px;
    --sp-card-min: 140px;
    --ad-chat-clearance: 140px; /* #chatCustomLabel: bottom 74px + 42px tall, plus margin */
}

/* ---------------------------------------------------------------- layout */

.sp-rail {
    display: none;
}

/*
 * Switch point: rails need >= 140px each.
 *   1140 (content) + 2 x 16 (gaps) + 2 x 140 (rails) = 1452px of layout width.
 * Media queries measure the viewport including a classic scrollbar (~17px on Windows) while the grid
 * only gets the width without it, so the query uses 1452 + 17 ≈ 1470px.
 * Below it: plain block layout exactly as before (no reserved columns), inline slot visible.
 */
@media (min-width: 1470px) {
    .page-layout {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, var(--ad-content-w)) minmax(0, 1fr);
        column-gap: var(--ad-gap);
    }

    .page-layout > .page-content {
        grid-column: 2;
        grid-row: 1;
        width: 100%;
        max-width: var(--ad-content-w);
        min-width: 0;
    }

    .sp-rail {
        display: block;
        grid-row: 1;
        min-width: 0;
        container-type: inline-size;
    }

    .sp-rail--left {
        grid-column: 1;
    }

    .sp-rail--right {
        grid-column: 3;
    }

    .ad-slot-inline {
        display: none !important;
    }
}

.sp-rail__stack {
    position: sticky;
    top: calc(var(--ad-header-h) + 16px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    /* Never run under the fixed "Chat with" label / chat bubble at the bottom of the viewport. */
    max-height: calc(100vh - var(--ad-header-h) - 16px - var(--ad-chat-clearance));
    overflow-y: auto;
    scrollbar-width: thin;
    padding: 2px 0; /* keep focus rings / borders inside the scroll box */
}

/* Below 140px the card would be unreadable: hide it (container = the rail column). */
@container (max-width: 139.98px) {
    .sp-rail .sp-card {
        display: none;
    }
}

/* ---------------------------------------------------------------- card */

.sp-card {
    position: relative;
    box-sizing: border-box;
    width: min(100%, var(--sp-card-max));
    margin-inline: auto;
    padding: clamp(8px, 5cqi, 12px);
    display: flex;
    flex-direction: column;
    gap: clamp(4px, 3cqi, 8px);
    background: #fff;
    border: 1px solid rgb(200, 200, 200);
    border-radius: 1.5rem;
}

.sp-card__close {
    position: absolute;
    top: 6px;
    right: 8px;
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #555;
    cursor: pointer;
}

.sp-card__close span {
    font-size: 22px; /* _Layout caps every element at 12px via `* { font-size: min(1em, 12px) }` */
    line-height: 1;
}

.sp-card__close:hover {
    background: #f1f1f1;
}

.sp-card__close:focus-visible {
    outline: 2px solid rgb(33, 105, 235);
    outline-offset: 2px;
}

.sp-card__title {
    margin: 0;
    padding-right: 30px; /* room for the close button */
    font-size: clamp(11px, 6.5cqi, 14px);
    font-weight: 700;
    line-height: 1.3;
    min-height: 2.6em;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
}

.sp-card__label {
    margin: 0;
    color: #757575;
    font-size: clamp(10px, 5cqi, 12px);
    font-weight: 500;
}

.sp-card__media {
    display: block;
    border-radius: 1rem;
    overflow: hidden;
}

.sp-card__img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 5 / 6;
    object-fit: cover;
    border-radius: 1rem;
    background: #f1f1f1; /* placeholder while the lazy image loads */
}

.sp-card__cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: clamp(6px, 4cqi, 9px) clamp(10px, 7cqi, 16px);
    border-radius: 100px;
    background: rgb(33, 105, 235);
    color: #fff;
    font-size: clamp(11px, 6cqi, 13px);
    font-weight: 500;
    letter-spacing: 0.02em;
    text-decoration: none;
}

.sp-card__cta i {
    font-size: 0.85em;
}

.sp-card__cta:hover,
.sp-card__cta:focus {
    color: #fff;
    text-decoration: none;
    opacity: 0.85;
}

.sp-card__cta:focus-visible,
.sp-card__media:focus-visible {
    outline: 2px solid rgb(33, 105, 235);
    outline-offset: 2px;
}

/* ---------------------------------------------------------------- inline slot (events grid) */

/* Grid item like .event-card-column; the card takes the whole cell and matches .event-card. */
.ad-slot-inline {
    container-type: inline-size;
}

.ad-slot-inline .sp-card {
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* Same photo height as #all-events-cards-row .event-card .photo (220px). */
.ad-slot-inline .sp-card__img {
    aspect-ratio: auto;
    height: 220px;
}

.ad-slot-inline .sp-card__cta {
    margin-top: auto;
}
