<!DOCTYPE html>
<html lang="en">
{{--
  Watermarked print page (spec §8 print formatting + audit). Embeds the
  watermarked VIEW route (already stamped for images/pdf) inside a print layout
  and adds a CSS diagonal watermark overlay so the caption survives even on a
  browser print-to-PDF. Auto-opens the print dialog.
--}}
<head>
    <meta charset="utf-8">
    <title>{{ $document->title }}</title>
    <style>
        html, body { margin: 0; }
        .doc-wrap { position: relative; }
        .doc-wrap iframe, .doc-wrap img { width: 100%; min-height: 90vh; border: 0; display: block; }
        .wm { position: fixed; inset: 0; pointer-events: none; opacity: .16; }
        .wm span { position: absolute; transform: rotate(-30deg); font: 600 18px/1 Arial, sans-serif; white-space: nowrap; color: #000; }
        @media print { .no-print { display: none; } }
    </style>
</head>
<body onload="window.print()">
    <div class="no-print" style="padding:8px;font-family:Arial,sans-serif;">
        <button onclick="window.print()">@lang('meddocuments::lang.print')</button>
        <span style="color:#888;">{{ $document->title }}</span>
    </div>
    <div class="doc-wrap">
        @if($version->isImage())
            <img src="{{ $viewUrl }}" alt="{{ $document->title }}">
        @else
            <iframe src="{{ $viewUrl }}"></iframe>
        @endif
        <div class="wm" id="wm"></div>
    </div>
    <script>
        (function () {
            var text = @json($caption);
            var wm = document.getElementById('wm');
            for (var r = 0; r < 14; r++) {
                for (var c = 0; c < 4; c++) {
                    var s = document.createElement('span');
                    s.textContent = text;
                    s.style.top = (r * 80) + 'px';
                    s.style.left = (c * 320) + 'px';
                    wm.appendChild(s);
                }
            }
        })();
    </script>
</body>
</html>
