<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <title>Admission Form - <?php echo htmlspecialchars($admission['student_name']); ?></title>
 <style>
 @page {
 margin: 0;
 size: A4;
 }
 body {
 font-family: 'DejaVu Sans', sans-serif;
 font-size: 10px;
 color: #334155;
 line-height: 1.4;
 margin: 0;
 padding: 0;
 background-color: #fff;
 }
 
 .page-border {
 margin: 15px;
 border: 1px solid #e2e8f0;
 min-height: 1080px;
 position: relative;
 }

 .top-line {
 height: 4px;
 background: linear-gradient(90deg, #6366f1, #0891b2);
 }

 .section {
 padding: 15px 25px;
 }

 .header-table {
 width: 100%;
 border-collapse: collapse;
 }
 .institute-name {
 font-size: 18px;
 font-weight: bold;
 color: #1e293b;
 margin: 0;
 }
 .institute-sub {
 font-size: 9px;
 color: #64748b;
 margin-top: 2px;
 }
 .form-label {
 font-size: 20px;
 font-weight: bold;
 color: #6366f1;
 text-align: right;
 text-transform: uppercase;
 }

 .section-title {
 background-color: #f8fafc;
 padding: 8px 25px;
 font-size: 9px;
 font-weight: bold;
 color: #6366f1;
 text-transform: uppercase;
 letter-spacing: 0.5px;
 border-top: 1px solid #f1f5f9;
 border-bottom: 1px solid #f1f5f9;
 }

 .photo-container {
 width: 90px;
 height: 110px;
 border: 1px dashed #cbd5e1;
 border-radius: 6px;
 text-align: center;
 overflow: hidden;
 background-color: #f8fafc;
 margin-left: auto;
 }
 .photo-container img {
 width: 100%;
 height: 100%;
 object-fit: cover;
 }
 .photo-placeholder {
 padding-top: 40px;
 font-size: 7px;
 color: #94a3b8;
 font-weight: bold;
 }

 .info-table {
 width: 100%;
 border-collapse: collapse;
 }
 .info-table td {
 padding: 8px 25px;
 vertical-align: top;
 }
 .field-label {
 font-size: 7px;
 text-transform: uppercase;
 font-weight: bold;
 color: #94a3b8;
 margin-bottom: 2px;
 }
 .field-value {
 font-size: 10px;
 font-weight: bold;
 color: #1e293b;
 }

 .declaration {
 padding: 15px 25px;
 font-size: 8px;
 color: #64748b;
 line-height: 1.5;
 }

 .signature-table {
 width: 100%;
 border-collapse: collapse;
 margin-top: 30px;
 padding: 0 25px;
 }
 .signature-table td {
 width: 33.33%;
 text-align: center;
 }
 .sign-line {
 border-top: 1px solid #e2e8f0;
 width: 100px;
 margin: 0 auto 5px auto;
 }
 .sign-text {
 font-size: 8px;
 font-weight: bold;
 color: #94a3b8;
 text-transform: uppercase;
 }

 .footer {
 position: absolute;
 bottom: 0;
 left: 0;
 right: 0;
 padding: 15px 25px;
 font-size: 8px;
 color: #cbd5e1;
 text-align: center;
 border-top: 1px solid #f8fafc;
 }
 .rupee { font-family: 'DejaVu Sans', sans-serif; }
 </style>
</head>
<body>
 <div class="page-border">
 <div class="top-line"></div>
 
 <!-- Header -->
 <div class="section">
 <table class="header-table">
 <tr>
 <td style="width: 70%;">
 <?php 
 $logoHtml = '';
 if (!empty($settings['institute_logo'])) {
 $possiblePaths = [
 $_SERVER['DOCUMENT_ROOT'] . $settings['institute_logo'],
 realpath(__DIR__ . '/../../public') . $settings['institute_logo'],
 realpath(__DIR__ . '/../../') . $settings['institute_logo'],
 realpath(__DIR__ . '/../../public/') . ltrim($settings['institute_logo'], '/'),
 ];
 foreach ($possiblePaths as $path) {
 if (!empty($path) && file_exists($path) && is_file($path)) {
 $logoData = base64_encode(file_get_contents($path));
 $logoType = pathinfo($path, PATHINFO_EXTENSION);
 $logoHtml = '<img src="data:image/' . $logoType . ';base64,' . $logoData . '" style="max-height: 50px; margin-bottom: 10px;">';
 break;
 }
 }
 }
 echo $logoHtml;
 ?>
 <div class="institute-name"><?php echo htmlspecialchars($settings['institute_name'] ?? 'Smart Tuitions'); ?></div>
 <div class="institute-sub">
 <?php echo nl2br(htmlspecialchars($settings['institute_address'] ?? 'Address not set')); ?><br>
 <?php if(!empty($settings['institute_phone'])): ?>
 <span style="font-weight: bold; color: #334155;">Phone:</span> <?php echo htmlspecialchars($settings['institute_phone']); ?>
 <?php endif; ?>
 <?php if(!empty($settings['institute_email'])): ?>
 <?php echo !empty($settings['institute_phone']) ? ' | ' : ''; ?>
 <span style="font-weight: bold; color: #334155;">Email:</span> <?php echo htmlspecialchars($settings['institute_email']); ?>
 <?php endif; ?>
 </div>
 </td>
 <td style="width: 30%; vertical-align: middle;">
 <div class="form-label">Admission Form</div>
 </td>
 </tr>
 </table>
 </div>

 <!-- Section: Student Info -->
 <div class="section-title">Personal Information</div>
 <table style="width: 100%; border-collapse: collapse;">
 <tr>
 <td style="width: 75%; vertical-align: top; padding: 10px 0;">
 <table class="info-table">
 <tr>
 <td style="width: 50%;">
 <div class="field-label">Student Full Name</div>
 <div class="field-value"><?php echo htmlspecialchars($admission['student_name']); ?></div>
 </td>
 <td style="width: 50%;">
 <div class="field-label">Student ID</div>
 <div class="field-value"><?php echo htmlspecialchars($admission['student_id_code']); ?></div>
 </td>
 </tr>
 <tr>
 <td>
 <div class="field-label">Contact Number</div>
 <div class="field-value"><?php echo htmlspecialchars($admission['student_phone']); ?></div>
 </td>
 <td>
 <div class="field-label">Email Address</div>
 <div class="field-value"><?php echo htmlspecialchars($admission['student_email'] ?? 'N/A'); ?></div>
 </td>
 </tr>
 <tr>
 <td>
 <div class="field-label">Guardian's Name</div>
 <div class="field-value"><?php echo htmlspecialchars($admission['guardian_name'] ?? 'N/A'); ?></div>
 </td>
 <td>
 <div class="field-label">Guardian's Contact</div>
 <div class="field-value"><?php echo htmlspecialchars($admission['guardian_phone'] ?? 'N/A'); ?></div>
 </td>
 </tr>
 <tr>
 <td colspan="2">
 <div class="field-label">Residential Address</div>
 <div class="field-value"><?php echo nl2br(htmlspecialchars($admission['student_address'] ?? 'N/A')); ?></div>
 </td>
 </tr>
 </table>
 </td>
 <td style="width: 25%; vertical-align: top; padding: 20px 25px 0 0; text-align: right;">
 <div class="photo-container">
 <?php 
 if (!empty($admission['student_photo'])) {
 $photoPath = realpath(__DIR__ . '/../../public') . $admission['student_photo'];
 if (file_exists($photoPath) && is_file($photoPath)) {
 $photoData = base64_encode(file_get_contents($photoPath));
 $photoType = pathinfo($photoPath, PATHINFO_EXTENSION);
 echo '<img src="data:image/' . $photoType . ';base64,' . $photoData . '">';
 } else {
 echo '<div class="photo-placeholder">PASTE<br>PHOTO<br>HERE</div>';
 }
 } else {
 echo '<div class="photo-placeholder">PASTE<br>PHOTO<br>HERE</div>';
 }
 ?>
 </div>
 </td>
 </tr>
 </table>

 <!-- Section: Course Info -->
 <div class="section-title">Academic Enrollment</div>
 <table class="info-table" style="padding: 10px 0;">
 <tr>
 <td style="width: 50%;">
 <div class="field-label">Enrolled Course</div>
 <div class="field-value"><?php echo htmlspecialchars($admission['course_name']); ?></div>
 </td>
 <td style="width: 50%;">
 <div class="field-label">Admission Date</div>
 <div class="field-value"><?php echo date('d/m/Y', strtotime($admission['admission_date'])); ?></div>
 </td>
 </tr>
 <tr>
 <td>
 <div class="field-label">Batch Assigned</div>
 <div class="field-value"><?php echo htmlspecialchars($admission['batch_name'] ?? 'N/A'); ?></div>
 </td>
 <td>
 <div class="field-label">Course Duration</div>
 <div class="field-value"><?php echo htmlspecialchars($admission['course_duration'] ?? 'N/A'); ?> Months</div>
 </td>
 </tr>
 <tr>
 <td>
 <div class="field-label">Batch Timing</div>
 <div class="field-value">
 <?php if(!empty($admission['batch_start_time'])): ?>
 <?php echo date('h:i A', strtotime($admission['batch_start_time'])); ?> - <?php echo date('h:i A', strtotime($admission['batch_end_time'])); ?>
 <?php else: ?>
 N/A
 <?php endif; ?>
 </div>
 </td>
 <td>
 <div class="field-label">Status</div>
 <div class="field-value"><?php echo htmlspecialchars($admission['status']); ?></div>
 </td>
 </tr>
 </table>

 <!-- Section: Payment Info -->
 <?php if(!empty($invoice)): ?>
 <div class="section-title">Financial Summary</div>
 <table class="info-table" style="padding: 10px 0;">
 <tr>
 <td style="width: 50%;">
 <div class="field-label">Total Course Fee</div>
 <div class="field-value"><span class="rupee">&#8377;</span><?php echo number_format($invoice['total_amount'], 2); ?></div>
 </td>
 <td style="width: 50%;">
 <div class="field-label">Total Paid Amount</div>
 <div class="field-value"><span class="rupee">&#8377;</span><?php echo number_format($invoice['paid_amount'], 2); ?></div>
 </td>
 </tr>
 <tr>
 <td>
 <div class="field-label">Invoice Reference</div>
 <div class="field-value">#INV-<?php echo str_pad($invoice['id'], 5, '0', STR_PAD_LEFT); ?></div>
 </td>
 <td>
 <div class="field-label">Outstanding Balance</div>
 <div class="field-value"><span class="rupee">&#8377;</span><?php echo number_format($invoice['total_amount'] - $invoice['paid_amount'] - $invoice['discount_amount'], 2); ?></div>
 </td>
 </tr>
 </table>
 <?php endif; ?>

 <!-- Declaration -->
 <div class="declaration" style="margin-top: 20px;">
 <strong>Declaration:</strong> I hereby certify that the information provided is correct to the best of my knowledge. I understand that any false information may lead to the cancellation of my admission. I agree to comply with all institute policies and regulations.
 </div>

 <!-- Signatures -->
 <table class="signature-table">
 <tr>
 <td>
 <div class="sign-line"></div>
 <div class="sign-text">Student Signature</div>
 </td>
 <td>
 <div class="sign-line"></div>
 <div class="sign-text">Guardian Signature</div>
 </td>
 <td>
 <div class="sign-line"></div>
 <div class="sign-text">Office Seal & Sign</div>
 </td>
 </tr>
 </table>

 <!-- Footer -->
 <div class="footer">
 This is a computer-generated admission form. Generated on <?php echo date('d M, Y h:i A'); ?>
 </div>
 </div>
</body>
</html>