/**
 * WC AI Homeopathic Chat - Styles MEJORADO
 * Version: 3.1.0
 */

/* Container principal */
#wc-ai-homeopathic-chat-container {
    position: fixed;
    bottom: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, sans-serif;
}

/* Posiciones */
#wc-ai-homeopathic-chat-container.wc-ai-chat-position-right {
    right: 20px;
}

#wc-ai-homeopathic-chat-container.wc-ai-chat-position-left {
    left: 20px;
}

/* Botón flotante ORIGINAL */
.wc-ai-chat-launcher {
    position: relative;
    cursor: pointer;
    z-index: 1000;
}

.wc-ai-chat-launcher .wc-ai-chat-icon {
    width: 60px;
    height: 60px;
    background: #25D366;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    box-shadow: 0 4px 20px rgba(37, 211, 102, 0.4);
    transition: all 0.3s ease;
}

.wc-ai-chat-launcher:hover .wc-ai-chat-icon {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(37, 211, 102, 0.6);
}

/* Robot EVA animado */
.wc-ai-chat-launcher .wc-ai-chat-icon img {
    width: 38px;
    height: 38px;
    animation: evaDance 6s infinite;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
    z-index: 1;
    position: relative;
}

@keyframes evaDance {

    0%,
    100% {
        transform:
            translateY(0) rotate(0deg) scale(1);
    }

    15% {
        transform:
            translateY(-6px) rotate(4deg) scale(1.05);
    }

    30% {
        transform:
            translateY(3px) rotate(-3deg) scale(0.98);
    }

    45% {
        transform:
            translateY(-3px) rotate(2deg) scale(1.02);
    }

    60% {
        transform:
            translateY(2px) rotate(-1deg) scale(0.99);
    }

    75% {
        transform:
            translateY(-1px) rotate(1deg) scale(1.01);
    }
}

/* Efecto hover - EVA se activa */
.wc-ai-chat-launcher:hover .wc-ai-chat-icon {
    box-shadow:
        0 6px 30px rgba(102, 126, 234, 0.6),
        inset 0 0 30px rgba(255, 255, 255, 0.2),
        0 0 20px rgba(102, 126, 234, 0.4);
}

.wc-ai-chat-launcher:hover .wc-ai-chat-icon img {
    animation: evaExcited 1.2s infinite ease-in-out;
}

@keyframes evaExcited {

    0%,
    100% {
        transform:
            translateY(0) rotate(0deg) scale(1.1);
    }

    50% {
        transform:
            translateY(-8px) rotate(8deg) scale(1.15);
    }
}


@keyframes evaEnergyPulse {
    0% {
        transform: scale(0.8);
        opacity: 0.7;
        box-shadow:
            0 0 0 0 rgba(102, 126, 234, 0.6),
            0 0 0 0 rgba(255, 255, 255, 0.3);
    }

    70% {
        transform: scale(1.5);
        opacity: 0;
        box-shadow:
            0 0 0 15px rgba(102, 126, 234, 0),
            0 0 0 30px rgba(255, 255, 255, 0);
    }

    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}


/* Pulso mejorado */
.wc-ai-chat-pulse {
    position: absolute;
    top: -8px;
    left: -8px;
    right: -8px;
    bottom: -8px;
    border: 2px solid rgba(102, 126, 234, 0.5);
    border-radius: 50%;
    animation: evaEnergyPulse 3s infinite;
    opacity: 0;
}

@keyframes wc-ai-pulse {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }

    70% {
        transform: scale(1.3);
        opacity: 0;
    }

    100% {
        transform: scale(1.3);
        opacity: 0;
    }
}

/* Ventana del chat */
.wc-ai-chat-window {
    position: absolute;
    bottom: 10px;
    width: 450px;
    /* Ligeramente más ancho para mejor legibilidad */
    max-width: 90vw;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s ease;
    z-index: 1999;
    overflow: hidden;
}

.wc-ai-chat-position-right .wc-ai-chat-window {
    right: 0;
}

.wc-ai-chat-position-left .wc-ai-chat-window {
    left: 0;
}

