<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Label — {{ $ticket->ticket_code }}</title>
    <style>
        /* ─── Reset ─────────────────────── */
        * { margin: 0; padding: 0; box-sizing: border-box; }

        /* ─── Print page size: 50mm × 30mm ─ */
        @page {
            size: 50mm 30mm;
            margin: 0;
        }

        html, body {
            width:  50mm;
            height: 30mm;
            background: #fff;
            font-family: 'Arial', sans-serif;
            -webkit-print-color-adjust: exact;
            print-color-adjust: exact;
        }

        /* ─── Label wrapper ──────────────── */
        .label {
            width:  50mm;
            height: 30mm;
            padding: 2mm 2.5mm;
            display: flex;
            flex-direction: row;
            align-items: stretch;
            gap: 2mm;
            border: 0.3mm solid #e5e7eb;
        }

        /* ─── Left: text content ─────────── */
        .label-text {
            flex: 1;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            overflow: hidden;
            min-width: 0;
        }

        .label-header {
            display: flex;
            align-items: center;
            gap: 1mm;
        }

        .label-brand {
            font-size: 4.5pt;
            font-weight: 700;
            color: #1d4ed8;
            text-transform: uppercase;
            letter-spacing: 0.3pt;
            white-space: nowrap;
        }

        .label-divider {
            flex: 1;
            height: 0.3mm;
            background: #d1d5db;
            margin: 1.2mm 0;
        }

        .label-ticket {
            font-size: 6pt;
            font-weight: 700;
            font-family: 'Courier New', monospace;
            color: #111827;
            letter-spacing: 0.4pt;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .label-customer {
            font-size: 5.5pt;
            font-weight: 600;
            color: #374151;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            margin-top: 0.8mm;
        }

        .label-device {
            font-size: 5pt;
            color: #6b7280;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            margin-top: 0.5mm;
        }

        .label-bottom {
            margin-top: auto;
            padding-top: 1mm;
            border-top: 0.2mm solid #f3f4f6;
        }

        .label-date {
            font-size: 4pt;
            color: #9ca3af;
        }

        /* ─── Right: QR Code ─────────────── */
        .label-qr {
            flex-shrink: 0;
            width: 24mm;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 0.8mm;
        }

        .label-qr svg {
            width:  22mm;
            height: 22mm;
            display: block;
        }

        .label-qr-hint {
            font-size: 3.5pt;
            color: #9ca3af;
            text-align: center;
            line-height: 1.2;
        }

        /* ─── Screen preview (tidak tercetak) */
        @media screen {
            body {
                background: #f3f4f6;
                display: flex;
                align-items: center;
                justify-content: center;
                min-height: 100vh;
                width: auto;
                height: auto;
            }

            .label {
                box-shadow: 0 4px 24px rgba(0,0,0,0.12);
                border-radius: 2mm;
                transform: scale(3.5);
                transform-origin: center center;
            }

            .print-btn {
                position: fixed;
                bottom: 24px;
                right: 24px;
                background: #2563eb;
                color: #fff;
                border: none;
                border-radius: 12px;
                padding: 12px 24px;
                font-size: 14px;
                font-weight: 600;
                cursor: pointer;
                box-shadow: 0 4px 14px rgba(37,99,235,0.4);
                display: flex;
                align-items: center;
                gap: 8px;
                font-family: Arial, sans-serif;
            }
            .print-btn:hover { background: #1d4ed8; }
            .back-btn {
                position: fixed;
                bottom: 24px;
                left: 24px;
                background: #fff;
                color: #374151;
                border: 1px solid #d1d5db;
                border-radius: 12px;
                padding: 12px 20px;
                font-size: 14px;
                font-weight: 500;
                cursor: pointer;
                font-family: Arial, sans-serif;
                text-decoration: none;
                display: flex;
                align-items: center;
                gap: 6px;
            }
        }

        @media print {
            .print-btn, .back-btn { display: none !important; }
            body { background: #fff !important; }
            .label { transform: none; box-shadow: none; border-radius: 0; }
        }
    </style>
</head>
<body>

<div class="label">
    {{-- ── Teks Kiri ── --}}
    <div class="label-text">
        <div>
            <div class="label-header">
                <span class="label-brand">Service Center</span>
            </div>
            <div class="label-divider"></div>

            <div class="label-ticket">{{ $ticket->ticket_code }}</div>
            <div class="label-customer">{{ $ticket->customer->name }}</div>
            <div class="label-device">
                {{ $ticket->brand }} {{ $ticket->model }}
            </div>
            @if($ticket->serial_number)
            <div class="label-device" style="margin-top:0.4mm; font-size:3.8pt;">
                S/N: {{ $ticket->serial_number }}
            </div>
            @endif
        </div>

        <div class="label-bottom">
            <div class="label-date">{{ $ticket->created_at->format('d/m/Y') }}</div>
        </div>
    </div>

    {{-- ── QR Code Kanan ── --}}
    <div class="label-qr">
        {!! QrCode::format('svg')
              ->size(80)
              ->margin(0)
              ->color(17, 24, 39)
              ->backgroundColor(255, 255, 255)
              ->errorCorrection('M')
              ->generate($qrUrl) !!}
        <span class="label-qr-hint">Scan untuk<br>cek status</span>
    </div>
</div>

{{-- Tombol (hanya tampil di layar, tidak tercetak) --}}
<a class="back-btn" href="{{ route('tickets.show', $ticket->id) }}">
    ← Kembali
</a>
<button class="print-btn" onclick="window.print()">
    <svg width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
              d="M17 17h2a2 2 0 002-2v-4a2 2 0 00-2-2H5a2 2 0 00-2 2v4a2 2 0 002 2h2m2 4h6a2 2 0 002-2v-4a2 2 0 00-2-2H9a2 2 0 00-2 2v4a2 2 0 002 2zm8-12V5a2 2 0 00-2-2H9a2 2 0 00-2 2v4h10z"/>
    </svg>
    Cetak Label
</button>

</body>
</html>
