/* =====================================================================
   sheet.css — Base de la hoja (papel), campos editables, controles
   de edición superpuestos y reglas de impresión.
   Las variables --paper-w, --m-top, --font, --fs, etc. las fija la app
   según los ajustes del usuario (js/render.js → applySettings).
   ===================================================================== */

.sheet {
  position: relative;
  width: var(--paper-w, 210mm);
  min-height: var(--paper-h, 297mm);
  padding: var(--m-top, 20mm) var(--m-right, 20mm) var(--m-bottom, 20mm) var(--m-left, 20mm);
  background: #fff;
  color: var(--text, #111);
  font-family: var(--font, "Times New Roman", Times, serif);
  font-size: var(--fs, 11pt);
  line-height: var(--lh, 1.25);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
  overflow-wrap: anywhere;
}
.sheet * { box-sizing: border-box; }
.sheet a { color: inherit; text-decoration: underline; }
.sheet ul, .sheet ol { margin: 0.4mm 0 0 4.5mm; padding: 0; }
.sheet li { margin: 0; }
.sheet p, .sheet div { margin: 0; }
.sheet h1, .sheet h2, .sheet h3 { margin: 0; font-weight: 700; }

/* ---------- Campos editables ---------- */
.ed {
  outline: none;
  border-radius: 2px;
  transition: background-color 0.12s, box-shadow 0.12s;
  cursor: text;
}
.ed:not(:focus):hover { background: rgba(37, 99, 235, 0.08); box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.30); }
.ed:focus { background: rgba(37, 99, 235, 0.05); box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.65); }
.ed:empty::before { content: attr(data-ph); color: #9ca3af; pointer-events: none; }
.ed.rich:empty { min-height: 1.3em; }
.ed.rich:empty::before { font-style: italic; }
/* Chrome deja un <br> en campos vacíos; que no se vea */
.ed.rich > br:only-child { display: none; }

/* Separadores que dependen de que el campo anterior tenga contenido */
.sep { white-space: pre; }

/* ---------- Controles de edición superpuestos ---------- */
.cv-section, .cv-item { position: relative; }
.cv-actions {
  position: absolute; display: flex; gap: 2px;
  opacity: 0; pointer-events: none; transition: opacity 0.12s; z-index: 7;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 12px; line-height: 1;
}
.show-actions > .cv-actions { opacity: 1; pointer-events: auto; }
.sec-actions {
  right: -2px; top: -8px; flex-direction: row;
  background: rgba(255, 255, 255, 0.96); border: 1px solid #e5e7eb; border-radius: 7px;
  padding: 2px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.14);
}
.item-actions { left: -27px; top: -2px; flex-direction: column; width: 26px; padding-right: 3px; }
.act {
  width: 22px; height: 22px; border: 0; border-radius: 5px; background: transparent; color: #4b5563;
  cursor: pointer; display: grid; place-items: center; padding: 0; user-select: none;
}
.act:hover { background: #e5e7eb; color: #111; }
.act.danger:hover { background: #fee2e2; color: #b91c1c; }
.act.grip { cursor: grab; }
.act.grip:active { cursor: grabbing; }
.act svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.act.grip svg { fill: currentColor; stroke: none; }
.item-actions .act { background: rgba(255, 255, 255, 0.95); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18); }

/* Estados de SortableJS */
.sortable-ghost { opacity: 0.35; outline: 2px dashed #2563eb; outline-offset: 2px; background: rgba(37, 99, 235, 0.06); }
.sortable-chosen > .cv-actions { opacity: 0 !important; }
.sortable-drag { opacity: 0.95; }
.sheet .chip.sortable-ghost { display: block; width: 100%; height: 6mm; border-radius: 3px; border: 0; }

/* Guías de salto de página (aproximadas) */
.page-guides { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.page-guide { position: absolute; left: 0; right: 0; border-top: 1px dashed #ef4444; }
.page-guide span {
  position: absolute; right: 6px; top: 2px; font: 10px/1.2 system-ui, sans-serif; color: #ef4444;
  background: rgba(255, 255, 255, 0.9); padding: 2px 5px; border-radius: 3px;
}

/* Sección sin entradas */
.cv-empty {
  border: 1px dashed #cbd5e1; border-radius: 4px; padding: 2.5mm; text-align: center; color: #94a3b8;
  font: italic 10pt/1.3 system-ui, sans-serif; cursor: pointer;
}
.cv-empty:hover { border-color: #2563eb; color: #2563eb; }

/* Foto (contenedor genérico; cada plantilla decide dónde va) */
.cv-photo { width: var(--photo-size, 30mm); height: var(--photo-size, 30mm); flex-shrink: 0; overflow: hidden; }
.cv-photo.shape-circle { border-radius: 50%; }
.cv-photo.shape-rounded { border-radius: 3mm; }
.cv-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cv-photo .photo-placeholder {
  width: 100%; height: 100%; border: 1px dashed #cbd5e1; background: #f8fafc; color: #64748b;
  font: 9pt/1.3 system-ui, sans-serif; cursor: pointer; border-radius: inherit; display: grid; place-items: center; text-align: center; padding: 2mm;
}
.cv-photo .photo-placeholder:hover { border-color: #2563eb; color: #2563eb; }

/* ---------- ATS text extraction (js/ats.js) ----------
   While ats.js reads the page, hide the same editor-only parts that printing hides. */
.sheet.ats-reading .cv-actions, .sheet.ats-reading .page-guides, .sheet.ats-reading .cv-empty,
.sheet.ats-reading .photo-placeholder, .sheet.ats-reading .ed:empty { display: none !important; }

/* ---------- Impresión / PDF ---------- */
@media print {
  html, body { margin: 0 !important; padding: 0 !important; background: #fff !important; height: auto !important; overflow: visible !important; }
  .app { display: block !important; height: auto !important; }
  .topbar, .sidebar, .fab, .floating-toolbar, .toast,
  .cv-actions, .drop-indicator, .page-guides, .cv-empty, .photo-placeholder { display: none !important; }
  .canvas { padding: 0 !important; overflow: visible !important; background: #fff !important; height: auto !important; }
  .sheet-wrap { width: auto !important; height: auto !important; margin: 0 !important; }
  .sheet {
    transform: none !important; width: auto !important; min-height: 0 !important;
    padding: 0 !important; box-shadow: none !important; margin: 0 !important;
  }
  .ed { background: none !important; box-shadow: none !important; }
  .ed:empty { display: none !important; }
  .ed:empty::before { content: none !important; }
  .ed:empty + .sep { display: none !important; }
  .cv-photo:has(.photo-placeholder) { display: none !important; }
  .cv-item { break-inside: avoid; page-break-inside: avoid; }
  .cv-heading { break-after: avoid; page-break-after: avoid; }
}
