<?php
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
require_once __DIR__ . '/../includes/db.php';
require_once __DIR__ . '/../includes/auth.php';
require_once __DIR__ . '/../includes/tcpdf/tcpdf.php';
require_once __DIR__ . '/../includes/helpers.php';

check_role('administrador');

$user = get_logged_in_user();

// Get user ID from URL parameter
$user_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;

if (!$user_id) {
    header('Location: users.php');
    exit;
}

// Get user details
$stmt = $pdo->prepare("SELECT u.*, r.name as role_name FROM users u JOIN roles r ON u.role_id = r.id WHERE u.id = ?");
$stmt->execute([$user_id]);
$user_data = $stmt->fetch();

if (!$user_data) {
    header('Location: users.php');
    exit;
}

// Get role-specific information
$role_info = [];
switch ($user_data['role_name']) {
    case 'alumno':
        $stmt = $pdo->prepare("SELECT * FROM students WHERE user_id = ?");
        $stmt->execute([$user_id]);
        $role_info = $stmt->fetch();
        break;
    case 'egresado':
        $stmt = $pdo->prepare("SELECT * FROM graduates WHERE user_id = ?");
        $stmt->execute([$user_id]);
        $role_info = $stmt->fetch();
        break;
}

if (!$role_info) {
    die('User profile not found.');
}

// Get user's languages
if ($user_data['role_name'] == 'alumno') {
    $stmt = $pdo->prepare("SELECT * FROM student_languages WHERE student_id = ? ORDER BY created_at DESC");
} else {
    $stmt = $pdo->prepare("SELECT * FROM graduate_languages WHERE graduate_id = ? ORDER BY created_at DESC");
}
$stmt->execute([$role_info['id']]);
$user_languages = $stmt->fetchAll();

// Get user's trainings
if ($user_data['role_name'] == 'alumno') {
    $stmt = $pdo->prepare("SELECT * FROM student_trainings WHERE student_id = ? ORDER BY start_date DESC");
} else {
    $stmt = $pdo->prepare("SELECT * FROM graduate_trainings WHERE graduate_id = ? ORDER BY start_date DESC");
}
$stmt->execute([$role_info['id']]);
$user_trainings = $stmt->fetchAll();

// Get user's work experience
if ($user_data['role_name'] == 'alumno') {
    $stmt = $pdo->prepare("SELECT * FROM student_work_experience WHERE student_id = ? ORDER BY start_date DESC");
} else {
    $stmt = $pdo->prepare("SELECT * FROM graduate_work_experience WHERE graduate_id = ? ORDER BY start_date DESC");
}
$stmt->execute([$role_info['id']]);
$user_experience = $stmt->fetchAll();

// Get career information
$stmt = $pdo->prepare("SELECT c.name as career_name FROM careers c WHERE c.id = ?");
$stmt->execute([$role_info['career_id'] ?? null]);
$career = $stmt->fetch();

// Generate PDF Resume
if (isset($_GET['download'])) {
    generatePDF($user_data, $role_info, $user_languages, $user_trainings, $user_experience, $career);
    exit;
}

