/* Tara — chatbot flotante */

:root {
    --tara-fab-size: 62px;
    --tara-fab-gap: 14px;
    --tara-edge: 24px;
    --tara-safe-bottom: env(safe-area-inset-bottom, 0px);
    --tara-safe-top: env(safe-area-inset-top, 0px);
    --tara-stack-offset: calc(var(--tara-edge) + var(--tara-fab-size) + var(--tara-fab-gap));
}

.tara-widget {
    position: fixed;
    bottom: var(--tara-stack-offset);
    right: var(--tara-edge);
    z-index: 99998;
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
}

.tara-widget.tara-panel-open .tara-fab-chip,
.tara-widget.tara-panel-open .tara-teaser {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.tara-fab {
    position: relative;
    width: 62px;
    height: 62px;
    border: none;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
    color: #fff;
    box-shadow: 0 8px 28px rgba(37, 99, 235, 0.45);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    animation: taraFabPulse 2.5s ease-out infinite;
}

@keyframes taraFabPulse {
    0% { box-shadow: 0 8px 28px rgba(37, 99, 235, 0.45), 0 0 0 0 rgba(124, 58, 237, 0.4); }
    70% { box-shadow: 0 8px 28px rgba(37, 99, 235, 0.45), 0 0 0 14px rgba(124, 58, 237, 0); }
    100% { box-shadow: 0 8px 28px rgba(37, 99, 235, 0.45), 0 0 0 0 rgba(124, 58, 237, 0); }
}

.tara-fab-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 0.68rem;
    font-weight: 800;
    line-height: 20px;
    text-align: center;
    border: 2px solid #fff;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.45);
    z-index: 2;
}

.tara-fab-badge[hidden] {
    display: none !important;
}

.tara-fab-chip {
    position: absolute;
    right: 74px;
    bottom: 50%;
    transform: translateY(50%);
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
    padding: 0.5rem 0.8rem;
    border-radius: 16px;
    background: #fff;
    color: #1e3a8a;
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.25;
    white-space: nowrap;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
    border: 1px solid rgba(37, 99, 235, 0.15);
    pointer-events: none;
    transition: opacity 0.2s, visibility 0.2s;
    animation: taraChipFloat 3s ease-in-out infinite;
}

.tara-fab-chip-line {
    display: block;
}

.tara-fab-chip-line:first-child {
    font-size: 0.72rem;
    font-weight: 800;
    color: #4338ca;
}

.tara-fab-chip::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    width: 10px;
    height: 10px;
    background: #fff;
    border-right: 1px solid rgba(37, 99, 235, 0.12);
    border-bottom: 1px solid rgba(37, 99, 235, 0.12);
    transform: translateY(-50%) rotate(-45deg);
}

@keyframes taraChipFloat {
    0%, 100% { transform: translateY(50%); }
    50% { transform: translateY(calc(50% - 5px)); }
}

.tara-widget.tara-widget--with-cart {
    bottom: calc(var(--tara-edge) + 60px + var(--tara-fab-gap));
    right: var(--tara-edge);
}

.tara-backdrop {
    display: none;
}

.tara-fab:hover {
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 12px 32px rgba(37, 99, 235, 0.55);
    animation: none;
}

.tara-widget.tara-panel-open .tara-fab {
    animation: none;
}

.tara-widget.tara-has-unread .tara-fab {
    animation: taraFabPulse 1.4s ease-out infinite;
}

.tara-fab i {
    font-size: 1.5rem;
}

