```python
def fill_order(sources: list, needed: int) -> dict:
    if not isinstance(needed, int) or needed <= 0:
        raise ValueError("Needed must be a positive integer")
    
    for source in sources:
        if not (isinstance(source, tuple) and len(source) == 2):
            raise ValueError("Each source must be a pair of cost and stock")
        unit_cost, stock = source
        if not (isinstance(unit_cost, int) and isinstance(stock, int) and unit_cost > 0 and stock > 0):
            raise ValueError("Cost and stock must be positive integers")
    
    total_stock = sum(source[1] for source in sources)
    if total_stock < needed:
        raise ValueError("Not enough stock to fulfill the order")
    
    order = sorted(range(len(sources)), key=lambda index: (sources[index][0], index))
    taken = [0] * len(sources)
    cost = 0
    remaining = needed
    
    for index in order:
        if remaining <= 0:
            break
        unit_cost, stock = sources[index]
        units_to_take = min(stock, remaining)
        taken[index] = units_to_take
        cost += units_to_take * unit_cost
        remaining -= units_to_take
    
    leftover = [source[1] - taken[i] for i, source in enumerate(sources)]
    
    return {"cost": cost, "taken": taken, "leftover": leftover}
```