/* =========================================
   1. GLOBAL VARIABLES & RESET
========================================= */
:root {
    /* App UI Colors */
    --primary: #2563eb;       /* Main Action Blue */
    --primary-dark: #1e40af;
    --secondary: #64748b;     /* Grey Text */
    --bg-light: #f1f5f9;      /* App Background */
    --border: #e2e8f0;        /* Light Borders */
    --white: #ffffff;
    
    /* Paper Dimensions (A4) */
    --paper-w: 210mm;
    --paper-h: 297mm;

    /* Dynamic User Settings (Updated via JS) */
    --cv-color: #2c3e50;      /* Accent Color */
    --cv-font: 'Inter', sans-serif;
    --cv-size: 14px;
    --cv-line-height: 1.5;
    --cv-text: #333333;
    --cv-bg: #ffffff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-light);
    color: #1e293b;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent body scroll, use inner scrolling */
}

/* =========================================
   2. NAVBAR
========================================= */
.navbar {
    height: 60px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    flex-shrink: 0;
    z-index: 50;
}

.logo {
    font-weight: 800;
    font-size: 1.25rem;
    color: #0f172a;
    letter-spacing: -0.5px;
}
.highlight { color: var(--primary); }

.nav-actions { display: flex; gap: 10px; }

/* Buttons */
.btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e2e8f0; color: #475569; }
.btn-secondary:hover { background: #cbd5e1; }
.btn-outline {
    width: 100%;
    background: white;
    border: 1px dashed var(--primary);
    color: var(--primary);
    padding: 10px;
    margin-bottom: 8px;
    justify-content: center;
}
.btn-outline:hover { background: #eff6ff; }
.btn-del {
    background: none; border: none; color: #ef4444; 
    cursor: pointer; font-size: 0.9rem; padding: 4px;
}
.btn-del:hover { color: #dc2626; background: #fee2e2; border-radius: 4px; }

/* =========================================
   3. APP CONTAINER & LAYOUT
========================================= */
.app-container {
    display: flex;
    flex: 1;
    height: calc(100vh - 60px);
    overflow: hidden;
}

/* --- LEFT COLUMN: EDITOR --- */
.editor-pane {
    width: 400px;
    background: var(--white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

/* Tabs */
.tabs {
    display: flex;
    position: sticky;
    top: 0;
    background: var(--white);
    z-index: 20;
    border-bottom: 1px solid var(--border);
}
.tab-link {
    flex: 1;
    padding: 15px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    font-weight: 600;
    color: var(--secondary);
    cursor: pointer;
    transition: 0.2s;
}
.tab-link:hover { background: #f8fafc; }
.tab-link.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: #f0f9ff;
}

.tab-content { display: none; padding: 20px; animation: fadeIn 0.3s ease; }
.tab-content.active { display: block; }

/* Form Elements */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.col-1 { grid-column: span 2; }
.col-2 { grid-column: span 1; }
.hidden { display: none; }

label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    color: #475569;
    margin-bottom: 5px;
    text-transform: uppercase;
}
input, select, textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.9rem;
    background: #fff;
    transition: border 0.2s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.full-select { width: 100%; padding: 10px; background: white; }

/* Accordions */
.accordion-item {
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 10px;
    overflow: hidden;
    background: white;
}
.accordion-header {
    background: #f8fafc;
    padding: 12px 15px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.accordion-header:hover { background: #f1f5f9; }
.accordion-body { display: none; padding: 15px; border-top: 1px solid var(--border); }
.accordion-item.open .accordion-body { display: block; }

/* Template Grid */
.template-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}
.t-card {
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
    background: #f8fafc;
    transition: all 0.2s;
}
.t-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.t-card.active { border-color: var(--primary); background: #eff6ff; }
.t-preview {
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e2e8f0;
    color: #94a3b8;
    font-weight: bold;
    font-size: 1.5rem;
}
.t-name {
    padding: 8px;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: #334155;
    background: white;
}

/* Legacy Toggle */
.legacy-toggle-btn {
    font-size: 0.85rem;
    color: var(--primary);
    cursor: pointer;
    margin-top: 10px;
    font-weight: 600;
    display: inline-block;
}

/* Editor Footer */
.editor-footer {
    margin-top: auto;
    padding: 15px;
    text-align: center;
    font-size: 0.8rem;
    color: #94a3b8;
    border-top: 1px solid var(--border);
}
.editor-footer a { color: var(--primary); text-decoration: none; }

/* --- RIGHT COLUMN: PREVIEW --- */
.preview-area {
    flex: 1;
    background: #525659; /* Standard PDF Reader Grey */
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    padding: 20px;
    position: relative;
}

.preview-controls {
    position: sticky;
    top: 0;
    z-index: 40;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    padding: 8px 15px;
    border-radius: 20px;
    display: flex;
    gap: 15px;
    align-items: center;
    color: white;
    margin-bottom: 20px;
}
.preview-controls button {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 1.2rem;
}

/* The A4 Paper */
.paper-wrapper {
    transition: transform 0.2s ease;
    transform-origin: top center;
    margin-bottom: 30px;
}
.cv-paper {
    width: var(--paper-w);
    min-height: var(--paper-h);
    background: var(--cv-bg);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    position: relative;
    overflow: hidden;
    /* CSS Variables for Dynamic Styling */
    font-family: var(--cv-font);
    font-size: var(--cv-size);
    line-height: var(--cv-line-height);
    color: var(--cv-text);
}

/* AdSense Slots */
.ad-slot {
    width: 100%;
    max-width: 728px;
    height: 90px;
    background: #f1f5f9;
    border: 1px dashed #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 10px auto;
    color: #94a3b8;
    font-size: 0.9rem;
    flex-shrink: 0;
}
.mobile-hide { display: flex; }
.desktop-only { display: flex; }
.mobile-only { display: none; }


/* =========================================
   4. TEMPLATE STYLES (The 20 Types)
========================================= */

/* Common Elements across templates */
.cv-header { padding: 30px; }
.cv-body { padding: 30px; }
.cv-section { margin-bottom: 25px; }
.cv-title { 
    font-weight: 700; 
    text-transform: uppercase; 
    margin-bottom: 12px; 
    color: var(--cv-color);
    letter-spacing: 0.5px;
}
.cv-entry { margin-bottom: 15px; page-break-inside: avoid; }
.entry-head { display: flex; justify-content: space-between; font-weight: 700; }
.entry-sub { font-style: italic; color: #555; font-size: 0.9em; margin-bottom: 4px; }
.cv-tag { 
    display: inline-block; 
    background: #f3f4f6; 
    color: #333; 
    padding: 3px 8px; 
    border-radius: 4px; 
    font-size: 0.85em; 
    margin: 0 4px 4px 0; 
    border: 1px solid #e5e7eb;
}

/* Legacy Info Grid */
.cv-legacy-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    font-size: 0.85em;
    gap: 8px;
    margin-bottom: 20px;
    padding: 10px;
    background: #f9fafb;
    border-left: 3px solid var(--cv-color);
}

/* --- STRUCTURE A: STANDARD (Top Header) --- */

/* T1: Classic Modern */
.template-1 .cv-header { background: var(--cv-color); color: white; }
.template-1 .cv-title { border-bottom: 2px solid #f0f0f0; padding-bottom: 5px; }

/* T2: Minimalist Clean */
.template-2 .cv-header { text-align: center; border-bottom: 1px solid #ddd; }
.template-2 .cv-title { text-align: center; border-bottom: none; text-decoration: underline; text-decoration-color: var(--cv-color); }
.template-2 .cv-name { color: var(--cv-color); }

/* T5: Tech Dark (Monospace) */
.template-5 { font-family: 'Roboto Mono', monospace !important; }
.template-5 .cv-header { background: #111; color: #2ecc71; border-bottom: 4px solid var(--cv-color); }
.template-5 .cv-name::before { content: '> '; }
.template-5 .cv-title::before { content: '// '; color: #888; }
.template-5 .cv-tag { border: 1px solid var(--cv-color); background: transparent; }

/* T6: Elegant Serif */
.template-6 { font-family: 'Playfair Display', serif !important; }
.template-6 .cv-header { text-align: center; border-bottom: 4px double var(--cv-color); margin: 0 30px; padding: 30px 0; }
.template-6 .cv-title { font-style: italic; text-transform: none; border-bottom: 1px solid #eee; }

/* T7: Clean Line */
.template-7 .cv-header { padding-left: 0; margin-left: 30px; border-left: 5px solid var(--cv-color); }
.template-7 .cv-title { background: #f3f4f6; padding: 5px 10px; display: inline-block; }

/* T8: Boxed Headers */
.template-8 .cv-title { background: var(--cv-color); color: white; padding: 5px 10px; clip-path: polygon(0 0, 95% 0, 100% 100%, 0 100%); }
.template-8 .cv-header { background: #f8fafc; border-bottom: 2px solid var(--cv-color); }

/* T9: Centered Bold */
.template-9 .cv-header { background: #333; color: white; text-align: center; }
.template-9 .cv-title { text-align: center; color: #333; border-top: 1px solid #ccc; padding-top: 10px; }

/* T11: Compact (Small Margins) */
.template-11 .cv-header, .template-11 .cv-body { padding: 15px 30px; }
.template-11 .cv-section { margin-bottom: 15px; }
.template-11 .cv-title { font-size: 1em; border-bottom: 1px solid #ccc; margin-bottom: 8px; }

/* T12: Creative (Big Name) */
.template-12 .cv-name { font-size: 4em !important; line-height: 0.8; opacity: 0.1; position: absolute; top: 10px; right: 20px; z-index: 0; }
.template-12 .cv-header { position: relative; z-index: 1; border-bottom: 3px solid var(--cv-color); }

/* T13: Timeline Style */
.template-13 .cv-body { border-left: 2px solid var(--cv-color); margin-left: 30px; padding-left: 20px; }
.template-13 .cv-header { margin-left: 30px; }
.template-13 .cv-title { position: relative; }
.template-13 .cv-title::before { content:'•'; position:absolute; left:-31px; color:var(--cv-color); font-size:2em; top:-8px; }

/* T14: Grid Box */
.template-14 .cv-body { display: grid; grid-template-columns: 1fr; gap: 10px; }
.template-14 .cv-section { background: #f9f9f9; padding: 15px; border-radius: 8px; margin-bottom: 0; }
.template-14 .cv-header { background: #f9f9f9; margin: 20px 20px 0; border-radius: 8px; }

/* --- STRUCTURE B: SIDEBAR LAYOUTS --- */
/* (Templates 3, 4, 10, 15 use the sidebar HTML structure) */

/* Layout Grid Setup */
.template-3, .template-4, .template-10, .template-15 { 
    display: grid; 
    height: 100%; 
    min-height: var(--paper-h); 
}

/* T3: Sidebar Left (Classic) */
.template-3 { grid-template-columns: 32% 68%; }
.template-3 .cv-sidebar { background: var(--cv-color); color: white; padding: 30px 20px; }
.template-3 .cv-main { padding: 40px 30px; }
.template-3 .cv-title { color: var(--cv-color); border-bottom: 2px solid #eee; }

/* T4: Sidebar Right */
.template-4 { grid-template-columns: 65% 35%; }
.template-4 .cv-sidebar { order: 2; background: #f1f5f9; padding: 30px 20px; border-left: 1px solid #ccc; }
.template-4 .cv-main { order: 1; padding: 40px 30px; }
.template-4 .cv-title { color: #333; font-weight: 800; }

/* T10: Dark Sidebar Left */
.template-10 { grid-template-columns: 30% 70%; }
.template-10 .cv-sidebar { background: #1e293b; color: white; padding: 30px 20px; }
.template-10 .cv-main { padding: 30px; }
.template-10 .cv-title { color: #1e293b; text-decoration: underline; }

/* T15: Split Header Sidebar */
.template-15 { grid-template-columns: 35% 65%; }
.template-15 .cv-sidebar { background: white; border-right: 1px solid var(--cv-color); padding: 30px; color: #333; }
.template-15 .cv-main { padding: 30px; background: #fff; }
.template-15 .cv-sidebar .cv-title { color: var(--cv-color); text-align: right; }
.template-15 .cv-sidebar .cv-entry { text-align: right; }

/* T16-T20: Simple Color Variations of Standard */
.template-16 .cv-header { border-top: 10px solid var(--cv-color); background: #fff; }
.template-17 .cv-section { border-left: 3px solid var(--cv-color); padding-left: 15px; }
.template-18 .cv-name { text-transform: uppercase; letter-spacing: 5px; text-align: center; display: block; width: 100%; }
.template-18 .cv-header { text-align: center; }
.template-19 { background: #fdfbf7; } /* Cream paper */
.template-20 .cv-header { background: linear-gradient(90deg, var(--cv-color) 0%, #333 100%); color: white; }

/* =========================================
   5. RESPONSIVE MEDIA QUERIES
========================================= */
@media (max-width: 1024px) {
    .app-container { flex-direction: column; height: auto; overflow: visible; }
    
    /* Editor on top */
    .editor-pane { width: 100%; height: auto; border-right: none; max-height: 50vh; overflow-y: scroll; border-bottom: 5px solid #ccc; }
    
    /* Hide specific UI */
    .mobile-hide { display: none !important; }
    .desktop-only { display: none !important; }
    .mobile-only { display: flex !important; }
    
    /* Preview at bottom */
    .preview-area { height: auto; padding: 10px; background: #e2e8f0; }
    .paper-wrapper { 
        transform: scale(0.5); 
        transform-origin: top center; 
        margin-bottom: -140mm; /* Compensate for empty space due to scale */
        margin-top: 10px;
    }
}

@media (max-width: 480px) {
    .form-grid { grid-template-columns: 1fr; }
    .col-2 { grid-column: span 1; }
    .paper-wrapper { transform: scale(0.42); margin-bottom: -160mm; }
}

/* =========================================
   6. PRINT STYLES
========================================= */
@media print {
    @page { margin: 0; size: auto; }
    body { background: white; height: auto; overflow: visible; }
    
    /* Hide UI */
    .navbar, .editor-pane, .preview-controls, .ad-slot, .editor-footer { 
        display: none !important; 
    }
    
    /* Setup Paper */
    .app-container, .preview-area, .paper-wrapper {
        display: block;
        width: 100%;
        height: auto;
        margin: 0;
        padding: 0;
        background: white;
        transform: none !important;
        box-shadow: none;
        overflow: visible;
    }
    
    .cv-paper {
        width: 100%;
        min-height: 100vh;
        margin: 0;
        box-shadow: none;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }
    
    /* Ensure page breaks don't cut text */
    p, h1, h2, h3, h4, h5, h6, li { page-break-inside: avoid; }
}

/* Animation */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}


/* =========================================
   7. THUMBNAIL PREVIEW STYLES (New)
   Adds visual skeletons to the template grid
========================================= */

.t-card .t-preview {
    position: relative;
    background: white;
    padding: 10px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow: hidden;
    border-bottom: 1px solid #eee;
}

/* The Mini Page Container */
.mini-page {
    width: 60px;
    height: 85px;
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    border: 1px solid #e2e8f0;
    font-size: 0; /* Hide text */
}

/* Mini Layout: Standard (Top Header) */
.mini-layout-standard .mini-header {
    height: 20%;
    background: #cbd5e1;
    margin-bottom: 4px;
    width: 100%;
}
.mini-layout-standard .mini-body {
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

/* Mini Layout: Sidebar Left */
.mini-layout-sidebar {
    flex-direction: row;
}
.mini-layout-sidebar .mini-side {
    width: 30%;
    background: #475569;
    height: 100%;
}
.mini-layout-sidebar .mini-main {
    width: 70%;
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

/* Mini Lines (Fake Text) */
.mini-line { height: 2px; background: #e2e8f0; width: 100%; margin-bottom: 2px; }
.mini-line.short { width: 50%; }
.mini-line.title { height: 4px; background: #94a3b8; margin-bottom: 4px; width: 70%; }

/* Style for the file input container */
input[type="file"] {
    background: #f8fafc;
    padding: 8px;
}
/* =========================================
   AD SLOT STYLING
   ========================================= */

/* 1. The Container (The Box) */
.ad-slot {
    width: 100%;
    max-width: 728px;      /* Standard Leaderboard size */
    height: 90px;          /* Fixed height */
    margin: 20px auto;     /* Centers the ad vertically & horizontally */
    
    /* Centering Logic */
    display: flex;
    justify-content: center;
    align-items: center;
    
    /* Aesthetics */
    background-color: transparent; /* Transparent so it looks clean */
    overflow: hidden;
    border-radius: 4px;
}

/* 2. The Image (The Content) */
.ad-slot img {
    width: 100%;
    height: 100%;
    display: block;
    
    /* CRITICAL DECISION: 
       'contain' = Shows full image, might leave empty space on sides.
       'cover'   = Fills the box, might crop top/bottom.
    */
    object-fit: contain; 
}

/* 3. Mobile Handling (Hide on screens smaller than 768px) */
@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }
}