/**
 * Estilos Frontend - Chat Inteligente Acción Eficaz
 * Version: 3.4.1
 * Diseño moderno, estético y profesional - CORREGIDO
 */

/* =============================================================================
   VARIABLES CSS Y CONFIGURACIÓN BASE
   ============================================================================= */

:root {
    --ae-primary: #0E3950;
    --ae-primary-light: #1a5a7a;
    --ae-primary-dark: #0a2a3c;
    --ae-text: #FFFFFF;
    --ae-accent: #4ADE80;
    --ae-accent-light: #6ee7a7;
    --ae-accent-dark: #22c55e;
    --ae-user-bubble: #1e7aee;
    --ae-user-bubble-light: #3b82f6;
    --ae-user-bubble-dark: #1d4ed8;
    --ae-background: #ffffff;
    --ae-gray-50: #f9fafb;
    --ae-gray-100: #f3f4f6;
    --ae-gray-200: #e5e7eb;
    --ae-gray-300: #d1d5db;
    --ae-gray-400: #9ca3af;
    --ae-gray-500: #6b7280;
    --ae-gray-600: #4b5563;
    --ae-gray-700: #374151;
    --ae-gray-800: #1f2937;
    --ae-gray-900: #111827;
    --ae-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --ae-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --ae-shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --ae-shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --ae-shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --ae-chat-width: 500px;
    --ae-transition-slow: 700ms cubic-bezier(0.23, 1, 0.32, 1);
    --ae-transition-normal: 300ms cubic-bezier(0.23, 1, 0.32, 1);
    --ae-transition-fast: 150ms cubic-bezier(0.23, 1, 0.32, 1);
    --ae-font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --ae-border-radius: 16px;
    --ae-border-radius-sm: 8px;
    --ae-border-radius-lg: 24px;
}

/* =============================================================================
   CHAT TRADICIONAL [ae_chat] - MODO COMPACTO INICIAL
   ============================================================================= */

.ae-chat-widget {
    font-family: var(--ae-font);
    line-height: 1.6;
    font-size: 15px;
    position: relative;
    margin: 30px auto;
    width: 100%;
    max-width: var(--chat-width, var(--ae-chat-width));
    background: transparent;
    z-index: 1000;
}

/* Contenedor principal del chat - INICIALMENTE COMPACTO */
.ae-chat-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    border-radius: var(--ae-border-radius);
    overflow: hidden;
    background: var(--ae-background);
    box-shadow: var(--ae-shadow-xl);
    transition: all var(--ae-transition-slow);
    border: 1px solid var(--ae-gray-200);
    position: relative;
    
    /* Estado inicial - SOLO INPUT Y BOTÓN */
    height: auto;
    min-height: auto;
}

/* ESTADO EXPANDIDO - cuando se hace clic para expandir */
.ae-chat-container.expanded {
    min-height: 600px;
    max-height: 90vh;
}

/* Header del chat */
.ae-chat-header {
    background: linear-gradient(135deg, var(--primary-color, var(--ae-primary)), var(--primary-color, var(--ae-primary-light)));
    color: var(--text-color, var(--ae-text));
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
    
    /* Inicialmente oculto */
    display: none;
}

/* Mostrar header solo cuando está expandido */
.ae-chat-container.expanded .ae-chat-header {
    display: flex;
}

.ae-chat-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, rgba(255,255,255,0.1) 0%, transparent 50%);
    pointer-events: none;
}

.ae-chat-header-content {
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    z-index: 1;
}

