/* SB Support Chat widget. Self-contained styles: nothing inherits from the
   theme, so the widget looks identical on any storefront. Accent colour comes
   inline from settings (JS), everything else is fixed. */

#sbchat-root {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 99999;
    /* Match the site's Futura Light BT (already loaded by the theme); the
       name varies by foundry/build, so several aliases are tried before
       falling back to the system stack. CSS skips unknown families for free. */
    font-family: "Futura Lt BT", "Futura Light BT", "FuturaLightBT", "Futura Light", "futura-lt-bt", Futura,
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.45;
}

/* Theme-proofing: storefront themes style button/textarea aggressively (their
   borders, gradients, shadows swallow our controls). The #id prefix outranks
   any theme class rule without resorting to !important. */
#sbchat-root button,
#sbchat-root textarea {
    margin: 0;
    font-family: inherit;
    background-image: none;
    text-shadow: none;
    text-transform: none;
    letter-spacing: normal;
}

/* -- bubble ---------------------------------------------------------------- */
.sbchat-bwrap { position: relative; display: inline-block; }

.sbchat-bubble {
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .22);
    transition: transform .15s ease, width .25s ease, height .25s ease, opacity .25s ease;
}
.sbchat-bubble:hover { transform: scale(1.06); }
#sbchat-root .sbchat-bubble svg {
    display: block;
    width: 26px;
    height: 26px;
    stroke: #fff;
    fill: none;
    transition: width .25s ease, height .25s ease;
}

/* Icon swap with the chat state: chat glyph when closed, chevron-down when
   open so it reads as "click to lower the chat". */
#sbchat-root .sbchat-bubble .sbchat-ico-down { display: none; }
#sbchat-root.is-open .sbchat-bubble .sbchat-ico-chat { display: none; }
#sbchat-root.is-open .sbchat-bubble .sbchat-ico-down { display: block; }

/* Dismiss X: floats just OUTSIDE the bubble's top-right edge (not on it),
   bubble-coloured (JS sets the accent), shown on hover while the chat is
   closed. Touch devices have no hover, so there it is always visible. */
#sbchat-root .sbchat-bubble__x {
    position: absolute;
    top: -14px;
    right: -14px;
    width: 20px;
    height: 20px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #6b7280; /* fallback; JS overrides with the accent colour */
    color: #fff;
    font-size: 13px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
    opacity: 0;
    transform: scale(.6);
    /* The .5s delay only applies on hover-OUT (transition back to hidden):
       a mouse that slips off the bubble on its way to the X gets a grace
       period before the X fades, and it stays clickable the whole time. */
    transition: opacity .15s ease .5s, transform .15s ease .5s;
}
@media (hover: none) {
    #sbchat-root .sbchat-bubble__x { opacity: 1; transform: none; }
}
/* NB: every state rule below carries the #sbchat-root prefix because the BASE
   rules do; an unprefixed state rule (class-only) loses to an ID-prefixed base
   and silently never applies - that bug shipped once (invisible dismiss X). */
#sbchat-root .sbchat-bwrap:hover .sbchat-bubble__x { opacity: 1; transform: none; transition-delay: 0s; }
#sbchat-root.is-open .sbchat-bubble__x,
#sbchat-root .sbchat-bwrap.is-mini .sbchat-bubble__x { display: none; }

/* Mini = dismissed: shrinks into the corner, semi-transparent, click restores. */
#sbchat-root .sbchat-bwrap.is-mini .sbchat-bubble {
    width: 30px;
    height: 30px;
    opacity: .55;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}
#sbchat-root .sbchat-bwrap.is-mini .sbchat-bubble:hover { opacity: .95; transform: scale(1.1); }
#sbchat-root .sbchat-bwrap.is-mini .sbchat-bubble svg { width: 16px; height: 16px; }

/* -- teaser nudge ----------------------------------------------------------- */
/* Small peek bubble above the launcher. Hidden by default via opacity+visibility
   (not display) so the .is-on class can fade/slide it in; a speech-bubble tail
   points down to the chat icon. */
