<?php

include 'include/header.php'; // ← Outputs <!DOCTYPE html> … both navbars … </script>

// DB Configuration
$db_host = 'localhost';
$db_user = 'u427625983_schoolinmycity';
$db_pass = 'K#$%^tfvgyt657guvgGG';
$db_name = 'u427625983_schoolinmycity';

$success_message = '';
$error_message = '';
$form_errors = [];

// ── DB helper ───────────────────────────────────────────────────────────────
function getDB($db_host, $db_user, $db_pass, $db_name) {
    $conn = new mysqli($db_host, $db_user, $db_pass, $db_name);
    if ($conn->connect_error) return null;
    $conn->set_charset("utf8mb4");

    $sql = "CREATE TABLE IF NOT EXISTS editorial_application (
        id INT AUTO_INCREMENT PRIMARY KEY,
        salutation VARCHAR(10) NOT NULL,
        full_name VARCHAR(255) NOT NULL,
        gender VARCHAR(20) NOT NULL,
        current_employment VARCHAR(500) NOT NULL,
        total_experience INT NOT NULL,
        educational_qualifications VARCHAR(500) NOT NULL,
        research_area VARCHAR(200) NOT NULL,
        personal_email VARCHAR(255) NOT NULL,
        work_email VARCHAR(255) NOT NULL,
        mobile_no VARCHAR(30) NOT NULL,
        whatsapp_no VARCHAR(30) NOT NULL,
        city VARCHAR(100) NOT NULL,
        state_province VARCHAR(100),
        country VARCHAR(100),
        international_publications INT NOT NULL,
        rsis_journal_publications INT NOT NULL,
        how_did_you_find_us VARCHAR(100) NOT NULL,
        cv_filename VARCHAR(500),
        cv_original_name VARCHAR(500),
        agreed_terms TINYINT(1) NOT NULL DEFAULT 0,
        submitted_at DATETIME DEFAULT CURRENT_TIMESTAMP,
        ip_address VARCHAR(45)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;";

    $conn->query($sql);
    return $conn;
}

// ── Send HTML email (same pattern as reviewer form) ─────────────────────────
function sendMail($to_email, $subject, $html_body) {
    $from_email = 'editorial.office@communeglobal.com';
    $from_name  = 'Communeglobal Editorial Office';

    if (!filter_var($to_email, FILTER_VALIDATE_EMAIL)) {
        error_log("sendMail SKIP: invalid address — $to_email");
        return false;
    }

    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
    $headers .= 'From: =?UTF-8?B?' . base64_encode($from_name) . '?= <' . $from_email . '>' . "\r\n";
    $headers .= 'Reply-To: ' . $from_email . "\r\n";
    $headers .= 'Return-Path: ' . $from_email . "\r\n";
    $headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
    $headers .= 'Message-ID: <' . time() . '.' . md5($to_email . $subject) . '@communeglobal.com>';

    $encoded_subject   = '=?UTF-8?B?' . base64_encode($subject) . '?=';
    $additional_params = '-f' . $from_email;

    $sent = mail($to_email, $encoded_subject, $html_body, $headers, $additional_params);

    if (!$sent) {
        $err = error_get_last();
        error_log("sendMail FAILED to $to_email | $subject | PHP error: " . ($err['message'] ?? 'none'));
    } else {
        error_log("sendMail OK to $to_email | $subject");
    }

    return $sent;
}

// ── Applicant confirmation email ─────────────────────────────────────────────
function sendApplicantEmail($full_name, $to_email, $research_area) {
    $subject = 'Editorial Board Application Received | Communeglobal';

    $html = '<!DOCTYPE html>
<html><head><meta charset="UTF-8"></head>
<body style="margin:0;padding:0;background:#f3f4f6;font-family:Arial,sans-serif;">
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f3f4f6;padding:40px 0;">
<tr><td align="center">
<table width="600" cellpadding="0" cellspacing="0" style="background:#ffffff;border-radius:8px;overflow:hidden;box-shadow:0 2px 8px rgba(0,0,0,0.08);">
  <tr>
    <td style="background:#0d2241;padding:32px 40px;text-align:center;">
      <h1 style="margin:0;color:#ffffff;font-size:22px;font-weight:700;">Communeglobal</h1>
      <p style="margin:6px 0 0;color:#93c5fd;font-size:13px;">International Peer-Reviewed Open Access Journals</p>
    </td>
  </tr>
  <tr>
    <td style="padding:36px 40px;">
      <p style="margin:0 0 16px;font-size:15px;color:#111827;">Dear <strong>' . htmlspecialchars($full_name) . '</strong>,</p>
      <p style="margin:0 0 16px;font-size:14px;color:#374151;line-height:1.7;">
        Thank you for applying to join the Communeglobal Editorial Board. We have successfully received your application and our editorial team will review it shortly.
      </p>

      <table width="100%" cellpadding="0" cellspacing="0" style="margin:20px 0;">
        <tr>
          <td style="background:#eff6ff;border:1px solid #bfdbfe;border-radius:8px;padding:20px;">
            <p style="margin:0 0 10px;font-size:13px;font-weight:700;color:#1d4ed8;text-transform:uppercase;letter-spacing:1px;">Application Summary</p>
            <table width="100%" cellpadding="0" cellspacing="0">
              <tr>
                <td style="font-size:13px;color:#6b7280;padding:4px 0;width:40%;">Research Area</td>
                <td style="font-size:13px;color:#111827;font-weight:600;padding:4px 0;">' . htmlspecialchars($research_area) . '</td>
              </tr>
              <tr>
                <td style="font-size:13px;color:#6b7280;padding:4px 0;">Date Submitted</td>
                <td style="font-size:13px;color:#111827;font-weight:600;padding:4px 0;">' . date('d M Y, h:i A') . '</td>
              </tr>
            </table>
          </td>
        </tr>
      </table>

      <table width="100%" cellpadding="0" cellspacing="0" style="margin:20px 0;">
        <tr>
          <td style="background:#f9fafb;border-left:4px solid #0d2241;border-radius:0 6px 6px 0;padding:16px 20px;">
            <p style="margin:0 0 8px;font-size:13px;font-weight:700;color:#0d2241;">What happens next?</p>
            <ul style="margin:0;padding-left:18px;">
              <li style="font-size:13px;color:#374151;padding:3px 0;">Our editorial team will review your application (typically within 5–7 business days).</li>
              <li style="font-size:13px;color:#374151;padding:3px 0;">You will receive an email notification once a decision has been made.</li>
              <li style="font-size:13px;color:#374151;padding:3px 0;">If approved, you will be officially added to the Editorial Board of the selected journal.</li>
            </ul>
          </td>
        </tr>
      </table>

      <p style="margin:24px 0 0;font-size:14px;color:#374151;line-height:1.7;">
        If you have any questions, please contact us at
        <a href="mailto:editorial.office@communeglobal.com" style="color:#1d4ed8;">editorial.office@communeglobal.com</a>.
      </p>
      <p style="margin:20px 0 0;font-size:14px;color:#374151;">
        Warm regards,<br><strong>Editorial Office</strong><br>Communeglobal International Journals
      </p>
    </td>
  </tr>
  <tr>
    <td style="background:#f9fafb;border-top:1px solid #e5e7eb;padding:20px 40px;text-align:center;">
      <p style="margin:0;font-size:12px;color:#9ca3af;">
        &copy; ' . date('Y') . ' Communeglobal. All rights reserved.<br>
        <a href="https://communeglobal.com" style="color:#6b7280;">communeglobal.com</a>
      </p>
    </td>
  </tr>
</table>
</td></tr>
</table>
</body></html>';

    return sendMail($to_email, $subject, $html);
}

