function PatientDetailModal({ handleDeleteRx, handleDeleteVisit, lang, selectedPatient, setActivePrescriptionToPrint, setEditingRx, setEditingVisit, setShowEditRxModal, setShowEditVisitModal, setShowPatientDetailModal, setShowPrescriptionModal, setShowPrintRxModal, strings }) {
    return (
        <>
        <div className="fixed inset-0 bg-brand-harbor/60 backdrop-blur-md z-50 flex items-center justify-center p-4">
            <div className="bg-white border border-brand-dune/80 rounded-3xl max-w-2xl w-full p-8 shadow-2xl text-brand-harbor max-h-[90vh] overflow-y-auto">
                <div className="flex items-center justify-between mb-6 border-b border-brand-dune/30 pb-4">
                    <div>
                        <h3 className="text-2xl font-extrabold text-brand-harbor">{selectedPatient.name}</h3>
                        <p className="text-xs text-brand-steel font-medium">{selectedPatient.age} {lang === 'ar' ? 'سنة' : 'yrs'} • {selectedPatient.gender} • {strings.phone}: <span className="font-mono text-brand-harbor">{selectedPatient.phone}</span></p>
                    </div>
                    <button onClick={() => setShowPatientDetailModal(false)} className="w-8 h-8 rounded-full bg-brand-linen hover:bg-brand-dune/40 flex items-center justify-center text-brand-steel">✕</button>
                </div>

                <div className="space-y-6">
                    <div className="bg-brand-linen/60 p-5 rounded-2xl border border-brand-dune/60 space-y-2">
                        <div>
                            <p className="text-xs font-bold uppercase text-brand-steel">{strings.diagnosis}</p>
                            <p className="text-sm font-bold text-brand-harbor">{selectedPatient.diagnosis}</p>
                        </div>
                        {selectedPatient.notes && (
                            <div>
                                <p className="text-xs font-bold uppercase text-brand-steel">{lang === 'ar' ? 'ملاحظات إكلينيكية / حساسية' : 'Clinical Notes / Allergies'}</p>
                                <p className="text-sm text-brand-harbor/90">{selectedPatient.notes}</p>
                            </div>
                        )}
                    </div>

                    <div>
                        <div className="flex items-center justify-between mb-3">
                            <h4 className="font-bold text-brand-harbor text-sm uppercase tracking-wider flex items-center space-x-2 rtl:space-x-reverse">
                                <i data-lucide="file-text" className="w-4 h-4 text-brand-steel"></i>
                                <span>{strings.rxHistory}</span>
                            </h4>
                            <button 
                                onClick={() => setShowPrescriptionModal(true)}
                                className="px-4 py-2 bg-brand-harbor hover:bg-brand-sky text-white rounded-xl text-xs font-bold shadow-md transition-all"
                            >
                                {strings.writeRx}
                            </button>
                        </div>
                        <div className="space-y-3">
                            {(!selectedPatient.prescriptions || selectedPatient.prescriptions.length === 0) ? (
                                <p className="text-xs text-brand-steel italic bg-brand-linen/50 p-4 rounded-2xl">{lang === 'ar' ? 'لا توجد روشتات مسجلة بعد.' : 'No prescriptions recorded yet.'}</p>
                            ) : (
                                selectedPatient.prescriptions.map((rx, idx) => (
                                    <div key={rx.id || idx} className="bg-brand-linen/40 border border-brand-dune/60 p-4 rounded-2xl flex justify-between items-start">
                                        <div>
                                            <div className="flex items-center space-x-2 rtl:space-x-reverse mb-1">
                                                <span className="font-bold text-brand-harbor text-sm">{rx.medication}</span>
                                                <span className="text-[11px] bg-brand-dune/40 text-brand-harbor px-2.5 py-0.5 rounded-lg font-bold">{rx.date}</span>
                                            </div>
                                            <p className="text-xs text-brand-harbor font-semibold">{rx.dosage}</p>
                                            <p className="text-xs text-brand-steel mt-1">{rx.instructions}</p>
                                            <p className="text-[11px] text-brand-steel/80 italic mt-1.5">{lang === 'ar' ? 'بواسطة' : 'By'} {rx.doctor}</p>
                                        </div>
                                        <div className="flex items-center space-x-2 rtl:space-x-reverse">
                                            <button 
                                                onClick={() => { setActivePrescriptionToPrint(rx); setShowPrintRxModal(true); }}
                                                className="px-2.5 py-1 bg-brand-harbor text-white rounded-xl text-xs font-bold shadow hover:bg-brand-sky transition-all flex items-center space-x-1 rtl:space-x-reverse"
                                            >
                                                <i data-lucide="printer" className="w-3.5 h-3.5"></i>
                                                <span>{strings.print}</span>
                                            </button>
                                            <button 
                                                onClick={() => { setEditingRx(rx); setShowEditRxModal(true); }}
                                                className="h-8 px-3 bg-white hover:bg-brand-dune/30 text-brand-harbor rounded-xl text-xs font-bold border border-brand-dune transition-colors"
                                            >
                                                {strings.edit}
                                            </button>
                                            <button 
                                                onClick={() => handleDeleteRx(rx.id)}
                                                className="text-rose-600 hover:text-rose-800 p-1"
                                            >
                                                <i data-lucide="trash-2" className="w-4 h-4"></i>
                                            </button>
                                        </div>
                                    </div>
                                ))
                            )}
                        </div>
                    </div>

                    <div>
                        <h4 className="font-bold text-brand-harbor text-sm uppercase tracking-wider mb-3 flex items-center space-x-2 rtl:space-x-reverse">
                            <i data-lucide="history" className="w-4 h-4 text-brand-steel"></i>
                            <span>{strings.visitTimeline}</span>
                        </h4>
                        <div className="space-y-3">
                            {(!selectedPatient.history || selectedPatient.history.length === 0) ? (
                                <p className="text-xs text-brand-steel italic bg-brand-linen/50 p-4 rounded-2xl">{lang === 'ar' ? 'لا توجد زيارات مسجلة بعد.' : 'No visit history recorded yet.'}</p>
                            ) : (
                                selectedPatient.history.map((h, idx) => (
                                    <div key={h.id || idx} className="bg-brand-linen/40 border border-brand-dune/60 p-4 rounded-2xl flex items-center justify-between text-xs">
                                        <div>
                                            <div className="flex items-center space-x-2 rtl:space-x-reverse mb-1">
                                                <span className="font-bold text-brand-harbor">{h.date}</span>
                                                {h.diagnosis && <span className="bg-brand-dune/30 text-brand-harbor px-2 py-0.5 rounded-lg font-bold">{h.diagnosis}</span>}
                                            </div>
                                            <p className="text-brand-harbor font-medium">{h.notes}</p>
                                            <p className="text-[11px] text-brand-steel/80 italic mt-1">{lang === 'ar' ? 'بواسطة' : 'By'} {h.doctor}</p>
                                        </div>
                                        <div className="flex items-center space-x-2 rtl:space-x-reverse">
                                            <button 
                                                onClick={() => { setEditingVisit(h); setShowEditVisitModal(true); }}
                                                className="h-8 px-3 bg-white hover:bg-brand-dune/30 text-brand-harbor rounded-xl text-xs font-bold border border-brand-dune transition-colors"
                                            >
                                                {strings.edit}
                                            </button>
                                            <button 
                                                onClick={() => handleDeleteVisit(h.id)}
                                                className="text-rose-600 hover:text-rose-800 p-1"
                                            >
                                                <i data-lucide="trash-2" className="w-4 h-4"></i>
                                            </button>
                                        </div>
                                    </div>
                                ))
                            )}
                        </div>
                    </div>
                </div>

                <div className="flex justify-end pt-6 border-t border-brand-dune/30 mt-6">
                    <button onClick={() => setShowPatientDetailModal(false)} className="px-6 py-2.5 rounded-2xl text-sm font-semibold bg-brand-linen hover:bg-brand-dune/40 text-brand-harbor">{strings.close}</button>
                </div>
            </div>
        </div>
        </>
    );
}
