/* ========================================
   SITE POPUP
   Frequency-capped promotional dialog. Rendered by SitePopup.razor, driven by js/site-popup.js.

   Every colour is a custom property with a fallback, so a host restyles the popup by setting the
   --site-popup-* variables somewhere above it rather than overriding these rules. The defaults are
   deliberately brand-neutral: this library ships in more than one project.

   Class names are part of the contract with site-popup.js — .is-open and .site-popup--sheet are
   applied by the script. Do not rename them here.
   ======================================== */

.site-popup {
    --site-popup-surface: #ffffff;
    --site-popup-surface-2: #f7f7fb;
    --site-popup-text: #14162e;
    --site-popup-muted: #5a5f80;
    --site-popup-accent: #6366f1;
    --site-popup-accent-2: #8b5cf6;
    --site-popup-accent-text: #ffffff;
    --site-popup-border: rgba(20, 22, 46, 0.10);
    --site-popup-backdrop: rgba(10, 12, 30, 0.58);
    --site-popup-radius: 24px;
    --site-popup-width: 470px;

    position: fixed;
    inset: 0;
    z-index: 2147483000; /* Above the host's own chrome, below nothing that matters. */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.site-popup[hidden] {
    display: none;
}

.site-popup-backdrop {
    position: absolute;
    inset: 0;
    background: var(--site-popup-backdrop);
    /* Blur costs a compositor layer, so it is applied only while open — a hidden popup should not
       leave the browser holding a full-viewport backdrop filter for the life of the page. */
    opacity: 0;
    transition: opacity 0.3s ease, backdrop-filter 0.3s ease;
}

.site-popup.is-open .site-popup-backdrop {
    opacity: 1;
    backdrop-filter: blur(4px) saturate(120%);
    -webkit-backdrop-filter: blur(4px) saturate(120%);
}

.site-popup-card {
    position: relative;
    width: 100%;
    max-width: var(--site-popup-width);
    max-height: calc(100vh - 48px);
    overflow: hidden auto;
    background: var(--site-popup-surface);
    color: var(--site-popup-text);
    border: 1px solid var(--site-popup-border);
    border-radius: var(--site-popup-radius);
    /* Layered rather than one big blur: a tight contact shadow reads as an edge, the wide one as
       elevation. One shadow doing both jobs always looks muddy. */
    box-shadow:
        0 2px 4px rgba(10, 12, 30, 0.06),
        0 12px 24px rgba(10, 12, 30, 0.14),
        0 40px 80px rgba(10, 12, 30, 0.30);
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    transition: opacity 0.3s ease, transform 0.42s cubic-bezier(0.22, 1.2, 0.36, 1);
}

/* Accent hairline across the top — the one piece of brand colour that shows even on a text-only
   popup with no artwork. */
.site-popup-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--site-popup-accent), var(--site-popup-accent-2));
    z-index: 3;
}

.site-popup.is-open .site-popup-card {
    opacity: 1;
    transform: none;
}

.site-popup-close {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 4;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.30);
    border-radius: 50%;
    /* Its own backdrop: the button sits over artwork that could be any colour. */
    background: rgba(10, 12, 30, 0.55);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    color: #ffffff;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.site-popup-close:hover {
    background: rgba(10, 12, 30, 0.82);
    transform: rotate(90deg);
}

.site-popup-media {
    position: relative;
    /* contain, not cover: promotional artwork is composed art with wording in it, and cropping it
       to fill a box cuts the message in half. */
    background:
        radial-gradient(120% 100% at 50% 0%, color-mix(in srgb, var(--site-popup-accent) 12%, transparent), transparent 70%),
        var(--site-popup-surface-2);
    overflow: hidden;
}

.site-popup-image {
    display: block;
    width: 100%;
    max-height: 330px;
    object-fit: contain;
}

/* Scrim behind the top controls so the close button and disclosure stay legible over pale artwork. */
.site-popup-media::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 76px;
    background: linear-gradient(to bottom, rgba(10, 12, 30, 0.28), transparent);
    pointer-events: none;
    z-index: 1;
}

