@if(empty($usageList))
    <div class="p-12 text-center">
        <svg class="mx-auto h-12 w-12 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
        </svg>
        <h3 class="mt-2 text-sm font-medium text-gray-900">조회된 사용량이 없습니다</h3>
        <p class="mt-1 text-sm text-gray-500">조회 기간을 확인하거나, 활성 회원사가 있는지 확인해주세요.</p>
    </div>
@else
    <div class="flex-1 overflow-auto">
        <table class="min-w-full divide-y divide-gray-200">
            <thead class="bg-gray-50 sticky top-0 z-10">
                <tr>
                    @if($allTenants ?? false)
                    <th scope="col" class="px-4 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider w-16">
                        T-ID
                    </th>
                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                        테넌트
                    </th>
                    @endif
                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                        사업자번호
                    </th>
                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                        상호명
                    </th>
                    <th scope="col" class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
                        세금계산서<span class="text-gray-400 font-normal">(건)</span>
                    </th>
                    <th scope="col" class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
                        등록계좌<span class="text-gray-400 font-normal">(개)</span>
                    </th>
                    <th scope="col" class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
                        등록카드<span class="text-gray-400 font-normal">(장)</span>
                    </th>
                    <th scope="col" class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
                        홈텍스
                    </th>
                    <th scope="col" class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
                        과금액
                    </th>
                    <th scope="col" class="px-6 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider w-20">
                        상세
                    </th>
                </tr>
            </thead>
            <tbody class="bg-white divide-y divide-gray-200">
                @foreach($usageList as $usage)
                    <tr class="hover:bg-gray-50 transition-colors group">
                        @if($allTenants ?? false)
                        <td class="px-4 py-4 whitespace-nowrap text-center">
                            <span class="inline-flex items-center justify-center w-8 h-8 rounded-full text-xs font-bold bg-indigo-100 text-indigo-700">
                                {{ $usage['tenant_id'] }}
                            </span>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-indigo-100 text-indigo-800">
                                {{ $usage['tenant_name'] }}
                            </span>
                        </td>
                        @endif
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="text-sm font-mono text-gray-500">{{ $usage['formatted_biz_no'] }}</div>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap">
                            <div class="text-sm font-medium text-gray-900">{{ $usage['corp_name'] }}</div>
                            <div class="text-xs text-gray-400">{{ $usage['barobill_id'] }}</div>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-right">
                            <span class="text-sm font-medium {{ $usage['tax_invoice_count'] > 0 ? 'text-purple-600' : 'text-gray-400' }}">
                                {{ number_format($usage['tax_invoice_count']) }}
                            </span>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-right">
                            <span class="text-sm font-medium {{ $usage['bank_account_count'] > 0 ? 'text-green-600' : 'text-gray-400' }}">
                                {{ number_format($usage['bank_account_count']) }}
                            </span>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-right">
                            <span class="text-sm font-medium {{ $usage['card_count'] > 0 ? 'text-indigo-600' : 'text-gray-400' }}">
                                {{ number_format($usage['card_count']) }}
                            </span>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-right">
                            <span class="text-sm font-medium {{ $usage['hometax_count'] > 0 ? 'text-orange-600' : 'text-gray-400' }}">
                                {{ number_format($usage['hometax_count']) }}
                            </span>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-right">
                            <span class="text-sm font-bold {{ $usage['total_amount'] > 0 ? 'text-gray-900' : 'text-gray-400' }}">
                                {{ number_format($usage['total_amount']) }}
                            </span>
                        </td>
                        <td class="px-6 py-4 whitespace-nowrap text-center">
                            <button
                                type="button"
                                onclick="UsageDetail.show({{ $usage['member_id'] }}, '{{ addslashes($usage['corp_name']) }}')"
                                class="p-2 text-blue-600 hover:bg-blue-50 rounded-lg opacity-30 group-hover:opacity-100 transition"
                                title="상세보기"
                            >
                                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
                                </svg>
                            </button>
                        </td>
                    </tr>
                @endforeach
            </tbody>
            <!-- 합계 행 -->
            <tfoot class="bg-gray-100 border-t-2 border-gray-300">
                <tr>
                    @if($allTenants ?? false)
                    <td class="px-4 py-4" colspan="2"></td>
                    @endif
                    <td class="px-6 py-4" colspan="2">
                        <span class="text-sm font-bold text-gray-700">합계</span>
                    </td>
                    <td class="px-6 py-4 text-right">
                        <span class="text-sm font-bold text-purple-600">{{ number_format($totalRow['tax_invoice_count']) }}</span>
                    </td>
                    <td class="px-6 py-4 text-right">
                        <span class="text-sm font-bold text-green-600">{{ number_format($totalRow['bank_account_count']) }}</span>
                    </td>
                    <td class="px-6 py-4 text-right">
                        <span class="text-sm font-bold text-indigo-600">{{ number_format($totalRow['card_count']) }}</span>
                    </td>
                    <td class="px-6 py-4 text-right">
                        <span class="text-sm font-bold text-orange-600">{{ number_format($totalRow['hometax_count']) }}</span>
                    </td>
                    <td class="px-6 py-4 text-right">
                        <span class="text-lg font-bold text-gray-900">{{ number_format($totalRow['total_amount']) }}원</span>
                    </td>
                    <td class="px-6 py-4"></td>
                </tr>
            </tfoot>
        </table>
    </div>
@endif
