<?php
require_once 'config.php';

$stmt = $pdo->prepare("SELECT * FROM lawyers WHERE is_active = 1 ORDER BY sort_order");
$stmt->execute();
$lawyers = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <title>Команда юристов - профессионалы своего дела</title>
    <meta name="description" content="Наши юристы и адвокаты. Опыт работы от 8 лет. Фото, специализация, достижения. Выберите своего эксперта.">
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body { font-family: 'Segoe UI', Arial, sans-serif; background: #f0f4f8; line-height: 1.6; }
        header, footer { background: #0f172a; color: #f8fafc; padding: 1rem; text-align: center; }
        nav a { color: #f8fafc; margin: 0 15px; text-decoration: none; transition: 0.3s; }
        nav a:hover { color: #3b82f6; }
        main { max-width: 1300px; margin: 30px auto; padding: 0 20px; min-height: 60vh; }
        h1 { text-align: center; color: #0f172a; margin-bottom: 10px; }
        .subtitle { text-align: center; color: #475569; margin-bottom: 40px; }
        
        .team-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)); gap: 35px; }
        .lawyer-card { background: #fff; border-radius: 20px; overflow: hidden; box-shadow: 0 5px 20px rgba(0,0,0,0.08); transition: transform 0.3s; }
        .lawyer-card:hover { transform: translateY(-8px); }
        .lawyer-photo { width: 100%; height: 300px; object-fit: cover; object-position: top center; }
        .lawyer-info { padding: 25px; }
        .lawyer-name { font-size: 1.5rem; font-weight: bold; color: #0f172a; margin-bottom: 5px; }
        .lawyer-position { color: #0f3b5f; font-weight: bold; margin-bottom: 12px; border-left: 3px solid #0f3b5f; padding-left: 10px; }
        .lawyer-specialization { background: #e2e8f0; padding: 8px 12px; border-radius: 10px; margin: 15px 0; font-size: 0.9rem; color: #1e293b; }
        .lawyer-specialization strong { color: #0f3b5f; }
        .lawyer-experience { color: #64748b; margin: 10px 0; display: flex; align-items: center; gap: 10px; }
        .lawyer-education { color: #475569; margin: 10px 0; font-size: 0.9rem; }
        .lawyer-bio { color: #475569; margin: 15px 0; line-height: 1.6; }
        .lawyer-email { color: #0f3b5f; text-decoration: none; font-weight: bold; display: inline-block; margin-top: 10px; }
        .lawyer-email:hover { text-decoration: underline; }
        .btn { display: inline-block; background: #0f3b5f; color: #fff; padding: 10px 25px; text-decoration: none; border-radius: 30px; transition: 0.3s; font-weight: bold; margin-top: 15px; }
        .btn:hover { background: #1e5a7a; }
        footer { margin-top: 50px; }
        .empty-message { text-align: center; padding: 50px; background: #fff; border-radius: 16px; }
        @media (max-width: 768px) { .team-grid { grid-template-columns: 1fr; } }
    </style>
</head>
<body>
<header>
    <div style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;">
        <h1 style="margin: 0;">⚖️ Юридическая компания "Правовед"</h1>
        <nav>
            <a href="index.php">📋 Услуги</a>
            <a href="team.php">👨‍⚖️ Команда</a>
            <a href="consultation.php">📝 Консультация</a>
            <a href="my_consultations.php">📋 Мои заявки</a>
            <?php if(isLoggedIn()): ?>
                <a href="logout.php">🚪 Выйти (<?= h($_SESSION['username']) ?>)</a>
            <?php else: ?>
                <a href="login.php">🔐 Вход</a>
                <a href="register.php">📝 Регистрация</a>
            <?php endif; ?>
        </nav>
    </div>
</header>

<main>
    <h1>👨‍⚖️ Наша команда</h1>
    <p class="subtitle">Опытные юристы и адвокаты, готовые защитить ваши права</p>
    
    <?php if(count($lawyers) > 0): ?>
        <div class="team-grid">
            <?php foreach($lawyers as $lawyer): ?>
                <div class="lawyer-card">
                    <img src="<?= h($lawyer['photo_url'] ?: 'img/avatar.jpg') ?>" alt="<?= h($lawyer['full_name']) ?>" class="lawyer-photo">
                    <div class="lawyer-info">
                        <div class="lawyer-name"><?= h($lawyer['full_name']) ?></div>
                        <div class="lawyer-position"><?= h($lawyer['position']) ?></div>
                        <div class="lawyer-specialization">
                            <strong>🎯 Специализация:</strong> <?= h($lawyer['specialization']) ?>
                        </div>
                        <div class="lawyer-experience">
                            <span>📅 Опыт: <?= $lawyer['experience'] ?> лет</span>
                        </div>
                        <div class="lawyer-education">
                            <strong>🎓 Образование:</strong> <?= h($lawyer['education']) ?>
                        </div>
                        <div class="lawyer-bio">
                            <?= h(mb_substr($lawyer['bio'], 0, 150)) ?>...
                        </div>
                        <a href="consultation.php?lawyer=<?= $lawyer['id'] ?>" class="btn">📝 Записаться на консультацию</a>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    <?php else: ?>
        <div class="empty-message">
            <p>😕 Информация о юристах временно отсутствует.</p>
        </div>
    <?php endif; ?>
</main>

<footer>
    <p>&copy; 2025 Юридическая компания "Правовед". Надёжная защита ваших прав.</p>
    <p>📍 Москва, ул. Правовая, 15 | 📞 +7 (999) 123-45-67 | ✉️ info@pravoved.ru</p>
</footer>
</body>
</html>