<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Receta <?php echo e($prescription->prescription_number); ?></title>
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body { font-family: DejaVu Sans, sans-serif; font-size: 11px; color: #1a1a1a; background: #fff; }
        .page { padding: 20mm 20mm 20mm 20mm; }

        /* Header */
        .header { border-bottom: 2px solid #4f46e5; padding-bottom: 12px; margin-bottom: 16px; }
        .header-inner { display: flex; justify-content: space-between; align-items: flex-start; }
        .company-name { font-size: 18px; font-weight: bold; color: #4f46e5; }
        .company-info { font-size: 9px; color: #666; margin-top: 2px; line-height: 1.5; }
        .doc-title { text-align: right; }
        .doc-title h1 { font-size: 14px; font-weight: bold; color: #4f46e5; }
        .doc-title .number { font-size: 11px; color: #888; margin-top: 2px; font-family: monospace; }
        .doc-title .date { font-size: 10px; color: #666; margin-top: 2px; }

        /* Patient & Doctor */
        .info-grid { display: flex; gap: 12px; margin-bottom: 16px; }
        .info-box { flex: 1; background: #f8f9ff; border: 1px solid #e0e7ff; border-radius: 4px; padding: 10px; }
        .info-box h3 { font-size: 9px; font-weight: bold; color: #4f46e5; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; border-bottom: 1px solid #e0e7ff; padding-bottom: 4px; }
        .info-row { display: flex; gap: 4px; margin-bottom: 3px; }
        .info-label { font-size: 9px; color: #888; min-width: 80px; }
        .info-value { font-size: 9px; font-weight: 500; }

        /* Diagnosis */
        .diagnosis-box { background: #fffbeb; border: 1px solid #fcd34d; border-radius: 4px; padding: 8px; margin-bottom: 12px; }
        .diagnosis-box p { font-size: 10px; }
        .diagnosis-label { font-size: 9px; font-weight: bold; color: #92400e; margin-bottom: 3px; }

        /* Medications */
        .section-title { font-size: 12px; font-weight: bold; color: #1f2937; margin-bottom: 8px; border-bottom: 1px solid #e5e7eb; padding-bottom: 4px; }
        .medication { border: 1px solid #e5e7eb; border-radius: 4px; padding: 10px; margin-bottom: 8px; }
        .med-number { display: inline-block; width: 20px; height: 20px; background: #4f46e5; color: white; border-radius: 50%; text-align: center; line-height: 20px; font-size: 9px; font-weight: bold; margin-right: 6px; }
        .med-name { font-size: 12px; font-weight: bold; color: #111; }
        .med-details { margin-top: 5px; margin-left: 26px; display: flex; flex-wrap: wrap; gap: 10px; }
        .med-detail { font-size: 9px; color: #555; }
        .med-detail strong { color: #111; }
        .med-instructions { margin-top: 5px; margin-left: 26px; background: #eff6ff; border-left: 3px solid #3b82f6; padding: 4px 6px; font-size: 9px; color: #1e40af; }

        /* Notes */
        .notes-box { background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 4px; padding: 8px; margin-top: 12px; }

        /* Signature */
        .signature-area { margin-top: 30px; border-top: 1px solid #e5e7eb; padding-top: 16px; display: flex; justify-content: space-between; }
        .sig-block { text-align: center; }
        .sig-line { width: 150px; border-bottom: 1px solid #333; margin: 0 auto 4px; height: 30px; }
        .sig-label { font-size: 9px; color: #888; }
        .sig-name { font-size: 9px; font-weight: bold; }

        /* Footer */
        .footer { margin-top: 20px; border-top: 1px solid #e5e7eb; padding-top: 8px; text-align: center; font-size: 8px; color: #aaa; }
    </style>
</head>
<body>
<div class="page">

    <div class="header">
        <div class="header-inner">
            <div>
                <div class="company-name"><?php echo e($company?->name ?? 'Centro Médico'); ?></div>
                <div class="company-info">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($company?->address): ?> <?php echo e($company->address); ?><br><?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($company?->phone): ?> Tel: <?php echo e($company->phone); ?><br><?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($company?->email): ?> <?php echo e($company->email); ?><?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>
            </div>
            <div class="doc-title">
                <h1>RECETA MÉDICA</h1>
                <div class="number"><?php echo e($prescription->prescription_number); ?></div>
                <div class="date"><?php echo e($prescription->created_at->format('d/m/Y')); ?></div>
            </div>
        </div>
    </div>

    <div class="info-grid">
        <div class="info-box">
            <h3>Datos del paciente</h3>
            <div class="info-row">
                <span class="info-label">Nombre:</span>
                <span class="info-value"><?php echo e($patient->fullName()); ?></span>
            </div>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($patient->document_number): ?>
            <div class="info-row">
                <span class="info-label">Documento:</span>
                <span class="info-value"><?php echo e(strtoupper($patient->document_type ?? '')); ?> <?php echo e($patient->document_number); ?></span>
            </div>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($patient->birthdate): ?>
            <div class="info-row">
                <span class="info-label">Fecha nac.:</span>
                <span class="info-value"><?php echo e($patient->birthdate->format('d/m/Y')); ?> (<?php echo e($patient->age()); ?> años)</span>
            </div>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($patient->blood_type): ?>
            <div class="info-row">
                <span class="info-label">Grupo sang.:</span>
                <span class="info-value"><?php echo e($patient->blood_type); ?></span>
            </div>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
        </div>
        <div class="info-box">
            <h3>Profesional prescriptor</h3>
            <div class="info-row">
                <span class="info-label">Nombre:</span>
                <span class="info-value"><?php echo e($prescription->employee?->user?->name ?? '—'); ?></span>
            </div>
            <div class="info-row">
                <span class="info-label">Fecha:</span>
                <span class="info-value"><?php echo e($prescription->created_at->format('d/m/Y')); ?></span>
            </div>
            <div class="info-row">
                <span class="info-label">Estado:</span>
                <span class="info-value"><?php echo e($prescription->isSigned() ? 'FIRMADA' : 'BORRADOR'); ?></span>
            </div>
        </div>
    </div>

    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($prescription->diagnosis_summary): ?>
    <div class="diagnosis-box">
        <div class="diagnosis-label">DIAGNÓSTICO</div>
        <p><?php echo e($prescription->diagnosis_summary); ?></p>
    </div>
    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

    <div class="section-title">MEDICAMENTOS PRESCRITOS</div>

    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $prescription->items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <div class="medication">
        <div>
            <span class="med-number"><?php echo e($i + 1); ?></span>
            <span class="med-name"><?php echo e($item->medication); ?></span>
        </div>
        <div class="med-details">
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($item->dose): ?><span class="med-detail"><strong>Dosis:</strong> <?php echo e($item->dose); ?></span><?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($item->frequency): ?><span class="med-detail"><strong>Frecuencia:</strong> <?php echo e($item->frequency); ?></span><?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($item->duration): ?><span class="med-detail"><strong>Duración:</strong> <?php echo e($item->duration); ?></span><?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($item->route): ?><span class="med-detail"><strong>Vía:</strong> <?php echo e($item->route); ?></span><?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
        </div>
        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($item->instructions): ?>
        <div class="med-instructions">📌 <?php echo e($item->instructions); ?></div>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    </div>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($prescription->notes): ?>
    <div class="notes-box">
        <div style="font-size:9px; font-weight:bold; color:#374151; margin-bottom:4px;">NOTAS ADICIONALES</div>
        <p style="font-size:10px;"><?php echo e($prescription->notes); ?></p>
    </div>
    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

    <div class="signature-area">
        <div></div>
        <div class="sig-block">
            <div class="sig-line"></div>
            <div class="sig-name"><?php echo e($prescription->employee?->user?->name ?? 'Profesional'); ?></div>
            <div class="sig-label">Firma y sello</div>
        </div>
    </div>

    <div class="footer">
        Documento generado el <?php echo e(now()->format('d/m/Y H:i')); ?> — <?php echo e($company?->name); ?>

        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($prescription->isSigned()): ?> | Firmado el <?php echo e($prescription->signed_at->format('d/m/Y')); ?><?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    </div>
</div>
</body>
</html>
<?php /**PATH /Applications/XAMPP/xamppfiles/htdocs/CitasSoft/resources/views/pdf/prescription.blade.php ENDPATH**/ ?>