/* ================================================================
   CHATBOT WIDGET - OFERTAPP
   Burbuja flotante con chat integrado
   ================================================================ */

:root {
    --chat-primary: #ff6b6b;
    --chat-primary-dark: #e63946;
    --chat-secondary: #667eea;
    --chat-success: #28a745;
    --chat-bg: #ffffff;
    --chat-bg-secondary: #f7fafc;
    --chat-text: #2d3748;
    --chat-text-light: #718096;
    --chat-border: #e2e8f0;
    --chat-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --chat-bubble-size: 60px;
    --chat-width: 380px;
    --chat-height: 520px;
    --chat-radius: 20px;
    --chat-z-index: 9999;
}

/* ================================================================
   CONTENEDOR PRINCIPAL
   ================================================================ */

.chatbot-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: var(--chat-z-index);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ================================================================
   BURBUJA FLOTANTE
   ================================================================ */

.chatbot-bubble {
    width: var(--chat-bubble-size);
    height: var(--chat-bubble-size);
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-dark) 100%);
    box-shadow: var(--chat-shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    outline: none;
    position: relative;
}

.chatbot-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 15px 50px rgba(255, 107, 107, 0.4);
}

.chatbot-bubble:active {
    transform: scale(0.95);
}

.chatbot-bubble i {
    font-size: 1.5rem;
    color: white;
    transition: transform 0.3s ease;
}

.chatbot-bubble.open i.fa-comments {
    display: none;
}

.chatbot-bubble.open i.fa-times {
    display: block;
}

.chatbot-bubble:not(.open) i.fa-times {
    display: none;
}

/* Indicador de mensajes nuevos */
.chatbot-bubble-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 22px;
    height: 22px;
    background: var(--chat-success);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: white;
    border: 2px solid white;
    animation: pulse-badge 2s infinite;
}

@keyframes pulse-badge {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Tooltip de la burbuja */
.chatbot-tooltip {
    position: absolute;
    right: calc(100% + 15px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--chat-text);
    color: white;
    padding: 0.6rem 1rem;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    pointer-events: none;
}

.chatbot-tooltip::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    border-left: 6px solid var(--chat-text);
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
}

.chatbot-bubble:hover .chatbot-tooltip {
    opacity: 1;
    visibility: visible;
}

.chatbot-bubble.open .chatbot-tooltip {
    display: none;
}

/* ================================================================
   VENTANA DEL CHAT
   ================================================================ */

.chatbot-window {
    position: absolute;
    bottom: calc(var(--chat-bubble-size) + 15px);
    right: 0;
    width: var(--chat-width);
    height: var(--chat-height);
    background: var(--chat-bg);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chatbot-window.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ================================================================
   HEADER DEL CHAT
   ================================================================ */

.chatbot-header {
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-dark) 100%);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: white;
    flex-shrink: 0;
}

.chatbot-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.chatbot-info {
    flex: 1;
}

.chatbot-name {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.15rem;
}

.chatbot-status {
    font-size: 0.8rem;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.chatbot-status-dot {
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chatbot-header-actions {
    display: flex;
    gap: 0.5rem;
}

.chatbot-header-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.chatbot-header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ================================================================
   ÁREA DE MENSAJES
   ================================================================ */

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: var(--chat-bg-secondary);
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--chat-border);
    border-radius: 3px;
}

/* Mensaje individual */
.chat-message {
    display: flex;
    gap: 0.5rem;
    max-width: 85%;
    animation: messageIn 0.3s ease;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message.bot {
    align-self: flex-start;
}

.chat-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.9rem;
}

.chat-message.bot .chat-message-avatar {
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    color: white;
}

.chat-message.user .chat-message-avatar {
    background: var(--chat-secondary);
    color: white;
}

.chat-message-content {
    padding: 0.75rem 1rem;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-message.bot .chat-message-content {
    background: white;
    color: var(--chat-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.chat-message.user .chat-message-content {
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    color: white;
    border-bottom-right-radius: 4px;
}

/* Markdown en mensajes */
.chat-message-content strong {
    font-weight: 600;
}

.chat-message-content ul,
.chat-message-content ol {
    margin: 0.5rem 0;
    padding-left: 1.25rem;
}

.chat-message-content li {
    margin-bottom: 0.25rem;
}

/* ================================================================
   MENSAJE DE BIENVENIDA CON OPCIONES
   ================================================================ */

.chat-welcome {
    padding: 0.5rem;
}

.chat-welcome-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.chat-option-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    background: white;
    border: 2px solid var(--chat-border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.chat-option-btn:hover {
    border-color: var(--chat-primary);
    background: rgba(255, 107, 107, 0.05);
    transform: translateX(5px);
}

.chat-option-btn i {
    font-size: 1.5rem;
    color: var(--chat-primary);
}

.chat-option-text {
    flex: 1;
}

.chat-option-title {
    font-weight: 600;
    color: var(--chat-text);
    font-size: 0.95rem;
}

.chat-option-desc {
    font-size: 0.8rem;
    color: var(--chat-text-light);
}

/* ================================================================
   INDICADOR DE ESCRITURA
   ================================================================ */

.chat-typing {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: white;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.chat-typing-dots {
    display: flex;
    gap: 4px;
}

.chat-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--chat-text-light);
    border-radius: 50%;
    animation: typingDot 1.4s infinite ease-in-out;
}

.chat-typing-dot:nth-child(1) { animation-delay: 0s; }
.chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

/* ================================================================
   INPUT DEL CHAT
   ================================================================ */

.chatbot-input-area {
    padding: 1rem;
    background: white;
    border-top: 1px solid var(--chat-border);
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    flex-shrink: 0;
}

.chatbot-input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    background: var(--chat-bg-secondary);
    border: 2px solid var(--chat-border);
    border-radius: 24px;
    padding: 0 1rem;
    transition: border-color 0.2s ease;
}

.chatbot-input-wrapper:focus-within {
    border-color: var(--chat-primary);
}

.chatbot-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0.75rem 0;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--chat-text);
    outline: none;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
}

