:root {
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --text: #1a202c;
  --muted: #64748b;
  --border: #94a3b8;
  --bg: #f8fafc;
  --input-bg: #fff;
  --accent: #667eea;
}

*, *::before, *::after { box-sizing: border-box; }

body.dark {
  --primary: #667eea;
  --primary-hover: #5a67d8;
  --text: #f5f5f5;
  --muted: #cbd5e1;
  --border: #4a5568;
  --bg: #1a202c;
  --input-bg: #2d3748;
  --accent: #667eea;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  line-height: 1.6;
  color: var(--text);
  background: linear-gradient(135deg, #1a202c 0%, #2d3748 50%, #4a5568 100%);
  margin: 0;
  padding: 1rem;
  transition: background-color 0.3s ease, color 0.3s ease;
  min-height: 100vh;
}

.main-container {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;
  max-width: 1400px;
  margin: 0 auto;
  background: transparent;
}

.form-section, .preview-section {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
  padding: 2rem;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

body.dark .form-section, body.dark .preview-section {
  background: rgba(45, 55, 72, 0.95);
  color: var(--text);
  border: 1px solid rgba(102, 126, 234, 0.2);
}

.form-section { flex: 1 1 400px; max-width: 500px; }

.preview-section {
  flex: 2 1 600px;
  font-size: 14px;
  background: white;
  color: #1f2937;
}

body.dark .preview-section { background: white; color: #1f2937; }

.form-section h2 {
  color: var(--accent);
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 2rem;
  text-align: center;
}

.form-group { margin-bottom: 1.5rem; }

label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

input, textarea, select {
  width: 100%;
  max-width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  margin: 0 0 0.5rem 0;
  background-color: var(--input-bg);
  color: var(--text);
  transition: all 0.3s ease;
  font-family: inherit;
  display: block;
  box-sizing: border-box;
  min-width: 0;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
  transform: translateY(-1px);
}

textarea { min-height: 100px; resize: vertical; }

.add-btn, .download-btn {
  background: linear-gradient(135deg, var(--accent) 0%, var(--primary-hover) 100%);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  margin-top: 0.5rem;
  margin-right: 0.5rem;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}
.add-btn:hover, .download-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

.remove-btn {
  display: inline-block;
  margin-top: 0.5rem;
  background: linear-gradient(135deg, #ef4444, #f97316);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.25);
}
.remove-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(249, 115, 22, 0.35);
}
.remove-btn:active { transform: translateY(0); }

.education-inputs:first-child > .remove-btn,
.experience-inputs:first-child > .remove-btn,
.certifications-inputs:first-child > .remove-btn,
.project-input:first-child > .remove-btn {
  display: none;
}

.improve-btn {
  display: inline-block;
  margin: 0.25rem 0 0.75rem 0;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.25);
}
.improve-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(22, 163, 74, 0.35);
}
.improve-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.suggestion-box {
  display: none;
  margin-top: 0.5rem;
  border: 1px dashed #86efac;
  background: #ecfdf5;
  color: #065f46;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
}
body.dark .suggestion-box {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.6);
  color: #d1fae5;
}
.suggestion-box.loading {
  display: block;
  opacity: 0.9;
}

.education-inputs,
.experience-inputs,
.certifications-inputs,
.project-input {
  margin-bottom: 1rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  background: rgba(102, 126, 234, 0.05);
  transition: all 0.3s ease;
  min-width: 0;
}

.education-inputs:hover,
.experience-inputs:hover,
.certifications-inputs:hover,
.project-input:hover {
  border-color: var(--accent);
  background: rgba(102, 126, 234, 0.08);
}

.skills-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}

.skills-grid > * { min-width: 0; }
.skills-grid > div { margin-bottom: 0.5rem; }
.skills-grid label { font-size: 0.9rem; margin-bottom: 0.5rem; font-weight: 600; }

/* --- Preview Section Styles --- */
.header {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid #667eea;
}

.preview-section .header h1 {
  font-size: 2.5rem;
  color: #667eea;
  margin-bottom: 0.5rem;
  font-weight: 700;
}

