:root {
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --text: #1a202c;
  --muted: #64748b;
  --border: #94a3b8;
  --bg: #f8fafc;
  --input-bg: #fff;
  --accent: #667eea;
}

/* Make layout math predictable everywhere */
*,
*::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 layout */
.main-container {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;
  max-width: 1400px;
  margin: 0 auto;
  background: transparent;
}

/* Cards */
.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;
  /* allow these cards to shrink when screen is narrow */
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* dark-mode tint */
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;
}

/* FIX: ensure readable text on white background */
.preview-section {
  flex: 2 1 600px;
  font-size: 14px;
  background: white;
  color: #1f2937; /* was white; causes white-on-white */
}

/* keep preview readable in dark mode too */
body.dark .preview-section {
  background: white;
  color: #1f2937; /* keep text dark on white sheet */
}

.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);
}

/* ======= FIXED INPUTS & TEXTAREAS (no overflow) =======
   - Use width:100% and box-sizing to avoid overflow.
   - Remove centering margin that caused calc + padding conflicts.
   - Keep padding, border, radius and other visuals intact.
*/
input,
textarea {
  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; /* normal stacked spacing (no auto centering) */
  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; /* allow flex children to shrink */
}

/* keep specific grouped inputs still full width (explicitly) */
.education-inputs input,
.experience-inputs input,
.experience-inputs textarea,
.certifications-inputs input,
.certifications-inputs textarea,
.project-input input,
.project-input textarea,
.skills-grid input,
.skills-grid textarea {
  width: 100%;
  max-width: 100%;
  margin: 0 0 0.5rem 0;
  box-sizing: border-box;
}

/* focus state preserved */
input:focus,
textarea: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;
}

/* Buttons */
.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 button inserted by JS */
.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);
}

/* Grammar improve / suggestion UI (JS referenced) */
.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;
}

/* Cards / grouped inputs */
.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; /* allow inner content to shrink on small screens */
}

.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;
}

/* make grid children able to shrink */
.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 */
.contact-info {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  color: #4a5568;
  font-size: 14px;
  margin-bottom: 0;
}

/* allow contact items to wrap and shrink */
.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; /* visual hint that sections are draggable */
}

.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;
}

.skills-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-top: 0.8rem;
}

.skills-grid > div {
  margin-bottom: 0.8rem;
}

.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 animations */
.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);
}

/* Theme toggle button */
#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 */
.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;
}

/* Character count */
.char-count {
  font-size: 0.8rem;
  color: var(--muted);
  display: block;
  margin-top: -0.3rem;
  text-align: right;
  padding-right: 0.7rem;
}

/* exceed color referenced in JS */
.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;
}

/* Drag and Drop Styles */
.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;
}

/* Responsive Design */
@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;
  }
}

@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 button section */
.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);
}

/* Arrow icon */
.back-to-top::before {
  content: "↑";
  font-weight: bold;
}

/* Responsive tweaks for back-to-top container mention retained */
@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;
  }
}

/* Print layout */
@media print {
  .no-print {
    display: none;
  }

  .preview-section {
    box-shadow: none;
    border: none;
    background: white;
    color: #111827; /* ensure readable when printing */
  }

  body {
    background: white !important;
  }
}

/* Accessibility improvements (no HTML/JS changes needed) */
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;
}

/* Optional subtle hover for cards */
.education-inputs:hover,
.experience-inputs:hover,
.certifications-inputs:hover,
.project-input:hover {
  box-shadow: 0 6px 18px rgba(102, 126, 234, 0.18);
}

/* Keep links inside preview readable and consistent */
.preview-section a {
  color: #4f46e5;
}
.preview-section a:hover {
  text-decoration: underline;
}

/* Subtle divider for footer actions when printing disabled */
.footer-actions.no-print {
  border-top: 1px solid #e5e7eb;
}

/* Ensure long URLs wrap in preview (avoids overflow) */
.preview-section .contact-info span,
.preview-section .project-links a {
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* Smooth transitions for theme toggling without layout shifts */
.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;
}
