<div class="ticket-content" style="font-family:'Courier New',monospace;font-size:12px;background:#fff;color:#000;width:100%;max-width:320px;margin:0 auto;padding:8px;">
    <div style="text-align:center;margin-bottom:8px;">
        <h2 style="margin:0;font-size:16px;letter-spacing:2px;"><i class="bi bi-shop"></i> VelMox</h2>
        <p style="margin:2px 0;font-size:10px;color:#555;">Ticket de Venta #<?= $sale['id_venta'] ?></p>
    </div>
    <hr style="border:none;border-top:1px dashed #000;margin:6px 0;">
    <div style="font-size:10px;margin-bottom:6px;">
        <span style="display:block;">Fecha: <?= date('d/m/Y H:i', strtotime($sale['fecha'])) ?></span>
        <span style="display:block;">Vendedor: <?= $sale['username'] ?></span>
        <span style="display:block;">Forma de Pago: 
            <?php if (!empty($sale['payments'])): ?>
                <?php foreach ($sale['payments'] as $p): ?>
                    <?= ucfirst($p['forma_pago_nombre']) ?>
                <?php endforeach; ?>
            <?php endif; ?>
        </span>
        <?php if (!empty($sale['observaciones'])): ?>
        <span style="display:block;">Obs: <?= esc($sale['observaciones']) ?></span>
        <?php endif; ?>
    </div>
    <hr style="border:none;border-top:1px dashed #000;margin:6px 0;">
    <table style="width:100%;border-collapse:collapse;font-size:10px;">
        <thead>
            <tr>
                <th style="text-align:left;border-bottom:1px dashed #000;padding:3px 0;">Prod</th>
                <th style="text-align:center;border-bottom:1px dashed #000;padding:3px 0;">Cat</th>
                <th style="text-align:right;border-bottom:1px dashed #000;padding:3px 0;">P.U.</th>
                <th style="text-align:right;border-bottom:1px dashed #000;padding:3px 0;">Total</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($sale['details'] as $d): ?>
            <tr>
                <td style="padding:2px 0;"><?= esc($d['producto_nombre']) ?> x<?= $d['cantidad'] ?></td>
                <td style="text-align:center;padding:2px 0;"><?= esc($d['codigo_unico']) ?></td>
                <td style="text-align:right;padding:2px 0;"><?= number_format($d['precio_unitario'], 2) ?></td>
                <td style="text-align:right;padding:2px 0;"><?= number_format($d['subtotal'], 2) ?></td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
    <hr style="border:none;border-top:1px dashed #000;margin:6px 0;">
    <table style="width:100%;border-collapse:collapse;font-size:10px;">
        <tr>
            <td style="font-weight:bold;padding:2px 0;">TOTAL</td>
            <td style="text-align:right;font-weight:bold;padding:2px 0;">S/ <?= number_format($sale['total'], 2) ?></td>
        </tr>
        <tr style="font-size:9px;color:#555;">
            <td style="padding:1px 0;">Base Imponible</td>
            <td style="text-align:right;padding:1px 0;">S/ <?= number_format($sale['total'] / 1.18, 2) ?></td>
        </tr>
        <tr style="font-size:9px;color:#555;">
            <td style="padding:1px 0;">IGV (18%)</td>
            <td style="text-align:right;padding:1px 0;">S/ <?= number_format($sale['total'] * 0.18 / 1.18, 2) ?></td>
        </tr>
    </table>
    <hr style="border:none;border-top:1px dashed #000;margin:6px 0;">
    <div style="text-align:center;margin-top:10px;font-size:9px;color:#777;">
        <p style="margin:2px 0;">Gracias por su compra!</p>
        <p style="margin:2px 0;">VelMox - Todos los derechos reservados</p>
    </div>
</div>