.tara-fab-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.tara-panel {
    position: absolute;
    right: 0;
    bottom: calc(var(--tara-fab-size) + 12px);
    width: min(390px, calc(100vw - 32px));
    height: min(620px, calc(100dvh - var(--tara-stack-offset) - 24px));
    max-height: calc(100dvh - var(--tara-stack-offset) - 24px);
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.22);
    border: 1px solid rgba(148, 163, 184, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tara-panel[hidden] {
    display: none !important;
}

.tara-panel-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1rem 0.85rem;
    background: linear-gradient(135deg, #1e3a8a 0%, #6d28d9 100%);
    color: #fff;
}

.tara-panel-avatar {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.16);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.tara-panel-header strong {
    display: block;
    line-height: 1.2;
}

.tara-panel-header small {
    display: block;
    opacity: 0.82;
    font-size: 0.75rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: min(220px, 52vw);
}

.tara-panel-close {
    margin-left: auto;
    border: none;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.tara-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.tara-msg {
    max-width: 92%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tara-msg-bot {
    align-self: flex-start;
}

.tara-msg-user {
    align-self: flex-end;
}

.tara-bubble {
    padding: 0.75rem 0.9rem;
    border-radius: 16px;
    font-size: 0.92rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.tara-msg-bot .tara-bubble {
    background: #fff;
    color: #0f172a;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 6px;
}

.tara-msg-user .tara-bubble {
    background: linear-gradient(135deg, #2563eb, #6d28d9);
    color: #fff;
    border-bottom-right-radius: 6px;
}

.tara-bubble strong {
    font-weight: 700;
}

.tara-msg-time {
    font-size: 0.68rem;
    color: #94a3b8;
    line-height: 1.2;
    padding: 0 0.2rem;
}

.tara-msg-user .tara-msg-time {
    text-align: right;
}

.tara-msg-bot .tara-msg-time {
    text-align: left;
}

.tara-products {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    width: 100%;
}

.tara-product-card {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    padding: 0.65rem;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    color: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.tara-product-top {
    display: grid;
    grid-template-columns: 64px 1fr;
    gap: 0.65rem;
}

.tara-product-card:hover {
    border-color: rgba(37, 99, 235, 0.35);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
}

.tara-product-img,
.tara-product-placeholder {
    width: 64px;
    height: 64px;
    border-radius: 10px;
    object-fit: cover;
    background: #eef2ff;
}

.tara-product-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-size: 1.4rem;
}

.tara-product-body strong {
    display: block;
    font-size: 0.82rem;
    line-height: 1.35;
    margin-bottom: 0.2rem;
}

.tara-product-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
    font-size: 0.78rem;
}

.tara-product-price {
    color: #2563eb;
    font-weight: 700;
}

.tara-product-stock {
    color: #059669;
    font-weight: 600;
}

.tara-product-stock.out {
    color: #dc2626;
}

.tara-product-discount {
    background: #fee2e2;
    color: #b91c1c;
    padding: 0.1rem 0.35rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
}

.tara-product-cart {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
}

.tara-qty-control {
    display: inline-flex;
    align-items: center;
    border: 1px solid #dbeafe;
    border-radius: 999px;
    overflow: hidden;
    background: #f8fbff;
}

.tara-qty-btn {
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    color: #1d4ed8;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
}

.tara-qty-input {
    width: 42px;
    border: none;
    background: transparent;
    text-align: center;
    font-size: 0.82rem;
    font-weight: 700;
    color: #0f172a;
    padding: 0.2rem 0;
    -moz-appearance: textfield;
}

.tara-qty-input::-webkit-outer-spin-button,
.tara-qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.tara-add-cart {
    flex: 1;
    min-width: 140px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.45rem 0.75rem;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    font-size: 0.76rem;
    font-weight: 700;
    cursor: pointer;
}

.tara-add-cart:hover {
    filter: brightness(1.05);
}

.tara-product-link {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.74rem;
    font-weight: 600;
    color: #64748b;
    text-decoration: none;
}

.tara-product-link:hover {
    color: #2563eb;
}

.tara-cart-toast-msg .tara-bubble {
    background: #ecfdf5;
    border-color: #bbf7d0;
    color: #166534;
}

.tara-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.tara-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.65rem;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid transparent;
}

.tara-action-btn-whatsapp {
    background: #dcfce7;
    color: #15803d;
    border-color: #bbf7d0;
}

.tara-action-btn-link,
.tara-action-btn-email,
.tara-action-btn-phone,
.tara-action-btn-social {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #dbeafe;
}

.tara-action-btn-tiktok {
    background: linear-gradient(135deg, #111827 0%, #6d28d9 55%, #db2777 100%);
    color: #fff;
    border-color: transparent;
    font-weight: 700;
    box-shadow: 0 8px 22px rgba(109, 40, 217, 0.35);
}

.tara-action-btn-tiktok:hover {
    filter: brightness(1.06);
    color: #fff;
}

.tara-action-btn-social[href*="instagram"],
.tara-action-btn-link[href*="instagram"] {
    background: #fdf2f8;
    color: #be185d;
    border-color: #fbcfe8;
}

.tara-action-btn-facebook,
.tara-action-btn-link[href*="facebook"] {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #bfdbfe;
}

.tara-suggestions {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.45rem;
    padding: 0.55rem 0.85rem 0;
    overflow-x: auto;
    background: #fff;
    border-top: 1px solid #eef2f7;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.tara-suggestions::-webkit-scrollbar {
    display: none;
}

.tara-suggestion {
    flex: 0 0 auto;
    border: 1px solid #dbeafe;
    background: #f8fbff;
    color: #1d4ed8;
    border-radius: 999px;
    padding: 0.35rem 0.7rem;
    font-size: 0.74rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.tara-form {
    display: flex;
    gap: 0.5rem;
    padding: 0.85rem;
    padding-bottom: calc(0.85rem + var(--tara-safe-bottom));
    background: #fff;
    border-top: 1px solid #eef2f7;
    flex-shrink: 0;
}

.tara-input {
    flex: 1;
    min-width: 0;
    border: 1px solid #dbeafe;
    border-radius: 999px;
    padding: 0.65rem 0.95rem;
    font-size: max(16px, 0.88rem);
    outline: none;
}

.tara-input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.tara-send {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #6d28d9);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.tara-typing {
    display: inline-flex;
    gap: 0.25rem;
    padding: 0.65rem 0.85rem;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    border-bottom-left-radius: 6px;
}

.tara-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: taraTyping 1.2s infinite ease-in-out;
}

.tara-typing span:nth-child(2) { animation-delay: 0.15s; }
.tara-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes taraTyping {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
    40% { transform: translateY(-4px); opacity: 1; }
}

@media (max-width: 767.98px) {
    :root {
        --tara-fab-size: 58px;
        --tara-edge: 16px;
        --tara-fab-gap: 12px;
    }

    .tara-widget {
        bottom: calc(var(--tara-edge) + var(--tara-fab-size) + var(--tara-fab-gap) + var(--tara-safe-bottom));
    }

    .tara-widget.tara-widget--with-cart {
        bottom: calc(var(--tara-edge) + 60px + var(--tara-fab-gap) + var(--tara-safe-bottom));
    }

    .tara-fab {
        width: var(--tara-fab-size);
        height: var(--tara-fab-size);
    }

    .tara-fab-chip {
        right: 0;
        left: auto;
        bottom: calc(100% + 10px);
        top: auto;
        transform: none;
        max-width: min(190px, calc(100vw - 32px));
        white-space: normal;
        animation: none;
        padding: 0.45rem 0.7rem;
    }

    .tara-fab-chip::after {
        right: 18px;
        top: auto;
        bottom: -6px;
        transform: rotate(45deg);
    }

    @keyframes taraChipFloat {
        0%, 100% { transform: none; }
        50% { transform: translateY(-4px); }
    }

    .tara-panel {
        width: calc(100vw - (var(--tara-edge) * 2));
        right: calc((100vw - 100%) / -2 + var(--tara-edge) * 0.5);
        height: min(72dvh, calc(100dvh - var(--tara-stack-offset) - 20px));
        max-height: min(72dvh, calc(100dvh - var(--tara-stack-offset) - 20px));
    }

    .tara-teaser {
        width: min(280px, calc(100vw - 88px));
        right: 0;
        bottom: calc(var(--tara-fab-size) + 12px);
    }

    .tara-product-cart {
        flex-direction: column;
        align-items: stretch;
    }

    .tara-add-cart {
        min-width: 0;
        width: 100%;
    }

    .tara-product-link {
        justify-content: center;
        padding-top: 0.15rem;
    }

    .tara-panel-header {
        padding-top: calc(0.85rem + var(--tara-safe-top));
    }

    .tara-widget.tara-panel-open {
        inset: 0;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        height: auto;
        z-index: 100000;
        pointer-events: none;
    }

    .tara-widget.tara-panel-open .tara-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        border: none;
        padding: 0;
        margin: 0;
        background: rgba(15, 23, 42, 0.52);
        cursor: pointer;
        pointer-events: auto;
        z-index: 0;
        animation: taraBackdropIn 0.2s ease;
    }

    .tara-widget.tara-panel-open .tara-panel {
        position: fixed;
        left: 0;
        right: 0;
        top: var(--tara-vv-offset-top, auto);
        bottom: 0;
        width: 100%;
        max-width: none;
        height: var(--tara-vv-height, min(92dvh, calc(100dvh - var(--tara-safe-top) - 8px)));
        max-height: var(--tara-vv-height, min(92dvh, calc(100dvh - var(--tara-safe-top) - 8px)));
        border-radius: 18px 18px 0 0;
        pointer-events: auto;
        z-index: 1;
        box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.22);
        animation: taraPanelSheetIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
        transition: height 0.18s ease, top 0.18s ease, max-height 0.18s ease;
    }

    .tara-widget.tara-panel-open.tara-keyboard-open .tara-panel {
        top: var(--tara-vv-offset-top, 0px);
        bottom: auto;
        animation: none;
    }

    .tara-widget.tara-keyboard-open .tara-backdrop {
        opacity: 0.18;
    }

    .tara-widget.tara-keyboard-open .tara-suggestions {
        display: none;
    }

    .tara-widget.tara-keyboard-open .tara-panel-header {
        padding-top: 0.7rem;
        padding-bottom: 0.65rem;
    }

    .tara-widget.tara-keyboard-open .tara-panel-avatar {
        width: 34px;
        height: 34px;
        border-radius: 11px;
        font-size: 1rem;
    }

    .tara-widget.tara-keyboard-open .tara-form {
        padding-top: 0.65rem;
        padding-bottom: calc(0.65rem + var(--tara-safe-bottom));
    }

    .tara-widget.tara-panel-open .tara-fab,
    .tara-widget.tara-panel-open .tara-fab-chip,
    .tara-widget.tara-panel-open .tara-teaser {
        display: none !important;
    }

    .tara-panel-close {
        width: 40px;
        height: 40px;
    }
}

@keyframes taraBackdropIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes taraPanelSheetIn {
    from { transform: translateY(100%); opacity: 0.6; }
    to { transform: translateY(0); opacity: 1; }
}

body.tara-scroll-lock {
    overflow: hidden;
    position: fixed;
    width: 100%;
    left: 0;
    right: 0;
}

@media (max-width: 575px) {
    .tara-msg {
        max-width: 96%;
    }

    .tara-bubble {
        font-size: 0.9rem;
    }

    .tara-action-btn {
        font-size: 0.72rem;
        padding: 0.38rem 0.6rem;
    }
}

/* Burbuja invitación Tara */
.tara-teaser {
    position: absolute;
    right: 0;
    bottom: calc(var(--tara-fab-size) + 12px);
    width: min(290px, calc(100vw - 110px));
    z-index: 2;
    animation: taraTeaserIn 0.5s ease, taraTeaserFloat 3s ease-in-out 0.5s infinite;
}

.tara-teaser[hidden] {
    display: none !important;
}

@keyframes taraTeaserIn {
    from { opacity: 0; transform: translateY(12px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes taraTeaserFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

.tara-teaser-body {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    width: 100%;
    padding: 0.85rem 2rem 0.85rem 0.85rem;
    border: none;
    border-radius: 18px;
    background: #fff;
    color: #0f172a;
    text-align: left;
    box-shadow: 0 12px 36px rgba(15, 23, 42, 0.18);
    cursor: pointer;
    transition: box-shadow 0.2s, transform 0.2s;
}

.tara-teaser-body:hover {
    box-shadow: 0 16px 40px rgba(37, 99, 235, 0.22);
    transform: translateY(-2px);
}

.tara-teaser-avatar {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #fff;
    font-size: 1rem;
}

.tara-teaser-text {
    font-size: 0.88rem;
    line-height: 1.45;
    font-weight: 600;
}

.tara-teaser-close {
    position: absolute;
    top: 0.45rem;
    right: 0.45rem;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 8px;
    background: #f1f5f9;
    color: #64748b;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 3;
    font-size: 0.85rem;
}

.tara-teaser-tail {
    position: absolute;
    right: 22px;
    bottom: -8px;
    width: 16px;
    height: 16px;
    background: #fff;
    transform: rotate(45deg);
    box-shadow: 4px 4px 10px rgba(15, 23, 42, 0.08);
}
