:root {
    --aichat-accent: #e58aa2;
    --aichat-accent-deep: #d77e97;
    --aichat-bg: #fdf6f7;
    --aichat-assistant: #fbe9ee;
    --aichat-user: #f5d4de;
    --aichat-text: #3d2f34;
    --aichat-muted: #a8959c;
    --aichat-soft: #f6dce4;
    --aichat-border: #f0dde4;
}

.aichat-widget {
    position: fixed;
    right: 20px;
    bottom: 20px;
    /* Fallback only — the real value comes from the "Widget Layer (z-index)"
       setting, applied inline on the element. Keep it BELOW the theme's
       popup/overlay layer. */
    z-index: 400;
    font-size: 14px;
    color: var(--aichat-text);
}

/*
 * Overlay etiquette: while a theme popup is open, the chat steps aside so it
 * can never block checkout/minicart actions. Covers Magento modals (body class,
 * no :has needed), the Luma minicart dropdown, and ScandiPWA-style overlays.
 */
body._has-modal .aichat-widget,
body:has(.modal-popup._show) .aichat-widget,
body:has(.minicart-wrapper.active) .aichat-widget,
body:has([class*="Overlay"][class*="_isVisible"]) .aichat-widget,
body:has([class*="Popup"][class*="_isVisible"]) .aichat-widget {
    visibility: hidden;
    pointer-events: none;
}

/* Launcher bubble */
.aichat-launcher {
    position: relative;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: var(--aichat-soft);
    color: var(--aichat-accent-deep);
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(213, 126, 151, .35);
    transition: transform .15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    overflow: hidden;
}
.aichat-launcher:hover { transform: scale(1.05); }
.aichat-launcher img { width: 100%; height: 100%; object-fit: cover; }
.aichat-launcher .aichat-spark { font-size: 24px; }
.aichat-open .aichat-launcher { display: none; }

/* Transparent-PNG logo: drop the pink circle and show the logo as-is. */
.aichat-launcher.has-logo {
    background: transparent;
    box-shadow: none;
}
.aichat-launcher.has-logo img {
    object-fit: contain;
    filter: drop-shadow(0 4px 12px rgba(213, 126, 151, .45));
}

/* Panel */
.aichat-panel {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 384px;
    max-width: calc(100vw - 40px);
    height: 580px;
    max-height: calc(100vh - 80px);
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 22px;
    overflow: hidden;
    box-shadow: 0 16px 48px rgba(120, 70, 85, .28);
    /* Closed state — animated open/close. */
    opacity: 0;
    visibility: hidden;
    transform: translateY(14px) scale(.97);
    transform-origin: bottom right;
    pointer-events: none;
    transition: opacity .2s ease, transform .24s cubic-bezier(.34, 1.4, .5, 1), visibility .24s;
}
.aichat-open .aichat-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header */
.aichat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--aichat-border);
    background: #fff;
}
.aichat-id { display: flex; align-items: center; gap: 11px; min-width: 0; }
.aichat-avatar {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--aichat-soft);
    color: var(--aichat-accent-deep);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: 18px;
}
.aichat-avatar img { width: 100%; height: 100%; object-fit: cover; }
.aichat-avatar.has-logo { background: transparent; }
.aichat-avatar.has-logo img { object-fit: contain; }
.aichat-id-text { display: flex; flex-direction: column; min-width: 0; }
.aichat-titlerow { display: flex; align-items: center; gap: 8px; }
.aichat-title {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: .2px;
}
.aichat-badge {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .5px;
    text-transform: uppercase;
    color: var(--aichat-accent-deep);
    background: var(--aichat-soft);
    border-radius: 999px;
    padding: 2px 7px;
}
.aichat-subtitle { font-size: 12px; color: var(--aichat-muted); margin-top: 2px; }
/* Identical circular buttons sized as comfortable touch targets (matches the 40px avatar). */
.aichat-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.aichat-actions button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    background: var(--aichat-bg);
    border: 1px solid var(--aichat-border);
    border-radius: 50%;
    color: var(--aichat-muted);
    cursor: pointer;
    padding: 0;
}
.aichat-actions button svg { width: 18px; height: 18px; }
.aichat-actions button:hover {
    color: var(--aichat-accent-deep);
    background: var(--aichat-soft);
    border-color: var(--aichat-accent);
}
.aichat-actions button:active { transform: scale(.94); }