.wc-ai-chat-window.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.wc-ai-chat-window.minimized {
    height: 60px !important;
    min-height: 60px !important;
}

.wc-ai-chat-window.minimized .wc-ai-chat-messages,
.wc-ai-chat-window.minimized .wc-ai-chat-input-container {
    display: none;
}

/* Header del chat */
.wc-ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px 12px 0 0;
}

.wc-ai-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Avatar ORIGINAL */
.wc-ai-chat-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    backdrop-filter: blur(10px);
}

.wc-ai-chat-title {
    position: relative;
}

.wc-ai-chat-title h4 {
    margin: 0 0 2px 0;
    font-size: 16px;
    font-weight: 600;
}

.wc-ai-chat-status {
    font-size: 12px;
    opacity: 0.9;
    color: #a0f0a0;
}

.wc-ai-chat-context-indicator {
    position: absolute;
    top: 0;
    right: -20px;
    font-size: 10px;
    opacity: 0.7;
    cursor: help;
}

/* Botones de acción con SVG */
.wc-ai-chat-actions {
    display: flex;
    gap: 5px;
}

.wc-ai-chat-actions button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: all 0.3s ease;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
}

.wc-ai-chat-actions button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.wc-ai-chat-clear-context:hover {
    background: rgba(255, 193, 7, 0.3) !important;
}

/* Iconos SVG */
.wc-ai-icon-svg {
    width: 14px;
    height: 14px;
    transition: transform 0.3s ease;
}

.wc-ai-chat-minimize:hover .wc-ai-icon-svg {
    transform: scale(1.2);
}


/* CON ID ÚNICO - prácticamente imposible de sobrescribir */
#wc-ai-chat-close-btn {
    background: rgba(255, 255, 255, 0.2) !important;
    border: none !important;
    cursor: pointer !important;
    color: white !important;
    transition: all 0.2s ease !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 18px !important;
    height: 18px !important;
    border-radius: 50% !important;
    margin: 0 !important;
    outline: none !important;
    box-shadow: none !important;
}

#wc-ai-chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.3) !important;
    transform: scale(1.1) !important;
}

#wc-ai-chat-close-btn:active {
    background: rgba(255, 255, 255, 0.4) !important;
    transform: scale(0.95) !important;
}

#wc-ai-chat-close-btn svg {
    width: 14px !important;
    height: 14px !important;
    stroke: white !important;
}

.wc-ai-chat-close:hover .wc-ai-icon-svg {
    transform: rotate(90deg) scale(1.2);
}

/* Área de mensajes MEJORADA para legibilidad */
.wc-ai-chat-messages {
    height: 400px;
    /* Más alto para mejor visualización */
    max-height: 55vh;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
    scrollbar-width: thin;
    scrollbar-color: #c1c1c1 transparent;
    display: flex;
    flex-direction: column;
    gap: 16px;
    /* Mejor espaciado entre mensajes */
}

.wc-ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.wc-ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.wc-ai-chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.wc-ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Mensajes individuales MEJORADOS */
.wc-ai-chat-message {
    animation: wc-ai-message-appear 0.3s ease;
    max-width: 85%;
    /* Limitar ancho para mejor lectura */
}

@keyframes wc-ai-message-appear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.wc-ai-chat-message.user {
    align-self: flex-end;
    text-align: right;
}

