Monthly interest is the remaining balance times the APR divided by 12, rounded to the cent. The payment pays that interest first and the rest reduces the balance. The last payment is smaller if it would otherwise pass zero. $1,000 at 18% APR with a $100 payment takes 11 months and $91.62 of interest. You pay $1,091.62.
A new purchase, a fee, or a rate that changes next month is not in this loop. If the payment is less than or equal to the first month’s interest, the balance does not fall and the page stops.