/* Messages area */
.aichat-messages-wrap {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.aichat-messages {
    position: relative;
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    background: var(--aichat-bg);
}

/* "More below" indicator: a soft shadow + chevron shown while the customer is
   not at the bottom of the chat (e.g. reading a reply above tall product cards). */
.aichat-scroll-more {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 36px;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, .12));
    opacity: 0;
    transition: opacity .2s ease;
}
.aichat-scroll-more.is-visible { opacity: 1; }
/* Clickable only while the hint is shown — a hidden (opacity 0) hint must not
   leave an invisible button floating over the last message. */
.aichat-scroll-more.is-visible span { pointer-events: auto; }
.aichat-scroll-more span {
    pointer-events: none;
    cursor: pointer;
    width: 24px;
    height: 24px;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 1px solid var(--aichat-border);
    border-radius: 50%;
    color: var(--aichat-accent-deep);
    font-size: 12px;
    line-height: 1;
    box-shadow: 0 1px 5px rgba(0, 0, 0, .18);
}

.aichat-row { display: flex; align-items: flex-end; gap: 8px; margin-bottom: 14px; }
.aichat-row-assistant { justify-content: flex-start; }
.aichat-row-user { justify-content: flex-end; }
.aichat-row .aichat-avatar { width: 30px; height: 30px; font-size: 14px; }
.aichat-col { display: flex; flex-direction: column; max-width: 84%; min-width: 0; }
.aichat-row-user .aichat-col { align-items: flex-end; }

