<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CV ATS Friendly - {{ $cv->content['contact']['name'] ?? 'Dokumen' }}</title>
    
    <!-- Google Fonts for Clean Print Output -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Times+New+Roman&family=Arial:wght@400;700&display=swap" rel="stylesheet">

    <style>
        /* Base page styling for screen view */
        body {
            background-color: #525659; /* Gray PDF-viewer-like bg */
            margin: 0;
            padding: 20px;
            font-family: 'Times New Roman', Times, serif;
            display: flex;
            flex-col: column;
            align-items: center;
            justify-content: center;
        }

        /* Screen preview action bar */
        .action-bar {
            background-color: #fff;
            box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
            border-radius: 8px;
            padding: 12px 24px;
            width: 100%;
            max-width: 210mm;
            margin-bottom: 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-sizing: border-box;
        }

        .action-bar h1 {
            font-family: Arial, sans-serif;
            font-size: 14px;
            margin: 0;
            color: #374151;
        }

        .btn {
            background-color: #4f46e5;
            color: #fff;
            border: none;
            padding: 8px 16px;
            border-radius: 6px;
            font-family: Arial, sans-serif;
            font-size: 12px;
            font-weight: bold;
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            gap: 6px;
            text-decoration: none;
            transition: background-color 0.2s;
        }

        .btn:hover {
            background-color: #4338ca;
        }

        .btn-secondary {
            background-color: #f3f4f6;
            color: #374151;
            border: 1px solid #d1d5db;
        }

        .btn-secondary:hover {
            background-color: #e5e7eb;
        }

        /* A4 Page container */
        .page {
            background-color: #fff;
            width: 210mm;
            min-height: 297mm;
            padding: 20mm;
            box-shadow: 0 4px 10px rgba(0,0,0,0.15);
            box-sizing: border-box;
            color: #000;
            font-size: 11pt;
            line-height: 1.4;
            text-align: justify;
        }

        /* ATS Typography Rules */
        h2 {
            font-size: 20pt;
            text-align: center;
            text-transform: uppercase;
            margin: 0 0 4px 0;
            font-family: Arial, sans-serif;
            font-weight: bold;
            letter-spacing: 0.5px;
        }

        .contact-info {
            text-align: center;
            font-size: 9.5pt;
            margin-bottom: 4px;
            color: #111;
        }

        .socials-info {
            text-align: center;
            font-size: 8.5pt;
            margin-bottom: 16px;
            color: #333;
        }

        h3 {
            font-family: Arial, sans-serif;
            font-size: 11pt;
            font-weight: bold;
            text-transform: uppercase;
            border-bottom: 1.2px solid #000;
            margin: 16px 0 8px 0;
            padding-bottom: 2px;
            letter-spacing: 0.5px;
        }

        .section-block {
            margin-bottom: 12px;
        }

        .block-header {
            display: flex;
            justify-content: space-between;
            font-weight: bold;
            font-size: 10.5pt;
            margin-bottom: 2px;
        }

        .block-header-title {
            font-family: Arial, sans-serif;
        }

        .block-header-date {
            font-weight: normal;
            font-style: italic;
        }

        .block-desc {
            margin: 0 0 8px 0;
            padding-left: 12px;
            font-size: 10pt;
            color: #222;
            white-space: pre-wrap;
        }

        .skills-list {
            font-size: 10pt;
        }

        /* PRINT STYLE RULES (Ctrl+P or Print Button) */
        @media print {
            body {
                background-color: #fff;
                padding: 0;
                margin: 0;
                display: block;
            }

            .action-bar {
                display: none; /* Hide toolbar in print */
            }

            .page {
                box-shadow: none;
                width: 100%;
                min-height: auto;
                padding: 15mm;
                margin: 0;
            }

            /* Prevent page breaking inside experience/education items */
            .section-block {
                page-break-inside: avoid;
            }
        }
    </style>
