<div class="card-box">
    <div class="card-box-header">
        <h5><i class="fa-solid fa-shirt text-warning"></i> Tailoring Order Details</h5>
        <div class="d-flex gap-2">
            <a href="<?= site_url('tailoring_order/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('tailoring_order') ?>" class="btn btn-sm" style="background:#f1f5f9;color:#374151;">
                <i class="fa-solid fa-arrow-left me-1"></i> Back
            </a>
        </div>
    </div>

    <?php
    $status_colors = [
        'Pending'     => ['bg' => '#fef3c7', 'color' => '#d97706'],
        'In Progress' => ['bg' => '#dbeafe', 'color' => '#2563eb'],
        'Ready'       => ['bg' => '#d1fae5', 'color' => '#059669'],
        'Delivered'   => ['bg' => '#dcfce7', 'color' => '#16a34a'],
        'Cancelled'   => ['bg' => '#fee2e2', 'color' => '#dc2626'],
    ];
    $sc = $status_colors[$row->order_status] ?? ['bg' => '#f1f5f9', 'color' => '#64748b'];
    ?>

    <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">Order No</th><td><code><?= htmlspecialchars($row->order_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">Order Date</th><td><?= date('d M Y', strtotime($row->order_date)) ?></td></tr>
                <tr><th class="bg-light">Delivery Date</th><td><?= date('d M Y', strtotime($row->delivery_date)) ?></td></tr>
                <tr><th class="bg-light">Status</th>
                    <td>
                        <span style="background:<?= $sc['bg'] ?>;color:<?= $sc['color'] ?>;padding:3px 12px;border-radius:12px;font-size:12px;font-weight:700;">
                            <?= $row->order_status ?>
                        </span>
                    </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">Total Charge</th><td><strong class="text-warning fs-6">₹<?= (int)($row->total_charge) ?></strong></td></tr>
                <tr><th class="bg-light">Advance Paid</th><td>₹<?= (int)($row->advance_paid) ?></td></tr>
                <tr><th class="bg-light">Balance Due</th>
                    <td><strong class="text-danger">₹<?= (int)($row->total_charge - $row->advance_paid) ?></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-shirt me-1"></i> Garment Items
        </div>
        <div class="table-responsive">
            <table class="table table-bordered mb-0" style="font-size:13px;">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Garment Type</th>
                        <th>Description / Measurements</th>
                        <th class="text-center">Qty</th>
                        <th class="text-end">Rate (₹)</th>
                        <th class="text-end">Amount (₹)</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if(!empty($items)): $i = 1; foreach($items as $item): ?>
                    <tr>
                        <td><?= $i++ ?></td>
                        <td><strong><?= htmlspecialchars($item->garment_type) ?></strong></td>
                        <td><?= nl2br(htmlspecialchars($item->description ?: '—')) ?></td>
                        <td class="text-center"><?= $item->qty ?></td>
                        <td class="text-end">₹<?= (int)($item->rate) ?></td>
                        <td class="text-end fw-bold">₹<?= (int)($item->amount) ?></td>
                    </tr>
                    <?php endforeach; else: ?>
                    <tr><td colspan="7" class="text-center text-muted">No items found.</td></tr>
                    <?php endif; ?>
                </tbody>
                <tfoot>
                    <tr class="table-warning">
                        <td colspan="6" class="text-end fw-bold">Grand Total:</td>
                        <td class="text-end fw-bold">₹<?= (int)($row->total_charge) ?></td>
                    </tr>
                </tfoot>
            </table>
        </div>
    </div>
</div>