<?php
$page_title = 'Procurement Intelligence';
require_once __DIR__ . '/../config.php';
if (session_status() === PHP_SESSION_NONE) { session_start(); }
if (!isset($_SESSION['admin_id'])) { redirect(SITE_URL . '/admin/login.php'); }
require_once __DIR__ . '/header.php';
?>

<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:24px;">
    <div>
        <h2 style="font-family:'Outfit', sans-serif; font-size:1.8rem; color:#0f172a; margin:0;"><i class="fas fa-brain" style="color:#14b8a6; margin-right:10px;"></i>Procurement Intelligence</h2>
        <p style="color:#64748b; font-size:0.95rem; margin-top:5px;">Commodity forecasting, hedging, supplier benchmarking, and fraud detection.</p>
    </div>
</div>

<div class="grid-4" style="margin-bottom:24px;">
    <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0; border-top:4px solid #14b8a6;">
        <div style="color:#64748b; font-size:0.8rem; font-weight:600; margin-bottom:8px;">TOTAL SPEND YTD</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">₹86 Cr</div>
        <div style="color:#14b8a6; font-size:0.8rem; margin-top:5px;"><i class="fas fa-chart-line"></i> Across 340 vendors</div>
    </div>
    <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0; border-top:4px solid #10b981;">
        <div style="color:#64748b; font-size:0.8rem; font-weight:600; margin-bottom:8px;">SAVINGS ACHIEVED</div>
        <div style="font-size:1.6rem; font-weight:700; color:#10b981;">₹4.2 Cr</div>
        <div style="color:#10b981; font-size:0.8rem; margin-top:5px;"><i class="fas fa-piggy-bank"></i> 4.9% Savings Rate</div>
    </div>
    <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0; border-top:4px solid #f59e0b;">
        <div style="color:#64748b; font-size:0.8rem; font-weight:600; margin-bottom:8px;">HEDGING POSITIONS</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">₹12 Cr</div>
        <div style="color:#f59e0b; font-size:0.8rem; margin-top:5px;"><i class="fas fa-shield-alt"></i> Nickel + Chrome</div>
    </div>
    <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0; border-top:4px solid #ef4444;">
        <div style="color:#64748b; font-size:0.8rem; font-weight:600; margin-bottom:8px;">FRAUD ALERTS</div>
        <div style="font-size:1.6rem; font-weight:700; color:#ef4444;">2</div>
        <div style="color:#ef4444; font-size:0.8rem; margin-top:5px;"><i class="fas fa-exclamation-triangle"></i> Under Investigation</div>
    </div>
</div>

<div class="grid-2" style="margin-bottom:24px;">
    <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0;">
        <h3 style="margin:0 0 15px; font-size:1.15rem; color:#0f172a;"><i class="fas fa-chart-area" style="color:#14b8a6; margin-right:8px;"></i>Commodity Forecast</h3>
        <?php
        $commodities = [
            ['Nickel (LME)', '$16,240/ton', '+2.4%', '#ef4444', '↗ Rising'],
            ['Chrome', '$8,120/ton', '-1.2%', '#10b981', '↘ Declining'],
            ['HR Coil', '₹52,400/ton', '+0.8%', '#f59e0b', '→ Stable'],
            ['SS 304 Scrap', '₹142/kg', '+3.1%', '#ef4444', '↗ Rising'],
            ['Molybdenum', '$45,800/ton', '-0.5%', '#10b981', '→ Stable'],
        ];
        foreach ($commodities as $c): ?>
        <div style="display:flex; justify-content:space-between; align-items:center; padding:12px 0; border-bottom:1px solid #f1f5f9;">
            <div>
                <div style="font-weight:600; font-size:0.9rem; color:#0f172a;"><?= $c[0] ?></div>
                <div style="font-size:0.8rem; color:#64748b;"><?= $c[1] ?></div>
            </div>
            <div style="text-align:right;">
                <div style="color:<?= $c[3] ?>; font-weight:bold; font-size:0.9rem;"><?= $c[2] ?></div>
                <div style="font-size:0.75rem; color:#94a3b8;"><?= $c[4] ?></div>
            </div>
        </div>
        <?php endforeach; ?>
    </div>

    <div style="display:flex; flex-direction:column; gap:24px;">
        <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0;">
            <h3 style="margin:0 0 15px; font-size:1.15rem; color:#0f172a;"><i class="fas fa-trophy" style="color:#f59e0b; margin-right:8px;"></i>Supplier Benchmarking</h3>
            <?php
            $suppliers = [
                ['Jindal Stainless', 98, '#10b981'],
                ['SAIL', 94, '#3b82f6'],
                ['POSCO India', 91, '#8b5cf6'],
                ['Acerinox', 87, '#f59e0b'],
            ];
            foreach ($suppliers as $s): ?>
            <div style="margin-bottom:12px;">
                <div style="display:flex; justify-content:space-between; font-size:0.85rem; margin-bottom:5px;">
                    <span style="font-weight:500;"><?= $s[0] ?></span>
                    <span style="color:<?= $s[2] ?>; font-weight:bold;"><?= $s[1] ?>/100</span>
                </div>
                <div style="background:#e2e8f0; height:6px; border-radius:3px; overflow:hidden;">
                    <div style="width:<?= $s[1] ?>%; height:100%; background:<?= $s[2] ?>; border-radius:3px;"></div>
                </div>
            </div>
            <?php endforeach; ?>
        </div>

        <div style="background:linear-gradient(135deg,#14b8a6,#0d9488); color:#fff; padding:20px; border-radius:12px;">
            <h3 style="margin:0 0 8px; font-size:1.1rem;"><i class="fas fa-chart-pie"></i> Spend Analytics</h3>
            <p style="margin:0 0 15px; font-size:0.85rem; opacity:0.85;">Top spend categories breakdown.</p>
            <div style="display:flex; justify-content:space-between; font-size:0.85rem; margin-bottom:8px;">
                <span>Raw Materials</span><span style="font-weight:bold;">62%</span>
            </div>
            <div style="display:flex; justify-content:space-between; font-size:0.85rem; margin-bottom:8px;">
                <span>Consumables</span><span style="font-weight:bold;">18%</span>
            </div>
            <div style="display:flex; justify-content:space-between; font-size:0.85rem; margin-bottom:8px;">
                <span>Services</span><span style="font-weight:bold;">12%</span>
            </div>
            <div style="display:flex; justify-content:space-between; font-size:0.85rem;">
                <span>Capital Goods</span><span style="font-weight:bold;">8%</span>
            </div>
        </div>
    </div>
</div>

<?php require_once __DIR__ . '/footer.php'; ?>
