/**
 * templates.css - Dynamic Multi-Template & Print Layout Matrix
 */

:root {
    --a4-width: 210mm;
    --a4-height: 297mm;
    --resume-primary: #1e293b;
    --resume-text: #334155;
    --resume-muted: #64748b;
    --resume-bg: #ffffff;
}

/* --- Base A4 Canvas --- */
.a4-paper {
    width: var(--a4-width);
    min-height: var(--a4-height);
    margin: 0 auto;
    background: var(--resume-bg);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
    position: relative;
    font-family: 'Inter', sans-serif;
    color: var(--resume-text);
    line-height: 1.6;
    overflow: visible;
}

/* --- Common Typography --- */
#preview-name {
    font-size: 26pt;
    font-weight: 800;
    line-height: 1.1;
    margin-bottom: 4px;
    text-transform: uppercase;
    color: var(--resume-primary);
}

#preview-title {
    font-size: 14pt;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--resume-text);
}

.contact-info {
    font-size: 9.5pt;
    color: var(--resume-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.contact-info span {
    display: flex;
    align-items: center;
    gap: 6px;
}

.section-title {
    font-size: 13pt;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 2px solid var(--resume-primary);
    color: var(--resume-primary);
    padding-bottom: 4px;
    margin-bottom: 12px;
}

.resume-section {
    margin-bottom: 20px;
    break-inside: avoid-page;
    page-break-inside: avoid;
}

.section-title {
    break-after: avoid-page;
    page-break-after: avoid;
}

#preview-profile-photo {
    width: 35mm;
    height: 35mm;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--resume-primary);
}

/* --- Hobbies & Skills grids --- */
.hobbies-grid, .skills-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.hobbies-grid span, .skills-grid span {
    background: #f1f5f9;
    color: var(--resume-text);
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 9pt;
    font-weight: 600;
    border: 1px solid #e2e8f0;
}

/* --- Extra / custom sections --- */
.extra-section-block { margin-bottom: 14px; }
.extra-section-block h4 {
    font-weight: 700;
    font-size: 10.5pt;
    color: var(--resume-primary);
    margin-bottom: 4px;
}
.extra-section-block p { font-size: 9.5pt; white-space: pre-wrap; }

.resume-heading-accent {
    color: var(--resume-primary);
}

.qr-block {
    margin-top: 18px;
    display: flex;
    break-inside: avoid-page;
    page-break-inside: avoid;
}
.qr-block.qr-left { justify-content: flex-start; }
.qr-block.qr-right { justify-content: flex-end; }

.qr-block.hidden { display: none; }

.qr-block .qr-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    max-width: 46mm;
}

.qr-block img {
    width: 24mm;
    height: 24mm;
    display: block;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}


.qr-block .qr-label {
    font-size: 8pt;
    font-weight: 600;
    color: var(--resume-primary);
    text-align: center;
    line-height: 1.2;
}
.qr-block .qr-label:empty { display: none; }

.qr-block .qr-url {
    font-size: 7pt;
    color: var(--resume-muted);
    text-align: center;
    line-height: 1.25;
    word-break: break-all;
}

/* --- Resume Footer (QR & Signature wrapper) --- */
.resume-footer {
    display: flex;
    align-items: flex-end; /* Perfectly aligns the bottom of the QR code with the signature line */
    justify-content: space-between;
    width: 100%;
    margin-top: 20px;
    break-inside: avoid-page;
    page-break-inside: avoid;
}

.resume-footer .qr-block, 
.resume-footer .signature-block {
    margin-top: 0 !important; /* Overrides the old vertical spacing */
    flex: 1; /* Splits the row 50/50 to prevent them from colliding */
}

/* --- Signature block --- */
.signature-block {
    margin-top: 30px;
    display: flex;
    break-inside: avoid-page;
    page-break-inside: avoid;
}
.signature-block.sig-left { justify-content: flex-start; }
.signature-block.sig-right { justify-content: flex-end; }

.signature-block .sig-box {
    width: 55mm;
    display: flex;
    flex-direction: column;
    align-items: center;
}


