<div class="tab-pane fade p-4" id="accountsDetailsTab" role="tabpanel">
    <h5 class="fw-bold mb-3">Contacts and Account Hierarchy</h5>
    <div class="row g-4">
        <div class="col-lg-7"><div class="card border mb-0"><div class="card-header">Contacts ({{ $account->contacts->count() }})</div><div class="list-group list-group-flush">
            @forelse($account->contacts as $contact)
                <a class="list-group-item list-group-item-action d-flex justify-content-between" href="{{ route('contacts.view',['id'=>$contact->id]) }}"><span>{{ trim($contact->first_name.' '.$contact->last_name) }} @if($contact->pivot->is_primary)<span class="badge bg-primary">Primary</span>@endif<small class="d-block text-muted">{{ $contact->job_title ?: $contact->pivot->role }}</small></span><span class="small text-muted">{{ $contact->contactEmails->first()?->email }}</span></a>
            @empty <div class="p-3 text-muted">No contacts linked to this Account.</div> @endforelse
        </div></div></div>
        <div class="col-lg-5"><div class="card border mb-0"><div class="card-header">Hierarchy</div><div class="card-body">
            <div class="mb-3"><span class="text-muted">Parent</span><div>@if($account->parentAccount)<a href="{{ route('account.view',['id'=>$account->parentAccount->id]) }}">{{ $account->parentAccount->account_name }}</a>@else <span class="text-muted">Top-level Account</span> @endif</div></div>
            <span class="text-muted">Child Accounts</span>
            @forelse($account->childAccounts as $child)<div><a href="{{ route('account.view',['id'=>$child->id]) }}">{{ $child->account_name }}</a></div>@empty <div class="text-muted">No child Accounts.</div> @endforelse
        </div></div></div>
    </div>
</div>

<div class="tab-pane fade p-4" id="productsTab" role="tabpanel"><h5 class="fw-bold mb-3">Products from Account Deals</h5>
    <div class="table-responsive"><table class="table"><thead><tr><th>Product</th><th>Deal</th><th>Quantity</th><th>Price</th><th>Total</th></tr></thead><tbody>
    @forelse($products as $line)<tr><td>{{ $line->product?->product_name ?? 'Product #'.$line->product_id }}</td><td><a href="{{ route('deals.view',['id'=>$line->deal_id]) }}">{{ $line->deal?->name ?? 'Deal #'.$line->deal_id }}</a></td><td>{{ $line->quantity }}</td><td>{{ number_format((float)$line->product_price,2) }}</td><td>{{ number_format((float)$line->line_total,2) }}</td></tr>
    @empty <tr><td colspan="5" class="text-muted">No products linked through Account Deals.</td></tr> @endforelse
    </tbody></table></div>
</div>

<div class="tab-pane fade p-4" id="projectsTab" role="tabpanel"><h5 class="fw-bold mb-3">Account Projects</h5>
    @forelse($projects as $project)<div class="border rounded p-3 mb-2 d-flex justify-content-between"><span><strong>{{ $project->name }}</strong><small class="d-block text-muted">{{ $project->description }}</small></span><span>{{ ucfirst(str_replace('_',' ',$project->status)) }} · {{ $project->progress }}%</span></div>@empty <div class="text-muted">No projects linked directly or through Deals.</div> @endforelse
</div>

<div class="tab-pane fade p-4" id="tradeDetailsTab" role="tabpanel"><h5 class="fw-bold mb-3">Trade Documents</h5>
    <div class="table-responsive"><table class="table"><thead><tr><th>Number</th><th>Type</th><th>Status</th><th>Deal</th><th>Total</th></tr></thead><tbody>
    @forelse($tradeDocuments as $document)<tr><td>{{ $document->document_number }}</td><td>{{ ucfirst($document->type) }}</td><td>{{ ucfirst(str_replace('_',' ',$document->status)) }}</td><td>{{ $document->deal?->name }}</td><td>{{ $document->currency }} {{ number_format((float)$document->total,2) }}</td></tr>
    @empty <tr><td colspan="5" class="text-muted">No quotations, proposals, or invoices for this Account.</td></tr> @endforelse
    </tbody></table></div>
</div>

<div class="tab-pane fade p-4" id="ticketTab" role="tabpanel"><h5 class="fw-bold mb-3">Account Tickets</h5>
    @forelse(\App\Models\Ticket::where('account_id',$account->id)->latest()->get() as $ticket)<a href="{{ route('ticket.view',['id'=>$ticket->id]) }}" class="d-flex justify-content-between border rounded p-3 mb-2"><span>{{ $ticket->topic ?: 'Ticket #'.$ticket->id }}</span><span>{{ ucfirst($ticket->status) }}</span></a>@empty <div class="text-muted">No Tickets for this Account.</div> @endforelse
</div>

<div class="tab-pane fade p-4" id="caseTab" role="tabpanel"><div class="d-flex justify-content-between mb-3"><h5 class="fw-bold mb-0">Account Cases</h5><a class="btn btn-sm btn-primary" href="{{ route('cases.index',['account_id'=>$account->id]) }}">Create Case</a></div>
    @forelse($cases as $case)<a href="{{ route('cases.show',$case) }}" class="border rounded p-3 mb-2 d-flex justify-content-between"><span><strong>{{ $case->case_number }} — {{ $case->subject }}</strong><small class="d-block text-muted">{{ $case->description }}</small></span><span>{{ ucfirst(str_replace('_',' ',$case->status)) }}</span></a>@empty <div class="text-muted">No Cases associated with this Account.</div> @endforelse
</div>

<div class="tab-pane fade p-4" id="meetingsTab" role="tabpanel"><h5 class="fw-bold mb-3">Invited Meetings</h5>
    @forelse($invitedMeetings as $meeting)<div class="border rounded p-3 mb-2"><strong>{{ $meeting->title }}</strong><span class="float-end">{{ $meeting->start_date }} {{ $meeting->start_time }}</span><div class="small text-muted">{{ ucfirst($meeting->meeting_type ?: 'meeting') }} · {{ $meeting->location }} · {{ $meeting->attendees->count() }} attendee(s)</div></div>@empty <div class="text-muted">No invited meetings linked to this Account.</div> @endforelse
</div>

<div class="tab-pane fade p-4" id="campaignsTab" role="tabpanel"><h5 class="fw-bold mb-3">Campaign History</h5>
    @forelse($campaigns as $target)<a href="{{ route('campaigns.view',['id'=>$target->campaign_id]) }}" class="d-flex justify-content-between border rounded p-3 mb-2"><span>{{ $target->campaign?->campaign_name }}</span><span>{{ $target->converted ? 'Converted' : ($target->responded_at ? 'Responded' : 'Targeted') }}</span></a>@empty <div class="text-muted">This Account has not been targeted by a Campaign.</div> @endforelse
    <x-profile-notification-history entity-type="Account" :entity-id="$account->id" />
</div>

<div class="tab-pane fade p-4" id="surveysTab" role="tabpanel"><h5 class="fw-bold mb-3">Account Surveys</h5>
    @forelse($surveys as $survey)<div class="border rounded p-3 mb-2 d-flex justify-content-between"><span><strong>{{ $survey->name }}</strong><small class="d-block text-muted">{{ $survey->description }}</small></span><span>{{ strtoupper($survey->type) }} · {{ ucfirst($survey->status) }}</span></div>@empty <div class="text-muted">No Surveys associated with this Account.</div> @endforelse
</div>
