/* 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 stays vertically centered on every viewport. */

/* 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;
}

/* Empty text block (no text, no media): no gap between the preceding
 * content and the trigger button. */
.wce-textpopup--no-text .wce-textpopup__trigger {
    margin-top: 0;
}

.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: 15px 0;
    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;
}

/* --- Trigger button icon (iconfont field, SVG + font glyph support) --- */
.wce-textpopup__btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

.wce-textpopup__btn-icon .av-icon-char {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1em;
    line-height: 1;
    /* Optical alignment, matching the native Enfold button (icon sits ~1.5px
     * above the line-box center for both font glyphs and inline SVG).
     * relative+top because the wrapper is a centered flex box: a negative
     * margin-bottom here would push the icon DOWN instead of up. */
    position: relative;
    top: -2px;
}

/* SVG icons follow the button font size, so they adapt to sm/md/lg. */
.wce-textpopup__btn-icon .av-icon-char svg {
    display: block;
    width: 1em;
    height: 1em;
    fill: currentColor;
}

/* --- 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);
    /* v0.9.66 — 85vh → 80vh: the popup never covers more than 80% of the
     * browser window height, whatever the viewport (the panel itself is
     * further constrained by the dialog's flex column to 80vh − 2×24px
     * padding). */
    max-height: 80vh;
    max-height: 80dvh;
    /* v0.9.65 — do NOT set `display` here. An author `display` on the base
     * dialog selector overrides the UA `dialog:not([open]) { display: none }`
     * (author styles always beat UA ones), so v0.9.64's `display: flex` made
     * the CLOSED dialog render inline in the page — position: absolute,
     * centered in its column, its panel and close cross painted over the
     * column text. `display` belongs to the [open] rule below; the closed
     * dialog keeps the UA display: none. Geometry (width, max-height,
     * padding) is inert while hidden and can stay here. */
}

/* v0.9.64 — double-scrollbar fix. The UA default overflow on <dialog> is
 * `auto`: when the panel overflowed the dialog (see the panel note below),
 * the DIALOG itself grew its own scrollbar, visible in the transparent
 * padding zone — the "outer" scrollbar reported on small windows.
 * Flex column makes the panel a flex item that shrinks to the real inner
 * height (see min-height: 0), and overflow: hidden guarantees the dialog
 * can never scroll: the only scrollbar is the __body one. */
dialog.wce-textpopup__dialog[open] {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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;
    /* v0.9.64 — was `max-height: inherit`, which passed the dialog's 85vh
     * down WITHOUT subtracting its own 24px×2 padding: a long body made the
     * panel 48px taller than the dialog's inner box, the content overflowed
     * and the dialog's UA `overflow: auto` grew the outer scrollbar (the
     * panel even stuck out of the viewport). The panel is now constrained by
     * the dialog's flex column (flex-shrink + min-height: 0) to the real
     * available height, and __body keeps the single internal scrollbar. */
    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 --- */
/* v0.9.66 — bottom-sheet retired: the popup is now vertically CENTERED on
 * every viewport, exactly like desktop (the UA centers an open modal dialog
 * when no margin override fights it, and the base rules carry no margin
 * override anymore). Width, centering and the 80% height cap all come from
 * the base rules above; the media query only keeps the denser panel padding
 * for touch. The 24px transparent dialog padding (click-outside target)
 * also applies on mobile, giving a tap zone above and below the panel. */
@media (max-width: 640px) {
    #top .wce-textpopup__panel {
        padding: 26px 20px;
    }
}

/* --- 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;
    /* v0.9.66 — 80% cap aligned with the native dialog rule. */
    max-height: 80vh;
    max-height: 80dvh;
}
