@extends('agency.layouts.app')

@section('title', $customer->full_name)
@section('page_title', 'Müşteri Detayı')

@push('styles')
<style>
:root {
    --cp: #2563eb;
    --cp-light: #eff6ff;
    --cs: #10b981;
    --cw: #f59e0b;
    --cd: #ef4444;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #f1f5f9;
}

/* ─── LAYOUT ─── */
.customer-page {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 1.5rem;
    align-items: start;
}
@media(max-width:1100px) { .customer-page { grid-template-columns: 1fr; } }

/* ─── LEFT CARD ─── */
.customer-card {
    background: #fff;
    border-radius: 20px;
    border: 1px solid var(--border);
    box-shadow: 0 2px 12px rgba(0,0,0,.05);
    overflow: hidden;
    position: sticky;
    top: 80px;
}
.card-header-gradient {
    height: 90px;
    background: linear-gradient(135deg, #2563eb 0%, #1e40af 50%, #0369a1 100%);
    position: relative;
}

/* Priority shimmer */
.customer-card.is-priority .card-header-gradient {
    background: linear-gradient(135deg,#fbbf24,#f59e0b,#d97706);
    animation: shimmer 2.5s infinite;
    background-size: 200% 200%;
}
@keyframes shimmer { 0%{background-position:0% 50%} 50%{background-position:100% 50%} 100%{background-position:0% 50%} }

/* Müşteri Tipi Badge */
.sb.type-individual { background: #eff6ff; color: #2563eb; border: 1px solid #dbeafe; }
.sb.type-corporate  { background: #f0f9ff; color: #0369a1; border: 1px solid #e0f2fe; }

/* Avatar */
.customer-avatar-wrap {
    display: flex; justify-content: center;
    margin-top: -36px; margin-bottom: 12px;
    position: relative; z-index: 2;
}
.customer-avatar-big {
    width: 72px; height: 72px; border-radius: 18px;
    background: linear-gradient(135deg,#2563eb,#3b82f6);
    color: #fff; font-size: 1.6rem; font-weight: 800;
    display: flex; align-items: center; justify-content: center;
    border: 3px solid #fff;
    box-shadow: 0 4px 16px rgba(37, 99, 235, .35);
}
.customer-avatar-big.corp {
    background: linear-gradient(135deg,#1e40af,#2563eb);
}

/* Identity */
.customer-identity { text-align: center; padding: 1.5rem 1.5rem 1rem; }
.ci-name { font-size: 1.4rem; font-weight: 800; color: var(--text-main); margin-bottom: 4px; display: flex; justify-content: center; align-items: center; gap: 0.5rem; }
.ci-company { font-size: .8rem; color: var(--text-muted); margin-bottom: 10px; }
.ci-badges { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; }

/* Status badges */
.sb { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 20px; font-size: .72rem; font-weight: 600; }
.sb.active    { background:#d1fae5;color:#065f46; }
.sb.inactive  { background:#f1f5f9;color:#475569; }
.sb.blocked   { background:#fee2e2;color:#991b1b; }
.sb.potential { background:#fef3c7;color:#92400e; }
.sb.priority-true    { background:linear-gradient(135deg,#fde68a,#fbbf24);color:#78350f; }
.sb.priority-false    { background:#f1f5f9;color:#64748b; }
.sb.blacklisted { background:#fee2e2;color:#991b1b; }

/* Divider */
.card-divider { height: 1px; background: var(--border); margin: .75rem 0; }

/* Info rows */
.info-list { padding: 0 1.25rem 1.25rem; }
.info-row {
    display: flex; align-items: center; gap: .75rem;
    padding: .5rem 0;
    border-bottom: 1px solid #f8fafc;
    font-size: .83rem;
}
.info-row:last-child { border-bottom: none; }
.info-icon {
    width: 32px; height: 32px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; flex-shrink: 0;
}
.info-icon.indigo { background:#eff6ff;color:#2563eb; }
.info-icon.green  { background:#d1fae5;color:#10b981; }
.info-icon.amber  { background:#fef3c7;color:#f59e0b; }
.info-icon.pink   { background:#fce7f3;color:#db2777; }
.info-icon.slate  { background:#f1f5f9;color:#64748b; }
.info-label { color:var(--text-muted); font-size:.75rem; }
.info-val   { color:var(--text-main); font-weight:500; word-break:break-all; }

/* Metrics row */
.metrics-strip {
    display: grid; grid-template-columns: repeat(3,1fr);
    gap: 0; border-top: 1px solid var(--border);
}
.metric-cell {
    text-align: center; padding: .9rem .5rem;
    border-right: 1px solid var(--border);
}
.metric-cell:last-child { border-right: none; }
.metric-val  { font-size: 1.1rem; font-weight: 800; color:var(--text-main); }
.metric-lbl  { font-size: .68rem; color:var(--text-muted); font-weight:500; letter-spacing:.3px; margin-top:2px; }

/* Quick action buttons */
.quick-actions { padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: .5rem; }
.qa-btn {
    display: flex; align-items: center; gap: .75rem;
    padding: .65rem 1rem; border-radius: 10px; border: none;
    font-size: .82rem; font-weight: 600; cursor: pointer;
    text-decoration: none; transition: all .15s; width: 100%; text-align: left;
}
.qa-btn:hover { filter: brightness(.97); transform: translateX(2px); }
.qa-btn.primary { background:var(--cp-light);color:var(--cp); }
.qa-btn.success { background:#d1fae5;color:#065f46; }
.qa-btn.warning { background:#fef3c7;color:#92400e; }
.qa-btn.danger  { background:#fee2e2;color:#991b1b; }
.qa-btn.neutral { background:#f1f5f9;color:#475569; }

/* ─── RIGHT TABS ─── */
.right-panel {}

/* Tab nav */
.customer-tabs {
    display: flex; gap: 4px;
    background: #fff; border-radius: 14px;
    padding: .4rem; margin-bottom: 1rem;
    border: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0,0,0,.04);
}
.ctab {
    flex: 1; text-align: center; padding: .55rem 1rem;
    border-radius: 10px; border: none; background: transparent;
    font-size: .82rem; font-weight: 600; color: var(--text-muted);
    cursor: pointer; transition: all .2s; text-decoration: none;
    display: flex; align-items: center; justify-content: center; gap: 6px;
}
.ctab:hover  { background: var(--cp-light); color: var(--cp); }
.ctab.active { background: var(--cp); color: #fff; box-shadow: 0 2px 8px rgba(37, 99, 235, .3); }
.ctab-badge {
    background: rgba(255,255,255,.3); border-radius: 20px;
    padding: 1px 6px; font-size: .68rem; font-weight: 700;
}
.ctab.active .ctab-badge { background: rgba(255,255,255,.2); }

/* Content panels */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Section card */
.section-card {
    background: #fff;
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0,0,0,.04);
    margin-bottom: 1rem;
    overflow: hidden;
}
.section-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.section-title { font-size: .88rem; font-weight: 700; color: var(--text-main); }
.section-body  { padding: 1.25rem; }

/* Activity timeline */
.timeline { position: relative; }
.timeline::before {
    content: ''; position: absolute;
    left: 20px; top: 0; bottom: 0; width: 2px;
    background: linear-gradient(to bottom, var(--cp), transparent);
}
.tl-item { display: flex; gap: 1rem; margin-bottom: 1.25rem; position: relative; }
.tl-dot {
    width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; flex-shrink: 0; z-index: 1;
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,.1);
}
.tl-dot.call      { background:#dbeafe;color:#2563eb; }
.tl-dot.email     { background:#fce7f3;color:#db2777; }
.tl-dot.meeting   { background:#d1fae5;color:#059669; }
.tl-dot.booking   { background:#ede9fe;color:#7c3aed; }
.tl-dot.complaint { background:#fee2e2;color:#dc2626; }
.tl-dot.note      { background:#fef3c7;color:#d97706; }
.tl-dot.default   { background:#f1f5f9;color:#64748b; }

.tl-content {
    flex: 1; background: #f8fafc; border-radius: 12px;
    padding: .85rem 1rem; min-width: 0;
    border: 1px solid var(--border);
    transition: box-shadow .15s;
}
.tl-content:hover { box-shadow: 0 2px 12px rgba(0,0,0,.07); }
.tl-header { display: flex; justify-content: space-between; align-items: start; gap: .5rem; margin-bottom: 4px; }
.tl-type { font-size: .75rem; font-weight: 700; color: var(--cp); text-transform: uppercase; letter-spacing: .4px; }
.tl-time { font-size: .72rem; color: #94a3b8; white-space: nowrap; }
.tl-subject { font-weight: 600; color: var(--text-main); font-size: .85rem; margin-bottom: 4px; }
.tl-desc { font-size: .8rem; color: var(--text-muted); }
.tl-footer { display: flex; gap: .75rem; margin-top: .5rem; }
.tl-meta { font-size: .72rem; color: #94a3b8; display: flex; align-items: center; gap: 4px; }

/* Activity status pills */
.pill {
    display: inline-flex; align-items: center; padding: 2px 8px;
    border-radius: 20px; font-size: .7rem; font-weight: 600;
}
.pill.completed { background:#d1fae5;color:#065f46; }
.pill.pending   { background:#fef3c7;color:#92400e; }
.pill.in_progress{ background:#dbeafe;color:#1d4ed8; }
.pill.cancelled  { background:#fee2e2;color:#991b1b; }

/* Custom fields panel */
.cf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px,1fr));
    gap: 1rem;
}
.cf-card {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    transition: box-shadow .15s;
}
.cf-card:hover { box-shadow: 0 2px 12px rgba(0,0,0,.07); }
.cf-label { font-size: .72rem; font-weight: 700; color: #94a3b8; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 6px; }
.cf-value { font-size: .92rem; font-weight: 600; color: var(--text-main); }
.cf-empty { color: #cbd5e1; font-style: italic; font-weight: 400; font-size: .85rem; }

/* Detail grid (2 col) */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media(max-width:600px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-item { }
.di-label { font-size: .73rem; font-weight: 600; color: #94a3b8; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 4px; }
.di-value { font-size: .88rem; color: var(--text-main); font-weight: 500; }

/* Blacklist badge */
.blacklist-banner {
    background: linear-gradient(135deg,#fee2e2,#fecaca);
    border: 1px solid #fca5a5;
    border-radius: 12px; padding: 1rem;
    display: flex; align-items: center; gap: .75rem;
    margin-bottom: 1rem;
}
</style>
@endpush

@php
    $statusOptions = [
        ['value' => 'active', 'label' => 'Aktif'],
        ['value' => 'inactive', 'label' => 'Pasif'],
        ['value' => 'blocked', 'label' => 'Engelli'],
        ['value' => 'potential', 'label' => 'Potansiyel'],
    ];

    $priorityOptions = [
        ['value' => '1', 'label' => 'Öncelikli'],
        ['value' => '0', 'label' => 'Normal'],
    ];

    $genderOptions = [
        ['value' => 'male', 'label' => 'Erkek'],
        ['value' => 'female', 'label' => 'Kadın'],
        ['value' => 'other', 'label' => 'Diğer'],
    ];
@endphp

@section('content')
<div class="container-fluid">

{{-- Breadcrumb row --}}
<div class="d-flex align-items-center gap-2 mb-3" style="font-size:.83rem;color:#94a3b8">
    <a href="{{ route('agency.customers.index') }}" style="color:#2563eb;text-decoration:none;font-weight:600">
        <i class="fas fa-users me-1"></i>Müşteriler
    </a>
    <i class="fas fa-chevron-right" style="font-size:10px"></i>
    <span style="color:#0f172a;font-weight:600">{{ $customer->full_name }}</span>
</div>

{{-- Blacklist warning --}}
@if($customer->blacklisted)
<div class="blacklist-banner mb-3">
    <div style="width:40px;height:40px;background:#ef4444;border-radius:50%;display:flex;align-items:center;justify-content:center;color:#fff;font-size:18px;flex-shrink:0">
        <i class="fas fa-ban"></i>
    </div>
    <div>
        <div style="font-weight:700;color:#991b1b">Bu müşteri kara listede!</div>
        <div style="font-size:.82rem;color:#b91c1c">{{ $customer->blacklist_reason }}</div>
    </div>
    <form method="POST" action="{{ route('agency.customers.toggle-blacklist', $customer) }}" class="ms-auto">
        @csrf
        <button class="btn btn-sm" style="background:#fff;border:1px solid #fca5a5;color:#991b1b;border-radius:8px">
            Listeden Çıkar
        </button>
    </form>
</div>
@endif

<div class="customer-page mt-3 {{ $customer->priority ? 'is-priority' : '' }}">
    <div>
        {{-- Left Card --}}
        <div class="customer-card {{ $customer->priority ? 'is-priority' : '' }}">
            {{-- Identity --}}
            <div class="customer-identity">
                <div class="ci-name d-flex align-items-center gap-2">
                    <span>
                        <span class="inline-editable" data-id="{{ $customer->id }}" data-field="first_name">{{ $customer->first_name }}</span>
                        <span class="inline-editable" data-id="{{ $customer->id }}" data-field="last_name">{{ $customer->last_name }}</span>
                    </span>
                    <i class="fas fa-copy copy-icon ms-1" style="cursor: pointer; opacity: 0.6; font-size: 1rem;" onclick="copyToClipboard('{{ $customer->full_name }}', this)" title="Ad Soyad Kopyala"></i>
                </div>
                @if($customer->national_id)
                    <div style="font-size: .8rem; color: #64748b; margin-top: -2px; margin-bottom: 8px;">
                        <span>
                            TC: <span class="inline-editable" data-id="{{ $customer->id }}" data-field="national_id">{{ $customer->national_id }}</span>
                            <i class="fas fa-copy copy-icon ms-1" style="cursor: pointer; opacity: 0.6;" onclick="copyToClipboard('{{ $customer->national_id }}', this)" title="TC Kopyala"></i>
                        </span>
                    </div>
                @endif
                @if($customer->company_name)
                    <div class="ci-company"><i class="fas fa-building me-1"></i>
                        <span class="inline-editable" data-id="{{ $customer->id }}" data-field="company_name">{{ $customer->company_name }}</span>
                    </div>
                @endif
                <div class="ci-badges">
                    <div class="ci-badge" title="Müşteri Tipi">
                        {!! $customer->customer_type === 'corporate' ? '<i class="fas fa-building me-1"></i> Şirket' : '<i class="fas fa-user me-1"></i> Kişi' !!}
                    </div>
                    <span class="sb {{ $customer->status }} inline-editable" 
                          data-id="{{ $customer->id }}" data-field="status" data-type="select" data-options="{{ json_encode($statusOptions) }}" data-value="{{ $customer->status }}">
                        {{ $customer->status_label }}
                    </span>
                    <span class="sb priority-{{ $customer->priority ? 'true' : 'false' }} inline-editable"
                          data-id="{{ $customer->id }}" data-field="priority" data-type="select" data-options="{{ json_encode($priorityOptions) }}" data-value="{{ $customer->priority ? '1' : '0' }}">
                        {{ $customer->priority_label }}
                    </span>
                    @if($customer->blacklisted)
                        <span class="sb blacklisted"><i class="fas fa-ban me-1"></i>Kara Liste</span>
                    @endif
                </div>
            </div>

            {{-- Metrics strip --}}
            <div class="metrics-strip">
                <div class="metric-cell">
                    <div class="metric-val">{{ $customer->total_bookings ?? 0 }}</div>
                    <div class="metric-lbl">REZERVASYON</div>
                </div>
                <div class="metric-cell">
                    <div class="metric-val">{{ number_format((float)($customer->total_spent ?? 0), 0, ',', '.') }}</div>
                    <div class="metric-lbl">TOPLAM (₺)</div>
                </div>
                <div class="metric-cell">
                    <div class="metric-val">{{ $customer->loyalty_points ?? 0 }}</div>
                    <div class="metric-lbl">PUAN</div>
                </div>
            </div>

            <div class="card-divider"></div>

            {{-- Info list --}}
            <div class="info-list">
                <div class="info-row" style="align-items: flex-start;">
                    <div class="info-icon indigo" style="margin-top: 2px;"><i class="fas fa-envelope"></i></div>
                    <div>
                        <div class="info-label">E-posta Adresleri</div>
                        <div class="info-val">
                             @if($customer->emails && is_array($customer->emails))
                                 @foreach($customer->emails as $email)
                                     <div class="d-flex align-items-center gap-2 {{ $loop->first ? 'fw-bold' : 'text-muted' }}" style="font-size: {{ $loop->first ? '0.85rem' : '0.75rem' }};">
                                         {{ $email }}
                                         <i class="fas fa-copy copy-icon" style="cursor: pointer; opacity: 0.5; font-size: 0.75rem;" onclick="copyToClipboard('{{ $email }}', this)" title="E-posta Kopyala"></i>
                                     </div>
                                 @endforeach
                             @else
                                 —
                             @endif
                        </div>
                    </div>
                </div>

                <div class="info-row">
                    <div class="info-icon green"><i class="fas fa-phone"></i></div>
                    <div>
                        <div class="info-label">Telefon</div>
                        <div class="info-val">
                            <span class="inline-editable" data-id="{{ $customer->id }}" data-field="phone" data-type="tel" data-value="{{ $customer->phone }}">{{ $customer->phone ?: '—' }}</span>
                            @if($customer->phone)
                                <i class="fas fa-copy copy-icon ms-1" style="cursor: pointer; opacity: 0.5;" onclick="copyToClipboard('{{ $customer->phone }}', this)" title="Telefon Kopyala"></i>
                            @endif
                        </div>
                        <div style="font-size:.75rem;color:#94a3b8">
                            Alt: <span class="inline-editable" data-id="{{ $customer->id }}" data-field="phone_alt" data-type="tel" data-value="{{ $customer->phone_alt }}">{{ $customer->phone_alt ?: 'Ekle' }}</span>
                            @if($customer->phone_alt)
                                <i class="fas fa-copy copy-icon ms-1" style="cursor: pointer; opacity: 0.4; font-size: 0.65rem;" onclick="copyToClipboard('{{ $customer->phone_alt }}', this)" title="Alternatif Telefon Kopyala"></i>
                            @endif
                        </div>
                    </div>
                </div>
                
                @if($customer->national_id)
                <div class="info-row">
                    <div class="info-icon slate"><i class="fas fa-id-card"></i></div>
                    <div>
                        <div class="info-label">TC / Kimlik No</div>
                        <div class="info-val">
                            {{ $customer->national_id }}
                            <i class="fas fa-copy copy-icon ms-1" style="cursor: pointer; opacity: 0.5;" onclick="copyToClipboard('{{ $customer->national_id }}', this)" title="TC Kopyala"></i>
                        </div>
                    </div>
                </div>
                @endif

                @if($customer->passport_number)
                <div class="info-row">
                    <div class="info-icon slate"><i class="fas fa-passport"></i></div>
                    <div>
                        <div class="info-label">Pasaport No</div>
                        <div class="info-val">
                            {{ $customer->passport_number }}
                            <i class="fas fa-copy copy-icon ms-1" style="cursor: pointer; opacity: 0.5;" onclick="copyToClipboard('{{ $customer->passport_number }}', this)" title="Pasaport Kopyala"></i>
                        </div>
                    </div>
                </div>
                @endif

                @if($customer->birth_date)
                <div class="info-row">
                    <div class="info-icon amber"><i class="fas fa-birthday-cake"></i></div>
                    <div>
                        <div class="info-label">Doğum Tarihi</div>
                        <div class="info-val">{{ $customer->birth_date->format('d.m.Y') }}
                            <span style="font-size:.75rem;color:#94a3b8">({{ $customer->birth_date->age }} yaş)</span>
                        </div>
                    </div>
                </div>
                @endif

                @if($customer->nationality)
                <div class="info-row">
                    <div class="info-icon pink"><i class="fas fa-flag"></i></div>
                    <div>
                        <div class="info-label">Uyruk</div>
                        <div class="info-val">{{ strtoupper($customer->nationality) }}</div>
                    </div>
                </div>
                @endif

                @if($customer->city || true)
                <div class="info-row">
                    <div class="info-icon slate"><i class="fas fa-map-marker-alt"></i></div>
                    <div>
                        <div class="info-label">Konum</div>
                        <div class="info-val">
                             <span class="inline-editable" data-id="{{ $customer->id }}" data-field="district" data-placeholder="İlçe">{{ $customer->district ?: 'İlçe' }}</span>,
                             <span class="inline-editable" data-id="{{ $customer->id }}" data-field="city" data-placeholder="Şehir">{{ $customer->city ?: 'Şehir' }}</span>
                        </div>
                    </div>
                </div>
                @endif

                @if($customer->assignedAgent)
                <div class="info-row">
                    <div class="info-icon indigo"><i class="fas fa-user-tie"></i></div>
                    <div>
                        <div class="info-label">Temsilci</div>
                        <div class="info-val">{{ $customer->assignedAgent->full_name }}</div>
                    </div>
                </div>
                @endif

                @if($customer->loyalty_tier)
                <div class="info-row">
                    <div class="info-icon amber"><i class="fas fa-medal"></i></div>
                    <div>
                        <div class="info-label">Sadakat Seviyesi</div>
                        <div class="info-val">{{ $customer->loyalty_tier_label }}</div>
                    </div>
                </div>
                @endif
            </div>

            {{-- Quick actions --}}
            <div class="card-divider" style="margin:0"></div>
            <div class="quick-actions">
                <a href="{{ route('agency.customers.edit', $customer) }}" class="qa-btn primary">
                    <i class="fas fa-pen-to-square"></i> Bilgileri Düzenle
                </a>
                <a href="{{ route('agency.customers.activities.create', $customer) }}" class="qa-btn success">
                    <i class="fas fa-plus-circle"></i> Aktivite Ekle
                </a>
                <a href="{{ route('agency.customers.field-values.edit', $customer) }}" class="qa-btn warning">
                    <i class="fas fa-sliders-h"></i> Özel Alanları Düzenle
                </a>
                <button class="qa-btn {{ $customer->blacklisted ? 'neutral' : 'danger' }}"
                        onclick="toggleBlacklist()">
                    <i class="fas fa-{{ $customer->blacklisted ? 'unlock' : 'ban' }}"></i>
                    {{ $customer->blacklisted ? 'Kara Listeden Çıkar' : 'Kara Listeye Al' }}
                </button>
            </div>
        </div>
    </div>

    {{-- ════════════════ RIGHT PANEL ════════════════ --}}
    <div class="right-panel">

        {{-- Tab nav --}}
        <div class="customer-tabs">
            <button class="ctab active" onclick="showTab('overview', this)">
                <i class="fas fa-chart-pie"></i> Özet
            </button>
            <button class="ctab" onclick="showTab('details', this)">
                <i class="fas fa-id-card"></i> Kişisel Bilgiler
            </button>
            <button class="ctab" onclick="showTab('custom', this)">
                <i class="fas fa-puzzle-piece"></i> Özel Alanlar
            </button>
            <button class="ctab" onclick="showTab('passengers', this)">
                <i class="fas fa-users"></i> Yolcular
                <span class="ctab-badge">{{ $customer->passengers->count() }}</span>
            </button>
            @if($customer->isCorporate())
            <button class="ctab" onclick="showTab('billing', this)">
                <i class="fas fa-file-invoice"></i> Fatura
            </button>
            @endif
            <button class="ctab" onclick="showTab('financial', this)">
                <i class="fas fa-wallet"></i> Finansal
            </button>
            <button class="ctab" onclick="showTab('documents', this)">
                <i class="fas fa-file-invoice"></i> Dökümanlar
                <span class="ctab-badge">{{ $customer->customerDocuments->count() }}</span>
            </button>
        </div>

        {{-- ── TAB: OVERVIEW ── --}}
        <div class="tab-panel active" id="tab-overview">

            {{-- Activity stats & Communication --}}
            <div style="display:grid;grid-template-columns: 2fr 1fr; gap:1.25rem; margin-bottom:1.25rem">
                {{-- Stats Grid --}}
                <div style="display:grid;grid-template-columns:repeat(2,1fr);gap:1rem">
                    @foreach([
                        ['label'=>'Toplam','val'=>$activityStats['total'],'icon'=>'fas fa-list','clr'=>'#6366f1','bg'=>'#eef2ff'],
                        ['label'=>'Bekleyen','val'=>$activityStats['pending'],'icon'=>'fas fa-clock','clr'=>'#f59e0b','bg'=>'#fef3c7'],
                        ['label'=>'Şikayet','val'=>$activityStats['complaints'],'icon'=>'fas fa-exclamation-circle','clr'=>'#ef4444','bg'=>'#fee2e2'],
                        ['label'=>'Takip','val'=>$activityStats['follow_up'],'icon'=>'fas fa-flag','clr'=>'#8b5cf6','bg'=>'#ede9fe'],
                    ] as $ac)
                    <div style="background:#fff;border-radius:14px;border:1px solid #f1f5f9;padding:1rem;display:flex;align-items:center;gap:.75rem;box-shadow:0 1px 4px rgba(0,0,0,.04)">
                        <div style="width:40px;height:40px;border-radius:10px;background:{{ $ac['bg'] }};color:{{ $ac['clr'] }};display:flex;align-items:center;justify-content:center;font-size:16px;flex-shrink:0">
                            <i class="{{ $ac['icon'] }}"></i>
                        </div>
                        <div>
                            <div style="font-size:1.3rem;font-weight:800;color:#0f172a;line-height:1">{{ $ac['val'] }}</div>
                            <div style="font-size:.72rem;color:#94a3b8;font-weight:500">{{ $ac['label'] }}</div>
                        </div>
                    </div>
                    @endforeach
                </div>

                {{-- Communication Permissions --}}
                <div style="background:#fff;border-radius:20px;border:1px solid #f1f5f9;padding:1.25rem;box-shadow:0 1px 4px rgba(0,0,0,.04)">
                    <div style="font-size:.85rem;font-weight:700;color:#64748b;text-transform:uppercase;letter-spacing:.5px;margin-bottom:1rem;display:flex;align-items:center;gap:.5rem">
                        <i class="fas fa-bullhorn text-primary"></i> İletişim İzinleri
                    </div>
                    
                    <div style="display:flex; flex-direction:column; gap:0.75rem">
                        <div style="display:flex; justify-content:space-between; align-items:center; padding:0.75rem; background:#f8fafc; border-radius:12px; border:1px solid #f1f5f9">
                            <div style="display:flex; align-items:center; gap:0.75rem">
                                <div style="width:32px; height:32px; border-radius:8px; background:#eff6ff; color:#2563eb; display:flex; align-items:center; justify-content:center; font-size:14px">
                                    <i class="fas fa-envelope"></i>
                                </div>
                                <div style="font-size:0.85rem; font-weight:600; color:#1e293b">E-posta</div>
                            </div>
                            @if($customer->email_marketing)
                                <span style="font-size:0.7rem; font-weight:700; color:#059669; background:#d1fae5; padding:3px 8px; border-radius:6px">AKTİF</span>
                            @else
                                <span style="font-size:0.7rem; font-weight:700; color:#dc2626; background:#fee2e2; padding:3px 8px; border-radius:6px">KAPALI</span>
                            @endif
                        </div>

                        <div style="display:flex; justify-content:space-between; align-items:center; padding:0.75rem; background:#f8fafc; border-radius:12px; border:1px solid #f1f5f9">
                            <div style="display:flex; align-items:center; gap:0.75rem">
                                <div style="width:32px; height:32px; border-radius:8px; background:#fef3c7; color:#f59e0b; display:flex; align-items:center; justify-content:center; font-size:14px">
                                    <i class="fas fa-comment-sms"></i>
                                </div>
                                <div style="font-size:0.85rem; font-weight:600; color:#1e293b">SMS / Mobil</div>
                            </div>
                            @if($customer->sms_marketing)
                                <span style="font-size:0.7rem; font-weight:700; color:#059669; background:#d1fae5; padding:3px 8px; border-radius:6px">AKTİF</span>
                            @else
                                <span style="font-size:0.7rem; font-weight:700; color:#dc2626; background:#fee2e2; padding:3px 8px; border-radius:6px">KAPALI</span>
                            @endif
                        </div>
                    </div>
                </div>
            </div>

            {{-- Recent activities --}}
            <div class="section-card">
                <div class="section-header">
                    <span class="section-title"><i class="fas fa-history me-2" style="color:#2563eb"></i>Son Aktiviteler</span>
                    <a href="{{ route('agency.customers.activities.index', $customer) }}" style="font-size:.8rem;color:#2563eb;text-decoration:none;font-weight:600">
                        Tümünü Gör <i class="fas fa-arrow-right ms-1"></i>
                    </a>
                </div>
                <div class="section-body p-0" style="padding:1.25rem">
                    @if($recentActivities->isEmpty())
                        <div style="text-align:center;padding:2rem;color:#94a3b8">
                            <i class="fas fa-inbox" style="font-size:2rem;margin-bottom:.75rem"></i>
                            <p style="font-size:.875rem">Henüz aktivite yok.</p>
                            <a href="{{ route('agency.customers.activities.create', $customer) }}" class="btn btn-sm" style="background:linear-gradient(135deg,#2563eb,#1e40af);color:#fff;border-radius:8px">
                                İlk Aktiviteyi Ekle
                            </a>
                        </div>
                    @else
                        <div class="timeline">
                            @foreach($recentActivities as $act)
                            @php
                                $dotClass = match($act->activity_type) {
                                    'call' => 'call', 'email' => 'email',
                                    'meeting' => 'meeting', 'booking' => 'booking',
                                    'complaint' => 'complaint', 'note' => 'note',
                                    default => 'default'
                                };
                                $dotIcon = match($act->activity_type) {
                                    'call' => 'fas fa-phone', 'email' => 'fas fa-envelope',
                                    'meeting' => 'fas fa-people-group', 'booking' => 'fas fa-calendar-check',
                                    'complaint' => 'fas fa-exclamation-circle', 'note' => 'fas fa-sticky-note',
                                    default => 'fas fa-circle'
                                };
                            @endphp
                            <div class="tl-item">
                                <div class="tl-dot {{ $dotClass }}"><i class="{{ $dotIcon }}"></i></div>
                                <div class="tl-content">
                                    <div class="tl-header">
                                        <span class="tl-type">{{ $act->activity_type_label }}</span>
                                        <span class="tl-time">{{ $act->activity_date?->diffForHumans() }}</span>
                                    </div>
                                    @if($act->subject)
                                        <div class="tl-subject">{{ $act->subject }}</div>
                                    @endif
                                    @if($act->description)
                                        <div class="tl-desc">{{ Str::limit($act->description, 120) }}</div>
                                    @endif
                                    <div class="tl-footer">
                                        <span class="pill {{ $act->status }}">{{ $act->status_label }}</span>
                                        @if($act->performedBy)
                                            <span class="tl-meta"><i class="fas fa-user"></i>{{ $act->performedBy->first_name }}</span>
                                        @endif
                                        @if($act->priority === 'urgent')
                                            <span class="tl-meta" style="color:#ef4444"><i class="fas fa-fire"></i>Acil</span>
                                        @endif
                                    </div>
                                </div>
                            </div>
                            @endforeach
                        </div>
                    @endif
                </div>
            </div>

            {{-- Notes --}}
            <div class="section-card">
                <div class="section-header">
                    <span class="section-title"><i class="fas fa-sticky-note me-2" style="color:#f59e0b"></i>Dahili Notlar</span>
                </div>
                <div class="section-body">
                    <div class="inline-editable w-100" data-id="{{ $customer->id }}" data-field="internal_notes" data-type="textarea" data-value="{{ $customer->internal_notes }}" style="background:#fffbeb;border:1px solid #fde68a;border-radius:10px;padding:1rem;font-size:.88rem;color:#78350f;white-space:pre-wrap">{{ $customer->internal_notes ?: 'Not eklemek için tıklayın...' }}</div>
                </div>
            </div>
        </div>

        {{-- ── TAB: DETAILS ── --}}
        <div class="tab-panel" id="tab-details">
            <div class="section-card">
                <div class="section-header">
                    <span class="section-title"><i class="fas fa-user me-2" style="color:#6366f1"></i>Kişisel Bilgiler</span>
                    <a href="{{ route('agency.customers.edit', $customer) }}" style="font-size:.8rem;color:#6366f1;text-decoration:none;font-weight:600">
                        <i class="fas fa-pen me-1"></i>Düzenle
                    </a>
                </div>
                <div class="section-body">
                    <div class="detail-grid">
                        <div class="detail-item">
                            <div class="di-label">Cinsiyet</div>
                            <div class="di-value">
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="gender" data-type="select" data-options="{{ json_encode($genderOptions) }}" data-value="{{ $customer->gender }}">
                                    {{ $customer->gender ? ['male'=>'Erkek', 'female'=>'Kadın', 'other'=>'Diğer'][$customer->gender] : '—' }}
                                </span>
                            </div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">TC / Kimlik No</div>
                            <div class="di-value">
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="national_id">{{ $customer->national_id ?: '—' }}</span>
                                @if($customer->national_id)
                                    <i class="fas fa-copy copy-icon ms-1" style="cursor: pointer; opacity: 0.5; font-size: 0.8rem;" onclick="copyToClipboard('{{ $customer->national_id }}', this)" title="TC Kopyala"></i>
                                @endif
                            </div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Pasaport No</div>
                            <div class="di-value">
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="passport_number">{{ $customer->passport_number ?: '—' }}</span>
                                @if($customer->passport_number)
                                    <i class="fas fa-copy copy-icon ms-1" style="cursor: pointer; opacity: 0.5; font-size: 0.8rem;" onclick="copyToClipboard('{{ $customer->passport_number }}', this)" title="Pasaport Kopyala"></i>
                                @endif
                            </div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Pasaport Geçerlilik</div>
                            <div class="di-value">
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="passport_expiry" data-type="date" data-value="{{ $customer->passport_expiry ? $customer->passport_expiry->format('Y-m-d') : '' }}">
                                    {{ $customer->passport_expiry ? $customer->passport_expiry->format('d.m.Y') : '—' }}
                                </span>
                            </div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Adres</div>
                            <div class="di-value">
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="address" data-type="textarea" data-value="{{ $customer->address }}">{{ $customer->address ?: '—' }}</span>
                                @if($customer->address)
                                    <i class="fas fa-copy copy-icon ms-1" style="cursor: pointer; opacity: 0.5; font-size: 0.8rem;" onclick="copyToClipboard('{{ $customer->address }}', this)" title="Adres Kopyala"></i>
                                @endif
                            </div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Posta Kodu</div>
                            <div class="di-value">
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="postal_code">{{ $customer->postal_code ?: '—' }}</span>
                            </div>
                        </div>
                        @if($customer->isCorporate())
                        <div class="detail-item">
                            <div class="di-label">Şirket Türü</div>
                            <div class="di-value">
                                @php
                                    $ctOptions = [];
                                    foreach(\App\Models\Customer\Customer::companyTypes() as $v => $l) {
                                        $ctOptions[] = ['value' => $v, 'label' => $l];
                                    }
                                @endphp
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="company_type" data-type="select" data-options="{{ json_encode($ctOptions) }}" data-value="{{ $customer->company_type }}">
                                    {{ $customer->company_type_label }}
                                </span>
                            </div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Vergi No</div>
                            <div class="di-value">
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="company_tax_number">{{ $customer->company_tax_number ?: '—' }}</span>
                                @if($customer->company_tax_number)
                                    <i class="fas fa-copy copy-icon ms-1" style="cursor: pointer; opacity: 0.5; font-size: 0.8rem;" onclick="copyToClipboard('{{ $customer->company_tax_number }}', this)" title="Vergi No Kopyala"></i>
                                @endif
                            </div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Vergi Dairesi</div>
                            <div class="di-value">
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="company_tax_office">{{ $customer->company_tax_office ?: '—' }}</span>
                            </div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Unvan / Pozisyon</div>
                            <div class="di-value">
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="company_position">{{ $customer->company_position ?: '—' }}</span>
                            </div>
                        </div>
                        @endif
                        <div class="detail-item">
                            <div class="di-label">Tercih İletişim</div>
                            <div class="di-value">
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="preferred_contact_method" data-type="select" data-options='[{"value":"email","label":"E-posta"},{"value":"phone","label":"Telefon"},{"value":"sms","label":"SMS"}]' data-value="{{ $customer->preferred_contact_method }}">
                                    {{ $customer->preferred_contact_method ? ucfirst($customer->preferred_contact_method) : '—' }}
                                </span>
                            </div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Referans Kaynağı</div>
                            <div class="di-value">
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="referral_source">{{ $customer->referral_source ?: '—' }}</span>
                            </div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Kayıt Tarihi</div>
                            <div class="di-value">{{ $customer->created_at->format('d.m.Y H:i') }}</div>
                        </div>
                    </div>

                    @if($customer->tags || $customer->interests)
                    <hr style="border-color:#f1f5f9;margin:1.25rem 0">
                    @if($customer->tags)
                    <div class="mb-3">
                        <div class="di-label mb-2">Etiketler</div>
                        <div style="display:flex;flex-wrap:wrap;gap:6px">
                            @foreach($customer->tags as $tag)
                                <span style="background:#eef2ff;color:#6366f1;padding:4px 10px;border-radius:20px;font-size:.78rem;font-weight:600">{{ $tag }}</span>
                            @endforeach
                        </div>
                    </div>
                    @endif
                    @if($customer->interests)
                    <div>
                        <div class="di-label mb-2">İlgi Alanları</div>
                        <div style="display:flex;flex-wrap:wrap;gap:6px">
                            @foreach($customer->interests as $interest)
                                <span style="background:#d1fae5;color:#065f46;padding:4px 10px;border-radius:20px;font-size:.78rem;font-weight:600">{{ $interest }}</span>
                            @endforeach
                        </div>
                    </div>
                    @endif
                    @endif
                </div>
            </div>
        </div>

        {{-- ── TAB: CUSTOM FIELDS ── --}}
        <div class="tab-panel" id="tab-custom">
            <div class="section-card">
                <div class="section-header">
                    <span class="section-title"><i class="fas fa-puzzle-piece me-2" style="color:#8b5cf6"></i>Özel Alanlar</span>
                    <a href="{{ route('agency.customers.field-values.edit', $customer) }}" style="font-size:.8rem;color:#6366f1;text-decoration:none;font-weight:600">
                        <i class="fas fa-pen me-1"></i>Düzenle
                    </a>
                </div>
                <div class="section-body">
                    @php
                        $customer->load(['customFieldValues.fieldDefinition']);
                        $cfValues = $customer->customFieldValues->filter(fn($cfv) => $cfv->fieldDefinition?->is_active);
                    @endphp

                    @if($cfValues->isEmpty())
                        <div style="text-align:center;padding:2rem;color:#94a3b8">
                            <i class="fas fa-puzzle-piece" style="font-size:2rem;margin-bottom:.75rem;color:#cbd5e1"></i>
                            <p style="font-size:.875rem">Henüz özel alan tanımlanmamış.</p>
                            <div style="display:flex;gap:.5rem;justify-content:center">
                                <a href="{{ route('agency.customers.fields.index') }}" class="btn btn-sm" style="background:#ede9fe;color:#7c3aed;border-radius:8px">
                                    Alan Tanımla
                                </a>
                                <a href="{{ route('agency.customers.field-values.edit', $customer) }}" class="btn btn-sm" style="background:#eef2ff;color:#6366f1;border-radius:8px">
                                    Değer Gir
                                </a>
                            </div>
                        </div>
                    @else
                        @php
                            $typeMap = [
                                'text' => 'text', 'textarea' => 'textarea', 'email' => 'email', 'phone' => 'tel',
                                'date' => 'date', 'number' => 'number', 'decimal' => 'number', 'select' => 'select',
                                'multiselect' => 'select', 'boolean' => 'select'
                            ];
                        @endphp
                        <div class="cf-grid">
                            @foreach($cfValues as $cfv)
                            @if($cfv->fieldDefinition)
                            <div class="cf-card">
                                <div class="cf-label">{{ $cfv->fieldDefinition->label }}</div>
                                @php
                                    $fieldType = $cfv->fieldDefinition->field_type;
                                    $options = $cfv->fieldDefinition->options ?? [];
                                    if ($fieldType === 'boolean') {
                                        $options = [['value' => '1', 'label' => 'Evet'], ['value' => '0', 'label' => 'Hayır']];
                                    }
                                @endphp
                                <div class="cf-value">
                                    <span class="inline-editable" 
                                          data-id="{{ $customer->id }}" 
                                          data-field="custom_field_{{ $cfv->field_definition_id }}"
                                          data-type="{{ $typeMap[$fieldType] ?? 'text' }}"
                                          data-options="{{ json_encode($options) }}"
                                          data-value="{{ $cfv->value }}">
                                        {{ $cfv->fieldDefinition->formatValue($cfv->value) }}
                                    </span>
                                </div>
                            </div>
                            @endif
                            @endforeach
                        </div>
                    @endif
                </div>
            </div>
        </div>

        {{-- ── TAB: PASSENGERS ── --}}
        <div class="tab-panel" id="tab-passengers">
            <div class="section-card">
                <div class="section-header">
                    <span class="section-title"><i class="fas fa-users me-2" style="color:#6366f1"></i>Yolcular / Bağlantılı Kişiler</span>
                    <button type="button" class="btn btn-sm text-white" style="background:linear-gradient(135deg,#6366f1,#8b5cf6);border-radius:8px"
                            data-bs-toggle="modal" data-bs-target="#addPassengerModal">
                        <i class="fas fa-plus me-1"></i>Yeni Yolcu Ekle
                    </button>
                </div>
                <div class="section-body p-0">
                    @if($customer->passengers->isEmpty())
                        <div style="text-align:center;padding:2rem;color:#94a3b8">
                            <i class="fas fa-users" style="font-size:2rem;margin-bottom:.75rem;color:#cbd5e1"></i>
                            <p style="font-size:.875rem">Henüz yolcu eklenmemiş.</p>
                        </div>
                    @else
                        <div class="table-responsive">
                            <table class="table table-hover align-middle mb-0" style="font-size:.85rem">
                                <thead style="background:#f8fafc;color:#64748b;text-transform:uppercase;font-size:.7rem;letter-spacing:.3px">
                                    <tr>
                                        <th class="ps-4">Ad Soyad</th>
                                        <th>Yakınlık</th>
                                        <th>TC / Pasaport</th>
                                        <th>Vize D.</th>
                                        <th class="text-end pe-4">İşlemler</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($customer->passengers as $pax)
                                    @php
                                        $pUrl = route('agency.customers.passengers.update-field', [$customer, $pax]);
                                        $relOptions = [
                                            ['value'=>'Eş','label'=>'Eş'],
                                            ['value'=>'Çocuk','label'=>'Çocuk'],
                                            ['value'=>'Baba','label'=>'Baba'],
                                            ['value'=>'Anne','label'=>'Anne'],
                                            ['value'=>'Kardeş','label'=>'Kardeş'],
                                            ['value'=>'Arkadaş','label'=>'Arkadaş'],
                                            ['value'=>'Diğer','label'=>'Diğer']
                                        ];
                                    @endphp
                                    <tr>
                                        <td class="ps-4">
                                            <div style="font-weight:600;color:#0f172a">
                                                <span class="inline-editable" data-id="{{ $customer->id }}" data-url="{{ $pUrl }}" data-field="first_name">{{ $pax->first_name }}</span>
                                                <span class="inline-editable" data-id="{{ $customer->id }}" data-url="{{ $pUrl }}" data-field="last_name">{{ $pax->last_name }}</span>
                                            </div>
                                            <div style="font-size:.75rem;color:#94a3b8">
                                                <span class="inline-editable" data-id="{{ $customer->id }}" data-url="{{ $pUrl }}" data-field="birth_date" data-type="date" data-value="{{ $pax->birth_date?->format('Y-m-d') }}">
                                                    {{ $pax->birth_date ? $pax->birth_date->format('d.m.Y') : 'Doğum Tarihi Ekle' }}
                                                </span>
                                                @if($pax->birth_date)
                                                    ({{ $pax->birth_date->age }} yaş)
                                                @endif
                                            </div>
                                        </td>
                                        <td>
                                            <span class="inline-editable sb type-{{ $pax->relationship === 'Diğer' ? 'potential' : 'active' }}" 
                                                  data-id="{{ $customer->id }}" 
                                                  data-url="{{ $pUrl }}" 
                                                  data-field="relationship" 
                                                  data-type="select" 
                                                  data-options="{{ json_encode($relOptions) }}"
                                                  data-value="{{ $pax->relationship }}"
                                                  style="background:#eef2ff;color:#6366f1;padding:4px 8px;border-radius:6px;font-size:11px">
                                                {{ $pax->relationship ?: 'İlişki?' }}
                                            </span>
                                        </td>
                                        <td>
                                            <div style="font-family:monospace">
                                                <span class="inline-editable" data-id="{{ $customer->id }}" data-url="{{ $pUrl }}" data-field="national_id" data-value="{{ $pax->national_id }}">{{ $pax->national_id ?: ($pax->passport_number ? '' : 'TC No Ekle') }}</span>
                                                @if($pax->passport_number && !$pax->national_id)
                                                    <span class="inline-editable" data-id="{{ $customer->id }}" data-url="{{ $pUrl }}" data-field="passport_number" data-value="{{ $pax->passport_number }}">{{ $pax->passport_number }}</span>
                                                @elseif(!$pax->national_id && !$pax->passport_number)
                                                    / <span class="inline-editable" data-id="{{ $customer->id }}" data-url="{{ $pUrl }}" data-field="passport_number">Pasaport Ekle</span>
                                                @endif
                                            </div>
                                            <div style="font-size:.7rem;color:{{ ($pax->passport_expiry && $pax->passport_expiry->isPast()) ? '#ef4444' : '#10b981' }}">
                                                P.Bitiş: <span class="inline-editable" data-id="{{ $customer->id }}" data-url="{{ $pUrl }}" data-field="passport_expiry" data-type="date" data-value="{{ $pax->passport_expiry?->format('Y-m-d') }}">
                                                    {{ $pax->passport_expiry ? $pax->passport_expiry->format('d.m.Y') : '—' }}
                                                </span>
                                            </div>
                                        </td>
                                        <td>
                                            <span class="inline-editable" data-id="{{ $customer->id }}" data-url="{{ $pUrl }}" data-field="visa_status" data-value="{{ $pax->visa_status }}">
                                                {{ $pax->visa_status ?: 'Vize Durumu?' }}
                                            </span>
                                            <div style="font-size:.7rem;color:{{ ($pax->visa_expiry && $pax->visa_expiry->isPast()) ? '#ef4444' : '#10b981' }}">
                                                Bit: <span class="inline-editable" data-id="{{ $customer->id }}" data-url="{{ $pUrl }}" data-field="visa_expiry" data-type="date" data-value="{{ $pax->visa_expiry?->format('Y-m-d') }}">
                                                    {{ $pax->visa_expiry ? $pax->visa_expiry->format('d.m.Y') : '—' }}
                                                </span>
                                            </div>
                                        </td>
                                        <td class="text-end pe-4">
                                            <button class="btn btn-sm btn-light" style="border-radius:6px" 
                                                    onclick="editPassenger({{ $pax->toJson() }})">
                                                <i class="fas fa-edit text-primary"></i>
                                            </button>
                                            <form action="{{ route('agency.customers.passengers.destroy', [$customer, $pax]) }}" method="POST" style="display:inline-block"
                                                  onsubmit="return confirm('Bu yolcuyu silmek istediğinize emin misiniz?');">
                                                @csrf @method('DELETE')
                                                <button type="submit" class="btn btn-sm btn-light" style="border-radius:6px">
                                                    <i class="fas fa-trash text-danger"></i>
                                                </button>
                                            </form>
                                        </td>
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    @endif
                </div>
            </div>
        </div>

        {{-- ── TAB: BILLING ── --}}
        @if($customer->isCorporate())
        <div class="tab-panel" id="tab-billing">
            <div class="section-card">
                <div class="section-header">
                    <span class="section-title"><i class="fas fa-file-invoice me-2" style="color:#6366f1"></i>Fatura Bilgileri</span>
                </div>
                <div class="section-body">
                    <div class="detail-grid">
                        <div class="detail-item" style="grid-column: span 2">
                            <div class="di-label">Fatura Adresi</div>
                            <div class="di-value">
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="billing_address" data-type="textarea" data-value="{{ $customer->billing_address }}">{{ $customer->billing_address ?: '—' }}</span>
                            </div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Fatura İli</div>
                            <div class="di-value">
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="billing_city">{{ $customer->billing_city ?: '—' }}</span>
                            </div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Fatura İlçe</div>
                            <div class="di-value">
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="billing_district">{{ $customer->billing_district ?: '—' }}</span>
                            </div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Fatura E-posta</div>
                            <div class="di-value">
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="billing_email" data-type="email" data-value="{{ $customer->billing_email }}">{{ $customer->billing_email ?: '—' }}</span>
                                @if($customer->billing_email)
                                    <i class="fas fa-copy copy-icon ms-1" style="cursor: pointer; opacity: 0.5; font-size: 0.8rem;" onclick="copyToClipboard('{{ $customer->billing_email }}', this)" title="Fatura E-posta Kopyala"></i>
                                @endif
                            </div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Fatura Vergi No</div>
                            <div class="di-value">
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="billing_tax_number">{{ $customer->billing_tax_number ?: '—' }}</span>
                                @if($customer->billing_tax_number)
                                    <i class="fas fa-copy copy-icon ms-1" style="cursor: pointer; opacity: 0.5; font-size: 0.8rem;" onclick="copyToClipboard('{{ $customer->billing_tax_number }}', this)" title="Fatura Vergi No Kopyala"></i>
                                @endif
                            </div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Fatura Vergi Dairesi</div>
                            <div class="di-value">
                                <span class="inline-editable" data-id="{{ $customer->id }}" data-field="billing_tax_office">{{ $customer->billing_tax_office ?: '—' }}</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        @endif

        {{-- ── TAB: FINANCIAL ── --}}
        <div class="tab-panel" id="tab-financial">
            <div class="section-card">
                <div class="section-header">
                    <span class="section-title"><i class="fas fa-wallet me-2" style="color:#10b981"></i>Finansal Özet</span>
                </div>
                <div class="section-body">
                    <div class="detail-grid">
                        <div class="detail-item">
                            <div class="di-label">Toplam Harcama</div>
                            <div class="di-value" style="font-size:1.1rem;font-weight:800;color:#10b981">
                                ₺{{ number_format((float)($customer->total_spent ?? 0), 2, ',', '.') }}
                            </div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Ortalama Rezervasyon</div>
                            <div class="di-value" style="font-weight:700">
                                ₺{{ number_format((float)($customer->average_booking_value ?? 0), 2, ',', '.') }}
                            </div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Kredi Limiti</div>
                            <div class="di-value">₺{{ number_format((float)($customer->credit_limit ?? 0), 2, ',', '.') }}</div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Mevcut Bakiye</div>
                            <div class="di-value">₺{{ number_format((float)($customer->current_balance ?? 0), 2, ',', '.') }}</div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">İlk Rezervasyon</div>
                            <div class="di-value">{{ $customer->first_booking_date?->format('d.m.Y') ?: '—' }}</div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Son Rezervasyon</div>
                            <div class="di-value">{{ $customer->last_booking_date?->format('d.m.Y') ?: '—' }}</div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">Ödeme Güvenilirliği</div>
                            <div class="di-value">{{ $customer->payment_reliability_label }}</div>
                        </div>
                        <div class="detail-item">
                            <div class="di-label">İptal Sayısı</div>
                            <div class="di-value">{{ $customer->cancellation_count ?? 0 }}</div>
                        </div>
                    </div>

                    {{-- Loyalty progress --}}
                    @if($customer->loyalty_points !== null)
                    <hr style="border-color:#f1f5f9;margin:1.25rem 0">
                    <div>
                        <div style="display:flex;justify-content:space-between;margin-bottom:.5rem">
                            <span style="font-size:.82rem;font-weight:600;color:#0f172a">Sadakat Puanı: <strong style="color:#f59e0b">{{ $customer->loyalty_points }}</strong></span>
                            <span style="font-size:.78rem;color:#94a3b8">{{ $customer->loyalty_tier_label }}</span>
                        </div>
                        @php
                            $tierProgress = match($customer->loyalty_tier) {
                                'bronze'   => [$customer->loyalty_points, 2000],
                                'silver'   => [$customer->loyalty_points - 2000, 3000],
                                'gold'     => [$customer->loyalty_points - 5000, 5000],
                                'platinum' => [1, 1],
                                default    => [0, 2000]
                            };
                            $pct = min(100, ($tierProgress[0] / max(1, $tierProgress[1])) * 100);
                        @endphp
                        <div style="background:#f1f5f9;border-radius:999px;height:8px;overflow:hidden">
                            <div style="background:linear-gradient(90deg,#f59e0b,#fbbf24);height:100%;width:{{ $pct }}%;border-radius:999px;transition:width .5s"></div>
                        </div>
                        <div style="font-size:.72rem;color:#94a3b8;margin-top:4px">Sonraki seviyeye: {{ max(0, $tierProgress[1] - $tierProgress[0]) }} puan kaldı</div>
                    </div>
                    @endif
                </div>
            </div>
        </div>

        {{-- ── TAB: DOCUMENTS ── --}}
        <div class="tab-panel" id="tab-documents">
            <div class="section-card">
                <div class="section-header">
                    <span class="section-title"><i class="fas fa-file-invoice me-2" style="color:#6366f1"></i>Müşteri Dökümanları</span>
                    <div class="d-flex gap-2">
                        <a href="{{ route('agency.customers.document-types.index') }}" class="btn btn-sm btn-outline-secondary" style="border-radius:8px">
                            <i class="fas fa-cog me-1"></i>Tipler
                        </a>
                        <button class="btn btn-sm text-white" style="background:linear-gradient(135deg,#6366f1,#8b5cf6);border-radius:8px" onclick="$('#doc-upload-area').slideToggle()">
                            <i class="fas fa-upload me-1"></i>Yükle
                        </button>
                    </div>
                </div>
                <div class="section-body">
                    <div id="doc-upload-area" class="mb-4 p-3 bg-light rounded-3" style="display:none; border:1px dashed #cbd5e1">
                        <form id="doc-upload-form" enctype="multipart/form-data">
                            @csrf
                            <input type="hidden" name="customer_id" value="{{ $customer->id }}">
                            <div class="row g-3">
                                <div class="col-md-5">
                                    <label class="form-label small fw-bold">Döküman Tipi</label>
                                    <select name="document_type_id" class="form-select form-select-sm" required>
                                        <option value="">Seçiniz...</option>
                                        @foreach(\App\Models\Customer\CustomerDocumentType::byAgency($customer->agency_id)->active()->get() as $type)
                                            <option value="{{ $type->id }}">{{ $type->name }}</option>
                                        @endforeach
                                    </select>
                                </div>
                                <div class="col-md-7">
                                    <label class="form-label small fw-bold">Dosya Seçin</label>
                                    <input type="file" name="file" class="form-control form-control-sm" required>
                                </div>
                                <div class="col-12">
                                    <label class="form-label small fw-bold">Notlar</label>
                                    <input type="text" name="notes" class="form-control form-control-sm" placeholder="Kısa bir not...">
                                </div>
                                <div class="col-12 text-end">
                                    <button type="button" class="btn btn-sm btn-link text-muted" onclick="$('#doc-upload-area').slideUp()">İptal</button>
                                    <button type="submit" class="btn btn-sm btn-primary px-4">Yükle</button>
                                </div>
                            </div>
                        </form>
                    </div>

                    @if($customer->customerDocuments->isEmpty())
                        <div class="text-center py-5">
                            <i class="fas fa-file-invoice text-muted mb-3" style="font-size: 2.5rem; opacity: 0.2;"></i>
                            <p class="text-muted small">Henüz yüklenmiş bir döküman bulunmamaktadır.</p>
                        </div>
                    @else
                        <div class="row g-3">
                            @foreach($customer->customerDocuments as $doc)
                                <div class="col-md-6 col-lg-4 doc-item-{{ $doc->id }}">
                                    <div class="card h-100 border shadow-xs" style="border-radius:12px; transition: transform 0.2s;">
                                        <div class="card-body p-3">
                                            <div class="d-flex align-items-start gap-2 mb-3">
                                                <div class="flex-shrink-0 bg-light rounded d-flex align-items-center justify-content-center" style="width:40px; height:40px;">
                                                    <i class="fas {{ match(true) { 
                                                        str_contains($doc->mime_type, 'pdf') => 'fa-file-pdf text-danger',
                                                        str_contains($doc->mime_type, 'image') => 'fa-file-image text-success',
                                                        str_contains($doc->mime_type, 'word') => 'fa-file-word text-primary',
                                                        default => 'fa-file-alt'
                                                    } }} fs-5"></i>
                                                </div>
                                                <div class="flex-grow-1 min-w-0">
                                                    <div class="fw-bold text-dark text-truncate small" title="{{ $doc->file_name }}">{{ $doc->file_name }}</div>
                                                    <div class="badge bg-soft-primary text-primary mt-1" style="font-size:0.65rem">{{ $doc->type->name }}</div>
                                                </div>
                                            </div>
                                            <div class="d-flex justify-content-between align-items-center mt-auto">
                                                <span class="text-muted" style="font-size:0.7rem">{{ $doc->created_at->format('d.m.Y') }} • {{ $doc->human_file_size }}</span>
                                                <div class="d-flex gap-1">
                                                    <a href="{{ $doc->file_url }}" target="_blank" class="btn btn-sm btn-light border p-1 px-2" title="Görüntüle"><i class="fas fa-external-link-alt text-primary"></i></a>
                                                    <button class="btn btn-sm btn-light border p-1 px-2" onclick="deleteDoc({{ $doc->id }}, this)" title="Sil"><i class="fas fa-trash text-danger"></i></button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            @endforeach
                        </div>
                    @endif
                </div>
            </div>
        </div>

    </div>
</div>

{{-- ─── MODALS ─── --}}
{{-- Blacklist Modal --}}
<div class="modal fade" id="blacklistModal" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content" style="border-radius:16px;border:none;box-shadow:0 20px 60px rgba(0,0,0,.15)">
            <div class="modal-header" style="border-bottom:1px solid #f1f5f9">
                <h5 class="modal-title" style="font-weight:700"><i class="fas fa-ban me-2 text-danger"></i>Kara Listeye Al</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <form method="POST" action="{{ route('agency.customers.toggle-blacklist', $customer) }}">
                @csrf
                <div class="modal-body">
                    <label style="font-size:.85rem;font-weight:600;color:#0f172a;margin-bottom:.5rem;display:block">Kara Liste Nedeni*</label>
                    <textarea name="blacklist_reason" rows="3" required
                              style="width:100%;border:1.5px solid #e2e8f0;border-radius:10px;padding:.75rem;font-size:.875rem;resize:none"
                              placeholder="Neden kara listeye alınıyor?"></textarea>
                </div>
                <div class="modal-footer" style="border-top:1px solid #f1f5f9">
                    <button type="button" class="btn btn-sm btn-outline-secondary" data-bs-dismiss="modal">İptal</button>
                    <button type="submit" class="btn btn-sm btn-danger" style="border-radius:8px">Kara Listeye Al</button>
                </div>
            </form>
        </div>
    </div>
</div>

{{-- Add Passenger Modal --}}
<div class="modal fade" id="addPassengerModal" tabindex="-1">
    <div class="modal-dialog modal-lg modal-dialog-centered">
        <div class="modal-content" style="border-radius:16px;border:none;box-shadow:0 20px 60px rgba(0,0,0,.15)">
            <div class="modal-header" style="border-bottom:1px solid #f1f5f9">
                <h5 class="modal-title" style="font-weight:700"><i class="fas fa-user-plus me-2" style="color:#6366f1"></i>Yeni Yolcu Ekle</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <form method="POST" action="{{ route('agency.customers.passengers.store', $customer) }}">
                @csrf
                <div class="modal-body">
                    <div class="row g-3">
                        <div class="col-md-6">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Ad*</label>
                            <input type="text" name="first_name" class="form-control" placeholder="Yolcu Adı" required>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Soyad*</label>
                            <input type="text" name="last_name" class="form-control" placeholder="Yolcu Soyadı" required>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Yakınlık (Örn: Eşi, Çocuğu)</label>
                            <input type="text" name="relationship" class="form-control" placeholder="Müşteriyle olan bağlantısı">
                        </div>
                        <div class="col-md-3">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Doğum Tarihi</label>
                            <input type="date" name="birth_date" class="form-control">
                        </div>
                        <div class="col-md-3">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Cinsiyet</label>
                            <select name="gender" class="form-select">
                                <option value="">Seçiniz</option>
                                <option value="male">Erkek</option>
                                <option value="female">Kadın</option>
                                <option value="other">Diğer</option>
                            </select>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">TC Kimlik No</label>
                            <input type="text" name="national_id" class="form-control" placeholder="11 haneli TC">
                        </div>
                        <div class="col-md-3">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Vize Durumu</label>
                            <input type="text" name="visa_status" class="form-control" placeholder="Schengen vs.">
                        </div>
                        <div class="col-md-3">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Vize Bitiş Tarihi</label>
                            <input type="date" name="visa_expiry" class="form-control">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Pasaport Numarası</label>
                            <input type="text" name="passport_number" class="form-control" placeholder="Pasaport No">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Pasaport Bitiş Tarihi</label>
                            <input type="date" name="passport_expiry" class="form-control">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Telefon</label>
                            <input type="text" name="phone" class="form-control" placeholder="Telefon numarası">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">E-posta</label>
                            <input type="email" name="email" class="form-control" placeholder="E-posta adresi">
                        </div>
                    </div>
                </div>
                <div class="modal-footer" style="border-top:1px solid #f1f5f9">
                    <button type="button" class="btn btn-sm btn-outline-secondary" data-bs-dismiss="modal">İptal</button>
                    <button type="submit" class="btn btn-sm text-white" style="background:linear-gradient(135deg,#6366f1,#8b5cf6);border-radius:8px">Kaydet</button>
                </div>
            </form>
        </div>
    </div>
</div>

{{-- Edit Passenger Modal --}}
<div class="modal fade" id="editPassengerModal" tabindex="-1">
    <div class="modal-dialog modal-lg modal-dialog-centered">
        <div class="modal-content" style="border-radius:16px;border:none;box-shadow:0 20px 60px rgba(0,0,0,.15)">
            <div class="modal-header" style="border-bottom:1px solid #f1f5f9">
                <h5 class="modal-title" style="font-weight:700"><i class="fas fa-user-edit me-2" style="color:#6366f1"></i>Yolcu Düzenle</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <form method="POST" id="editPassengerForm" action="">
                @csrf @method('PUT')
                <div class="modal-body">
                    <div class="row g-3">
                        <div class="col-md-6">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Ad*</label>
                            <input type="text" name="first_name" id="edit_first_name" class="form-control" required>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Soyad*</label>
                            <input type="text" name="last_name" id="edit_last_name" class="form-control" required>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Yakınlık</label>
                            <input type="text" name="relationship" id="edit_relationship" class="form-control">
                        </div>
                        <div class="col-md-3">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Doğum Tarihi</label>
                            <input type="date" name="birth_date" id="edit_birth_date" class="form-control">
                        </div>
                        <div class="col-md-3">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Cinsiyet</label>
                            <select name="gender" id="edit_gender" class="form-select">
                                <option value="">Seçiniz</option>
                                <option value="male">Erkek</option>
                                <option value="female">Kadın</option>
                                <option value="other">Diğer</option>
                            </select>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">TC Kimlik No</label>
                            <input type="text" name="national_id" id="edit_national_id" class="form-control">
                        </div>
                        <div class="col-md-3">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Vize Durumu</label>
                            <input type="text" name="visa_status" id="edit_visa_status" class="form-control">
                        </div>
                        <div class="col-md-3">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Vize Bitiş Tarihi</label>
                            <input type="date" name="visa_expiry" id="edit_visa_expiry" class="form-control">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Pasaport Numarası</label>
                            <input type="text" name="passport_number" id="edit_passport_number" class="form-control">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Pasaport Bitiş Tarihi</label>
                            <input type="date" name="passport_expiry" id="edit_passport_expiry" class="form-control">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">Telefon</label>
                            <input type="text" name="phone" id="edit_phone" class="form-control">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label" style="font-size:.8rem;font-weight:600">E-posta</label>
                            <input type="email" name="email" id="edit_email" class="form-control">
                        </div>
                    </div>
                </div>
                <div class="modal-footer" style="border-top:1px solid #f1f5f9">
                    <button type="button" class="btn btn-sm btn-outline-secondary" data-bs-dismiss="modal">İptal</button>
                    <button type="submit" class="btn btn-sm text-white" style="background:linear-gradient(135deg,#6366f1,#8b5cf6);border-radius:8px">Güncelle</button>
                </div>
            </form>
        </div>
    </div>
</div>

</div>
@endsection

@push('scripts')
<script>
// Tab switching
function showTab(tab, el) {
    document.querySelectorAll('.tab-panel').forEach(p => p.classList.remove('active'));
    document.querySelectorAll('.ctab').forEach(t => t.classList.remove('active'));
    document.getElementById('tab-' + tab).classList.add('active');
    el.classList.add('active');
}

// Blacklist toggle
function toggleBlacklist() {
    @if($customer->blacklisted)
        if (confirm('Müşteriyi kara listeden çıkarmak istediğinizden emin misiniz?')) {
            document.querySelector('#blacklistModal form').onsubmit = null;
            fetch('{{ route("agency.customers.toggle-blacklist", $customer) }}', {
                method: 'POST',
                headers: {'X-CSRF-TOKEN': '{{ csrf_token() }}', 'Content-Type': 'application/json'},
                body: JSON.stringify({blacklist_reason: ''})
            }).then(() => location.reload());
        }
    @else
        new bootstrap.Modal(document.getElementById('blacklistModal')).show();
    @endif
}

// Edit Passenger Modal
function editPassenger(pax) {
    let form = document.getElementById('editPassengerForm');
    form.action = `/agency/customers/{{ $customer->id }}/passengers/${pax.id}`;
    
    document.getElementById('edit_first_name').value = pax.first_name || '';
    document.getElementById('edit_last_name').value = pax.last_name || '';
    document.getElementById('edit_relationship').value = pax.relationship || '';
    
    if (pax.birth_date && typeof pax.birth_date === 'string') {
        document.getElementById('edit_birth_date').value = pax.birth_date.substring(0, 10);
    } else {
        document.getElementById('edit_birth_date').value = '';
    }
    
    document.getElementById('edit_gender').value = pax.gender || '';
    document.getElementById('edit_national_id').value = pax.national_id || '';
    document.getElementById('edit_visa_status').value = pax.visa_status || '';
    
    if (pax.visa_expiry && typeof pax.visa_expiry === 'string') {
        document.getElementById('edit_visa_expiry').value = pax.visa_expiry.substring(0, 10);
    } else {
        document.getElementById('edit_visa_expiry').value = '';
    }
    
    document.getElementById('edit_passport_number').value = pax.passport_number || '';
    
    if (pax.passport_expiry && typeof pax.passport_expiry === 'string') {
        document.getElementById('edit_passport_expiry').value = pax.passport_expiry.substring(0, 10);
    } else {
        document.getElementById('edit_passport_expiry').value = '';
    }
    
    document.getElementById('edit_phone').value = pax.phone || '';
    document.getElementById('edit_email').value = pax.email || '';
    
    new bootstrap.Modal(document.getElementById('editPassengerModal')).show();
}

// Auto-trigger from URL params
document.addEventListener('DOMContentLoaded', () => {
    const urlParams = new URLSearchParams(window.location.search);
    const tab = urlParams.get('tab');
    const addPassenger = urlParams.get('add_passenger');
    const blacklist = urlParams.get('blacklist');

    if (tab) {
        const tabBtn = document.querySelector(`.ctab[onclick*="'${tab}'"]`);
        if (tabBtn) tabBtn.click();
    }

    if (addPassenger === '1') {
        const addModal = new bootstrap.Modal(document.getElementById('addPassengerModal'));
        addModal.show();
    }

    if (blacklist === '1') {
        toggleBlacklist();
    }

    // Doc upload handle
    $('#doc-upload-form').on('submit', function(e) {
        e.preventDefault();
        let fd = new FormData(this);
        let btn = $(this).find('button[type="submit"]');
        btn.prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i>');
        
        $.ajax({
            url: "{{ route('agency.customers.documents.store', $customer->id) }}",
            type: 'POST', data: fd, processData: false, contentType: false,
            success: (r) => { 
                Swal.fire({ icon: 'success', title: 'Başarılı', text: r.message, timer: 1500, showConfirmButton: false })
                .then(() => location.reload()); 
            },
            error: (xhr) => { 
                Swal.fire('Hata', xhr.responseJSON?.message || 'Hata oluştu', 'error'); 
                btn.prop('disabled', false).text('Yükle'); 
            }
        });
    });
});

function deleteDoc(id, btn) {
    if(!confirm('Bu dökümanı silmek istediğinize emin misiniz?')) return;
    $(btn).prop('disabled', true);
    $.ajax({
        url: "/agency/customers/documents/" + id,
        type: 'DELETE', data: { _token: "{{ csrf_token() }}" },
        success: (r) => { 
            Swal.fire({ icon: 'success', title: 'Silindi', text: r.message, timer: 1500, showConfirmButton: false });
            $(btn).closest('.col-md-6').fadeOut(); 
        },
        error: () => { 
            Swal.fire('Hata', 'Hata oluştu', 'error'); 
            $(btn).prop('disabled', false); 
        }
    });
}
</script>
@endpush