.ae-chat-logo {
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.ae-chat-logo svg {
    width: 24px;
    height: 24px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.ae-chat-info .ae-chat-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 4px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.ae-chat-status {
    font-size: 13px;
    opacity: 0.95;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ae-chat-status-dot {
    width: 8px;
    height: 8px;
    background: var(--accent-color, var(--ae-accent));
    border-radius: 50%;
    animation: ae-pulse 2s infinite;
    box-shadow: 0 0 0 0 var(--accent-color, var(--ae-accent));
}

.ae-chat-actions {
    display: flex;
    gap: 8px;
    position: relative;
    z-index: 1;
}

.ae-chat-action-button {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-color, var(--ae-text));
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all var(--ae-transition-fast);
    opacity: 0.8;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.ae-chat-action-button:hover {
    background: rgba(255, 255, 255, 0.2);
    opacity: 1;
    transform: scale(1.05);
}

/* Área de conversación - inicialmente oculta */
.ae-chat-conversation {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    background: var(--ae-gray-50);
    background-image: 
        radial-gradient(circle at 25px 25px, var(--ae-gray-200) 2px, transparent 0),
        radial-gradient(circle at 75px 75px, var(--ae-gray-200) 2px, transparent 0);
    background-size: 100px 100px;
    background-position: 0 0, 50px 50px;
    min-height: 300px;
    max-height: 400px;
    position: relative;
    
    /* Inicialmente oculto */
    display: none;
}

/* Mostrar conversación solo cuando está expandido */
.ae-chat-container.expanded .ae-chat-conversation {
    display: block;
}

.ae-chat-conversation::-webkit-scrollbar {
    width: 6px;
}

.ae-chat-conversation::-webkit-scrollbar-track {
    background: transparent;
}

.ae-chat-conversation::-webkit-scrollbar-thumb {
    background: var(--ae-gray-300);
    border-radius: 3px;
}

.ae-chat-conversation::-webkit-scrollbar-thumb:hover {
    background: var(--ae-gray-400);
}

/* Mensajes */
.ae-message {
    margin-bottom: 24px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    animation: ae-slide-up 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transition: all var(--ae-transition-normal);
    position: relative;
}

.ae-message:hover {
    transform: translateY(-1px);
}

.ae-message:hover .ae-message-bubble {
    box-shadow: 
        0 8px 25px rgba(0, 0, 0, 0.12),
        0 4px 12px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.ae-message.ae-message-user:hover .ae-message-bubble {
    box-shadow: 
        0 8px 25px rgba(30, 122, 238, 0.35),
        0 4px 12px rgba(30, 122, 238, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.ae-message.ae-message-user {
    flex-direction: row-reverse;
}

.ae-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    flex-shrink: 0;
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.15),
        0 2px 4px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    border: 3px solid var(--ae-background);
    transition: all var(--ae-transition-normal);
    position: relative;
    overflow: hidden;
}

.ae-avatar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255,255,255,0.1) 50%, transparent 70%);
    opacity: 0;
    transition: opacity var(--ae-transition-normal);
}

.ae-message:hover .ae-avatar::before {
    opacity: 1;
    animation: ae-shine 1s ease-in-out;
}

.ae-message.ae-message-assistant .ae-avatar {
    background: linear-gradient(135deg, var(--primary-color, var(--ae-primary)), var(--primary-color, var(--ae-primary-light)));
    color: var(--text-color, var(--ae-text));
}

.ae-message.ae-message-user .ae-avatar {
    background: linear-gradient(135deg, var(--user-bubble-color, var(--ae-user-bubble)), var(--user-bubble-color, var(--ae-user-bubble-light)));
    color: white;
}

.ae-message-bubble {
    background: linear-gradient(145deg, var(--ae-background), var(--ae-gray-50));
    padding: 16px 20px;
    border-radius: 20px;
    max-width: 75%;
    font-size: 15px;
    line-height: 1.6;
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.08),
        0 2px 4px rgba(0, 0, 0, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    position: relative;
    word-wrap: break-word;
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    transition: all var(--ae-transition-normal);
    font-weight: 400;
    color: var(--ae-gray-800);
}

.ae-message.ae-message-user .ae-message-bubble {
    background: linear-gradient(135deg, var(--user-bubble-color, var(--ae-user-bubble)), var(--user-bubble-color, var(--ae-user-bubble-light)));
    color: white;
    border: none;
    box-shadow: 
        0 4px 12px rgba(30, 122, 238, 0.25),
        0 2px 4px rgba(30, 122, 238, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* ESTILOS MEJORADOS PARA CONTENIDO DE MENSAJES */

/* Texto en negrita */
.ae-message-bubble strong {
    font-weight: 700;
    color: var(--primary-color, var(--ae-primary));
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.ae-message.ae-message-user .ae-message-bubble strong {
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

/* Texto enfatizado */
.ae-message-bubble em {
    font-style: italic;
    color: var(--accent-color, var(--ae-accent-dark));
    font-weight: 500;
}

.ae-message.ae-message-user .ae-message-bubble em {
    color: rgba(255, 255, 255, 0.9);
}

/* Enlaces */
.ae-message-bubble a {
    color: var(--primary-color, var(--ae-primary));
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1px solid transparent;
    transition: all var(--ae-transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.ae-message-bubble a:hover {
    color: var(--accent-color, var(--ae-accent));
    border-bottom-color: currentColor;
    transform: translateY(-1px);
}

.ae-message.ae-message-user .ae-message-bubble a {
    color: rgba(255, 255, 255, 0.95);
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}

.ae-message.ae-message-user .ae-message-bubble a:hover {
    color: white;
    border-bottom-color: white;
}

/* Listas */
.ae-message-bubble ul,
.ae-message-bubble ol {
    margin: 12px 0;
    padding-left: 0;
    list-style: none;
}

.ae-message-bubble li {
    position: relative;
    padding: 6px 0 6px 24px;
    margin-bottom: 8px;
}

.ae-message-bubble ul li:before {
    content: "✓";
    position: absolute;
    left: 0;
    top: 6px;
    color: var(--accent-color, var(--ae-accent));
    font-weight: 700;
    font-size: 14px;
}

.ae-message.ae-message-user .ae-message-bubble ul li:before {
    color: rgba(255, 255, 255, 0.8);
}

.ae-message-bubble ol {
    counter-reset: item;
}

.ae-message-bubble ol li:before {
    content: counter(item) ".";
    counter-increment: item;
    position: absolute;
    left: 0;
    top: 6px;
    color: var(--primary-color, var(--ae-primary));
    font-weight: 700;
    font-size: 14px;
}

.ae-message.ae-message-user .ae-message-bubble ol li:before {
    color: rgba(255, 255, 255, 0.8);
}

/* Separadores visuales */
.ae-message-bubble hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--ae-gray-300), transparent);
    margin: 16px 0;
}

.ae-message.ae-message-user .ae-message-bubble hr {
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
}

/* Código inline */
.ae-message-bubble code {
    background: var(--ae-gray-100);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: var(--ae-gray-800);
    border: 1px solid var(--ae-gray-200);
}

.ae-message.ae-message-user .ae-message-bubble code {
    background: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

/* Bloques de texto destacados */
.ae-message-bubble blockquote {
    margin: 12px 0;
    padding: 12px 16px;
    border-left: 4px solid var(--accent-color, var(--ae-accent));
    background: var(--ae-gray-50);
    border-radius: 0 8px 8px 0;
    font-style: italic;
    position: relative;
}

.ae-message.ae-message-user .ae-message-bubble blockquote {
    background: rgba(255, 255, 255, 0.1);
    border-left-color: rgba(255, 255, 255, 0.4);
}

/* Párrafos con espaciado mejorado */
.ae-message-bubble p {
    margin: 0 0 12px 0;
}

.ae-message-bubble p:last-child {
    margin-bottom: 0;
}

.ae-message-bubble::before {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border: 6px solid transparent;
}

.ae-message.ae-message-assistant .ae-message-bubble::before {
    left: -6px;
    top: 18px;
    border-right-color: var(--ae-background);
}

.ae-message.ae-message-user .ae-message-bubble::before {
    right: -6px;
    top: 18px;
    border-left-color: var(--user-bubble-color, var(--ae-user-bubble));
}

.ae-message-bubble strong {
    font-weight: 600;
    color: inherit;
}

.ae-message-bubble em {
    font-style: italic;
    color: inherit;
}

.ae-message-bubble a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: all var(--ae-transition-fast);
}

.ae-message.ae-message-user .ae-message-bubble a {
    color: rgba(255, 255, 255, 0.9);
}

.ae-message-bubble a:hover {
    opacity: 0.8;
}

/* Sugerencias */
.ae-suggestions {
    margin-top: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    animation: ae-fade-in 0.5s ease;
}

.ae-suggestion {
    background: linear-gradient(135deg, var(--accent-color, var(--ae-accent)), var(--accent-color, var(--ae-accent-light)));
    color: white;
    padding: 10px 16px;
    border-radius: var(--ae-border-radius-lg);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--ae-transition-normal);
    border: none;
    box-shadow: var(--ae-shadow);
    backdrop-filter: blur(10px);
}

.ae-suggestion:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: var(--ae-shadow-lg);
    background: linear-gradient(135deg, var(--accent-color, var(--ae-accent-dark)), var(--accent-color, var(--ae-accent)));
}

.ae-suggestion:active {
    transform: translateY(0) scale(0.98);
}

/* Indicador de escritura */
.ae-typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 16px;
    background: var(--ae-background);
    border-radius: 18px;
    box-shadow: var(--ae-shadow);
    margin-bottom: 16px;
    border: 1px solid var(--ae-gray-100);
}

.ae-typing-dot {
    width: 6px;
    height: 6px;
    background: var(--ae-gray-400);
    border-radius: 50%;
    animation: ae-typing-dot 1.4s infinite ease-in-out;
}

.ae-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.ae-typing-dot:nth-child(2) { animation-delay: -0.16s; }
.ae-typing-dot:nth-child(3) { animation-delay: 0s; }

/* Área de input - SIEMPRE VISIBLE */
.ae-chat-input-area {
    padding: 20px 24px;
    background: var(--ae-background);
    border-top: 1px solid var(--ae-gray-200);
}

.ae-chat-input-container {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--ae-gray-100);
    border-radius: var(--ae-border-radius-lg);
    padding: 12px 16px;
    border: 2px solid transparent;
    transition: all var(--ae-transition-fast);
    box-shadow: var(--ae-shadow-sm);
    position: relative;
}

