/*
 * One look for every overlay the shops show: age gate, cookie notice and its
 * settings, the email-server onsite popups/fly-ins and the web-chat launcher.
 * Values follow the popy design tokens (card #fff, ink #0A0A0A, muted #666,
 * radius.xl 16, pill CTAs). The accent is the theme's own primary, so
 * popy-csp stays black and asgano-csp uses its brand blue.
 *
 * Desktop: centred card. Phone: bottom sheet. Only one overlay at a time:
 * while a modal dialog, the cookie notice or its settings are open, the
 * onsite popups and the chat launcher wait and appear once they are gone.
 */
:root {
    --popy-ov-bg: #ffffff;
    --popy-ov-fg: #0a0a0a;
    --popy-ov-muted: #666666;
    --popy-ov-line: #e5e5e5;
    --popy-ov-scrim: rgb(10 10 10 / 0.55);
    --popy-ov-accent: var(--color-primary, #0a0a0a);
    --popy-ov-on-accent: var(--color-on-primary, #ffffff);
    --popy-ov-radius: 16px;
    --popy-ov-shadow: 0 24px 64px -16px rgb(10 10 10 / 0.35), 0 2px 8px rgb(10 10 10 / 0.08);
    --popy-ov-pad: 2rem;
}

@media (max-width: 639px) {
    :root {
        --popy-ov-pad: 1.5rem;
    }
}

/* ---------------------------------------------------------------- age gate */
/* Magedia_Popy::modal.phtml; its texts and callbacks stay as they are. The
   second button ("No") is the quiet option. */
[x-data="initAgeVerificationModal"] dialog {
    width: min(28rem, calc(100% - 2rem));
    max-width: none;
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    padding: 0;
    border: 0;
    border-radius: var(--popy-ov-radius);
    background: var(--popy-ov-bg);
    color: var(--popy-ov-fg);
    box-shadow: var(--popy-ov-shadow);
}

[x-data="initAgeVerificationModal"] dialog::backdrop {
    background: var(--popy-ov-scrim);
}

[x-data="initAgeVerificationModal"] dialog > div:first-child {
    padding: var(--popy-ov-pad) var(--popy-ov-pad) 0;
}

[x-data="initAgeVerificationModal"] dialog img {
    max-height: 3rem;
    width: auto;
}

[x-data="initAgeVerificationModal"] dialog #modal-title {
    font-size: 1.375rem;
    line-height: 1.25;
    text-wrap: balance;
}

[x-data="initAgeVerificationModal"] dialog #modal-title + div {
    color: var(--popy-ov-muted);
    line-height: 1.5;
}

[x-data="initAgeVerificationModal"] dialog > div:last-child {
    padding: 1.5rem var(--popy-ov-pad) var(--popy-ov-pad);
    gap: 0.75rem;
}

@media (max-width: 639px) {
    [x-data="initAgeVerificationModal"] dialog {
        width: 100%;
        max-height: calc(100dvh - 1rem);
        margin: auto 0 0;
        border-radius: var(--popy-ov-radius) var(--popy-ov-radius) 0 0;
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Shared pill buttons inside overlays (theme .btn keeps its behaviour). */
[x-data="initAgeVerificationModal"] dialog .btn,
.mst-gdpr__cookie-bar .mst-gdpr__buttons .action,
[data-mst-gdpr-settings-modal] .btn {
    justify-content: center;
    min-height: 3rem;
    padding: 0.75rem 1.5rem;
    border: 1.5px solid var(--popy-ov-accent);
    border-radius: 999px;
    background: var(--popy-ov-accent);
    color: var(--popy-ov-on-accent);
    font-size: 0.9375rem;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    box-shadow: none;
}

[x-data="initAgeVerificationModal"] dialog > div:last-child > .btn:last-child,
.mst-gdpr__cookie-bar .mst-gdpr__buttons [data-trigger-settings="trigger"] {
    border-color: var(--popy-ov-line);
    background: transparent;
    color: var(--popy-ov-fg);
}

[x-data="initAgeVerificationModal"] dialog .btn:hover,
.mst-gdpr__cookie-bar .mst-gdpr__buttons .action:hover,
[data-mst-gdpr-settings-modal] .btn:hover {
    filter: brightness(1.15);
}

[x-data="initAgeVerificationModal"] dialog > div:last-child > .btn:last-child:hover,
.mst-gdpr__cookie-bar .mst-gdpr__buttons [data-trigger-settings="trigger"]:hover {
    filter: none;
    border-color: var(--popy-ov-fg);
}

[x-data="initAgeVerificationModal"] dialog .btn:focus-visible,
.mst-gdpr__cookie-bar .mst-gdpr__buttons .action:focus-visible,
[data-mst-gdpr-settings-modal] .btn:focus-visible,
[data-mst-gdpr-settings-modal] [x-on\:click="close"]:focus-visible {
    outline: 2px solid var(--popy-ov-fg);
    outline-offset: 2px;
}

/* ----------------------------------------------------------- cookie notice */
/* The consent text and buttons stay Mirasvit's; only placement and look. */
.mst-gdpr__cookie-bar,
[data-mst-gdpr-settings-modal] {
    color: var(--popy-ov-fg);
    background-color: var(--popy-ov-bg);
}

.mst-gdpr__cookie-bar .consent-text a,
[data-mst-gdpr-settings-modal] a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

#gdprCookieBar .mst-gdpr__cookie-bar {
    left: 1.5rem;
    right: auto;
    bottom: 1.5rem;
    width: min(34rem, calc(100% - 3rem));
    max-width: none;
    max-height: calc(100dvh - 3rem);
    overflow-y: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 1.25rem;
    padding: 1.5rem;
    border: 0;
    border-radius: var(--popy-ov-radius);
    box-shadow: var(--popy-ov-shadow);
    font-size: 0.875rem;
    line-height: 1.55;
}

#gdprCookieBar .mst-gdpr__cookie-bar .consent-text {
    color: #333333;
}

