<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Quote {{ $quote->number }}</title>
    <style>
        body {
            font-family: 'Helvetica', Arial, sans-serif;
            font-size: 12px;
            color: #333;
            margin: 40px;
        }
        .company-name {
            font-size: 24px;
            font-weight: bold;
            color: #1d4ed8;
        }
        .quote-title {
            font-size: 28px;
            font-weight: bold;
            text-align: right;
            color: #1d4ed8;
        }
        .quote-meta {
            text-align: right;
            margin-top: 8px;
        }
        .meta-label {
            color: #666;
        }
        .address-label {
            font-weight: bold;
            font-size: 11px;
            text-transform: uppercase;
            color: #666;
            margin-bottom: 5px;
        }
        table.items {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        table.items th {
            background-color: #1d4ed8;
            color: white;
            padding: 8px 12px;
            text-align: left;
            font-size: 11px;
            text-transform: uppercase;
        }
        table.items th.text-right {
            text-align: right;
        }
        table.items td {
            padding: 8px 12px;
            border-bottom: 1px solid #eee;
        }
        table.items tr:nth-child(even) {
            background-color: #f9f9f9;
        }
        .totals {
            width: 300px;
            margin-left: auto;
        }
        .totals table {
            width: 100%;
        }
        .totals td {
            padding: 4px 8px;
        }
        .totals .total-row td {
            font-size: 16px;
            font-weight: bold;
            border-top: 2px solid #1d4ed8;
            padding-top: 8px;
        }
        .status-badge {
            display: inline-block;
            padding: 4px 12px;
            border-radius: 4px;
            font-size: 11px;
            font-weight: bold;
            text-transform: uppercase;
            color: white;
        }
        .status-draft {
            background-color: #82868b;
        }
        .status-sent {
            background-color: #ff9f43;
        }
        .status-accepted {
            background-color: #28c76f;
        }
        .status-rejected {
            background-color: #ea5455;
        }
        .status-expired {
            background-color: #82868b;
        }
        .notes {
            margin-top: 20px;
            padding: 12px;
            background-color: #f8f9fa;
            border-left: 3px solid #1d4ed8;
            font-size: 11px;
        }
        .notes-label {
            font-weight: bold;
            margin-bottom: 4px;
        }
        .footer {
            margin-top: 40px;
            text-align: center;
            font-size: 10px;
            color: #999;
            border-top: 1px solid #eee;
            padding-top: 15px;
        }
    </style>
</head>
<body>
    {{-- Header --}}
    <table width="100%" style="margin-bottom: 30px;">
        <tr>
            <td width="50%" style="vertical-align: top;">
                <div class="company-name">EZSCALE</div>
                <div style="margin-top: 5px; color: #666;">Cloud Infrastructure Services</div>
            </td>
            <td width="50%" style="vertical-align: top; text-align: right;">
                <div class="quote-title">QUOTE</div>
                <div class="quote-meta">
                    <div><span class="meta-label">Quote #:</span> {{ $quote->number }}</div>
                    <div><span class="meta-label">Date:</span> {{ $quote->created_at->format('M d, Y') }}</div>
                    @if($quote->valid_until)
                        <div><span class="meta-label">Valid Until:</span> {{ $quote->valid_until->format('M d, Y') }}</div>
                    @endif
                    <div style="margin-top: 5px;">
                        <span class="status-badge status-{{ strtolower($quote->status) }}">{{ ucfirst($quote->status) }}</span>
                    </div>
                </div>
            </td>
        </tr>
    </table>

    {{-- Recipient / From --}}
    <table width="100%" style="margin-bottom: 30px;">
        <tr>
            <td width="50%" style="vertical-align: top;">
                <div class="address-label">Prepared For</div>
                @if($quote->user)
                    <div><strong>{{ $quote->user->name }}</strong></div>
                    <div>{{ $quote->user->email }}</div>
                    @if($quote->user->company)<div>{{ $quote->user->company }}</div>@endif
                @else
                    @if($quote->prospect_name)<div><strong>{{ $quote->prospect_name }}</strong></div>@endif
                    @if($quote->prospect_email)<div>{{ $quote->prospect_email }}</div>@endif
                @endif
            </td>
            <td width="50%" style="vertical-align: top;">
                <div class="address-label">From</div>
                <div><strong>EZSCALE</strong></div>
                <div>support@ezscale.cloud</div>
                @if($quote->creator)
                    <div style="margin-top: 5px; color: #666;">
                        Prepared by: {{ $quote->creator->name }}
                    </div>
                @endif
            </td>
        </tr>
    </table>

    {{-- Line Items --}}
    <table class="items">
        <thead>
            <tr>
                <th>Description</th>
                <th class="text-right" style="text-align: center;">Qty</th>
                <th class="text-right" style="text-align: right;">Unit Price</th>
                <th class="text-right" style="text-align: right;">Total</th>
            </tr>
        </thead>
        <tbody>
            @foreach($quote->items as $item)
                <tr>
                    <td>{{ $item['description'] }}</td>
                    <td style="text-align: center;">{{ $item['quantity'] }}</td>
                    <td style="text-align: right;">${{ number_format((float) $item['unit_price'], 2) }}</td>
                    <td style="text-align: right;">${{ number_format((float) $item['unit_price'] * (int) $item['quantity'], 2) }}</td>
                </tr>
            @endforeach
        </tbody>
    </table>

    {{-- Totals --}}
    <div class="totals">
        <table>
            <tr>
                <td>Subtotal</td>
                <td style="text-align: right;">${{ number_format((float) $quote->subtotal, 2) }}</td>
            </tr>
            @if((float) $quote->tax > 0)
                <tr>
                    <td>Tax</td>
                    <td style="text-align: right;">${{ number_format((float) $quote->tax, 2) }}</td>
                </tr>
            @endif
            <tr class="total-row">
                <td>Total ({{ strtoupper($quote->currency) }})</td>
                <td style="text-align: right;">${{ number_format((float) $quote->total, 2) }}</td>
            </tr>
        </table>
    </div>

    {{-- Notes --}}
    @if($quote->notes)
        <div class="notes">
            <div class="notes-label">Notes</div>
            {{ $quote->notes }}
        </div>
    @endif

    {{-- Acceptance --}}
    @if($quote->status === 'accepted' && $quote->accepted_at)
        <div style="margin-top: 20px; padding: 8px 12px; background-color: #d4edda; border-left: 3px solid #28c76f;">
            <strong>Accepted</strong> on {{ $quote->accepted_at->format('M d, Y') }}
        </div>
    @endif

    {{-- Footer --}}
    <div class="footer">
        <p>This quote is valid {{ $quote->valid_until ? 'until '.$quote->valid_until->format('M d, Y') : 'for 30 days from the date issued' }}.</p>
        <p>EZSCALE &mdash; Cloud Infrastructure Services &mdash; support@ezscale.cloud</p>
    </div>
</body>
</html>