.wc-ai-chat-message.user .wc-ai-message-content {
    background: #667eea;
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.wc-ai-chat-message.bot .wc-ai-message-content {
    background: white;
    color: #333;
    border: 1px solid #e1e5e9;
    border-bottom-left-radius: 4px;
}

.wc-ai-chat-message.system .wc-ai-message-content {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
    border-radius: 12px;
    font-size: 13px;
    padding: 10px 15px;
}

/* Contenido de mensajes MEJORADO */
.wc-ai-message-content {
    display: inline-block;
    padding: 14px 18px;
    /* Más padding para mejor legibilidad */
    border-radius: 18px;
    max-width: 100%;
    word-wrap: break-word;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    line-height: 1.5;
    /* Mejor interlineado */
    font-size: 14px;
    text-align: left;
    /* Forzar alineación izquierda para mejor lectura */
}

/* Estilos específicos para mensajes de productos */
.wc-ai-message-content .product-info {
    background: #f8f9fa;
    border-left: 3px solid #667eea;
    padding: 12px;
    margin: 8px 0;
    border-radius: 8px;
}

.wc-ai-message-content .product-price {
    color: #25D366;
    font-weight: 600;
    font-size: 15px;
}

.wc-ai-message-content .product-sku {
    color: #666;
    font-size: 12px;
    font-family: monospace;
}

.wc-ai-message-content .product-stock {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    margin-left: 8px;
}

.wc-ai-message-content .product-stock.in-stock {
    background: #d4edda;
    color: #155724;
}

.wc-ai-message-content .product-stock.out-of-stock {
    background: #f8d7da;
    color: #721c24;
}

.wc-ai-message-content p {
    margin: 0 0 12px 0;
    /* Más espacio entre párrafos */
    line-height: 1.5;
}

.wc-ai-message-content p:last-child {
    margin-bottom: 0;
}

.wc-ai-message-content ul,
.wc-ai-message-content ol {
    margin: 12px 0;
    padding-left: 24px;
    /* Más indentación */
}

.wc-ai-message-content li {
    margin: 6px 0;
    /* Más espacio entre items de lista */
    line-height: 1.4;
}

.wc-ai-message-content strong {
    font-weight: 600;
    color: #2c3e50;
}

.wc-ai-message-content em {
    font-style: italic;
    color: #7f8c8d;
}

.wc-ai-message-time {
    font-size: 11px;
    color: #999;
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.wc-ai-chat-message.user .wc-ai-message-time {
    justify-content: flex-end;
}

/* Contenedor de input */
.wc-ai-chat-input-container {
    padding: 15px;
    background: white;
    border-top: 1px solid #e1e5e9;
}

.wc-ai-chat-input {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    margin-bottom: 12px;
}

.wc-ai-chat-input textarea {
    flex: 1;
    border: 1px solid #e1e5e9;
    border-radius: 20px;
    padding: 12px 16px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    max-height: 120px;
    transition: border-color 0.3s ease;
    background: #f8f9fa;
}

.wc-ai-chat-input textarea:focus {
    outline: none;
    border-color: #667eea;
    background: white;
}

.wc-ai-chat-input textarea::placeholder {
    color: #999;
}

/* Botón de enviar */
.wc-ai-chat-send {
    background: #667eea;
    border: none;
    color: white;
    padding: 12px;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.wc-ai-chat-send:hover:not(:disabled) {
    background: #5a6fd8;
    transform: scale(1.05);
}

.wc-ai-chat-send:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.wc-ai-send-icon {
    font-size: 16px;
    font-weight: bold;
}

/* Fallback de WhatsApp */
.wc-ai-chat-fallback {
    text-align: center;
}

.wc-ai-whatsapp-fallback {
    background: #25D366;
    border: none;
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
}

.wc-ai-whatsapp-fallback:hover {
    background: #128C7E;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

.wc-ai-whatsapp-icon {
    font-size: 16px;
}

/* Enlace de WhatsApp en mensajes */
.wc-ai-whatsapp-link {
    display: inline-block;
    background: #25D366;
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.3s ease;
    margin-top: 8px;
}

.wc-ai-whatsapp-link:hover {
    background: #128C7E;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

/* Loading */
.wc-ai-chat-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #666;
    font-style: italic;
}

.loading-dots {
    display: flex;
    gap: 3px;
}

.loading-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #667eea;
    animation: wc-ai-loading-bounce 1.4s ease-in-out infinite both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes wc-ai-loading-bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Estados responsivos */
@media (max-width: 480px) {
    #wc-ai-homeopathic-chat-container {
        bottom: 10px;
    }

    #wc-ai-homeopathic-chat-container.wc-ai-chat-position-right {
        right: 10px;
    }

    #wc-ai-homeopathic-chat-container.wc-ai-chat-position-left {
        left: 10px;
    }

    .wc-ai-chat-window {
        width: calc(100vw - 20px);
        max-width: none;
        bottom: 70px;
    }

    .wc-ai-chat-messages {
        height: 350px;
        max-height: 50vh;
        padding: 15px;
    }

    .wc-ai-chat-message {
        max-width: 90%;
    }

    .wc-ai-message-content {
        padding: 12px 15px;
        font-size: 13px;
    }

    .wc-ai-chat-context-indicator {
        position: static;
        display: block;
        margin-top: 2px;
        font-size: 10px;
    }
}

/* Animación de entrada del chat */
@keyframes wc-ai-chat-entrance {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.wc-ai-chat-window.active {
    animation: wc-ai-chat-entrance 0.3s ease;
}

/* Mejoras de accesibilidad */
.wc-ai-chat-actions button:focus,
.wc-ai-chat-send:focus,
.wc-ai-whatsapp-fallback:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

.wc-ai-chat-input textarea:focus {
    outline: 2px solid #667eea;
    outline-offset: -2px;
}

/* Estados de interactividad */
.wc-ai-chat-launcher.active .wc-ai-chat-icon {
    background: #128C7E;
}

/* Smooth transitions para todos los elementos interactivos */
.wc-ai-chat-launcher,
.wc-ai-chat-actions button,
.wc-ai-chat-send,
.wc-ai-whatsapp-fallback,
.wc-ai-chat-input textarea {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Indicador de caché */
.wc-ai-cache-indicator {
    font-size: 0.7em;
    opacity: 0.6;
    font-style: italic;
    margin-left: 8px;
}

/* Efecto de escritura palabra por palabra */
.wc-ai-message-content.typing-effect {
    overflow: hidden;
}

.wc-ai-message-content.typing-effect span.word {
    opacity: 0;
    animation: wordAppear 0.3s ease forwards;
}

@keyframes wordAppear {
    to {
        opacity: 1;
    }
}

/* Cursor parpadeante para efecto de escritura */
.wc-ai-typing-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: #667eea;
    margin-left: 2px;
    animation: blink 1s infinite;
    vertical-align: middle;
}

@keyframes blink {

    0%,
    50% {
        opacity: 1;
    }

    51%,
    100% {
        opacity: 0;
    }
}

.wc-ai-whatsapp-link {
    display: inline-block;
    background: #25D366;
    color: white !important;
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none !important;
    font-weight: bold;
    margin-top: 10px;
    transition: all 0.3s ease;
    border: 2px solid #25D366;
}

.wc-ai-whatsapp-link:hover {
    background: white;
    color: #25D366 !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

/* Estilo para mensajes de error/fallback */
.wc-ai-chat-message.bot .wc-ai-message-content {
    line-height: 1.6;
}

.wc-ai-chat-message.bot .wc-ai-message-content strong {
    color: #333;
}

.wc-ai-chat-message.bot .wc-ai-message-content em {
    color: #666;
    font-style: italic;
}

/* Context indicator tooltip */
.wc-ai-chat-context-indicator {
    position: relative;
}

.wc-ai-chat-context-indicator::after {
    content: 'Contexto activo por pestaña';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s;
    z-index: 1000;
}

.wc-ai-chat-context-indicator:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Mensaje de sistema */
.wc-ai-chat-message.system {
    align-self: center;
    max-width: 90%;
    text-align: center;
}

.wc-ai-chat-message.system .wc-ai-message-content {
    background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
    border: 1px solid #f5c6cb;
    color: #856404;
    font-weight: 500;
}

/* Estilos para el botón de limpiar contexto */
.wc-ai-chat-clear-context svg {
    stroke: white !important;
    width: 16px !important;
    height: 16px !important;
    display: block !important;
}

.wc-ai-chat-clear-context {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 8px !important;
    min-width: 20px !important;
    min-height: 20px !important;
}

.wc-ai-chat-clear-context:hover svg {
    stroke: #ffc107 !important;
    transform: rotate(45deg);
    transition: transform 0.3s ease;
}