/* Fondo general (no afecta al PDF salvo que cambies el color del A4) */
body {
  font-family: sans-serif;
  background-color: #F2E9E4;
  color: #333;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
  margin: 0;
}

.app-container { text-align: center; }
.toolbar { display: inline-flex; gap: 10px; margin-bottom: 20px; align-items: center; }

#generar-pdf, #guardar-plantilla, #cargar-plantilla {
  padding: 10px 20px; font-size: 16px; cursor: pointer;
  background-color: #22223B; color: white; border: none; border-radius: 5px;
  transition: background-color 0.3s;
}
#guardar-plantilla { background-color: #1f6f8b; }
#cargar-plantilla { background-color: #364f6b; }
#generar-pdf:hover, #generar-pdf-baja:hover { background-color: #3c3c62; }
#guardar-plantilla:hover { background-color: #2a8fac; }
#cargar-plantilla:hover { background-color: #4a6a90; }

.toolbar select {
  padding: 10px 12px; font-size: 14px;
  border-radius: 5px; border: 1px solid #ccc; background: white;
}

/* Lienzo A4 (blanco por defecto) */
#lienzo-a4 {
  width: 1122px; height: 794px;
  background-color: #ffffff;
  border: 1px solid #ccc;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  position: relative;
  overflow: hidden;
}

/* --- Contenedores --- */
.contenedor-imagen, .contenedor-texto {
  position: absolute; background-color: #e9ecef; cursor: default; overflow: hidden; color: #adb5bd;
}
.contenedor-imagen { width: 200px; height: 356px; }
.contenedor-texto { width: 200px; height: 80px; background-color: transparent; border: 2px dashed #ccc; }

/* --- Contenido Interno --- */
.placeholder {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  display: flex; flex-direction: column; justify-content: center; align-items: center; pointer-events: auto;
}
.plus-symbol { font-size: 4rem; font-weight: 200; line-height: 1; }
.upload-text { margin-top: 10px; font-size: 0.9rem; letter-spacing: 1px; font-weight: 500; }
.contenedor-imagen img { position: absolute; top: 0; left: 0; display: none; cursor: grab; transform-origin: top left; }
.text-editor { box-sizing: border-box; width: 100%; height: 100%; padding: 10px; outline: none; font-size: 24px; overflow-y: auto; text-align: left; }

/* --- Asas de Control (Handles) --- */
.upload-handle, .drag-handle, .resize-handle, .controls-handle, .duplicate-handle, .delete-handle {
  position: absolute; width: 24px; height: 24px; background-color: #4A4E69;
  background-position: center; background-repeat: no-repeat; z-index: 10; cursor: pointer;
  opacity: .35; transition: opacity .15s ease-in-out;
}
.upload-handle:hover, .drag-handle:hover, .resize-handle:hover, .controls-handle:hover, .duplicate-handle:hover, .delete-handle:hover { opacity: 1; }
.upload-handle { top: 0; left: 0; border-bottom-right-radius: 4px;
  background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 4V20M4 12H20' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.drag-handle { top: 0; right: 0; cursor: move; border-bottom-left-radius: 4px;
  background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M10 4L4 10M4 4L10 10M14 4L20 10M20 4L14 10M10 20L4 14M4 20L10 14M14 20L20 14M20 20L14 14' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.resize-handle { bottom: 0; right: 0; cursor: nwse-resize; border-top-left-radius: 4px;
  background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M21 15V21H15M21 21L15 15' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.controls-handle { bottom: 0; left: 0; border-top-right-radius: 4px;
  background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20 7L4 7M18 12L6 12M16 17H8' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.duplicate-handle { top: 0; left: 50%; transform: translateX(-50%); border-bottom-left-radius: 4px; border-bottom-right-radius: 4px;
  background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Crect x='8' y='8' width='12' height='12' rx='2' stroke='white' stroke-width='2'/%3E%3Cpath d='M4 16V4H16' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.delete-handle { bottom: 0; left: 50%; transform: translateX(-50%); background-color: #E63946; border-top-left-radius: 4px; border-top-right-radius: 4px;
  background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3 6H5H21M8 6V4C8 3.46957 8.21071 2.96086 8.58579 2.58579C8.96086 2.21071 9.46957 2 10 2H14C14.5304 2 15.0391 2.21071 15.4142 2.58579C15.7893 2.96086 16 3.46957 16 4V6M19 6V20C19 20.5304 18.7893 21.0391 18.4142 21.4142C18.0391 21.7893 17.5304 22 17 22H7C6.46957 22 5.96086 21.7893 5.58579 21.4142C5.21071 21.0391 5 20.5304 5 20V6H3Z' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* Paneles de Control */
.controls-panel {
  position: absolute; bottom: 24px; left: 0; z-index: 5; box-sizing: border-box; width: 100%;
  background-color: rgba(40, 40, 40, 0.85); backdrop-filter: blur(2px);
  padding: 8px; display: none; flex-direction: column; gap: 8px; border-top-right-radius: 4px;
}
.controls-handle:hover + .controls-panel, .controls-panel:hover { display: flex; }
.controls-panel label { color: white; font-size: 12px; display: flex; align-items: center; justify-content: space-between; }
.controls-panel input[type="range"] { width: 100px; }
.controls-panel .button-group { display: flex; gap: 5px; }
.controls-panel button { background: #555; color: white; border: 1px solid #777; border-radius: 3px; padding: 4px 8px; font-size: 12px; cursor: pointer; flex-grow: 1; }
.controls-panel button:hover { background: #666; }
.text-controls select { width: 100%; background: #555; color: white; border: 1px solid #777; border-radius: 3px; padding: 4px; }
.text-style-controls { display: flex; flex-direction: column; gap: 8px; margin-top: 5px; }
.text-style-controls .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.text-controls button.active { background-color: #007BFF; }
.text-controls input[type="number"] { width: 60px; }

/* Estados */
.contenedor-imagen.dragging, .contenedor-texto.dragging { opacity: 0.7; z-index: 1000; }
#lienzo-a4.generating-pdf .contenedor-texto { border-color: transparent; }
#lienzo-a4.generating-pdf .upload-handle, #lienzo-a4.generating-pdf .drag-handle, #lienzo-a4.generating-pdf .resize-handle, #lienzo-a4.generating-pdf .controls-handle, #lienzo-a4.generating-pdf .duplicate-handle, #lienzo-a4.generating-pdf .delete-handle, #lienzo-a4.generating-pdf .controls-panel { display: none !important; }

/* Realce visual para drop */
.contenedor-imagen.drag-over {
  outline: 3px dashed #2b9348;
  outline-offset: -3px;
  background-color: rgba(43,147,72,0.08);
}