function generatePDF($user, $profile, $languages, $trainings, $experience, $career) {
    // Create new PDF document
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

    // Set document information
    $pdf->SetCreator('Bolsa de Trabajo System');
    $pdf->SetAuthor($user['first_name'] . ' ' . $user['last_name']);
    $pdf->SetTitle('CV - ' . $user['first_name'] . ' ' . $user['last_name']);
    $pdf->SetSubject('Professional Resume');

    // Remove default header/footer
    $pdf->setPrintHeader(false);
    $pdf->setPrintFooter(false);

    // Set margins
    $pdf->SetMargins(15, 15, 15);

    // Set auto page breaks
    $pdf->SetAutoPageBreak(TRUE, 15);

    // Add a page
    $pdf->AddPage();

    // Set font
    $pdf->SetFont('helvetica', '', 10);

    // Header - Photo and Name/Contact Info
    if ($user['photo'] && file_exists(BASE_PATH . '/' . $user['photo'])) {
        // Add photo (positioned on the left)
        $pdf->Image(BASE_PATH . '/' . $user['photo'], 15, 15, 30, 30, '', '', '', false, 300, '', false, false, 0, false, false, false);

        // Name (positioned to the right of photo)
        $pdf->SetXY(50, 13);
        $pdf->SetFont('helvetica', 'B', 16);
        $pdf->Cell(0, 8, $user['first_name'] . ' ' . $user['last_name'], 0, 1);

        // Contact info aligned with the name
        $pdf->SetFont('helvetica', '', 10);
        $pdf->SetXY(50, 21);
        $pdf->Cell(0, 5, $user['email'], 0, 1);
        if ($profile['birth_date']) {
            $pdf->SetXY(50, 26);
            $pdf->Cell(0, 5, 'Fecha de Nacimiento: ' . date('M d, Y', strtotime($profile['birth_date'])), 0, 1);
        }
        if ($profile['dni']) {
            $pdf->SetXY(50, $profile['birth_date'] ? 31 : 26);
            $pdf->Cell(0, 5, 'DNI: ' . $profile['dni'], 0, 1);
        }
        if ($profile['phone']) {
            $current_y = 26;
            if ($profile['birth_date']) $current_y += 5;
            if ($profile['dni']) $current_y += 5;
            $pdf->SetXY(50, $current_y);
            $pdf->Cell(0, 5, 'Celular: ' . $profile['phone'], 0, 1);
        }
        if ($profile['address']) {
            $current_y = 26;
            if ($profile['birth_date']) $current_y += 5;
            if ($profile['dni']) $current_y += 5;
            if ($profile['phone']) $current_y += 5;
            $pdf->SetXY(50, $current_y);
            $pdf->MultiCell(0, 10, 'Dirección: ' . $profile['address'], 0, 'L');
        }
        $pdf->Ln(5);
    } else {
        // No photo - center the name and contact info
        $pdf->SetFont('helvetica', 'B', 16);
        $pdf->Cell(0, 10, $user['first_name'] . ' ' . $user['last_name'], 0, 1, 'C');
        $pdf->SetFont('helvetica', '', 10);
        $pdf->Cell(0, 5, $user['email'], 0, 1, 'C');
        if ($profile['phone']) {
            $pdf->Cell(0, 5, 'Phone: ' . $profile['phone'], 0, 1, 'C');
        }
        if ($profile['address']) {
            $pdf->MultiCell(0, 5, 'Address: ' . $profile['address'], 0, 'C');
        }
        $pdf->Ln(5);
    }

    // Professional Summary
    $pdf->SetFont('helvetica', 'B', 12);
    $pdf->Cell(0, 8, 'RESUMEN PROFESIONAL', 0, 1);
    $pdf->SetFont('helvetica', '', 10);

    // Use the resume field from profile table, or fallback to auto-generated summary
    $summary = $profile['resume'];
    if (empty(trim($summary))) {
        // Fallback to auto-generated summary if resume field is empty
        $role_type = isset($profile['current_position']) ? 'professional' : 'student';
        $summary = 'Motivated ' . ($career['career_name'] ?? 'professional') . ' ' . $role_type . ' seeking opportunities to apply academic knowledge and develop professional skills. ';
        if (count($languages) > 0) {
            $summary .= 'Multilingual with proficiency in ' . count($languages) . ' language(s). ';
        }
        if (count($trainings) > 0) {
            $summary .= 'Completed ' . count($trainings) . ' professional training program(s). ';
        }
        if (count($experience) > 0) {
            $summary .= 'Brings ' . count($experience) . ' work experience(s) to contribute to organizational success.';
        }
    }

    $pdf->MultiCell(0, 5, $summary, 0, 'L');
    $pdf->Ln(3);

    // Languages Section
    if (count($languages) > 0) {
        $pdf->SetFont('helvetica', 'B', 12);
        $pdf->Cell(0, 8, 'IDIOMAS', 0, 1);
        $pdf->SetFont('helvetica', '', 10);

        foreach ($languages as $lang) {
            $lang_info = $lang['language_name'];
            if ($lang['proficiency_level']) {
                $lang_info .= ' (' . $lang['proficiency_level'] . ')';
            }
            if ($lang['reading_level'] || $lang['writing_level'] || $lang['speaking_level']) {
                $skills = [];
                if ($lang['reading_level']) $skills[] = 'R: ' . $lang['reading_level'];
                if ($lang['writing_level']) $skills[] = 'W: ' . $lang['writing_level'];
                if ($lang['speaking_level']) $skills[] = 'S: ' . $lang['speaking_level'];
                $lang_info .= ' - ' . implode(', ', $skills);
            }
            $pdf->Cell(0, 5, '• ' . $lang_info, 0, 1);
        }
        $pdf->Ln(3);
    }

    // Education & Training Section
    if (count($trainings) > 0) {
        $pdf->SetFont('helvetica', 'B', 12);
        $pdf->Cell(0, 8, 'CAPACITACIONES', 0, 1);
        $pdf->SetFont('helvetica', '', 10);

        foreach ($trainings as $training) {
            $pdf->SetFont('helvetica', 'B', 10);
            $pdf->Cell(0, 5, $training['training_name'], 0, 1);

            $pdf->SetFont('helvetica', 'I', 9);
            $institution = $training['institution'] ?: 'Not specified';
            $type = ucfirst($training['training_type']);
            $pdf->Cell(0, 4, $institution . ' - ' . $type, 0, 1);

            if ($training['start_date'] || $training['end_date']) {
                $dates = '';
                if ($training['start_date']) $dates .= date('M Y', strtotime($training['start_date']));
                if ($training['end_date']) $dates .= ' - ' . date('M Y', strtotime($training['end_date']));
                $pdf->Cell(0, 4, $dates, 0, 1);
            }

            if ($training['description']) {
                $pdf->SetFont('helvetica', '', 9);
                $pdf->MultiCell(0, 4, $training['description'], 0, 'L');
            }

            if ($training['skills_acquired']) {
                $pdf->SetFont('helvetica', '', 9);
                $pdf->Cell(0, 4, 'Skills: ' . $training['skills_acquired'], 0, 1);
            }

            $pdf->Ln(2);
        }
        $pdf->Ln(3);
    }

    // Work Experience Section
    if (count($experience) > 0) {
        $pdf->SetFont('helvetica', 'B', 12);
        $pdf->Cell(0, 8, 'EXPERIENCIA LABORAL', 0, 1);
        $pdf->SetFont('helvetica', '', 10);

        foreach ($experience as $exp) {
            $pdf->SetFont('helvetica', 'B', 10);
            $pdf->Cell(0, 5, $exp['job_title'], 0, 1);

            $pdf->SetFont('helvetica', 'I', 9);
            $company = $exp['company_name'];
            $type = ucfirst($exp['employment_type']);
            $location = $exp['location'] ? ' - ' . $exp['location'] : '';
            $pdf->Cell(0, 4, $company . ' (' . $type . ')' . $location, 0, 1);

            // Dates
            $dates = '';
            if ($exp['start_date']) $dates .= date('M Y', strtotime($exp['start_date']));
            if ($exp['current_job']) {
                $dates .= ' - Present';
            } elseif ($exp['end_date']) {
                $dates .= ' - ' . date('M Y', strtotime($exp['end_date']));
            }
            $pdf->Cell(0, 4, $dates, 0, 1);

            if ($exp['description']) {
                $pdf->SetFont('helvetica', '', 9);
                $pdf->MultiCell(0, 4, $exp['description'], 0, 'L');
            }

            if ($exp['achievements']) {
                $pdf->SetFont('helvetica', '', 9);
                $pdf->Cell(0, 4, 'Achievements: ' . $exp['achievements'], 0, 1);
            }

            if ($exp['skills_used']) {
                $pdf->SetFont('helvetica', '', 9);
                $pdf->Cell(0, 4, 'Skills Used: ' . $exp['skills_used'], 0, 1);
            }

            $pdf->Ln(2);
        }
        $pdf->Ln(3);
    }

    // Skills Section
    $all_skills = [];

    // Collect skills from trainings
    foreach ($trainings as $training) {
        if ($training['skills_acquired']) {
            $skills = explode(',', $training['skills_acquired']);
            $all_skills = array_merge($all_skills, array_map('trim', $skills));
        }
    }

    // Collect skills from work experience
    foreach ($experience as $exp) {
        if ($exp['skills_used']) {
            $skills = explode(',', $exp['skills_used']);
            $all_skills = array_merge($all_skills, array_map('trim', $skills));
        }
    }

    // Skills are now collected from trainings and work experience tables

    $unique_skills = array_unique(array_filter($all_skills));

    if (count($unique_skills) > 0) {
        $pdf->SetFont('helvetica', 'B', 12);
        $pdf->Cell(0, 8, 'SKILLS & COMPETENCIES', 0, 1);
        $pdf->SetFont('helvetica', '', 10);

        $skill_chunks = array_chunk($unique_skills, 4);
        foreach ($skill_chunks as $chunk) {
            $pdf->Cell(0, 5, '• ' . implode(' • ', $chunk), 0, 1);
        }
        $pdf->Ln(3);
    }


    // Additional Information
    $pdf->SetFont('helvetica', 'B', 12);
    $pdf->Cell(0, 8, 'INFORMACIÓN ADICIONAL', 0, 1);
    $pdf->SetFont('helvetica', '', 10);


    $additional_info[] = 'Programa de Estudio: ' . ($career['career_name'] ?? 'Not specified');
    if ($profile['graduation_year']) {
        $additional_info[] = 'Año de Egreso: ' . $profile['graduation_year'];
    }
    if (isset($profile['current_position']) && $profile['current_position']) {
        $additional_info[] = 'Posición Actual: ' . $profile['current_position'];
    }
    if (isset($profile['company']) && $profile['company']) {
        $additional_info[] = 'Empresa Actual: ' . $profile['company'];
    }
    $additional_info[] = 'Idiomas: ' . count($languages);
    $additional_info[] = 'Capacitaciones: ' . count($trainings);
    $additional_info[] = 'Experiencia Laboral: ' . count($experience) . ' position(s)';

    foreach ($additional_info as $info) {
        $pdf->Cell(0, 5, '• ' . $info, 0, 1);
    }

    // Output the PDF
    $filename = 'CV-' . $user['first_name'] . '_' . $user['last_name'] . '.pdf';
    $pdf->Output($filename, 'D');
}

