<div class="card-box">
    <div class="card-box-header">
        <h5><i class="fa-solid fa-file-invoice-dollar text-success"></i> Sales Bill Details</h5>
        <div class="d-flex gap-2">
            <a href="<?= site_url('sales_billing/edit/'.$row->id) ?>" class="btn btn-sm btn-edit">
                <i class="fa-solid fa-pen-to-square me-1"></i> Edit
            </a>
            <a href="<?= site_url('sales_billing') ?>" class="btn btn-sm" style="background:#f1f5f9;color:#374151;">
                <i class="fa-solid fa-arrow-left me-1"></i> Back
            </a>
        </div>
    </div>

    <div class="row mb-3">
        <div class="col-md-6">
            <table class="table table-bordered" style="font-size:13.5px;">
                <tr><th width="40%" class="bg-light">Bill No</th><td><code><?= htmlspecialchars($row->bill_no) ?></code></td></tr>
                <tr><th class="bg-light">Customer</th><td><strong><?= htmlspecialchars($row->customer_name) ?></strong></td></tr>
                <tr><th class="bg-light">Mobile</th><td><?= $row->mobile ?></td></tr>
                <tr><th class="bg-light">Address</th><td><?= nl2br(htmlspecialchars($row->address ?: '—')) ?></td></tr>
                <tr><th class="bg-light">Bill Date</th><td><?= date('d M Y', strtotime($row->bill_date)) ?></td></tr>
                <tr><th class="bg-light">Notes</th><td><?= nl2br(htmlspecialchars($row->notes ?: '—')) ?></td></tr>
            </table>
        </div>
        <div class="col-md-4">
            <table class="table table-bordered" style="font-size:13.5px;">
                <tr><th class="bg-light">Sub Total</th><td>₹<?= (int)($row->subtotal) ?></td></tr>
                <tr><th class="bg-light">Discount</th><td class="text-danger">- ₹<?= (int)($row->discount) ?></td></tr>
                <tr><th class="bg-light">Net Payable</th><td><strong class="text-success fs-6">₹<?= (int)($row->net_payable) ?></strong></td></tr>
            </table>
        </div>
    </div>

    <div class="p-3 rounded" style="background:#f8fafc;border:1px solid #e2e8f0;">
        <div class="fw-bold text-muted mb-2" style="font-size:12px;letter-spacing:.8px;text-transform:uppercase;">
            <i class="fa-solid fa-bag-shopping me-1"></i> Items
        </div>
        <div class="table-responsive">
            <table class="table table-bordered mb-0" style="font-size:13px;">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Product</th>
                        <th>Unit</th>
                        <th class="text-end">Qty</th>
                        <th class="text-end">Sale Rate (₹)</th>
                        <th class="text-end">GST %</th>
                        <th class="text-end">Amount (₹)</th>
                        <th class="text-end">Total (₹)</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if(!empty($items)): $i = 1; foreach($items as $item): ?>
                    <tr>
                        <td><?= $i++ ?></td>
                        <td><?= htmlspecialchars($item->product_name) ?></td>
                        <td><small class="text-muted"><?= $item->unit_name ?></small></td>
                        <td class="text-end"><?= (int)($item->qty) ?></td>
                        <td class="text-end">₹<?= (int)($item->rate) ?></td>
                        <td class="text-end"><?= $item->gst_percent ?>%</td>
                        <td class="text-end">₹<?= (int)($item->amount) ?></td>
                        <td class="text-end fw-bold">₹<?= (int)($item->total) ?></td>
                    </tr>
                    <?php endforeach; else: ?>
                    <tr><td colspan="9" class="text-center text-muted">No items found.</td></tr>
                    <?php endif; ?>
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="8" class="text-end fw-bold">Sub Total:</td>
                        <td class="text-end fw-bold">₹<?= (int)($row->subtotal) ?></td>
                    </tr>
                    <tr>
                        <td colspan="8" class="text-end fw-bold text-danger">Discount:</td>
                        <td class="text-end fw-bold text-danger">- ₹<?= (int)($row->discount) ?></td>
                    </tr>
                    <tr class="table-success">
                        <td colspan="8" class="text-end fw-bold">Net Payable:</td>
                        <td class="text-end fw-bold text-success">₹<?= (int)($row->net_payable) ?></td>
                    </tr>
                </tfoot>
            </table>
        </div>
    </div>
</div>