/* Widget Chatbot Flotante */
#chatbot-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: 'Space Grotesk', sans-serif;
}

/* Botón flotante */
.chatbot-boton-flotante {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2f6e3c 0%, #234d2c 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(27, 46, 31, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    color: white;
    font-size: 24px;
}

.chatbot-boton-flotante:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(27, 46, 31, 0.4);
}

.chatbot-boton-flotante.activo {
    background: linear-gradient(135deg, #a8d28a 0%, #6ba84f 100%);
}

/* Ventana del chat */
.chatbot-ventana {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 30px rgba(27, 46, 31, 0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

.chatbot-ventana.visible {
    display: flex;
}

/* Tarea guiada en curso */
.chatbot-ventana.chatbot-en-flujo {
    box-shadow: 0 5px 30px rgba(47, 110, 60, 0.35);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Encabezado */
.chatbot-cabeza {
    background: linear-gradient(135deg, #2f6e3c 0%, #234d2c 100%);
    color: white;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #d8dfca;
}

.chatbot-cabeza-textos {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.chatbot-titulo {
    font-weight: 600;
    font-size: 1rem;
}

/* Progreso de una tarea guiada (ej. "Paso 3 de 7") */
.chatbot-progreso {
    font-size: 0.7rem;
    opacity: 0.85;
    letter-spacing: 0.03em;
}

.chatbot-progreso:empty {
    display: none;
}

.chatbot-cerrar {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.chatbot-cerrar:hover {
    opacity: 0.8;
}

/* Área de mensajes */
.chatbot-mensajes {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chatbot-mensaje {
    padding: 10px 14px;
    border-radius: 8px;
    max-width: 90%;
    word-wrap: break-word;
    font-size: 0.85rem;
    line-height: 1.4;
}

.chatbot-mensaje.usuario {
    align-self: flex-end;
    background: linear-gradient(135deg, #6ba84f 0%, #2f6e3c 100%);
    color: white;
    border-bottom-right-radius: 2px;
}

.chatbot-mensaje.asistente {
    align-self: flex-start;
    background: #f0f0f0;
    color: #1b2e1f;
    border-bottom-left-radius: 2px;
}

.chatbot-mensaje.chatbot-escribiendo {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
}

.chatbot-mensaje.chatbot-escribiendo span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #2f6e3c;
    opacity: 0.4;
    animation: chatbotEscribiendoRebote 1s infinite ease-in-out;
}

.chatbot-mensaje.chatbot-escribiendo span:nth-child(2) {
    animation-delay: 0.15s;
}

.chatbot-mensaje.chatbot-escribiendo span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes chatbotEscribiendoRebote {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* Respuesta con botón */
.chatbot-respuesta {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chatbot-texto {
    margin: 0;
    white-space: pre-wrap;
}

.chatbot-boton {
    background: linear-gradient(135deg, #6ba84f 0%, #2f6e3c 100%);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    text-decoration: none;
    text-align: center;
    transition: opacity 0.2s;
    display: inline-block;
}

.chatbot-boton:hover {
    opacity: 0.9;
}

.chatbot-boton:disabled {
    opacity: 0.45;
    cursor: default;
}

.chatbot-boton-suave {
    background: none;
    color: #2f6e3c;
    border: 1px solid #d8dfca;
}

.chatbot-boton-suave:disabled {
    color: #8a9a8d;
}

/* Botonera de un paso guiado */
.chatbot-flujo-controles {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chatbot-flujo-controles .chatbot-boton {
    flex: 1 1 auto;
}

/* Archivo adjuntado por el usuario */
.chatbot-adjunto {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chatbot-adjunto-nombre {
    font-size: 0.8rem;
    word-break: break-all;
}

.chatbot-adjunto-preview {
    max-width: 160px;
    border-radius: 6px;
    display: block;
}

.chatbot-imagen {
    max-width: 100%;
    border-radius: 6px;
    margin-top: 8px;
}

.chatbot-archivo-oculto {
    display: none !important;
}

/* Barra de entrada */
.chatbot-entrada {
    padding: 12px;
    border-top: 1px solid #d8dfca;
    display: flex;
    gap: 8px;
    background: white;
}

.chatbot-input {
    flex: 1;
    border: 1px solid #d8dfca;
    border-radius: 20px;
    padding: 8px 14px;
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
}

.chatbot-input:focus {
    border-color: #2f6e3c;
}

.chatbot-enviar {
    background: linear-gradient(135deg, #6ba84f 0%, #2f6e3c 100%);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: opacity 0.2s;
}

.chatbot-enviar:hover {
    opacity: 0.9;
}

.chatbot-enviar:active {
    transform: scale(0.95);
}

/* Scrollbar personalizada */
.chatbot-mensajes::-webkit-scrollbar {
    width: 6px;
}

.chatbot-mensajes::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chatbot-mensajes::-webkit-scrollbar-thumb {
    background: #2f6e3c;
    border-radius: 3px;
}

.chatbot-mensajes::-webkit-scrollbar-thumb:hover {
    background: #234d2c;
}

/* Responsive */
@media (max-width: 620px) {
    /* El ancho fijo de 380px se sale en un telefono de 360px.
       Se ajusta al ancho real y se deja fuera de la barra de
       gestos del sistema. */
    .chatbot-ventana {
        width: calc(100vw - 24px);
        max-width: 100%;
        height: min(70dvh, 520px);
        right: 12px;
        left: auto;
        bottom: calc(76px + env(safe-area-inset-bottom));
    }

    .chatbot-boton-flotante {
        width: 52px;
        height: 52px;
    }

    #chatbot-widget {
        right: 14px;
        bottom: calc(14px + env(safe-area-inset-bottom));
    }
}
