<?php
$page_title = 'Identity Federation';
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-fingerprint" style="color:#3b82f6; margin-right:10px;"></i>Identity Federation</h2>
        <p style="color:#64748b; font-size:0.95rem; margin-top:5px;">SSO, OAuth/SAML, role federation, multi-company access, partner login.</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 #3b82f6;">
        <div style="color:#64748b; font-size:0.8rem; font-weight:600; margin-bottom:8px;">SSO USERS</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-sign-in-alt"></i> Single Sign-On</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 SESSIONS</div>
        <div style="font-size:1.6rem; font-weight:700; color:#10b981;">842</div>
        <div style="color:#10b981; font-size:0.8rem; margin-top:5px;"><i class="fas fa-circle"></i> Online Now</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;">ROLES DEFINED</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">56</div>
        <div style="color:#8b5cf6; font-size:0.8rem; margin-top:5px;"><i class="fas fa-user-tag"></i> RBAC + ABAC</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;">PARTNER LOGINS</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">120</div>
        <div style="color:#f59e0b; font-size:0.8rem; margin-top:5px;"><i class="fas fa-handshake"></i> External Access</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-key" style="color:#3b82f6; margin-right:8px;"></i>Authentication Protocols</h3>
        <?php
        $protocols = [
            ['Single Sign-On (SSO)', 'SAML 2.0 + OIDC', '#3b82f6', 'Active', 'fas fa-sign-in-alt'],
            ['OAuth 2.0 / SAML', 'External app auth', '#10b981', 'Active', 'fas fa-lock'],
            ['Role Federation', 'Cross-company roles', '#8b5cf6', 'Active', 'fas fa-user-shield'],
            ['Multi-Company Access', '4 entities unified', '#f59e0b', 'Active', 'fas fa-building'],
            ['External Partner Login', 'Vendor + dealer portal', '#ec4899', 'Active', 'fas fa-door-open'],
        ];
        foreach ($protocols as $p): ?>
        <div style="border:1px solid #e2e8f0; border-radius:8px; padding:12px 15px; margin-bottom:8px; display:flex; justify-content:space-between; align-items:center;">
            <div style="display:flex; align-items:center; gap:12px;">
                <i class="<?= $p[4] ?>" style="color:<?= $p[2] ?>; font-size:1.1rem;"></i>
                <div>
                    <div style="font-weight:600; font-size:0.9rem;"><?= $p[0] ?></div>
                    <div style="font-size:0.75rem; color:#94a3b8;"><?= $p[1] ?></div>
                </div>
            </div>
            <span style="background:#dcfce7; color:#166534; padding:3px 8px; border-radius:6px; font-size:0.7rem; font-weight:bold;"><?= $p[3] ?></span>
        </div>
        <?php endforeach; ?>
    </div>
    <div style="background:linear-gradient(135deg,#3b82f6,#2563eb); color:#fff; padding:25px; border-radius:12px;">
        <h3 style="margin:0 0 15px; font-size:1.2rem;"><i class="fas fa-shield-alt"></i> Security Overview</h3>
        <div style="display:flex; justify-content:space-between; font-size:0.85rem; margin-bottom:10px;">
            <span>MFA Enabled</span><span style="font-weight:bold;">94% of users</span>
        </div>
        <div style="display:flex; justify-content:space-between; font-size:0.85rem; margin-bottom:10px;">
            <span>Failed Logins (24h)</span><span style="font-weight:bold;">12</span>
        </div>
        <div style="display:flex; justify-content:space-between; font-size:0.85rem; margin-bottom:10px;">
            <span>Locked Accounts</span><span style="font-weight:bold;">3</span>
        </div>
        <div style="display:flex; justify-content:space-between; font-size:0.85rem;">
            <span>Session Timeout</span><span style="font-weight:bold;">30 min</span>
        </div>
    </div>
</div>
<?php require_once __DIR__ . '/footer.php'; ?>
