<?php include('config.php'); ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>My Professional CV</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        body { font-family: 'Arial', sans-serif; background: #f4f4f4; margin: 0; padding: 0; color: #333; }
        .cv-page { width: 210mm; min-height: 297mm; padding: 20mm; margin: 10mm auto; background: white; box-shadow: 0 0 10px rgba(0,0,0,0.1); position: relative; }
        
        /* Layout */
        .header { display: flex; align-items: center; border-bottom: 3px solid #38bdf8; padding-bottom: 20px; margin-bottom: 30px; }
        .header-img { width: 120px; height: 120px; border-radius: 10px; object-fit: cover; margin-right: 25px; border: 2px solid #38bdf8; }
        .header-info h1 { margin: 0; color: #0f172a; text-transform: uppercase; letter-spacing: 1px; }
        .contact-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; font-size: 13px; color: #666; }

        .section-title { background: #f1f5f9; color: #0369a1; padding: 8px 15px; font-weight: bold; text-transform: uppercase; margin: 25px 0 15px 0; border-left: 5px solid #38bdf8; }
        
        .item { margin-bottom: 15px; }
        .item-header { display: flex; justify-content: space-between; font-weight: bold; color: #0f172a; }
        .item-sub { color: #0369a1; font-style: italic; font-size: 14px; }
        .item-desc { font-size: 13px; margin-top: 5px; line-height: 1.5; text-align: justify; }

        .skills-container { display: flex; flex-wrap: wrap; gap: 10px; }
        .skill-tag { background: #e0f2fe; color: #0369a1; padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: bold; border: 1px solid #bae6fd; }

        /* Print Button - Screen Only */
        .no-print { position: fixed; bottom: 20px; right: 20px; background: #38bdf8; color: white; padding: 15px 30px; border: none; border-radius: 50px; cursor: pointer; font-weight: bold; box-shadow: 0 5px 15px rgba(0,0,0,0.2); }
        @media print { .no-print { display: none; } .cv-page { margin: 0; box-shadow: none; } body { background: white; } }
    </style>
</head>
<body>

<button class="no-print" onclick="window.print()"><i class="fas fa-print"></i> Download / Print CV</button>

<div class="cv-page">
    <?php
    // Fetch Bio
    $bio_res = mysqli_query($conn, "SELECT * FROM cv_bio LIMIT 1");
    $bio = mysqli_fetch_assoc($bio_res);
    ?>

    <div class="header">
        <?php if(!empty($bio['profile_pic'])): ?>
            <img src="uploads/<?php echo $bio['profile_pic']; ?>" class="header-img">
        <?php endif; ?>
        <div class="header-info">
            <h1><?php echo $bio['full_name'] ?? 'Your Name'; ?></h1>
            <div class="contact-grid">
                <span><i class="fas fa-envelope"></i> <?php echo $bio['email'] ?? ''; ?></span>
                <span><i class="fas fa-phone"></i> <?php echo $bio['phone'] ?? ''; ?></span>
                <span><i class="fas fa-map-marker-alt"></i> <?php echo $bio['address'] ?? ''; ?></span>
                <span><i class="fab fa-github"></i> <?php echo $bio['github'] ?? ''; ?></span>
            </div>
        </div>
    </div>

    <div class="section-title">Professional Objective</div>
    <p class="item-desc"><?php echo $bio['objective'] ?? ''; ?></p>

    <!-- EDUCATION SECTION -->
    <div class="section-title">Education</div>
    <?php
    $edu_res = mysqli_query($conn, "SELECT * FROM cv_education ORDER BY id DESC");
    while($edu = mysqli_fetch_assoc($edu_res)): ?>
        <div class="item">
            <div class="item-header">
                <span><?php echo $edu['degree_level']; ?></span>
                <span><?php echo $edu['division_grade']; ?></span>
            </div>
            <div class="item-sub"><?php echo $edu['institute']; ?> | <?php echo $edu['board_university']; ?></div>
            <div class="item-desc">Marks/GPA: <?php echo $edu['marks_gpa']; ?></div>
        </div>
    <?php endwhile; ?>

    <!-- PROJECTS SECTION -->
    <div class="section-title">Projects</div>
    <?php
    $proj_res = mysqli_query($conn, "SELECT * FROM cv_projects ORDER BY id DESC");
    while($proj = mysqli_fetch_assoc($proj_res)): ?>
        <div class="item">
            <div class="item-header">
                <span><?php echo $proj['project_title']; ?></span>
                <a href="<?php echo $proj['project_link']; ?>" style="font-size: 12px; color: #38bdf8;">Live Link</a>
            </div>
            <div class="item-sub">Tech Stack: <?php echo $proj['tech_stack']; ?></div>
            <div class="item-desc"><?php echo $proj['description']; ?></div>
        </div>
    <?php endwhile; ?>

    <!-- SKILLS SECTION -->
    <div class="section-title">Skills</div>
    <div class="skills-container">
        <?php
        $skill_res = mysqli_query($conn, "SELECT * FROM cv_skills");
        while($skill = mysqli_fetch_assoc($skill_res)): ?>
            <span class="skill-tag"><?php echo $skill['skill_name']; ?> (<?php echo $skill['proficiency']; ?>)</span>
        <?php endwhile; ?>
    </div>

</div>

</body>
</html>