<?php
$page_title = 'Knowledge OS';
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-book-open" style="color:#f59e0b; margin-right:10px;"></i>Knowledge OS</h2>
        <p style="color:#64748b; font-size:0.95rem; margin-top:5px;">SOPs, training, FAQs, best practices, and enterprise knowledge base.</p>
    </div>
    <button style="background:linear-gradient(135deg,#f59e0b,#d97706); 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> Create Article</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 #f59e0b;">
        <div style="color:#64748b; font-size:0.8rem; font-weight:600; margin-bottom:8px;">TOTAL ARTICLES</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">1,240</div>
        <div style="color:#f59e0b; font-size:0.8rem; margin-top:5px;"><i class="fas fa-book"></i> Across 7 Libraries</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;">SOPs ACTIVE</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">342</div>
        <div style="color:#3b82f6; font-size:0.8rem; margin-top:5px;"><i class="fas fa-clipboard-list"></i> 98% Reviewed</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;">VIDEO LIBRARY</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">156</div>
        <div style="color:#10b981; font-size:0.8rem; margin-top:5px;"><i class="fas fa-video"></i> Training Videos</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;">Q&A FORUM</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">2,480</div>
        <div style="color:#8b5cf6; font-size:0.8rem; margin-top:5px;"><i class="fas fa-comments"></i> Questions Answered</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-folder-open" style="color:#f59e0b; margin-right:8px;"></i>Knowledge Libraries</h3>
        <?php
        $libs = [
            ['SOP Library', '342 SOPs', '#3b82f6', 'fas fa-clipboard-list'],
            ['Training Wiki', '186 articles', '#10b981', 'fas fa-graduation-cap'],
            ['FAQ Knowledge Base', '420 FAQs', '#f59e0b', 'fas fa-question-circle'],
            ['Best Practices Vault', '89 guides', '#8b5cf6', 'fas fa-star'],
            ['Engineering Docs', '124 docs', '#ec4899', 'fas fa-drafting-compass'],
            ['Product Manuals', '56 manuals', '#06b6d4', 'fas fa-book'],
            ['Video Library', '156 videos', '#ef4444', 'fas fa-play-circle'],
        ];
        foreach ($libs as $l): ?>
        <div style="border:1px solid #e2e8f0; border-radius:8px; padding:12px 15px; margin-bottom:10px; display:flex; justify-content:space-between; align-items:center; cursor:pointer; transition:all 0.2s;" onmouseover="this.style.background='#f8fafc'" onmouseout="this.style.background='#fff'">
            <div style="display:flex; align-items:center; gap:12px;">
                <i class="<?= $l[3] ?>" style="color:<?= $l[2] ?>; font-size:1.1rem; width:20px; text-align:center;"></i>
                <span style="font-weight:600; font-size:0.9rem; color:#0f172a;"><?= $l[0] ?></span>
            </div>
            <div style="display:flex; align-items:center; gap:8px;">
                <span style="color:#64748b; font-size:0.8rem;"><?= $l[1] ?></span>
                <i class="fas fa-chevron-right" style="color:#cbd5e1; font-size:0.8rem;"></i>
            </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-fire" style="color:#ef4444; margin-right:8px;"></i>Trending Topics</h3>
            <?php
            $trending = [
                ['How to process GST credit notes?', 42, 'FAQ'],
                ['SS 304 welding best practices', 38, 'Engineering'],
                ['New dealer onboarding checklist', 35, 'SOP'],
                ['Safety gear requirements 2024', 31, 'Training'],
            ];
            foreach ($trending as $t): ?>
            <div style="display:flex; justify-content:space-between; align-items:center; padding:10px 0; border-bottom:1px solid #f1f5f9;">
                <div style="font-size:0.9rem; font-weight:500; color:#0f172a;"><?= $t[0] ?></div>
                <div style="display:flex; gap:8px; align-items:center;">
                    <span style="font-size:0.75rem; color:#64748b;"><?= $t[1] ?> views</span>
                    <span style="background:#f1f5f9; padding:2px 6px; border-radius:4px; font-size:0.65rem; color:#475569;"><?= $t[2] ?></span>
                </div>
            </div>
            <?php endforeach; ?>
        </div>

        <div style="background:linear-gradient(135deg,#f59e0b,#d97706); color:#fff; padding:20px; border-radius:12px;">
            <h3 style="margin:0 0 8px; font-size:1.1rem;"><i class="fas fa-comments"></i> Internal Q&A Forum</h3>
            <p style="margin:0 0 10px; font-size:0.85rem; opacity:0.85;">2,480 questions answered. 94% resolution rate.</p>
            <div style="display:flex; justify-content:space-between; font-size:0.85rem; margin-bottom:8px;">
                <span>Open Questions</span><span style="font-weight:bold;">18</span>
            </div>
            <div style="display:flex; justify-content:space-between; font-size:0.85rem;">
                <span>Avg Response Time</span><span style="font-weight:bold;">2.4 hrs</span>
            </div>
        </div>
    </div>
</div>

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