```python
def read_config(text: str) -> dict[str, str]:
    config = {}
    lines = text.splitlines()
    
    for line in lines:
        line = line.strip()
        
        if not line or line.startswith('#'):
            continue
        
        parts = line.split('=', 1)
        
        if len(parts) != 2:
            raise ValueError(f"Invalid format in config: {line}")
        
        key, value = parts
        key = key.strip()
        value = value.strip()
        
        if not key:
            raise ValueError("Key cannot be empty")
        
        config[key] = value
    
    return config
```