.ae-chat-input-container:focus-within {
    border-color: var(--primary-color, var(--ae-primary));
    background: var(--ae-background);
    box-shadow: var(--ae-shadow);
}

.ae-chat-input-container:hover {
    border-color: var(--ae-gray-300);
}

.ae-chat-input {
    flex: 1;
    min-height: 20px;
    max-height: 100px;
    overflow-y: auto;
    background: none;
    border: none;
    outline: none;
    font-size: 15px;
    line-height: 1.4;
    color: var(--ae-gray-800);
    resize: none;
    font-family: inherit;
    
    /* Centrado vertical */
    display: flex;
    align-items: center;
    padding: 0;
}

.ae-chat-input[data-placeholder]:empty:before {
    content: attr(data-placeholder);
    color: var(--ae-gray-500);
    font-style: normal;
}

.ae-chat-input::-webkit-scrollbar {
    width: 4px;
}

.ae-chat-input::-webkit-scrollbar-track {
    background: transparent;
}

.ae-chat-input::-webkit-scrollbar-thumb {
    background: var(--ae-gray-300);
    border-radius: 2px;
}

.ae-chat-send {
    background: linear-gradient(135deg, var(--primary-color, var(--ae-primary)), var(--primary-color, var(--ae-primary-light)));
    border: none;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--ae-transition-fast);
    color: var(--text-color, var(--ae-text));
    flex-shrink: 0;
    box-shadow: var(--ae-shadow);
}