// ── Admin notification email ──────────────────────────────────────────────────
function sendAdminEmail(
    $full_name, $salutation, $gender, $applicant_email, $work_email,
    $mobile_no, $whatsapp_no,
    $current_employment, $total_experience, $educational_qualifications,
    $research_area,
    $city, $state_province, $country,
    $international_publications, $rsis_journal_publications,
    $how_did_you_find_us,
    $cv_original_name
) {
    $admin_email = 'editorialoffice@rsis-international.org';
    $subject     = '[New Editorial Board Application] ' . $salutation . ' ' . $full_name;

    $html = '<!DOCTYPE html>
<html><head><meta charset="UTF-8"></head>
<body style="margin:0;padding:0;background:#f3f4f6;font-family:Arial,sans-serif;">
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f3f4f6;padding:40px 0;">
<tr><td align="center">
<table width="620" cellpadding="0" cellspacing="0" style="background:#ffffff;border-radius:8px;overflow:hidden;box-shadow:0 2px 8px rgba(0,0,0,0.08);">
  <tr>
    <td style="background:#1e293b;padding:24px 32px;">
      <p style="margin:0;font-size:11px;color:#94a3b8;text-transform:uppercase;letter-spacing:1px;">Admin Notification</p>
      <h1 style="margin:6px 0 0;color:#ffffff;font-size:18px;">New Editorial Board Application</h1>
    </td>
  </tr>
  <tr>
    <td style="background:#0d2241;padding:14px 32px;">
      <p style="margin:0;font-size:13px;color:#93c5fd;">
        Received: <strong style="color:#ffffff;">' . date('d M Y, h:i A') . '</strong>
      </p>
    </td>
  </tr>
  <tr><td style="padding:28px 32px;">

    <p style="margin:0 0 12px;font-size:14px;font-weight:700;color:#111827;border-bottom:2px solid #e5e7eb;padding-bottom:8px;">Personal Information</p>
    <table width="100%" cellpadding="0" cellspacing="0" style="margin-bottom:20px;">
      <tr style="background:#f9fafb;">
        <td style="padding:8px 12px;font-size:13px;color:#6b7280;width:40%;">Full Name</td>
        <td style="padding:8px 12px;font-size:13px;color:#111827;font-weight:600;">' . htmlspecialchars($salutation . ' ' . $full_name) . '</td>
      </tr>
      <tr>
        <td style="padding:8px 12px;font-size:13px;color:#6b7280;">Gender</td>
        <td style="padding:8px 12px;font-size:13px;color:#111827;">' . htmlspecialchars($gender) . '</td>
      </tr>
      <tr style="background:#f9fafb;">
        <td style="padding:8px 12px;font-size:13px;color:#6b7280;">Personal Email</td>
        <td style="padding:8px 12px;font-size:13px;"><a href="mailto:' . htmlspecialchars($applicant_email) . '" style="color:#1d4ed8;">' . htmlspecialchars($applicant_email) . '</a></td>
      </tr>
      <tr>
        <td style="padding:8px 12px;font-size:13px;color:#6b7280;">Work Email</td>
        <td style="padding:8px 12px;font-size:13px;"><a href="mailto:' . htmlspecialchars($work_email) . '" style="color:#1d4ed8;">' . htmlspecialchars($work_email) . '</a></td>
      </tr>
      <tr style="background:#f9fafb;">
        <td style="padding:8px 12px;font-size:13px;color:#6b7280;">Mobile</td>
        <td style="padding:8px 12px;font-size:13px;color:#111827;">' . htmlspecialchars($mobile_no) . '</td>
      </tr>
      <tr>
        <td style="padding:8px 12px;font-size:13px;color:#6b7280;">WhatsApp</td>
        <td style="padding:8px 12px;font-size:13px;color:#111827;">' . htmlspecialchars($whatsapp_no) . '</td>
      </tr>
      <tr style="background:#f9fafb;">
        <td style="padding:8px 12px;font-size:13px;color:#6b7280;">Location</td>
        <td style="padding:8px 12px;font-size:13px;color:#111827;">' . htmlspecialchars(implode(', ', array_filter([$city, $state_province, $country]))) . '</td>
      </tr>
    </table>

    <p style="margin:0 0 12px;font-size:14px;font-weight:700;color:#111827;border-bottom:2px solid #e5e7eb;padding-bottom:8px;">Professional Information</p>
    <table width="100%" cellpadding="0" cellspacing="0" style="margin-bottom:20px;">
      <tr style="background:#f9fafb;">
        <td style="padding:8px 12px;font-size:13px;color:#6b7280;width:40%;">Current Employment</td>
        <td style="padding:8px 12px;font-size:13px;color:#111827;">' . htmlspecialchars($current_employment) . '</td>
      </tr>
      <tr>
        <td style="padding:8px 12px;font-size:13px;color:#6b7280;">Total Experience</td>
        <td style="padding:8px 12px;font-size:13px;color:#111827;">' . htmlspecialchars($total_experience) . ' year(s)</td>
      </tr>
      <tr style="background:#f9fafb;">
        <td style="padding:8px 12px;font-size:13px;color:#6b7280;">Educational Qualifications</td>
        <td style="padding:8px 12px;font-size:13px;color:#111827;">' . htmlspecialchars($educational_qualifications) . '</td>
      </tr>
      <tr>
        <td style="padding:8px 12px;font-size:13px;color:#6b7280;">Research Area</td>
        <td style="padding:8px 12px;font-size:13px;color:#111827;">' . htmlspecialchars($research_area) . '</td>
      </tr>
      <tr style="background:#f9fafb;">
        <td style="padding:8px 12px;font-size:13px;color:#6b7280;">Intl. Publications</td>
        <td style="padding:8px 12px;font-size:13px;color:#111827;">' . htmlspecialchars($international_publications) . '</td>
      </tr>
      <tr>
        <td style="padding:8px 12px;font-size:13px;color:#6b7280;">Communeglobal Publications</td>
        <td style="padding:8px 12px;font-size:13px;color:#111827;">' . htmlspecialchars($rsis_journal_publications) . '</td>
      </tr>
      <tr style="background:#f9fafb;">
        <td style="padding:8px 12px;font-size:13px;color:#6b7280;">How Did They Find Us</td>
        <td style="padding:8px 12px;font-size:13px;color:#111827;">' . htmlspecialchars($how_did_you_find_us) . '</td>
      </tr>
      <tr>
        <td style="padding:8px 12px;font-size:13px;color:#6b7280;">CV File</td>
        <td style="padding:8px 12px;font-size:13px;color:#111827;">' . htmlspecialchars($cv_original_name ?: 'Not uploaded') . '</td>
      </tr>
    </table>

    <table width="100%" cellpadding="0" cellspacing="0">
      <tr>
        <td align="center" style="padding:8px 0;">
          <a href="https://communeglobal.com/admin/editorial_applications.php"
             style="display:inline-block;background:#0d2241;color:#ffffff;text-decoration:none;padding:12px 32px;border-radius:6px;font-size:14px;font-weight:600;">
            Review Application in Admin Panel
          </a>
        </td>
      </tr>
    </table>

  </td></tr>
  <tr>
    <td style="background:#f9fafb;border-top:1px solid #e5e7eb;padding:16px 32px;text-align:center;">
      <p style="margin:0;font-size:12px;color:#9ca3af;">
        Automated notification from Communeglobal Editorial System<br>
        &copy; ' . date('Y') . ' Communeglobal
      </p>
    </td>
  </tr>
</table>
</td></tr>
</table>
</body></html>';

    return sendMail($admin_email, $subject, $html);
}