$page_title = 'Resumen de ' . htmlspecialchars($user_data['first_name'] . ' ' . $user_data['last_name']);

$content = '
<div class="row">
    <div class="col-md-12">
        <div class="card card-modern shadow-lg">
            <div class="card-header bg-gradient-primary text-white">
                <h3 class="card-title mb-0">
                    <i class="fas fa-user-graduate mr-2"></i>
                    Resumen de ' . htmlspecialchars($user_data['first_name'] . ' ' . $user_data['last_name']) . '
                    <span class="badge badge-light ml-2">' . ucfirst($user_data['role_name']) . '</span>
                </h3>
                <div class="card-tools">
                    
                    </a>
                </div>
            </div>
            <div class="card-body">
                <div class="row">
                    <!-- Profile Photo Section -->
                    <div class="col-md-3">
                        <div class="text-center profile-section">
                            <div class="profile-photo-container mb-3">
                                <img src="' . ((isset($user_data['photo']) && $user_data['photo']) ? url($user_data['photo']) : asset('img/avatar.png')) . '"
                                     alt="User Photo"
                                     class="img-fluid rounded-circle profile-photo shadow"
                                     style="width: 140px; height: 140px; object-fit: cover; border: 4px solid #fff; box-shadow: 0 4px 15px rgba(0,0,0,0.1);">
                                ' . ((isset($user_data['photo']) && $user_data['photo']) ? '<div class="photo-status"><i class="fas fa-check-circle text-success"></i> Foto incluida en PDF</div>' : '<div class="photo-status text-muted"><i class="fas fa-info-circle"></i> Sin foto</div>') . '
                            </div>
                            <div class="stats-container">
                                <div class="stat-item">
                                    <span class="stat-number">' . count($user_languages) . '</span>
                                    <span class="stat-label">Idiomas</span>
                                </div>
                                <div class="stat-item">
                                    <span class="stat-number">' . count($user_trainings) . '</span>
                                    <span class="stat-label">Capacitaciones</span>
                                </div>
                                <div class="stat-item">
                                    <span class="stat-number">' . count($user_experience) . '</span>
                                    <span class="stat-label">Experiencias</span>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Personal Information Section -->
                    <div class="col-md-4">
                        <div class="info-section">
                            <h5 class="section-title">
                                <i class="fas fa-id-card text-primary"></i> Información Personal
                            </h5>
                            <div class="info-grid">
                                <div class="info-row">
                                    <span class="info-label">Nombre Completo:</span>
                                    <span class="info-value">' . htmlspecialchars($user_data['first_name'] . ' ' . $user_data['last_name']) . '</span>
                                </div>
                                <div class="info-row">
                                    <span class="info-label">DNI:</span>
                                    <span class="info-value">' . htmlspecialchars($role_info['dni'] ?? 'No especificado') . '</span>
                                </div>
                                <div class="info-row">
                                    <span class="info-label">Fecha de Nacimiento:</span>
                                    <span class="info-value">' . ($role_info['birth_date'] ? date('d/m/Y', strtotime($role_info['birth_date'])) : 'No especificada') . '</span>
                                </div>
                                <div class="info-row">
                                    <span class="info-label">Dirección:</span>
                                    <span class="info-value">' . htmlspecialchars($role_info['address'] ?? 'No especificada') . '</span>
                                </div>
                                <div class="info-row">
                                    <span class="info-label">Email:</span>
                                    <span class="info-value">' . htmlspecialchars($user_data['email']) . '</span>
                                </div>
                                <div class="info-row">
                                    <span class="info-label">Programa de Estudio:</span>
                                    <span class="info-value">' . htmlspecialchars($career['career_name'] ?? 'No especificado') . '</span>
                                </div>
                                <div class="info-row">
                                    <span class="info-label">Año de Egreso:</span>
                                    <span class="info-value">' . htmlspecialchars($role_info['graduation_year'] ?? 'No especificado') . '</span>
                                </div>
                                ' . ($user_data['role_name'] == 'egresado' ? '
                                <div class="info-row">
                                    <span class="info-label">Posición Actual:</span>
                                    <span class="info-value">' . htmlspecialchars($role_info['current_position'] ?? 'No especificada') . '</span>
                                </div>
                                <div class="info-row">
                                    <span class="info-label">Empresa Actual:</span>
                                    <span class="info-value">' . htmlspecialchars($role_info['company'] ?? 'No especificada') . '</span>
                                </div>' : '') . '
                            </div>
                        </div>
                    </div>

                    <!-- Skills and Certificates Section -->
                    <div class="col-md-5">
                        <div class="certificates-section">
                            <h5 class="section-title">
                                <i class="fas fa-certificate text-success"></i> Certificados y Habilidades
                            </h5>';

