<?php
$page_title = 'Master Data Management';
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-database" style="color:#6366f1; margin-right:10px;"></i>Master Data Management</h2>
        <p style="color:#64748b; font-size:0.95rem; margin-top:5px;">Centralized hub for all enterprise master records.</p>
    </div>
    <button style="background:linear-gradient(135deg,#6366f1,#8b5cf6); 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 Master Record</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 #6366f1;">
        <div style="color:#64748b; font-size:0.8rem; font-weight:600; margin-bottom:8px;">TOTAL MASTERS</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">12 <span style="font-size:0.9rem; color:#64748b;">Categories</span></div>
        <div style="color:#6366f1; font-size:0.8rem; margin-top:5px;"><i class="fas fa-layer-group"></i> All Synced</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;">ACTIVE RECORDS</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">24,580</div>
        <div style="color:#10b981; font-size:0.8rem; margin-top:5px;"><i class="fas fa-check-circle"></i> 99.2% Clean</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 REVIEW</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">47</div>
        <div style="color:#f59e0b; font-size:0.8rem; margin-top:5px;"><i class="fas fa-clock"></i> Awaiting Approval</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;">DUPLICATES FOUND</div>
        <div style="font-size:1.6rem; font-weight:700; color:#ef4444;">12</div>
        <div style="color:#ef4444; font-size:0.8rem; margin-top:5px;"><i class="fas fa-exclamation-triangle"></i> Needs Merge</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-th-list" style="color:#6366f1; margin-right:8px;"></i>Master Directories</h3>
        <?php
        $masters = [
            ['Customer Master', 'fas fa-users', '#3b82f6', '3,240 records', 'Last sync: 2 min ago'],
            ['Dealer Master', 'fas fa-handshake', '#10b981', '856 records', 'Last sync: 5 min ago'],
            ['Vendor Master', 'fas fa-truck', '#f59e0b', '1,120 records', 'Last sync: 10 min ago'],
            ['Employee Master', 'fas fa-id-badge', '#8b5cf6', '2,480 records', 'Last sync: 1 min ago'],
            ['Product Master', 'fas fa-box', '#ec4899', '4,750 records', 'Last sync: 3 min ago'],
            ['SKU Taxonomy', 'fas fa-sitemap', '#06b6d4', '12,340 SKUs', 'Last sync: 8 min ago'],
        ];
        foreach ($masters as $m): ?>
        <div style="border:1px solid #e2e8f0; border-radius:8px; padding:12px 15px; margin-bottom:10px; display:flex; justify-content:space-between; align-items:center; transition:all 0.2s;" onmouseover="this.style.borderColor='#6366f1'; this.style.background='#f8fafc'" onmouseout="this.style.borderColor='#e2e8f0'; this.style.background='#fff'">
            <div style="display:flex; align-items:center; gap:12px;">
                <i class="<?= $m[1] ?>" style="color:<?= $m[2] ?>; font-size:1.2rem; width:20px; text-align:center;"></i>
                <div>
                    <div style="font-weight:600; font-size:0.9rem; color:#0f172a;"><?= $m[0] ?></div>
                    <div style="font-size:0.75rem; color:#94a3b8;"><?= $m[4] ?></div>
                </div>
            </div>
            <div style="display:flex; align-items:center; gap:10px;">
                <span style="background:#f1f5f9; color:#475569; padding:3px 10px; border-radius:10px; font-size:0.75rem; font-weight:600;"><?= $m[3] ?></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-cog" style="color:#f59e0b; margin-right:8px;"></i>Configuration Masters</h3>
            <?php
            $configs = [
                ['Territory Master', '28 Zones', '#3b82f6'],
                ['Price Master', '156 Price Lists', '#10b981'],
                ['Tax Master', '42 Tax Rules', '#f59e0b'],
                ['Approval Matrix', '18 Workflows', '#8b5cf6'],
                ['Document Master', '8,450 Docs', '#ec4899'],
                ['Asset Master', '1,240 Assets', '#06b6d4'],
            ];
            foreach ($configs as $c): ?>
            <div style="display:flex; justify-content:space-between; align-items:center; padding:10px 0; border-bottom:1px solid #f1f5f9;">
                <span style="font-size:0.9rem; font-weight:500; color:#0f172a;"><?= $c[0] ?></span>
                <span style="background:<?= $c[2] ?>15; color:<?= $c[2] ?>; padding:3px 10px; border-radius:6px; font-size:0.75rem; font-weight:bold;"><?= $c[1] ?></span>
            </div>
            <?php endforeach; ?>
        </div>

        <div style="background:linear-gradient(135deg,#6366f1,#8b5cf6); color:#fff; padding:20px; border-radius:12px;">
            <h3 style="margin:0 0 10px; font-size:1.1rem;"><i class="fas fa-magic"></i> Data Quality Score</h3>
            <div style="font-size:2.5rem; font-weight:700; margin-bottom:5px;">96.8%</div>
            <p style="margin:0; font-size:0.85rem; opacity:0.8;">Overall data completeness and accuracy across all master records.</p>
            <div style="background:rgba(255,255,255,0.2); height:8px; border-radius:4px; margin-top:15px; overflow:hidden;">
                <div style="width:96.8%; height:100%; background:#fff; border-radius:4px;"></div>
            </div>
        </div>
    </div>
</div>

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