.signature-block img {
    min-height: 16mm;
    max-height: 22mm;
    max-width: 55mm;
    object-fit: contain;

    object-position: center bottom;
}
.signature-block img:not([src]),
.signature-block img[src=""] {
    visibility: hidden;
}

.signature-block .sig-line {
    width: 100%;
    border-top: 1px solid var(--resume-muted);
    margin-top: 2px;
}

.signature-block .sig-caption {
    font-size: 8pt;
    color: var(--resume-muted);
    padding-top: 4px;
    text-align: center;
}

/* ============================================================
   TEMPLATE 1: Modern Left (Sidebar layout)
   ============================================================ */
.template-1 {
    display: grid;
    grid-template-columns: 35% 65%;
    padding: 0;
}
.template-1 .resume-header {
    background-color: var(--resume-primary);
    color: #ffffff;
    padding: 20mm 10mm;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}
.template-1 #preview-name { color: #ffffff; font-size: 20pt; }
.template-1 #preview-title { color: rgba(255,255,255,0.8); }
.template-1 .contact-info { flex-direction: column; gap: 8px; color: rgba(255,255,255,0.9); margin-top: 15px; align-items: center;}
.template-1 #preview-profile-photo { border-color: #ffffff; margin-bottom: 20px; }
.template-1 .resume-body { padding: 20mm 15mm; }

/* ============================================================
   TEMPLATE 2: Classic Top (Standard full-width)
   ============================================================ */
.template-2 {
    display: block;
    padding: 20mm;
}
.template-2 .resume-header {
    text-align: center;
    border-bottom: 3px solid var(--resume-primary);
    padding-bottom: 15px;
    margin-bottom: 20px;
}
.template-2 #preview-profile-photo { margin: 0 auto 15px auto; }
.template-2 .contact-info { justify-content: center; }

/* ============================================================
   TEMPLATE 4: Minimalist Clean (thin rules, generous whitespace)
   ============================================================ */
.template-4 {
    display: block;
    padding: 22mm 20mm;
}
.template-4 .resume-header {
    text-align: left;
    padding-bottom: 10px;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 18px;
}
.template-4 #preview-name { font-size: 22pt; text-transform: none; letter-spacing: 0.5px; }
.template-4 #preview-title { color: var(--resume-muted); font-weight: 500; }
.template-4 .section-title {
    border-bottom: none;
    border-top: 1px solid var(--resume-muted);
    padding-top: 6px;
    letter-spacing: 2px;
    font-size: 10.5pt;
}
.template-4 #preview-profile-photo { border-width: 1px; width: 28mm; height: 28mm; }


/* ============================================================
   TEMPLATE 6: Bold Header Banner (full-width color block header)
   ============================================================ */
.template-6 { display: block; padding: 0; }
.template-6 .resume-header {
    background-color: var(--resume-primary);
    color: #fff;
    padding: 18mm 20mm;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 20px;
}
.template-6 #preview-name { color: #fff; font-size: 24pt; }
.template-6 #preview-title { color: rgba(255,255,255,0.85); }
.template-6 .contact-info { color: rgba(255,255,255,0.9); }
.template-6 #preview-profile-photo { border-color: #fff; }
.template-6 .resume-body { padding: 14mm 20mm; }
.template-6 .section-title { border-bottom-width: 3px; }

/* ============================================================
   TEMPLATE 7: Compact Timeline (dense, single column, accent rail)
   ============================================================ */
.template-7 { display: block; padding: 18mm; }
.template-7 .resume-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-left: 14px;
    border-left: 5px solid var(--resume-primary);
    margin-bottom: 16px;
}
.template-7 #preview-name { font-size: 19pt; }
.template-7 #preview-profile-photo { width: 26mm; height: 26mm; }
.template-7 .section-title {
    border-bottom: none;
    padding-left: 14px;
    border-left: 5px solid var(--resume-primary);
    font-size: 11pt;
}
.template-7 .resume-section { padding-left: 14px; margin-bottom: 14px; }
.template-7 p, .template-7 .resume-block { font-size: 9.5pt; }