if (count($user_languages) > 0) {
    $content .= '<div class="certificate-group">
                            <h6 class="group-title">
                                <i class="fas fa-language text-info"></i> Idiomas (' . count($user_languages) . ')
                            </h6>
                            <div class="certificate-list">';
    foreach ($user_languages as $lang) {
        $content .= '<div class="certificate-item">
                                <span class="certificate-name">' . htmlspecialchars($lang['language_name']) . '</span>';
        if ($lang['certificate_file']) {
            $content .= '<a href="' . url($lang['certificate_file']) . '" target="_blank" class="btn btn-sm btn-outline-info btn-certificate">
                                    <i class="fas fa-eye"></i> Ver Certificado
                                </a>';
        }
        $content .= '</div>';
    }
    $content .= '</div></div>';
}

if (count($user_trainings) > 0) {
    $content .= '<div class="certificate-group">
                            <h6 class="group-title">
                                <i class="fas fa-graduation-cap text-success"></i> Capacitaciones (' . count($user_trainings) . ')
                            </h6>
                            <div class="certificate-list">';
    foreach ($user_trainings as $training) {
        $content .= '<div class="certificate-item">
                                <span class="certificate-name">' . htmlspecialchars($training['training_name']) . '</span>';
        if ($training['certificate_file']) {
            $content .= '<a href="' . url($training['certificate_file']) . '" target="_blank" class="btn btn-sm btn-outline-success btn-certificate">
                                    <i class="fas fa-eye"></i> Ver Certificado
                                </a>';
        }
        $content .= '</div>';
    }
    $content .= '</div></div>';
}

