/* Winsiders Custom Elements — Bloc texte & popup (av_wce_text_popup).
 *
 * Short rich text rendered in the page + trigger button that opens a modal
 * dialog. The popup content lives in the page HTML (server-side render). The
 * scroll happens INSIDE the dialog body (overflow-y), never on the page, and
 * the dialog becomes a bottom-sheet on mobile. */

/* Accordion-style float safety: Enfold's av_hr floats left and would shrink
 * this column otherwise. */
.wce-textpopup {
    clear: both;

    /* Layout: column so the trigger sits under the text. Alignment is driven
     * by modifiers on the container (see --align-* below). */
    display: flex;
    flex-direction: column;
    align-items: var(--wce-tp-items, flex-start);

    /* Zone-aware accent (inline --wce-tp-accent from the element, when set,
     * wins over all of these because inline styles have higher precedence). */
    --wce-tp-accent: var(--enfold-main-color-primary, currentColor);
    --wce-tp-items: flex-start;
}

/* In a column flex layout items shrink-wrap and do not stretch: force the
 * text to keep the full container width whatever the button alignment is. */
.wce-textpopup__text {
    width: 100%;
}

.wce-textpopup--align-left {
    --wce-tp-items: flex-start;
}

.wce-textpopup--align-center {
    --wce-tp-items: center;
}

.wce-textpopup--align-right {
    --wce-tp-items: flex-end;
}

.alternate_color .wce-textpopup {
    --wce-tp-accent: var(--enfold-alternate-color-primary, currentColor);
}

.footer_color .wce-textpopup {
    --wce-tp-accent: var(--enfold-footer-color-primary, currentColor);
}

.socket_color .wce-textpopup {
    --wce-tp-accent: var(--enfold-socket-color-primary, currentColor);
}

/* --- Trigger button --- */
.wce-textpopup__trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 14px;
    cursor: pointer;
    border: 0;
    border-radius: 999px;
    font-weight: 600;
    line-height: 1.3;
    text-decoration: none;
    transition: opacity 0.2s ease;
    color: var(--wce-tp-accent, currentColor);
}

.wce-textpopup__trigger--sm {
    padding: 8px 16px;
    font-size: 13px;
}

.wce-textpopup__trigger--md {
    padding: 11px 22px;
    font-size: 15px;
}

.wce-textpopup__trigger--lg {
    padding: 14px 28px;
    font-size: 17px;
}

.wce-textpopup__trigger--solid {
    background: var(--wce-tp-accent, currentColor);
    color: #ffffff;
}

.wce-textpopup__trigger--outline {
    background: transparent;
    border: 2px solid var(--wce-tp-accent, currentColor);
    padding-top: 9px;
    padding-bottom: 9px;
}

.wce-textpopup__trigger--link {
    background: transparent;
    border-radius: 0;
    padding: 2px 0;
    font-size: inherit;
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* Hover: opacity only — no background/brand color swap (plugin convention:
 * custom colors must not be overridden). */
.wce-textpopup__trigger:hover {
    opacity: 0.92;
}

.wce-textpopup__trigger:focus-visible {
    outline: 2px solid var(--wce-tp-accent, currentColor);
    outline-offset: 2px;
}

/* --- Dialog (native <dialog>) --- */
/* The 24px top/bottom transparent padding is the "click beside the panel to
 * close" target: a click whose event target IS the dialog closes it.
 * The `main_color` class (added by the PHP handler) lets Enfold's zone CSS
 * drive the text color: do NOT set `color` here or on the panel — a section
 * with an alternate color must not leak its light text onto the white panel. */
dialog.wce-textpopup__dialog {
    border: 0;
    padding: 24px 0;
    background: transparent;
    width: min(var(--wce-tp-width, 720px), calc(100vw - 48px));
    max-width: calc(100vw - 48px);
    max-height: 85vh;
    max-height: 85dvh;
}

dialog.wce-textpopup__dialog::backdrop {
    background: var(--wce-tp-overlay, rgba(15, 23, 32, 0.62));
    animation: wce-tp-backdrop-in 0.25s ease-out;
}

/* #top prefix to beat the Enfold zone selectors that paint generic elements. */
#top .wce-textpopup__panel {
    position: relative;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border-radius: var(--wce-tp-radius, 16px);
    box-shadow: 0 24px 64px rgba(15, 23, 32, 0.35);
    padding: 26px 28px;
    max-height: inherit;
    min-height: 0;
    overflow: hidden;
}

#top .wce-textpopup__title {
    margin: 0;
    padding: 0;
    padding-right: 40px;
    margin-bottom: 12px;
    color: inherit;
}

#top .wce-textpopup__close {
    position: absolute;
    top: 10px;
    right: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: transparent;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    color: inherit;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

