/* Sidebar advertisement (sponsors app).

   Wide screens (1400px and up): the ad sits in the decorated space right of the
   content column. A "rail" runs down that space (it is placed inside .content,
   so it starts below the menu and ends above the footer on every page) and the
   ad card sticks to the top of the screen while scrolling.

   Narrower screens (laptops below 1400px, tablets, phones): the same card is
   shown centred at the bottom of the page content, just above the footer.

   Swedish law (marknadsföringslagen 9 §) requires that it is clear (1) that this
   is advertising – the "Annons" label – and (2) who is behind it – the
   advertiser's name/logo under the banner. Both are always visible. */

/* ---------- The ad card (all screen sizes) ---------- */
.sidebar-ad-link {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 6px 6px 8px;
    border-radius: 10px;
    background: rgba(255, 252, 247, 0.96);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
    color: #4a3a32;
    text-decoration: none;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.sidebar-ad-label {
    align-self: center;
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #8a7364;
    line-height: 1;
    padding-top: 2px;
}

.sidebar-ad-banner {
    display: block;
    line-height: 0;
    border-radius: 6px;
    overflow: hidden;
    background: #fff;
}

.sidebar-ad-banner img {
    display: block;
    width: 100%;
    height: auto;
    object-fit: contain;
    transition: transform 0.4s ease;
}

.sidebar-ad-sender {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;             /* a long name goes below the logo instead of being split */
    gap: 3px 6px;
    padding: 2px 4px 0;
    font-size: 0.78rem;
    line-height: 1.2;
}

.sidebar-ad-logo {
    flex: none;
    height: 18px;
    width: auto;
    max-width: 54px;
    object-fit: contain;
}

.sidebar-ad-sender-name {
    font-weight: 600;
    text-align: center;
    overflow-wrap: break-word;   /* only very long names wrap, at spaces where possible */
    text-decoration: underline;
    text-decoration-color: transparent;
    text-decoration-thickness: 1.5px;
    text-underline-offset: 3px;
    transition: text-decoration-color 0.25s ease, color 0.25s ease;
}

/* Hover (mouse) / keyboard focus: the card lifts a little, the banner zooms very
   slightly and the advertiser's name gets a soft gold underline. */
@media (hover: hover) {
    .sidebar-ad-link:hover {
        transform: translateY(-3px);
        box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3);
    }

    .sidebar-ad-link:hover .sidebar-ad-banner img {
        transform: scale(1.03);
    }

    .sidebar-ad-link:hover .sidebar-ad-sender-name {
        color: #2d211c;
        text-decoration-color: var(--accent-gold, #c9954e);
    }
}

.sidebar-ad-link:focus-visible {
    transform: translateY(-3px);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3);
    outline: 3px solid var(--accent-gold, #c9954e);
    outline-offset: 3px;
}

.sidebar-ad-link:focus-visible .sidebar-ad-sender-name {
    color: #2d211c;
    text-decoration-color: var(--accent-gold, #c9954e);
}

/* ---------- Narrower screens: centred at the bottom of the page ---------- */
@media screen and (max-width: 1399.98px) {
    .sidebar-ad-rail {
        display: block;
        clear: both;
        padding: 2rem 1rem 2.5rem;
    }

    .sidebar-ad {
        width: min(300px, 100%);
        margin: 0 auto;
    }

    .sidebar-ad-banner img {
        max-height: 70vh;
    }
}

/* ---------- Wide screens: in the decorated side space ---------- */
@media screen and (min-width: 1400px) {
    /* Make the content column a little narrower (only on pages with an ad) so the
       side space has room for the card. --content-max-width also sizes the
       decorated side images (css/responsive.css), so they shrink to match and no
       plain background shows between them and the content. From about 1575px
       the column is back at its full 1200px. */
    :root:has(.sidebar-ad-rail) {
        --content-max-width: min(1200px, calc(100% - 360px));
    }

    .content:has(> .sidebar-ad-rail) {
        max-width: var(--content-max-width);
    }

    .sidebar-ad-rail {
        display: block;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 100%;                          /* right edge of the content column */
        width: calc((100vw - 100%) / 2);     /* the free space up to the screen edge */
        padding-top: 24px;
        box-sizing: border-box;
        z-index: 1;
        pointer-events: none;
    }

    .sidebar-ad {
        position: sticky;
        top: 84px;   /* just below the menu bar that stays at the top of the screen (65px) */
        width: clamp(140px, calc(100% - 36px), 260px);
        margin: 0 auto;
        pointer-events: auto;
    }

    .sidebar-ad-banner img {
        max-height: calc(100vh - 190px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar-ad-link,
    .sidebar-ad-banner img,
    .sidebar-ad-sender-name {
        transition: none;
    }

    .sidebar-ad-link:hover,
    .sidebar-ad-link:focus-visible,
    .sidebar-ad-link:hover .sidebar-ad-banner img {
        transform: none;
    }
}
