/* =================================================================== */
/* === editor-personajes.css - VERSIÓN FINAL Y DEPURADA ================ */
/* =================================================================== */

/* --- 1. VIEWPORT Y LIENZO DE FONDO --- */
#personajes {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    cursor: grab;
 
}
#personajes:active {
    cursor: grabbing;
}

#lienzo-visual {
    position: absolute;
    width: 16000px;
    height: 16000px;
    transform-origin: 0 0;
    background-image: radial-gradient(circle at 1px 1px, rgba(0, 0, 0, 0.1) 1px, transparent 0);
    background-size: 25px 25px;
    z-index: 1; overflow: hidden;
  
}

/* El contenedor de datos pesados está oculto, no necesita estilos visuales */
#listapersonajes {
    display: none;
    overflow: hidden;
}


/* --- 2. STICKERS (ELEMENTOS VISUALES EN EL LIENZO) --- */
.personaje-sticker {
    position: absolute;
    width: 150px;
    height: auto;
    aspect-ratio: 1 / 1;
    padding: 5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: rgba(240, 240, 240, 0.13);
    border: 0px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    cursor: grab;
    transition: box-shadow 0.2s ease;
}
.personaje-sticker.dragging {
    cursor: grabbing;
    z-index: 100;
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
}

.sticker-img {
    width: 140px;
    height: 140px;
    object-fit: contain;
    border-radius: 4px;
    -webkit-user-drag: none;
    user-select: none;
}

/* --- NUEVO ESTILO --- */
/* Estilo para el input cuando se está editando el nombre */
.sticker-nombre-edit {
    font-family: inherit; /* Usa la misma fuente que el resto de la app */
    font-size: 14px;
    font-weight: bold;
    color: #000;
    background-color: #ffffff;
    text-align: center;
    width: 95%; /* Un poco menos del 100% para que se vea el borde */
    border: 1px solid #007bff; /* Un borde azul para indicar que es editable */
    border-radius: 4px;
    padding: 3px;
    margin: 1px 0;
    box-sizing: border-box; /* Muy importante para que no cambie el tamaño del sticker */
    height: 25px;
}
.sticker-nombre-edit:focus {
    outline: none;
    box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
}
.sticker-nombre {
    font-size: 14px;
    font-weight: bold;
    background-color: black;
    color: #ffffff;
    padding: 5px 0;
    text-align: center;
    width: 100%;
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sticker-edit-btn {
    position: absolute;
    bottom: 47%;
    right: 2%;
    opacity: 0; 
    transform: scale(0.8);
    transition: opacity 0.2s ease, transform 0.2s ease;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 16px;
     
    line-height: 30px;
    text-align: center;
    cursor: pointer;
    z-index: 10;
}



.personaje-sticker .personaje-visual {
    /* ... otros estilos que ya tengas ... */

    /* --- AÑADE ESTAS LÍNEAS --- */
    background-size: cover;          /* Hace que el fondo cubra todo el espacio disponible. */
    background-position: center;     /* Centra el fondo por si acaso. */
    background-repeat: no-repeat;    /* Evita que el fondo se repita. */
}

.personaje-sticker:hover .sticker-edit-btn {
    opacity: 1;
    transform: scale(1);
}


/* =================================================================== */
/* --- 3. LÓGICA DEL MODAL DE EDICIÓN (CÓDIGO UNIFICADO Y CORREGIDO) --- */
/* =================================================================== */

/* El fondo oscuro que cubre toda la pantalla */
.modal-background-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0);
    z-index: 9999;
    backdrop-filter: blur(4px);
}
 
/* El contenedor .personaje, cuando se convierte en el modal */
.personaje.editing-in-modal {
    position: fixed !important; /* Usamos !important para asegurar que sobreescribe 'position: absolute' */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10000;
    
    width: 70vw;
     
    height: 70vh;
  

    background-color: #ffffff15;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
    
    display: flex;
    flex-direction: column;
    padding: 20px;
}

/* --- Control de visibilidad del contenido DENTRO del modal --- */