if (count($user_experience) > 0) {
    $content .= '<div class="certificate-group">
                            <h6 class="group-title">
                                <i class="fas fa-briefcase text-warning"></i> Experiencia Laboral (' . count($user_experience) . ')
                            </h6>
                            <div class="certificate-list">';
    foreach ($user_experience as $exp) {
        $content .= '<div class="certificate-item">
                                <span class="certificate-name">' . htmlspecialchars($exp['job_title']) . '</span>';
        if ($exp['certificate_file']) {
            $content .= '<a href="' . url($exp['certificate_file']) . '" target="_blank" class="btn btn-sm btn-outline-warning btn-certificate">
                                    <i class="fas fa-eye"></i> Ver Certificado
                                </a>';
        }
        $content .= '</div>';
    }
    $content .= '</div></div>';
}

$content .= '</div>
                    </div>
                </div>
            </div>
            <div class="card-footer bg-light">
                <div class="row">
                    <div class="col-md-6">
                        <a href="' . url('admin/resume.php?id=' . $user_id . '&download=1') . '" class="btn btn-success btn-lg btn-block">
                            <i class="fas fa-file-pdf mr-2"></i> Generar CV del Alumno
                        </a>
                    </div>
                    <div class="col-md-6 text-right">
                        <a href="' . url('admin/jobs.php') . '" class="btn btn-secondary btn-lg">
                            <i class="fas fa-arrow-left mr-2"></i> Volver
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
.card-modern {
    border: none;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}