// ── Handle form submission ───────────────────────────────────────────────────
if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    // Sanitize inputs
    $salutation                 = trim($_POST['salutation'] ?? '');
    $full_name                  = trim($_POST['full_name'] ?? '');
    $gender                     = trim($_POST['gender'] ?? '');
    $current_employment         = trim($_POST['current_employment'] ?? '');
    $total_experience           = intval($_POST['total_experience'] ?? 0);
    $educational_qualifications = trim($_POST['educational_qualifications'] ?? '');
    $research_area              = trim($_POST['research_area'] ?? '');
    $personal_email             = trim($_POST['personal_email'] ?? '');
    $work_email                 = trim($_POST['work_email'] ?? '');
    $mobile_no                  = trim($_POST['mobile_no'] ?? '');
    $whatsapp_no                = trim($_POST['whatsapp_no'] ?? '');
    $city                       = trim($_POST['city'] ?? '');
    $state_province             = trim($_POST['state_province'] ?? '');
    $country                    = trim($_POST['country'] ?? '');
    $international_publications = intval($_POST['international_publications'] ?? 0);
    $rsis_journal_publications  = intval($_POST['rsis_journal_publications'] ?? 0);
    $how_did_you_find_us        = trim($_POST['how_did_you_find_us'] ?? '');
    $agreed_terms               = isset($_POST['agreed_terms']) ? 1 : 0;

    // Validation
    if (empty($salutation))               $form_errors['salutation']                 = 'Please select a salutation.';
    if (empty($full_name))                $form_errors['full_name']                  = 'Full name is required.';
    if (empty($gender))                   $form_errors['gender']                     = 'Please select gender.';
    if (empty($current_employment))       $form_errors['current_employment']         = 'Current employment is required.';
    if (empty($educational_qualifications)) $form_errors['educational_qualifications'] = 'Educational qualifications are required.';
    if (empty($research_area))            $form_errors['research_area']              = 'Please select a research area.';
    if (empty($personal_email) || !filter_var($personal_email, FILTER_VALIDATE_EMAIL))
                                          $form_errors['personal_email']             = 'Valid personal email is required.';
    if (empty($work_email) || !filter_var($work_email, FILTER_VALIDATE_EMAIL))
                                          $form_errors['work_email']                 = 'Valid work email is required.';
    if (empty($mobile_no))                $form_errors['mobile_no']                  = 'Mobile number is required.';
    if (empty($whatsapp_no))              $form_errors['whatsapp_no']                = 'WhatsApp number is required.';
    if (empty($city))                     $form_errors['city']                       = 'City is required.';
    if (empty($how_did_you_find_us))      $form_errors['how_did_you_find_us']        = 'Please tell us how you found us.';
    if (!$agreed_terms)                   $form_errors['agreed_terms']               = 'You must agree to the terms and conditions.';

    // CV Upload Validation
    $cv_filename      = null;
    $cv_original_name = null;

    if (isset($_FILES['cv']) && $_FILES['cv']['error'] !== UPLOAD_ERR_NO_FILE) {
        $file = $_FILES['cv'];

        if ($file['error'] !== UPLOAD_ERR_OK) {
            $form_errors['cv'] = 'File upload failed. Please try again.';
        } else {
            $original_name    = $file['name'];
            $file_ext         = strtolower(pathinfo($original_name, PATHINFO_EXTENSION));
            $allowed_extensions = ['pdf', 'doc', 'docx'];
            $allowed_mimes    = [
                'pdf'  => 'application/pdf',
                'doc'  => 'application/msword',
                'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
            ];
            $blocked_mimes = [
                'application/x-msdownload','application/x-executable',
                'application/x-sh','application/x-php',
                'text/x-php','application/x-httpd-php',
                'application/javascript','text/html',
                'application/x-perl','application/x-python',
            ];

            $finfo         = finfo_open(FILEINFO_MIME_TYPE);
            $detected_mime = finfo_file($finfo, $file['tmp_name']);
            finfo_close($finfo);

            $mime_valid = in_array($detected_mime, $allowed_mimes) ||
                          ($file_ext === 'doc'  && $detected_mime === 'application/msword') ||
                          ($file_ext === 'docx' && strpos($detected_mime, 'officedocument') !== false);

            if (!in_array($file_ext, $allowed_extensions)) {
                $form_errors['cv'] = 'Only PDF, DOC, or DOCX files are allowed.';
            } elseif (in_array($detected_mime, $blocked_mimes)) {
                $form_errors['cv'] = 'This file type is not allowed for security reasons.';
            } elseif (!$mime_valid) {
                $form_errors['cv'] = 'File content does not match its extension. Only PDF or Word documents are accepted.';
            } elseif ($file['size'] > 5 * 1024 * 1024) {
                $form_errors['cv'] = 'File size must not exceed 5MB.';
            } else {
                $upload_dir = __DIR__ . '/uploads/editor_cv/';
                if (!is_dir($upload_dir)) mkdir($upload_dir, 0755, true);
                $safe_name = time() . '_' . bin2hex(random_bytes(8)) . '.' . $file_ext;
                if (move_uploaded_file($file['tmp_name'], $upload_dir . $safe_name)) {
                    $cv_filename      = $safe_name;
                    $cv_original_name = $original_name;
                } else {
                    $form_errors['cv'] = 'Could not save the uploaded file.';
                }
            }
        }
    } else {
        $form_errors['cv'] = 'CV upload is required.';
    }

    // Insert into DB and send emails if no errors
    if (empty($form_errors)) {
        $conn = getDB($db_host, $db_user, $db_pass, $db_name);
        if (!$conn) {
            $error_message = 'Database connection failed. Please try again later.';
        } else {
            $ip = $_SERVER['REMOTE_ADDR'] ?? '';

            $stmt = $conn->prepare("INSERT INTO editorial_application
                (salutation, full_name, gender, current_employment, total_experience,
                 educational_qualifications, research_area, personal_email, work_email,
                 mobile_no, whatsapp_no, city, state_province, country,
                 international_publications, rsis_journal_publications, how_did_you_find_us,
                 cv_filename, cv_original_name, agreed_terms, ip_address)
                VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");

            $stmt->bind_param(
                "ssssississsssiisssiis",
                $salutation, $full_name, $gender, $current_employment,
                $total_experience, $educational_qualifications, $research_area,
                $personal_email, $work_email, $mobile_no, $whatsapp_no,
                $city, $state_province, $country,
                $international_publications, $rsis_journal_publications,
                $how_did_you_find_us, $cv_filename, $cv_original_name,
                $agreed_terms, $ip
            );

            if ($stmt->execute()) {
                $stmt->close();
                $conn->close();

                // ── Send applicant confirmation email (to personal email) ──
                $sent_applicant = sendApplicantEmail(
                    $full_name,
                    $personal_email,
                    $research_area
                );

                // ── Send admin notification email ──────────────────────────
                $sent_admin = sendAdminEmail(
                    $full_name, $salutation, $gender,
                    $personal_email, $work_email,
                    $mobile_no, $whatsapp_no,
                    $current_employment, $total_experience, $educational_qualifications,
                    $research_area,
                    $city, $state_province, $country,
                    $international_publications, $rsis_journal_publications,
                    $how_did_you_find_us,
                    $cv_original_name
                );

                error_log("EBM Application — Applicant email: " . ($sent_applicant ? 'OK' : 'FAILED') . " | Admin email: " . ($sent_admin ? 'OK' : 'FAILED'));

                $success_message = 'Your application has been submitted successfully! A confirmation email has been sent to ' . htmlspecialchars($personal_email) . '. We will review it and get back to you soon.';
                $_POST = [];

            } else {
                $error_message = 'Failed to save your application. Please try again. Error: ' . $stmt->error;
                $stmt->close();
                $conn->close();
            }
        }
    }
}