.aichat-msg {
    padding: 11px 14px;
    border-radius: 16px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: normal;
}
.aichat-msg-assistant {
    background: var(--aichat-assistant);
    border-bottom-left-radius: 5px;
}
.aichat-msg-user {
    background: var(--aichat-user);
    border-bottom-right-radius: 5px;
}
.aichat-msg a { color: var(--aichat-accent-deep); text-decoration: underline; }
.aichat-msg.aichat-error { background: #fdecea; color: #a12622; }
.aichat-meta { font-size: 11px; color: var(--aichat-muted); margin: 4px 4px 0; }
.aichat-ticks { color: var(--aichat-accent); }

/* Typing indicator */
.aichat-typing span {
    display: inline-block; width: 6px; height: 6px; margin: 0 1px;
    background: var(--aichat-accent); border-radius: 50%; animation: aichat-blink 1.2s infinite both;
}
.aichat-typing span:nth-child(2) { animation-delay: .2s; }
.aichat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes aichat-blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

/* Product cards */
.aichat-cards {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    padding-bottom: 4px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}
.aichat-cards::-webkit-scrollbar { height: 5px; }
.aichat-cards::-webkit-scrollbar-thumb { background: var(--aichat-soft); border-radius: 5px; }
.aichat-card {
    flex: 0 0 150px;
    width: 150px;
    scroll-snap-align: start;
    background: #fff;
    border: 1px solid var(--aichat-border);
    border-radius: 14px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    transition: box-shadow .15s ease;
}
.aichat-card:hover { box-shadow: 0 6px 16px rgba(213, 126, 151, .22); }
.aichat-card-main {
    display: flex;
    flex-direction: column;
    flex: 1;
    text-decoration: none;
    color: inherit;
}
.aichat-card-price { font-size: 12px; font-weight: 600; color: var(--aichat-accent-deep); margin-top: auto; margin-bottom: 0; }

.aichat-card-actions { display: flex; gap: 6px; margin-top: 9px; justify-content: flex-start; }
.aichat-card-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 1px;
    border: none;
    border-radius: 999px;
    padding: 6px 9px;
    cursor: pointer;
    line-height: 1;
    transition: background .15s ease;
}
.aichat-card-btn svg { display: block; }
.aichat-card-cart { background: var(--aichat-accent); color: #fff; }
.aichat-card-cart:hover { background: var(--aichat-accent-deep); }
.aichat-card-cart .aichat-plus { font-size: 13px; font-weight: 700; }
.aichat-card-cart:disabled { cursor: default; }
.aichat-card-cart.is-added { background: #1f7a33; }
.aichat-card-cart.is-error { background: #b3261e; }
.aichat-card-viewcart {
    display: block; margin-top: 7px; font-size: 12px; font-weight: 600;
    color: var(--aichat-accent-deep); text-decoration: underline; cursor: pointer;
}
.aichat-card-oldprice { margin-left: 6px; color: var(--aichat-muted); font-weight: 400; font-size: 0.92em; }
.aichat-card-discount {
    margin-left: 6px; background: var(--aichat-accent); color: #fff; border-radius: 8px;
    padding: 1px 6px; font-size: 11px; font-weight: 700; vertical-align: 1px;
}
.aichat-card-rating { display: block; margin-top: 3px; font-size: 11.5px; color: #b8860b; }
.aichat-wait-note { margin-top: 5px; font-size: 12px; color: var(--aichat-muted); font-style: italic; }
.aichat-cart-toast {
    margin: 8px 0; padding: 8px 12px; background: #eef8ef; border: 1px solid #cde8d0;
    border-radius: 10px; font-size: 12.5px; color: #1f7a33;
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.aichat-cart-toast .aichat-card-viewcart { margin-top: 0; white-space: nowrap; }
.aichat-chip-photo { border-style: dashed; }
.aichat-card-info { background: var(--aichat-soft); color: var(--aichat-accent-deep); }
.aichat-card-info:hover { background: var(--aichat-assistant); }
.aichat-card-img {
    display: block;
    width: 100%;
    height: 110px;
    border-radius: 10px;
    background: var(--aichat-bg) center/cover no-repeat;
    margin-bottom: 8px;
}
.aichat-card-noimg { background: var(--aichat-soft); }
.aichat-card-name { font-size: 12.5px; line-height: 1.35; margin-bottom: 6px; }
.aichat-card-tag {
    align-self: flex-start;
    margin-top: 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .5px;
    text-transform: uppercase;
    color: var(--aichat-accent-deep);
}

/* Unread-reply badge on the collapsed launcher */
.aichat-unread {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #d9534f;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    border-radius: 999px;
    border: 2px solid #fff;
}

/* Welcome teaser bubble (collapsed state, new session) */
.aichat-teaser {
    position: absolute;
    right: 0;
    bottom: 76px;
    width: 250px;
    max-width: calc(100vw - 60px);
    background: #fff;
    border: 1px solid var(--aichat-border);
    border-radius: 14px 14px 4px 14px;
    box-shadow: 0 6px 22px rgba(0, 0, 0, .16);
    padding: 12px 30px 12px 14px;
    z-index: 1;
    transform: translateY(6px);
    opacity: 0;
    transition: transform .25s ease, opacity .25s ease;
}
.aichat-teaser.is-in { transform: translateY(0); opacity: 1; }
.aichat-teaser-text {
    font-size: 13px;
    line-height: 1.45;
    color: #333;
    cursor: pointer;
}
.aichat-teaser-close {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--aichat-soft);
    color: #777;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
}
.aichat-teaser-close:hover { color: var(--aichat-accent-deep); }
.aichat-open .aichat-teaser { display: none !important; }

/* Photo consent notice (GDPR, shown once) */
.aichat-photo-consent {
    padding: 10px 12px;
    background: var(--aichat-soft);
    border-top: 1px solid var(--aichat-border);
}
.aichat-photo-consent p { margin: 0 0 8px; font-size: 12px; line-height: 1.45; color: #4a3b41; }
.aichat-photo-consent-actions { display: flex; gap: 8px; }
.aichat-photo-consent button {
    border: none; border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: 12.5px;
}
.aichat-consent-accept { background: var(--aichat-accent); color: #fff; }
.aichat-consent-accept:hover { background: var(--aichat-accent-deep); }
.aichat-consent-cancel { background: #fff; border: 1px solid var(--aichat-border) !important; color: #666; }

/* Photo attach (vision) */
.aichat-input .aichat-attach {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid var(--aichat-accent);
    border-radius: 50%;
    background: #fff;
    color: var(--aichat-accent);
    cursor: pointer;
    align-self: center;
}
.aichat-input .aichat-attach:hover {
    border-color: var(--aichat-accent-deep);
    color: var(--aichat-accent-deep);
    background: #fff;
}
.aichat-attach-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--aichat-soft);
    border-top: 1px solid var(--aichat-border);
}
.aichat-attach-preview img {
    height: 44px;
    width: 44px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--aichat-border);
}
.aichat-attach-preview button {
    border: none;
    background: #fff;
    border: 1px solid var(--aichat-border);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    line-height: 1;
    cursor: pointer;
    color: #777;
    font-size: 13px;
    padding: 0;
}
.aichat-msg-photo {
    display: block;
    max-width: 120px;
    max-height: 120px;
    border-radius: 10px;
    margin-bottom: 6px;
}

/* Side-by-side product comparison */
.aichat-compare { margin-top: 10px; background: #fff; border: 1px solid var(--aichat-border); border-radius: 12px; overflow: hidden; }
.aichat-compare-table { width: 100%; table-layout: fixed; border-collapse: collapse; }
.aichat-compare-table td {
    padding: 6px 8px; vertical-align: top; font-size: 11.5px; line-height: 1.35;
    border-left: 1px solid #f2eaee;
}
.aichat-compare-table td:first-child { border-left: none; }
.aichat-compare-table tr + tr td { border-top: 1px solid #f7f1f4; }
.aichat-cmp-img .aichat-cmp-img, .aichat-cmp-img span.aichat-cmp-img { display: block; }
.aichat-cmp-img { text-align: center; }
span.aichat-cmp-img {
    display: block; width: 100%; height: 64px; border-radius: 8px;
    background: var(--aichat-bg) center/cover no-repeat;
}
.aichat-cmp-name a { font-weight: 600; color: inherit; text-decoration: none; font-size: 11.5px; }
.aichat-cmp-name a:hover { color: var(--aichat-accent-deep); }
.aichat-cmp-price td, .aichat-cmp-price span { font-weight: 700; color: var(--aichat-accent-deep); }
.aichat-cmp-rating span { color: #b8860b; }
.aichat-cmp-stock .is-in { color: #3aa76d; font-weight: 600; }
.aichat-cmp-stock .is-out { color: #d9534f; font-weight: 600; }
.aichat-cmp-desc span { color: #777; font-size: 10.5px; }
.aichat-cmp-actions { display: flex; gap: 5px; }

/* Answer feedback (thumbs) */
.aichat-feedback { display: flex; gap: 6px; margin-top: 5px; }
.aichat-fb {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px; padding: 0;
    border: 1px solid var(--aichat-border); border-radius: 50%;
    background: #fff; color: #9a9a9a; cursor: pointer;
    transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.aichat-fb:hover { color: var(--aichat-accent-deep); border-color: var(--aichat-accent); }
.aichat-fb.is-active { color: #fff; background: var(--aichat-accent); border-color: var(--aichat-accent); }
.aichat-fb svg { display: block; }
.aichat-fb-comment { display: flex; gap: 6px; margin-top: 6px; }
.aichat-fb-comment input {
    flex: 1; padding: 6px 9px; border: 1px solid var(--aichat-border); border-radius: 8px;
    font-size: 12px; font-family: inherit;
}
.aichat-fb-comment button {
    border: none; border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 12px;
    background: var(--aichat-accent); color: #fff;
}
.aichat-fb-comment button:hover { background: var(--aichat-accent-deep); }
.aichat-fb-thanks { margin-top: 6px; font-size: 12px; color: var(--aichat-accent-deep); }

/* Chips (starter + inline follow-ups) */
.aichat-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.aichat-starters { margin-top: 14px; }
.aichat-chip {
    background: #fff;
    border: 1px solid var(--aichat-soft);
    color: var(--aichat-accent-deep);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background .15s ease;
}
.aichat-chip:hover { background: var(--aichat-assistant); }

/* Input */
.aichat-input {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--aichat-border);
    background: #fff;
}
.aichat-input textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--aichat-border);
    border-radius: 22px;
    padding: 11px 16px;
    font-family: inherit;
    font-size: 14px;
    max-height: 120px;
    outline: none;
    background: var(--aichat-bg);
}
.aichat-input textarea:focus { border-color: var(--aichat-accent); }
/* Failswitch: the placeholder must never wrap to a second line — long hints
   (e.g. context-aware ones with product names) are ellipsized instead. */
.aichat-input textarea::placeholder {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.aichat-input button[data-aichat-send] {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: var(--aichat-accent);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    transition: background .15s ease;
}
.aichat-input button[data-aichat-send]:hover { background: var(--aichat-accent-deep); }
.aichat-input button[data-aichat-send]:disabled { opacity: .5; cursor: default; }

/* Footer disclaimer */
.aichat-disclaimer {
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: center;
    padding: 8px 14px 12px;
    font-size: 11px;
    color: var(--aichat-muted);
    background: #fff;
    text-align: center;
}
.aichat-disclaimer svg { color: var(--aichat-accent); flex: 0 0 auto; }