:root {
  --primary: #3b82f6;
  --bg-color: #f3f4f6;
  --doc-bg: #ffffff;
  --text-main: #333333;
  --border-color: #e5e7eb;
}

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

body {
  font-family: 'Open Sans', 'Helvetica Neue', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

.app-container {
  display: flex;
  height: 100vh;
}

/* Editor Sidebar */
.editor-sidebar {
  width: 480px;
  background: white;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 15px rgba(0, 0, 0, 0.05);
  z-index: 10;
}

.editor-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fafafa;
}

/* Ocultar/Visualizar Preview */
.app-container.preview-hidden .preview-area {
  display: none !important;
}

.app-container.preview-hidden .editor-sidebar {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  border-right: 1px solid var(--border-color);
  border-left: 1px solid var(--border-color);
}

@media (max-width: 1024px) {
  .app-container.preview-hidden .editor-sidebar {
    border-right: none;
    border-left: none;
    border-bottom: none;
  }

  .app-container.preview-hidden .editor-content {
    max-height: none;
    overflow-y: visible;
  }
}

.editor-header h2 {
  font-size: 1.2rem;
  font-weight: 600;
  color: #1f2937;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-primary:hover {
  background: #2563eb;
}

.btn-secondary {
  background: #e5e7eb;
  color: #4b5563;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: background 0.2s;
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-secondary:hover {
  background: #d1d5db;
}

.btn-danger {
  background: #fee2e2;
  color: #ef4444;
  border: none;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  margin-left: auto;
  display: flex;
  align-items: center;
  transition: background 0.2s;
}

.btn-danger:hover {
  background: #fca5a5;
}

.editor-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* Forms */
.form-section {
  margin-bottom: 30px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}

.form-section-header {
  background: #f9fafb;
  padding: 12px 15px;
  border-bottom: 1px solid #e5e7eb;
  font-weight: 700;
  color: #374151;
  font-size: 0.95rem;
}

.form-section-body {
  padding: 15px;
}

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 4px;
  color: #4b5563;
  font-weight: 600;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  outline: none;
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.info-alert {
  background-color: #eff6ff;
  border-left: 4px solid var(--primary);
  padding: 12px 15px;
  border-radius: 4px;
  font-size: 0.85rem;
  color: #1e3a8a;
  margin-bottom: 15px;
  line-height: 1.5;
}

.info-alert i {
  color: var(--primary);
  margin-right: 6px;
  font-size: 0.95rem;
}

.dynamic-list-item {
  border: 1px dashed #d1d5db;
  padding: 15px;
  border-radius: 6px;
  margin-bottom: 15px;
  background: #fcfcfc;
}

.list-item-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 15px;
  align-items: center;
  color: #4b5563;
}

/* Preview Area */
.preview-area {
  flex: 1;
  overflow-y: auto;
  padding: 40px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: #6b7280;
}

.paper {
  background: var(--doc-bg);
  width: 210mm;
  min-height: 297mm;
  /* Ensure it stays A4 size at min */
  padding: 20mm;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  font-size: 10pt;
  line-height: 1.5;
  color: #333;
  transform: scale(var(--user-zoom, 1));
  transform-origin: top center;
  margin-bottom: calc(-297mm * (1 - var(--user-zoom, 1)));
  transition: transform 0.2s, margin 0.2s;
}

/* Zoom Controls */
.zoom-controls {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: white;
  padding: 8px 12px;
  border-radius: 30px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
  display: none;
  /* Escondido por padrão no desktop */
  align-items: center;
  gap: 12px;
  z-index: 100;
  border: 1px solid var(--border-color);
}

.btn-zoom {
  background: #f3f4f6;
  border: none;
  width: 35px;
  height: 35px;
  border-radius: 50%;
  cursor: pointer;
  color: #4b5563;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.2s;
  font-size: 1.1rem;
}

.btn-zoom:hover {
  background: #e5e7eb;
  color: var(--primary);
}

#zoom-level {
  font-size: 0.95rem;
  font-weight: 600;
  color: #374151;
  min-width: 45px;
  text-align: center;
}

/* PDF Export Fixes */
.pdf-export-mode {
  padding: 0 !important;
  width: 100% !important;
  min-height: auto !important;
  box-shadow: none !important;
  margin: 0 !important;
  transform: scale(1) !important;
}

/* Resume Layout matching exactly */
.resume-header {
  margin-bottom: 35px;
}

