<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{{ $documentTitle ?? '' }}</title>
    <style>
        *, *::before, *::after { box-sizing: border-box; }

        body {
            margin: 0;
            padding: 24px;
            font-family: "Microsoft YaHei", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
            font-size: 12px;
            line-height: 1.5;
            color: #111;
            background: #f3f4f6;
        }

        .print-page {
            max-width: 210mm;
            margin: 0 auto;
            padding: 16mm 14mm;
            background: #fff;
            box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
            position: relative;
        }

        .print-toolbar {
            display: flex;
            gap: 8px;
            margin-bottom: 16px;
            max-width: 210mm;
            margin-left: auto;
            margin-right: auto;
        }

        .print-toolbar button {
            padding: 8px 16px;
            font-size: 13px;
            border: 1px solid #d1d5db;
            border-radius: 6px;
            background: #fff;
            cursor: pointer;
        }

        .print-toolbar button.primary {
            background: #111827;
            color: #fff;
            border-color: #111827;
        }

        .company-header {
            text-align: center;
            margin-bottom: 20px;
            border-bottom: 2px solid #111;
            padding-bottom: 12px;
        }

        .company-header h1 {
            margin: 0 0 6px;
            font-size: 20px;
            font-weight: 700;
        }

        .company-header .meta {
            font-size: 11px;
            color: #4b5563;
        }

        .document-title {
            text-align: center;
            font-size: 18px;
            font-weight: 700;
            margin: 0 0 8px;
        }

        .document-status {
            text-align: center;
            font-size: 13px;
            margin-bottom: 16px;
            color: #374151;
        }

        .void-watermark {
            position: absolute;
            top: 45%;
            left: 50%;
            transform: translate(-50%, -50%) rotate(-30deg);
            font-size: 72px;
            font-weight: 700;
            color: rgba(220, 38, 38, 0.18);
            pointer-events: none;
            user-select: none;
            z-index: 1;
            white-space: nowrap;
        }

        .print-content {
            position: relative;
            z-index: 2;
        }

        .print-footer {
            margin-top: 24px;
            padding-top: 8px;
            border-top: 1px solid #e5e7eb;
            font-size: 10px;
            color: #6b7280;
            text-align: right;
        }

        @page {
            size: A4;
            margin: 14mm 12mm;
        }

        @media print {
            body {
                background: #fff;
                padding: 0;
            }

            .print-toolbar {
                display: none !important;
            }

            .print-page {
                box-shadow: none;
                max-width: none;
                margin: 0;
                padding: 0;
            }
        }
    </style>
</head>
<body>
    <div class="print-toolbar no-print">
        <button type="button" class="primary" onclick="window.print()">{{ __('dberp.print.actions.print') }}</button>
        <button type="button" onclick="window.close()">{{ __('dberp.print.actions.close') }}</button>
    </div>

    <div class="print-page">
        @if (! empty($showVoidWatermark))
            <div class="void-watermark" aria-hidden="true">{{ __('dberp.print.labels.watermark_voided') }}</div>
        @endif

        <header class="company-header">
            <h1>{{ $company['name'] ?? '' }}</h1>
            @if (! empty($company['address']) || ! empty($company['phone']) || ! empty($company['email']))
                <div class="meta">
                    @if (! empty($company['address']))
                        <span>{{ $company['address'] }}</span>
                    @endif
                    @if (! empty($company['phone']))
                        <span>@if (! empty($company['address'])) · @endif{{ $company['phone'] }}</span>
                    @endif
                    @if (! empty($company['email']))
                        <span>@if (! empty($company['address']) || ! empty($company['phone'])) · @endif{{ $company['email'] }}</span>
                    @endif
                </div>
            @endif
        </header>

        <h2 class="document-title">{{ $documentTitle ?? '' }}</h2>
        @if (! empty($statusLabel))
            <div class="document-status">{{ __('dberp.print.labels.document_status') }}：{{ $statusLabel }}</div>
        @endif

        <div class="print-content">
            @yield('content')
        </div>

        <footer class="print-footer">
            {{ __('dberp.print.labels.print_time') }}：{{ isset($printTime) ? $printTime->format('Y-m-d H:i:s') : now()->format('Y-m-d H:i:s') }}
        </footer>
    </div>

    <script>
        window.addEventListener('load', function () {
            if (window.matchMedia('print').matches) {
                return;
            }

            setTimeout(function () {
                window.print();
            }, 300);
        });
    </script>
</body>
</html>