.ae-chat-send:disabled {
    background: var(--ae-gray-300);
    cursor: not-allowed;
    opacity: 0.6;
}

.ae-chat-send:not(:disabled):hover {
    transform: scale(1.05);
    box-shadow: var(--ae-shadow-md);
}

.ae-chat-send:not(:disabled):active {
    transform: scale(0.95);
}

.ae-chat-send svg {
    width: 18px;
    height: 18px;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
}

/* Footer - inicialmente oculto */
.ae-chat-footer {
    padding: 12px 24px;
    background: var(--ae-gray-100);
    border-top: 1px solid var(--ae-gray-200);
    text-align: center;
    font-size: 12px;
    color: var(--ae-gray-500);
    font-weight: 500;
    
    /* Inicialmente oculto */
    display: none;
}

/* Mostrar footer solo cuando está expandido */
.ae-chat-container.expanded .ae-chat-footer {
    display: block;
}

/* Estado minimizado - volver al estado compacto */
.ae-chat-container.minimized {
    min-height: auto;
    height: auto;
}

.ae-chat-container.minimized .ae-chat-header,
.ae-chat-container.minimized .ae-chat-conversation,
.ae-chat-container.minimized .ae-chat-footer {
    display: none;
}

/* =============================================================================
   BURBUJA FLOTANTE [ae_chat_bubble] - POSICIONAMIENTO CORREGIDO
   ============================================================================= */

.ae-chat-bubble-widget {
    position: fixed;
    z-index: 999999;
    font-family: var(--ae-font);
    user-select: none;
}

/* Trigger de la burbuja */
.ae-bubble-trigger {
    position: relative;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary-color, var(--ae-primary)), var(--primary-color, var(--ae-primary-light)));
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--ae-shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--ae-transition-normal);
    color: var(--text-color, var(--ae-text));
    border: none;
    backdrop-filter: blur(10px);
    /* REMOVIDO overflow: hidden PARA QUE LA NOTIFICACIÓN SEA VISIBLE */
}

.ae-bubble-trigger::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.2), transparent 50%);
    pointer-events: none;
}

.ae-bubble-trigger:hover {
    transform: scale(1.05);
    box-shadow: var(--ae-shadow-xl);
}

.ae-bubble-trigger.active {
    background: linear-gradient(135deg, var(--accent-color, var(--ae-accent)), var(--accent-color, var(--ae-accent-light)));
    transform: rotate(45deg);
}

.ae-bubble-icon {
    transition: all var(--ae-transition-normal);
    position: relative;
    z-index: 1;
}

.ae-bubble-chat-icon svg,
.ae-bubble-close-icon svg {
    width: 26px;
    height: 26px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

/* Notificación */
.ae-bubble-notification {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, #ff4444, #ff6b6b);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: ae-bubble-pulse 2s infinite;
    border: 2px solid white;
    box-shadow: var(--ae-shadow);
}

.ae-notification-count {
    color: white;
    font-size: 11px;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.ae-notification-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #ff4444;
    animation: ae-pulse-ring 2s infinite;
}

/* Panel del chat - POSICIONAMIENTO CORREGIDO */
.ae-bubble-chat-panel {
    position: absolute;
    width: 360px;
    height: 500px;
    background: var(--ae-background);
    border-radius: var(--ae-border-radius);
    box-shadow: var(--ae-shadow-xl);
    opacity: 0;
    visibility: hidden;
    transition: all var(--ae-transition-normal);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95) translateY(10px);
    border: 1px solid var(--ae-gray-200);
}

.ae-bubble-chat-panel.active {
    opacity: 1;
    visibility: visible;
    transform: scale(1) translateY(0);
}

/* Posicionamiento dinámico del panel - CORREGIDO PARA NO SALIRSE */
.ae-chat-bubble-widget[style*="bottom"][style*="right"] .ae-bubble-chat-panel {
    bottom: 70px;
    right: 0;
    /* Posicionar hacia arriba-izquierda cuando burbuja está abajo-derecha */
    transform-origin: bottom right;
}

