{{-- 블루 프로페셔널 견적서 템플릿 --}}
<style>
    .blue { font-family: 'Pretendard', sans-serif; color: #1e293b; }
    .blue .doc-table { width: 100%; border-collapse: collapse; }
    .blue .doc-table th, .blue .doc-table td { padding: 7px 10px; font-size: 13px; border: 1px solid #cbd5e1; }
    .blue .doc-table thead th { background: linear-gradient(135deg, #1e40af, #2563eb); color: #fff; border-color: #1e40af; font-weight: 600; }
    .blue .doc-table tbody tr:nth-child(even) { background-color: #f0f5ff; }
    .blue .doc-table tfoot td, .blue .doc-table tfoot th { border-color: #cbd5e1; }
    .blue .header-bar { background: linear-gradient(135deg, #1e40af, #3b82f6); color: #fff; padding: 20px 28px; border-radius: 0; margin: -18mm -22mm 24px; width: calc(100% + 44mm); }
    .blue .seal-box { display: inline-block; width: 60px; height: 60px; border: 2px solid #1e40af; border-radius: 50%; text-align: center; line-height: 56px; color: #1e40af; font-weight: 700; font-size: 16px; }

    @media print {
        .blue .header-bar { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
        .blue .doc-table thead th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    }
</style>

<div class="blue document-page max-w-[210mm] mx-auto my-8 bg-white shadow-lg" style="padding: 18mm 22mm;">

    {{-- 블루 헤더 바 --}}
    <div class="header-bar" style="display: flex; justify-content: space-between; align-items: center;">
        <div>
            <h1 style="font-size: 28px; font-weight: 700; letter-spacing: 0.4em; margin: 0;">견 적 서</h1>
            <p style="font-size: 11px; opacity: 0.8; margin-top: 4px;">QUOTATION</p>
        </div>
        <div style="text-align: right; font-size: 12px; opacity: 0.9;">
            <p>{{ $quotationNo }}</p>
            <p>{{ $quotation->created_at->format('Y. m. d') }}</p>
        </div>
    </div>

    {{-- 견적 정보 --}}
    <div style="display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 12px; color: #64748b;">
        <p>유효기간: 견적일로부터 30일</p>
    </div>

    {{-- 수신 / 공급자 --}}
    <table class="doc-table mb-6">
        <colgroup>
            <col style="width: 8%;"><col style="width: 42%;"><col style="width: 8%;"><col style="width: 42%;">
        </colgroup>
        <thead>
            <tr>
                <th colspan="2" class="text-center">수 신</th>
                <th colspan="2" class="text-center">공 급 자</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td style="font-weight:600; background:#f8fafc;">귀사명</td><td>{{ $quotation->title }}</td>
                <td style="font-weight:600; background:#f8fafc;">상 호</td><td>(주)코드브릿지엑스</td>
            </tr>
            <tr>
                <td style="font-weight:600; background:#f8fafc;">업 종</td><td>{{ $company['industry'] ?? '-' }}</td>
                <td style="font-weight:600; background:#f8fafc;">대 표</td><td>이의찬</td>
            </tr>
            <tr>
                <td style="font-weight:600; background:#f8fafc;">규 모</td><td>{{ $company['scale'] ?? '-' }}</td>
                <td style="font-weight:600; background:#f8fafc;">주 소</td><td>인천 남동구 남동대로 215번길 30</td>
            </tr>
            <tr>
                <td style="font-weight:600; background:#f8fafc;">현재시스템</td><td>{{ !empty($company['current_systems']) ? implode(', ', $company['current_systems']) : '-' }}</td>
                <td style="font-weight:600; background:#f8fafc;">연락처</td><td>032-123-4567</td>
            </tr>
        </tbody>
    </table>

    {{-- 합계 --}}
    <div style="margin-bottom: 24px; padding: 16px 20px; border: 2px solid #2563eb; border-radius: 8px; text-align: center; background: linear-gradient(to right, #eff6ff, #ffffff);">
        <p style="font-size: 12px; color: #64748b; margin-bottom: 6px;">아래와 같이 견적합니다.</p>
        <p style="font-size: 20px; font-weight: 700; color: #1e40af;">
            합계금액: 금 {{ $devTotalKorean }}원정
            <span style="font-size: 14px; font-weight: 400; color: #475569;">(&#8361;{{ number_format($devSubtotal) }})</span>
        </p>
        <p style="font-size: 11px; color: #94a3b8; margin-top: 4px;">※ 부가가치세 별도 / 월 구독료 {{ number_format($monthlySubtotal) }}원 별도</p>
    </div>

    {{-- 품목 --}}
    <table class="doc-table" style="margin-bottom: 24px;">
        <colgroup>
            <col style="width: 5%;"><col style="width: 7%;"><col style="width: 20%;"><col style="width: 33%;"><col style="width: 17.5%;"><col style="width: 17.5%;">
        </colgroup>
        <thead>
            <tr>
                <th class="text-center">No</th><th class="text-center">구분</th><th class="text-center">품 목</th>
                <th class="text-center">설 명</th><th class="text-center">개발비 (원)</th><th class="text-center">월 구독료 (원)</th>
            </tr>
        </thead>
        <tbody>
            @foreach($sortedItems as $index => $item)
                <tr>
                    <td class="text-center">{{ $index + 1 }}</td>
                    <td class="text-center">
                        <span style="font-size: 11px; padding: 1px 6px; border-radius: 3px; {{ $item->is_required ? 'background:#dbeafe;color:#1e40af;' : 'background:#f1f5f9;color:#64748b;' }}">
                            {{ $item->is_required ? '필수' : '선택' }}
                        </span>
                    </td>
                    <td style="font-weight: 500;">{{ $item->module_name }}</td>
                    <td style="font-size: 12px; color: #64748b;">{{ Str::limit($item->reason, 80) }}</td>
                    <td class="text-right">{{ number_format((int) $item->dev_cost) }}</td>
                    <td class="text-right">{{ number_format((int) $item->monthly_fee) }}</td>
                </tr>
            @endforeach
        </tbody>
        <tfoot>
            <tr>
                <th colspan="4" class="text-right">소 계</th>
                <td class="text-right font-bold">{{ number_format($devSubtotal) }}</td>
                <td class="text-right font-bold">{{ number_format($monthlySubtotal) }}</td>
            </tr>
            <tr>
                <th colspan="4" class="text-right">부가세 (10%)</th>
                <td class="text-right">{{ number_format($devVat) }}</td>
                <td class="text-right">{{ number_format($monthlyVat) }}</td>
            </tr>
            <tr style="background: linear-gradient(to right, #eff6ff, #dbeafe); -webkit-print-color-adjust: exact; print-color-adjust: exact;">
                <th colspan="4" class="text-right" style="font-size: 15px; color: #1e40af;">합 계</th>
                <td class="text-right font-bold" style="font-size: 15px; color: #1e40af;">{{ number_format($devTotal) }}</td>
                <td class="text-right font-bold" style="font-size: 15px; color: #1e40af;">{{ number_format($monthlyTotal) }}</td>
            </tr>
        </tfoot>
    </table>

    {{-- 비고 --}}
    <div style="margin-bottom: 28px;">
        <table class="doc-table">
            <thead><tr><th class="text-left" style="font-size: 13px;">비 고</th></tr></thead>
            <tbody>
                <tr>
                    <td style="padding: 12px 16px;">
                        <ol style="list-style: decimal; padding-left: 18px; font-size: 12px; color: #475569; line-height: 1.8;">
                            <li>상기 금액은 부가가치세 별도입니다.</li>
                            <li>개발비 납부 조건: 계약 시 50%, 완료 시 50% 분할 납부</li>
                            <li>월 구독료: 서비스 오픈일부터 과금 (월 {{ number_format($monthlyTotal) }}원, VAT 포함)</li>
                            @if($estimatedMonths)
                                <li>예상 구축 기간: {{ $estimatedMonths }}개월</li>
                            @endif
                            <li>본 견적서의 유효기간은 견적일로부터 30일입니다.</li>
                            <li>세부 사항은 별도 협의를 통해 조정될 수 있습니다.</li>
                        </ol>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>

    {{-- 서명 --}}
    <div class="flex justify-end items-center gap-6 mt-12">
        <div class="text-right">
            <p style="font-size: 16px; font-weight: 700; color: #1e40af;">(주)코드브릿지엑스</p>
            <p style="font-size: 12px; color: #64748b; margin-top: 4px;">대표이사 이 의 찬</p>
        </div>
        <div class="seal-box">(인)</div>
    </div>

</div>
