<div>

    {{-- ══════════════════════════════════════════
         PAGE HEADER & TOOLBAR
    ══════════════════════════════════════════ --}}
    <div class="px-5 pt-5 pb-4 bg-white dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700">

        {{-- Title row --}}
        <div class="flex items-center justify-between mb-4">
            <div>
                <h1 class="text-xl font-bold text-gray-900 dark:text-white sm:text-2xl tracking-tight">
                    {{ __('hotel::modules.reservation.reservations') }}
                </h1>
            </div>
            <div class="flex items-center gap-2 shrink-0">
                <a href="{{ route('hotel.reservations.availability') }}"
                    class="inline-flex items-center gap-1.5 px-3.5 py-2 text-sm font-medium rounded-lg border border-gray-300 bg-white text-gray-700 hover:bg-gray-50 dark:bg-gray-700 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-600 transition">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
                    </svg>
                    {{ __('hotel::modules.reservation.checkAvailability') }}
                </a>
                @if(user_can('Create Hotel Reservation'))
                <button type="button" wire:click="$toggle('showAddReservationModal')"
                    class="inline-flex items-center gap-1.5 px-3.5 py-2 text-sm font-semibold rounded-lg bg-skin-base text-white hover:opacity-90 transition shadow-sm">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
                    </svg>
                    {{ __('hotel::modules.reservation.newReservation') }}
                </button>
                @endif
            </div>
        </div>

        {{-- Filter toolbar --}}
        <div class="flex flex-col sm:flex-row gap-2">
            {{-- Search --}}
            <div class="relative flex-1 min-w-0 sm:max-w-sm">
                <div class="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
                    <svg class="w-4 h-4 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-4.35-4.35M17 11A6 6 0 111 11a6 6 0 0116 0z" />
                    </svg>
                </div>
                <x-input type="text"
                    wire:model.live.debounce.400ms="search"
                    placeholder="{{ __('hotel::modules.reservation.searchPlaceholder') }}"
                    class="block w-full pl-9" />
            </div>

            {{-- Date filter --}}
            <x-input type="date" wire:model.live="filterDate" class="block w-full sm:w-40" />

            {{-- Status filter --}}
            <x-select wire:model.live="filterStatus" class="block w-full sm:w-44">
                <option value="">{{ __('hotel::modules.reservation.allStatuses') }}</option>
                @foreach($statuses as $status)
                    <option value="{{ $status->value }}">{{ $status->label() }}</option>
                @endforeach
            </x-select>
        </div>
    </div>

    {{-- ══════════════════════════════════════════
         TABLE
    ══════════════════════════════════════════ --}}
    @php
        $statusCfg = [
            'tentative'   => ['dot' => 'bg-amber-400',   'badge' => 'bg-amber-50 text-amber-700 ring-amber-200 dark:bg-amber-900/30 dark:text-amber-300 dark:ring-amber-700'],
            'confirmed'   => ['dot' => 'bg-blue-500',    'badge' => 'bg-blue-50 text-blue-700 ring-blue-200 dark:bg-blue-900/30 dark:text-blue-300 dark:ring-blue-700'],
            'checked_in'  => ['dot' => 'bg-emerald-500', 'badge' => 'bg-emerald-50 text-emerald-700 ring-emerald-200 dark:bg-emerald-900/30 dark:text-emerald-300 dark:ring-emerald-700'],
            'checked_out' => ['dot' => 'bg-slate-400',   'badge' => 'bg-slate-50 text-slate-600 ring-slate-200 dark:bg-slate-700/40 dark:text-slate-300 dark:ring-slate-600'],
            'cancelled'   => ['dot' => 'bg-rose-500',    'badge' => 'bg-rose-50 text-rose-700 ring-rose-200 dark:bg-rose-900/30 dark:text-rose-300 dark:ring-rose-700'],
            'no_show'     => ['dot' => 'bg-orange-400',  'badge' => 'bg-orange-50 text-orange-700 ring-orange-200 dark:bg-orange-900/30 dark:text-orange-300 dark:ring-orange-700'],
        ];
    @endphp

    <div class="overflow-x-auto">
        <table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
            <thead class="bg-gray-50 dark:bg-gray-700/50">
                <tr>
                    <th class="px-5 py-3 text-left text-[11px] font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400">{{ __('hotel::modules.reservation.reservationNumber') }}</th>
                    <th class="px-5 py-3 text-left text-[11px] font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400">{{ __('hotel::modules.reservation.guest') }}</th>
                    <th class="px-5 py-3 text-left text-[11px] font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400">{{ __('hotel::modules.reservation.checkIn') }}</th>
                    <th class="px-5 py-3 text-left text-[11px] font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400">{{ __('hotel::modules.reservation.checkOut') }}</th>
                    <th class="px-5 py-3 text-center text-[11px] font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400">{{ __('hotel::modules.reservation.rooms') }}</th>
                    <th class="px-5 py-3 text-right text-[11px] font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400">{{ __('hotel::modules.reservation.amount') }}</th>
                    <th class="px-5 py-3 text-right text-[11px] font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400">{{ __('hotel::modules.reservation.status') }}</th>
                    <th class="px-5 py-3 text-right text-[11px] font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400">{{ __('hotel::modules.reservation.action') }}</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-100 dark:divide-gray-700 bg-white dark:bg-gray-800">
                @forelse ($reservations as $reservation)
                @php
                    $sc = $statusCfg[$reservation->status->value] ?? ['dot' => 'bg-gray-400', 'badge' => 'bg-gray-100 text-gray-600 ring-gray-200'];
                    $initials = collect(explode(' ', $reservation->primaryGuest->full_name))->map(fn($w) => strtoupper($w[0] ?? ''))->take(2)->join('');
                @endphp
                <tr class="group hover:bg-gray-50 dark:hover:bg-gray-700/40 transition-colors duration-100">

                    {{-- Reservation # --}}
                    <td class="px-5 py-3.5 whitespace-nowrap">
                        <span class="text-sm font-bold text-gray-900 dark:text-white tracking-tight">
                            {{ $reservation->reservation_number }}
                        </span>
                    </td>

                    {{-- Guest --}}
                    <td class="px-5 py-3.5 whitespace-nowrap">
                        <div class="flex items-center gap-2.5">
                            <span class="inline-flex items-center justify-center w-7 h-7 rounded-full bg-indigo-100 dark:bg-indigo-900/40 text-indigo-700 dark:text-indigo-300 text-[10px] font-bold shrink-0">
                                {{ $initials }}
                            </span>
                            <span class="text-sm font-medium text-gray-800 dark:text-gray-100 truncate max-w-[140px]">
                                {{ $reservation->primaryGuest->full_name }}
                            </span>
                        </div>
                    </td>

                    {{-- Check-in --}}
                    <td class="px-5 py-3.5 whitespace-nowrap">
                        <div class="flex items-center gap-1.5">
                            <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 text-gray-400 shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                                <path stroke-linecap="round" stroke-linejoin="round" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
                            </svg>
                            <span class="text-sm text-gray-700 dark:text-gray-200">{{ $reservation->check_in_date->format('M d, Y') }}</span>
                        </div>
                    </td>

                    {{-- Check-out --}}
                    <td class="px-5 py-3.5 whitespace-nowrap">
                        <div class="flex items-center gap-1.5">
                            <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 text-gray-400 shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                                <path stroke-linecap="round" stroke-linejoin="round" d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1" />
                            </svg>
                            <span class="text-sm text-gray-700 dark:text-gray-200">{{ $reservation->check_out_date->format('M d, Y') }}</span>
                        </div>
                    </td>

                    {{-- Rooms --}}
                    <td class="px-5 py-3.5 whitespace-nowrap text-center">
                        <span class="inline-flex items-center justify-center w-6 h-6 rounded-full bg-purple-100 dark:bg-purple-900/40 text-purple-700 dark:text-purple-300 text-xs font-bold">
                            {{ $reservation->rooms_count }}
                        </span>
                    </td>

                    {{-- Amount --}}
                    <td class="px-5 py-3.5 whitespace-nowrap text-right">
                        <span class="text-sm font-semibold text-gray-900 dark:text-white">
                            {{ currency_format($reservation->total_amount) }}
                        </span>
                    </td>

                    {{-- Status --}}
                    <td class="px-5 py-3.5 whitespace-nowrap text-right">
                        <span class="inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-[11px] font-semibold ring-1 {{ $sc['badge'] }}">
                            <span class="w-1.5 h-1.5 rounded-full {{ $sc['dot'] }} shrink-0"></span>
                            {{ $reservation->status->label() }}
                        </span>
                    </td>

                    {{-- Actions --}}
                    <td class="px-5 py-3.5 whitespace-nowrap text-right">
                        <div class="inline-flex items-center justify-end gap-1">
                            @if(user_can('Update Hotel Reservation'))
                                <x-secondary-button-table wire:click='showEditReservation({{ $reservation->id }})'>
                                    <svg class="w-4 h-4 mr-1" fill="currentColor" viewBox="0 0 20 20"><path d="M10 12a2 2 0 100-4 2 2 0 000 4z"></path><path fill-rule="evenodd" d="M.458 10C1.732 5.943 5.522 3 10 3s8.268 2.943 9.542 7c-1.274 4.057-5.064 7-9.542 7S1.732 14.057.458 10zM14 10a4 4 0 11-8 0 4 4 0 018 0z" clip-rule="evenodd"></path></svg>
                                    {{ __('hotel::modules.reservation.view') }}
                                </x-secondary-button-table>
                            @endif

                            @if(user_can('Update Hotel Reservation') && in_array($reservation->status->value, ['tentative', 'confirmed']))
                                <x-secondary-button-table wire:click='openEditReservationForm({{ $reservation->id }})'>
                                    <svg class="w-4 h-4 mr-1" fill="currentColor" viewBox="0 0 20 20"><path d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z"></path></svg>
                                    {{ __('hotel::modules.reservation.edit') }}
                                </x-secondary-button-table>
                            @endif

                            @if(user_can('Cancel Hotel Reservation') && in_array($reservation->status->value, ['tentative', 'confirmed']))
                                <x-danger-button-table wire:click="showCancelReservation({{ $reservation->id }})">
                                    {{ __('hotel::modules.reservation.cancel') }}
                                </x-danger-button-table>
                            @endif
                        </div>
                    </td>
                </tr>
                @empty
                <tr>
                    <td colspan="8" class="px-5 py-16 text-center">
                        <div class="flex flex-col items-center gap-3">
                            <span class="inline-flex items-center justify-center w-14 h-14 rounded-2xl bg-gray-100 dark:bg-gray-700">
                                <svg xmlns="http://www.w3.org/2000/svg" class="w-7 h-7 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5">
                                    <path stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2" />
                                </svg>
                            </span>
                            <p class="text-sm font-medium text-gray-500 dark:text-gray-400">{{ __('hotel::modules.reservation.noReservationsFound') }}</p>
                        </div>
                    </td>
                </tr>
                @endforelse
            </tbody>
        </table>
    </div>

    <div class="px-5 py-4 border-t border-gray-200 dark:border-gray-700">
        {{ $reservations->links() }}
    </div>

    {{-- ══════════════════════════════════════════
         MODALS
    ══════════════════════════════════════════ --}}

    {{-- Add Reservation --}}
    <x-right-modal wire:model.live="showAddReservationModal">
        <x-slot name="title">{{ __('hotel::modules.reservation.newReservation') }}</x-slot>
        <x-slot name="content">
            @if ($showAddReservationModal)
                <livewire:hotel::forms.add-reservation />
            @endif
        </x-slot>
        <x-slot name="footer">
            <x-secondary-button wire:click="$set('showAddReservationModal', false)">{{ __('app.close') }}</x-secondary-button>
        </x-slot>
    </x-right-modal>

    {{-- View / Detail Reservation --}}
    <x-right-modal wire:model.live="showEditReservationModal" maxWidth="3xl">
        <x-slot name="title">
            @if($activeReservation ?? null)
            @php
                $titleStatusCfg = [
                    'confirmed'   => 'bg-emerald-100 text-emerald-800 dark:bg-emerald-900/40 dark:text-emerald-300',
                    'tentative'   => 'bg-amber-100 text-amber-800 dark:bg-amber-900/40 dark:text-amber-300',
                    'checked_in'  => 'bg-sky-100 text-sky-800 dark:bg-sky-900/40 dark:text-sky-300',
                    'checked_out' => 'bg-slate-100 text-slate-700 dark:bg-slate-700 dark:text-slate-300',
                    'cancelled'   => 'bg-rose-100 text-rose-800 dark:bg-rose-900/40 dark:text-rose-300',
                    'no_show'     => 'bg-orange-100 text-orange-800 dark:bg-orange-900/40 dark:text-orange-300',
                ];
                $titleStatusStyle = $titleStatusCfg[$activeReservation->status->value] ?? 'bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300';
            @endphp
            <span class="flex items-center gap-2.5">
                <span class="text-gray-900 dark:text-white font-bold">{{ $activeReservation->reservation_number }}</span>
                <span class="text-xs font-semibold px-2 py-0.5 rounded-full {{ $titleStatusStyle }}">{{ $activeReservation->status->label() }}</span>
            </span>
            @endif
        </x-slot>

        <x-slot name="content">
            @if ($showEditReservationModal && $activeReservation)
            <div class="space-y-5">

                {{-- ══ Reservation banner ══ --}}
                @php
                    $nights = $activeReservation->check_in_date->diffInDays($activeReservation->check_out_date);
                @endphp
                <div class="flex items-center justify-between px-4 py-3 rounded-xl bg-gradient-to-r from-indigo-50 to-blue-50 border border-indigo-200 dark:from-indigo-900/20 dark:to-blue-900/20 dark:border-indigo-700/60">
                    <div class="flex items-center gap-3">
                        <span class="inline-flex items-center justify-center w-10 h-10 rounded-xl bg-indigo-100 dark:bg-indigo-800/60 shrink-0">
                            <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-indigo-600 dark:text-indigo-300" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.8">
                                <path stroke-linecap="round" stroke-linejoin="round" d="M9 12h3.75M9 15h3.75M9 18h3.75m3 .75H18a2.25 2.25 0 002.25-2.25V6.108c0-1.135-.845-2.098-1.976-2.192a48.424 48.424 0 00-1.123-.08m-5.801 0c-.065.21-.1.433-.1.664 0 .414.336.75.75.75h4.5a.75.75 0 00.75-.75 2.25 2.25 0 00-.1-.664m-5.8 0A2.251 2.251 0 0113.5 2.25H15c1.012 0 1.867.668 2.15 1.586m-5.8 0c-.376.023-.75.05-1.124.08C9.095 4.01 8.25 4.973 8.25 6.108V8.25m0 0H4.875c-.621 0-1.125.504-1.125 1.125v11.25c0 .621.504 1.125 1.125 1.125h9.75c.621 0 1.125-.504 1.125-1.125V9.375c0-.621-.504-1.125-1.125-1.125H8.25z" />
                            </svg>
                        </span>
                        <div>
                            <p class="text-sm font-bold text-indigo-900 dark:text-indigo-100 leading-tight">
                                {{ $activeReservation->primaryGuest?->full_name }}
                            </p>
                            <p class="text-xs text-indigo-600 dark:text-indigo-400 mt-0.5">
                                {{ $activeReservation->check_in_date->format('M d') }}
                                @if($activeReservation->check_in_time) · {{ \Carbon\Carbon::parse($activeReservation->check_in_time)->format('g:i A') }} @endif
                                <span class="mx-1.5 opacity-40">→</span>
                                {{ $activeReservation->check_out_date->format('M d, Y') }}
                            </p>
                        </div>
                    </div>
                    <div class="text-right shrink-0">
                        <p class="text-xs font-bold text-indigo-700 dark:text-indigo-300">{{ $nights }} {{ Str::plural('night', $nights) }}</p>
                        <p class="text-xs text-indigo-500 dark:text-indigo-400 mt-0.5">{{ $activeReservation->rooms_count }} {{ Str::plural('room', $activeReservation->rooms_count) }}</p>
                    </div>
                </div>

                {{-- ══ SECTION 1: Guest ══ --}}
                <div class="rounded-xl border border-gray-200 dark:border-gray-700 overflow-hidden">
                    <div class="flex items-center gap-2 px-4 py-2.5 bg-gray-50 dark:bg-gray-700/50 border-b border-gray-200 dark:border-gray-700">
                        <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-indigo-500 shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                            <path stroke-linecap="round" stroke-linejoin="round" d="M15.75 6a3.75 3.75 0 11-7.5 0 3.75 3.75 0 017.5 0zM4.501 20.118a7.5 7.5 0 0114.998 0A17.933 17.933 0 0112 21.75c-2.676 0-5.216-.584-7.499-1.632z" />
                        </svg>
                        <span class="text-xs font-bold uppercase tracking-wider text-gray-500 dark:text-gray-400">{{ __('hotel::modules.reservation.guest') }}</span>
                    </div>
                    <div class="px-4 py-3.5 bg-white dark:bg-gray-800 flex items-center gap-3">
                        <span class="inline-flex items-center justify-center w-10 h-10 rounded-full bg-indigo-100 dark:bg-indigo-900/40 text-indigo-700 dark:text-indigo-300 text-sm font-bold shrink-0">
                            {{ collect(explode(' ', $activeReservation->primaryGuest?->full_name ?? ''))->map(fn($w) => strtoupper($w[0] ?? ''))->take(2)->join('') }}
                        </span>
                        <div class="flex-1 min-w-0">
                            <p class="text-sm font-semibold text-gray-900 dark:text-white">{{ $activeReservation->primaryGuest?->full_name }}</p>
                            <div class="flex flex-wrap gap-x-4 gap-y-0.5 mt-0.5">
                                @if($activeReservation->primaryGuest?->phone)
                                <span class="flex items-center gap-1 text-xs text-gray-500 dark:text-gray-400">
                                    <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V21a2 2 0 01-2 2h-1C9.716 23 3 16.284 3 8V5z"/></svg>
                                    {{ $activeReservation->primaryGuest->phone }}
                                </span>
                                @endif
                                @if($activeReservation->primaryGuest?->email)
                                <span class="flex items-center gap-1 text-xs text-gray-500 dark:text-gray-400">
                                    <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/></svg>
                                    {{ $activeReservation->primaryGuest->email }}
                                </span>
                                @endif
                            </div>
                        </div>
                    </div>
                </div>

                {{-- ══ SECTION 2: Stay Details ══ --}}
                <div class="rounded-xl border border-gray-200 dark:border-gray-700 overflow-hidden">
                    <div class="flex items-center gap-2 px-4 py-2.5 bg-gray-50 dark:bg-gray-700/50 border-b border-gray-200 dark:border-gray-700">
                        <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-sky-500 shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                            <path stroke-linecap="round" stroke-linejoin="round" d="M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 012.25-2.25h13.5A2.25 2.25 0 0121 7.5v11.25m-18 0A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75m-18 0v-7.5A2.25 2.25 0 015.25 9h13.5A2.25 2.25 0 0121 9v7.5" />
                        </svg>
                        <span class="text-xs font-bold uppercase tracking-wider text-gray-500 dark:text-gray-400">{{ __('hotel::modules.checkIn.stayDetails') }}</span>
                    </div>
                    <div class="divide-y divide-gray-100 dark:divide-gray-700/60">
                        <div class="flex items-center justify-between px-4 py-3 bg-white dark:bg-gray-800">
                            <span class="text-xs text-gray-500 dark:text-gray-400">{{ __('hotel::modules.reservation.checkIn') }}</span>
                            <span class="text-sm font-medium text-gray-900 dark:text-white">
                                {{ $activeReservation->check_in_date->format('D, M d, Y') }}
                                @if($activeReservation->check_in_time) · {{ \Carbon\Carbon::parse($activeReservation->check_in_time)->format('H:i') }} @endif
                            </span>
                        </div>
                        <div class="flex items-center justify-between px-4 py-3 bg-white dark:bg-gray-800">
                            <span class="text-xs text-gray-500 dark:text-gray-400">{{ __('hotel::modules.reservation.checkOut') }}</span>
                            <span class="text-sm font-medium text-gray-900 dark:text-white">
                                {{ $activeReservation->check_out_date->format('D, M d, Y') }}
                                @if($activeReservation->check_out_time) · {{ \Carbon\Carbon::parse($activeReservation->check_out_time)->format('H:i') }} @endif
                            </span>
                        </div>
                        @if($activeReservation->ratePlan)
                        <div class="flex items-center justify-between px-4 py-3 bg-white dark:bg-gray-800">
                            <span class="text-xs text-gray-500 dark:text-gray-400">{{ __('hotel::modules.reservation.ratePlanLabel') }}</span>
                            <span class="text-sm font-medium text-gray-900 dark:text-white">{{ $activeReservation->ratePlan->name }}</span>
                        </div>
                        @endif
                    </div>
                </div>

                {{-- ══ SECTION 3: Rooms & Pricing ══ --}}
                <div class="rounded-xl border border-gray-200 dark:border-gray-700 overflow-hidden">
                    <div class="flex items-center gap-2 px-4 py-2.5 bg-gray-50 dark:bg-gray-700/50 border-b border-gray-200 dark:border-gray-700">
                        <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-emerald-500 shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                            <path stroke-linecap="round" stroke-linejoin="round" d="M3 9.75L12 3l9 6.75V21a.75.75 0 01-.75.75H15v-6H9v6H3.75A.75.75 0 013 21V9.75z" />
                        </svg>
                        <span class="text-xs font-bold uppercase tracking-wider text-gray-500 dark:text-gray-400">{{ __('hotel::modules.reservation.rooms') }}</span>
                    </div>
                    <div class="divide-y divide-gray-100 dark:divide-gray-700/60 bg-white dark:bg-gray-800">
                        @foreach($activeReservation->reservationRooms as $rr)
                        <div class="flex items-center justify-between px-4 py-3">
                            <div class="flex items-center gap-2">
                                <span class="inline-flex items-center justify-center w-5 h-5 rounded-full bg-emerald-100 dark:bg-emerald-900/30 text-emerald-700 dark:text-emerald-400 text-[10px] font-bold">{{ $rr->quantity }}</span>
                                <span class="text-sm font-medium text-gray-900 dark:text-white">{{ $rr->roomType?->name }}</span>
                            </div>
                            <div class="flex items-center gap-4">
                                <span class="text-xs text-gray-400">{{ currency_format($rr->rate) }} / {{ __('hotel::modules.reservation.night') }}</span>
                                <span class="text-sm font-semibold text-gray-900 dark:text-white">{{ currency_format($rr->total_amount) }}</span>
                            </div>
                        </div>
                        @endforeach
                        <div class="flex items-center justify-between px-4 py-3 bg-gray-50/60 dark:bg-gray-700/30">
                            <span class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">{{ __('hotel::modules.reservation.totalStay') }}</span>
                            <span class="text-base font-bold text-gray-900 dark:text-white">{{ currency_format($activeReservation->total_amount) }}</span>
                        </div>
                    </div>
                </div>

                {{-- ══ SECTION 4: Payments ══ --}}
                <div class="rounded-xl border border-gray-200 dark:border-gray-700 overflow-hidden">
                    <div class="flex items-center gap-2 px-4 py-2.5 bg-gray-50 dark:bg-gray-700/50 border-b border-gray-200 dark:border-gray-700">
                        <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-amber-500 shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                            <path stroke-linecap="round" stroke-linejoin="round" d="M2.25 18.75a60.07 60.07 0 0115.797 2.101c.727.198 1.453-.342 1.453-1.096V18.75M3.75 4.5v.75A.75.75 0 013 6h-.75m0 0v-.375c0-.621.504-1.125 1.125-1.125H20.25M2.25 6v9m18-10.5v.75c0 .414.336.75.75.75h.75m-1.5-1.5h.375c.621 0 1.125.504 1.125 1.125v9.75c0 .621-.504 1.125-1.125 1.125h-.375m1.5-1.5H21a.75.75 0 00-.75.75v.75m0 0H3.75m0 0h-.375a1.125 1.125 0 01-1.125-1.125V15m1.5 1.5v-.75A.75.75 0 003 15h-.75" />
                        </svg>
                        <span class="text-xs font-bold uppercase tracking-wider text-gray-500 dark:text-gray-400">{{ __('hotel::modules.reservation.paymentDetails') }}</span>
                    </div>

                    @php
                        $advancePaid = (float) $activeReservation->advance_paid;
                        $folioPayments = $activeReservation->stays->flatMap(fn($s) => $s->folio ? $s->folio->folioPayments : collect());
                        $advanceAlreadyApplied = $folioPayments->contains(fn($p) => ($p->payment_method ?? null) === 'advance');
                        $totalPaid = $advanceAlreadyApplied ? $folioPayments->sum('amount') : ($advancePaid + $folioPayments->sum('amount'));
                        $balanceDue = (float) $activeReservation->total_amount - $totalPaid;
                    @endphp

                    <div class="bg-white dark:bg-gray-800">
                        @if($advancePaid > 0 || $folioPayments->isNotEmpty())
                        <div class="overflow-x-auto">
                            <table class="min-w-full text-sm">
                                <thead class="bg-gray-50/60 dark:bg-gray-700/30">
                                    <tr>
                                        <th class="px-4 py-2.5 text-left text-[10px] font-semibold uppercase tracking-wide text-gray-400 dark:text-gray-500">{{ __('hotel::modules.reservation.date') }}</th>
                                        <th class="px-4 py-2.5 text-left text-[10px] font-semibold uppercase tracking-wide text-gray-400 dark:text-gray-500">{{ __('hotel::modules.reservation.method') }}</th>
                                        <th class="px-4 py-2.5 text-left text-[10px] font-semibold uppercase tracking-wide text-gray-400 dark:text-gray-500">{{ __('hotel::modules.reservation.reference') }}</th>
                                        <th class="px-4 py-2.5 text-right text-[10px] font-semibold uppercase tracking-wide text-gray-400 dark:text-gray-500">{{ __('hotel::modules.reservation.amount') }}</th>
                                    </tr>
                                </thead>
                                <tbody class="divide-y divide-gray-100 dark:divide-gray-700/60">
                                    @if($advancePaid > 0)
                                    <tr>
                                        <td class="px-4 py-2.5 text-xs text-gray-500 dark:text-gray-400">{{ $activeReservation->created_at->format('M d, Y') }}</td>
                                        <td class="px-4 py-2.5 text-xs text-gray-800 dark:text-gray-200">{{ __('hotel::modules.reservation.advancePaid') }}</td>
                                        <td class="px-4 py-2.5 text-xs text-gray-400">—</td>
                                        <td class="px-4 py-2.5 text-right text-xs font-semibold text-emerald-600 dark:text-emerald-400">{{ currency_format($advancePaid) }}</td>
                                    </tr>
                                    @endif
                                    @foreach($folioPayments as $payment)
                                    <tr>
                                        <td class="px-4 py-2.5 text-xs text-gray-500 dark:text-gray-400">{{ $payment->created_at->format('M d, Y H:i') }}</td>
                                        <td class="px-4 py-2.5 text-xs text-gray-800 dark:text-gray-200 capitalize">{{ $payment->payment_method }}</td>
                                        <td class="px-4 py-2.5 text-xs text-gray-400">{{ $payment->transaction_reference ?? '—' }}</td>
                                        <td class="px-4 py-2.5 text-right text-xs font-semibold text-emerald-600 dark:text-emerald-400">{{ currency_format($payment->amount) }}</td>
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                        @else
                        <p class="px-4 py-3.5 text-xs text-gray-400 dark:text-gray-500">{{ __('hotel::modules.reservation.noPaymentsRecorded') }}</p>
                        @endif

                        {{-- Balance summary strip --}}
                        <div class="flex items-center justify-between px-4 py-3 {{ $balanceDue > 0 ? 'bg-amber-50 border-t border-amber-200 dark:bg-amber-900/20 dark:border-amber-700/50' : 'bg-emerald-50 border-t border-emerald-200 dark:bg-emerald-900/20 dark:border-emerald-700/50' }}">
                            <div class="space-y-0.5">
                                <p class="text-[10px] uppercase tracking-wide font-semibold {{ $balanceDue > 0 ? 'text-amber-500 dark:text-amber-400' : 'text-emerald-500 dark:text-emerald-400' }}">{{ __('hotel::modules.reservation.totalPaid') }}</p>
                                <p class="text-sm font-semibold text-gray-900 dark:text-white">{{ currency_format($totalPaid) }}</p>
                            </div>
                            <div class="text-right">
                                <p class="text-[10px] uppercase tracking-wide font-semibold {{ $balanceDue > 0 ? 'text-amber-500 dark:text-amber-400' : 'text-emerald-500 dark:text-emerald-400' }}">{{ __('hotel::modules.reservation.balanceDue') }}</p>
                                <p class="text-base font-bold {{ $balanceDue > 0 ? 'text-amber-700 dark:text-amber-400' : 'text-emerald-600 dark:text-emerald-400' }}">
                                    {{ $balanceDue > 0 ? currency_format($balanceDue) : '✓ ' . currency_format(0) }}
                                </p>
                            </div>
                        </div>
                    </div>
                </div>

                {{-- ══ Special Requests ══ --}}
                @if($activeReservation->special_requests)
                <div class="rounded-xl border border-amber-200 dark:border-amber-700/50 overflow-hidden">
                    <div class="flex items-center gap-2 px-4 py-2.5 bg-amber-50 dark:bg-amber-900/20 border-b border-amber-200 dark:border-amber-700/50">
                        <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-amber-500 shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                            <path stroke-linecap="round" stroke-linejoin="round" d="M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z" />
                        </svg>
                        <span class="text-xs font-bold uppercase tracking-wider text-amber-700 dark:text-amber-400">{{ __('hotel::modules.reservation.specialRequestsLabel') }}</span>
                    </div>
                    <div class="px-4 py-3.5 bg-white dark:bg-gray-800">
                        <p class="text-sm text-gray-700 dark:text-gray-300">{{ $activeReservation->special_requests }}</p>
                    </div>
                </div>
                @endif

            </div>
            @endif
        </x-slot>

        <x-slot name="footer">
            <div class="flex justify-end gap-2">
                @if($activeReservation && in_array($activeReservation->status->value, ['tentative', 'confirmed']) && user_can('Update Hotel Reservation'))
                <x-button wire:click="openEditReservationForm({{ $activeReservation->id }})">{{ __('hotel::modules.reservation.edit') }}</x-button>
                @endif
                <x-secondary-button wire:click="closeViewReservationModal">{{ __('app.close') }}</x-secondary-button>
            </div>
        </x-slot>
    </x-right-modal>

    {{-- Edit Reservation Form --}}
    <x-right-modal wire:model.live="showEditReservationFormModal">
        <x-slot name="title">{{ __('hotel::modules.reservation.editReservation') }}</x-slot>
        <x-slot name="content">
            @if ($showEditReservationFormModal && $activeReservationForEdit)
                <livewire:hotel::forms.edit-reservation :reservation-id="$activeReservationForEdit" :key="'edit-reservation-'.$activeReservationForEdit" />
            @endif
        </x-slot>
        <x-slot name="footer">
            <x-secondary-button wire:click="closeEditReservationForm">{{ __('app.close') }}</x-secondary-button>
        </x-slot>
    </x-right-modal>

    {{-- Cancel Confirmation --}}
    @if ($activeReservation)
    <x-confirmation-modal wire:model="confirmCancelReservationModal">
        <x-slot name="title">{{ __('hotel::modules.reservation.cancelReservation') }}</x-slot>
        <x-slot name="content">{{ __('hotel::modules.reservation.cancelReservationMessage', ['number' => $activeReservation->reservation_number]) }}</x-slot>
        <x-slot name="footer">
            <x-secondary-button wire:click="$toggle('confirmCancelReservationModal')">{{ __('app.cancel') }}</x-secondary-button>
            <x-danger-button class="ml-3" wire:click="cancelReservation({{ $activeReservation->id }})">{{ __('hotel::modules.reservation.confirm') }}</x-danger-button>
        </x-slot>
    </x-confirmation-modal>
    @endif

</div>
