<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <style>
        @page {
            margin: 15mm 28mm 28mm 28mm;
        }

        * { box-sizing: border-box; margin: 0; padding: 0; }

        body {
            font-family: 'DejaVu Sans', Arial, sans-serif;
            font-size: 10.5pt;
            color: #1a1a1a;
            line-height: 1.55;
        }

        /* ── Letterhead ─────────────────────────────────────── */
        .letterhead {
            text-align: right;
            padding-bottom: 12px;
            margin-bottom: 30px;
        }
        .letterhead img {
            max-height: 70px;
            max-width: 220px;
        }
        .letterhead .firm-name {
            font-size: 22pt;
            font-weight: bold;
            color: #1a1a1a;
            letter-spacing: -1px;
        }

        /* ── Address + Date row ─────────────────────────────── */
        .address-date-row {
            display: table;
            width: 100%;
            margin-bottom: 26px;
        }
        .recipient-block {
            display: table-cell;
            width: 58%;
            vertical-align: top;
            font-size: 10.5pt;
            line-height: 1.75;
        }
        .recipient-block .institution-name {
            font-weight: bold;
        }
        .recipient-block .no-address {
            color: #aaa;
            font-style: italic;
            font-size: 9pt;
        }
        .date-block {
            display: table-cell;
            width: 42%;
            vertical-align: top;
            text-align: right;
            font-size: 10.5pt;
            color: #333;
        }

        /* ── Subject / Ref ──────────────────────────────────── */
        .subject-line {
            margin-bottom: 18px;
        }
        .subject-line .label {
            font-weight: bold;
            font-size: 10.5pt;
        }
        .subject-line .ref {
            font-size: 9.5pt;
            color: #555;
            margin-top: 2px;
        }

        /* ── Body ───────────────────────────────────────────── */
        .dsar-content {
            font-size: 9pt;
            line-height: 1.7;
            color: #1a1a1a;
        }
        .dsar-content p { margin-bottom: 10px; }

        {{--
            Footer is NOT rendered in this HTML document.
            It is injected via Browsershot's native footerHtml() template so that
            Chrome renders it in the bottom-margin zone on every page at the OS level.
            See DsarService::buildPdf() for the footer HTML string.
        --}}
    </style>
</head>
<body>

    {{-- ── Letterhead: logo right-aligned ─────────────────── --}}
    <div class="letterhead">
        @if($solicitorLogoUrl)
            <img src="{{ $solicitorLogoUrl }}" alt="{{ $solicitor?->name }}">
        @else
            <div class="firm-name">{{ $solicitor?->name ?? 'Unknown Solicitor' }}</div>
        @endif
    </div>

    {{-- ── Recipient address (envelope window) + Date ─────── --}}
    <div class="address-date-row">
        <div class="recipient-block">
            <span class="institution-name">{{ $institution?->display_name ?? 'Unknown Institution' }}</span><br>
            @if($institutionAddress)
                @foreach(['line_1','line_2','line_3','line_4','line_5','line_6'] as $line)
                    @if(!empty($institutionAddress->$line))
                        {{ $institutionAddress->$line }}<br>
                    @endif
                @endforeach
                @if($institutionAddress->postcode)
                    {{ $institutionAddress->postcode }}
                @endif
            @else
                <span class="no-address">No address on record</span>
            @endif
        </div>
        <div class="date-block">
            Date {{ now()->format('d/m/Y') }}
        </div>
    </div>

    {{-- ── Subject / Ref ────────────────────────────────────── --}}
    <div class="subject-line">
        <div class="ref">
            Ref: {{ $dsar->claim->client->displayId }}
        </div>
    </div>

    {{-- ── Body ─────────────────────────────────────────────── --}}
    <div class="dsar-content">
        {!! $dsar->content !!}
    </div>

</body>
</html>
