```python
def fill_order(sources: list, needed: int) -> dict:
    """
    Plans how an order for needed units is covered from a list of sources.
    Each source is a [cost, stock] pair: the price of one unit and the units it holds.
    Returns a mapping with cost, total paid; taken, one entry per source in the given order;
    and leftover, one entry per source saying how many units it still holds.
    Raises ValueError for invalid inputs.
    """
    if not isinstance(needed, int) or needed <= 0:
        raise ValueError("Needed must be a positive integer.")
    
    if not all(isinstance(source, list) 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 across all sources cannot cover the needed amount.")
    
    order = sorted(range(len(sources)), key=lambda index: sources[index][0])
    taken = [0] * len(sources)
    cost = 0
    remaining = needed
    
    for index in order(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}
```