#gdprCookieBar .mst-gdpr__buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

/* Accept and decline are equal-weight; settings sits below as the quiet option. */
#gdprCookieBar .mst-gdpr__buttons .action {
    width: auto;
    margin: 0;
    font-size: 0.875rem;
}

#gdprCookieBar .mst-gdpr__buttons [data-trigger-settings="trigger"] {
    grid-column: 1 / -1;
    order: 3;
}

@media (max-width: 639px) {
    #gdprCookieBar .mst-gdpr__cookie-bar {
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 85dvh;
        padding: 1.25rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom));
        border-radius: var(--popy-ov-radius) var(--popy-ov-radius) 0 0;
        font-size: 0.8125rem;
    }
}

/* Cookie settings: scrim behind a centred card, bottom sheet on phones. */
div:has(> [data-mst-gdpr-settings-modal]) {
    z-index: 2147483100;
    padding: 1rem;
    background: var(--popy-ov-scrim);
}

[data-mst-gdpr-settings-modal] {
    width: 100%;
    max-width: 40rem;
    height: auto;
    max-height: calc(100dvh - 2rem);
    margin: 0;
    padding: var(--popy-ov-pad);
    border: 0;
    border-radius: var(--popy-ov-radius);
    box-shadow: var(--popy-ov-shadow);
    font-size: 0.875rem;
    line-height: 1.55;
}

[data-mst-gdpr-settings-modal] > div:first-child {
    align-items: flex-start;
    gap: 1rem;
    border-color: var(--popy-ov-line);
}

[data-mst-gdpr-settings-modal] h3 {
    font-size: 1.375rem;
    font-weight: 700;
    line-height: 1.25;
}

[data-mst-gdpr-settings-modal] [x-on\:click="close"] {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    margin: -0.5rem -0.75rem 0 0;
    padding: 0;
    border-radius: 999px;
}

[data-mst-gdpr-settings-modal] [x-on\:click="close"]:hover {
    background: #f4f4f4;
}

[data-mst-gdpr-settings-modal] .cookie-group-container {
    border-color: var(--popy-ov-line);
    border-radius: 12px;
    box-shadow: none;
}

[data-mst-gdpr-settings-modal] [data-mst-gdpr-settings-apply] {
    margin-left: 0;
    width: 100%;
}

@media (max-width: 639px) {
    div:has(> [data-mst-gdpr-settings-modal]) {
        align-items: flex-end;
        padding: 0;
    }

    [data-mst-gdpr-settings-modal] {
        max-width: none;
        max-height: 90dvh;
        padding-bottom: calc(var(--popy-ov-pad) + env(safe-area-inset-bottom));
        border-radius: var(--popy-ov-radius) var(--popy-ov-radius) 0 0;
    }

    [data-mst-gdpr-settings-modal] h3 {
        font-size: 1.25rem;
    }
}

/* --------------------------------------------- email-server onsite widget */
/* onsite.js injects its stylesheet after this file; the html/body prefix
   keeps these shop-wide overlay rules ahead of it without !important. */