.sbchat-teaser {
    position: absolute;
    right: 0;
    bottom: 70px; /* clears the 56px bubble */
    width: max-content;
    max-width: 260px;
    background: #fff;
    color: #1f2937;
    border-radius: 14px;
    box-shadow: 0 6px 22px rgba(0, 0, 0, .16);
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px) scale(.96);
    transform-origin: 100% 100%;
    transition: opacity .25s ease, transform .25s ease, visibility .25s;
    pointer-events: none;
}
.sbchat-teaser.is-on {
    opacity: 1;
    visibility: visible;
    transform: none;
    pointer-events: auto;
}
/* Speech-bubble tail: a small rotated square sitting under the bubble's right side. */
.sbchat-teaser::after {
    content: '';
    position: absolute;
    right: 18px;
    bottom: -5px;
    width: 12px;
    height: 12px;
    background: #fff;
    transform: rotate(45deg);
    box-shadow: 3px 3px 6px rgba(0, 0, 0, .05);
}
#sbchat-root .sbchat-teaser__text {
    display: block;
    border: 0;
    background: none;
    color: inherit;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.4;
    text-align: left;
    padding: 11px 30px 11px 14px; /* right padding leaves room for the X */
    cursor: pointer;
}
#sbchat-root .sbchat-teaser__x {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 18px;
    height: 18px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: #9ca3af;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
#sbchat-root .sbchat-teaser__x:hover { color: #4b5563; }
/* Belt-and-braces: never overlap the open chat or a dismissed bubble. */
#sbchat-root.is-open .sbchat-teaser,
#sbchat-root .sbchat-bwrap.is-mini .sbchat-teaser { display: none; }

/* -- panel ------------------------------------------------------------------ */
/* Open/closed is class-driven: an explicit display rule (ours or the theme's)
   outranks the UA [hidden] style, so the hidden attribute was unreliable. */
.sbchat-panel {
    position: absolute;
    right: 0;
    bottom: 70px;
    width: 350px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 110px);
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
    display: none;
    flex-direction: column;
    overflow: hidden;
}
/* Pop out of the support bubble: scale up from the bottom-right corner where
   the bubble sits. Keyframes (not transition) because display:none can't
   transition. Closing plays the reverse and 'forwards' holds the last frame
   until JS drops the classes. */
.sbchat-panel.is-open {
    display: flex;
    transform-origin: 100% 100%;
    animation: sbchat-pop .32s cubic-bezier(.2, .9, .3, 1.12);
}
.sbchat-panel.is-open.is-closing {
    animation: sbchat-pop-out .22s ease-in forwards;
}
@keyframes sbchat-pop {
    from { opacity: 0; transform: scale(.55) translateY(12px); }
    to   { opacity: 1; transform: none; }
}
@keyframes sbchat-pop-out {
    from { opacity: 1; transform: none; }
    to   { opacity: 0; transform: scale(.55) translateY(12px); }
}

