/**
 * AI Chatbot Styles
 * Sistema de chatbot con IA para landing pages
 * 
 * @version 1.0.0
 * @author Edumedia Tech
 */

/* ============================================
   Variables CSS
   ============================================ */
:root {
    --chatbot-primary: linear-gradient(135deg, #4E5FE8 0%, #3949AB 100%);
    --chatbot-primary-dark: #3949AB;
    --chatbot-secondary: #F59E0B;
    --chatbot-bg: #FFFFFF;
    --chatbot-message-user: #4E5FE8;
    --chatbot-message-assistant: #F3F4F6;
    --chatbot-text: #1F2937;
    --chatbot-text-light: #6B7280;
    --chatbot-border: #E5E7EB;
    --chatbot-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    --chatbot-shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.15);
    --chatbot-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   Botón Flotante
   ============================================ */
/* Contenedor wrapper para el botón y tooltip */
.ai-chatbot-float-wrapper {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9998;
}

.ai-chatbot-float {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--chatbot-primary);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(78, 95, 232, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    overflow: visible;
}

.ai-chatbot-float::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4E5FE8 0%, #3949AB 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
}

.ai-chatbot-float:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 8px 30px rgba(78, 95, 232, 0.6);
}

.ai-chatbot-float:hover::before {
    opacity: 0.3;
    animation: pulse-ring 1.5s ease-out infinite;
}

.ai-chatbot-float:active {
    transform: translateY(-2px) scale(1.02);
}

.ai-chatbot-float.hidden {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

/* Tooltip del botón de chat */
.chatbot-tooltip {
    position: absolute;
    bottom: calc(100% + 12px);
    right: 0;
    background: white;
    color: #1F2937;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    opacity: 0;
    transform: translateY(10px) scale(0.9);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    max-width: 200px;
    line-height: 1.4;
}

.chatbot-tooltip.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.chatbot-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 20px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid white;
}

/* Animación de pulso para el tooltip */
@keyframes tooltip-pulse {
    0%, 100% {
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    }
    50% {
        box-shadow: 0 4px 25px rgba(78, 95, 232, 0.3);
    }
}

.chatbot-tooltip.show {
    animation: tooltip-pulse 2s ease-in-out infinite;
}

/* Icono del chat con animación */
.ai-chatbot-float .chat-icon {
    animation: float-icon 3s ease-in-out infinite;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.ai-chatbot-float .chat-icon circle {
    animation: dots-pulse 1.5s ease-in-out infinite;
}

.ai-chatbot-float .chat-icon circle:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-chatbot-float .chat-icon circle:nth-child(3) {
    animation-delay: 0.4s;
}

.ai-chatbot-float .chat-icon circle:nth-child(4) {
    animation-delay: 0.6s;
}

/* Animaciones */
@keyframes float-icon {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-3px);
    }
}

@keyframes dots-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(0.8);
    }
}

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

/* ============================================
   Wrapper para integración con la página
   ============================================ */
body.chatbot-open {
    margin-right: 400px;
    transition: margin-right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Ajustar elementos fixed al ancho del chatbot */
body.chatbot-open header,
body.chatbot-open .header,
body.chatbot-open .top-bar,
body.chatbot-open .sticky-header,
body.chatbot-open .fixed-top,
body.chatbot-open .countdown-banner,
body.chatbot-open [style*="position: fixed"][style*="top: 0"],
body.chatbot-open [style*="position:fixed"][style*="top:0"] {
    right: 400px !important;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

/* Ajustar width de elementos fixed que ocupan todo el ancho */
body.chatbot-open header,
body.chatbot-open .header,
body.chatbot-open .top-bar,
body.chatbot-open .sticky-header,
body.chatbot-open .fixed-top,
body.chatbot-open .countdown-banner {
    width: calc(100% - 400px) !important;
}

/* ============================================
   Panel del Chatbot - Desktop (Integrado)
   ============================================ */
.ai-chatbot-panel.desktop {
    position: fixed;
    top: 0;
    right: 0;
    width: 400px;
    height: 100vh;
    background: var(--chatbot-bg);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-chatbot-panel.desktop.open {
    transform: translateX(0);
}

/* Resize Handle - Divisor Arrastrable Visible */
.resize-handle {
    position: absolute;
    left: -8px;
    top: 0;
    bottom: 0;
    width: 16px;
    cursor: ew-resize;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.resize-handle::before {
    content: '';
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, 
        transparent 0%, 
        #E5E7EB 10%, 
        #E5E7EB 90%, 
        transparent 100%
    );
    border-radius: 2px;
    transition: all 0.2s ease;
}

.resize-handle::after {
    content: '⋮';
    position: absolute;
    font-size: 24px;
    color: #9CA3AF;
    line-height: 1;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.resize-handle:hover::before {
    background: linear-gradient(180deg, 
        transparent 0%, 
        var(--chatbot-primary-dark) 10%, 
        var(--chatbot-primary-dark) 90%, 
        transparent 100%
    );
    width: 6px;
    box-shadow: 0 0 10px rgba(78, 95, 232, 0.3);
}

.resize-handle:hover::after {
    opacity: 1;
}

.resize-handle:active::before {
    background: linear-gradient(180deg, 
        transparent 0%, 
        #4E5FE8 10%, 
        #4E5FE8 90%, 
        transparent 100%
    );
    box-shadow: 0 0 15px rgba(78, 95, 232, 0.5);
}

/* ============================================
   Panel del Chatbot - Mobile
   ============================================ */
.ai-chatbot-panel.mobile {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 70%;
    background: var(--chatbot-bg);
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-chatbot-panel.mobile.open {
    transform: translateY(0);
}

/* Drag Handle */
.drag-handle {
    width: 100%;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    padding: 8px 0;
}

.drag-handle::before {
    content: '';
    width: 40px;
    height: 4px;
    background: var(--chatbot-border);
    border-radius: 2px;
}

/* ============================================
   Header del Chatbot
   ============================================ */
.chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--chatbot-primary);
    color: white;
    flex-shrink: 0;
}

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

.chatbot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid white;
}

.chatbot-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chatbot-status {
    font-size: 12px;
    opacity: 0.9;
}

.chatbot-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--chatbot-transition);
}

