.ai-assistant-launcher {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 1060;
    width: 68px;
    height: 68px;
    padding: 0;
    overflow: hidden;
    border: 3px solid #ffd400;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 25%, #4f91ff, #0b3d91 70%);
    color: #fff;
    box-shadow: 0 10px 24px rgba(11, 61, 145, .45), 0 0 0 4px rgba(255, 212, 0, .16);
    transition: transform .2s ease, box-shadow .2s ease;
    animation: ai-assistant-greeting 5s ease-in-out infinite;
    /* Keep the launcher pinned to the layout viewport on iOS Safari. */
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.ai-assistant-launcher img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    object-position: center;
    transform: scale(1.05);
}

.ai-assistant-launcher:hover,
.ai-assistant-launcher:focus-visible {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 14px 30px rgba(11, 61, 145, .55), 0 0 0 5px rgba(255, 212, 0, .25);
    animation-play-state: paused;
}

.ai-assistant-launcher:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 3px;
}

@keyframes ai-assistant-greeting {
    0%, 82%, 100% { transform: translateY(0) rotate(0); }
    86% { transform: translateY(-3px) rotate(-3deg); }
    90% { transform: translateY(-4px) rotate(3deg); }
    94% { transform: translateY(-2px) rotate(-2deg); }
}

.ai-assistant-panel {
    position: fixed;
    right: 1.25rem;
    bottom: 5.5rem;
    z-index: 1060;
    width: min(380px, calc(100vw - 2rem));
    max-height: min(620px, calc(100vh - 7rem));
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #d9e2f1;
    border-radius: 16px;
    background: #fff;
    /* Avoid iOS visual-viewport drift that leaves the panel mid-screen. */
    transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.ai-assistant-panel.is-open { display: flex; }
.ai-assistant-header { padding: 1rem; background: #0b5ed7; color: #fff; }
.ai-assistant-header-actions { flex-shrink: 0; }
.ai-assistant-lang {
    display: inline-flex;
    border: 1px solid rgba(255, 255, 255, .55);
    border-radius: .4rem;
    overflow: hidden;
}
.ai-assistant-lang__btn {
    appearance: none;
    border: 0;
    background: transparent;
    color: #fff;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .02em;
    line-height: 1;
    padding: .35rem .45rem;
    cursor: pointer;
}
.ai-assistant-lang__btn + .ai-assistant-lang__btn {
    border-left: 1px solid rgba(255, 255, 255, .45);
}
.ai-assistant-lang__btn[aria-pressed="true"] {
    background: #fff;
    color: #0b5ed7;
}
.ai-assistant-close {
    font-weight: 700;
    color: #0b5ed7 !important;
    border: none;
}
.ai-assistant-close:hover,
.ai-assistant-close:focus-visible {
    background: #fff;
    color: #084298 !important;
}
/* min-height lets the thread shrink so it always keeps its own scrollbar. */
.ai-assistant-messages { flex: 1 1 auto; min-height: 6rem; overflow-y: auto; padding: 1rem; -webkit-overflow-scrolling: touch; }
.ai-assistant-message { margin-bottom: .75rem; padding: .75rem; border-radius: 12px; background: #f1f5f9; white-space: pre-wrap; }
.ai-assistant-message.is-user { margin-left: 2rem; background: #dbeafe; }
/* Capped so a long list of buttons can never push the conversation out of view. */
.ai-assistant-actions {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    gap: .5rem;
    max-height: 8.5rem;
    overflow-y: auto;
    padding: 0 .75rem .75rem;
}
.ai-assistant-promotion-card {
    width: 100%;
    margin-bottom: .6rem;
    padding: .65rem;
    border: 1px solid #f2b344;
    border-left: 4px solid #ff9800;
    border-radius: .55rem;
    background: #fff8e8;
    color: #5b3a00;
}
.ai-assistant-promotion-card__detail { margin: .35rem 0 .55rem; font-size: .84rem; line-height: 1.35; }
.ai-assistant-promotion-card__validity { margin: -.25rem 0 .55rem; color: #8a5a00; font-size: .75rem; }
.ai-assistant-promotion-card .btn { margin-right: .35rem; }
.ai-assistant-promotion-more { display: inline-block; margin-bottom: .75rem; font-size: .85rem; font-weight: 600; }
.ai-assistant-whatsapp { margin: 0 .75rem .75rem; padding: .6rem .75rem; border-radius: .5rem; background: #25d366; color: #fff; font-weight: 600; text-align: center; text-decoration: none; }
.ai-assistant-whatsapp:hover, .ai-assistant-whatsapp:focus { color: #fff; background: #1ebe57; }
.ai-assistant-form { display: flex; gap: .5rem; padding: .75rem; border-top: 1px solid #e5e7eb; }
.ai-assistant-form textarea { min-height: 42px; resize: none; }

@keyframes ai-assistant-product-confirmed {
    0% { box-shadow: 0 0 0 0 rgba(255, 212, 0, .9); transform: scale(1); }
    35% { box-shadow: 0 0 0 12px rgba(255, 212, 0, .18); transform: scale(1.025); }
    100% { box-shadow: 0 0 0 0 rgba(255, 212, 0, 0); transform: scale(1); }
}

.producto-card.ai-assistant-product-added {
    outline: 3px solid #ffd400;
    outline-offset: 3px;
    background: #fffbe8;
    animation: ai-assistant-product-confirmed 1.2s ease-in-out 2;
}

@media (max-width: 768px) {
    .ai-assistant-launcher {
        right: max(.75rem, env(safe-area-inset-right));
        bottom: max(.75rem, env(safe-area-inset-bottom));
        width: 60px;
        height: 60px;
    }
    .ai-assistant-panel {
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: none;
        max-height: min(72dvh, calc(100dvh - env(safe-area-inset-top, 0px) - 4.5rem));
        border-radius: 16px 16px 0 0;
        border-bottom: 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .ai-assistant-header { padding: .75rem 1rem; }
    .ai-assistant-messages { padding: .75rem; font-size: .92rem; }
    .ai-assistant-message { margin-bottom: .5rem; padding: .65rem; }
    .ai-assistant-actions { padding: 0 .75rem .65rem; }
    .ai-assistant-actions .btn { width: 100%; }
    .ai-assistant-form { padding: .65rem .75rem; }
    /* While open on phones/tablets, keep page scroll usable behind the sheet. */
    body.ai-assistant-open {
        overscroll-behavior: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ai-assistant-launcher { animation: none; transition: none; }
}
