graph TB
    UPLOAD["Admin Uploads<br/>Source Documents<br/>(PDF, DOCX, etc.)"] --> STORE["Store in<br/>File Storage"]
    STORE --> TRIGGER["Trigger<br/>Processing Job"]

    TRIGGER --> PARSE["Parse Documents<br/>(LlamaParse API)"]
    PARSE --> MD["Parsed Markdown<br/>per Document"]

    MD --> COMBINE["Combine All<br/>Parsed Markdown"]
    COMBINE --> DISTIL["Distil via Gemini<br/>(Generate Spec)"]

    DISTIL --> SPEC["New Spec Version<br/>(Versioned Content)"]
    SPEC --> ACTIVATE["Set as Active<br/>Spec Version"]

    ACTIVATE --> CACHE["Invalidate<br/>Reference Docs Cache"]
    CACHE --> AGENTS["Agents Use<br/>Updated Specs"]

    subgraph "5 Knowledge Base Types"
        direction LR
        KB1["Legal<br/>Compliance"]
        KB2["Barclays<br/>Brand"]
        KB3["Barclaycard<br/>Brand"]
        KB4["Channel<br/>Best Practices"]
        KB5["Channel<br/>Tech Specs"]
    end

    subgraph "Processing Job Tracking"
        direction LR
        S1["pending"]
        S1 --> S2["parsing"]
        S2 --> S3["distilling"]
        S3 --> S4["completed"]
        S2 -.-> S5["failed"]
        S3 -.-> S5
    end

    classDef upload fill:#006DE3,stroke:#1A2142,color:#fff
    classDef process fill:#1A2142,stroke:#006DE3,color:#fff
    classDef output fill:#C3FB5A,stroke:#1A2142,color:#1A2142
    classDef cache fill:#01A1A2,stroke:#1A2142,color:#fff
    classDef kb fill:#7A0FF9,stroke:#1A2142,color:#fff
    classDef status fill:#FFBA00,stroke:#1A2142,color:#1A2142
    classDef failed fill:#E3000F,stroke:#1A2142,color:#fff

    class UPLOAD upload
    class STORE,TRIGGER,PARSE,MD,COMBINE,DISTIL process
    class SPEC,ACTIVATE output
    class CACHE,AGENTS cache
    class KB1,KB2,KB3,KB4,KB5 kb
    class S1,S2,S3,S4 status
    class S5 failed