/* ============================================================
   TEMPLATE 8: Executive Serif (centred, double rule, serif type)
   ------------------------------------------------------------
   The only serif template in the set. Font-family is set on the paper
   itself so every child inherits it - none of the generated markup sets
   a family of its own, so there's nothing to override.
   ============================================================ */
.template-8 {
    display: block;
    padding: 20mm;
    font-family: Georgia, 'Times New Roman', serif;
}
.template-8 .resume-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding-bottom: 12px;
    border-bottom: 3px double var(--resume-primary);
    margin-bottom: 18px;
}
.template-8 #preview-name { font-size: 24pt; letter-spacing: 3px; font-weight: 700; }
.template-8 #preview-title { font-style: italic; font-weight: 400; color: var(--resume-muted); font-size: 12.5pt; }
.template-8 .contact-info { justify-content: center; }
.template-8 #preview-profile-photo { border-width: 1px; margin-bottom: 12px; }
.template-8 .section-title {
    text-align: center;
    border-bottom: 1px solid var(--resume-muted);
    letter-spacing: 3px;
    font-size: 11pt;
    font-weight: 700;
}

/* ============================================================
   TEMPLATE 9: Sidebar Right (mirror of Template 1)
   ------------------------------------------------------------
   Same two-grid-item structure as Template 1 (header + .resume-body),
   just with the columns swapped via explicit grid-column. No
   display:contents, so the QR and signature blocks stay ordinary
   children of .resume-body and need no placement rules.
   ============================================================ */
.template-9 {
    display: grid;
    grid-template-columns: 65% 35%;
    padding: 0;
}
.template-9 .resume-header {
    grid-column: 2 / 3;
    grid-row: 1;
    background-color: var(--resume-primary);
    color: #ffffff;
    padding: 20mm 10mm;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}
.template-9 .resume-body {
    grid-column: 1 / 2;
    grid-row: 1;
    padding: 20mm 12mm 20mm 15mm;
}
.template-9 #preview-name { color: #ffffff; font-size: 20pt; }
.template-9 #preview-title { color: rgba(255,255,255,0.8); }
.template-9 .contact-info { flex-direction: column; gap: 8px; color: rgba(255,255,255,0.9); margin-top: 15px; align-items: center; }
.template-9 #preview-profile-photo { border-color: #ffffff; margin-bottom: 20px; }


.template-10 { display: block; padding: 20mm; }
.template-10 .resume-header {
    display: flex;
    align-items: center;
    gap: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 18px;
}
.template-10 #preview-name { font-size: 21pt; }
.template-10 .section-title {
    border-bottom: none;
    font-size: 11pt;
    margin-bottom: 10px;
}
.template-10 .resume-block {
    position: relative;
    padding-left: 16px;
    border-left: 2px solid #e2e8f0;
    padding-bottom: 2px;
}
.template-10 .resume-block::before {
    content: "";
    position: absolute;
    left: -6px;
    top: 7px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--resume-primary);
    border: 2px solid #ffffff;
}

/* ============================================================
   TEMPLATE 11: Accent Tabs (section titles as solid labels)
   ============================================================ */
