<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Kuitansi {{ $pembayaran->nomor_invoice }}</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * { box-sizing: border-box; margin: 0; padding: 0; }

        body {
            font-family: 'Segoe UI', Arial, sans-serif;
            background: #f1f5f9;
            padding: 2rem 1rem;
            color: #0f172a;
            font-size: 14px;
            line-height: 1.5;
        }

        .kuitansi {
            background: #fff;
            max-width: 680px;
            margin: 0 auto;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 8px 30px rgba(0,0,0,0.12);
        }

        /* Header */
        .kuitansi-header {
            background: linear-gradient(135deg, #0d9488, #14b8a6);
            color: #fff;
            padding: 1.5rem 2rem;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .klinik-logo { display: flex; align-items: center; gap: 0.875rem; }
        .klinik-icon {
            width: 44px; height: 44px;
            background: rgba(255,255,255,0.2);
            border-radius: 10px;
            display: flex; align-items: center; justify-content: center;
            font-size: 1.25rem;
        }
        .klinik-name { font-size: 1rem; font-weight: 700; }
        .klinik-sub  { font-size: 0.75rem; opacity: 0.85; }
        .invoice-badge {
            text-align: right;
        }
        .invoice-label { font-size: 0.7rem; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.05em; }
        .invoice-number { font-size: 1rem; font-weight: 700; }
        .invoice-date { font-size: 0.75rem; opacity: 0.85; }

        /* Status bar */
        .status-bar {
            background: #f0fdf4;
            border-bottom: 1px solid #bbf7d0;
            padding: 0.6rem 2rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            font-size: 0.8rem;
            color: #166534;
            font-weight: 600;
        }

        /* Body */
        .kuitansi-body { padding: 1.5rem 2rem; }

        /* Info Grid */
        .info-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 1rem 2rem;
            margin-bottom: 1.5rem;
        }
        .info-item {}
        .info-label {
            font-size: 0.7rem;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            color: #64748b;
            margin-bottom: 0.2rem;
        }
        .info-value { font-size: 0.875rem; font-weight: 600; color: #0f172a; }

        /* Rincian Table */
        .rincian-title {
            font-size: 0.75rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            color: #64748b;
            margin-bottom: 0.5rem;
            padding-bottom: 0.5rem;
            border-bottom: 2px solid #e2e8f0;
        }
        .rincian-table { width: 100%; border-collapse: collapse; }
        .rincian-table td { padding: 0.5rem 0; font-size: 0.875rem; }
        .rincian-table .label { color: #475569; }
        .rincian-table .value { text-align: right; font-weight: 500; color: #0f172a; }
        .rincian-table .divider td { border-top: 1px solid #e2e8f0; }
        .rincian-table .total-row td { padding-top: 0.75rem; }
        .rincian-table .total-row .label { font-weight: 700; font-size: 0.95rem; color: #0f172a; }
        .rincian-table .total-row .value { font-weight: 800; font-size: 1.1rem; color: #0d9488; }
        .rincian-table .diskon .value { color: #ef4444; }

        /* Metode badge */
        .metode-badge {
            display: inline-flex;
            align-items: center;
            gap: 0.35rem;
            padding: 0.25rem 0.75rem;
            border-radius: 100px;
            font-size: 0.75rem;
            font-weight: 600;
            background: #f0fdf4;
            color: #166534;
            border: 1px solid #bbf7d0;
            margin-top: 1rem;
        }

        /* Footer */
        .kuitansi-footer {
            margin-top: 1.5rem;
            padding-top: 1rem;
            border-top: 1px solid #e2e8f0;
            display: flex;
            justify-content: space-between;
            align-items: flex-end;
        }
        .ttd-box { text-align: center; }
        .ttd-label { font-size: 0.75rem; color: #64748b; margin-bottom: 4rem; }
        .ttd-name { font-size: 0.8rem; font-weight: 600; color: #0f172a; border-top: 1px solid #94a3b8; padding-top: 0.4rem; min-width: 130px; }

        .footer-note {
            background: #f8fafc;
            padding: 0.75rem 2rem;
            text-align: center;
            font-size: 0.7rem;
            color: #94a3b8;
            border-top: 1px solid #e2e8f0;
        }

        /* Print button */
        .print-btn {
            display: block;
            width: fit-content;
            margin: 1.5rem auto 0;
            padding: 0.625rem 1.5rem;
            background: linear-gradient(135deg, #14b8a6, #0d9488);
            color: #fff;
            font-weight: 600;
            font-size: 0.875rem;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            box-shadow: 0 4px 12px rgba(20,184,166,0.3);
        }
        .print-btn:hover { opacity: 0.9; }

        @media print {
            body { background: #fff; padding: 0; }
            .kuitansi { box-shadow: none; border-radius: 0; max-width: 100%; }
            .print-btn { display: none; }
        }
    </style>
</head>
<body>

<div class="kuitansi">

    {{-- Header --}}
    <div class="kuitansi-header">
        <div class="klinik-logo">
            <div class="klinik-icon"><i class="fas fa-heartbeat"></i></div>
            <div>
                <div class="klinik-name">{{ env('APP_NAMA_KLINIK', 'Klinik Kesehatan Digital') }}</div>
                <div class="klinik-sub">Sistem Informasi Kesehatan</div>
            </div>
        </div>
        <div class="invoice-badge">
            <div class="invoice-label">Kuitansi Pembayaran</div>
            <div class="invoice-number">{{ $pembayaran->nomor_invoice }}</div>
            <div class="invoice-date">{{ $pembayaran->waktu_konfirmasi?->format('d/m/Y H:i') }}</div>
        </div>
    </div>

    {{-- Status Bar --}}
    <div class="status-bar">
        <i class="fas fa-check-circle"></i>
        LUNAS — Pembayaran telah dikonfirmasi oleh {{ $pembayaran->dikonfirmasiOleh->name ?? 'Admin' }}
    </div>

    {{-- Body --}}
    <div class="kuitansi-body">

        {{-- Info Grid --}}
        <div class="info-grid">
            <div class="info-item">
                <div class="info-label">Nama Pasien</div>
                <div class="info-value">{{ $pembayaran->pasien->nama_lengkap ?? '-' }}</div>
            </div>
            <div class="info-item">
                <div class="info-label">No. Rekam Medis</div>
                <div class="info-value">{{ $pembayaran->pasien->no_rekam_medis ?? '-' }}</div>
            </div>
            <div class="info-item">
                <div class="info-label">Dokter</div>
                <div class="info-value">{{ $pembayaran->dokter->nama_lengkap ?? '-' }}</div>
            </div>
            <div class="info-item">
                <div class="info-label">No. Konsultasi</div>
                <div class="info-value">{{ $pembayaran->dokterPasien->nomor_konsultasi ?? '-' }}</div>
            </div>
            <div class="info-item">
                <div class="info-label">Tanggal Layanan</div>
                <div class="info-value">{{ $pembayaran->dokterPasien->created_at?->format('d/m/Y') ?? '-' }}</div>
            </div>
            <div class="info-item">
                <div class="info-label">Waktu Konfirmasi</div>
                <div class="info-value">{{ $pembayaran->waktu_konfirmasi?->format('d/m/Y H:i') ?? '-' }}</div>
            </div>
        </div>

        {{-- Rincian Biaya --}}
        <div class="rincian-title">Rincian Biaya</div>
        <table class="rincian-table">
            <tr>
                <td class="label">Biaya Konsultasi</td>
                <td class="value">Rp {{ number_format($pembayaran->biaya_konsultasi, 0, ',', '.') }}</td>
            </tr>
            @if($pembayaran->biaya_tambahan > 0)
            <tr>
                <td class="label">
                    Biaya Tambahan
                    @if($pembayaran->keterangan_biaya_tambahan)
                        <small style="color:#94a3b8">({{ $pembayaran->keterangan_biaya_tambahan }})</small>
                    @endif
                </td>
                <td class="value">Rp {{ number_format($pembayaran->biaya_tambahan, 0, ',', '.') }}</td>
            </tr>
            @endif
            @if($pembayaran->diskon > 0)
            <tr class="diskon">
                <td class="label">Diskon</td>
                <td class="value">- Rp {{ number_format($pembayaran->diskon, 0, ',', '.') }}</td>
            </tr>
            @endif
            <tr class="divider"><td colspan="2"></td></tr>
            <tr class="total-row">
                <td class="label">Total Dibayar</td>
                <td class="value">Rp {{ number_format($pembayaran->total_bayar, 0, ',', '.') }}</td>
            </tr>
        </table>

        {{-- Metode --}}
        <div>
            <span class="metode-badge">
                @if($pembayaran->metode_pembayaran === 'QRIS')
                    <i class="fas fa-qrcode"></i> QRIS
                @else
                    <i class="fas fa-money-bill-wave"></i> Tunai
                    @if($pembayaran->tunai_kembalian > 0)
                        | Kembalian: Rp {{ number_format($pembayaran->tunai_kembalian, 0, ',', '.') }}
                    @endif
                @endif
            </span>
        </div>

        {{-- TTD --}}
        <div class="kuitansi-footer">
            <div class="ttd-box">
                <div class="ttd-label">Diterima oleh</div>
                <div class="ttd-name">{{ $pembayaran->pasien->nama_lengkap ?? '_____________' }}</div>
            </div>
            <div class="ttd-box">
                <div class="ttd-label">Kasir / Admin</div>
                <div class="ttd-name">{{ $pembayaran->dikonfirmasiOleh->name ?? '_____________' }}</div>
            </div>
        </div>
    </div>

    {{-- Footer Note --}}
    <div class="footer-note">
        Kuitansi ini merupakan bukti pembayaran yang sah. Simpan sebagai arsip.
        &nbsp;|&nbsp; {{ env('APP_NAMA_KLINIK', 'Klinik Kesehatan Digital') }} &nbsp;|&nbsp; Dicetak: {{ now()->format('d/m/Y H:i') }}
    </div>

</div>

<button class="print-btn" onclick="window.print()">
    <i class="fas fa-print mr-2"></i>Cetak Kuitansi
</button>

<script>
    // Auto print saat halaman sudah siap (opsional)
    // window.onload = () => window.print();
</script>
</body>
</html>