Grades are only one metric of predicting academic success. To be successful in a PhD program, one needs to be independent, creative, motivated, persistent, and resilient. Hence your application material should demonstrate that you have what it takes to be a successful researcher. So if, for example, your grades suffered because you were focused on research and the research resulted in publications in top conferences or journals, you should be able to have strong recommendation letters and your prospects for admission are most likely very good.
If you don’t have good grades and limited research achievements, it may be hard to convince the reviewers that you have the potential to be a strong PhD student. If you are passionate about doing a PhD, try to work with a faculty on research for a semester/year and then apply for a PhD with a letter from the research mentor. Keep in mind that lower-ranked schools often have top researchers in some areas. Getting admitted to such schools is a little easier and you can still have a good experience getting your PhD.
Conversely, having a perfect GPA does not guarantee admission to competitive graduate programs. Many students applying to top rated PhD programs have a perfect or almost perfect GPA. To get admitted into a top program, your application needs to stand out in other ways that demonstrate your research potential.