.site-popup-disclosure {
    position: absolute;
    top: 14px;
    left: 14px;
    z-index: 2;
    padding: 5px 11px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 100px;
    background: rgba(10, 12, 30, 0.72);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    color: rgba(255, 255, 255, 0.94);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.site-popup-body {
    position: relative;
    padding: 26px 28px 28px;
}

.site-popup-title {
    margin: 0 0 10px;
    font-size: 25px;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.site-popup-text {
    margin: 0;
    color: var(--site-popup-muted);
    font-size: 15.5px;
    line-height: 1.6;
}

.site-popup-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 24px;
}

.site-popup-btn {
    flex: 1 1 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 12px 22px;
    border: 1px solid transparent;
    border-radius: 100px;
    font-size: 15px;
    font-weight: 650;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.22s ease, background 0.2s ease;
}

.site-popup-btn-primary {
    background: linear-gradient(135deg, var(--site-popup-accent), var(--site-popup-accent-2));
    color: var(--site-popup-accent-text);
    box-shadow: 0 6px 18px color-mix(in srgb, var(--site-popup-accent) 38%, transparent);
}

.site-popup-btn-primary:hover {
    color: var(--site-popup-accent-text);
    transform: translateY(-2px);
    box-shadow: 0 10px 26px color-mix(in srgb, var(--site-popup-accent) 50%, transparent);
}

.site-popup-btn-primary:active {
    transform: translateY(0);
}

.site-popup-btn-ghost {
    flex: 0 1 auto;
    background: transparent;
    border-color: var(--site-popup-border);
    color: var(--site-popup-muted);
}

.site-popup-btn-ghost:hover {
    background: color-mix(in srgb, var(--site-popup-text) 6%, transparent);
}

/* Keyboard focus must stay obvious inside a focus-trapped dialog. */
.site-popup-btn:focus-visible,
.site-popup-close:focus-visible {
    outline: 3px solid var(--site-popup-accent);
    outline-offset: 3px;
}

/* Scroll lock. Applied to <html> so it survives the host re-rendering <body> content. */
.has-site-popup {
    overflow: hidden;
}

/* ---- Mobile: bottom sheet ----------------------------------------------
   Applied by the script below the configured breakpoint. A sheet that slides over the bottom of the
   page, rather than a dialog that covers it, is the difference between a promotion and the kind of
   content-blocking interstitial mobile search ranks down. */
.site-popup--sheet {
    align-items: flex-end;
    padding: 0;
}

.site-popup--sheet .site-popup-card {
    max-width: none;
    max-height: 90vh;
    border-radius: 26px 26px 0 0;
    border-bottom: none;
    transform: translateY(100%) scale(1);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.25s ease;
}

.site-popup--sheet.is-open .site-popup-card {
    transform: none;
}

/* Grab handle. Purely a affordance cue — dragging is not wired up — so it is drawn in CSS rather
   than added to the markup, and stays out of the accessibility tree. */
.site-popup--sheet .site-popup-body::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 50%;
    width: 40px;
    height: 4px;
    margin-left: -20px;
    border-radius: 100px;
    background: color-mix(in srgb, var(--site-popup-text) 18%, transparent);
}

.site-popup--sheet .site-popup-body {
    padding-top: 30px;
    padding-bottom: max(28px, env(safe-area-inset-bottom));
}

/* Artwork present means the handle would sit on the image, so it moves onto the body below it. */
.site-popup--sheet .site-popup-media {
    border-radius: 26px 26px 0 0;
}

.site-popup--sheet .site-popup-image {
    max-height: 38vh;
}

/* Primary action on top on a sheet: it sits nearest the thumb. */
.site-popup--sheet .site-popup-actions {
    flex-direction: column-reverse;
}

.site-popup--sheet .site-popup-btn {
    width: 100%;
    flex: 0 0 auto;
}

/* ---- Dark scheme ------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
    .site-popup {
        --site-popup-surface: #171a30;
        --site-popup-surface-2: #10122a;
        --site-popup-text: #f2f3fb;
        --site-popup-muted: #a6abcd;
        --site-popup-border: rgba(255, 255, 255, 0.12);
        --site-popup-backdrop: rgba(4, 5, 16, 0.72);
    }

    .site-popup-card {
        box-shadow:
            0 2px 4px rgba(0, 0, 0, 0.30),
            0 12px 24px rgba(0, 0, 0, 0.40),
            0 40px 80px rgba(0, 0, 0, 0.55);
    }
}

@media (prefers-reduced-motion: reduce) {
    .site-popup-backdrop,
    .site-popup-card,
    .site-popup-close,
    .site-popup-btn,
    .site-popup--sheet .site-popup-card {
        transition-duration: 0.01ms;
    }

    .site-popup-close:hover,
    .site-popup-btn-primary:hover {
        transform: none;
    }
}