.template-11 { display: block; padding: 20mm; }
.template-11 .resume-header {
    display: flex;
    align-items: center;
    gap: 18px;
    margin-bottom: 18px;
}
.template-11 #preview-name { font-size: 22pt; }
.template-11 .section-title {
    display: inline-block;
    background: var(--resume-primary);
    color: #ffffff;
    border-bottom: none;
    border-radius: 4px;
    padding: 4px 12px;
    font-size: 10pt;
    letter-spacing: 1.5px;
}
.template-11 .resume-section { border-bottom: 1px solid #f1f5f9; padding-bottom: 12px; }
.template-11 .resume-section:last-child { border-bottom: none; }

/* ============================================================
   TEMPLATE 12: Boxed Cards (each section in a tinted card)
   ============================================================ */
.template-12 { display: block; padding: 18mm; }
.template-12 .resume-header {
    display: flex;
    align-items: center;
    gap: 18px;
    background: #f8fafc;
    border: 1px solid #e8eef5;
    border-left: 5px solid var(--resume-primary);
    border-radius: 10px;
    padding: 8mm;
    margin-bottom: 14px;
}
.template-12 #preview-name { font-size: 21pt; }
.template-12 .resume-section {
    background: #f8fafc;
    border: 1px solid #e8eef5;
    border-left: 5px solid var(--resume-primary);
    border-radius: 10px;
    padding: 6mm 7mm;
    margin-bottom: 12px;
}
.template-12 .section-title {
    border-bottom: none;
    font-size: 11pt;
    margin-bottom: 8px;
}

/* ============================================================
   TEMPLATE 14: Statement (oversized name, hairline rules)
   ============================================================ */
.template-14 { display: block; padding: 22mm 20mm; }
.template-14 .resume-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    padding-bottom: 10px;
    border-bottom: 6px solid var(--resume-primary);
    margin-bottom: 20px;
}
.template-14 .header-text { flex: 1; min-width: 0; }
.template-14 #preview-name { font-size: 30pt; letter-spacing: -0.5px; line-height: 1; }
.template-14 #preview-title { font-size: 12pt; color: var(--resume-muted); font-weight: 500; margin-bottom: 8px; }
/* order:2 moves the photo to the right of the name without touching the
   markup - the photo is the first child in the DOM for every template. */
.template-14 #preview-profile-photo { order: 2; width: 30mm; height: 30mm; border-width: 0; }
.template-14 .section-title {
    border-bottom: none;
    border-left: 4px solid var(--resume-primary);
    padding-left: 8px;
    font-size: 10.5pt;
    letter-spacing: 2px;
}

/* --- Print Rules --- */
@media print {
    /* 1. Set the global safety margin for all pages (Prevents cut-offs on page 2) */
    @page { 
        size: A4 portrait; 
        margin: 10mm 0; 
    }
    
    body * { visibility: hidden; }
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
    
    .rb-canvas-container, .a4-paper, .a4-paper * { visibility: visible; }
    .rb-canvas-container { position: absolute; left: 0; top: 0; padding: 0; margin: 0; width: 100%; background: transparent; }
    
    .a4-paper {
        width: 210mm;
        min-height: 297mm;
        height: auto;
        box-shadow: none;
        margin: 0;
        page-break-after: always;
    }

    /* ==========================================================
       2. MASTER PADDING NORMALIZER
       Subtracts exactly 10mm from the top/bottom of every template 
       so the PDF perfectly matches the live preview.
       ========================================================== */
       
    /* Templates with 20mm default padding */
    .template-2, .template-8, .template-10, .template-11 { 
        padding-top: 10mm !important; 
        padding-bottom: 10mm !important; 
    }

    /* Templates with 22mm default padding */
    .template-4, .template-14 { 
        padding-top: 12mm !important; 
        padding-bottom: 12mm !important; 
    }

    /* Templates with 18mm default padding */
    .template-7, .template-12 { 
        padding-top: 8mm !important; 
        padding-bottom: 8mm !important; 
    }

    /* Sidebars and Colored Header banners */
    .template-1 .resume-header, .template-9 .resume-header {
        padding-top: 10mm !important;
    }
    .template-1 .resume-body, .template-9 .resume-body {
        padding-top: 10mm !important;
        padding-bottom: 10mm !important;
    }

    .template-6 .resume-header {
        padding-top: 8mm !important;
    }
    .template-6 .resume-body {
        padding-bottom: 4mm !important;
    }

    /* ==========================================================
       3. SMART PAGE BREAK CONTROL
       Prevents signatures, QR codes, and jobs from splitting 
       across two pages or creating blank third pages.
       ========================================================== */
    .resume-block, 
    .signature-block, 
    .qr-block, 
    .extra-section-block,
    img { 
        page-break-inside: avoid !important; 
        break-inside: avoid !important; 
    }

    /* Keeps headings locked to the text below them */
    h1, h2, h3, h4, .section-title {
        page-break-after: avoid !important;
        break-after: avoid !important;
    }
}