/* ==========================================================================
   CSS VARIABLES & RESET
   ========================================================================== */
:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-color: #f3f4f6;
    --panel-bg: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --danger: #ef4444;

    --res-primary: #2563eb;
    --res-text: #1f2937;
    --res-bg: #ffffff;
    --res-font-size: 14px;
    --res-spacing: 1.5rem;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
/* NOTE: body height and overflow removed here as it's managed by index.html <style> block for Global Navbar compatibility */
body { font-family: 'Inter', sans-serif; background: var(--bg-color); color: var(--text-main); display: flex; flex-direction: column; transition: background-color 0.3s, color 0.3s; }

/* ─── HEADER (Local Tool Header) ─────────────────────────────────────────────── */
header { background: var(--panel-bg); padding: 0.7rem 1.5rem; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-color); z-index: 10; flex-shrink: 0; gap: 1rem; transition: background-color 0.3s, border-color 0.3s;}
.logo { font-size: 1.05rem; font-weight: 700; color: var(--primary); display: flex; align-items: center; gap: 0.5rem; }
.header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

/* Back button */
.btn-back { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.4rem 0.8rem; background: var(--bg-color); color: var(--text-main); border: 1px solid var(--border-color); border-radius: 6px; font-family: inherit; font-size: 0.8rem; font-weight: 600; text-decoration: none; transition: all 0.18s; }
.btn-back:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Buttons */
button { cursor: pointer; border: none; border-radius: 6px; padding: 0.45rem 0.9rem; font-family: inherit; font-size: 0.85rem; font-weight: 600; transition: all 0.2s; display: inline-flex; align-items: center; gap: 0.4rem; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border-color); color: var(--text-main); }
.btn-outline:hover { background: var(--bg-color); }
.btn-danger { background: #fee2e2; color: var(--danger); border: 1px solid #fca5a5; }
.btn-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.btn-success:hover { background: #10b981; color: white; }

/* ─── SIDEBAR & TABS ─────────────────────────────────────────────── */
.sidebar { 
    width: 480px; 
    min-width: 340px; 
    background: var(--panel-bg); 
    display: flex; 
    flex-direction: column; 
    border-right: 1px solid var(--border-color); 
    flex-shrink: 0; 
    height: 100%; /* For internal scrolling */
    transition: background-color 0.3s, border-color 0.3s;
}
.tabs { display: flex; border-bottom: 1px solid var(--border-color); background: var(--bg-color); position: sticky; top: 0; z-index: 5; transition: background-color 0.3s, border-color 0.3s;}
.tab { flex: 1; padding: 0.85rem 0.5rem; text-align: center; font-weight: 600; cursor: pointer; color: var(--text-muted); border-bottom: 2px solid transparent; font-size: 0.85rem; transition: color 0.3s, background-color 0.3s;}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--panel-bg); }

.tab-content { 
    padding: 1.25rem; 
    display: none; 
    flex: 1; 
    overflow-y: auto; /* Internal Scroll for Left Panel */
    scrollbar-width: thin;
}
.tab-content.active { display: block; }

/* Scrollbar styling for sidebar */
.tab-content::-webkit-scrollbar { width: 6px; }
.tab-content::-webkit-scrollbar-track { background: transparent; }
.tab-content::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 10px; }

.form-section { margin-bottom: 1.5rem; background: var(--panel-bg); border: 1px solid var(--border-color); border-radius: 8px; overflow: hidden; transition: background-color 0.3s, border-color 0.3s;}
.form-section-header { padding: 0.85rem 1rem; background: var(--bg-color); border-bottom: 1px solid var(--border-color); font-weight: 600; display: flex; justify-content: space-between; align-items: center; font-size: 0.9rem; transition: background-color 0.3s, border-color 0.3s;}
.form-section-body { padding: 1rem; display: flex; flex-direction: column; gap: 0.85rem; }

/* ─── FORMS & INPUTS ─────────────────────────────────────────────── */
.input-group { display: flex; flex-direction: column; gap: 0.2rem; }
label { font-size: 0.72rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; transition: color 0.3s;}
input, textarea, select { padding: 0.45rem 0.5rem; border: 1px solid var(--border-color); border-radius: 4px; font-family: inherit; font-size: 0.85rem; width: 100%; transition: border-color 0.2s, background-color 0.3s, color 0.3s; background: var(--panel-bg); color: var(--text-main);}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,0.1); }
textarea { resize: vertical; min-height: 70px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.85rem; }

