/* Scoped styles for the Produp connector plugin. Everything is prefixed
   with .produp- to avoid clobbering the host theme. Component-level
   custom properties get set inline from the per-shop branding blob:
   --produp-accent (branding.bubbleColor, legacy primaryColor) themes the
   FAB background, user bubbles, focus rings and card hover; --produp-icon
   (branding.iconColor) colors the launcher glyph. Both have fallbacks so
   an un-themed shop still renders. */

.produp-typeahead {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 9999;
    margin-top: 4px;
    background: #fff;
    border: 1px solid #e2e2e2;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    max-height: 60vh;
    overflow-y: auto;
}

.produp-typeahead__row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid #f1f1f1;
}
.produp-typeahead__row:last-child { border-bottom: none; }
.produp-typeahead__row:hover { background: #f7f7f7; }

.produp-typeahead__row img {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

.produp-typeahead__meta { display: flex; flex-direction: column; min-width: 0; }
.produp-typeahead__name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.produp-typeahead__price {
    font-size: 0.85em;
    color: #555;
}
.produp-typeahead__price del { opacity: 0.5; margin-right: 4px; }

/* ----------------------- Chat: FAB + Panel ---------------------------- */

.produp-fab {
    --produp-accent: #111;
    --produp-icon: #fff;
    /* Version stamp read by the style self-heal in produp.js (#321).
       Speed optimizers aggregate this file into their own per-page
       bundles, so after a plugin update some pages keep serving a stale
       copy — markup rendered by newer JS then has no rules. MUST match
       REQUIRED_CSS_VERSION in produp.js and the plugin version
       (pinned by the version-sync test in plugins/tests/). */
    --produp-css-version: "0.10.0";
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 56px;
    height: 56px;
    /* Full button reset: theme button styles apply to this element and
       their em-based values explode at our 24px font-size. Flatsome's
       reset (padding: 0 1.2em; min-height: 2.5em; margin-right: 1em)
       left a 56px border-box button with 57.6px of horizontal padding —
       a zero-width content box, so the flex-shrunk icon svg computed to
       0px wide and the launcher rendered as a blank circle (#321). */
    padding: 0;
    margin: 0;
    min-width: 0;
    min-height: 0;
    max-width: none;
    border-radius: 50%;
    border: none;
    background: var(--produp-accent);
    color: var(--produp-icon);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    z-index: 9998;
    transition: transform 120ms ease, box-shadow 120ms ease;
    /* Center the launcher glyph (SVG or emoji fallback). */
    display: flex;
    align-items: center;
    justify-content: center;
}
/* Explicit size + no shrink: the width/height presentation attributes
   lose to any theme CSS that targets svg, and a squeezed flex container
   would otherwise shrink the icon to nothing (#321). */
.produp-fab svg {
    display: block;
    width: 26px;
    height: 26px;
    flex-shrink: 0;
}
.produp-fab:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25); }
.produp-fab:focus-visible {
    outline: 2px solid var(--produp-accent);
    outline-offset: 3px;
}

.produp-chat {
    --produp-accent: #111;
    position: fixed;
    right: 20px;
    bottom: 88px;
    width: min(380px, calc(100vw - 40px));
    height: min(560px, calc(100vh - 120px));
    background: #fff;
    color: #111;
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    font-size: 14px;
    line-height: 1.45;
}