.contact-info {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  color: #4a5568;
  font-size: 14px;
  margin-bottom: 0;
}
.contact-info span { min-width: 0; display: flex; align-items: center; gap: 0.3rem; }
.preview-section .contact-info a { color: #667eea; text-decoration: none; }
.preview-section .contact-info a:hover { text-decoration: underline; }

.section {
  margin-bottom: 1.5rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  cursor: grab;
  /* FIX: Prevents sections from splitting across pages */
  break-inside: avoid;
  page-break-inside: avoid;
}
.section:active { cursor: grabbing; }

.preview-section .section h2 {
  font-size: 1.25rem;
  color: #667eea;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
  font-weight: 700;
}
.preview-section .section p { color: #4a5568; line-height: 1.7; margin-bottom: 1rem; }

ul { padding-left: 1.5rem; margin: 0.8rem 0; list-style: none; }
.preview-section ul li { margin-bottom: 1rem; position: relative; color: #2d3748; line-height: 1.6; }
.preview-section ul li::before { content: "•"; color: #667eea; font-weight: bold; position: absolute; left: -1.5rem; top: 0; }
.preview-section ul li strong { color: #2d3748; font-weight: 600; }
ul li ul { margin-top: 0.5rem; padding-left: 1.2rem; }
.preview-section ul li ul li { margin-bottom: 0.3rem; font-size: 0.95rem; color: #4a5568; }
.preview-section ul li ul li::before { content: "◦"; color: #667eea; left: -1.2rem; }

.preview-section .skills-grid strong { color: #2d3748; font-weight: 600; }
.preview-section .skills-grid span { color: #4a5568; }

.project-links { margin: 0.5rem 0; }
.preview-section .project-links a { color: #667eea; text-decoration: none; font-size: 13px; font-weight: 500; margin-right: 1rem; display: inline-flex; align-items: center; gap: 0.3rem; }
.preview-section .project-links a::before { content: "🔗"; font-size: 12px; }
.preview-section .project-links a:hover { text-decoration: underline; }

.fade-in { opacity: 0; transform: translateY(20px); transition: opacity 0.6s ease-out, transform 0.6s ease-out; will-change: opacity, transform; }
.fade-in.show { opacity: 1; transform: translateY(0); }

#themeToggle {
  position: fixed;
  top: 20px;
  right: 20px;
  background: rgba(102, 126, 234, 0.9);
  backdrop-filter: blur(10px);
  border: none;
  font-size: 24px;
  cursor: pointer;
  z-index: 1000;
  color: white;
  padding: 12px;
  border-radius: 50%;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}
#themeToggle:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4); }

.footer-actions { display: flex; justify-content: center; gap: 1rem; padding: 1.5rem; border-top: 1px solid #e2e8f0; background: transparent; margin-top: 2rem; }
.btn-refresh, .btn-autofill {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  color: white;
  padding: 12px 20px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}
.btn-refresh:hover, .btn-autofill:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4); }

.footer { background: rgba(26, 32, 44, 0.95); color: #f5f5f5; margin-top: 3rem; padding: 2rem 0; text-align: center; border-top: 1px solid rgba(102, 126, 234, 0.3); }
.footer-link { color: #667eea; text-decoration: none; }
.footer-link:hover { text-decoration: underline; }

.char-count { font-size: 0.8rem; color: var(--muted); display: block; margin-top: -0.3rem; text-align: right; padding-right: 0.7rem; }
.char-count.exceeded { color: #ef4444; font-weight: 600; }
.error-message { color: #f56565; font-size: 0.85rem; margin-top: -0.3rem; margin-bottom: 0.5rem; display: block; font-weight: 500; }

.section.dragging { opacity: 0.6; background-color: rgba(102, 126, 234, 0.1); border: 2px dashed #667eea; cursor: grabbing; transform: scale(1.02); transition: all 0.2s ease-in-out; }

/* --- Photo, Undo/Redo, and Template Styles --- */
#preview-photo {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--accent);
  margin-bottom: 1rem;
}
#preview-photo.hidden { display: none; }

#controls {
  padding-bottom: 1rem;
  border-bottom: 1px dashed #ccc;
  margin-bottom: 1rem;
}
#controls button { margin-right: 0.5rem; padding: 5px 10px; }

/* ======== CORRECTED Two-Column Template Styles v2 ======== */
.preview-section.template-modern #resume-sections {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 2rem;
  align-items: start;
}

.preview-section.template-modern .header {
  grid-column: 1 / -1;
  grid-row: 1; /* Header is in the first row */
}

/* --- Left Column Content --- */
.preview-section.template-modern .section[data-id="Education"] {
  grid-column: 1;
  grid-row: 2; /* Starts on row 2 */
}
.preview-section.template-modern .section[data-id="skills-summary"] {
  grid-column: 1;
  grid-row: 3; /* Starts on row 3 */
}
.preview-section.template-modern .section[data-id="Certificates"] {
  grid-column: 1;
  grid-row: 4; /* Starts on row 4 */
}

/* --- Right Column Content --- */
.preview-section.template-modern .section[data-id="summary"] {
  grid-column: 2;
  grid-row: 2; /* Starts on row 2 */
}
.preview-section.template-modern .section[data-id="experience"] {
  grid-column: 2;
  grid-row: 3; /* Starts on row 3 */
}
.preview-section.template-modern .section[data-id="Projects"] {
  grid-column: 2;
  grid-row: 4; /* Starts on row 4 */
}
/* ======================================================= */

@media (max-width: 900px) {
  .main-container { flex-direction: column; gap: 1.5rem; padding: 0 0.5rem; }
  .form-section, .preview-section { max-width: 100%; min-width: 0; padding: 1.5rem; }
  .skills-grid { grid-template-columns: 1fr; }
  .contact-info { flex-direction: column; gap: 0.8rem; }
  .preview-section .header h1 { font-size: 2rem; }
  /* Disable two-column layout on smaller screens */
  .preview-section.template-modern #resume-sections { display: block; }
}

@media (max-width: 768px) {
  .footer { flex-direction: column; text-align: center; align-items: center; padding: 1.5rem; gap: 1rem; }
  #themeToggle { font-size: 20px; padding: 10px; }
}

.back-to-top {
  position: fixed;
  bottom: 30px;
  right: 30px;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: white;
  border: none;
  border-radius: 50%;
  width: 60px;
  height: 60px;
  font-size: 24px;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.back-to-top.show { opacity: 1; visibility: visible; transform: translateY(0); }
.back-to-top:hover { transform: translateY(-3px); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); background: linear-gradient(135deg, #1481ca, #2563eb); }
.back-to-top:active { transform: translateY(-1px); }
.back-to-top::before { content: "↑"; font-weight: bold; }

@media (max-width: 768px) {
  .container { margin: 10px; border-radius: 0; }
  .header, .section { padding: 20px; }
  .back-to-top { bottom: 20px; right: 20px; width: 50px; height: 50px; font-size: 20px; }
}

@media print {
  .no-print { display: none; }
  .preview-section { box-shadow: none; border: none; background: white; color: #111827; }
  body { background: white !important; }
}

a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid rgba(102, 126, 234, 0.4); outline-offset: 2px; border-radius: 12px; }

.education-inputs:hover, .experience-inputs:hover, .certifications-inputs:hover, .project-input:hover { box-shadow: 0 6px 18px rgba(102, 126, 234, 0.18); }

.preview-section a { color: #4f46e5; }
.preview-section a:hover { text-decoration: underline; }

.footer-actions.no-print { border-top: 1px solid #e5e7eb; }

.preview-section .contact-info span,
.preview-section .project-links a { word-break: break-word; overflow-wrap: anywhere; }

.form-section, .preview-section, input, textarea, .add-btn, .download-btn {
  transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease, transform 0.2s ease;
}



:root {
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --text: #1a202c;
  --muted: #64748b;
  --border: #94a3b8;
  --bg: #f8fafc;
  --input-bg: #fff;
  --accent: #667eea;
}

*, *::before, *::after { box-sizing: border-box; }

body.dark {
  --primary: #667eea;
  --primary-hover: #5a67d8;
  --text: #f5f5f5;
  --muted: #cbd5e1;
  --border: #4a5568;
  --bg: #1a202c;
  --input-bg: #2d3748;
  --accent: #667eea;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  line-height: 1.6;
  color: var(--text);
  background: linear-gradient(135deg, #1a202c 0%, #2d3748 50%, #4a5568 100%);
  margin: 0;
  padding: 1rem;
  transition: background-color 0.3s ease, color 0.3s ease;
  min-height: 100vh;
}

.main-container {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;
  max-width: 1400px;
  margin: 0 auto;
  align-items: flex-start;
}

.form-section, .preview-section {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

body.dark .form-section {
  background: rgba(45, 55, 72, 0.95);
  color: var(--text);
  border: 1px solid rgba(102, 126, 234, 0.2);
}

.form-section { 
  flex: 1 1 400px; 
  max-width: 500px;
  padding: 2rem;
}

/* --- Realistic Page Preview Styles --- */
.preview-section {
  flex: 2 1 600px;
  padding: 2rem;
  background: transparent;
  border: none;
}

#resume-page {
  background: white;
  color: #1f2937;
  width: 8.5in; /* Standard Letter width */
  min-height: 11in; /* Standard Letter height */
  padding: 0.5in;
  margin: 0 auto;
  box-shadow: 0 0 15px rgba(0,0,0,0.15);
  overflow: hidden; /* Hide content that overflows in paged mode */
}

#resume-page.one-page-limit {
  height: 11in; /* Fixed height for one-page mode */
}

#resume-page.overflowing {
  border: 2px solid #ef4444; /* Red border warning */
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.5);
}

body.dark .preview-section { background: transparent; }
body.dark #resume-page { color: #1f2937; }

.form-section h2 {
  color: var(--accent);
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 2rem;
  text-align: center;
}

.form-group { margin-bottom: 1.5rem; }

label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

input, textarea, select {
  width: 100%;
  max-width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  margin: 0 0 0.5rem 0;
  background-color: var(--input-bg);
  color: var(--text);
  transition: all 0.3s ease;
  font-family: inherit;
  display: block;
  box-sizing: border-box;
  min-width: 0;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
  transform: translateY(-1px);
}

textarea { min-height: 100px; resize: vertical; }

.download-btn {
  background: linear-gradient(135deg, var(--accent) 0%, var(--primary-hover) 100%);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  margin-top: 0.5rem;
  margin-right: 0.5rem;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}
.download-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

/* --- Moved Action Button Styles --- */
.action-buttons {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    background: rgba(102, 126, 234, 0.05);
    padding: 1rem;
    border-radius: 12px;
}
.tool-btn {
    background-color: rgba(255,255,255,0.1);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.tool-btn:hover {
    background-color: rgba(102, 126, 234, 0.1);
}

.header { margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 2px solid #667eea; }
.preview-section .header h1 { font-size: 2.5rem; color: #667eea; margin-bottom: 0.5rem; font-weight: 700; }
.contact-info { display: flex; flex-wrap: wrap; gap: 1.5rem; color: #4a5568; font-size: 14px; margin-bottom: 0; }
.contact-info span { min-width: 0; display: flex; align-items: center; gap: 0.3rem; }

.section {
  margin-bottom: 1.5rem;
  cursor: grab;
  break-inside: avoid;
  page-break-inside: avoid;
  position: relative;
  padding-left: 1.5rem; /* Space for drag handle */
}
.section:active { cursor: grabbing; }

.preview-section .section h2 {
  font-size: 1.25rem;
  color: #667eea;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
  font-weight: 700;
}

/* Drag Handle Icon */
.section h2::before {
  content: '⠿';
  position: absolute;
  left: 0;
  top: 6px;
  font-size: 1.2rem;
  color: #cbd5e1;
  cursor: grab;
}

ul { padding-left: 1.5rem; margin: 0.8rem 0; list-style: none; }
.preview-section ul li { margin-bottom: 1rem; position: relative; color: #2d3748; line-height: 1.6; }
.preview-section ul li::before { content: "•"; color: #667eea; font-weight: bold; position: absolute; left: -1.5rem; top: 0; }


.template-modern #resume-sections {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 2rem;
  align-items: start;
}
.template-modern .header {
  grid-column: 1 / -1;
  grid-row: 1;
}
.template-modern .section[data-id="Education"],
.template-modern .section[data-id="skills-summary"],
.template-modern .section[data-id="Certificates"] {
  grid-column: 1;
}
.template-modern .section[data-id="summary"],
.template-modern .section[data-id="experience"],
.template-modern .section[data-id="Projects"] {
  grid-column: 2;
}

@media (max-width: 1200px) {
    .main-container { flex-direction: column; }
    .form-section, .preview-section { max-width: 100%; }
    #resume-page { width: 100%; min-height: 0; height: auto; }
}

@media (max-width: 900px) {
  .template-modern #resume-sections { display: block; }
}

