/**
 * Dekofactory FloatingContact – FAB Widget
 */

/* ── CSS custom properties (colour defaults) ────────────────────────────────
   These are overridden per-store by an inline <style> injected from the block
   when admin colours are configured.
   ─────────────────────────────────────────────────────────────────────────── */
#custom-fab-widget {
    --fab-clr-main:      #8B7A35;
    --fab-clr-info:      #333333;
    --fab-clr-tawk:      #8B7A35;
    --fab-clr-whatsapp:  #128C7E;
}

/* ── Container ─────────────────────────────────────────────────────────────── */
.custom-fab-widget {
    position: fixed;
    bottom: 24px;
    z-index: 9000;
    width: 56px;
    height: 56px;
    -webkit-tap-highlight-color: transparent;
}

.custom-fab-widget--right { right: 24px; left: auto; }
.custom-fab-widget--left  { left: 24px;  right: auto; }

/* ── Base circular button ───────────────────────────────────────────────────── */
.fab-btn {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    text-decoration: none;
    outline: none;
    -webkit-appearance: none;
    box-sizing: border-box;
    color: #fff;
    -webkit-transition: -webkit-filter .22s ease, -webkit-transform .22s ease, box-shadow .22s ease;
    transition: filter .22s ease, transform .22s ease, box-shadow .22s ease;
}

.fab-btn:focus-visible {
    outline: 3px solid rgba(255, 255, 255, .7);
    outline-offset: 2px;
}

/* Override theme.css rule that hides all [aria-hidden="true"] elements */
#custom-fab-widget [aria-hidden="true"] {
    display: -webkit-flex !important;
    display: flex !important;
}

.fab-btn__icon {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    line-height: 1;
    pointer-events: none;
}

.fab-btn__icon svg { display: block; }

/* ── Main toggle button ─────────────────────────────────────────────────────── */
.fab-btn--main {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 56px;
    height: 56px;
    background: var(--fab-clr-main);
    box-shadow: 0 4px 14px rgba(0, 0, 0, .30);
    z-index: 1;
}

.fab-btn--main:hover,
.fab-btn--main:focus-visible {
    -webkit-filter: brightness(1.18);
    filter: brightness(1.18);
    -webkit-transform: scale(1.08);
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
}

.fab-btn--main:active {
    -webkit-transform: scale(.96);
    transform: scale(.96);
}

/* ── Main button icons ──────────────────────────────────────────────────────── */
.fab-btn--main .fab-icon {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
}

#custom-fab-widget .fab-btn--main .fab-icon--close { display: none !important; }

/* Icon swap via CSS only – no jQuery show/hide */
#custom-fab-widget.is-open .fab-btn--main .fab-icon--chat  { display: none !important; }
#custom-fab-widget.is-open .fab-btn--main .fab-icon--close {
    display: -webkit-flex !important;
    display: flex !important;
}

/* When Tawk chat is maximised – main FAB becomes the "close chat" button */
#custom-fab-widget.is-tawk-open {
    z-index: 2147483647; /* max int – must beat Tawk iframe z-index */
}
#custom-fab-widget.is-tawk-open .fab-btn--main .fab-icon--chat  { display: none !important; }
#custom-fab-widget.is-tawk-open .fab-btn--main .fab-icon--close {
    display: -webkit-flex !important;
    display: flex !important;
}

/* ── Sub-buttons container ──────────────────────────────────────────────────── */
.fab-sub-buttons {
    position: absolute;
    bottom: 66px; /* 56px main + 10px gap */
    left: 0;
    right: 0;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
    -webkit-align-items: center;
    align-items: center;
    gap: 10px;
    pointer-events: none;
}

/* ── Sub-buttons – collapsed state ─────────────────────────────────────────── */
.fab-btn--info,
.fab-btn--tawk,
.fab-btn--whatsapp {
    width: 48px;
    height: 48px;
    opacity: 0;
    -webkit-transform: translateY(8px) scale(.75);
    transform: translateY(8px) scale(.75);
    pointer-events: none;
    box-shadow: 0 3px 10px rgba(0, 0, 0, .22);
    -webkit-transition: opacity .22s ease, -webkit-transform .22s ease,
                        -webkit-filter .22s ease, box-shadow .22s ease;
    transition: opacity .22s ease, transform .22s ease,
                filter .22s ease, box-shadow .22s ease;
}

.fab-btn--info     { background: var(--fab-clr-info); }
.fab-btn--tawk     { background: var(--fab-clr-tawk); }
.fab-btn--whatsapp { background: var(--fab-clr-whatsapp); }

.fab-btn--info:hover,     .fab-btn--info:focus-visible,
.fab-btn--tawk:hover,     .fab-btn--tawk:focus-visible,
.fab-btn--whatsapp:hover, .fab-btn--whatsapp:focus-visible {
    -webkit-filter: brightness(1.2);
    filter: brightness(1.2);
    box-shadow: 0 5px 18px rgba(0, 0, 0, .30);
}

/* ── Open state – staggered slide-up ───────────────────────────────────────── */
.custom-fab-widget.is-open .fab-btn--whatsapp {
    opacity: 1;
    -webkit-transform: translateY(0) scale(1);
    transform: translateY(0) scale(1);
    pointer-events: auto;
    transition-delay: 0s;
}

.custom-fab-widget.is-open .fab-btn--tawk {
    opacity: 1;
    -webkit-transform: translateY(0) scale(1);
    transform: translateY(0) scale(1);
    pointer-events: auto;
    transition-delay: .06s;
}

.custom-fab-widget.is-open .fab-btn--info {
    opacity: 1;
    -webkit-transform: translateY(0) scale(1);
    transform: translateY(0) scale(1);
    pointer-events: auto;
    transition-delay: .12s;
}

/* ── Hide default Tawk.to launcher bubble ───────────────────────────────────── */
/*
 * Tawk creates several <iframe title="chat widget"> elements directly in the
 * main document body. #tawk-bubble-container lives INSIDE those iframes and
 * cannot be reached from parent-page CSS. Targeting the iframes themselves
 * works and applies before any JS runs → eliminates the initial flash.
 */
iframe[title="chat widget"] {
    display: none !important;
}

/* Revealed only when our FAB button explicitly opens the chat */
body.tawk-chat-open iframe[title="chat widget"] {
    display: block !important;
}

/* ── Mobile ─────────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .custom-fab-widget { bottom: 14px; }
    /*
     * Use left+calc(100vw) instead of right: Xpx.
     * When the page has horizontal overflow content, mobile browsers fix the
     * element relative to the wider layout-viewport, not the visual viewport.
     * 100vw always equals the visual viewport width, so this avoids the clipping.
     * 100vw - 14px margin - 50px button width = correct right-aligned position.
     */
    .custom-fab-widget--right { right: auto; left: calc(100vw - 64px); }
    .custom-fab-widget--left  { left: 14px; right: auto; }

    .fab-btn--main { width: 50px; height: 50px; }

    .fab-sub-buttons { bottom: 60px; }

    .fab-btn--info,
    .fab-btn--tawk,
    .fab-btn--whatsapp { width: 44px; height: 44px; }
}