// Helper to keep form values after error
function val($key, $default = '') {
    return htmlspecialchars($_POST[$key] ?? $default);
}
function sel($key, $value) {
    return (isset($_POST[$key]) && $_POST[$key] === $value) ? 'selected' : '';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Join as Editorial Board Member – Communeglobal</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;600;700&family=DM+Sans:wght@300;400;500;600&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">

    <style>
        *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

        :root {
            --navy: #0d2241;
            --navy-mid: #1a3a6b;
            --gold: #c9a84c;
            --gold-light: #e8c97a;
            --cream: #faf8f3;
            --white: #ffffff;
            --red: #d94040;
            --green: #2d7d46;
            --text: #1c2b3a;
            --muted: #6b7a8d;
            --border: #dde3eb;
            --input-bg: #f5f7fa;
            --shadow: 0 2px 16px rgba(13,34,65,0.10);
            --radius: 10px;
        }

        body {
            font-family: 'DM Sans', sans-serif;
            background: var(--cream);
            color: var(--text);
            min-height: 100vh;
        }

        .page-header {
            background: linear-gradient(135deg, var(--navy) 0%, var(--navy-mid) 60%, #1e4c8a 100%);
            color: white;
            padding: 60px 24px 50px;
            text-align: center;
            position: relative;
            overflow: hidden;
        }
        .page-header::before {
            content: '';
            position: absolute; inset: 0;
            background: repeating-linear-gradient(45deg, transparent, transparent 40px, rgba(201,168,76,0.06) 40px, rgba(201,168,76,0.06) 80px);
        }
        .page-header h1 { font-family: 'Playfair Display', serif; font-size: clamp(2rem, 5vw, 3.2rem); font-weight: 700; letter-spacing: -0.5px; position: relative; }
        .page-header h1 span { color: var(--gold-light); }
        .header-line { width: 60px; height: 3px; background: var(--gold); margin: 18px auto 16px; border-radius: 2px; position: relative; }
        .page-header p { font-size: 1.05rem; opacity: 0.85; max-width: 540px; margin: 0 auto; font-weight: 300; position: relative; }

        .form-wrap { max-width: 1000px; margin: 28px auto 60px; padding: 0 16px; }
        .form-card { background: var(--white); border-radius: 18px; box-shadow: 0 8px 48px rgba(13,34,65,0.13); overflow: hidden; }

        .section-head { background: linear-gradient(90deg, var(--navy) 0%, var(--navy-mid) 100%); color: white; padding: 14px 28px; font-family: 'Playfair Display', serif; font-size: 1rem; font-weight: 600; letter-spacing: 0.5px; display: flex; align-items: center; gap: 10px; }
        .section-head .dot { width: 8px; height: 8px; background: var(--gold); border-radius: 50%; flex-shrink: 0; }

        .form-body { padding: 32px 28px 28px; }

        .form-grid { display: grid; gap: 22px; }
        .ebm-col-2 { grid-template-columns: 1fr 1fr !important; }
        .ebm-col-3 { grid-template-columns: 1fr 1fr 1fr !important; }
        @media (max-width: 600px) {
            .ebm-col-2, .ebm-col-3 { grid-template-columns: 1fr !important; }
            .form-body { padding: 24px 16px 20px; }
        }

        .field-group { display: flex; flex-direction: column; gap: 6px; }
        label { font-size: 0.82rem; font-weight: 600; color: var(--navy); text-transform: uppercase; letter-spacing: 0.6px; }
        label .req { color: var(--red); margin-left: 2px; }

        input[type="text"], input[type="email"], input[type="tel"], select {
            width: 100%; padding: 11px 14px; border: 1.5px solid var(--border); border-radius: var(--radius);
            background: var(--input-bg); font-family: 'DM Sans', sans-serif; font-size: 0.95rem; color: var(--text);
            transition: border-color 0.2s, box-shadow 0.2s; appearance: none; -webkit-appearance: none;
        }
        input:focus, select:focus { outline: none; border-color: var(--navy-mid); box-shadow: 0 0 0 3px rgba(26,58,107,0.10); background: white; }
        select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%236b7a8d' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 38px; }

        .field-error input, .field-error select { border-color: var(--red) !important; background: #fff5f5; }
        .error-msg { font-size: 0.78rem; color: var(--red); font-weight: 500; }

        .file-upload-wrap { border: 2px dashed var(--border); border-radius: var(--radius); padding: 20px; text-align: center; background: var(--input-bg); cursor: pointer; transition: border-color 0.2s, background 0.2s; position: relative; }
        .file-upload-wrap:hover { border-color: var(--navy-mid); background: #eef2f8; }
        .file-upload-wrap input[type="file"] { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
        .file-icon { font-size: 2rem; margin-bottom: 8px; }
        .file-label { font-size: 0.9rem; color: var(--navy-mid); font-weight: 500; }
        .file-hint { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }
        .field-error .file-upload-wrap { border-color: var(--red); background: #fff5f5; }

        .checkbox-wrap { display: flex; align-items: flex-start; gap: 12px; padding: 16px; background: #f0f4fa; border-radius: var(--radius); border: 1.5px solid var(--border); }
        .checkbox-wrap input[type="checkbox"] { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--navy); cursor: pointer; flex-shrink: 0; }
        .checkbox-wrap label { font-size: 0.88rem; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--text); cursor: pointer; }
        .checkbox-wrap label a { color: var(--navy-mid); font-weight: 600; }
        .field-error .checkbox-wrap { border-color: var(--red); background: #fff5f5; }

        .section-gap { height: 8px; background: #f2f4f8; }

        .alert { margin: 0 28px 24px; padding: 16px 20px; border-radius: var(--radius); font-size: 0.95rem; font-weight: 500; display: flex; align-items: flex-start; gap: 12px; }
        .alert-success { background: #edfaf3; color: var(--green); border: 1.5px solid #a3d9b8; }
        .alert-error { background: #fff0f0; color: var(--red); border: 1.5px solid #f5b8b8; }
        .alert-icon { font-size: 1.3rem; flex-shrink: 0; }

        .form-wrap .btn-submit { display: block; width: 100%; padding: 15px; background: linear-gradient(135deg, var(--navy) 0%, var(--navy-mid) 100%); color: white; border: none; border-radius: var(--radius); font-family: 'DM Sans', sans-serif; font-size: 1rem; font-weight: 600; cursor: pointer; letter-spacing: 0.5px; transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s; position: relative; overflow: hidden; }
        .form-wrap .btn-submit::after { content: ''; position: absolute; top: 0; left: -100%; width: 60%; height: 100%; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.12), transparent); transition: left 0.5s; }
        .form-wrap .btn-submit:hover::after { left: 140%; }
        .form-wrap .btn-submit:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(13,34,65,0.28); }
        .form-wrap .btn-submit:active { transform: translateY(0); }

        .form-footer { padding: 20px 28px 30px; }
        .required-note { font-size: 0.78rem; color: var(--muted); text-align: center; margin-top: 14px; }

        .main-content { flex: 1; min-width: 0; }
        .main-layout { display: flex; align-items: flex-start; gap: 24px; }
        .sidebar { width: 260px; min-width: 260px; }
        @media (max-width: 768px) {
            .main-layout { flex-direction: column; }
            .sidebar { width: 100%; min-width: 100%; }
        }
        .main-content { width: 100%; }
        .container { max-width: 1200px; margin: 0 auto; }
    </style>
</head>
<body>
<div class="page-header">
    <h1>Join as <span>Editorial Board Member</span></h1>
    <div class="header-line"></div>
    <p>Apply to join our international peer-review editorial panel across Communeglobal journals.</p>
</div>
<div class="container">
    <div class="main-layout">
        <?php include __DIR__ . '/include/nsidebar.php'; ?>

        <section class="main-content">
            <div class="form-wrap">
                <div class="form-card">

                    <?php if ($success_message): ?>
                    <div style="padding: 28px;">
                        <div class="alert alert-success">
                            <span class="alert-icon">✅</span>
                            <div><?= htmlspecialchars($success_message) ?></div>
                        </div>
                    </div>
                    <?php endif; ?>

                    <?php if ($error_message): ?>
                    <div class="alert alert-error" style="margin: 24px 28px 0;">
                        <span class="alert-icon">⚠️</span>
                        <div><?= htmlspecialchars($error_message) ?></div>
                    </div>
                    <?php endif; ?>

                    <form method="POST" enctype="multipart/form-data" novalidate>

                        <div class="section-gap"></div>

                        <!-- PERSONAL INFO -->
                        <div class="section-head"><span class="dot"></span> Personal Information</div>
                        <div class="form-body">
                            <div class="form-grid ebm-col-3">
                                <div class="field-group <?= isset($form_errors['salutation']) ? 'field-error' : '' ?>">
                                    <label for="salutation">Salutation <span class="req">*</span></label>
                                    <select name="salutation" id="salutation" required>
                                        <option value="">— Select —</option>
                                        <option value="Mr" <?= sel('salutation','Mr') ?>>Mr</option>
                                        <option value="Mrs" <?= sel('salutation','Mrs') ?>>Mrs</option>
                                        <option value="Dr" <?= sel('salutation','Dr') ?>>Dr</option>
                                        <option value="Er" <?= sel('salutation','Er') ?>>Er</option>
                                    </select>
                                    <?php if (isset($form_errors['salutation'])): ?><span class="error-msg"><?= $form_errors['salutation'] ?></span><?php endif; ?>
                                </div>
                                <div class="field-group <?= isset($form_errors['full_name']) ? 'field-error' : '' ?>" style="grid-column: span 2;">
                                    <label for="full_name">Full Name <span class="req">*</span></label>
                                    <input type="text" name="full_name" id="full_name" placeholder="E.g. John Smith" value="<?= val('full_name') ?>" required>
                                    <?php if (isset($form_errors['full_name'])): ?><span class="error-msg"><?= $form_errors['full_name'] ?></span><?php endif; ?>
                                </div>
                            </div>
                            <div class="form-grid ebm-col-2" style="margin-top:22px;">
                                <div class="field-group <?= isset($form_errors['gender']) ? 'field-error' : '' ?>">
                                    <label for="gender">Gender <span class="req">*</span></label>
                                    <select name="gender" id="gender" required>
                                        <option value="">— Select —</option>
                                        <option value="Male" <?= sel('gender','Male') ?>>Male</option>
                                        <option value="Female" <?= sel('gender','Female') ?>>Female</option>
                                        <option value="Other" <?= sel('gender','Other') ?>>Other</option>
                                    </select>
                                    <?php if (isset($form_errors['gender'])): ?><span class="error-msg"><?= $form_errors['gender'] ?></span><?php endif; ?>
                                </div>
                                <div class="field-group <?= isset($form_errors['current_employment']) ? 'field-error' : '' ?>">
                                    <label for="current_employment">Current Employment <span class="req">*</span></label>
                                    <input type="text" name="current_employment" id="current_employment" placeholder="E.g. IIT Gandhinagar" value="<?= val('current_employment') ?>" required>
                                    <?php if (isset($form_errors['current_employment'])): ?><span class="error-msg"><?= $form_errors['current_employment'] ?></span><?php endif; ?>
                                </div>
                            </div>
                            <div class="form-grid ebm-col-2" style="margin-top:22px;">
                                <div class="field-group <?= isset($form_errors['total_experience']) ? 'field-error' : '' ?>">
                                    <label for="total_experience">Total Experience (Years) <span class="req">*</span></label>
                                    <select name="total_experience" id="total_experience" required>
                                        <option value="">— Select —</option>
                                        <?php for($i=0;$i<=50;$i++): ?>
                                        <option value="<?= $i ?>" <?= sel('total_experience',(string)$i) ?>><?= $i ?></option>
                                        <?php endfor; ?>
                                    </select>
                                </div>
                                <div class="field-group <?= isset($form_errors['educational_qualifications']) ? 'field-error' : '' ?>">
                                    <label for="educational_qualifications">Educational Qualifications <span class="req">*</span></label>
                                    <input type="text" name="educational_qualifications" id="educational_qualifications" placeholder="E.g. PhD(ECE), M.Tech(ECE)" value="<?= val('educational_qualifications') ?>" required>
                                    <?php if (isset($form_errors['educational_qualifications'])): ?><span class="error-msg"><?= $form_errors['educational_qualifications'] ?></span><?php endif; ?>
                                </div>
                            </div>
                            <div class="form-grid" style="margin-top:22px;">
                                <div class="field-group <?= isset($form_errors['research_area']) ? 'field-error' : '' ?>">
                                    <label for="research_area">Research Area <span class="req">*</span></label>
                                    <select name="research_area" id="research_area" required>
                                        <option value="">— Select Research Area —</option>
                                        <?php
                                        $areas = ["Aerospace Engineering","Agricultural Engineering","Agronomy Science","Anatomy","Anatomy Science","Anthropology Science","Architecture","Astronomy Science","Automobile Engineering","Biochemistry Science","Biological Engineering","Biology Science","Bio mechanics Engineering","Botany Science","Cardiology Science","Chemical Engineering","Chemistry Science","Civil Engineering","Computer Engineering","Earth Science and Engineering","Ecology","Ecology Science","Economics","Education","Electrical Engineering","Electronics & Communication Engineering","Engineering Science","Entomology Science","Environment Science","Financial Engineering","Forestry Science","Genetics Science","Geography Science","Geology Science","Geophysics Science","Gynaecology","Ichthyology Science","Industrial Engineering","Information Technology","Library Science","Linguistics Science","Management","Manufacturing Engineering","Material Science and Engineering","Materials Engineering","Mathematics","Mechanical Engineering","Mechanics Science","Medical Surgical","Medicine Science","Meteorology Science","Microbiology","Microbiology Science","Mineralogy Science","Molecular engineering","Mycology Science","Nuclear engineering","Nutrition Science","Ocean Engineering","Oceanography Science","Optical engineering","Pathology Science","Peace and Conflict Studies","Pedagogy","Pediatric Specialty","Pediatric Nursing","Petroleum Engineering","Pharmacology Science","Physics Science","Physical Education","Physiology Science","Power engineering","Production Engineering","Psychology Science","Radiological Sciences","Radiology Science","Robotics Science","Software Engineering","Statistics","Systematic Science","Textile Engineering","Tourism","Toxicology Science","Yoga & Meditation","Zoology Science","Others"];
                                        foreach($areas as $a): ?>
                                        <option value="<?= htmlspecialchars($a) ?>" <?= sel('research_area',$a) ?>><?= htmlspecialchars($a) ?></option>
                                        <?php endforeach; ?>
                                    </select>
                                    <?php if (isset($form_errors['research_area'])): ?><span class="error-msg"><?= $form_errors['research_area'] ?></span><?php endif; ?>
                                </div>
                            </div>
                        </div>

                        <div class="section-gap"></div>

                        <!-- CONTACT -->
                        <div class="section-head"><span class="dot"></span> Contact Details</div>
                        <div class="form-body">
                            <div class="form-grid ebm-col-2">
                                <div class="field-group <?= isset($form_errors['personal_email']) ? 'field-error' : '' ?>">
                                    <label for="personal_email">Personal Email <span class="req">*</span></label>
                                    <input type="email" name="personal_email" id="personal_email" placeholder="john@gmail.com" value="<?= val('personal_email') ?>" required>
                                    <?php if (isset($form_errors['personal_email'])): ?><span class="error-msg"><?= $form_errors['personal_email'] ?></span><?php endif; ?>
                                </div>
                                <div class="field-group <?= isset($form_errors['work_email']) ? 'field-error' : '' ?>">
                                    <label for="work_email">Work Email <span class="req">*</span></label>
                                    <input type="email" name="work_email" id="work_email" placeholder="john@university.edu" value="<?= val('work_email') ?>" required>
                                    <?php if (isset($form_errors['work_email'])): ?><span class="error-msg"><?= $form_errors['work_email'] ?></span><?php endif; ?>
                                </div>
                                <div class="field-group <?= isset($form_errors['mobile_no']) ? 'field-error' : '' ?>">
                                    <label for="mobile_no">Mobile No <span class="req">*</span></label>
                                    <input type="tel" name="mobile_no" id="mobile_no" placeholder="+1 3004005000" value="<?= val('mobile_no') ?>" required>
                                    <?php if (isset($form_errors['mobile_no'])): ?><span class="error-msg"><?= $form_errors['mobile_no'] ?></span><?php endif; ?>
                                </div>
                                <div class="field-group <?= isset($form_errors['whatsapp_no']) ? 'field-error' : '' ?>">
                                    <label for="whatsapp_no">WhatsApp No <span class="req">*</span></label>
                                    <input type="tel" name="whatsapp_no" id="whatsapp_no" placeholder="+1 3004005000" value="<?= val('whatsapp_no') ?>" required>
                                    <?php if (isset($form_errors['whatsapp_no'])): ?><span class="error-msg"><?= $form_errors['whatsapp_no'] ?></span><?php endif; ?>
                                </div>
                            </div>
                            <div class="form-grid ebm-col-3" style="margin-top:22px;">
                                <div class="field-group <?= isset($form_errors['city']) ? 'field-error' : '' ?>">
                                    <label for="city">City <span class="req">*</span></label>
                                    <input type="text" name="city" id="city" placeholder="E.g. Sydney" value="<?= val('city') ?>" required>
                                    <?php if (isset($form_errors['city'])): ?><span class="error-msg"><?= $form_errors['city'] ?></span><?php endif; ?>
                                </div>
                                <div class="field-group">
                                    <label for="state_province">State / Province</label>
                                    <input type="text" name="state_province" id="state_province" placeholder="E.g. New South Wales" value="<?= val('state_province') ?>">
                                </div>
                                <div class="field-group">
                                    <label for="country">Country</label>
                                    <select name="country" id="country">
                                        <option value="">— Select Country —</option>
                                        <?php
                                        $countries = ["Afghanistan","Albania","Algeria","American Samoa","Andorra","Angola","Anguilla","Antarctica","Antigua and Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia and Herzegovina","Botswana","Brazil","Brunei","Bulgaria","Burkina Faso","Burundi","Cabo Verde","Cambodia","Cameroon","Canada","Cayman Islands","Central African Republic","Chad","Chile","China, People's Republic of","Colombia","Comoros","Congo, Democratic Republic of the","Congo, Republic of the","Costa Rica","Croatia","Cuba","Cyprus","Czech Republic","Denmark","Djibouti","Dominica","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Ethiopia","Fiji","Finland","France","Gabon","Gambia","Georgia","Germany","Ghana","Gibraltar","Greece","Greenland","Guatemala","Guinea","Guyana","Haiti","Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Israel","Italy","Jamaica","Japan","Jordan","Kazakhstan","Kenya","Kiribati","Korea, Republic of","Kuwait","Kyrgyzstan","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Mauritania","Mauritius","Mexico","Moldova","Mongolia","Montenegro","Morocco","Mozambique","Myanmar","Namibia","Nepal","Netherlands","New Zealand","Nicaragua","Niger","Nigeria","Norway","Oman","Pakistan","Palestine, State of","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Poland","Portugal","Qatar","Romania","Russia","Rwanda","Saudi Arabia","Senegal","Serbia","Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","Somalia","South Africa","Spain","Sri Lanka","Sudan","Suriname","Sweden","Switzerland","Syria","Taiwan, Republic of China","Tajikistan","Tanzania","Thailand","Togo","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Uganda","Ukraine","United Arab Emirates","United Kingdom","United States of America (USA)","Uruguay","Uzbekistan","Vanuatu","Venezuela","Vietnam","Yemen","Zambia","Zimbabwe"];
                                        foreach($countries as $c): ?>
                                        <option value="<?= htmlspecialchars($c) ?>" <?= sel('country',$c) ?>><?= htmlspecialchars($c) ?></option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="section-gap"></div>

                        <!-- PUBLICATIONS -->
                        <div class="section-head"><span class="dot"></span> Publications & Discovery</div>
                        <div class="form-body">
                            <div class="form-grid ebm-col-3">
                                <div class="field-group <?= isset($form_errors['international_publications']) ? 'field-error' : '' ?>">
                                    <label for="international_publications">International Publications <span class="req">*</span></label>
                                    <select name="international_publications" id="international_publications" required>
                                        <option value="">— Select —</option>
                                        <?php for($i=0;$i<=50;$i++): ?>
                                        <option value="<?= $i ?>" <?= sel('international_publications',(string)$i) ?>><?= $i ?></option>
                                        <?php endfor; ?>
                                    </select>
                                </div>
                                <div class="field-group <?= isset($form_errors['rsis_journal_publications']) ? 'field-error' : '' ?>">
                                    <label for="rsis_journal_publications">Communeglobal Journal Publications <span class="req">*</span></label>
                                    <select name="rsis_journal_publications" id="rsis_journal_publications" required>
                                        <option value="">— Select —</option>
                                        <?php for($i=0;$i<=50;$i++): ?>
                                        <option value="<?= $i ?>" <?= sel('rsis_journal_publications',(string)$i) ?>><?= $i ?></option>
                                        <?php endfor; ?>
                                    </select>
                                </div>
                                <div class="field-group <?= isset($form_errors['how_did_you_find_us']) ? 'field-error' : '' ?>">
                                    <label for="how_did_you_find_us">How Did You Find Us? <span class="req">*</span></label>
                                    <select name="how_did_you_find_us" id="how_did_you_find_us" required>
                                        <option value="">— Select —</option>
                                        <?php foreach(["Academia.edu","AOL","Bing","Email","Ex Communeglobal Author","Facebook","Google","Google Scholar","ISSUU","Linkedin","Open Access Journals","Other Search Engine","Scribed","Someone Refereed Me","Twitter","Yahoo","Youtube","Other"] as $src): ?>
                                        <option value="<?= htmlspecialchars($src) ?>" <?= sel('how_did_you_find_us',$src) ?>><?= htmlspecialchars($src) ?></option>
                                        <?php endforeach; ?>
                                    </select>
                                    <?php if (isset($form_errors['how_did_you_find_us'])): ?><span class="error-msg"><?= $form_errors['how_did_you_find_us'] ?></span><?php endif; ?>
                                </div>
                            </div>
                        </div>

                        <div class="section-gap"></div>

                        <!-- CV UPLOAD -->
                        <div class="section-head"><span class="dot"></span> CV Upload</div>
                        <div class="form-body">
                            <div class="field-group <?= isset($form_errors['cv']) ? 'field-error' : '' ?>">
                                <label>Upload CV <span class="req">*</span></label>
                                <div class="file-upload-wrap">
                                    <input type="file" name="cv" id="cv" accept=".pdf,.doc,.docx">
                                    <div class="file-icon">📄</div>
                                    <div class="file-label">Click to browse or drag & drop your CV</div>
                                    <div class="file-hint">Accepted formats: PDF, DOC, DOCX &nbsp;·&nbsp; Max size: 5MB</div>
                                </div>
                                <?php if (isset($form_errors['cv'])): ?><span class="error-msg"><?= $form_errors['cv'] ?></span><?php endif; ?>
                            </div>
                        </div>

                        <div class="section-gap"></div>

                        <!-- TERMS -->
                        <div class="form-body">
                            <div class="field-group <?= isset($form_errors['agreed_terms']) ? 'field-error' : '' ?>">
                                <div class="checkbox-wrap">
                                    <input type="checkbox" name="agreed_terms" id="agreed_terms" value="1" <?= (isset($_POST['agreed_terms'])) ? 'checked' : '' ?>>
                                    <label for="agreed_terms">I agree to the <a href="#" target="_blank">Communeglobal terms and conditions</a> and confirm that all information provided is accurate and complete. <span class="req">*</span></label>
                                </div>
                                <?php if (isset($form_errors['agreed_terms'])): ?><span class="error-msg" style="margin-top:4px;"><?= $form_errors['agreed_terms'] ?></span><?php endif; ?>
                            </div>
                        </div>

                        <div class="form-footer">
                            <button type="submit" class="btn-submit">Submit Application →</button>
                            <p class="required-note"><span style="color:var(--red)">*</span> All fields marked with an asterisk are required.</p>
                        </div>

                    </form>

                </div>
            </div>
        </section>

    </div>
</div>

<script>
document.getElementById('cv').addEventListener('change', function() {
    const label = this.closest('.file-upload-wrap').querySelector('.file-label');
    if (this.files && this.files[0]) {
        label.textContent = '📎 ' + this.files[0].name;
    }
});
</script>
</body>
</html>

<?php include 'include/footer.php'; ?>