.sbchat-head {
    color: #fff;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}
.sbchat-head__title { font-weight: 600; flex: 1 1 auto; }
.sbchat-head__test {
    background: #fbbf24;
    color: #422006;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    letter-spacing: .04em;
}
.sbchat-head__close {
    background: none;
    border: 0;
    color: #fff;
    line-height: 1;
    cursor: pointer;
    opacity: .85;
    padding: 0 2px;
    display: flex;
    align-items: center;
}
.sbchat-head__close:hover { opacity: 1; }
#sbchat-root .sbchat-head__close svg { display: block; stroke: #fff; fill: none; }

/* -- messages ---------------------------------------------------------------- */
.sbchat-msgs {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f6f7f9;
}
.sbchat-msg {
    max-width: 82%;
    padding: 9px 12px;
    border-radius: 12px;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.sbchat-msg--user {
    align-self: flex-end;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.sbchat-msg--bot {
    align-self: flex-start;
    background: #fff;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
    white-space: normal;
}
.sbchat-msg--bot a { color: inherit; text-decoration: underline; }
.sbchat-msg--sys {
    align-self: center;
    background: #fef3c7;
    color: #78350f;
    font-size: 13.5px;
    border-radius: 8px;
}

/* typing dots */
.sbchat-typing { display: flex; gap: 4px; padding: 12px 14px; }
.sbchat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9ca3af;
    animation: sbchat-blink 1.2s infinite both;
}
.sbchat-typing span:nth-child(2) { animation-delay: .2s; }
.sbchat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes sbchat-blink {
    0%, 80%, 100% { opacity: .25; }
    40% { opacity: 1; }
}

/* -- turnstile holder -------------------------------------------------------- */
.sbchat-ts { display: none; padding: 6px 14px; background: #f6f7f9; flex: 0 0 auto; }
.sbchat-ts.is-on { display: block; }

/* -- bot name label ----------------------------------------------------------- */
.sbchat-msg__name {
    /* Same size and family as the chat body so the identity row reads as part
       of the conversation, just quieter through colour. */
    font-size: 16px;
    color: #6b7280;
    margin: 2px 0 -4px 6px;
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 6px;
}
#sbchat-root .sbchat-msg__ava {
    display: block;
    width: 30px;
    height: 30px;
    /* No circle clip and no cropping: transparent PNG mascots show whole,
       exactly as drawn. 'contain' keeps any aspect ratio undistorted. */
    border-radius: 0;
    object-fit: contain;
    background: none;
}

/* -- input ------------------------------------------------------------------- */
/* align-items:flex-end keeps the send button pinned to the bottom while the
   textarea grows upward as the customer types. */
.sbchat-form {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid #eceef1;
    background: #fff;
    flex: 0 0 auto;
    align-items: flex-end;
}
#sbchat-root .sbchat-input {
    flex: 1 1 auto;
    border: 1px solid #e3e6ea;
    border-radius: 16px;
    padding: 10px 14px;
    /* 16px also stops iOS Safari from auto-zooming the page on focus. */
    font-size: 16px;
    line-height: 1.4;
    font-family: inherit;
    outline: none;
    resize: none;
    overflow-y: auto;
    min-height: 44px;
    max-height: 110px;
    background: #fff;
    color: #1f2937;
    box-shadow: none;
}
#sbchat-root .sbchat-input:focus {
    border-color: #c3c9d1;
    outline: none;
    box-shadow: none;
}
#sbchat-root .sbchat-send {
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    margin-bottom: 2px;
}
#sbchat-root .sbchat-send svg {
    display: block;
    width: 18px;
    height: 18px;
    stroke: #fff;
    fill: none;
}
#sbchat-root .sbchat-send:disabled { opacity: .55; cursor: default; }

/* -- mobile ------------------------------------------------------------------ */
@media (max-width: 480px) {
    /* On a phone the open chat takes the whole screen (the standard chat-app
       pattern): a floating panel gets shoved off-screen when the keyboard
       opens. JS refines the height live via the VisualViewport API, so the
       panel SHRINKS above the keyboard instead of being pushed up; header and
       composer are always both visible. */
    .sbchat-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: auto;
        width: auto;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
    }
    /* The bubble has no job while the chat covers the screen. */
    #sbchat-root.is-open .sbchat-bwrap { display: none; }

    /* Keep the nudge from running past a narrow screen's edge. */
    .sbchat-teaser { max-width: calc(100vw - 70px); }

    /* Dismissed bubble on a phone: truly tiny and see-through in the corner. */
    #sbchat-root .sbchat-bwrap.is-mini .sbchat-bubble {
        width: 24px;
        height: 24px;
        opacity: .4;
    }
    #sbchat-root .sbchat-bwrap.is-mini .sbchat-bubble svg {
        width: 13px;
        height: 13px;
    }
}