html body .popyf-ov {
    background: var(--popy-ov-scrim);
}

html body .popyf-card,
html body .popyf-fly {
    border-radius: var(--popy-ov-radius);
    box-shadow: var(--popy-ov-shadow);
}

html body .popyf-card {
    max-width: 30rem;
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    padding: var(--popy-ov-pad) var(--popy-ov-pad) calc(var(--popy-ov-pad) - 0.25rem);
}

html body .popyf-card .popyf-hero {
    width: calc(100% + 2 * var(--popy-ov-pad));
    margin: calc(-1 * var(--popy-ov-pad)) calc(-1 * var(--popy-ov-pad)) 1.25rem;
    border-radius: var(--popy-ov-radius) var(--popy-ov-radius) 0 0;
    max-height: 15rem;
}

html body .popyf-fly .popyf-hero {
    border-radius: var(--popy-ov-radius) var(--popy-ov-radius) 0 0;
}

html body .popyf-h {
    color: var(--popy-ov-fg);
    font-size: 1.375rem;
    line-height: 1.25;
    text-wrap: balance;
}

html body .popyf-p {
    color: var(--popy-ov-muted);
}

html body .popyf-btn,
html body .popyf-lnk-primary {
    border-radius: 999px;
    background: var(--popy-ov-accent);
    color: var(--popy-ov-on-accent);
}

html body .popyf-lnk-secondary {
    border-color: var(--popy-ov-line);
    border-radius: 999px;
}

html body .popyf-in {
    border-color: var(--popy-ov-line);
    border-radius: 12px;
}

html body .popyf-in:focus {
    border-color: var(--popy-ov-fg);
}

html body .popyf-x {
    border-radius: 999px;
    color: var(--popy-ov-fg);
}

html body .popyf-x:focus-visible,
html body .popyf-btn:focus-visible,
html body .popyf-lnk:focus-visible {
    outline: 2px solid var(--popy-ov-fg);
    outline-offset: 2px;
}

/* One quiet overlay per visit (#1363): overlay-guard.js adds .popy-ov-ok to the
   one placement this visit may show; everything else stays held. */
html body .popyf-ov:not(.popy-ov-ok),
html body .popyf-fly:not(.popy-ov-ok),
html body .popyf-ban:not(.popy-ov-ok),
html body:not(.popy-ov-claimed) .popyf-teaser {
    display: none !important;
}

/* Desktop and tablet: a corner card bottom left, never a scrim over the hero
   or its button. The page stays usable around it. */
@media (min-width: 640px) {
    html body .popyf-ov,
    html body .popyf-ov[class] {
        align-items: flex-end;
        justify-content: flex-start;
        padding: 1.125rem;
        background: transparent;
        pointer-events: none;
    }

    html body .popyf-card,
    html body .popyf-fly[class] {
        max-width: 22.5rem;
    }

    html body .popyf-card {
        pointer-events: auto;
    }

    html body .popyf-fly[class] {
        top: auto;
        right: auto;
        bottom: 1.125rem;
        left: 1.125rem;
    }

    html body .popyf-card .popyf-hero,
    html body .popyf-fly .popyf-hero {
        max-height: 9rem;
    }
}

/* Phone (also held sideways): every placement is a compact bottom sheet of at
   most 30 % of the screen, without scrim: thumbnail, headline, button, a 44px
   close. Inline embeds keep their own layout. */
