<div class="users-directory-container">
    <div class="directory-header">
        <h1><i class="fas fa-users"></i> <?= \App\Helpers\Lang::t('members') ?></h1>
        <p>Спільнота нашої платформи. Знаходь цікавих людей та спілкуйся!</p>
    </div>

    <div class="users-grid">
        <?php foreach ($users as $user): ?>
            <div class="user-card">
                <div class="user-card-inner">
                    <a href="/u/<?= htmlspecialchars($user['username']) ?>" class="user-avatar-link">
                        <div class="user-avatar-wrapper">
                            <img src="<?= \App\Helpers\Asset::avatar($user['avatar'], $user['username'], 80) ?>" alt="<?= htmlspecialchars($user['username']) ?>" class="user-avatar">
                            <?php if (isset($user['role_name']) && $user['role_name'] === 'admin'): ?>
                                <div class="admin-badge" title="Administrator"><i class="fas fa-shield-alt"></i></div>
                            <?php endif; ?>
                        </div>
                    </a>
                    
                    <div class="user-card-content">
                        <h3 class="user-username">
                            <a href="/u/<?= htmlspecialchars($user['username']) ?>"><?= htmlspecialchars($user['username']) ?></a>
                        </h3>
                        <div class="user-role"><?= htmlspecialchars($user['role_name'] ?? 'User') ?></div>
                        
                        <div class="user-meta">
                            <div class="meta-item" title="Reputation">
                                <i class="fas fa-star text-warning"></i> <span><?= number_format($user['reputation'] ?? 0) ?></span>
                            </div>
                            <div class="meta-item" title="Joined">
                                <i class="far fa-calendar-alt"></i> <span><?= date('M Y', strtotime($user['created_at'])) ?></span>
                            </div>
                        </div>

                        <a href="/u/<?= htmlspecialchars($user['username']) ?>" class="btn-profile">
                            <?= \App\Helpers\Lang::t('view_profile') ?> <i class="fas fa-chevron-right"></i>
                        </a>
                    </div>
                </div>
            </div>
        <?php endforeach; ?>
    </div>

    <?php if ($totalPages > 1): ?>
        <div class="pagination">
            <?php for ($i = 1; $i <= $totalPages; $i++): ?>
                <a href="?page=<?= $i ?>" class="page-link <?= $page == $i ? 'active' : '' ?>"><?= $i ?></a>
            <?php endfor; ?>
        </div>
    <?php endif; ?>
</div>

<style>
.users-directory-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.directory-header {
    text-align: center;
    margin-bottom: 3rem;
}

.directory-header h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.directory-header h1 i {
    color: var(--primary);
}

.directory-header p {
    color: var(--text-muted);
    font-size: 1.1rem;
}

.users-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.user-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 1.5rem;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.user-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
    box-shadow: 0 12px 24px rgba(99, 102, 241, 0.1);
}

.user-card-inner {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.user-avatar-wrapper {
    position: relative;
    margin-bottom: 1.5rem;
}

.user-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid var(--bg);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.admin-badge {
    position: absolute;
    bottom: 5px;
    right: 5px;
    background: #eab308;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    border: 3px solid var(--card);
}

.user-username {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.user-username a {
    color: var(--text);
    text-decoration: none;
}

.user-username a:hover {
    color: var(--primary);
}

.user-role {
    font-size: 0.85rem;
    color: var(--primary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 1rem;
}

.user-meta {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 0.75rem 1rem;
    background: var(--bg);
    border-radius: 1rem;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.btn-profile {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
    border-radius: 0.75rem;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.3s;
}

.btn-profile:hover {
    background: var(--primary);
    color: white;
}

.pagination {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

.page-link {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s;
}

.page-link.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.page-link:hover:not(.active) {
    border-color: var(--primary);
    color: var(--primary);
}

@media (max-width: 640px) {
    .users-grid {
        grid-template-columns: 1fr;
    }
}
</style>
