<?php
$page_title = 'Smart Contract Layer';
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-file-contract" style="color:#8b5cf6; margin-right:10px;"></i>Smart Contract Layer</h2>
        <p style="color:#64748b; font-size:0.95rem; margin-top:5px;">Automated vendor contracts, dealer agreements, incentive rules, and compliance monitoring.</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 #8b5cf6;">
        <div style="color:#64748b; font-size:0.8rem; font-weight:600; margin-bottom:8px;">ACTIVE CONTRACTS</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">284</div>
        <div style="color:#8b5cf6; font-size:0.8rem; margin-top:5px;"><i class="fas fa-file-signature"></i> Auto-managed</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;">AUTO-EXECUTED</div>
        <div style="font-size:1.6rem; font-weight:700; color:#10b981;">1,240</div>
        <div style="color:#10b981; font-size:0.8rem; margin-top:5px;"><i class="fas fa-check"></i> This Quarter</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;">RENEWALS DUE</div>
        <div style="font-size:1.6rem; font-weight:700; color:#f59e0b;">18</div>
        <div style="color:#f59e0b; font-size:0.8rem; margin-top:5px;"><i class="fas fa-clock"></i> Next 30 Days</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;">COMPLIANCE FLAGS</div>
        <div style="font-size:1.6rem; font-weight:700; color:#ef4444;">5</div>
        <div style="color:#ef4444; font-size:0.8rem; margin-top:5px;"><i class="fas fa-flag"></i> Clause Violations</div>
    </div>
</div>
<div class="grid-2">
    <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-gavel" style="color:#8b5cf6; margin-right:8px;"></i>Contract Automation</h3>
        <?php
        $contracts = [
            ['Vendor Contracts', '142 active', 'Auto-renewal + penalty clauses', '#8b5cf6'],
            ['Dealer Agreements', '86 active', 'Territory + pricing locked', '#3b82f6'],
            ['Incentive Smart Rules', '56 rules', 'Auto-payout on target met', '#10b981'],
            ['Compliance Clauses', '284 monitored', 'AI flagging deviations', '#ef4444'],
        ];
        foreach ($contracts as $c): ?>
        <div style="border:1px solid #e2e8f0; border-radius:8px; padding:15px; margin-bottom:10px; border-left:4px solid <?= $c[3] ?>;">
            <div style="font-weight:600; font-size:0.9rem; color:#0f172a;"><?= $c[0] ?></div>
            <div style="font-size:0.75rem; color:#94a3b8; margin-top:3px;"><?= $c[1] ?> · <?= $c[2] ?></div>
        </div>
        <?php endforeach; ?>
    </div>
    <div style="background:linear-gradient(135deg,#8b5cf6,#7c3aed); color:#fff; padding:25px; border-radius:12px; display:flex; flex-direction:column; justify-content:center;">
        <h3 style="margin:0 0 15px; font-size:1.2rem;"><i class="fas fa-robot"></i> Auto-Execution Log</h3>
        <div style="display:flex; justify-content:space-between; font-size:0.85rem; margin-bottom:10px;">
            <span>Incentive Payouts</span><span style="font-weight:bold;">₹2.4 Cr auto-paid</span>
        </div>
        <div style="display:flex; justify-content:space-between; font-size:0.85rem; margin-bottom:10px;">
            <span>Penalty Deductions</span><span style="font-weight:bold;">₹12L enforced</span>
        </div>
        <div style="display:flex; justify-content:space-between; font-size:0.85rem; margin-bottom:10px;">
            <span>Auto-Renewals</span><span style="font-weight:bold;">24 executed</span>
        </div>
        <div style="display:flex; justify-content:space-between; font-size:0.85rem;">
            <span>Compliance Alerts</span><span style="font-weight:bold;">5 sent today</span>
        </div>
    </div>
</div>
<?php require_once __DIR__ . '/footer.php'; ?>
