<?php
$page_title = 'Document 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-file-alt" style="color:#10b981; margin-right:10px;"></i>Document Intelligence</h2>
        <p style="color:#64748b; font-size:0.95rem; margin-top:5px;">OCR scanning, smart archival, e-signatures, and intelligent document processing.</p>
    </div>
    <button style="background:linear-gradient(135deg,#10b981,#059669); color:#fff; border:none; padding:10px 20px; border-radius:8px; font-size:0.9rem; cursor:pointer; font-weight:600;"><i class="fas fa-upload"></i> Upload Document</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 #10b981;">
        <div style="color:#64748b; font-size:0.8rem; font-weight:600; margin-bottom:8px;">DOCUMENTS SCANNED</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">18,420</div>
        <div style="color:#10b981; font-size:0.8rem; margin-top:5px;"><i class="fas fa-eye"></i> OCR Processed</div>
    </div>
    <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0; border-top:4px solid #3b82f6;">
        <div style="color:#64748b; font-size:0.8rem; font-weight:600; margin-bottom:8px;">INVOICES EXTRACTED</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">4,280</div>
        <div style="color:#3b82f6; font-size:0.8rem; margin-top:5px;"><i class="fas fa-magic"></i> Auto-indexed</div>
    </div>
    <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;">CONTRACTS ACTIVE</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">342</div>
        <div style="color:#8b5cf6; font-size:0.8rem; margin-top:5px;"><i class="fas fa-file-signature"></i> Tagged & Tracked</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;">E-SIGNATURES</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">89</div>
        <div style="color:#f59e0b; font-size:0.8rem; margin-top:5px;"><i class="fas fa-pen-fancy"></i> Pending Sign</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-robot" style="color:#10b981; margin-right:8px;"></i>AI Document Processing</h3>
        <?php
        $docs = [
            ['Invoice Auto-Extraction', '4,280 processed', '99.2% accuracy', '#10b981', 'fas fa-file-invoice'],
            ['Contract Clause Tagging', '342 contracts', '87 clauses flagged', '#3b82f6', 'fas fa-tag'],
            ['Auto-Indexing Engine', '18,420 indexed', 'Smart categorization', '#8b5cf6', 'fas fa-sort-alpha-down'],
            ['Retention Policy Engine', '24 policies active', '156 docs expiring', '#f59e0b', 'fas fa-calendar-times'],
        ];
        foreach ($docs as $d): ?>
        <div style="border:1px solid #e2e8f0; border-radius:8px; padding:15px; margin-bottom:10px; display:flex; align-items:center; gap:15px;">
            <div style="width:45px; height:45px; border-radius:10px; background:<?= $d[3] ?>15; display:flex; align-items:center; justify-content:center; flex-shrink:0;">
                <i class="<?= $d[4] ?>" style="color:<?= $d[3] ?>; font-size:1.1rem;"></i>
            </div>
            <div style="flex:1;">
                <div style="font-weight:600; font-size:0.9rem; color:#0f172a;"><?= $d[0] ?></div>
                <div style="font-size:0.75rem; color:#94a3b8;"><?= $d[1] ?></div>
            </div>
            <span style="background:<?= $d[3] ?>15; color:<?= $d[3] ?>; padding:3px 10px; border-radius:10px; font-size:0.7rem; font-weight:bold;"><?= $d[2] ?></span>
        </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-pen-fancy" style="color:#f59e0b; margin-right:8px;"></i>E-Signature Vault</h3>
            <div style="border-left:3px solid #ef4444; padding-left:12px; margin-bottom:15px;">
                <div style="font-weight:600; font-size:0.9rem;">Vendor Agreement — Steel Corp Ltd</div>
                <div style="font-size:0.8rem; color:#64748b;">Awaiting MD signature · Due: Tomorrow</div>
            </div>
            <div style="border-left:3px solid #f59e0b; padding-left:12px; margin-bottom:15px;">
                <div style="font-weight:600; font-size:0.9rem;">Dealer Credit Extension — RK Metals</div>
                <div style="font-size:0.8rem; color:#64748b;">CFO signed · Awaiting Legal</div>
            </div>
            <div style="border-left:3px solid #10b981; padding-left:12px;">
                <div style="font-weight:600; font-size:0.9rem;">Employment Contract — Batch 2024-Q2</div>
                <div style="font-size:0.8rem; color:#64748b;">All 12 signatures completed ✓</div>
            </div>
        </div>

        <div style="background:linear-gradient(135deg,#10b981,#059669); color:#fff; padding:20px; border-radius:12px;">
            <h3 style="margin:0 0 10px; font-size:1.1rem;"><i class="fas fa-archive"></i> Smart Archive</h3>
            <div style="font-size:2rem; font-weight:700; margin-bottom:5px;">2.4 TB</div>
            <p style="margin:0; font-size:0.85rem; opacity:0.8;">Total document storage with version control and 7-year retention compliance.</p>
            <div style="background:rgba(255,255,255,0.2); height:8px; border-radius:4px; margin-top:15px; overflow:hidden;">
                <div style="width:62%; height:100%; background:#fff; border-radius:4px;"></div>
            </div>
            <div style="display:flex; justify-content:space-between; font-size:0.75rem; margin-top:5px; opacity:0.8;">
                <span>1.5 TB used</span><span>2.4 TB total</span>
            </div>
        </div>
    </div>
</div>

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