/* 
 * Consolidated Preview Styling Fixes - No Duplicates
 * This file contains all preview-related styles to avoid conflicts
 * Duplicates removed from styles.css and builder.html inline styles minimized
 */

/* Main preview section layout - Maximum specificity */
body .cv-builder .builder-container .two-column-layout .preview-section {
  flex: 1 !important;
  width: 50% !important;
  min-width: 500px !important;
  background: white !important;
  border-radius: 8px !important;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
  padding: 0 !important;
  position: static !important;
  height: auto !important;
  max-height: calc(100vh - 100px) !important;
  overflow: visible !important; /* don't clip bottom content; inner container handles scroll */
  display: flex !important;
  flex-direction: column !important;
  border-left: 1px solid #e2e8f0 !important;
  flex-shrink: 0 !important;
  flex-grow: 1 !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Preview header */
.preview-header {
  background: #f8fafc;
  padding: 15px 20px;
  border-bottom: 1px solid #e5e7eb;
  border-radius: 8px 8px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.preview-header h2 {
  margin: 0;
  font-size: 1.2rem;
  color: #1f2937;
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview-header h2 i {
  color: #3b82f6;
}

/* Template selector */
.template-selector {
  display: flex;
  align-items: center;
  gap: 10px;
}

.template-label {
  margin-right: 10px;
  font-weight: 500;
  color: #4b5563;
}

.template-dropdown {
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 0.9rem;
  cursor: pointer;
}

/* Preview container - Maximum specificity */
body .cv-builder .builder-container .two-column-layout .preview-section .preview-container {
  flex: 1 !important;
  height: 100% !important;
  overflow-y: auto !important;
  position: relative !important;
  background: #f8fafc !important;
  border-radius: 0 0 8px 8px !important;
  padding: 20px !important;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05) !important;
  display: flex !important;
  justify-content: center !important;
  align-items: flex-start !important;
  min-height: 700px !important;
  width: 100% !important;
  min-width: 500px !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* CV Preview styling - Maximum specificity */
body .cv-builder .builder-container .two-column-layout .preview-section .preview-container .cv-preview {
  background: white !important;
  width: 100% !important;
  max-width: 800px !important;
  min-height: 700px !important;
  margin: 0 auto !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
  transform-origin: top center !important;
  padding: 0 !important;
  overflow: visible !important;
  border-radius: 8px !important;
  border: 1px solid #e5e7eb !important;
  display: block !important;
  transition: transform 0.3s ease !important;
  visibility: visible !important;
  opacity: 1 !important;
  min-width: 500px !important;
  position: relative !important;
  transform: none !important;
  padding-bottom: 32px !important; /* ensure bottom content visible */
}

/* Ensure all sections within preview are not clipped */
body .cv-builder .builder-container .two-column-layout .preview-section .preview-container .cv-preview .cv-section,
body .cv-builder .builder-container .two-column-layout .preview-section .preview-container .cv-preview .cv-content,
body .cv-builder .builder-container .two-column-layout .preview-section .preview-container .cv-preview .cv-main {
  overflow: visible !important;
  max-height: none !important;
}

/* Extra safety: never clip inside preview tree */
body .cv-builder .preview-section .preview-container .cv-preview,
body .cv-builder .preview-section .preview-container .cv-preview * {
  overflow: visible !important;
}

/* Ensure circular profile image cropping inside preview (override global overflow) */
body .cv-builder .preview-section .preview-container .cv-preview .cv-profile-image {
  overflow: hidden !important; /* restore clipping for avatar wrapper */
  border-radius: 50% !important; /* enforce circular mask */
}

body .cv-builder .preview-section .preview-container .cv-preview .cv-profile-image img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  border-radius: 50% !important; /* belt-and-suspenders for some browsers */
  display: block !important;
}

/* Match Step 3 (final) avatar look & feel in Step 2 preview */
/* Modern */
body .cv-builder .preview-section .preview-container .cv-preview .cv-template.template-modern .cv-profile-image {
  width: 100px !important;
  height: 100px !important;
  border: 4px solid rgba(255, 255, 255, 0.9) !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
  margin-bottom: 10px !important;
}

/* Classic */
body .cv-builder .preview-section .preview-container .cv-preview .cv-template.template-classic .cv-profile-image {
  width: 110px !important;
  height: 110px !important;
  border: 3px solid #2c2c2c !important;
  box-shadow: 0 3px 10px rgba(44, 44, 44, 0.2) !important;
  margin: 0 auto 15px !important;
}

/* Creative */
body .cv-builder .preview-section .preview-container .cv-preview .cv-template.template-creative .cv-profile-image {
  width: 105px !important;
  height: 105px !important;
  border: 4px solid rgba(255, 255, 255, 0.95) !important;
  box-shadow: 0 6px 15px rgba(124, 58, 237, 0.4) !important;
  margin-bottom: 10px !important;
}

/* ATS stays image-free in preview too */
body .cv-builder .preview-section .preview-container .cv-preview .cv-template.template-ats .cv-profile-image {
  display: none !important;
}

/* Force proper initial state */
.cv-preview:empty::before {
  content: "Loading CV preview...";
  display: flex;
  align-items: center;
  justify-content: center;
  height: 600px;
  color: #6b7280;
  font-size: 1.1rem;
  background: #f9fafb;
  border-radius: 8px;
}

/* Template switching animation */
.cv-preview.switching {
  opacity: 0.3;
}

/* Loading indicator */
.loading-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 100px 0;
  color: #718096;
  text-align: center;
}

.loading-preview i {
  font-size: 48px;
  margin-bottom: 20px;
  color: #3b82f6;
}

/* Ensure final template styles are properly applied */
.final-cv-template,
.cv-template {
  width: 100%;
  height: auto;
  font-family: 'Segoe UI', Arial, sans-serif;
  overflow: visible;
  display: block;
}

/* Better spacing for CV sections */
.cv-section {
  margin-bottom: 20px;
  padding: 0 20px;
}

/* Make sure images display properly */
.cv-profile-img {
  max-width: 150px;
  height: auto;
  border-radius: 50%;
  object-fit: cover;
}

/* Responsive preview scaling - Override with larger minimum sizes */
@media (max-width: 1400px) {
  .cv-preview {
    transform: scale(1) !important; /* Prevent scaling */
    margin: 0 auto !important;
    min-width: 500px !important;
  }
}

@media (max-width: 1200px) {
  .cv-preview {
    transform: scale(1) !important; /* Prevent scaling */
    margin: 0 auto !important;
    min-width: 480px !important;
  }
  
  .preview-container {
    padding: 20px !important;
    min-width: 500px !important;
  }
  
  .preview-section {
    min-width: 500px !important;
  }
}

@media (max-width: 900px) {
  .cv-preview {
    transform: scale(1) !important; /* Prevent scaling */
    margin: 0 auto !important;
    min-width: 400px !important;
  }
}

@media (min-width: 769px) {
  /* Force large size on desktop */
  .preview-section {
    display: flex !important;
    min-width: 500px !important;
  }
  
  .preview-container {
    min-width: 500px !important;
    min-height: 700px !important;
  }
  
  .cv-preview {
    min-width: 500px !important;
    max-width: 800px !important;
    min-height: 700px !important;
  }
}

@media (max-width: 768px) {
  .preview-section {
    display: none;
  }
}

/* Prevent any layout collapse during page load */
.preview-section,
.preview-container,
.cv-preview {
  transition: none !important;
}

/* After page loads, restore transitions */
.page-loaded .preview-section,
.page-loaded .preview-container,
.page-loaded .cv-preview {
  transition: transform 0.3s ease;
}

/* A11y improvements */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  /* keep content visually hidden but do not affect preview containers */
  overflow: clip;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