.chatbot-input::placeholder {
    color: var(--chat-text-light);
}

.chatbot-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chatbot-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.4);
}

.chatbot-send-btn:active {
    transform: scale(0.95);
}

.chatbot-send-btn:disabled {
    background: var(--chat-border);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ================================================================
   FOOTER CON ACCIONES RÁPIDAS
   ================================================================ */

.chatbot-quick-actions {
    padding: 0.5rem 1rem;
    background: white;
    border-top: 1px solid var(--chat-border);
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.quick-action-btn {
    padding: 0.4rem 0.75rem;
    background: var(--chat-bg-secondary);
    border: 1px solid var(--chat-border);
    border-radius: 16px;
    font-size: 0.75rem;
    color: var(--chat-text-light);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.quick-action-btn:hover {
    background: var(--chat-primary);
    color: white;
    border-color: var(--chat-primary);
}

/* ================================================================
   FEEDBACK DE MENSAJE
   ================================================================ */

.chat-message-feedback {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chat-message:hover .chat-message-feedback {
    opacity: 1;
}

.feedback-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--chat-bg-secondary);
    border: 1px solid var(--chat-border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: var(--chat-text-light);
    transition: all 0.2s ease;
}

.feedback-btn:hover {
    background: var(--chat-primary);
    color: white;
    border-color: var(--chat-primary);
}

.feedback-btn.active {
    background: var(--chat-success);
    color: white;
    border-color: var(--chat-success);
}

/* ================================================================
   RESPONSIVE
   ================================================================ */

@media (max-width: 480px) {
    .chatbot-container {
        bottom: 15px;
        right: 15px;
    }
    
    .chatbot-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: calc(100% - 60px);
        border-radius: var(--chat-radius) var(--chat-radius) 0 0;
        max-height: none;
    }
    
    .chatbot-bubble {
        width: 55px;
        height: 55px;
    }
    
    .chatbot-bubble i {
        font-size: 1.3rem;
    }
    
    .chatbot-tooltip {
        display: none;
    }
    
    .chatbot-header {
        padding: 1rem;
    }
    
    .chatbot-avatar {
        width: 40px;
        height: 40px;
    }
}

/* ================================================================
   ANIMACIONES ADICIONALES
   ================================================================ */

@keyframes bounceIn {
    0% { transform: scale(0); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.chatbot-bubble {
    animation: bounceIn 0.5s ease 0.5s both;
}

/* Estado de carga */
.chatbot-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--chat-text-light);
}

.chatbot-loading i {
    font-size: 2rem;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Enlace de ayuda */
.chat-help-link {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--chat-primary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.chat-help-link:hover {
    color: var(--chat-primary-dark);
    text-decoration: underline;
}

.chatbot-container {
    right: auto !important;
    left: 20px;
}

.chatbot-window {
    right: auto;
    left: 0;
}

.chatbot-tooltip {
    right: auto;
    left: calc(100% + 15px);
}

.chatbot-tooltip::after {
    right: auto;
    left: -6px;
    border-left: none;
    border-right: 6px solid #2d3748;
}

/* ================================================================
   AJUSTE MÓVIL - Subir chatbot para evitar solape con barra catálogo
   Agregar en chatbot.css
   ================================================================ */

@media (max-width: 768px) {
    .chatbot-container {
        bottom: 90px; /* Subir por encima de la barra del catálogo */
    }
}

/* ================================================================
   FIX: CONSISTENCIA POSICIÓN CHATBOT EN 480px
   ================================================================ */

@media (max-width: 480px) {
    .chatbot-container {
        left: 15px !important;
        right: auto !important;
        bottom: 15px;
    }
}

/* ================================================================
   FIX: POSICIÓN CHATBOT - POR ENCIMA DE FLOATING CATALOG
   ================================================================ */

.chatbot-container {
    bottom: 100px !important;
    left: 20px !important;
}

@media (max-width: 768px) {
    .chatbot-container {
        bottom: 100px !important;
        left: 20px !important;
    }
}

@media (max-width: 480px) {
    .chatbot-container {
        bottom: 90px !important;
        left: 15px !important;
    }
}