.resume-name {
  font-size: 26pt;
  font-weight: 400;
  margin-bottom: 12px;
  color: #1a1a1a;
  letter-spacing: -0.5px;
}

.personal-details {
  font-size: 10pt;
  line-height: 1.4;
  margin-bottom: 25px;
  color: #333;
}

.contact-bar {
  background-color: #f3f4f6;
  display: flex;
  gap: 30px;
  padding: 12px 20px;
  font-size: 9.5pt;
  align-items: center;
  justify-content: flex-start;
  margin-left: -5px;
  border-radius: 2px;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #444;
}

.contact-item i {
  color: #666;
  font-size: 11pt;
}

.contact-link {
  color: inherit;
  text-decoration: none;
}

.contact-link:hover {
  text-decoration: underline;
}

.resume-section {
  margin-bottom: 30px;
  page-break-inside: avoid;
}

.resume-section-title {
  font-size: 14pt;
  font-weight: 700;
  margin-bottom: 20px;
  color: #333;
}

.resume-block-simple {
  margin-left: 15px;
  border-left: 1px solid #bce;
  padding-left: 20px;
  font-size: 10.5pt;
  line-height: 1.6;
  color: #444;
  border-color: #c5c5c5;
}

.resume-item-grid {
  display: grid;
  grid-template-columns: 80px 1fr;
  column-gap: 41px;
  row-gap: 8px;
  position: relative;
  margin-bottom: 25px;
  page-break-inside: avoid;
}

.resume-item-grid-line {
  position: absolute;
  top: 0;
  bottom: -5px;
  left: 100px;
  width: 1px;
  background-color: #c5c5c5;
}

.grid-label {
  grid-column: 1;
  text-align: right;
  color: #777;
  font-weight: 700;
  font-size: 10pt;
}

.grid-value {
  grid-column: 2;
  font-size: 10.5pt;
  color: #444;
  line-height: 1.5;
}

.font-bold {
  font-weight: 700;
  color: #333;
}

/* Resume Links */
.resume-link {
  color: #3b82f6;
  text-decoration: underline;
  background: transparent;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.loading-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.loading-content {
  text-align: center;
  color: var(--primary);
  font-weight: 600;
  font-size: 1.1rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e5e7eb;
  border-top: 4px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 15px auto;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* ------------------------------------- */
/* Mobile & Responsiveness               */
/* ------------------------------------- */

/* Breakpoint for Tablets and below */
@media (max-width: 1024px) {
  .app-container {
    flex-direction: column;
    overflow-y: auto;
    /* Permite scroll da própria tela caso necessário */
  }

  body {
    overflow: auto;
    /* Permite scroll global em telas pequenas */
  }

  .editor-sidebar {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 2px solid var(--border-color);
  }

  .editor-content {
    /* Sem limite de altura por padrão em celulares para evitar rolagem dupla */
    max-height: none;
    overflow-y: visible;
  }

  /* No mobile/tablet, o preview vem depois e preenche a largura COMO MODAL */
  .preview-area {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    background: #6b7280;
    padding: 20px 10px;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
  }

  /* O botão fechar aparece somente quando está como modal */
  #close-preview-btn-mobile {
    display: inline-flex !important;
  }

  /* Em Mobile o modal fica acima de tudo, inclusive scroll do body some quando visualizando pdf */
  body:has(.app-container:not(.preview-hidden)) {
    overflow: hidden;
  }

  .zoom-controls {
    display: flex;
    /* Exibe os controles de zoom apenas no mobile/tablet */
    z-index: 1050;
    /* Garante controle de zoom ficar em cima do proprio modal */
  }

  .paper {
    /* Nos dispositivos móveis cruzamos com aspect-ratio via scale */
    transform-origin: top center;
    transform: scale(calc(var(--user-zoom) * 0.85));
    margin-bottom: calc(-297mm * (1 - (var(--user-zoom) * 0.85)));
  }
}

/* Breakpoint for Mobile specifics */
@media (max-width: 768px) {

  /* Na tela de celular de fato, a escala do PDF precisa ignorar as quebras por flexbox e grids
     para que o PDF final ainda saia no formato e não saia desconfigurado. Deixamos a visuzalização simulando. */
  .paper {
    /* Em mobile simulamos papel inteiro e o usuario usa scroll */
    transform-origin: top center;
    transform: scale(calc(var(--user-zoom) * 0.45));
    /* Pequeno o suficiente pra caber no cel vertical */
    margin-bottom: calc(-297mm * (1 - (var(--user-zoom) * 0.45)));
  }
}