.array-item { border: 1px dashed var(--border-color); padding: 0.85rem; border-radius: 6px; margin-bottom: 0.85rem; position: relative; transition: border-color 0.3s;}
.remove-btn { position: absolute; top: 0.4rem; right: 0.4rem; background: none; border: none; color: var(--danger); font-size: 1.2rem; cursor: pointer; padding: 0; line-height: 1; }
.draggable-list { display: flex; flex-direction: column; gap: 0.5rem; }
.draggable-item { padding: 0.65rem 0.85rem; background: var(--bg-color); border: 1px solid var(--border-color); border-radius: 4px; display: flex; align-items: center; cursor: grab; font-size: 0.875rem; transition: background-color 0.3s, border-color 0.3s;}
.draggable-item:active { cursor: grabbing; }

/* ─── CROPPER MODAL ──────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.65); display: flex; justify-content: center; align-items: center; z-index: 100; }
.modal-content { background: var(--panel-bg); padding: 1.4rem; border-radius: 12px; width: 460px; max-width: 96vw; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,0.3); transition: background-color 0.3s;}
.modal-content h3 { margin-bottom: 0.25rem; font-size: 1rem; color: var(--text-main);}
.modal-content p  { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 0.75rem; }
.canvas-container { width: 400px; height: 400px; margin: 0 auto; overflow: hidden; border: 1.5px solid var(--border-color); border-radius: 8px; background: #888; cursor: crosshair; }
#crop-canvas { display: block; cursor: crosshair; }
.modal-actions { display: flex; justify-content: space-between; margin-top: 1.1rem; }

/* ─── PREVIEW AREA ───────────────────────────────────────── */
/* Note: Removed flex:1 so it takes natural height and scroll works cleanly */
.preview-container { background: #6b7280; padding: 1.5rem 2rem; display: flex; flex-direction: column; align-items: center; flex: 1; overflow-y: auto;}

/* ─── A4 PAGE ── */
.a4-page {
    width: 794px;              /* Exact A4 width at 96dpi */
    min-height: 1123px;        /* Exact A4 min-height at 96dpi */
    background: var(--res-bg);
    box-shadow: 0 8px 30px rgba(0,0,0,0.25);
    font-size: var(--res-font-size);
    color: var(--res-text);
    transform-origin: top center;
    flex-shrink: 0;
    
    /* Red Line Indicator for Page Breaks in Preview */
    background-image: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent 1121px,
        #ef4444 1121px, 
        #ef4444 1123px
    );
}

/* ─── RESUME INTERNALS ────────────────────────────────────── */
.res-section { margin-bottom: var(--res-spacing); width: 100%; page-break-inside: avoid; }
.res-section-title { font-size: 1.2em; font-weight: 700; color: var(--res-primary); margin-bottom: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 2px solid var(--res-primary); padding-bottom: 0.2rem; page-break-after: avoid; }
.res-section-title + .res-item,
.res-section-title + .res-skills-list,
.res-section-title + .res-pd-list,
.res-section-title + .res-item-desc { page-break-before: avoid; }

