int totalPages(int totalItems) { if (totalItems == 0) return 1; return math.max(1, (totalItems / pageSize).ceil()); }