```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Lead Intake API Documentation</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <style>
        body {
            margin: 0;
            font-family: Inter, Arial, sans-serif;
            background: #f6f8fb;
            color: #172033;
        }

        .container {
            max-width: 980px;
            margin: 0 auto;
            padding: 48px 24px;
        }

        .hero {
            background: linear-gradient(135deg, #172033, #31415f);
            color: white;
            padding: 36px;
            border-radius: 18px;
            margin-bottom: 28px;
        }

        .hero h1 {
            margin: 0 0 12px;
            font-size: 34px;
        }

        .hero p {
            margin: 0;
            color: #dbe5ff;
            font-size: 16px;
        }

        .card {
            background: white;
            border-radius: 16px;
            padding: 28px;
            margin-bottom: 22px;
            box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
        }

        h2 {
            margin-top: 0;
            color: #172033;
        }

        h3 {
            margin-top: 24px;
            color: #172033;
        }

        code, pre {
            background: #0f172a;
            color: #e5e7eb;
            border-radius: 12px;
        }

        code {
            padding: 3px 7px;
            white-space: nowrap;
        }

        pre {
            padding: 18px;
            overflow-x: auto;
            line-height: 1.5;
        }

        .method {
            display: inline-block;
            background: #16a34a;
            color: white;
            padding: 6px 10px;
            border-radius: 8px;
            font-weight: 700;
            margin-right: 8px;
        }

        .note {
            background: #fff7ed;
            border-left: 4px solid #f97316;
            padding: 14px 16px;
            border-radius: 10px;
            margin: 16px 0;
        }

        .success {
            background: #f0fdf4;
            border-left: 4px solid #16a34a;
            padding: 14px 16px;
            border-radius: 10px;
            margin: 16px 0;
        }

        .danger {
            background: #fef2f2;
            border-left: 4px solid #dc2626;
            padding: 14px 16px;
            border-radius: 10px;
            margin: 16px 0;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 14px;
        }

        th, td {
            padding: 12px;
            border-bottom: 1px solid #e5e7eb;
            text-align: left;
            vertical-align: top;
        }

        th {
            background: #f8fafc;
        }

        .badge {
            display: inline-block;
            padding: 4px 8px;
            border-radius: 999px;
            font-size: 12px;
            font-weight: 700;
        }

        .badge-required {
            background: #fee2e2;
            color: #991b1b;
        }

        .badge-conditional {
            background: #fef3c7;
            color: #92400e;
        }

        .badge-optional {
            background: #e0f2fe;
            color: #075985;
        }

        .toc a {
            display: block;
            color: #172033;
            text-decoration: none;
            margin: 8px 0;
        }

        .toc a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
<div class="container">

    <section class="hero">
        <h1>Lead Intake API</h1>
        <p>Use this API to submit new client leads and automatically create the associated claim.</p>
    </section>

    <section class="card toc">
        <h2>Contents</h2>
        <a href="#endpoint">Endpoint</a>
        <a href="#authentication">Authentication</a>
        <a href="#request-body">Request Body</a>
        <a href="#name-fields">Name Fields</a>
        <a href="#example-requests">Example Requests</a>
        <a href="#success-response">Success Response</a>
        <a href="#error-responses">Error Responses</a>
        <a href="#curl-example">cURL Example</a>
        <a href="#important-notes">Important Notes</a>
    </section>

    <section class="card" id="endpoint">
        <h2>Endpoint</h2>
        <p>
            <span class="method">POST</span>
            <code>/api/leads/{key}</code>
        </p>

        <p>
            The <code>{key}</code> is your unique endpoint key. This identifies the endpoint, solicitor and lead source configuration.
        </p>

        <pre>https://ha.fintrixor.co.uk/api/leads/YOUR_ENDPOINT_KEY</pre>
    </section>

    <section class="card" id="authentication">
        <h2>Authentication</h2>
        <p>Authentication requires both:</p>

        <ul>
            <li>An active endpoint key in the URL: <code>/api/leads/{key}</code></li>
            <li>A valid API key sent as a bearer token</li>
        </ul>

        <p>Send the API key using the <code>Authorization</code> header:</p>

        <pre>Authorization: Bearer YOUR_API_KEY</pre>

        <div class="note">
            Invalid or inactive endpoint keys return <strong>404 Not Found</strong>.
            Missing or invalid API keys return <strong>401 Unauthorized</strong>.
        </div>
    </section>

    <section class="card" id="request-body">
        <h2>Request Body</h2>

        <p>
            The request body must be sent as JSON using the <code>Content-Type: application/json</code> header.
        </p>

        <table>
            <thead>
            <tr>
                <th>Field</th>
                <th>Required</th>
                <th>Type</th>
                <th>Example</th>
                <th>Notes</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td><code>reference</code></td>
                <td><span class="badge badge-optional">Optional</span></td>
                <td>string</td>
                <td>EXT-123</td>
                <td>Your external reference for the lead.</td>
            </tr>
            <tr>
                <td><code>full_name</code></td>
                <td><span class="badge badge-conditional">Conditional</span></td>
                <td>string</td>
                <td>Mr John Edward Smith</td>
                <td>Required if <code>first_name</code> and <code>last_name</code> are not provided.</td>
            </tr>
            <tr>
                <td><code>title</code></td>
                <td><span class="badge badge-optional">Optional</span></td>
                <td>string</td>
                <td>Mr</td>
                <td>Can also be extracted from <code>full_name</code> if supplied.</td>
            </tr>
            <tr>
                <td><code>first_name</code></td>
                <td><span class="badge badge-conditional">Conditional</span></td>
                <td>string</td>
                <td>John</td>
                <td>Required with <code>last_name</code> if <code>full_name</code> is not provided.</td>
            </tr>
            <tr>
                <td><code>middle_name</code></td>
                <td><span class="badge badge-optional">Optional</span></td>
                <td>string|null</td>
                <td>Edward</td>
                <td>Optional middle name.</td>
            </tr>
            <tr>
                <td><code>last_name</code></td>
                <td><span class="badge badge-conditional">Conditional</span></td>
                <td>string</td>
                <td>Smith</td>
                <td>Required with <code>first_name</code> if <code>full_name</code> is not provided.</td>
            </tr>
            <tr>
                <td><code>preferred_name</code></td>
                <td><span class="badge badge-optional">Optional</span></td>
                <td>string|null</td>
                <td>Johnny</td>
                <td>Optional preferred name.</td>
            </tr>
            <tr>
                <td><code>dob</code></td>
                <td><span class="badge badge-optional">Optional</span></td>
                <td>date</td>
                <td>1985-05-20</td>
                <td>Use <code>YYYY-MM-DD</code> format.</td>
            </tr>
            <tr>
                <td><code>landline_number</code></td>
                <td><span class="badge badge-optional">Optional</span></td>
                <td>string</td>
                <td>01511234567</td>
                <td>Must be a valid UK landline number.</td>
            </tr>
            <tr>
                <td><code>email</code></td>
                <td><span class="badge badge-required">Required</span></td>
                <td>string</td>
                <td>john@example.com</td>
                <td>Must be a valid email address.</td>
            </tr>
            <tr>
                <td><code>phone_number</code></td>
                <td><span class="badge badge-required">Required</span></td>
                <td>string</td>
                <td>+447123456789</td>
                <td>Spaces are removed automatically.</td>
            </tr>
            <tr>
                <td><code>what_type_of_care_were_you_in</code></td>
                <td><span class="badge badge-optional">Optional</span></td>
                <td>string|null</td>
                <td>Foster care</td>
                <td>If supplied, this is saved as a note against the client.</td>
            </tr>
            <tr>
                <td><code>anything_you_wish_to_tell_us</code></td>
                <td><span class="badge badge-optional">Optional</span></td>
                <td>string|null</td>
                <td>I moved between several foster placements.</td>
                <td>If supplied, this is saved as a note against the client.</td>
            </tr>
            </tbody>
        </table>
    </section>

    <section class="card" id="name-fields">
        <h2>Name Fields</h2>

        <p>
            The API accepts names in one of two formats.
        </p>

        <h3>Option 1: Send <code>full_name</code></h3>

        <p>
            Use this when the lead provider stores the client name as a single field.
        </p>

        <pre>{
  "full_name": "Mr John Smith"
}</pre>

        <p>
            The API will attempt to split the full name into:
        </p>

        <ul>
            <li><code>title</code>: Mr</li>
            <li><code>first_name</code>: John</li>
            <li><code>last_name</code>: Smith</li>
        </ul>

        <h3>Option 2: Send <code>first_name</code> and <code>last_name</code></h3>

        <p>
            Use this when the lead provider stores first and last names separately.
        </p>

        <pre>{
  "first_name": "John",
  "last_name": "Smith"
}</pre>

        <div class="danger">
            A request must include either <strong>full_name</strong>, or both <strong>first_name</strong> and <strong>last_name</strong>.
            Sending only a first name or only a last name will return a <strong>422 Validation Error</strong>.
        </div>

        <h3>Supported titles in <code>full_name</code></h3>

        <p>
            The following titles are recognised when supplied at the start of <code>full_name</code>:
        </p>

        <pre>Mr, Mrs, Ms, Miss, Dr, Prof, Rev, Sir, Lady, Lord, Mx</pre>
    </section>

    <section class="card" id="example-requests">
        <h2>Example Requests</h2>

        <h3>Example using first and last name</h3>

        <pre>{
  "reference": "EXT-123",
  "title": "Mr",
  "first_name": "John",
  "middle_name": null,
  "last_name": "Smith",
  "preferred_name": null,
  "dob": "1985-05-20",
  "email": "john@example.com",
  "phone": "+447123456789",
  "what_type_of_care_were_you_in": "Foster care",
  "anything_you_wish_to_tell_us": "I moved between several foster placements."
}</pre>

        <h3>Example using full name</h3>

        <pre>{
  "reference": "EXT-124",
  "full_name": "Ms Jane Smith",
  "dob": "1990-03-14",
  "email": "jane@example.com",
  "phone": "+447987654321",
  "what_type_of_care_were_you_in": "Residential care",
  "anything_you_wish_to_tell_us": null
}</pre>
    </section>

    <section class="card" id="success-response">
        <h2>Success Response</h2>

        <p>Status: <code>201 Created</code></p>

        <div class="success">
            A successful request creates both a Client and a Claim.
        </div>

        <pre>{
  "success": true,
  "message": "Client and claim created successfully.",
  "data": {
    "client_id": 123,
    "claim_id": 456,
    "reference": "EXT-123"
  }
}</pre>
    </section>

    <section class="card" id="error-responses">
        <h2>Error Responses</h2>

        <h3>401 Unauthorized</h3>

        <p>
            Returned when the API key is missing, invalid or inactive.
        </p>

        <pre>{
  "message": "Unauthorized."
}</pre>

        <h3>404 Not Found</h3>

        <p>
            Returned when the endpoint key is invalid or inactive.
        </p>

        <pre>{
  "message": "Endpoint not found."
}</pre>

        <h3>422 Validation Error</h3>

        <p>
            Returned when the submitted data does not pass validation.
        </p>

        <pre>{
  "message": "The given data was invalid.",
  "errors": {
    "name": [
      "Either full name or both first name and last name are required."
    ]
  }
}</pre>

        <h3>422 Validation Error: Missing last name</h3>

        <pre>{
  "message": "The given data was invalid.",
  "errors": {
    "name": [
      "The name must include both a first name and last name."
    ]
  }
}</pre>

        <h3>422 Validation Error: Invalid phone</h3>

        <pre>{
  "message": "The given data was invalid.",
  "errors": {
    "phone": [
      "The phone format is invalid."
    ]
  }
}</pre>
    </section>

    <section class="card" id="curl-example">
        <h2>cURL Example</h2>

        <h3>Using first and last name</h3>

        <pre>curl -X POST https://ha.fintrixor.co.uk/api/leads/YOUR_ENDPOINT_KEY \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "reference": "EXT-123",
    "title": "Mr",
    "first_name": "John",
    "last_name": "Smith",
    "dob": "1985-05-20",
    "email": "john@example.com",
    "phone": "+447123456789"
  }'</pre>

        <h3>Using full name</h3>

        <pre>curl -X POST https://ha.fintrixor.co.uk/api/leads/YOUR_ENDPOINT_KEY \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "reference": "EXT-124",
    "full_name": "Ms Jane Smith",
    "dob": "1990-03-14",
    "email": "jane@example.com",
    "phone": "+447987654321"
  }'</pre>
    </section>

    <section class="card" id="important-notes">
        <h2>Important Notes</h2>

        <ul>
            <li>The API creates both a Client and Claim.</li>
            <li>Solicitor and Lead Source are resolved automatically from the endpoint key.</li>
            <li>Do not send <code>solicitor_id</code>, <code>lead_source_id</code>, or <code>lead_source_endpoint_id</code>.</li>
            <li>Names are automatically trimmed, whitespace-normalised and title-cased.</li>
            <li>Email addresses are automatically lowercased.</li>
            <li>Spaces are automatically removed from phone numbers.</li>
            <li>Optional care-related answers are saved as notes against the client.</li>
        </ul>
    </section>

</div>
</body>
</html>
```