.chatbot-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.chatbot-close svg {
    width: 18px;
    height: 18px;
}

/* ============================================
   Área de Mensajes
   ============================================ */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #F9FAFB;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--chatbot-border);
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: var(--chatbot-text-light);
}

/* Mensaje de Bienvenida */
.chatbot-welcome {
    text-align: center;
    padding: 40px 20px;
}

.welcome-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin-bottom: 16px;
    border: 3px solid var(--chatbot-primary-dark);
}

.chatbot-welcome p {
    color: var(--chatbot-text-light);
    font-size: 14px;
}

/* Mensajes */
.chatbot-message {
    display: flex;
    animation: fadeInUp 0.3s ease-out;
}

.chatbot-message.user {
    justify-content: flex-end;
}

.chatbot-message.assistant {
    justify-content: flex-start;
}

.message-content {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 16px;
    position: relative;
}

.chatbot-message.user .message-content {
    background: var(--chatbot-message-user);
    color: white;
    border-bottom-right-radius: 4px;
}

.chatbot-message.assistant .message-content {
    background: var(--chatbot-message-assistant);
    color: var(--chatbot-text);
    border-bottom-left-radius: 4px;
}

.message-content p {
    margin: 0 0 8px 0;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
}

.message-content p:last-of-type {
    margin-bottom: 0;
}

/* Formato de texto */
.message-content strong {
    font-weight: 600;
    color: inherit;
}

.message-content em {
    font-style: italic;
}

/* Listas en mensajes */
.message-content .chatbot-list {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content .chatbot-list li {
    margin: 4px 0;
    line-height: 1.6;
    font-size: 14px;
}

.message-content ul.chatbot-list {
    list-style-type: disc;
}

.message-content ol.chatbot-list {
    list-style-type: decimal;
}

.message-content br {
    display: block;
    content: "";
    margin: 4px 0;
}

.message-time {
    font-size: 11px;
    opacity: 0.7;
    display: block;
    margin-top: 8px;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Indicador de Escritura */
.chatbot-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--chatbot-message-assistant);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    max-width: 60px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--chatbot-text-light);
    border-radius: 50%;
    animation: typing 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Formulario de Captura de Lead */
.chatbot-lead-form {
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    animation: fadeInUp 0.3s ease-out;
}

.lead-form-header {
    margin-bottom: 12px;
}

.lead-form-header p {
    margin: 0;
    font-size: 14px;
    color: var(--chatbot-text);
    font-weight: 500;
}

.chatbot-lead-form form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chatbot-lead-form input {
    padding: 10px 12px;
    border: 1px solid var(--chatbot-border);
    border-radius: 8px;
    font-size: 14px;
    transition: var(--chatbot-transition);
}

.chatbot-lead-form input:focus {
    outline: none;
    border-color: var(--chatbot-primary-dark);
    box-shadow: 0 0 0 3px rgba(78, 95, 232, 0.1);
}

.chatbot-lead-form button {
    padding: 10px 16px;
    background: var(--chatbot-primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--chatbot-transition);
}