.bg-gradient-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.profile-section {
    padding: 20px;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 10px;
    margin-bottom: 20px;
}

.profile-photo {
    border: 4px solid #fff !important;
    box-shadow: 0 8px 25px rgba(0,0,0,0.15) !important;
}

.photo-status {
    margin-top: 10px;
    font-size: 0.85rem;
    font-weight: 500;
}

.stats-container {
    display: flex;
    justify-content: space-around;
    margin-top: 15px;
}

.stat-item {
    text-align: center;
    padding: 10px;
    background: rgba(255,255,255,0.8);
    border-radius: 8px;
    min-width: 60px;
}

.stat-number {
    display: block;
    font-size: 1.5rem;
    font-weight: bold;
    color: #495057;
}

.stat-label {
    display: block;
    font-size: 0.75rem;
    color: #6c757d;
    margin-top: 2px;
}

.info-section, .certificates-section {
    background: #fff;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    margin-bottom: 20px;
}

.section-title {
    color: #495057;
    border-bottom: 2px solid #e9ecef;
    padding-bottom: 10px;
    margin-bottom: 15px;
    font-weight: 600;
}

.info-grid {
    display: grid;
    gap: 8px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #f8f9fa;
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    font-weight: 600;
    color: #495057;
    flex: 0 0 40%;
}

.info-value {
    color: #6c757d;
    flex: 1;
    text-align: right;
}

.certificate-group {
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #007bff;
}

.group-title {
    color: #495057;
    margin-bottom: 10px;
    font-weight: 600;
}

.certificate-list {
    display: grid;
    gap: 8px;
}

.certificate-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.certificate-name {
    font-weight: 500;
    color: #495057;
    flex: 1;
}

.btn-certificate {
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: 4px;
    margin-left: 10px;
}

.btn-block {
    width: 100%;
}

.mr-2 {
    margin-right: 0.5rem;
}

.ml-2 {
    margin-left: 0.5rem;
}

@media (max-width: 768px) {
    .stats-container {
        flex-direction: column;
        gap: 10px;
    }

    .stat-item {
        width: 100%;
    }

    .info-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .info-value {
        text-align: left;
    }

    .certificate-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .btn-certificate {
        align-self: stretch;
        margin-left: 0;
        margin-top: 8px;
    }
}
</style>';

include __DIR__ . '/../includes/layout.php';