/* Cuando está en modo modal, ocultamos la vista previa y los botones externos */
.personaje.editing-in-modal .personaje-visual,
.personaje.editing-in-modal > .change-tag-btn,
.personaje.editing-in-modal > .change-arc-btn,
.personaje.editing-in-modal > .nombreh {
    display: none;
}

/* Por defecto, el panel de edición está oculto */
.personaje .personaje-edit-overlay {
    display: none;
}

/* Y MOSTRAMOS el panel de edición SÓLO cuando el padre tiene la clase de modal */
.personaje.editing-in-modal .personaje-edit-overlay {
    display: flex; /* <-- La clave es mostrarlo aquí */
    flex-direction: column;
    flex-grow: 1;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    
    /* Reseteamos cualquier estilo de posicionamiento antiguo que pudiera interferir */
    position: static; 
    opacity: 1;
    pointer-events: auto;
    transform: none;
}


/* --- Estilos de los elementos INTERNOS del panel de edición --- */
.edit-controls {
    display: flex;
    flex-direction: row;
    gap: 20px;
    height: 100%;
    min-height: 500px; /* Asegura una altura mínima para ver el contenido */
}

.edit-preview-container {
    flex: 1 1 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f0f0f0;
    border-radius: 8px;
    min-height: 250px;
}
.edit-preview-image, .edit-svg-preview, .edit-3d-canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}
/* La imagen se muestra por defecto, el resto se gestiona por JS */
.edit-preview-image { display: block; }
.edit-svg-preview, .edit-3d-canvas { display: none; }


.edit-text-controls {
    flex: 1 1 50%; overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.descripcionh, .prompt-visualh {
    width: 100%;
    background-color: #f7f7f7;
    color: #333;
    
    border-radius: 8px;
    padding: 10px;
    box-sizing: border-box;
    resize: none;
    font-size: 1em;
}
.descripcionh { flex-grow: 1; }
.prompt-visualh { height: 40%; }
.edit-buttons-wrapper { overflow: none; display: flex; justify-content: center; gap: 10px; margin-top: auto; }
.edit-btn {
  
    border-radius: 50%;
    border: none;
 
    color: #333;
    font-size: 18px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.edit-btn:hover { background-color: #007bff; color: white; }
.edit-btn.delete-btn:hover { background-color: #dc3545; }

/* Menús emergentes (sin cambios) */
.menu-etiquetas { position: absolute; background-color: #fff; border: 1px solid #ccc; border-radius: 8px; z-index: 10001; box-shadow: 0 4px 15px rgba(0,0,0,0.15); padding: 5px; max-height: 250px; overflow-y: auto; }
.item-menu-etiqueta { padding: 8px 12px; cursor: pointer; color: #333; border-radius: 5px; font-size: 16px; }
.item-menu-etiqueta:hover { background-color: #f0f0f0; }



/* =================================================================== */
/* --- 4. EDICIÓN RÁPIDA DE ETIQUETA Y ARCO EN STICKERS (HOVER) --- */
/* =================================================================== */

/* 1. Estilo y posición base para los botones dentro de un sticker */
.personaje-sticker .change-tag-btn,
.personaje-sticker .change-arc-btn {
    position: absolute;
    bottom: 5px;
    opacity: 0; /* Ocultos por defecto */
    pointer-events: none;
    transform: scale(0.8);
    transition: opacity 0.2s ease, transform 0.2s ease;
    
    /* Estilos visuales para que se vean bien */
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 16px;
    line-height: 30px;
    padding: 0;
    text-align: center;
    cursor: pointer;
    z-index: 10;
}

/* 2. Posicionamos cada botón en su esquina */
.personaje-sticker .change-arc-btn {
    right: 5px;
}
/* Movemos el de etiqueta para que no se solape con el de editar */
.personaje-sticker .change-tag-btn {
    left: 5px; 
}


/* 3. Al pasar el ratón sobre el STICKER, hacemos visibles los botones */
.personaje-sticker:hover .change-tag-btn,
.personaje-sticker:hover .change-arc-btn {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
}