<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Land Feasibility Report #{{ str_pad($report->id, 5, '0', STR_PAD_LEFT) }}</title>
<style>
    * { box-sizing: border-box; margin: 0; padding: 0; }
    body { font-family: DejaVu Sans, Arial, sans-serif; font-size: 11px; color: #1a1a2e; background: #fff; line-height: 1.5; }

    /* Page frame */
    .page { padding: 28px 32px; }

    /* Header strip */
    .header { background: #1a237e; color: #fff; padding: 18px 24px; border-radius: 6px; margin-bottom: 20px; display: table; width: 100%; }
    .header-left { display: table-cell; vertical-align: middle; }
    .header-right { display: table-cell; vertical-align: middle; text-align: right; }
    .logo-text { font-size: 18px; font-weight: 700; letter-spacing: -.3px; }
    .logo-text span { color: #7986cb; }
    .report-meta { font-size: 10px; color: #c5cae9; margin-top: 2px; }
    .score-box { display: inline-block; background: {{ $report->feasibility_score >= 70 ? '#2e7d32' : ($report->feasibility_score >= 40 ? '#e65100' : '#b71c1c') }}; color: #fff; padding: 8px 16px; border-radius: 6px; text-align: center; }
    .score-num { font-size: 28px; font-weight: 700; line-height: 1; }
    .score-lbl { font-size: 9px; text-transform: uppercase; letter-spacing: .08em; }

    /* Section title */
    .section-title { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: #1a237e; border-bottom: 2px solid #1a237e; padding-bottom: 4px; margin: 18px 0 10px; }

    /* Two-column grid via tables */
    .grid-2 { width: 100%; border-collapse: collapse; }
    .grid-2 td { width: 50%; vertical-align: top; padding: 0 6px 0 0; }
    .grid-2 td:last-child { padding: 0 0 0 6px; }
    .grid-3 { width: 100%; border-collapse: collapse; }
    .grid-3 td { width: 33.33%; vertical-align: top; padding: 0 4px; }

    /* Data card */
    .data-card { background: #f5f6fa; border: 1px solid #e0e0e0; border-radius: 5px; padding: 10px 12px; margin-bottom: 10px; }
    .data-card-label { font-size: 9px; text-transform: uppercase; letter-spacing: .06em; color: #757575; margin-bottom: 2px; }
    .data-card-value { font-size: 15px; font-weight: 700; color: #0d0d35; }
    .data-card-unit { font-size: 9px; color: #9e9e9e; }

    /* Key-value rows */
    .kv-table { width: 100%; border-collapse: collapse; }
    .kv-table tr { border-bottom: 1px solid #f0f0f0; }
    .kv-table td { padding: 5px 0; font-size: 11px; }
    .kv-table .key { color: #616161; width: 45%; }
    .kv-table .val { color: #0d0d35; font-weight: 600; }

    /* Badges */
    .badge { display: inline-block; padding: 2px 7px; border-radius: 3px; font-size: 9px; font-weight: 700; }
    .badge-green  { background: #e8f5e9; color: #2e7d32; }
    .badge-yellow { background: #fff8e1; color: #e65100; }
    .badge-red    { background: #ffebee; color: #b71c1c; }
    .badge-blue   { background: #e3f2fd; color: #1565c0; }

    /* Tags */
    .tag { display: inline-block; background: #e8eaf6; color: #3949ab; padding: 3px 8px; border-radius: 3px; font-size: 9px; margin: 2px 3px 2px 0; }

    /* Warning box */
    .warning-box { background: #fff3e0; border-left: 4px solid #e65100; padding: 8px 12px; border-radius: 0 4px 4px 0; margin-bottom: 10px; font-size: 10px; color: #bf360c; }

    /* Log entries */
    .log-entry { font-family: 'Courier New', monospace; font-size: 9px; color: #546e7a; border-bottom: 1px solid #eceff1; padding: 3px 0; }

    /* Footer */
    .footer { margin-top: 24px; padding-top: 10px; border-top: 1px solid #e0e0e0; font-size: 9px; color: #9e9e9e; text-align: center; }

    /* Score bar */
    .score-bar-bg { width: 100%; height: 8px; background: #e0e0e0; border-radius: 4px; overflow: hidden; margin: 4px 0 2px; }
    .score-bar-fill { height: 8px; border-radius: 4px; background: {{ $report->feasibility_score >= 70 ? '#2e7d32' : ($report->feasibility_score >= 40 ? '#e65100' : '#b71c1c') }}; width: {{ $report->feasibility_score ?? 0 }}%; }
</style>
</head>
<body>
<div class="page">

    <!-- HEADER -->
    <div class="header">
        <div class="header-left">
            <div class="logo-text">Land<span>Feasibility</span>.in</div>
            <div class="report-meta">
                Report #{{ str_pad($report->id, 5, '0', STR_PAD_LEFT) }}
                &nbsp;|&nbsp; Generated {{ now()->format('d M Y, H:i') }}
                @if($report->zone) &nbsp;|&nbsp; Zone: {{ $report->zone->name }} @endif
            </div>
        </div>
        <div class="header-right">
            <div class="score-box">
                <div class="score-num">{{ $report->feasibility_score ?? '—' }}</div>
                <div class="score-lbl">{{ $report->feasibility_score >= 70 ? 'Feasible' : ($report->feasibility_score >= 40 ? 'Marginal' : 'Challenging') }}</div>
            </div>
        </div>
    </div>

    <!-- LOCATION & ZONE -->
    <div class="section-title">Location &amp; Zone</div>
    <table class="grid-2">
        <tr>
            <td>
                <table class="kv-table">
                    <tr><td class="key">Address</td><td class="val">{{ $report->address ?? '—' }}</td></tr>
                    <tr><td class="key">Coordinates</td><td class="val" style="font-family: 'Courier New', monospace; font-size:10px;">{{ $report->latitude }}, {{ $report->longitude }}</td></tr>
                    <tr><td class="key">State</td><td class="val">{{ $report->state?->name ?? '—' }}</td></tr>
                    <tr><td class="key">City</td><td class="val">{{ $report->city?->name ?? '—' }}</td></tr>
                </table>
            </td>
            <td>
                <table class="kv-table">
                    <tr><td class="key">Zone</td><td class="val">{{ $report->zone?->name ?? '—' }}</td></tr>
                    <tr><td class="key">Road Width</td><td class="val">{{ $report->road_width_m ? $report->road_width_m.' m' : '—' }}</td></tr>
                    <tr><td class="key">Regulation</td><td class="val">{{ $report->zoneRule?->rule_source ?? '—' }}</td></tr>
                    <tr><td class="key">Status</td><td class="val"><span class="badge badge-blue">{{ ucfirst($report->status) }}</span></td></tr>
                </table>
            </td>
        </tr>
    </table>

    <!-- FEASIBILITY SCORE BAR -->
    <div style="margin: 14px 0 0;">
        <div style="display: table; width: 100%;">
            <div style="display: table-cell; width: 60px; font-size: 10px; color: #616161; vertical-align: middle;">Score</div>
            <div style="display: table-cell; vertical-align: middle;">
                <div class="score-bar-bg"><div class="score-bar-fill"></div></div>
            </div>
            <div style="display: table-cell; width: 50px; text-align: right; font-size: 13px; font-weight: 700; color: {{ $report->feasibility_score >= 70 ? '#2e7d32' : ($report->feasibility_score >= 40 ? '#e65100' : '#b71c1c') }}; vertical-align: middle;">{{ $report->feasibility_score ?? '—' }}/100</div>
        </div>
    </div>

    <!-- CALCULATION RESULTS -->
    <div class="section-title">Calculation Results</div>
    <table class="grid-3" style="margin-bottom:10px;">
        <tr>
            <td>
                <div class="data-card">
                    <div class="data-card-label">Plot Area</div>
                    <div class="data-card-value">{{ $report->plot_area_sqm ? number_format($report->plot_area_sqm) : '—' }}</div>
                    <div class="data-card-unit">sq.m</div>
                </div>
            </td>
            <td>
                <div class="data-card">
                    <div class="data-card-label">Max Buildable Area</div>
                    <div class="data-card-value">{{ $report->max_buildable_area_sqm ? number_format($report->max_buildable_area_sqm) : '—' }}</div>
                    <div class="data-card-unit">sq.m</div>
                </div>
            </td>
            <td>
                <div class="data-card">
                    <div class="data-card-label">Ground Coverage</div>
                    <div class="data-card-value">{{ $report->ground_coverage_sqm ? number_format($report->ground_coverage_sqm) : '—' }}</div>
                    <div class="data-card-unit">sq.m</div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="data-card">
                    <div class="data-card-label">Max Floors</div>
                    <div class="data-card-value">{{ $report->max_floors ?? '—' }}</div>
                    <div class="data-card-unit">floors</div>
                </div>
            </td>
            <td>
                <div class="data-card">
                    <div class="data-card-label">FAR / FSI</div>
                    <div class="data-card-value">{{ $report->zoneRule?->max_far ?? '—' }}</div>
                    <div class="data-card-unit">ratio</div>
                </div>
            </td>
            <td>
                <div class="data-card">
                    <div class="data-card-label">Max Height</div>
                    <div class="data-card-value">{{ $report->zoneRule?->max_height_m ?? '—' }}</div>
                    <div class="data-card-unit">metres</div>
                </div>
            </td>
        </tr>
    </table>

    <!-- SETBACKS & PERMITTED USES -->
    <table class="grid-2">
        <tr>
            <td>
                @if($report->setback_summary)
                <div class="section-title">Required Setbacks</div>
                <table class="kv-table">
                    @foreach($report->setback_summary as $dir => $val)
                    <tr>
                        <td class="key">{{ ucfirst($dir) }}</td>
                        <td class="val">{{ $val }} m</td>
                    </tr>
                    @endforeach
                </table>
                @endif
            </td>
            <td>
                @if($report->permitted_uses && count($report->permitted_uses))
                <div class="section-title">Permitted Uses</div>
                @foreach($report->permitted_uses as $use)
                    <span class="tag">{{ $use }}</span>
                @endforeach
                @endif
            </td>
        </tr>
    </table>

    <!-- RESTRICTION FLAGS -->
    @if($report->restriction_flags && count(array_filter($report->restriction_flags ?? [])))
    <div class="section-title">Restriction Flags</div>
    @foreach($report->restriction_flags ?? [] as $flag => $active)
        @if($active)
        <div class="warning-box">⚠ {{ str_replace('_', ' ', ucfirst($flag)) }}</div>
        @endif
    @endforeach
    @endif

    <!-- ZONE RULE DETAILS -->
    @if($report->zoneRule)
    <div class="section-title">Applied Zone Rule</div>
    <table class="kv-table">
        <tr><td class="key">Rule Source</td><td class="val">{{ $report->zoneRule->rule_source }}</td></tr>
        <tr><td class="key">Road Width Band</td><td class="val">{{ $report->zoneRule->road_width_label }}</td></tr>
        <tr><td class="key">Ground Coverage %</td><td class="val">{{ $report->zoneRule->max_ground_coverage ? ($report->zoneRule->max_ground_coverage * 100).'%' : '—' }}</td></tr>
        <tr><td class="key">Parking Ratio</td><td class="val">{{ $report->zoneRule->parking_ratio_ecs ?? '—' }} ECS/sqm</td></tr>
        @if($report->zoneRule->special_conditions)
        <tr><td class="key">Special Conditions</td><td class="val" style="font-style:italic;color:#616161;">{{ $report->zoneRule->special_conditions }}</td></tr>
        @endif
    </table>
    @endif

    <!-- COST & ROI ESTIMATES -->
    @php $ce = $report->cost_estimates ?? []; @endphp
    @if(!empty($ce))
    <div class="section-title">Cost &amp; ROI Estimates</div>
    <table class="grid-3" style="margin-bottom:10px;">
        <tr>
            <td>
                <div class="data-card">
                    <div class="data-card-label">Construction Cost</div>
                    <div class="data-card-value" style="font-size:13px;">
                        ₹{{ number_format($ce['construction_cost_min_inr'] ?? 0) }}
                        <span style="font-size:11px;color:#757575;">–</span>
                        ₹{{ number_format($ce['construction_cost_max_inr'] ?? 0) }}
                    </div>
                    <div class="data-card-unit">indicative range</div>
                </div>
            </td>
            <td>
                <div class="data-card">
                    <div class="data-card-label">Gross Dev. Value</div>
                    <div class="data-card-value" style="font-size:13px;">₹{{ number_format($ce['gross_development_value_inr'] ?? 0) }}</div>
                    <div class="data-card-unit">market value at completion</div>
                </div>
            </td>
            <td>
                <div class="data-card">
                    <div class="data-card-label">Est. Profit</div>
                    <div class="data-card-value" style="font-size:13px;color:{{ ($ce['estimated_profit_inr'] ?? 0) > 0 ? '#2e7d32' : '#b71c1c' }};">
                        ₹{{ number_format($ce['estimated_profit_inr'] ?? 0) }}
                    </div>
                    <div class="data-card-unit">GDV minus max construction cost</div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="data-card">
                    <div class="data-card-label">ROI</div>
                    <div class="data-card-value" style="color:{{ ($ce['roi_pct'] ?? 0) >= 15 ? '#2e7d32' : (($ce['roi_pct'] ?? 0) >= 5 ? '#e65100' : '#b71c1c') }};">
                        {{ $ce['roi_pct'] ?? '—' }}%
                    </div>
                    <div class="data-card-unit">return on investment</div>
                </div>
            </td>
            <td>
                <div class="data-card">
                    <div class="data-card-label">Monthly Rent Est.</div>
                    <div class="data-card-value" style="font-size:13px;">₹{{ number_format($ce['monthly_rent_estimate_inr'] ?? 0) }}</div>
                    <div class="data-card-unit">indicative rental income</div>
                </div>
            </td>
            <td>
                <div class="data-card">
                    <div class="data-card-label">Break-even</div>
                    <div class="data-card-value">{{ $ce['breakeven_years'] ?? '—' }}</div>
                    <div class="data-card-unit">years (from rental)</div>
                </div>
            </td>
        </tr>
    </table>
    <div style="font-size:9px;color:#9e9e9e;font-style:italic;margin-bottom:12px;">
        ⚠ Cost &amp; ROI figures are indicative estimates based on state-level benchmarks. Actual values may vary significantly.
        Project type: {{ ucfirst($report->project_type ?? 'residential') }}.
        @if(!empty($ce['note'])) {{ $ce['note'] }} @endif
    </div>
    @endif

    <!-- CALCULATION LOG -->
    @if($report->calculation_log && count($report->calculation_log))
    <div class="section-title">Calculation Log</div>
    @foreach($report->calculation_log as $entry)
    <div class="log-entry">
        @if(is_array($entry))
            <strong>{{ $entry['step'] ?? '' }}:</strong> {{ $entry['result'] ?? '' }}
        @else
            {{ $entry }}
        @endif
    </div>
    @endforeach
    @endif

    <!-- FOOTER -->
    <div class="footer">
        <strong>Disclaimer:</strong> This report is for informational purposes only based on publicly available regulations. Always consult a licensed architect, structural engineer, or town planner before making investment or development decisions. LandFeasibility.in accepts no liability for decisions made based on this report.
        <br>Generated by LandFeasibility.in &mdash; AI-Powered Land Analysis for India &mdash; {{ now()->format('d M Y') }}
    </div>

</div>
</body>
</html>
