/* =========================================================================
   UX-02  Floating-controls overlay hierarchy
   -------------------------------------------------------------------------
   Four things are pinned to the viewport on every page:

     cookie banner  ·  cookie "Manage" link  ·  WhatsApp button  ·  HubSpot chat

   They used to be positioned independently and fought over the same
   bottom corner. This file is the single place that decides who is where.

   LAYERS (low -> high)
     1  WhatsApp button          z-index 900     bottom-right, ABOVE the chat launcher
     2  HubSpot launcher / panel HubSpot's own z-index (we only control WHEN it shows)
     3  Cookie banner            cookie-consent.css
     4  Cookie preferences modal cookie-consent.css (covers everything)

   ONE-AT-A-TIME RULES
     - While the cookie banner is open (html.eximus-banner-open) the chat
       launcher is hidden at every width, and the WhatsApp button is hidden
       below 900px, where the banner spans the screen. From 900px up the
       banner (max 690px, left-aligned) cannot reach the right-hand launchers,
       so WhatsApp stays visible.
     - When the banner is answered the launchers fade in AFTER it has faded
       out (see the transition-delay), never on top of it.
     - The chat never opens by itself (loader logic lives in partials/head.php;
       html.eximus-chat-hold keeps the launcher invisible until it is collapsed).

   SAFE AREA
     env(safe-area-inset-*) is added to every edge offset. It is 0 today
     because the viewport meta has no viewport-fit=cover; the offsets start
     working the moment that is enabled (see the notes that came with this fix).

   Classes toggled on <html>:
     eximus-banner-open   set in head.php before first paint, cleared by cookie-consent.js
     eximus-chat-hold     set by head.php while the HubSpot launcher is being collapsed
   ========================================================================= */

:root {
    --exm-edge-x: 20px;            /* gap between a launcher and the side of the screen   */
    --exm-chat-clearance: 100px;   /* bottom edge of WhatsApp: clears the HubSpot launcher's ~100px-tall hit area (the bubble itself is ~60px + 20px margin) */
    --exm-safe-bottom: env(safe-area-inset-bottom, 0px);
    --exm-safe-right: env(safe-area-inset-right, 0px);
}

/* ---- WhatsApp button -------------------------------------------------- */
html .whatsapp-sticky {
    position: fixed;
    right: calc(var(--exm-edge-x) + var(--exm-safe-right));
    bottom: calc(var(--exm-chat-clearance) + var(--exm-safe-bottom));
    z-index: 900;
    /* Reveal: wait .3s so the banner has finished fading out (it takes .25s). */
    transition: opacity .25s ease .3s, transform .25s ease .3s, visibility 0s linear .3s;
}

/* ---- HubSpot chat container (third-party markup, so selector + !important) */
#hubspot-messages-iframe-container {
    bottom: var(--exm-safe-bottom) !important;
    right: var(--exm-safe-right) !important;
}

/* Hidden while the banner is up, or while we are collapsing a chat that tried to open itself. */
html.eximus-banner-open #hubspot-messages-iframe-container,
html.eximus-chat-hold #hubspot-messages-iframe-container {
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* ---- Below 900px the banner spans the screen: WhatsApp waits for it ---- */
@media (max-width: 899.98px) {
    html.eximus-banner-open .whatsapp-sticky {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transform: translateY(8px);
        /* Hide quickly (.15s) so the two never share the screen. */
        transition: opacity .15s ease, transform .15s ease, visibility 0s linear .15s;
    }
}

/* ---- Cookie preferences modal is a full-screen dialog: nothing floats above it.
        (:has() is progressive enhancement; the modal's own z-index already covers them.) */
body:has(#eximus-cookie-preferences.active) .whatsapp-sticky,
body:has(#eximus-cookie-preferences.active) #hubspot-messages-iframe-container {
    visibility: hidden !important;
}

@media (prefers-reduced-motion: reduce) {
    html .whatsapp-sticky,
    html.eximus-banner-open .whatsapp-sticky {
        transition: none;
    }
}