.produp-chat__header {
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.produp-chat__header strong { font-size: 14px; }

.produp-chat__close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: #888;
    padding: 4px 8px;
    line-height: 1;
    min-width: 32px;
    min-height: 32px;
}
.produp-chat__close:hover { color: #111; }
.produp-chat__close:focus-visible {
    outline: 2px solid var(--produp-accent);
    outline-offset: 2px;
    border-radius: 4px;
}

.produp-chat__log {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.produp-chat__sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.produp-chat__bubble {
    padding: 8px 12px;
    border-radius: 12px;
    max-width: 85%;
    line-height: 1.45;
    word-wrap: break-word;
}
/* Tighten the visual rhythm of LLM markdown inside a bubble — without
   these resets the host theme often gives paragraphs and lists 1em of
   top/bottom margin which dwarfs the bubble's own padding. */
.produp-chat__bubble .produp-chat__p {
    margin: 0;
}
.produp-chat__bubble .produp-chat__p + .produp-chat__p,
.produp-chat__bubble .produp-chat__p + .produp-chat__list,
.produp-chat__bubble .produp-chat__list + .produp-chat__p {
    margin-top: 8px;
}
.produp-chat__bubble .produp-chat__list {
    margin: 4px 0 0;
    padding-left: 18px;
}
.produp-chat__bubble .produp-chat__list li {
    margin: 2px 0;
}
/* Comparison tables the agent writes in markdown. The wrapper scrolls
   horizontally so wide tables don't stretch the (narrow) bubble. */
.produp-chat__table-wrap {
    margin-top: 8px;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.produp-chat__table {
    border-collapse: collapse;
    font-size: 0.92em;
    min-width: 100%;
}
.produp-chat__table th,
.produp-chat__table td {
    border: 1px solid #e0e0e0;
    padding: 4px 8px;
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}
.produp-chat__table th {
    background: #f5f5f5;
    font-weight: 600;
}
.produp-chat__bubble strong { font-weight: 600; }
.produp-chat__bubble--user {
    background: var(--produp-accent);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.produp-chat__bubble--assistant {
    background: #f1f1f1;
    color: #111;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.produp-chat__bubble--greeting { font-style: italic; opacity: 0.85; }
.produp-chat__bubble--error {
    background: #fff4f4;
    color: #8a1f1f;
    border: 1px solid #f3c4c4;
}

/* Clickable starter prompts under the greeting (#318). Wrapping pills,
   left-aligned with the assistant bubbles, outlined so they read as
   tappable affordances rather than sent messages. The accent themes the
   hover/focus state to match the rest of the widget. */
.produp-chat__suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-self: flex-start;
    margin-top: 4px;
}
.produp-chat__suggestion {
    font: inherit;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 16px;
    border: 1px solid #d8d8d8;
    background: #fff;
    color: #222;
    line-height: 1.3;
    transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}
.produp-chat__suggestion:hover {
    border-color: var(--produp-accent);
    color: var(--produp-accent);
}
.produp-chat__suggestion:focus-visible {
    outline: 2px solid var(--produp-accent);
    outline-offset: 2px;
}

.produp-chat__assistant {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
}

/* Typing indicator: three pulsing dots while the LLM is composing
   its first token. Replaced by the "picking products" badge once the
   agent starts emitting the displayProductPicks tool call. */
.produp-chat__status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #f1f1f1;
    border-radius: 12px;
    color: #666;
    font-size: 12px;
}
.produp-chat__dots {
    display: inline-flex;
    gap: 3px;
}
.produp-chat__dots span {
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    animation: produp-pulse 1.2s infinite ease-in-out;
}
.produp-chat__dots span:nth-child(2) { animation-delay: 0.15s; }
.produp-chat__dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes produp-pulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}
.produp-chat__picking {
    font-weight: 500;
    color: var(--produp-accent);
    font-size: 12px;
    padding: 2px 4px;
    margin-bottom: 2px;
}

.produp-chat__cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.produp-chat__card {
    display: flex;
    gap: 10px;
    padding: 10px;
    background: #fff;
    border: 1px solid #e6e6e6;
    border-radius: 10px;
    text-decoration: none;
    color: inherit;
    transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}
.produp-chat__card:hover {
    border-color: var(--produp-accent);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    transform: translateY(-1px);
}
.produp-chat__card:focus-visible {
    outline: 2px solid var(--produp-accent);
    outline-offset: 2px;
}

.produp-chat__card-img {
    width: 64px;
    height: 64px;
    border-radius: 8px;
    background: #f5f5f5;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: 11px;
    font-weight: 500;
    color: #999;
    letter-spacing: 0.5px;
}
.produp-chat__card-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.produp-chat__card-body {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.produp-chat__card-name {
    font-weight: 600;
    font-size: 13px;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.produp-chat__card-reason {
    font-size: 12px;
    color: #444;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.produp-chat__card-meta {
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    font-size: 11px;
    color: #666;
}
.produp-chat__card-brand {
    text-transform: uppercase;
    letter-spacing: 0.04em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.produp-chat__card-price {
    font-weight: 600;
    color: #111;
    white-space: nowrap;
}
.produp-chat__card-price del { opacity: 0.5; margin-right: 4px; font-weight: 400; }

/* Skeleton state while the resolve round-trip is in flight. */
.produp-chat__card--skeleton {
    background: linear-gradient(90deg, #f3f3f3 25%, #ececec 50%, #f3f3f3 75%);
    background-size: 200% 100%;
    animation: produp-shimmer 1.4s infinite;
    border-color: transparent;
    min-height: 84px;
}
@keyframes produp-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.produp-chat__form {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}
.produp-chat__form input {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font: inherit;
    background: #fff;
    color: #111;
}
.produp-chat__form input:focus-visible {
    outline: 2px solid var(--produp-accent);
    outline-offset: 1px;
    border-color: var(--produp-accent);
}
.produp-chat__form button {
    padding: 9px 14px;
    background: var(--produp-accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.produp-chat__form button:focus-visible {
    outline: 2px solid var(--produp-accent);
    outline-offset: 2px;
}
.produp-chat__form button:disabled,
.produp-chat__form input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Provenance + disclaimer line under the input. #6b6b6b keeps ≥4.5:1
   contrast on white — the text is small, so AA large-text leeway
   doesn't apply. */
.produp-chat__footer {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 0 12px 10px;
    font-size: 11px;
    line-height: 1.4;
    color: #6b6b6b;
    text-align: center;
    flex-shrink: 0;
}
.produp-chat__footer a {
    color: inherit;
    font-weight: 600;
    text-decoration: none;
}
.produp-chat__footer a:hover,
.produp-chat__footer a:focus-visible {
    text-decoration: underline;
}
.produp-chat__footer a:focus-visible {
    outline: 2px solid var(--produp-accent);
    outline-offset: 2px;
    border-radius: 2px;
}

/* Mobile: fullscreen sheet. The desktop fixed-corner panel is unusable
   at phone widths — most storefront traffic lives there. */
@media (max-width: 600px) {
    .produp-chat {
        right: 0;
        bottom: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100vh;
        height: 100dvh; /* iOS Safari URL-bar collapse */
        max-height: 100dvh;
        border-radius: 0;
    }
    .produp-fab {
        right: 16px;
        bottom: 16px;
    }
    /* Touch targets must clear 44×44 on mobile (WCAG 2.5.5). */
    .produp-chat__close,
    .produp-chat__form button {
        min-width: 44px;
        min-height: 44px;
    }
    /* The footer is the bottom-most element now, so it (not the form)
       absorbs the home-indicator safe area. */
    .produp-chat__footer {
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }
}

@media (prefers-reduced-motion: reduce) {
    .produp-fab,
    .produp-chat__card,
    .produp-chat__dots span {
        transition: none;
        animation: none;
    }
    /* Animation off leaves the gradient stuck at its starting position
       (a dark band). Flatten to a plain block instead. */
    .produp-chat__card--skeleton {
        background: #f3f3f3;
        animation: none;
    }
}