.chatbot-lead-form button:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* Mensaje de pre-carga de datos */
.preload-message {
    background: linear-gradient(135deg, #e8f5e9 0%, #f1f8f4 100%);
    border-left: 4px solid #4caf50;
    padding: 14px 16px;
    margin-bottom: 16px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.5;
    color: #2e7d32;
    animation: slideInDown 0.3s ease-out;
}

.preload-message strong {
    color: #1b5e20;
    font-weight: 600;
}

/* Form groups */
.chatbot-lead-form .form-group {
    margin-bottom: 0;
}

.chatbot-lead-form .lead-submit-btn {
    margin-top: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mensaje de Error */
.chatbot-error {
    text-align: center;
    padding: 20px;
    color: #EF4444;
}

/* ============================================
   Input Container
   ============================================ */
.chatbot-input-container {
    display: flex;
    gap: 8px;
    padding: 16px 20px;
    background: white;
    border-top: 1px solid var(--chatbot-border);
    flex-shrink: 0;
}

.chatbot-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--chatbot-border);
    border-radius: 24px;
    font-size: 14px;
    transition: var(--chatbot-transition);
}

.chatbot-input:focus {
    outline: none;
    border-color: var(--chatbot-primary-dark);
    box-shadow: 0 0 0 3px rgba(78, 95, 232, 0.1);
}

.chatbot-input:disabled {
    background: #F3F4F6;
    cursor: not-allowed;
}

.chatbot-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--chatbot-primary);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--chatbot-transition);
    flex-shrink: 0;
}

.chatbot-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
}

.chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chatbot-send-btn svg {
    width: 20px;
    height: 20px;
    stroke: white;
}

/* ============================================
   Responsive - Mobile
   ============================================ */
@media (max-width: 768px) {
    .ai-chatbot-float-wrapper {
        bottom: 16px;
        right: 16px;
    }
    
    .ai-chatbot-float {
        width: 56px;
        height: 56px;
    }
    
    .ai-chatbot-float img {
        width: 32px;
        height: 32px;
    }
    
    .chatbot-tooltip {
        max-width: 180px;
        font-size: 13px;
        padding: 10px 14px;
        white-space: normal;
        right: -10px;
    }
    
    .chatbot-tooltip::after {
        right: 30px;
    }
    
    .chatbot-header {
        padding: 12px 16px;
    }
    
    .chatbot-messages {
        padding: 16px;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .chatbot-input-container {
        padding: 12px 16px;
    }
}

/* ============================================
   Botones de Opciones (AlanBOT / WhatsApp)
   ============================================ */
.chat-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

.chat-option-button {
    padding: 14px 18px;
    background: white;
    border: 2px solid var(--chatbot-primary-dark);
    color: var(--chatbot-primary-dark);
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--chatbot-transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-align: center;
}

.chat-option-button .option-main {
    display: block;
}

.chat-option-button .option-hours {
    display: block;
    font-size: 11px;
    font-weight: 400;
    opacity: 0.7;
    margin-top: 2px;
}

.chat-option-button:hover:not(:disabled) {
    background: var(--chatbot-primary);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(78, 95, 232, 0.3);
}

.chat-option-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #F3F4F6;
    border-color: #D1D5DB;
    color: #9CA3AF;
}

/* ============================================
   Botón de WhatsApp Persistente
   ============================================ */
.chat-whatsapp-button-container {
    padding: 12px 20px;
    background: #F9FAFB;
    border-top: 1px solid var(--chatbot-border);
}

.chat-whatsapp-button {
    width: 100%;
    padding: 12px 16px;
    background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--chatbot-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 2px 8px rgba(37, 211, 102, 0.3);
}

.chat-whatsapp-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.4);
}

.chat-whatsapp-button:active {
    transform: translateY(0);
}

/* ============================================
   Avatar en mensajes del asistente
   ============================================ */
.chatbot-message.assistant {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.message-avatar {
    font-size: 24px;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-message.assistant .message-content {
    flex: 1;
}

/* ============================================
   Utilidades
   ============================================ */
.chatbot-hidden {
    display: none !important;
}

/* Animaciones adicionales */
@keyframes slideInRight {
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0);
    }
}

@keyframes slideInUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

/* ============================================
   Modal Inicial (Formulario y Opciones)
   ============================================ */
@keyframes slideUpFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes slideDownFadeOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
}

.chatbot-initial-modal {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.chatbot-initial-modal .initial-modal-close:hover {
    background: rgba(255, 255, 255, 0.3) !important;
    transform: rotate(90deg);
}

.chatbot-initial-modal input:focus {
    border-color: #4E5FE8 !important;
    box-shadow: 0 0 0 3px rgba(78, 95, 232, 0.1) !important;
}