.res-item { margin-bottom: 0.9rem; page-break-inside: avoid; }
.res-item-header { display: flex; justify-content: space-between; font-weight: 600; }
.res-item-sub { font-style: italic; color: #4b5563; font-size: 0.9em; margin-bottom: 0.2rem; }
.res-item-desc { font-size: 0.9em; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: break-word; word-break: break-word; }
.res-skills-list { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.res-skill-badge { background: var(--res-primary); color: white; padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.82em; }
.res-pd-list { display: grid; grid-template-columns: max-content 1fr; gap: 0.2rem 0.85rem; font-size: 0.88em; }
.res-pd-list strong { font-weight: 600; }
.res-photo { width: 110px; height: 110px; object-fit: cover; display: block; flex-shrink: 0; }
.photo-circle { border-radius: 50%; }
.photo-square { border-radius: 6px; }

/* ─── TEMPLATES ──────────────────────────────────────────── */
.template-modern { display: flex; }
.template-modern .res-left  { width: 35%; background: var(--res-primary); color: white; padding: 1.75rem; display: flex; flex-direction: column; }
.template-modern .res-right { width: 65%; padding: 1.75rem; display: flex; flex-direction: column; }
.template-modern .res-name  { font-size: 2em; font-weight: 700; margin-bottom: 0.35rem; line-height: 1.2; }
.template-modern .res-title { font-size: 1.05em; opacity: 0.9; margin-bottom: 1.25rem; }
.template-modern .res-left .res-section-title { color: white; border-bottom-color: rgba(255,255,255,0.3); }
.template-modern .res-left .res-item-sub { color: rgba(255,255,255,0.8); }
.template-modern .res-left .res-skill-badge { background: rgba(255,255,255,0.2); }
.template-modern .res-left .res-pd-list { display: flex; flex-direction: column; gap: 0.4rem; }
.template-modern .res-left .res-pd-list strong { display: block; opacity: 0.75; font-size: 0.75em; text-transform: uppercase; }

.template-minimal { padding: 2.5rem; display: block; }
.template-minimal .res-header { display: flex; align-items: flex-start; text-align: left; gap: 2rem; border-bottom: 1px solid var(--border-color); padding-bottom: 1.5rem; margin-bottom: 1.5rem; }
.template-minimal .res-header > div { flex: 1; }
.template-minimal .res-name  { font-size: 2.3em; font-weight: 300; letter-spacing: 0.1em; line-height: 1.1; }
.template-minimal .res-title { font-size: 1.1em; color: var(--res-primary); margin-top: 0.4rem; }
.template-minimal .res-contact-info { display: flex; justify-content: flex-start; gap: 1rem; flex-wrap: wrap; margin-top: 0.85rem; font-size: 0.88em; }

.template-corporate { padding: 1.75rem; display: block; }
.template-corporate .res-header { background: var(--res-primary); color: white; padding: 1.75rem; margin: -1.75rem -1.75rem 1.75rem; display: flex; align-items: center; gap: 1.5rem; }
.template-corporate .res-name { font-size: 2em; font-weight: 700; }
.template-corporate .res-section-title { color: var(--text-main); border-bottom: 1px solid #ccc; }

.template-ats { padding: 2rem 2.5rem; display: block; background: #fff !important; color: #000 !important; }
.template-ats .res-header { display: flex; align-items: flex-start; text-align: left; gap: 2rem; margin-bottom: 1.5rem; border-bottom: 2px solid #000; padding-bottom: 1.25rem; }
.template-ats .res-header > div { flex: 1; }
.template-ats .res-name { font-size: 24pt; font-weight: bold; text-transform: uppercase; letter-spacing: 1px; line-height: 1.1; }
.template-ats .res-title { font-size: 13pt; font-weight: bold; color: #333; margin-top: 0.35rem; }
.template-ats .res-contact-info { display: flex; justify-content: flex-start; flex-wrap: wrap; gap: 0.85rem; font-size: 11pt; margin-top: 0.5rem; }
.template-ats .res-section-title { font-size: 13pt; border-bottom: 1px solid #000; color: #000; margin-top: 1.25rem; font-weight: bold; text-transform: uppercase; padding-bottom: 3px; }
.template-ats .res-skill-badge { background: none; color: #000; padding: 0; font-size: 11pt; border: none; }
.template-ats .res-skill-badge::after { content: ", "; }
.template-ats .res-skill-badge:last-child::after { content: ""; }

.template-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
.template-card { border: 2px solid var(--border-color); border-radius: 6px; cursor: pointer; text-align: center; padding: 0.85rem; transition: 0.2s; font-size: 0.875rem; background: var(--panel-bg); color: var(--text-main);}
.template-card:hover, .template-card.active { border-color: var(--primary); background: #eff6ff; color: var(--primary); font-weight: 600; }

@media (max-width: 1024px) {
    body { overflow: auto; height: auto; }
    .main-container { flex-direction: column; overflow: visible; }
    .sidebar { width: 100%; min-width: unset; border-right: none; border-bottom: 1px solid var(--border-color); max-height: 60vh; }
    .preview-container { padding: 1rem; overflow: visible; min-height: 400px; }
}

/* ─── PRINT OPTIMIZATION (Fix Blank Space Issue) ─── */
@media print {
    * { 
        -webkit-print-color-adjust: exact !important; 
        print-color-adjust: exact !important; 
    }
    
    @page { size: A4 portrait; margin: 0; }
    
    /* Pura HTML aur Body strict reset */
    body, html { 
        height: auto !important; 
        overflow: visible !important; 
        background: white !important; 
        margin: 0 !important;
        padding: 0 !important;
        display: block !important;
    }
    
    /* 🔴 Jo bhi print nahi karna, usko completely gayab karo (including their space) */
    header, 
    .sidebar, 
    #global-navbar, 
    #global-footer, 
    .app-layout > header, /* Safe side for local header */
    .preview-container > *:not(.a4-page) { 
        display: none !important;
        height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* Layout ki fixed heights aur margins hatao */
    .app-layout {
        display: block !important;
        margin-top: 0 !important; /* Yehi wo blank space de raha tha! */
        min-height: auto !important;
        height: auto !important;
    }

    .main-container, .preview-container { 
        display: block !important; 
        overflow: visible !important; 
        height: auto !important; 
        padding: 0 !important; 
        margin: 0 !important;
        background: transparent !important; 
    }
    
    /* A4 Page ko exact PDF/Print wali height do */
    .a4-page { 
        transform: none !important; 
        box-shadow: none !important; 
        margin: 0 auto !important; 
        width: 100% !important; 
        height: auto !important; 
        min-height: 1120px !important; 
        background-image: none !important; 
    }
    
    /* Page Break Logic */
    .res-section { page-break-inside: auto !important; }
    .res-section-title { page-break-after: avoid !important; }
    .res-item { page-break-inside: avoid !important; }
    h1, h2, h3 { page-break-after: avoid !important; }
    
    /* 🔥 MODERN TEMPLATE MAGIC FIX 🔥 */
    .template-modern { 
        display: flex !important; 
        background: linear-gradient(to right, var(--res-primary) 0%, var(--res-primary) 35%, white 35%) !important; 
        min-height: 1120px !important; 
    }
    
    .template-modern .res-left  { 
        width: 35% !important; 
        background: transparent !important; 
        padding: 1.75rem !important; 
    }
    
    .template-modern .res-right { 
        width: 65% !important; 
        background: transparent !important; 
        padding: 1.75rem !important; 
    }
}
/* ─── EXTRA MOBILE FRIENDLY FIXES ─── */
@media (max-width: 600px) {
    header { flex-direction: column; align-items: stretch; gap: 0.8rem; padding: 1rem; }
    .header-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
    .header-actions button { width: 100%; justify-content: center; font-size: 0.75rem; padding: 0.5rem; margin: 0; }
    #btn-download-pdf { grid-column: span 2; }
    .btn-primary[onclick="window.print()"] { grid-column: span 2; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 0.85rem; }
    .template-grid { grid-template-columns: 1fr; }
    .preview-container { padding: 0.5rem; }
}


/* ==========================================================================
   🌙 DARK MODE SUPER FIX
   ========================================================================== */

/* Overriding root variables when dark mode is active */
body.dark-mode {
    --bg-color: #0b1120;
    --panel-bg: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;
    
    /* Notice we DO NOT change --res variables here, 
       because the resume A4 paper must stay white/print-ready */
}

/* Specific Dark Mode Overrides for UI Elements */
body.dark-mode .btn-outline {
    color: var(--text-main);
    border-color: var(--border-color);
}
body.dark-mode .btn-outline:hover {
    background-color: #334155;
}
body.dark-mode .btn-back {
    background-color: var(--panel-bg);
    border-color: var(--border-color);
}
body.dark-mode .btn-back:hover {
    background-color: var(--primary);
    border-color: var(--primary);
}

body.dark-mode .tab.active {
    background-color: var(--panel-bg);
}
body.dark-mode .form-section-header {
    background-color: #0f172a;
}
body.dark-mode .draggable-item {
    background-color: #0f172a;
}
body.dark-mode .preview-container {
    background-color: #0f172a;
}

/* Ensure the template cards look good in dark mode */
body.dark-mode .template-card {
    background-color: var(--panel-bg);
    border-color: var(--border-color);
}
body.dark-mode .template-card:hover, 
body.dark-mode .template-card.active {
    background-color: rgba(37,99,235,0.15); /* light blue tint */
    border-color: var(--primary);
    color: #bfdbfe;
}

/* ==========================================================================
   🚀 FINAL MOBILE PREVIEW OVERLAP FIX (HTML AWARE)
   ========================================================================== */
@media (max-width: 1024px) {
    /* 1. Poora page hilne se rokne ke liye */
    html, body {
        overflow-x: hidden !important;
        width: 100% !important;
    }

    /* 2. Main Layout ko column banane ke liye */
    .app-layout {
        display: block !important; 
        height: auto !important;
        min-height: auto !important;
    }

    .main-container {
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;
        width: 100% !important;
    }

    /* 3. Sidebar (Form Section) */
    .sidebar {
        width: 100% !important;
        max-width: 100% !important;
        position: static !important; 
        height: auto !important;
        max-height: none !important; 
        overflow: visible !important;
        border-right: none !important;
        border-bottom: 2px solid var(--border-color);
    }

    /* 4. MAGIC FIX: Sirf Preview box me Left-Right scroll ON karna */
    .preview-container {
        width: 100% !important;
        height: 600px !important; 
        display: block !important; /* Flexbox hataya taaki aaram se scroll ho */
        overflow-x: auto !important; /* 🎉 Yahan se Live Preview Left-Right scroll hoga */
        overflow-y: auto !important; /* Upar-niche bhi scroll hoga */
        background: #6b7280;
    }

    /* 5. Resume Paper ki position taaki scroll properly kaam kare */
    .a4-page {
        zoom: normal !important;
        transform: scale(1.00) !important;
        transform-origin: top left !important;
        margin: 0 !important; 
        position: static !important;
        flex-shrink: 0;
    }

    /* 6. Footer Spacing Fix */
    #global-footer {
        margin-top: 0 !important; 
    }
}