```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.")
    
    if not all(isinstance(source, tuple) and len(source) == 2 for source in sources):
        raise ValueError("Each source must be a pair of a positive integer cost and a positive integer stock.")
    
    total_stock = sum(stock for _, stock in sources)
    if total_stock < needed:
        raise ValueError("Total stock cannot cover the order.")
    
    order = sorted(range(len(sources)), key=lambda index: sources[index][0])
    taken = [0] * len(sources)
    cost = 0
    remaining = needed
    
    for index in order:
        if remaining <= 0:
            break
        unit_cost, stock = sources[index]
        if stock > remaining:
            taken[index] = remaining
            cost += remaining * unit_cost
            remaining = 0
        else:
            taken[index] = stock
            cost += stock * unit_cost
            remaining -= stock
    
    leftover = []
    for index in range(len(sources)):
        leftover.append(sources[index][1] - taken[index])
    
    return {"cost": cost, "taken": taken, "leftover": leftover}
```