<?php
$page_title = 'Enterprise Workflow Engine';
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-project-diagram" style="color:#0ea5e9; margin-right:10px;"></i>Enterprise Workflow Engine</h2>
        <p style="color:#64748b; font-size:0.95rem; margin-top:5px;">Multi-level approvals, conditional routing, and SLA management.</p>
    </div>
    <button style="background:linear-gradient(135deg,#0ea5e9,#06b6d4); color:#fff; border:none; padding:10px 20px; border-radius:8px; font-size:0.9rem; cursor:pointer; font-weight:600;"><i class="fas fa-plus"></i> New Workflow</button>
</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 #0ea5e9;">
        <div style="color:#64748b; font-size:0.8rem; font-weight:600; margin-bottom:8px;">ACTIVE WORKFLOWS</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">42</div>
        <div style="color:#0ea5e9; font-size:0.8rem; margin-top:5px;"><i class="fas fa-play-circle"></i> Running</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;">COMPLETED TODAY</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">128</div>
        <div style="color:#10b981; font-size:0.8rem; margin-top:5px;"><i class="fas fa-check"></i> Avg 2.4 hrs</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;">PENDING APPROVALS</div>
        <div style="font-size:1.6rem; font-weight:700; color:#f59e0b;">23</div>
        <div style="color:#f59e0b; font-size:0.8rem; margin-top:5px;"><i class="fas fa-hourglass-half"></i> 5 Escalated</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;">SLA BREACHES</div>
        <div style="font-size:1.6rem; font-weight:700; color:#ef4444;">3</div>
        <div style="color:#ef4444; font-size:0.8rem; margin-top:5px;"><i class="fas fa-exclamation-circle"></i> Auto-escalated</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-stream" style="color:#0ea5e9; margin-right:8px;"></i>Active Approval Chains</h3>
        <?php
        $workflows = [
            ['Purchase Order > ₹5L', 'Multi-level', '3 pending', '#ef4444', 'HOD → CFO → MD'],
            ['Leave Request > 5 Days', 'Conditional', '8 pending', '#f59e0b', 'Manager → HR Head'],
            ['New Vendor Onboarding', 'Parallel', '2 pending', '#3b82f6', 'Procurement + Finance + Legal'],
            ['Credit Note Approval', 'Sequential', '5 pending', '#8b5cf6', 'Sales → Finance → MD'],
            ['Capital Expenditure', 'Digital Sign', '1 pending', '#10b981', 'Plant Head → CFO → Board'],
        ];
        foreach ($workflows as $w): ?>
        <div style="border:1px solid #e2e8f0; border-radius:8px; padding:15px; margin-bottom:10px; border-left:4px solid <?= $w[3] ?>;">
            <div style="display:flex; justify-content:space-between; align-items:flex-start; margin-bottom:8px;">
                <div>
                    <div style="font-weight:600; font-size:0.9rem; color:#0f172a;"><?= $w[0] ?></div>
                    <div style="font-size:0.75rem; color:#94a3b8; margin-top:3px;">Flow: <?= $w[4] ?></div>
                </div>
                <span style="background:<?= $w[3] ?>15; color:<?= $w[3] ?>; padding:3px 10px; border-radius:10px; font-size:0.7rem; font-weight:bold;"><?= $w[2] ?></span>
            </div>
            <div style="display:flex; gap:8px;">
                <span style="background:#f1f5f9; padding:2px 8px; border-radius:4px; font-size:0.7rem; color:#475569;"><?= $w[1] ?></span>
                <span style="background:#dbeafe; padding:2px 8px; border-radius:4px; font-size:0.7rem; color:#1d4ed8;">SLA: 24hrs</span>
            </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-chart-bar" style="color:#8b5cf6; margin-right:8px;"></i>Workflow Analytics</h3>
            <div style="display:grid; grid-template-columns:1fr 1fr; gap:15px;">
                <div style="background:#f8fafc; padding:15px; border-radius:8px; text-align:center;">
                    <div style="font-size:1.8rem; font-weight:700; color:#0ea5e9;">94%</div>
                    <div style="font-size:0.8rem; color:#64748b;">SLA Compliance</div>
                </div>
                <div style="background:#f8fafc; padding:15px; border-radius:8px; text-align:center;">
                    <div style="font-size:1.8rem; font-weight:700; color:#10b981;">2.1h</div>
                    <div style="font-size:0.8rem; color:#64748b;">Avg Cycle Time</div>
                </div>
                <div style="background:#f8fafc; padding:15px; border-radius:8px; text-align:center;">
                    <div style="font-size:1.8rem; font-weight:700; color:#f59e0b;">18</div>
                    <div style="font-size:0.8rem; color:#64748b;">Delegations Active</div>
                </div>
                <div style="background:#f8fafc; padding:15px; border-radius:8px; text-align:center;">
                    <div style="font-size:1.8rem; font-weight:700; color:#8b5cf6;">856</div>
                    <div style="font-size:0.8rem; color:#64748b;">This Month</div>
                </div>
            </div>
        </div>

        <div style="background:linear-gradient(135deg,#0f172a,#1e293b); color:#fff; padding:20px; border-radius:12px;">
            <h3 style="margin:0 0 8px; font-size:1.1rem; color:#38bdf8;"><i class="fas fa-bell"></i> Reminder Engine</h3>
            <p style="margin:0 0 15px; font-size:0.85rem; color:#94a3b8;">Auto reminders sent at 4hr, 8hr, and 24hr marks.</p>
            <div style="display:flex; justify-content:space-between; font-size:0.85rem;">
                <span>Reminders Sent Today</span>
                <span style="font-weight:bold;">34</span>
            </div>
            <div style="display:flex; justify-content:space-between; font-size:0.85rem; margin-top:8px;">
                <span>Auto Escalations</span>
                <span style="font-weight:bold; color:#f59e0b;">5</span>
            </div>
            <div style="display:flex; justify-content:space-between; font-size:0.85rem; margin-top:8px;">
                <span>Digital Signatures Pending</span>
                <span style="font-weight:bold; color:#ef4444;">3</span>
            </div>
        </div>
    </div>
</div>

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