@php
    $patient = $patient ?? null;
@endphp

<div class="form-grid" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.5rem; margin-bottom: 1.5rem;">
    <!-- Column 1: Personal Info & Emergency -->
    <div class="flex flex-col" style="display: flex; flex-direction: column; gap: 1.5rem;">
        <div class="card mb-0">
            <h3 class="card-title" style="margin-top: 0; margin-bottom: 1.25rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; font-size: 1.1rem; color: var(--primary);">
                🩺 {{ __('clinic.overview') }}
            </h3>
            
            <div class="form-group">
                <label for="full_name">{{ __('clinic.full_name') }} <span style="color:var(--danger)">*</span></label>
                <input id="full_name" class="form-control" name="full_name" value="{{ old('full_name', $patient->full_name ?? '') }}" required>
                @error('full_name')<div class="error-text" style="color:var(--danger); font-size:0.85rem; margin-top:0.25rem;">{{ $message }}</div>@enderror
            </div>

            <div class="form-grid" style="display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem;">
                <div class="form-group">
                    <label for="phone">{{ __('clinic.phone') }} <span style="color:var(--danger)">*</span></label>
                    <input id="phone" class="form-control" name="phone" value="{{ old('phone', $patient->phone ?? '') }}" required>
                    @error('phone')<div class="error-text" style="color:var(--danger); font-size:0.85rem; margin-top:0.25rem;">{{ $message }}</div>@enderror
                </div>
                <div class="form-group">
                    <label for="whatsapp">{{ __('clinic.whatsapp') }}</label>
                    <input id="whatsapp" class="form-control" name="whatsapp" value="{{ old('whatsapp', $patient->whatsapp ?? '') }}">
                    @error('whatsapp')<div class="error-text" style="color:var(--danger); font-size:0.85rem; margin-top:0.25rem;">{{ $message }}</div>@enderror
                </div>
            </div>

            <div class="form-grid" style="display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem;">
                <div class="form-group">
                    <label for="gender">{{ __('clinic.gender') }} <span style="color:var(--danger)">*</span></label>
                    <select id="gender" class="form-control" name="gender" required>
                        <option value="">—</option>
                        <option value="male" @selected(old('gender', $patient->gender ?? '') === 'male')>{{ __('clinic.male') }}</option>
                        <option value="female" @selected(old('gender', $patient->gender ?? '') === 'female')>{{ __('clinic.female') }}</option>
                        <option value="other" @selected(old('gender', $patient->gender ?? '') === 'other')>{{ __('clinic.other') }}</option>
                    </select>
                    @error('gender')<div class="error-text" style="color:var(--danger); font-size:0.85rem; margin-top:0.25rem;">{{ $message }}</div>@enderror
                </div>
                <div class="form-group">
                    <label for="status">{{ __('clinic.status') }} <span style="color:var(--danger)">*</span></label>
                    <select id="status" class="form-control" name="status" required>
                        <option value="active" @selected(old('status', $patient->status ?? 'active') === 'active')>{{ __('clinic.active') }}</option>
                        <option value="archived" @selected(old('status', $patient->status ?? '') === 'archived')>{{ __('clinic.archived') }}</option>
                    </select>
                    @error('status')<div class="error-text" style="color:var(--danger); font-size:0.85rem; margin-top:0.25rem;">{{ $message }}</div>@enderror
                </div>
            </div>

            <div class="form-grid" style="display: grid; grid-template-columns: 1.5fr 0.5fr; gap: 1rem; margin-top: 1rem;">
                <div class="form-group">
                    <label for="birth_date">{{ __('clinic.birth_date') }}</label>
                    <input id="birth_date" type="date" class="form-control" name="birth_date" value="{{ old('birth_date', $patient && $patient->birth_date ? $patient->birth_date->format('Y-m-d') : '') }}">
                    @error('birth_date')<div class="error-text" style="color:var(--danger); font-size:0.85rem; margin-top:0.25rem;">{{ $message }}</div>@enderror
                </div>
                <div class="form-group">
                    <label for="age">{{ __('clinic.age') }}</label>
                    <input id="age" type="number" class="form-control" name="age" value="{{ old('age', $patient->age ?? '') }}">
                    @error('age')<div class="error-text" style="color:var(--danger); font-size:0.85rem; margin-top:0.25rem;">{{ $message }}</div>@enderror
                </div>
            </div>

            <div class="form-group" style="margin-top: 1rem;">
                <label for="national_id">{{ __('clinic.national_id') }}</label>
                <input id="national_id" class="form-control" name="national_id" value="{{ old('national_id', $patient->national_id ?? '') }}">
                @error('national_id')<div class="error-text" style="color:var(--danger); font-size:0.85rem; margin-top:0.25rem;">{{ $message }}</div>@enderror
            </div>

            <div class="form-group" style="margin-top: 1rem;">
                <label for="address">{{ __('clinic.address') }}</label>
                <textarea id="address" class="form-control" name="address" rows="2">{{ old('address', $patient->address ?? '') }}</textarea>
                @error('address')<div class="error-text" style="color:var(--danger); font-size:0.85rem; margin-top:0.25rem;">{{ $message }}</div>@enderror
            </div>
        </div>

        <div class="card mb-0">
            <h3 class="card-title" style="margin-top: 0; margin-bottom: 1.25rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; font-size: 1.1rem; color: var(--accent-rose);">
                🚨 {{ __('clinic.emergency_contact_name') }}
            </h3>

            <div class="form-group">
                <label for="emergency_contact_name">{{ __('clinic.emergency_contact_name') }}</label>
                <input id="emergency_contact_name" class="form-control" name="emergency_contact_name" value="{{ old('emergency_contact_name', $patient->emergency_contact_name ?? '') }}">
                @error('emergency_contact_name')<div class="error-text" style="color:var(--danger); font-size:0.85rem; margin-top:0.25rem;">{{ $message }}</div>@enderror
            </div>

            <div class="form-group" style="margin-top: 1rem;">
                <label for="emergency_contact_phone">{{ __('clinic.emergency_contact_phone') }}</label>
                <input id="emergency_contact_phone" class="form-control" name="emergency_contact_phone" value="{{ old('emergency_contact_phone', $patient->emergency_contact_phone ?? '') }}">
                @error('emergency_contact_phone')<div class="error-text" style="color:var(--danger); font-size:0.85rem; margin-top:0.25rem;">{{ $message }}</div>@enderror
            </div>
        </div>
    </div>

    <!-- Column 2: Medical Info -->
    <div class="flex flex-col" style="display: flex; flex-direction: column; gap: 1.5rem;">
        <div class="card mb-0" style="height: 100%;">
            <h3 class="card-title" style="margin-top: 0; margin-bottom: 1.25rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; font-size: 1.1rem; color: var(--accent-emerald);">
                📋 {{ __('clinic.medical_history') }}
            </h3>

            <div class="form-group">
                <label for="medical_history">{{ __('clinic.medical_history') }}</label>
                <textarea id="medical_history" class="form-control" name="medical_history" rows="3" placeholder="الجراحة السابقة، الأمراض، السيرة المرضية للعائلة">{{ old('medical_history', $patient->medical_history ?? '') }}</textarea>
                @error('medical_history')<div class="error-text" style="color:var(--danger); font-size:0.85rem; margin-top:0.25rem;">{{ $message }}</div>@enderror
            </div>

            <div class="form-group" style="margin-top: 1rem;">
                <label for="chronic_diseases">{{ __('clinic.chronic_diseases') }}</label>
                <textarea id="chronic_diseases" class="form-control" name="chronic_diseases" rows="2" placeholder="الضغط، السكر، القلب، إلخ">{{ old('chronic_diseases', $patient->chronic_diseases ?? '') }}</textarea>
                @error('chronic_diseases')<div class="error-text" style="color:var(--danger); font-size:0.85rem; margin-top:0.25rem;">{{ $message }}</div>@enderror
            </div>

            <div class="form-group" style="margin-top: 1rem;">
                <label for="allergies">{{ __('clinic.allergies') }}</label>
                <textarea id="allergies" class="form-control" name="allergies" rows="2" placeholder="حساسية البنسلين، أطعمة معينة، إلخ">{{ old('allergies', $patient->allergies ?? '') }}</textarea>
                @error('allergies')<div class="error-text" style="color:var(--danger); font-size:0.85rem; margin-top:0.25rem;">{{ $message }}</div>@enderror
            </div>

            <div class="form-group" style="margin-top: 1rem;">
                <label for="current_medications">{{ __('clinic.current_medications') }}</label>
                <textarea id="current_medications" class="form-control" name="current_medications" rows="2" placeholder="الأدوية التي يتناولها بانتظام">{{ old('current_medications', $patient->current_medications ?? '') }}</textarea>
                @error('current_medications')<div class="error-text" style="color:var(--danger); font-size:0.85rem; margin-top:0.25rem;">{{ $message }}</div>@enderror
            </div>

            <div class="form-group" style="margin-top: 1rem;">
                <label for="notes">{{ __('clinic.notes') }}</label>
                <textarea id="notes" class="form-control" name="notes" rows="2">{{ old('notes', $patient->notes ?? '') }}</textarea>
                @error('notes')<div class="error-text" style="color:var(--danger); font-size:0.85rem; margin-top:0.25rem;">{{ $message }}</div>@enderror
            </div>
        </div>
    </div>
</div>
