<!DOCTYPE html>
<html lang="es">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Pedido #<?php echo (int) $order['id']; ?></title>
	<style>
		body { margin:0; font-family:Segoe UI, sans-serif; background:#f8fafc; color:#0f172a; }
		.wrap { max-width:900px; margin:0 auto; padding:24px 16px; }
		.card { background:#fff; border:1px solid #e2e8f0; border-radius:14px; padding:18px; }
		table { width:100%; border-collapse:collapse; margin-top:10px; }
		th, td { text-align:left; border-bottom:1px solid #e2e8f0; padding:8px; }
		th { color:#64748b; font-size:12px; text-transform:uppercase; }
		a { color:#0b5ecf; text-decoration:none; }
	</style>
</head>
<body>
	<div class="wrap">
		<div class="card">
			<p><a href="<?php echo site_url('catalog/admin'); ?>">&larr; Volver al panel</a></p>
			<h1 style="margin:6px 0 12px;">Pedido #<?php echo (int) $order['id']; ?></h1>
			<p>
				<strong>Cliente:</strong> <?php echo html_escape($order['customer_name']); ?><br>
				<strong>Fecha:</strong> <?php echo html_escape($order['ordered_at']); ?><br>
				<strong>Venta suspendida:</strong> #<?php echo (int) $order['sale_id']; ?><br>
				<strong>Sucursal/Empleado:</strong> L<?php echo (int) $order['location_id']; ?> / E<?php echo (int) $order['employee_id']; ?><br>
				<strong>Total:</strong> <?php echo html_escape($currency_symbol . number_format((float)$order['total'], 2)); ?><br>
				<strong>Reportes:</strong>
				<a href="<?php echo site_url('catalog/admin/orders/'.(int)$order['id'].'/csv'); ?>">CSV</a> |
				<a href="<?php echo site_url('catalog/admin/orders/'.(int)$order['id'].'/pdf'); ?>">PDF</a>
			</p>

			<?php if (trim((string)$order['customer_note']) !== ''): ?>
				<p><strong>Nota cliente:</strong><br><?php echo nl2br(html_escape($order['customer_note'])); ?></p>
			<?php endif; ?>

			<table>
				<thead>
					<tr>
						<th>ID Item</th>
						<th>Producto</th>
						<th>Cantidad</th>
						<th>Precio</th>
						<th>Total</th>
					</tr>
				</thead>
				<tbody>
				<?php foreach ($items as $item): ?>
					<tr>
						<td><?php echo (int) $item['item_id']; ?></td>
						<td><?php echo html_escape($item['item_name']); ?></td>
						<td><?php echo (float) $item['quantity']; ?></td>
						<td><?php echo html_escape($currency_symbol . number_format((float)$item['unit_price'], 2)); ?></td>
						<td><?php echo html_escape($currency_symbol . number_format((float)$item['line_total'], 2)); ?></td>
					</tr>
				<?php endforeach; ?>
				</tbody>
			</table>
		</div>
	</div>
</body>
</html>
