/**
 * GPRO Scripts — Offcanvas.
 * Panels sliding in from any side or popping up centered, a dimmed
 * backdrop, and a hamburger that morphs into an X. Enqueued only
 * when the Offcanvas script is enabled under GPRO Dashboard → Scripts.
 *
 * Panel classes (on the panel Section):
 *   gpro-offcanvas             slides in from the right (default)
 *   gpro-offcanvas--left       from the left
 *   gpro-offcanvas--top        from the top, full width
 *   gpro-offcanvas--bottom     from the bottom, full width
 *   gpro-offcanvas--center     centered popup, fades and scales in
 *   gpro-offcanvas--over       above the header (center always is)
 *
 * Size and offset: set in Divi on the panel Section (Sizing → Width
 * and Height, Position → Fixed + Vertical Offset); the defaults below
 * have zero specificity. Fallbacks: top 0, side width
 * min(400px, 75vw), center min(600px, 90vw). The side a panel is
 * anchored to comes from its class, whatever Divi's offset origin.
 *
 * Variables, on :root or a panel ID:
 *   --gpro-offcanvas-speed     animation length (450ms)
 *   --gpro-offcanvas-dim       backdrop colour (rgba(0,0,0,.35))
 *   --gpro-crystal-blur        backdrop blur (12px)
 *   --gpro-burger-size         hamburger size (Divi Icon Size)
 *   --gpro-burger-thickness    bar thickness (0.085em, 1-3px)
 *   --gpro-offcanvas-z         backdrop layer (990); panels +1,
 *                              header +2, --over panels +3
 *
 * Stacking: Divi gives each template's .et_builder_inner_content
 * z-index 3, trapping a panel's own z-index inside it. The header
 * wrappers holding panels or toggles are lifted instead:
 * page < backdrop < panels < header < --over panels. Panels belong in
 * a Divi off-canvas canvas or the header template.
 */

/* Defaults, Divi overrides these */
:where(.gpro-offcanvas) {
    top: 0;
    width: min(400px, 75vw);
    max-height: 100vh;
    max-height: 100dvh;
    overflow-y: auto;
}
:where(.gpro-offcanvas--top, .gpro-offcanvas--bottom) {
    width: auto;
}
:where(.gpro-offcanvas--center) {
    width: min(600px, 90vw);
    max-height: 90vh;
    max-height: 90dvh;
}

/* Forced: fixed, anchored, hidden */
body .gpro-offcanvas {
    --gpro-oc-ease: cubic-bezier(0.25, 1, 0.5, 1);
    position: fixed;
    right: 0;
    bottom: auto;
    left: auto;
    transform: translateX(100%);
    visibility: hidden;
    pointer-events: none;
    transition: transform var(--gpro-offcanvas-speed, 450ms) var(--gpro-oc-ease),
                visibility 0s linear var(--gpro-offcanvas-speed, 450ms);
    z-index: 9999;
}

/* Left */
body .gpro-offcanvas--left {
    right: auto;
    left: 0;
    transform: translateX(-100%);
}

/* Top and bottom */
body .gpro-offcanvas--top,
body .gpro-offcanvas--bottom {
    left: 0;
    right: 0;
}
body .gpro-offcanvas--top {
    transform: translateY(-100%);
}
body .gpro-offcanvas--bottom {
    top: auto;
    bottom: 0;
    transform: translateY(100%);
}

/* Center popup */
body .gpro-offcanvas--center {
    top: 50%;
    left: 50%;
    right: auto;
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.96);
    transition: transform var(--gpro-offcanvas-speed, 450ms) var(--gpro-oc-ease),
                opacity var(--gpro-offcanvas-speed, 450ms) var(--gpro-oc-ease),
                visibility 0s linear var(--gpro-offcanvas-speed, 450ms);
}

/* Open state */
body .gpro-offcanvas.gpro-offcanvas-open {
    transform: none;
    visibility: visible;
    pointer-events: auto;
    transition-delay: 0s;
}
body .gpro-offcanvas--center.gpro-offcanvas-open {
    opacity: 1;
    transform: translate(-50%, -50%);
}

/* Always visible in builder */
body.et-fb .gpro-offcanvas {
    transform: none !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}
body.et-fb .gpro-offcanvas--center {
    transform: translate(-50%, -50%) !important;
}

/* Dimmed page behind panel */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    background: var(--gpro-offcanvas-dim, rgba(0, 0, 0, 0.35));
    -webkit-backdrop-filter: blur(var(--gpro-crystal-blur, 12px));
    backdrop-filter: blur(var(--gpro-crystal-blur, 12px));
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--gpro-offcanvas-speed, 450ms) cubic-bezier(0.25, 1, 0.5, 1);
    z-index: var(--gpro-offcanvas-z, 990);
}
body:not(.et-fb):has(.gpro-offcanvas.gpro-offcanvas-open)::after {
    opacity: 1;
    pointer-events: auto;
}

/* Panels above backdrop */
.et-l--header > .et_builder_inner_content:has(.gpro-offcanvas) {
    z-index: calc(var(--gpro-offcanvas-z, 990) + 1);
}

/* Header above panels */
.et-l--header > .et_builder_inner_content:has(#gpro-offcanvas-toggle, .gpro-offcanvas-toggle):not(:has(.gpro-offcanvas)) {
    z-index: calc(var(--gpro-offcanvas-z, 990) + 2);
}

/* Over panels above header */
.et-l--header > .et_builder_inner_content:has(.gpro-offcanvas--over, .gpro-offcanvas--center) {
    z-index: calc(var(--gpro-offcanvas-z, 990) + 3);
}

/* Toggle hit area */
#gpro-offcanvas-toggle,
.gpro-offcanvas-toggle {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.et-pb-icon:has(> .gpro-burger) {
    display: inline-flex;
    line-height: 0;
}

/* Three bars, sized by font */
.gpro-burger {
    --gpro-burger-bar: var(--gpro-burger-thickness, clamp(1.5px, 0.085em, 3px));
    --gpro-burger-gap: 0.21em;
    --gpro-burger-shift: calc(var(--gpro-burger-gap) + var(--gpro-burger-bar));
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: var(--gpro-burger-gap);
    width: 1em;
    height: 1em;
    font-size: var(--gpro-burger-size, inherit);
    vertical-align: middle;
}
/* Whole pixels, crisp bars */
@supports (width: round(1.5px, 1px)) {
    .gpro-burger {
        --gpro-burger-bar: var(--gpro-burger-thickness, clamp(1px, round(0.085em, 1px), 3px));
        --gpro-burger-gap: round(0.21em, 1px);
        width: round(1em, 2px);
        height: round(1em, 2px);
    }
}
.gpro-burger > span {
    display: block;
    flex: none;
    height: var(--gpro-burger-bar);
    background: currentColor;
    border-radius: 1px;
    transition: transform 400ms cubic-bezier(0.25, 1, 0.5, 1),
                opacity 200ms ease;
}

/* Morph to X */
[aria-expanded="true"] .gpro-burger > span:nth-child(1) {
    transform: translateY(var(--gpro-burger-shift)) rotate(45deg);
}
[aria-expanded="true"] .gpro-burger > span:nth-child(2) {
    opacity: 0;
}
[aria-expanded="true"] .gpro-burger > span:nth-child(3) {
    transform: translateY(calc(var(--gpro-burger-shift) * -1)) rotate(-45deg);
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    .gpro-burger > span,
    body .gpro-offcanvas,
    body::after {
        transition: none;
    }
}