.ae-chat-bubble-widget[style*="bottom"][style*="left"] .ae-bubble-chat-panel {
    bottom: 70px;
    left: 0;
    /* Posicionar hacia arriba-derecha cuando burbuja está abajo-izquierda */
    transform-origin: bottom left;
}

.ae-chat-bubble-widget[style*="top"][style*="right"] .ae-bubble-chat-panel {
    top: 70px;
    right: 0;
    /* Posicionar hacia abajo-izquierda cuando burbuja está arriba-derecha */
    transform-origin: top right;
}

.ae-chat-bubble-widget[style*="top"][style*="left"] .ae-bubble-chat-panel {
    top: 70px;
    left: 0;
    /* Posicionar hacia abajo-derecha cuando burbuja está arriba-izquierda */
    transform-origin: top left;
}

/* Header del panel */
.ae-bubble-header {
    background: linear-gradient(135deg, var(--primary-color, var(--ae-primary)), var(--primary-color, var(--ae-primary-light)));
    color: var(--text-color, var(--ae-text));
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
}

.ae-bubble-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, rgba(255,255,255,0.1) 0%, transparent 50%);
    pointer-events: none;
}

.ae-bubble-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    z-index: 1;
}

.ae-bubble-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.ae-bubble-title {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 2px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.ae-bubble-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ae-status-dot {
    width: 6px;
    height: 6px;
    background: var(--accent-color, var(--ae-accent));
    border-radius: 50%;
    animation: ae-status-pulse 2s infinite;
}

.ae-bubble-minimize {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-color, var(--ae-text));
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all var(--ae-transition-fast);
    opacity: 0.8;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    z-index: 1;
}

.ae-bubble-minimize:hover {
    background: rgba(255, 255, 255, 0.2);
    opacity: 1;
    transform: scale(1.05);
}

/* Conversación de la burbuja */
.ae-bubble-conversation {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: var(--ae-gray-50);
    background-image: 
        radial-gradient(circle at 20px 20px, var(--ae-gray-200) 1px, transparent 0),
        radial-gradient(circle at 60px 60px, var(--ae-gray-200) 1px, transparent 0);
    background-size: 80px 80px;
    background-position: 0 0, 40px 40px;
}

.ae-bubble-conversation::-webkit-scrollbar {
    width: 4px;
}

.ae-bubble-conversation::-webkit-scrollbar-track {
    background: transparent;
}

.ae-bubble-conversation::-webkit-scrollbar-thumb {
    background: var(--ae-gray-300);
    border-radius: 2px;
}

/* Mensajes de la burbuja */
.ae-bubble-message {
    margin-bottom: 14px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    animation: ae-slide-up 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.ae-bubble-message.user {
    flex-direction: row-reverse;
}

.ae-bubble-message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
    box-shadow: var(--ae-shadow-sm);
    border: 2px solid var(--ae-background);
}

.ae-bubble-message.assistant .ae-bubble-message-avatar {
    background: linear-gradient(135deg, var(--primary-color, var(--ae-primary)), var(--primary-color, var(--ae-primary-light)));
    color: var(--text-color, var(--ae-text));
}

.ae-bubble-message.user .ae-bubble-message-avatar {
    background: linear-gradient(135deg, var(--user-bubble-color, var(--ae-user-bubble)), var(--user-bubble-color, var(--ae-user-bubble-light)));
    color: white;
}

.ae-bubble-message-content {
    background: var(--ae-background);
    padding: 10px 14px;
    border-radius: 14px;
    max-width: 240px;
    font-size: 13px;
    line-height: 1.4;
    box-shadow: var(--ae-shadow-sm);
    word-wrap: break-word;
    border: 1px solid var(--ae-gray-100);
    position: relative;
}

.ae-bubble-message.user .ae-bubble-message-content {
    background: linear-gradient(135deg, var(--user-bubble-color, var(--ae-user-bubble)), var(--user-bubble-color, var(--ae-user-bubble-light)));
    color: white;
    border: none;
}

.ae-bubble-message-content::before {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border: 5px solid transparent;
}

.ae-bubble-message.assistant .ae-bubble-message-content::before {
    left: -5px;
    top: 12px;
    border-right-color: var(--ae-background);
}

.ae-bubble-message.user .ae-bubble-message-content::before {
    right: -5px;
    top: 12px;
    border-left-color: var(--user-bubble-color, var(--ae-user-bubble));
}

/* Sugerencias de burbuja */
.ae-bubble-suggestions {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    animation: ae-fade-in 0.5s ease;
}

.ae-bubble-suggestion {
    background: linear-gradient(135deg, var(--primary-color, var(--ae-primary)), var(--primary-color, var(--ae-primary-light)));
    color: var(--text-color, var(--ae-text));
    padding: 10px 14px;
    border-radius: var(--ae-border-radius-lg);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--ae-transition-fast);
    text-align: center;
    border: none;
    box-shadow: var(--ae-shadow-sm);
}

