<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <style>
        body { font-family: 'Helvetica', sans-serif; color: #333; margin: 0; padding: 0; }
        .header { border-bottom: 2px solid #2c3e50; padding-bottom: 20px; margin-bottom: 20px; }
        .doctor-info { float: left; width: 60%; }
        .chamber-info { float: right; width: 35%; text-align: right; font-size: 12px; }
        .clear { clear: both; }
        .patient-bar { background: #f8f9fa; padding: 10px; margin-bottom: 20px; border: 1px solid #dee2e6; }
        .main-content { min-height: 500px; }
        .sidebar { float: left; width: 30%; border-right: 1px solid #dee2e6; padding-right: 15px; }
        .rx-content { float: right; width: 65%; padding-left: 15px; }
        .footer { position: fixed; bottom: 0; width: 100%; border-top: 1px solid #dee2e6; padding-top: 10px; font-size: 10px; text-align: center; }
        .medicine-item { margin-bottom: 15px; }
        .medicine-name { font-weight: bold; font-size: 16px; }
        .dosage { font-style: italic; color: #555; }
        .rx-symbol { font-size: 30px; font-weight: bold; color: #2c3e50; margin-bottom: 10px; }
    </style>
</head>
<body>
    <div class="header">
        <div class="doctor-info">
            <h1 style="margin:0; color: #2c3e50;">Dr. Luies Sourav Sarker</h1>
            <p style="margin:5px 0;">MBBS, BCS (Health)</p>
            <p style="margin:0; font-size:14px;">Specialist Physician</p>
        </div>
        <div class="chamber-info">
            <strong>{{ $encounter->visit->chamber->name ?? 'Main Chamber' }}</strong><br>
            {{ $encounter->visit->chamber->address ?? '' }}<br>
            {{ $encounter->visit->chamber->phone ?? '' }}
        </div>
        <div class="clear"></div>
    </div>

    <div class="patient-bar">
        <table width="100%" cellspacing="0" cellpadding="0">
            <tr>
                <td><strong>Patient:</strong> {{ $patient->name }}</td>
                <td><strong>Age/Sex:</strong> {{ $patient->age ?? 'N/A' }} / {{ $patient->gender ?? 'N/A' }}</td>
                <td><strong>ID:</strong> {{ $patient->patient_id }}</td>
                <td align="right"><strong>Date:</strong> {{ $encounter->visit->visit_date->format('d M, Y') }}</td>
            </tr>
        </table>
    </div>

    <div class="main-content">
        <div class="sidebar">
            <h4 style="margin-top:0;">Vitals</h4>
            @if($encounter->vitals)
                @foreach($encounter->vitals as $label => $value)
                    <div style="font-size:12px; margin-bottom:5px;">
                        <strong>{{ ucfirst($label) }}:</strong> {{ $value }}
                    </div>
                @endforeach
            @endif

            <h4>Chief Complaints</h4>
            <p style="font-size:12px;">{{ $encounter->chief_complaints }}</p>

            <h4>Investigations</h4>
            <ul style="font-size:12px; padding-left:15px;">
                @foreach($prescription->investigations ?? [] as $test)
                    <li>{{ $test }}</li>
                @endforeach
            </ul>
        </div>

        <div class="rx-content">
            <div class="rx-symbol">Rx</div>
            
            @foreach($prescription->medicines ?? [] as $med)
                <div class="medicine-item">
                    <div class="medicine-name">{{ $med['medicine_id'] }}</div>
                    <div class="dosage">{{ $med['dosage'] }} --- {{ $med['duration'] }}</div>
                    <div style="font-size:11px; color:#777;">{{ $med['instructions'] }}</div>
                </div>
            @endforeach

            <div style="margin-top:50px;">
                <h4>Advice</h4>
                <p style="font-size:14px;">{{ $encounter->advice }}</p>
            </div>
            
            <div style="margin-top:30px;">
                <strong>Follow up:</strong> {{ $encounter->follow_up_date ? $encounter->follow_up_date->format('d M, Y') : 'As needed' }}
            </div>
        </div>
        <div class="clear"></div>
    </div>

    <div class="footer">
        This is a computer generated prescription. No signature required. 
        | Powered by MedChamber DPMS
    </div>
</body>
</html>
