<!-- ── 4 STAT CARDS — CLICKABLE ── -->
<div class="row g-3 mb-4">

    <div class="col-xl-3 col-md-6">
        <a href="<?= site_url('tailoring_order') ?>" class="stat-card-link">
        <div class="stat-card" style="border-left-color:#7c3aed;">
            <div class="stat-icon" style="background:#f5f3ff;color:#7c3aed;">
                <i class="fa-solid fa-shirt"></i>
            </div>
            <div>
                <div class="stat-label">Total Orders</div>
                <div class="stat-value"><?= $total_orders ?></div>
            </div>
        </div>
        </a>
    </div>

    <div class="col-xl-3 col-md-6">
        <a href="<?= site_url('tailoring_order') ?>?status=Pending" class="stat-card-link">
        <div class="stat-card" style="border-left-color:#f59e0b;">
            <div class="stat-icon" style="background:#fffbeb;color:#f59e0b;">
                <i class="fa-solid fa-clock"></i>
            </div>
            <div>
                <div class="stat-label">Pending Orders</div>
                <div class="stat-value" style="color:#f59e0b;"><?= $pending_orders ?></div>
            </div>
        </div>
        </a>
    </div>

    <div class="col-xl-3 col-md-6">
        <a href="<?= site_url('tailoring_order') ?>?status=Delivered" class="stat-card-link">
        <div class="stat-card" style="border-left-color:#16a34a;">
            <div class="stat-icon" style="background:#f0fdf4;color:#16a34a;">
                <i class="fa-solid fa-box-open"></i>
            </div>
            <div>
                <div class="stat-label">Delivered Orders</div>
                <div class="stat-value" style="color:#16a34a;"><?= $delivered_orders ?></div>
            </div>
        </div>
        </a>
    </div>

    <div class="col-xl-3 col-md-6">
        <a href="<?= site_url('purchase') ?>" class="stat-card-link">
        <div class="stat-card" style="border-left-color:#dc2626;">
            <div class="stat-icon" style="background:#fef2f2;color:#dc2626;">
                <i class="fa-solid fa-cart-shopping"></i>
            </div>
            <div>
                <div class="stat-label">Total Purchase</div>
                <div class="stat-value" style="font-size:20px;color:#dc2626;">₹<?= (int)($total_purchase_amt) ?></div>
            </div>
        </div>
        </a>
    </div>

</div>

<!-- <div class="col-xl-3 col-md-6">
    <a href="<?= site_url('quotation') ?>" class="stat-card-link">
    <div class="stat-card" style="border-left-color:#ec4899;">
        <div class="stat-icon" style="background:#fdf2f8;color:#ec4899;">
            <i class="fa-solid fa-file-lines"></i>
        </div>
        <div>
            <div class="stat-label">Total Quotations</div>
            <div class="stat-value"><?= $total_quotations ?></div>
        </div>
    </div>
    </a>
</div> -->

<!-- ── RECENT ACTIVITY ── -->
<div class="row g-3">

    <!-- Recent Orders -->
    <div class="col-lg-6">
        <div class="card-box h-100">
            <div class="card-box-header">
                <h5><i class="fa-solid fa-shirt" style="color:#7c3aed;"></i> Recent Tailoring Orders</h5>
                <a href="<?= site_url('tailoring_order') ?>" class="btn btn-sm" style="background:#f5f3ff;color:#7c3aed;">View All</a>
            </div>
            <?php if(!empty($recent_orders)): ?>
            <div class="table-responsive">
            <table class="table table-sm table-hover mb-0" style="font-size:12.5px;">
                <thead><tr><th>Order No</th><th>Customer</th><th>Garment</th><th>Delivery</th><th>Status</th></tr></thead>
                <tbody>
                <?php
                $sc = ['Pending'=>['#fef3c7','#d97706'],'In Progress'=>['#dbeafe','#2563eb'],'Ready'=>['#d1fae5','#059669'],'Delivered'=>['#dcfce7','#16a34a'],'Cancelled'=>['#fee2e2','#dc2626']];
                foreach($recent_orders as $o):
                    $s = $sc[$o->order_status] ?? ['#f1f5f9','#64748b'];
                ?>
                <tr style="cursor:pointer;" onclick="window.location='<?= site_url('tailoring_order/view/'.$o->id) ?>'">
                    <td><span style="color:#7c3aed;font-weight:600;"><code><?= $o->order_no ?></code></span></td>
                    <td><?= htmlspecialchars($o->customer_name) ?></td>
                    <td><?= htmlspecialchars($o->garment_type ?? '-') ?></td>
                    <td><?= date('d M', strtotime($o->delivery_date)) ?></td>
                    <td><span style="background:<?= $s[0] ?>;color:<?= $s[1] ?>;padding:2px 8px;border-radius:10px;font-size:11px;font-weight:700;"><?= $o->order_status ?></span></td>
                </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
            </div>
            <?php else: ?>
            <div class="text-center text-muted py-3" style="font-size:13px;">No orders yet. <a href="<?= site_url('tailoring_order/create') ?>">Add first order</a></div>
            <?php endif; ?>
        </div>
    </div>

    <!-- Recent Sales -->
    <div class="col-lg-6">
        <div class="card-box h-100">
            <div class="card-box-header">
                <h5><i class="fa-solid fa-file-invoice-dollar" style="color:#16a34a;"></i> Recent Sales</h5>
                <a href="<?= site_url('sales') ?>" class="btn btn-sm" style="background:#f0fdf4;color:#16a34a;">View All</a>
            </div>
            <?php if(!empty($recent_sales)): ?>
            <div class="table-responsive">
            <table class="table table-sm table-hover mb-0" style="font-size:12.5px;">
                <thead><tr><th>Bill No</th><th>Customer</th><th>Date</th><th class="text-end">Amount</th></tr></thead>
                <tbody>
                <?php foreach($recent_sales as $s): ?>
                <tr style="cursor:pointer;" onclick="window.location='<?= site_url('sales/view/'.$s->id) ?>'">
                    <td><span style="color:#16a34a;font-weight:600;"><code><?= $s->bill_no ?></code></span></td>
                    <td><?= htmlspecialchars($s->customer_name) ?></td>
                    <td><?= date('d M Y', strtotime($s->bill_date)) ?></td>
                    <td class="text-end fw-bold text-success">₹<?= (int)($s->net_payable) ?></td>
                </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
            </div>
            <?php else: ?>
            <div class="text-center text-muted py-3" style="font-size:13px;">No sales yet. <a href="<?= site_url('sales/create') ?>">Add first bill</a></div>
            <?php endif; ?>
        </div>
    </div>

</div>

<style>
.stat-card-link {
    display: block;
    text-decoration: none;
    color: inherit;
}
.stat-card-link .stat-card {
    cursor: pointer;
    transition: transform .22s, box-shadow .22s, border-left-width .2s;
}
.stat-card-link:hover .stat-card {
    transform: translateY(-5px);
    box-shadow: 0 10px 32px rgba(0,0,0,.14);
    border-left-width: 6px;
}
</style>