/* ShopFSI chat widget — floating bubble + expandable chat panel.
 * Scoped under .fsi-chat to keep specificity tight and avoid colliding
 * with storefront styles. All elements use class names, no element
 * selectors, so <img> defaults remain inline (see project CLAUDE.md).
 */

.fsi-chat {
    position: fixed;
    right: 30px;
    /* Bottom offset stacks three contributors so the chat clears whatever
       the storefront is parking against the viewport bottom:
         --fsi-chat-bottom-extra : the accessories strip / chip height,
                                   measured by the widget JS at runtime.
         --buybar-h              : the product-sticky-buybar height,
                                   maintained by the product page's own
                                   script (product.php). Stacked under
                                   the strip when both are visible.
         52px                    : base inset away from the viewport edge. */
    bottom: calc(var(--fsi-chat-bottom-extra, 0px) + var(--buybar-h, 0px) + 52px);
    z-index: 99998;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #e6e6e6;
    transition: bottom 0.18s ease;
}
/* Cart flyout takes over the right side and the user is in checkout
   focus — yield to it completely. JS toggles this class on .fsi-chat. */
.fsi-chat--hidden-by-cart { display: none !important; }

/* ────────── Bubble (collapsed state) */
.fsi-chat__bubble {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #1a1a1a;
    color: #fff;
    border: 1px solid #2a2a2a;
    box-shadow: 0 8px 20px rgba(0,0,0,0.35);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, background 0.15s ease;
    padding: 0;
}
.fsi-chat__bubble:hover     { background: #252525; transform: translateY(-2px); }
.fsi-chat__bubble:focus     { outline: 2px solid #555; outline-offset: 2px; }
.fsi-chat__bubble svg       { width: 26px; height: 26px; }
.fsi-chat__bubble[hidden]   { display: none; }

/* Tiny unread badge over the bubble */
.fsi-chat__badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: #d04848;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
    padding: 0 5px;
    box-sizing: border-box;
}
.fsi-chat__badge[hidden] { display: none; }

/* ────────── Panel (expanded state) */
.fsi-chat__panel {
    width: 400px;
    height: 640px;
    /* Shrink the panel cap by both bottom contributors so the bottom of
       the panel never extends past the strip + buybar stack. */
    max-height: calc(100vh - var(--fsi-chat-bottom-extra, 0px) - var(--buybar-h, 0px) - 36px);
    background: #0f0f0f;
    border: 1px solid #2a2a2a;
    border-radius: 12px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.55);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.fsi-chat__panel[hidden] { display: none; }

.fsi-chat__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: #1a1a1a;
    border-bottom: 1px solid #2a2a2a;
    flex-shrink: 0;
}
.fsi-chat__title    { font-size: 14px; font-weight: 600; letter-spacing: 0.02em; }
.fsi-chat__subtitle {
    font-size: 12px;
    color: #888;
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.fsi-chat__status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #facc15; /* default/offline: amber */
}
.fsi-chat__status-dot--online  { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18); }
.fsi-chat__status-dot--offline { background: #facc15; box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.16); }
.fsi-chat__close {
    background: transparent;
    border: none;
    color: #aaa;
    cursor: pointer;
    padding: 4px;
    margin: -4px;
    border-radius: 4px;
}
.fsi-chat__close:hover { color: #fff; background: #252525; }
.fsi-chat__close svg   { width: 18px; height: 18px; vertical-align: middle; }

/* ────────── Body (form / messages / done) — all share padding */
.fsi-chat__body {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    background: #0f0f0f;
}

/* ────────── Form view */
.fsi-chat__form-intro {
    font-size: 13px;
    color: #ccc;
    margin: 0 0 12px;
    line-height: 1.45;
    text-align: center;
}
.fsi-chat__field {
    margin-bottom: 10px;
}
.fsi-chat__label {
    display: block;
    font-size: 12px;
    color: #888;
    margin-bottom: 4px;
}
.fsi-chat__input,
.fsi-chat__textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 11px;
    background: #141414;
    border: 1px solid #2a2a2a;
    color: #e6e6e6;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
}
.fsi-chat__input:focus,
.fsi-chat__textarea:focus { border-color: #555; }
.fsi-chat__textarea { resize: vertical; min-height: 64px; }

.fsi-chat__btn {
    display: block;
    width: 100%;
    padding: 10px;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    color: #fff;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    margin-top: 6px;
}
.fsi-chat__btn:hover    { background: #353535; }
.fsi-chat__btn:disabled { opacity: 0.6; cursor: progress; }
.fsi-chat__btn--primary { background: #3b76d0; border-color: #4787e0; }
.fsi-chat__btn--primary:hover { background: #4787e0; }

.fsi-chat__error {
    color: #f0a0a0;
    font-size: 12px;
    margin-top: 6px;
    min-height: 16px;
}

/* ────────── Chat view */
.fsi-chat__messages {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.fsi-chat__msg {
    max-width: 84%;
    padding: 8px 11px;
    border-radius: 12px;
    font-size: 13.5px;
    line-height: 1.4;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.fsi-chat__msg--visitor {
    align-self: flex-end;
    background: #3b76d0;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.fsi-chat__msg--staff {
    align-self: flex-start;
    background: #1f1f1f;
    border: 1px solid #2a2a2a;
    color: #e6e6e6;
    border-bottom-left-radius: 4px;
}
.fsi-chat__msg--system {
    align-self: center;
    background: transparent;
    color: #888;
    font-size: 12px;
    font-style: italic;
    max-width: 100%;
    text-align: center;
}
.fsi-chat__msg-sender {
    font-size: 11px;
    color: #888;
    margin-bottom: 2px;
}
.fsi-chat__msg-img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin-top: 4px;
}

/* ────────── Composer (input bar at bottom of chat view)
   Box-style composer: textarea + the action icons live inside one rounded
   container so they read as a single widget. The textarea starts at one
   line and grows upward as the visitor types; align-items: flex-end pins
   the icons to the bottom-right corner regardless of textarea height. */
.fsi-chat__composer {
    border-top: 1px solid #2a2a2a;
    background: #141414;
    padding: 10px 10px 6px;
    flex-shrink: 0;
}
.fsi-chat__composer-box {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    border-radius: 8px;
    padding: 4px 4px 4px 12px;
}

.fsi-chat__composer-input {
    flex: 1;
    background: transparent;
    border: none;
    color: #e6e6e6;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    line-height: 1.4;
    outline: none;
    /* 1 line at rest (~20px text + 8px padding); JS auto-grows up to the
       cap, scrollbar appears past that. */
    padding: 4px 0;
    min-height: 28px;
    max-height: 144px;
}
.fsi-chat__composer-input::placeholder { color: #6a6a6a; }

.fsi-chat__composer-actions {
    display: flex;
    gap: 2px;
}
.fsi-chat__composer-upload,
.fsi-chat__composer-send {
    background: transparent;
    border: none;
    cursor: pointer;
    width: 30px;
    height: 30px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}
.fsi-chat__composer-upload          { color: #888; }
.fsi-chat__composer-upload:hover    { color: #ddd; background: #252525; }
.fsi-chat__composer-upload:disabled { opacity: 0.3; cursor: not-allowed; }
.fsi-chat__composer-send            { color: #6a9ee0; }
.fsi-chat__composer-send:hover      { color: #8ab4ee; background: #1f2c44; }
.fsi-chat__composer-send:disabled   { opacity: 0.4; cursor: not-allowed; }
.fsi-chat__composer-upload svg      { width: 16px; height: 16px; }
.fsi-chat__composer-send svg        { width: 16px; height: 16px; }
.fsi-chat__composer-upload-input    { display: none; }

/* ────────── Footer row (transcript request).
   Background matches the composer so the two read as one stacked unit
   without a divider between them. */
.fsi-chat__footer-bar {
    padding: 4px 12px 10px;
    background: #141414;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    font-size: 12px;
    color: #888;
}
.fsi-chat__link {
    background: transparent;
    border: none;
    color: #6a9ee0;
    cursor: pointer;
    font-size: 12px;
    padding: 0;
}
.fsi-chat__link:hover { color: #8ab4ee; text-decoration: underline; }

/* ────────── Done state */
.fsi-chat__done {
    text-align: center;
    padding: 20px 8px;
    color: #ccc;
}
.fsi-chat__done-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #2d4d2d;
    color: #a6e0a6;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
}
.fsi-chat__done-icon svg { width: 22px; height: 22px; }
.fsi-chat__done-title    { font-size: 15px; color: #fff; margin: 0 0 4px; }
.fsi-chat__done-text     { font-size: 13px; line-height: 1.5; margin: 0 0 14px; }

/* ────────── Mobile: full-screen panel */
@media (max-width: 480px) {
    .fsi-chat {
        right: 12px;
        /* Mobile bubble dodges the sticky chip + buybar the same way
           desktop does; the panel below is full-screen and ignores the
           offset entirely. */
        bottom: calc(var(--fsi-chat-bottom-extra, 0px) + var(--buybar-h, 0px) + 12px);
    }
    .fsi-chat__panel {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        border: none;
    }
}