.ae-bubble-suggestion:hover {
    transform: translateY(-1px);
    box-shadow: var(--ae-shadow);
    background: linear-gradient(135deg, var(--accent-color, var(--ae-accent)), var(--accent-color, var(--ae-accent-light)));
}

/* Indicador de escritura para burbuja */
.ae-bubble-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: var(--ae-background);
    border-radius: 14px;
    margin-bottom: 14px;
    box-shadow: var(--ae-shadow-sm);
    border: 1px solid var(--ae-gray-100);
}

.ae-bubble-typing-dot {
    width: 5px;
    height: 5px;
    background: var(--ae-gray-400);
    border-radius: 50%;
    animation: ae-typing-dot 1.4s infinite ease-in-out;
}

.ae-bubble-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.ae-bubble-typing-dot:nth-child(2) { animation-delay: -0.16s; }
.ae-bubble-typing-dot:nth-child(3) { animation-delay: 0s; }

/* Input de la burbuja */
.ae-bubble-input-area {
    padding: 16px;
    background: var(--ae-background);
    border-top: 1px solid var(--ae-gray-200);
}

.ae-bubble-input-container {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--ae-gray-100);
    border-radius: var(--ae-border-radius-lg);
    padding: 10px 12px;
    border: 2px solid transparent;
    transition: all var(--ae-transition-fast);
}

.ae-bubble-input-container:focus-within {
    border-color: var(--primary-color, var(--ae-primary));
    background: var(--ae-background);
    box-shadow: var(--ae-shadow-sm);
}

.ae-bubble-input-container:hover {
    border-color: var(--ae-gray-300);
}

.ae-bubble-input {
    flex: 1;
    min-height: 18px;
    max-height: 80px;
    overflow-y: auto;
    background: none;
    border: none;
    outline: none;
    font-size: 14px;
    line-height: 1.3;
    color: var(--ae-gray-800);
    resize: none;
    font-family: inherit;
    
    /* Centrado vertical */
    display: flex;
    align-items: center;
    padding: 0;
}

.ae-bubble-input[data-placeholder]:empty:before {
    content: attr(data-placeholder);
    color: var(--ae-gray-500);
    font-style: normal;
}

.ae-bubble-send {
    background: linear-gradient(135deg, var(--primary-color, var(--ae-primary)), var(--primary-color, var(--ae-primary-light)));
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--ae-transition-fast);
    color: var(--text-color, var(--ae-text));
    flex-shrink: 0;
    box-shadow: var(--ae-shadow-sm);
}

.ae-bubble-send:disabled {
    background: var(--ae-gray-300);
    cursor: not-allowed;
    opacity: 0.6;
}

.ae-bubble-send:not(:disabled):hover {
    transform: scale(1.1);
    box-shadow: var(--ae-shadow);
}

.ae-bubble-send svg {
    width: 14px;
    height: 14px;
}

/* Footer de la burbuja */
.ae-bubble-footer {
    padding: 8px 16px;
    background: var(--ae-gray-100);
    border-top: 1px solid var(--ae-gray-200);
    text-align: center;
    font-size: 11px;
    color: var(--ae-gray-500);
    font-weight: 500;
}

/* =============================================================================
   RESPONSIVE DESIGN
   ============================================================================= */

@media (max-width: 768px) {
    .ae-chat-widget {
        margin: 15px auto;
        max-width: calc(100% - 20px);
    }
    
    .ae-chat-container {
        border-radius: 12px;
    }
    
    .ae-chat-container.expanded {
        min-height: 500px;
    }
    
    .ae-message-bubble {
        max-width: 260px;
        font-size: 14px;
    }
    
    .ae-bubble-chat-panel {
        width: calc(100vw - 20px);
        max-width: 340px;
        height: calc(100vh - 120px);
        max-height: 480px;
    }
    
    .ae-bubble-message-content {
        max-width: 200px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .ae-chat-header {
        padding: 16px 20px;
    }
    
    .ae-chat-conversation {
        padding: 16px;
    }
    
    .ae-chat-input-area {
        padding: 16px 20px;
    }
    
    .ae-message-bubble {
        max-width: 90%;
        font-size: 14px;
    }
    
    .ae-chat-input {
        font-size: 16px; /* Evitar zoom en iOS */
    }
    
    .ae-bubble-trigger {
        width: 54px;
        height: 54px;
    }
    
    .ae-bubble-chat-panel {
        width: calc(100vw - 10px);
        height: calc(100vh - 80px);
        border-radius: 12px 12px 0 0;
    }
}

/* =============================================================================
   ANIMACIONES Y EFECTOS
   ============================================================================= */

@keyframes ae-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.05);
    }
}

@keyframes ae-bubble-pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 68, 68, 0.4);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 8px rgba(255, 68, 68, 0);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 68, 68, 0);
    }
}

@keyframes ae-pulse-ring {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    100% {
        transform: scale(2);
        opacity: 0;
    }
}

@keyframes ae-status-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

