/* =================== 
   Chatbot Flotante ACE - Estilos Modernos
   =================== */

/* Variables CSS para el chatbot */
:root {
    --chatbot-primary: #515964;
    --chatbot-secondary: #778da9;
    --chatbot-light: #e0e1dd;
    --chatbot-success: #10b981;
    --chatbot-radius: 16px;
    --chatbot-shadow: 0 8px 32px rgba(81, 89, 100, 0.3);
    --chatbot-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* Contenedor principal del chatbot */
.chatbot-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: var(--chatbot-font);
}

/* Botón flotante */
.chatbot-toggle {
    position: relative;
    background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-secondary) 100%);
    color: white;
    border-radius: 50px;
    padding: 15px 20px;
    cursor: pointer;
    box-shadow: var(--chatbot-shadow);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 10px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    min-width: 60px;
    justify-content: center;
}

.chatbot-toggle:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 12px 40px rgba(81, 89, 100, 0.4);
    background: linear-gradient(135deg, #415a77 0%, #515964 100%);
}

.chatbot-toggle.hidden {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
    pointer-events: none;
}

.chatbot-toggle.bounce-in {
    animation: bounceIn 0.8s ease-out;
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3) translateY(50px);
    }
    50% {
        opacity: 1;
        transform: scale(1.1) translateY(-10px);
    }
    70% {
        transform: scale(0.9) translateY(5px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Icono del chatbot */
.chatbot-icon {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bot-icon {
    width: 24px;
    height: 24px;
    color: white;
}

.pulse-indicator {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

.chatbot-text {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

/* Ventana del chatbot */
.chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 500px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chatbot-window.active {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* Header del chatbot */
.chatbot-header {
    background: white;
    color: var(--chatbot-primary);
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #e9ecef;
}

.chatbot-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bot-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
}

.bot-avatar svg {
    width: 20px;
    height: 20px;
    color: white;
}

.bot-info h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--chatbot-primary);
}

.bot-status {
    margin: 0;
    font-size: 12px;
    opacity: 0.7;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--chatbot-primary);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.status-dot.online {
    background: #10b981;
    animation: glow 2s ease-in-out infinite alternate;
}

@keyframes glow {
    from {
        box-shadow: 0 0 5px #10b981;
    }
    to {
        box-shadow: 0 0 15px #10b981;
    }
}

.chatbot-controls {
    display: flex;
    gap: 8px;
}

.control-btn {
    width: 32px;
    height: 32px;
    background: rgba(81, 89, 100, 0.1);
    border: none;
    border-radius: 8px;
    color: var(--chatbot-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.control-btn:hover {
    background: rgba(81, 89, 100, 0.2);
    transform: scale(1.1);
}

.control-btn svg {
    width: 16px;
    height: 16px;
}

/* Área de mensajes */
.chatbot-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8fafc;
}

.chatbot-messages::-webkit-scrollbar {
    width: 4px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 2px;
}

/* Mensajes */
.message {
    display: flex;
    gap: 8px;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
}

.message.animate-in {
    opacity: 1;
    transform: translateY(0);
}

.message.user-message {
    flex-direction: row-reverse;
    align-self: flex-end;
}

.message-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #515964 0%, #415a77 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message-avatar svg {
    width: 16px;
    height: 16px;
    color: white;
}

.message-content {
    max-width: 80%;
}

.message-bubble {
    background: white;
    padding: 12px 16px;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    font-size: 14px;
    line-height: 1.5;
    /* Predeterminado (afinaremos por tipo de mensaje) */
    word-break: normal;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    hyphens: auto;
    -webkit-hyphens: auto;
    -ms-hyphens: auto;
    font-family: var(--chatbot-font);
}

.user-message .message-bubble {
    background: linear-gradient(135deg, #515964 0%, #415a77 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.bot-message .message-bubble {
    border-bottom-left-radius: 4px;
}

/* Evitar cortes raros en textos cortos del usuario */
.user-message .message-bubble {
    /* Colapsar espacios y no cortar dentro de palabras salvo overflow real */
    white-space: normal;
    word-break: keep-all;
    overflow-wrap: break-word; /* solo si la palabra es más larga que el contenedor */
    hyphens: manual; /* no autohifenar en usuario */
    display: inline-block;
}

/* Mantener formato (saltos de línea/listas) en respuestas del bot */
.bot-message .message-bubble {
    white-space: pre-wrap;
    word-break: normal;
    overflow-wrap: break-word;
    hyphens: auto;
}

.message-time {
    font-size: 11px;
    color: #64748b;
    margin-top: 4px;
    text-align: right;
}

.user-message .message-time {
    text-align: left;
}

/* Sugerencias rápidas */
.quick-suggestions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.suggestion-btn {
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #475569;
}

.suggestion-btn:hover {
    border-color: #515964;
    background: #f8fafc;
    transform: translateX(4px);
}

/* Indicador de escritura */
.typing-indicator {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 12px;
    color: #64748b;
    background: #f1f5f9;
    border-radius: 8px;
    margin-bottom: 8px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typing 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}

/* Área de input */
.chatbot-input-area {
    background: white;
    border-top: 1px solid #e2e8f0;
    padding: 16px;
}

.input-container {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#chatbot-input {
    flex: 1;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 14px;
    resize: none;
    outline: none;
    transition: all 0.2s ease;
    font-family: inherit;
}

#chatbot-input:focus {
    border-color: #515964;
    box-shadow: 0 0 0 3px rgba(81, 89, 100, 0.1);
}

.send-btn {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #515964 0%, #415a77 100%);
    border: none;
    border-radius: 12px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(81, 89, 100, 0.3);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.send-btn svg {
    width: 20px;
    height: 20px;
}

/* Responsive */
@media (max-width: 480px) {
    .chatbot-window {
        width: 100vw;
        height: 100vh;
        bottom: 0;
        right: 0;
        border-radius: 0;
        position: fixed;
    }
    
    .chatbot-toggle {
        bottom: 20px;
        right: 20px;
    }
}

@media (max-width: 420px) {
    .chatbot-toggle .chatbot-text {
        display: none;
    }
    
    .chatbot-toggle {
        width: 60px;
        height: 60px;
        border-radius: 50%;
        padding: 0;
    }
}
