<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{{ $medicalRecord->title ?: __('Consulta') }} — {{ $patient->name }}</title>
    <style>
        body { font-family: system-ui, Segoe UI, Roboto, sans-serif; color: #111; line-height: 1.45; max-width: 48rem; margin: 0 auto; padding: 1.5rem; }
        h1 { font-size: 1.25rem; margin: 0 0 0.25rem; }
        .muted { color: #555; font-size: 0.875rem; }
        .box { border: 1px solid #ccc; border-radius: 8px; padding: 1rem; margin-top: 1rem; }
        .label { font-weight: 600; color: #000; }
        .block { margin-top: 0.75rem; white-space: pre-wrap; }
        .toolbar { margin-bottom: 1.5rem; display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
        .btn { display: inline-block; padding: 0.5rem 1rem; background: #6d28d9; color: #fff !important; text-decoration: none; border-radius: 8px; font-weight: 600; border: none; cursor: pointer; font-size: 0.875rem; }
        .btn:hover { background: #5b21b6; }
        ul.att { list-style: none; padding: 0; margin: 0.5rem 0 0; }
        ul.att li { padding: 0.35rem 0; border-bottom: 1px solid #eee; font-size: 0.875rem; }
        @media print {
            .toolbar { display: none; }
            body { padding: 0; }
            .box { break-inside: avoid; }
        }
    </style>
</head>
<body>
    <div class="toolbar">
        <button type="button" class="btn" onclick="window.print()">{{ __('Imprimir / PDF') }}</button>
        <a class="btn" style="background:#0f766e;" href="{{ route('clients.patients.medical-records.show', [$client, $patient, $medicalRecord]) }}">{{ __('Volver a la ficha') }}</a>
    </div>

    <p class="muted">{{ config('app.name') }}</p>
    <h1>{{ $medicalRecord->title ?: __('Entrada clínica') }}</h1>
    <p class="muted">
        {{ $patient->name }}
        @if ($patient->clinical_code)
            · {{ __('ID') }}: {{ $patient->clinical_code }}
        @endif
        · {{ __('Titular') }}: {{ $client->name }}
    </p>
    <p class="muted">
        {{ $medicalRecord->recorded_at->translatedFormat('d M Y H:i') }}
        @if ($medicalRecord->author)
            · {{ __('Por') }} {{ $medicalRecord->author->name }}
        @endif
    </p>

    <div class="box">
        @if ($medicalRecord->weight_kg)
            <p><span class="label">{{ __('Peso') }}:</span> {{ $medicalRecord->weight_kg }} kg</p>
        @endif
        @if ($medicalRecord->temperature_c)
            <p><span class="label">{{ __('Temperatura') }}:</span> {{ $medicalRecord->temperature_c }} °C</p>
        @endif
        @if ($medicalRecord->chief_complaint)
            <p><span class="label">{{ __('Motivo de consulta') }}:</span> {{ $medicalRecord->chief_complaint }}</p>
        @endif
        @if ($medicalRecord->physical_exam)
            <div class="block"><span class="label">{{ __('Examen físico') }}</span><br>{{ $medicalRecord->physical_exam }}</div>
        @endif
        @if ($medicalRecord->diagnosis)
            <div class="block"><span class="label">{{ __('Diagnóstico') }}</span><br>{{ $medicalRecord->diagnosis }}</div>
        @endif
        @if ($medicalRecord->treatment)
            <div class="block"><span class="label">{{ __('Tratamiento') }}</span><br>{{ $medicalRecord->treatment }}</div>
        @endif
        @if ($medicalRecord->medications)
            <div class="block"><span class="label">{{ __('Medicación') }}</span><br>{{ $medicalRecord->medications }}</div>
        @endif
        @if ($medicalRecord->body)
            <div class="block"><span class="label">{{ __('Notas adicionales') }}</span><br>{{ $medicalRecord->body }}</div>
        @endif
    </div>

    @if ($medicalRecord->attachments->isNotEmpty())
        <div class="box">
            <p class="label">{{ __('Adjuntos') }}</p>
            <ul class="att">
                @foreach ($medicalRecord->attachments as $att)
                    <li>
                        {{ $att->original_name }}
                        — <a href="{{ \Illuminate\Support\Facades\Storage::url($att->path) }}">{{ __('Abrir') }}</a>
                    </li>
                @endforeach
            </ul>
        </div>
    @endif
</body>
</html>