@keyframes ae-slide-up {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes ae-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes ae-typing-dot {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* =============================================================================
   ESTADOS Y UTILIDADES
   ============================================================================= */

.ae-chat-hidden {
    display: none !important;
}

.ae-chat-loading {
    opacity: 0.7;
    pointer-events: none;
}

.ae-fade-in {
    animation: ae-fade-in 0.3s ease;
}

.ae-bounce {
    animation: ae-bounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes ae-bounce {
    0% {
        transform: scale(0.8);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes ae-shine {
    0% {
        transform: translateX(-100%);
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    100% {
        transform: translateX(100%);
        opacity: 0;
    }
}

@keyframes ae-text-glow {
    0% {
        text-shadow: 0 0 5px rgba(74, 222, 128, 0.3);
    }
    50% {
        text-shadow: 0 0 20px rgba(74, 222, 128, 0.6), 0 0 30px rgba(74, 222, 128, 0.4);
    }
    100% {
        text-shadow: 0 0 5px rgba(74, 222, 128, 0.3);
    }
}

@keyframes ae-message-appear {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Efectos de hover mejorados */
.ae-chat-send:not(:disabled):hover,
.ae-bubble-send:not(:disabled):hover {
    background: linear-gradient(135deg, var(--primary-color, var(--ae-primary-light)), var(--primary-color, var(--ae-primary)));
}

.ae-suggestion:hover,
.ae-bubble-suggestion:hover {
    background: linear-gradient(135deg, var(--accent-color, var(--ae-accent-light)), var(--accent-color, var(--ae-accent-dark)));
}

/* Focus states para accesibilidad */
.ae-chat-input:focus,
.ae-bubble-input:focus {
    outline: none;
}

.ae-chat-send:focus,
.ae-bubble-send:focus,
.ae-chat-action-button:focus,
.ae-bubble-minimize:focus,
.ae-suggestion:focus,
.ae-bubble-suggestion:focus {
    outline: 2px solid var(--accent-color, var(--ae-accent));
    outline-offset: 2px;
}

/* Estilos avanzados para formato de mensajes */

/* Encabezados en mensajes */
.ae-message-bubble .ae-message-h1,
.ae-message-bubble .ae-message-h2,
.ae-message-bubble .ae-message-h3 {
    margin: 16px 0 12px 0;
    font-weight: 700;
    line-height: 1.3;
    color: var(--primary-color, var(--ae-primary));
}

.ae-message-bubble .ae-message-h1 {
    font-size: 1.5em;
    border-bottom: 2px solid var(--accent-color, var(--ae-accent));
    padding-bottom: 8px;
}

.ae-message-bubble .ae-message-h2 {
    font-size: 1.3em;
    border-left: 4px solid var(--accent-color, var(--ae-accent));
    padding-left: 12px;
}

.ae-message-bubble .ae-message-h3 {
    font-size: 1.1em;
    color: var(--accent-color, var(--ae-accent-dark));
}

.ae-message.ae-message-user .ae-message-bubble .ae-message-h1,
.ae-message.ae-message-user .ae-message-bubble .ae-message-h2,
.ae-message.ae-message-user .ae-message-bubble .ae-message-h3 {
    color: rgba(255, 255, 255, 0.95);
}

.ae-message.ae-message-user .ae-message-bubble .ae-message-h1 {
    border-bottom-color: rgba(255, 255, 255, 0.4);
}

.ae-message.ae-message-user .ae-message-bubble .ae-message-h2 {
    border-left-color: rgba(255, 255, 255, 0.4);
}

/* Texto con formato avanzado */
.ae-message-bubble .ae-message-bold {
    font-weight: 700;
    color: var(--primary-color, var(--ae-primary));
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.ae-message-bubble .ae-message-italic {
    font-style: italic;
    color: var(--accent-color, var(--ae-accent-dark));
    font-weight: 500;
}

.ae-message.ae-message-user .ae-message-bubble .ae-message-bold,
.ae-message.ae-message-user .ae-message-bubble .ae-message-italic {
    color: rgba(255, 255, 255, 0.95);
}

/* Enlaces con estilos mejorados */
.ae-message-bubble .ae-message-link {
    color: var(--primary-color, var(--ae-primary));
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1px solid transparent;
    transition: all var(--ae-transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 4px;
    border-radius: 4px;
    background: linear-gradient(135deg, transparent, rgba(78, 222, 128, 0.1));
}

.ae-message-bubble .ae-message-link:hover {
    color: var(--accent-color, var(--ae-accent));
    border-bottom-color: currentColor;
    transform: translateY(-1px);
    background: linear-gradient(135deg, rgba(78, 222, 128, 0.1), rgba(78, 222, 128, 0.2));
}

.ae-message-bubble .ae-link-icon {
    font-size: 0.8em;
    opacity: 0.7;
    transition: opacity var(--ae-transition-fast);
}

.ae-message-bubble .ae-message-link:hover .ae-link-icon {
    opacity: 1;
}

.ae-message.ae-message-user .ae-message-bubble .ae-message-link {
    color: rgba(255, 255, 255, 0.95);
    background: linear-gradient(135deg, transparent, rgba(255, 255, 255, 0.1));
}

.ae-message.ae-message-user .ae-message-bubble .ae-message-link:hover {
    color: white;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.2));
}

/* Código inline */
.ae-message-bubble .ae-message-code {
    background: linear-gradient(135deg, var(--ae-gray-100), var(--ae-gray-50));
    color: var(--primary-color, var(--ae-primary));
    padding: 3px 8px;
    border-radius: 6px;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 0.9em;
    font-weight: 600;
    border: 1px solid var(--ae-border-light);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.05);
}

.ae-message.ae-message-user .ae-message-bubble .ae-message-code {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.1));
    color: rgba(255, 255, 255, 0.95);
    border-color: rgba(255, 255, 255, 0.2);
}

/* Listas con estilos mejorados */
.ae-message-bubble .ae-message-list {
    margin: 16px 0;
    padding-left: 0;
    list-style: none;
    background: linear-gradient(135deg, rgba(78, 222, 128, 0.05), transparent);
    border-left: 3px solid var(--accent-color, var(--ae-accent));
    border-radius: 0 8px 8px 0;
    padding: 8px 12px 8px 20px;
}

.ae-message-bubble .ae-message-list-item {
    position: relative;
    padding: 6px 0 6px 24px;
    margin-bottom: 8px;
    line-height: 1.5;
    transition: all var(--ae-transition-fast);
}

.ae-message-bubble .ae-message-list-item:hover {
    transform: translateX(4px);
}

.ae-message-bubble .ae-bulleted-list .ae-message-list-item:before {
    content: "✨";
    position: absolute;
    left: 0;
    top: 6px;
    color: var(--accent-color, var(--ae-accent));
    font-size: 14px;
    animation: ae-shine 2s ease-in-out infinite;
}

.ae-message-bubble .ae-numbered-list {
    counter-reset: item;
}

.ae-message-bubble .ae-numbered-list .ae-message-list-item:before {
    content: counter(item) "⭐";
    counter-increment: item;
    position: absolute;
    left: 0;
    top: 6px;
    color: var(--primary-color, var(--ae-primary));
    font-weight: 700;
    font-size: 14px;
    background: linear-gradient(135deg, var(--accent-color, var(--ae-accent)), var(--primary-color, var(--ae-primary)));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.ae-message.ae-message-user .ae-message-bubble .ae-message-list {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), transparent);
    border-left-color: rgba(255, 255, 255, 0.4);
}

.ae-message.ae-message-user .ae-message-bubble .ae-bulleted-list .ae-message-list-item:before {
    color: rgba(255, 255, 255, 0.8);
}

.ae-message.ae-message-user .ae-message-bubble .ae-numbered-list .ae-message-list-item:before {
    color: rgba(255, 255, 255, 0.9);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.6));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Citas con estilo mejorado */
.ae-message-bubble .ae-message-quote {
    margin: 16px 0;
    padding: 16px 20px;
    background: linear-gradient(135deg, rgba(14, 57, 80, 0.1), rgba(78, 222, 128, 0.1));
    border-left: 4px solid var(--primary-color, var(--ae-primary));
    border-radius: 0 12px 12px 0;
    font-style: italic;
    position: relative;
    color: var(--ae-text-secondary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.ae-message-bubble .ae-message-quote:before {
    content: '"';
    position: absolute;
    top: -5px;
    left: 10px;
    font-size: 3em;
    color: var(--primary-color, var(--ae-primary));
    opacity: 0.3;
    font-family: Georgia, serif;
}

.ae-message.ae-message-user .ae-message-bubble .ae-message-quote {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.1));
    border-left-color: rgba(255, 255, 255, 0.4);
    color: rgba(255, 255, 255, 0.9);
}

.ae-message.ae-message-user .ae-message-bubble .ae-message-quote:before {
    color: rgba(255, 255, 255, 0.4);
}

/* Separadores estilizados */
.ae-message-bubble .ae-message-separator {
    border: none;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent-color, var(--ae-accent)), transparent);
    margin: 20px 0;
    border-radius: 1px;
    position: relative;
    overflow: hidden;
}

.ae-message-bubble .ae-message-separator:after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, white, transparent);
    animation: ae-shimmer 2s ease-in-out infinite;
}

.ae-message.ae-message-user .ae-message-bubble .ae-message-separator {
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
}

@keyframes ae-shimmer {
    0% { left: -100%; }
    50% { left: 100%; }
    100% { left: 100%; }
}

@keyframes ae-shine {
    0%, 100% { transform: scale(1); opacity: 0.7; }
    50% { transform: scale(1.2); opacity: 1; }
}

/* Print styles */
@media print {
    .ae-chat-bubble-widget {
        display: none !important;
    }
    
    .ae-chat-widget {
        box-shadow: none !important;
        border: 1px solid #ccc !important;
    }
}