#top .wce-textpopup__close:hover {
    opacity: 1;
}

#top .wce-textpopup__close:focus-visible {
    outline: 2px solid var(--wce-tp-accent, currentColor);
    outline-offset: 2px;
}

#top .wce-textpopup__close svg {
    display: block;
}

/* --- Scrollable body (core ergonomics: the page never scrolls) --- */
#top .wce-textpopup__body {
    overflow-y: auto;
    min-height: 0;
    padding-right: 4px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(31, 45, 43, 0.3) transparent;
}

#top .wce-textpopup__body::-webkit-scrollbar {
    width: 8px;
}

#top .wce-textpopup__body::-webkit-scrollbar-track {
    background: transparent;
}

#top .wce-textpopup__body::-webkit-scrollbar-thumb {
    background: rgba(31, 45, 43, 0.25);
    border-radius: 999px;
}

/* --- Body typography (Enfold resets) --- */
#top .wce-textpopup__body p {
    margin: 0 0 1em;
}

#top .wce-textpopup__body ul,
#top .wce-textpopup__body ol {
    margin: 0 0 1em;
    padding-left: 1.4em;
}

#top .wce-textpopup__body li {
    margin: 0 0 0.35em;
}

#top .wce-textpopup__body a {
    color: var(--wce-tp-accent, currentColor);
}

#top .wce-textpopup__body > :first-child {
    margin-top: 0;
}

#top .wce-textpopup__body > :last-child {
    margin-bottom: 0;
}

/* --- Open animation --- */
dialog.wce-textpopup__dialog[open] .wce-textpopup__panel {
    animation: wce-tp-in 0.3s ease-out;
}

.wce-textpopup--anim-fade .wce-textpopup__dialog[open] .wce-textpopup__panel {
    animation-name: wce-tp-in-fade;
}

.wce-textpopup--anim-none .wce-textpopup__dialog[open] .wce-textpopup__panel {
    animation: none;
}

@keyframes wce-tp-in {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes wce-tp-in-fade {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes wce-tp-backdrop-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* --- Close animation (symmetric with the opening) --- */
/* The dialog gets the .wce-tp-closing class from the JS (all close paths),
 * then actually closes ~230ms later. Placed AFTER the open rules so they win
 * the equal-specificity, later-in-file cascade. */
dialog.wce-textpopup__dialog.wce-tp-closing .wce-textpopup__panel {
    animation: wce-tp-out 0.22s ease-in forwards;
}

dialog.wce-textpopup__dialog.wce-tp-closing::backdrop {
    animation: wce-tp-backdrop-out 0.22s ease-in forwards;
}

.wce-textpopup--anim-fade .wce-textpopup__dialog.wce-tp-closing .wce-textpopup__panel {
    animation-name: wce-tp-out-fade;
}

.wce-textpopup--anim-none .wce-textpopup__dialog.wce-tp-closing .wce-textpopup__panel {
    animation: none;
}

@keyframes wce-tp-out {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(16px);
    }
}

@keyframes wce-tp-out-fade {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

@keyframes wce-tp-backdrop-out {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    dialog.wce-textpopup__dialog,
    dialog.wce-textpopup__dialog::backdrop,
    dialog.wce-textpopup__dialog .wce-textpopup__panel {
        animation: none !important;
        transition: none !important;
    }
}

/* --- Mobile: bottom sheet --- */
@media (max-width: 640px) {
    dialog.wce-textpopup__dialog {
        margin: auto 0 0;
        width: 100vw;
        max-width: 100vw;
        padding: 0 0 env(safe-area-inset-bottom, 0px);
        max-height: 88vh;
        max-height: 88dvh;
    }

    #top .wce-textpopup__panel {
        border-radius: var(--wce-tp-radius, 16px) var(--wce-tp-radius, 16px) 0 0;
        padding: 26px 20px;
        /* Keep the panel above the home-indicator / safe-area zone. */
        max-height: calc(88vh - env(safe-area-inset-bottom, 0px));
        max-height: calc(88dvh - env(safe-area-inset-bottom, 0px));
    }
}

/* --- Fallback without showModal (rare legacy browsers) --- */
.wce-textpopup__dialog--no-native {
    position: fixed;
    inset: 0;
    display: none;
    flex-direction: column;
    width: auto;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 24px;
    z-index: 99999;
}

.wce-textpopup__dialog--no-native.is-open {
    display: flex;
}

.wce-textpopup__dialog--no-native::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--wce-tp-overlay, rgba(15, 23, 32, 0.62));
}

.wce-textpopup__dialog--no-native .wce-textpopup__panel {
    position: relative;
    margin: auto;
    max-height: 85vh;
    max-height: 85dvh;
}