</head>
<body>

    <!-- Action Bar for Web Preview -->
    <div class="action-bar">
        <h1>Preview CV: {{ $cv->title }}</h1>
        <div style="display: flex; gap: 10px;">
            <a href="{{ route('dashboard') }}" class="btn btn-secondary">
                Kembali ke Dashboard
            </a>
            <button onclick="window.print()" class="btn">
                Cetak / Simpan PDF
            </button>
        </div>
    </div>

    <!-- The ATS A4 Document -->
    <div class="page">
        
        <!-- Header -->
        <header>
            <h2>{{ $cv->content['contact']['name'] }}</h2>
            <div class="contact-info">
                {{ $cv->content['contact']['location'] }} &bull; 
                {{ $cv->content['contact']['phone'] }} &bull; 
                {{ $cv->content['contact']['email'] }}
            </div>
            <div class="socials-info">
                @if(!empty($cv->content['contact']['linkedin']))
                    {{ $cv->content['contact']['linkedin'] }}
                @endif
                @if(!empty($cv->content['contact']['github']))
                    @if(!empty($cv->content['contact']['linkedin'])) &nbsp;|&nbsp; @endif
                    {{ $cv->content['contact']['github'] }}
                @endif
            </div>
        </header>

        <!-- Summary -->
        @if(!empty($cv->content['contact']['summary']))
        <section>
            <h3>Professional Summary</h3>
            <p style="margin: 0; font-size: 10pt; text-align: justify;">
                {{ $cv->content['contact']['summary'] }}
            </p>
        </section>
        @endif

        <!-- Experience -->
        @if(!empty($cv->content['experience']))
        <section>
            <h3>Professional Experience</h3>
            @foreach($cv->content['experience'] as $exp)
            <div class="section-block">
                <div class="block-header">
                    <span class="block-header-title">{{ $exp['role'] }} &ndash; {{ $exp['company'] }}</span>
                    <span class="block-header-date">{{ $exp['start'] }} &ndash; {{ $exp['end'] }}</span>
                </div>
                <div class="block-desc">{{ $exp['description'] }}</div>
            </div>
            @endforeach
        </section>
        @endif

        <!-- Education -->
        @if(!empty($cv->content['education']))
        <section>
            <h3>Education</h3>
            @foreach($cv->content['education'] as $edu)
            <div class="section-block">
                <div class="block-header">
                    <span class="block-header-title">{{ $edu['degree'] }} &ndash; {{ $edu['institution'] }}</span>
                    <span class="block-header-date">{{ $edu['start'] }} &ndash; {{ $edu['end'] }}</span>
                </div>
                @if(!empty($edu['description']))
                <div class="block-desc" style="margin-bottom: 2px;">{{ $edu['description'] }}</div>
                @endif
            </div>
            @endforeach
        </section>
        @endif

        <!-- Projects -->
        @if(!empty($cv->content['projects']))
        <section>
            <h3>Projects</h3>
            @foreach($cv->content['projects'] as $proj)
            <div class="section-block">
                <div class="block-header">
                    <span class="block-header-title">{{ $proj['name'] }} @if(!empty($proj['role'])) ({{ $proj['role'] }}) @endif</span>
                    @if(!empty($proj['link']))
                    <span class="block-header-date" style="font-size: 8.5pt;">{{ $proj['link'] }}</span>
                    @endif
                </div>
                <div class="block-desc">{{ $proj['description'] }}</div>
            </div>
            @endforeach
        </section>
        @endif

        <!-- Skills & Languages -->
        <section>
            <h3>Skills & Languages</h3>
            <div class="skills-list">
                @if(!empty($cv->content['skills']))
                <div style="margin-bottom: 4px;">
                    <strong>Technical Skills:</strong> {{ implode(', ', $cv->content['skills']) }}
                </div>
                @endif
                @if(!empty($cv->content['languages']))
                <div>
                    <strong>Languages:</strong> {{ implode(', ', $cv->content['languages']) }}
                </div>
                @endif
            </div>
        </section>

    </div>

</body>
</html>