@media (max-width: 639px), (max-height: 500px) {
    html body .popyf-ov,
    html body .popyf-ov[class] {
        align-items: flex-end;
        padding: 0;
        background: transparent;
        pointer-events: none;
    }

    html body .popyf-card,
    html body .popyf-fly[class],
    html body .popyf-ban {
        box-sizing: border-box;
        max-height: 30vh;
        max-height: 30dvh;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    html body .popyf-card,
    html body .popyf-fly[class] {
        max-width: none;
        padding: 0.75rem 3.25rem calc(0.75rem + env(safe-area-inset-bottom)) 1rem;
        border-radius: var(--popy-ov-radius) var(--popy-ov-radius) 0 0;
        box-shadow: 0 -8px 32px -12px rgba(10, 10, 10, 0.35);
    }

    html body .popyf-card {
        pointer-events: auto;
    }

    html body .popyf-fly[class] {
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        width: auto;
    }

    html body .popyf-card > div,
    html body .popyf-fly > div {
        display: grid;
        grid-template-columns: 6rem minmax(0, 1fr);
        column-gap: 0.75rem;
        align-items: center;
    }

    html body .popyf-card > div > *,
    html body .popyf-fly > div > * {
        grid-column: 1 / -1;
    }

    html body .popyf-card .popyf-hero,
    html body .popyf-fly .popyf-hero {
        grid-column: 1;
        grid-row: span 2;
        width: 6rem;
        height: 4.5rem;
        max-height: none;
        aspect-ratio: auto;
        margin: 0 0 0.5rem;
        border-radius: 12px;
        object-fit: cover;
    }

    html body .popyf-has-hero > div > .popyf-h,
    html body .popyf-has-hero > div > .popyf-p {
        grid-column: 2;
        text-align: left;
    }

    html body :is(.popyf-card, .popyf-fly, .popyf-ban) .popyf-h {
        font-size: 1.0625rem;
        margin: 0 0 0.25rem;
    }

    html body :is(.popyf-card, .popyf-fly, .popyf-ban) .popyf-p {
        font-size: 0.875rem;
        line-height: 1.4;
        margin: 0 0 0.5rem;
    }

    html body :is(.popyf-card, .popyf-fly, .popyf-ban) .popyf-logo,
    html body :is(.popyf-card, .popyf-fly, .popyf-ban) .popyf-recs,
    html body .popyf-teaser {
        display: none !important;
    }

    html body :is(.popyf-card, .popyf-fly, .popyf-ban) .popyf-btn,
    html body :is(.popyf-card, .popyf-fly, .popyf-ban) .popyf-lnk,
    html body :is(.popyf-card, .popyf-fly, .popyf-ban) .popyf-in {
        min-height: 44px;
        padding-top: 0.625rem;
        padding-bottom: 0.625rem;
        margin-bottom: 0.5rem;
    }

    html body :is(.popyf-card, .popyf-fly, .popyf-ban) .popyf-cons {
        font-size: 0.75rem;
        margin-top: 0;
    }

    html body .popyf-x,
    html body .popyf-has-hero .popyf-x {
        top: 0.25rem;
        right: 0.25rem;
        width: 44px;
        height: 44px;
        background: none;
        color: var(--popy-ov-fg);
        box-shadow: none;
        backdrop-filter: none;
        font-size: 1.375rem;
    }
}

/* ------------------------------------------------------ one at a time */
/* The age gate (and any other native modal dialog), the cookie notice and
   its settings come first. Onsite popups wait behind them and show once they
   are closed; the chat launcher steps aside so nothing overlaps. */
body:has(dialog:modal) #gdprCookieBar .mst-gdpr__cookie-bar,
body:has(dialog:modal) .popyf-ov,
body:has(dialog:modal) .popyf-fly,
body:has(dialog:modal) .popyf-ban,
body:has(dialog:modal) .popyf-teaser,
body:has(#gdprCookieBar .mst-gdpr__cookie-bar:not([style*="none"])) .popyf-ov,
body:has(#gdprCookieBar .mst-gdpr__cookie-bar:not([style*="none"])) .popyf-fly,
body:has(#gdprCookieBar .mst-gdpr__cookie-bar:not([style*="none"])) .popyf-ban,
body:has(#gdprCookieBar .mst-gdpr__cookie-bar:not([style*="none"])) .popyf-teaser,
body:has([data-mst-gdpr-settings-modal]:not([style*="none"])) .popyf-ov,
body:has([data-mst-gdpr-settings-modal]:not([style*="none"])) .popyf-fly,
body:has([data-mst-gdpr-settings-modal]:not([style*="none"])) .popyf-ban,
body:has([data-mst-gdpr-settings-modal]:not([style*="none"])) .popyf-teaser {
    display: none !important;
}

/* Web-chat host (wa.popy.rocks widget renders into a shadow root on body). */
body:has(dialog:modal) > div[data-theme][dir],
body:has(#gdprCookieBar .mst-gdpr__cookie-bar:not([style*="none"])) > div[data-theme][dir],
body:has([data-mst-gdpr-settings-modal]:not([style*="none"])) > div[data-theme][dir] {
    display: none !important;
}

@media (max-width: 639px), (max-height: 500px) {
    body:has(.popyf-ov.popy-ov-ok) > div[data-theme][dir],
    body:has(.popyf-fly.popy-ov-ok) > div[data-theme][dir],
    body:has(.popyf-ban.popy-ov-ok) > div[data-theme][dir] {
        display: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    html body .popyf-ov,
    html body .popyf-card,
    html body .popyf-fly {
        animation: none;
    }
}
